AdminCustomerApiController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.List;
  6. import java.util.UUID;
  7. import javax.annotation.Resource;
  8. import javax.servlet.http.HttpServletRequest;
  9. import org.apache.commons.beanutils.BeanUtils;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.goafanti.customer.bo.AdminOut;
  15. import com.goafanti.customer.bo.CustomerIn;
  16. import com.goafanti.customer.bo.CustomerOut;
  17. import com.goafanti.customer.service.CustomerOrganizationService;
  18. import com.goafanti.customer.service.CustomerService;
  19. import com.goafanti.customer.service.CustomerUserService;
  20. import com.goafanti.customer.service.FollowUpService;
  21. import com.goafanti.admin.service.AdminService;
  22. import com.goafanti.common.bo.Result;
  23. import com.goafanti.common.constant.AFTConstants;
  24. import com.goafanti.common.controller.BaseController;
  25. import com.goafanti.common.model.Customer;
  26. import com.goafanti.common.model.CustomerOrganizationInfo;
  27. import com.goafanti.common.model.CustomerUserInfo;
  28. import com.goafanti.common.model.FollowUpRecord;
  29. import com.goafanti.core.mybatis.page.Pagination;
  30. @RestController
  31. @RequestMapping(value = "/api/admin/customer")
  32. public class AdminCustomerApiController extends BaseController {
  33. @Resource
  34. private CustomerService customerService;
  35. @Resource
  36. private CustomerUserService customerUserService;
  37. @Resource
  38. private CustomerOrganizationService customerOrganizationService;
  39. @Resource
  40. private AdminService adminService;
  41. @Resource
  42. private FollowUpService followUpService;
  43. /**
  44. * 新增客户
  45. *
  46. * @return
  47. * @throws ParseException
  48. * @throws InvocationTargetException
  49. * @throws IllegalAccessException
  50. */
  51. @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
  52. public Result addCustomer(CustomerIn cusIn,CustomerOrganizationInfo coi,CustomerUserInfo cui,FollowUpRecord fur) throws ParseException, IllegalAccessException, InvocationTargetException {
  53. Result res=new Result();
  54. //添加 customer
  55. String customerId = UUID.randomUUID().toString();//客户记录ID
  56. String customerUsrId= UUID.randomUUID().toString();//客户联系人ID
  57. String followId=UUID.randomUUID().toString();//跟进记录ID
  58. Customer c = new Customer();
  59. cusIn.setFollowId(followId);
  60. cusIn.setId(customerId);
  61. cui.setId(customerUsrId);
  62. cui.setCid(customerId);//客户联系人表中的cid
  63. coi.setId(UUID.randomUUID().toString());//客户公司ID
  64. coi.setCid(customerId);//客户公司表中的cid
  65. fur.setId(followId);//跟进记录的ID
  66. fur.setCid(customerId);//跟进记录表中的cid
  67. fur.setCuid(customerUsrId);//跟进记录表中的联系人id
  68. /*if(StringUtils.isNotBlank(cusIn.getAid())) fur.setAid(cusIn.getAid());*//*暂时注释*/
  69. BeanUtils.copyProperties(c, cusIn);
  70. c.setShareType(Integer.parseInt(cusIn.getShareTyp()));
  71. c.setCustomerType(Integer.parseInt(cusIn.getCustomerTyp()));
  72. c.setId(customerId);
  73. customerService.addCustomer(c);
  74. //插入 customerUserInfo
  75. customerUserService.addCustomerUserInfo(cui);
  76. //插入 customerOrganizationInfo
  77. customerOrganizationService.addCustomerOrganizationInfo(coi);
  78. //插入跟进表
  79. followUpService.addFollowUp(fur,cusIn);
  80. //添加日志
  81. customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_CREATE,customerId);
  82. return res;
  83. }
  84. /**
  85. * 删除
  86. *
  87. * @return
  88. * @throws ParseException
  89. */
  90. @RequestMapping(value = "/deleteCustomer", method = RequestMethod.POST)
  91. public Result deleteCustomer(String id,CustomerIn cusIn) throws ParseException {
  92. Result res=new Result();
  93. customerService.deleteCustomer(id);
  94. customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_DELETE,id);
  95. return res;
  96. }
  97. /**
  98. * 查询操作员信息
  99. *
  100. * @return
  101. * @throws InvocationTargetException
  102. * @throws IllegalAccessException
  103. * @throws ParseException
  104. */
  105. @RequestMapping(value = "/findAdmin", method = RequestMethod.POST)
  106. public Result selectAllAdmin(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  107. Result res = new Result();
  108. List<AdminOut> adminList = adminService.selectAdmin();
  109. for (int i = 0; i < adminList.size(); i++) {
  110. adminList.get(i).setBeforeAdminName(cusIn.getBeforeAdminName());
  111. adminList.get(i).setBeforeCompanyIntention(cusIn.getBeforeCompanyIntention());
  112. adminList.get(i).setBeforeCustomerStatus(cusIn.getBeforeCustomerStatus());
  113. adminList.get(i).setBeforeFollowSituation(cusIn.getBeforeFollowSituation());
  114. adminList.get(i).setCid(cusIn.getId());
  115. }
  116. res.setData(adminList);
  117. return res;
  118. }
  119. /**
  120. * 查看私有客户
  121. * @param request
  122. * @return
  123. */
  124. @RequestMapping(value = "/listPrivateCustomer", method = RequestMethod.POST)
  125. public Result listPrivateCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNumber){
  126. Result res = new Result();
  127. Pagination<CustomerOut> boList = customerService.getPrivateCustomer(cin, pageSize, pageNumber);
  128. res.setData(boList);
  129. return res;
  130. }
  131. /**
  132. * 查询客户资料
  133. *
  134. * @return
  135. */
  136. @RequestMapping(value = "/findCustomerUserDetails", method = RequestMethod.POST)
  137. public Result findCustomerUserDetails(String id) {
  138. Result res=new Result();
  139. res.setData(customerService.findCustomerDetails(id));
  140. return res;
  141. }
  142. /**
  143. * 查询联系人姓名列表
  144. *
  145. * @return
  146. */
  147. @RequestMapping(value = "/findCustomerUserNameList", method = RequestMethod.POST)
  148. public Result findCustomerUserNameList (String cid) {
  149. Result res =new Result();
  150. res.setData(customerUserService.findCustomerUserNameList(cid));
  151. return res;
  152. }
  153. /**
  154. * 添加联系人
  155. *
  156. * @return
  157. * @throws InvocationTargetException
  158. * @throws IllegalAccessException
  159. */
  160. @RequestMapping(value = "/addContacter", method = RequestMethod.POST)
  161. public Result addContacter (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  162. Result res =new Result();
  163. CustomerUserInfo cui =new CustomerUserInfo();
  164. BeanUtils.copyProperties(cui, cusIn);
  165. cui.setId(UUID.randomUUID().toString());
  166. if(cui.getPrimaryFlg()==0) {//0:主要联系人,1-非主要联系人
  167. String primaryId = customerUserService.selectPrimaryFlgByCid(cusIn.getId());
  168. if(StringUtils.isNoneBlank(primaryId)) {
  169. customerUserService.updPrimaryFlg(cusIn.getId());//把主要联系人状态给去掉
  170. }
  171. customerUserService.addCustomerUserInfo(cui);//再添加联系人
  172. }else {
  173. customerUserService.addCustomerUserInfo(cui);
  174. }
  175. return res;
  176. }
  177. /**
  178. * 修改客户信息
  179. * @return
  180. * @throws InvocationTargetException
  181. * @throws IllegalAccessException
  182. */
  183. @RequestMapping(value = "/updCustomer", method = RequestMethod.POST)
  184. public Result updCustomer (CustomerIn cusIn,CustomerOrganizationInfo coi) throws IllegalAccessException, InvocationTargetException {
  185. Result res=new Result();
  186. Customer c =new Customer();
  187. BeanUtils.copyProperties(c, cusIn);
  188. c.setShareType(Integer.parseInt(cusIn.getShareTyp()));
  189. c.setCustomerType(Integer.parseInt(cusIn.getCustomerTyp()));
  190. coi.setCid(cusIn.getId());
  191. //更新主表
  192. customerService.updateCustomer(c);
  193. //更新公司表
  194. customerOrganizationService.updateCustomerOrganizationInfo(coi);
  195. //插入日志表
  196. customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_MODIFY,cusIn.getId());
  197. return res;
  198. }
  199. /**
  200. * 转交
  201. * @return
  202. * @throws InvocationTargetException
  203. * @throws IllegalAccessException
  204. */
  205. @RequestMapping(value = "/transferCustomer", method = RequestMethod.POST)
  206. public Result transferCustomer (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  207. Result res=new Result();
  208. Customer c =new Customer();
  209. BeanUtils.copyProperties(c, cusIn);
  210. //更新主表
  211. customerService.updateCustomer(c);
  212. //插入日志表
  213. customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_TRANSFER,cusIn.getId());
  214. return res;
  215. }
  216. /**
  217. * 查询单个联系人信息
  218. * @return
  219. */
  220. /*@RequestMapping(value = "/transferCsutomer", method = RequestMethod.POST)
  221. public Result findContractById (String id) {
  222. Result res=new Result();
  223. res.setData(customerUserService.findContractById(id));
  224. return res;
  225. }*/
  226. /**
  227. * 修改单个联系人信息
  228. * @return
  229. */
  230. /*@RequestMapping(value = "/transferCsutomer", method = RequestMethod.POST)
  231. public Result updContractById (String id) {
  232. Result res=new Result();
  233. return res;
  234. }*/
  235. /**
  236. * 添加跟进记录
  237. * @param fur
  238. * @return
  239. * @throws ParseException
  240. */
  241. @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
  242. public Result addFollowUpRecord(FollowUpRecord fur, CustomerIn cusIn ,String followDate) throws ParseException{
  243. Result res = new Result();
  244. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  245. if(StringUtils.isNotBlank(followDate)) fur.setFollowDate(format.parse(followDate));
  246. String followId = UUID.randomUUID().toString();
  247. fur.setId(followId);
  248. cusIn.setFollowId(followId);
  249. followUpService.addFollowUp(fur, cusIn);
  250. Customer cus = new Customer();
  251. try {
  252. BeanUtils.copyProperties(cus, cusIn);
  253. if(StringUtils.isNotBlank(cusIn.getFollowSituation()))
  254. cus.setFollowSituation(Integer.parseInt(cusIn.getFollowSituation()));
  255. if(StringUtils.isNotBlank(cusIn.getCustomerStatus()))
  256. cus.setCustomerStatus(Integer.parseInt(cusIn.getCustomerStatus()));
  257. } catch (IllegalAccessException | InvocationTargetException e) {
  258. e.printStackTrace();
  259. }
  260. customerService.updateCustomer(cus);
  261. return res;
  262. }
  263. /**
  264. * 查看公司基本信息
  265. * @return
  266. */
  267. @RequestMapping(value = "/findCustomerBaseInfo" , method = RequestMethod.GET)
  268. public Result findCustomerBaseInfo(String customerId,String customerName){
  269. Result res= new Result();
  270. CustomerOut cusOut = customerService.findCustomerBaseInfo(customerId);
  271. cusOut.setCustomerName(customerName);
  272. res.setData(cusOut);
  273. return res;
  274. }
  275. /**
  276. * 查看跟进记录
  277. * @param customerId
  278. * @return
  279. */
  280. @RequestMapping(value = "/listFollowUpRecord" , method = RequestMethod.GET)
  281. public Result listFollowUpRecord(String customerId){
  282. Result res= new Result();
  283. res.setData(followUpService.listFollowUpRecord(customerId));
  284. return res;
  285. }
  286. }