AdminCustomerApiController.java 15 KB

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