AdminCustomerApiController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. package com.goafanti.customer.controller;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.List;
  7. import java.util.UUID;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.apache.commons.beanutils.BeanUtils;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import com.goafanti.customer.bo.AdminOut;
  17. import com.goafanti.customer.bo.CustomerIn;
  18. import com.goafanti.customer.bo.CustomerOut;
  19. import com.goafanti.customer.service.CustomerOrganizationService;
  20. import com.goafanti.customer.service.CustomerService;
  21. import com.goafanti.customer.service.CustomerUserService;
  22. import com.goafanti.customer.service.FollowUpService;
  23. import com.goafanti.admin.service.AdminService;
  24. import com.goafanti.common.bo.Error;
  25. import com.goafanti.common.bo.Result;
  26. import com.goafanti.common.constant.AFTConstants;
  27. import com.goafanti.common.constant.ErrorConstants;
  28. import com.goafanti.common.controller.BaseApiController;
  29. import com.goafanti.common.model.Customer;
  30. import com.goafanti.common.model.CustomerOrganizationInfo;
  31. import com.goafanti.common.model.CustomerUserInfo;
  32. import com.goafanti.common.model.FollowUpRecord;
  33. import com.goafanti.core.mybatis.page.Pagination;
  34. import com.goafanti.core.shiro.token.TokenManager;
  35. @RestController
  36. @RequestMapping(value = "/api/admin/customer")
  37. public class AdminCustomerApiController extends BaseApiController {
  38. @Resource
  39. private CustomerService customerService;
  40. @Resource
  41. private CustomerUserService customerUserService;
  42. @Resource
  43. private CustomerOrganizationService customerOrganizationService;
  44. @Resource
  45. private AdminService adminService;
  46. @Resource
  47. private FollowUpService followUpService;
  48. /**
  49. * 新增客户
  50. *
  51. * @return
  52. * @throws ParseException
  53. * @throws InvocationTargetException
  54. * @throws IllegalAccessException
  55. */
  56. @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
  57. public Result addCustomer(CustomerIn cusIn,CustomerOrganizationInfo coi,CustomerUserInfo cui,FollowUpRecord fur) throws ParseException, IllegalAccessException, InvocationTargetException {
  58. Result res=new Result();
  59. //查询客户是否已经存在
  60. if(customerOrganizationService.findCustomerOrganizationByName(cusIn.getCompanyName())>0){
  61. res.getError().add(buildError(ErrorConstants.CUSTOMER_ALREADY_EXIST));
  62. return res;
  63. }
  64. //添加 customer
  65. String customerId = UUID.randomUUID().toString();//客户记录ID
  66. String customerUsrId= UUID.randomUUID().toString();//客户联系人ID
  67. String followId=UUID.randomUUID().toString();//跟进记录ID
  68. Customer c = new Customer();
  69. cusIn.setFollowId(followId);
  70. cusIn.setId(customerId);
  71. cui.setId(customerUsrId);
  72. cui.setCid(customerId);//客户联系人表中的cid
  73. coi.setId(UUID.randomUUID().toString());//客户公司ID
  74. coi.setCid(customerId);//客户公司表中的cid
  75. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDD);
  76. fur.setFollowDate(format.parse(cusIn.getFollowDates()));
  77. fur.setId(followId);//跟进记录的ID
  78. fur.setCid(customerId);//跟进记录表中的cid
  79. fur.setCuid(customerUsrId);//跟进记录表中的联系人id
  80. /*if(StringUtils.isNotBlank(cusIn.getAid())) fur.setAid(cusIn.getAid());*//*暂时注释*/
  81. BeanUtils.copyProperties(c, cusIn);
  82. c.setShareType(Integer.parseInt(cusIn.getShareType()));
  83. c.setCustomerType(Integer.parseInt(cusIn.getCustomerType()));
  84. c.setId(customerId);
  85. customerService.addCustomer(c);
  86. //插入 customerUserInfo
  87. customerUserService.addCustomerUserInfo(cui);
  88. //插入 customerOrganizationInfo
  89. customerOrganizationService.addCustomerOrganizationInfo(coi);
  90. //插入跟进表
  91. followUpService.addFollowUp(fur);
  92. //添加日志
  93. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_CREATE,customerId);
  94. return res;
  95. }
  96. /**
  97. * 删除
  98. *
  99. * @return
  100. * @throws ParseException
  101. */
  102. @RequestMapping(value = "/deleteCustomer", method = RequestMethod.POST)
  103. public Result deleteCustomer(CustomerIn cusIn) throws ParseException {
  104. Result res=new Result();
  105. customerService.deleteCustomer(cusIn.getId());
  106. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_DELETE,cusIn.getId());
  107. return res;
  108. }
  109. /**
  110. * 查询操作员信息
  111. *
  112. * @return
  113. * @throws InvocationTargetException
  114. * @throws IllegalAccessException
  115. * @throws ParseException
  116. */
  117. @RequestMapping(value = "/findAdmin", method = RequestMethod.POST)
  118. public Result selectAllAdmin(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  119. Result res = new Result();
  120. List<AdminOut> adminList = adminService.selectAdmin();
  121. for (int i = 0; i < adminList.size(); i++) {
  122. adminList.get(i).setBeforeAdminName(cusIn.getBeforeAdminName());
  123. adminList.get(i).setBeforeCompanyIntention(cusIn.getBeforeCompanyIntention());
  124. adminList.get(i).setBeforeCustomerStatus(cusIn.getBeforeCustomerStatus());
  125. adminList.get(i).setBeforeFollowSituation(cusIn.getBeforeFollowSituation());
  126. adminList.get(i).setCid(cusIn.getId());
  127. }
  128. res.setData(adminList);
  129. return res;
  130. }
  131. /**
  132. * 查看个人客户列表
  133. * @param request
  134. * @return
  135. */
  136. @RequestMapping(value = "/listPrivateCustomer", method = RequestMethod.POST)
  137. public Result listPrivateCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
  138. Result res = new Result();
  139. Pagination<CustomerOut> boList = customerService.getPrivateCustomer(cin, pageSize, pageNo);
  140. res.setData(boList);
  141. return res;
  142. }
  143. /**
  144. * 查询客户详情
  145. *
  146. * @return
  147. */
  148. @RequestMapping(value = "/findCustomerDetails", method = RequestMethod.POST)
  149. public Result findCustomerDetails(String id) {
  150. Result res=new Result();
  151. res.setData(customerService.findCustomerDetails(id));
  152. return res;
  153. }
  154. /**
  155. * 查询公司客户资料
  156. *
  157. * @return
  158. */
  159. @RequestMapping(value = "/findAllCustomerDetails", method = RequestMethod.POST)
  160. public Result findAllCustomerDetails(String id) {
  161. Result res=new Result();
  162. res.setData(customerService.findCustomerDetails(id));
  163. return res;
  164. }
  165. /**
  166. * 查询联系人姓名列表
  167. *
  168. * @return
  169. */
  170. @RequestMapping(value = "/findCustomerUserList", method = RequestMethod.POST)
  171. public Result findCustomerUserList (String cid) {
  172. Result res =new Result();
  173. res.setData(customerUserService.selectCustomerUserList(cid));
  174. return res;
  175. }
  176. /**
  177. * 添加联系人
  178. *
  179. * @return
  180. * @throws InvocationTargetException
  181. * @throws IllegalAccessException
  182. */
  183. @RequestMapping(value = "/addContacter", method = RequestMethod.POST)
  184. public Result addContacter (CustomerUserInfo cui) throws IllegalAccessException, InvocationTargetException {
  185. Result res =new Result();
  186. cui.setId(UUID.randomUUID().toString());
  187. if(cui.getPrimaryFlg()==0) {//0:主要联系人,1-非主要联系人
  188. String primaryId = customerUserService.selectPrimaryFlgByCid(cui.getCid());
  189. if(StringUtils.isNoneBlank(primaryId)) {
  190. customerUserService.updatePrimaryFlg(primaryId);//把主要联系人状态给去掉
  191. }
  192. customerUserService.addCustomerUserInfo(cui);//再添加联系人
  193. }else {
  194. customerUserService.addCustomerUserInfo(cui);
  195. }
  196. return res;
  197. }
  198. /**
  199. * 修改客户信息
  200. * @return
  201. * @throws InvocationTargetException
  202. * @throws IllegalAccessException
  203. */
  204. @RequestMapping(value = "/updateCustomer", method = RequestMethod.POST)
  205. public Result updateCustomer (CustomerIn cusIn,CustomerOrganizationInfo coi,HttpServletResponse rsp) throws IllegalAccessException, InvocationTargetException {
  206. Result res=new Result();
  207. Customer c =new Customer();
  208. BeanUtils.copyProperties(c, cusIn);
  209. c.setCustomerType(Integer.parseInt(cusIn.getCustomerType()));
  210. coi.setCid(cusIn.getId());
  211. //更新主表
  212. customerService.updateCustomer(c);
  213. //更新公司表
  214. customerOrganizationService.updateCustomerOrganizationInfo(coi);
  215. //插入日志表
  216. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_MODIFY,cusIn.getId());
  217. return res;
  218. }
  219. /**
  220. * 转交
  221. * @return
  222. * @throws InvocationTargetException
  223. * @throws IllegalAccessException
  224. */
  225. @RequestMapping(value = "/transferCustomer", method = RequestMethod.POST)
  226. public Result transferCustomer (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  227. Result res=new Result();
  228. Customer c =new Customer();
  229. c.setId(cusIn.getId());
  230. c.setAid(cusIn.getAid());
  231. c.setCreateTime(new Date());
  232. //更新主表
  233. customerService.updateCustomer(c);
  234. //插入日志表
  235. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_TRANSFER,cusIn.getId());
  236. return res;
  237. }
  238. /**
  239. * 查询单个联系人信息
  240. * @return
  241. */
  242. @RequestMapping(value = "/findContactDetail", method = RequestMethod.GET)
  243. public Result findContactDetail (String contactId) {
  244. Result res=new Result();
  245. res.setData(customerUserService.findContactDetail(contactId));
  246. return res;
  247. }
  248. /**
  249. * 修改联系人信息
  250. * @return
  251. */
  252. @RequestMapping(value = "/updateContacter", method = RequestMethod.POST)
  253. public Result updateContacter (CustomerUserInfo cui) {
  254. Result res=new Result();
  255. if(cui.getPrimaryFlg() == 0){
  256. String primaryId = customerUserService.selectPrimaryFlgByCid(cui.getCid());
  257. if(StringUtils.isNoneBlank(primaryId)) {
  258. customerUserService.updatePrimaryFlg(primaryId);//把主要联系人状态给去掉
  259. }
  260. }
  261. customerUserService.updateContractById(cui);
  262. return res;
  263. }
  264. /**
  265. * 添加跟进记录
  266. * @param fur
  267. * @return
  268. * @throws ParseException
  269. */
  270. @RequestMapping(value = "/addFollowUpRecord", method = RequestMethod.POST)
  271. public Result addFollowUpRecord(FollowUpRecord fur, CustomerIn cusIn) throws ParseException{
  272. Result res = new Result();
  273. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  274. if(StringUtils.isNotBlank(cusIn.getFollowDates())) fur.setFollowDate(format.parse(cusIn.getFollowDates()));
  275. String followId = UUID.randomUUID().toString();
  276. fur.setId(followId);
  277. fur.setCid(cusIn.getId());
  278. fur.setEffective(0);
  279. cusIn.setFollowId(followId);
  280. followUpService.addFollowUp(fur);
  281. Customer cus = new Customer();
  282. try {
  283. BeanUtils.copyProperties(cus, cusIn);
  284. if(StringUtils.isNotBlank(cusIn.getFollowSituation()))
  285. cus.setFollowSituation(Integer.parseInt(cusIn.getFollowSituation()));
  286. if(StringUtils.isNotBlank(cusIn.getCustomerStatus()))
  287. cus.setCustomerStatus(Integer.parseInt(cusIn.getCustomerStatus()));
  288. } catch (IllegalAccessException | InvocationTargetException e) {
  289. e.printStackTrace();
  290. }
  291. customerService.updateCustomer(cus);
  292. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_FOLLOW,cusIn.getId());
  293. return res;
  294. }
  295. /**
  296. * 查看公司基本信息
  297. * @return
  298. */
  299. @RequestMapping(value = "/findCustomerBaseInfo" , method = RequestMethod.GET)
  300. public Result findCustomerBaseInfo(String customerId,String customerName){
  301. Result res= new Result();
  302. CustomerOut cusOut = customerService.findCustomerBaseInfo(customerId);
  303. cusOut.setCustomerName(customerName);
  304. res.setData(cusOut);
  305. return res;
  306. }
  307. /**
  308. * 查看跟进记录
  309. * @param customerId
  310. * @return
  311. */
  312. @RequestMapping(value = "/listFollowUpRecord" , method = RequestMethod.GET)
  313. public Result listFollowUpRecord(String customerId){
  314. Result res= new Result();
  315. res.setData(followUpService.listFollowUpRecord(customerId));
  316. return res;
  317. }
  318. /**
  319. * 查看公司客户跟进记录
  320. * @param customerId
  321. * @return
  322. */
  323. @RequestMapping(value = "/listAllFollowUpRecord" , method = RequestMethod.GET)
  324. public Result listAllFollowUpRecord(String customerId){
  325. Result res= new Result();
  326. res.setData(followUpService.listFollowUpRecord(customerId));
  327. return res;
  328. }
  329. /**
  330. * 删除联系人
  331. * @param customerId
  332. * @return
  333. */
  334. @RequestMapping(value = "/deleteContacter" , method = RequestMethod.GET)
  335. public Result deleteContacter(String contactId){
  336. Result res= new Result();
  337. CustomerUserInfo customerUserInfo = customerUserService.findContractById(contactId);
  338. if(customerUserInfo.getPrimaryFlg()==0) {
  339. res.getError().add(new Error("该联系人为主要联系人,不能进行删除操作!"));
  340. }else {
  341. customerUserService.deleteContractById(contactId);
  342. }
  343. return res;
  344. }
  345. /**
  346. * 营销员填写跟进记录上传文件
  347. * @param req
  348. * @param sign
  349. * @return
  350. */
  351. @RequestMapping(value = "/attachmentUpload" , method = RequestMethod.POST)
  352. public Result attachmentUpload(HttpServletRequest req, String sign){
  353. Result res= new Result();
  354. res.setData(handleFile(res, "/customer_sys_file/", true, req, sign));
  355. return res;
  356. }
  357. /**
  358. * 删除跟进记录
  359. * @param followId
  360. * @return
  361. */
  362. @RequestMapping(value = "/deleteFollowUpRecord", method = RequestMethod.GET)
  363. public Result deleteFollowUpRecord(String followId){
  364. Result res= new Result();
  365. followUpService.deleteFollowUpRecord(followId);
  366. return res;
  367. }
  368. /**
  369. * 查看公共客户
  370. * @param request
  371. * @return
  372. */
  373. @RequestMapping(value = "/listPublicCustomer", method = RequestMethod.POST)
  374. public Result listPublicCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
  375. Result res = new Result();
  376. Pagination<CustomerOut> boList = customerService.getPublicCustomer(cin, pageSize, pageNo);
  377. res.setData(boList);
  378. return res;
  379. }
  380. /**
  381. * 领取
  382. * @param cusIn
  383. * @return
  384. * @throws IllegalAccessException
  385. * @throws InvocationTargetException
  386. */
  387. @RequestMapping(value = "/receivePublicCustomer", method = RequestMethod.GET)
  388. public Result receivePublicCustomer(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException{
  389. Result res=new Result();
  390. Customer c =new Customer();
  391. c.setId(cusIn.getId());
  392. c.setAid(TokenManager.getAdminId());
  393. c.setShareType(0);
  394. //更新主表
  395. customerService.updateCustomer(c);
  396. //插入日志表
  397. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_RECEIVE,cusIn.getId());
  398. return res;
  399. }
  400. /**
  401. * 查看公共客户
  402. * @param request
  403. * @return
  404. */
  405. @RequestMapping(value = "/listTeamCustomer", method = RequestMethod.POST)
  406. public Result listTeamCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
  407. Result res = new Result();
  408. Pagination<CustomerOut> boList = customerService.getTeamCustomer(cin, pageSize, pageNo);
  409. res.setData(boList);
  410. return res;
  411. }
  412. /**
  413. * 转为公共客户
  414. * @return
  415. * @throws InvocationTargetException
  416. * @throws IllegalAccessException
  417. */
  418. @RequestMapping(value = "/transferToPublic" , method = RequestMethod.POST)
  419. public Result transferToPublic(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException{
  420. Result res=new Result();
  421. Customer c = new Customer();
  422. c.setId(cusIn.getId());
  423. c.setAid("");
  424. c.setShareType(1);
  425. c.setCreateTime(new Date());
  426. //更新主表
  427. customerService.updateCustomer(c);
  428. //插入日志表
  429. customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_TO_PUBLIC,cusIn.getId());
  430. return res;
  431. }
  432. /**
  433. * 查看公司客户
  434. * @param request
  435. * @return
  436. */
  437. @RequestMapping(value = "/listCompanyCustomer", method = RequestMethod.POST)
  438. public Result listCompanyCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
  439. Result res = new Result();
  440. Pagination<CustomerOut> boList = customerService.getCompanyCustomer(cin, pageSize, pageNo);
  441. res.setData(boList);
  442. return res;
  443. }
  444. /**
  445. * 查看日志信息
  446. * @param customerId
  447. * @return
  448. */
  449. @RequestMapping(value = "/listCustomerLog",method = RequestMethod.GET)
  450. public Result listCustomerLog(String customerId){
  451. Result res = new Result();
  452. res.setData(customerService.listCustomerLog(customerId));
  453. return res;
  454. }
  455. /**
  456. * 客户详情-操作记录
  457. * @return
  458. */
  459. @RequestMapping(value = "/findCustomerHistory",method = RequestMethod.GET)
  460. public Result findCustomerHistory(String customerId){
  461. Result res = new Result();
  462. res.setData(customerService.findCustomerHistory(customerId));
  463. return res;
  464. }
  465. }