AdminCustomerApiController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package com.goafanti.customer.controller;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.text.ParseException;
  4. import java.util.List;
  5. import java.util.UUID;
  6. import javax.annotation.Resource;
  7. import javax.servlet.http.HttpServletRequest;
  8. import org.apache.commons.beanutils.BeanUtils;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import com.goafanti.customer.bo.CustomerIn;
  14. import com.goafanti.customer.bo.CustomerOut;
  15. import com.goafanti.customer.service.CustomerOrganizationService;
  16. import com.goafanti.customer.service.CustomerService;
  17. import com.goafanti.customer.service.CustomerUserService;
  18. import com.goafanti.customer.service.FollowUpService;
  19. import com.goafanti.admin.service.AdminService;
  20. import com.goafanti.common.bo.Result;
  21. import com.goafanti.common.constant.AFTConstants;
  22. import com.goafanti.common.controller.BaseController;
  23. import com.goafanti.common.model.Admin;
  24. import com.goafanti.common.model.Customer;
  25. import com.goafanti.common.model.CustomerOrganizationInfo;
  26. import com.goafanti.common.model.CustomerUserInfo;
  27. import com.goafanti.common.model.FollowUpRecord;
  28. import com.goafanti.core.mybatis.page.Pagination;
  29. import com.goafanti.core.shiro.token.TokenManager;
  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. cui.setId(customerUsrId);
  61. cui.setCid(customerId);//客户联系人表中的cid
  62. coi.setId(UUID.randomUUID().toString());//客户公司ID
  63. coi.setCid(customerId);//客户公司表中的cid
  64. fur.setId(followId);//跟进记录的ID
  65. fur.setCid(customerId);//跟进记录表中的cid
  66. fur.setCuid(customerUsrId);//跟进记录表中的联系人id
  67. fur.setAid(TokenManager.getUserId());
  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 ParseException
  102. */
  103. @RequestMapping(value = "/findAdmin", method = RequestMethod.POST)
  104. public Result selectAllAdmin() throws ParseException {
  105. Result res = new Result();
  106. List<Admin> selectAllAdmin = adminService.selectAllAdmin();
  107. res.setData(selectAllAdmin);
  108. return res;
  109. }
  110. /**
  111. * 查看私有客户
  112. * @param request
  113. * @return
  114. */
  115. @RequestMapping(value = "/listPrivateCustomer", method = RequestMethod.POST)
  116. public Result listPrivateCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNumber){
  117. Result res = new Result();
  118. Pagination<CustomerOut> boList = customerService.getPrivateCustomer(cin, pageSize, pageNumber);
  119. res.setData(boList);
  120. return res;
  121. }
  122. /**
  123. * 查询客户资料
  124. *
  125. * @return
  126. */
  127. @RequestMapping(value = "/findCustomerUserDetails", method = RequestMethod.POST)
  128. public Result findCustomerUserDetails(String id) {
  129. Result res=new Result();
  130. res.setData(customerService.findCustomerDetails(id));
  131. return res;
  132. }
  133. /**
  134. * 查询联系人姓名列表
  135. *
  136. * @return
  137. */
  138. @RequestMapping(value = "/findCustomerUserNameList", method = RequestMethod.POST)
  139. public Result findCustomerUserNameList (String cid) {
  140. Result res =new Result();
  141. res.setData(customerUserService.findCustomerUserNameList(cid));
  142. return res;
  143. }
  144. /**
  145. * 添加联系人
  146. *
  147. * @return
  148. * @throws InvocationTargetException
  149. * @throws IllegalAccessException
  150. */
  151. @RequestMapping(value = "/addContacter", method = RequestMethod.POST)
  152. public Result addContacter (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  153. Result res =new Result();
  154. CustomerUserInfo cui =new CustomerUserInfo();
  155. BeanUtils.copyProperties(cui, cusIn);
  156. cui.setId(UUID.randomUUID().toString());
  157. if(cui.getPrimaryFlg()==0) {//0:主要联系人,1-非主要联系人
  158. String primaryId = customerUserService.selectPrimaryFlgByCid(cusIn.getId());
  159. if(StringUtils.isNoneBlank(primaryId)) {
  160. customerUserService.updPrimaryFlg(cusIn.getId());//把主要联系人状态给去掉
  161. }
  162. customerUserService.addCustomerUserInfo(cui);//再添加联系人
  163. }else {
  164. customerUserService.addCustomerUserInfo(cui);
  165. }
  166. return res;
  167. }
  168. /**
  169. * 修改客户信息
  170. * @return
  171. * @throws InvocationTargetException
  172. * @throws IllegalAccessException
  173. */
  174. @RequestMapping(value = "/updCustomer", method = RequestMethod.POST)
  175. public Result updCustomer (CustomerIn cusIn,CustomerOrganizationInfo coi) throws IllegalAccessException, InvocationTargetException {
  176. Result res=new Result();
  177. Customer c =new Customer();
  178. BeanUtils.copyProperties(c, cusIn);
  179. c.setShareType(Integer.parseInt(cusIn.getShareTyp()));
  180. c.setCustomerType(Integer.parseInt(cusIn.getCustomerTyp()));
  181. coi.setCid(cusIn.getId());
  182. //更新主表
  183. customerService.updateCustomer(c);
  184. //更新公司表
  185. customerOrganizationService.updateCustomerOrganizationInfo(coi);
  186. //插入日志表
  187. customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_MODIFY,cusIn.getId());
  188. return res;
  189. }
  190. /**
  191. * 转交
  192. * @return
  193. * @throws InvocationTargetException
  194. * @throws IllegalAccessException
  195. */
  196. @RequestMapping(value = "/transferCsutomer", method = RequestMethod.POST)
  197. public Result transferCsutomer (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
  198. Result res=new Result();
  199. Customer c =new Customer();
  200. BeanUtils.copyProperties(c, cusIn);
  201. //更新主表
  202. customerService.updateCustomer(c);
  203. //插入日志表
  204. customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_TRANSFER,cusIn.getId());
  205. return res;
  206. }
  207. }