CustomerApiController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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.ArrayList;
  6. import java.util.Date;
  7. import java.util.List;
  8. import javax.annotation.Resource;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import com.alibaba.fastjson.JSON;
  13. import com.alibaba.fastjson.JSONArray;
  14. import com.goafanti.common.bo.Result;
  15. import com.goafanti.common.constant.AFTConstants;
  16. import com.goafanti.common.constant.ErrorConstants;
  17. import com.goafanti.common.controller.BaseController;
  18. import com.goafanti.common.error.BusinessException;
  19. import com.goafanti.common.model.OrganizationContactBook;
  20. import com.goafanti.common.model.User;
  21. import com.goafanti.common.model.UserBusiness;
  22. import com.goafanti.common.utils.BeanUtilsExt;
  23. import com.goafanti.common.utils.StringUtils;
  24. import com.goafanti.core.shiro.token.TokenManager;
  25. import com.goafanti.customer.bo.CustomerListIn;
  26. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  27. import com.goafanti.customer.bo.FollowBusinessBo;
  28. import com.goafanti.customer.bo.UserDetailBo;
  29. import com.goafanti.customer.service.BusinessService;
  30. import com.goafanti.customer.service.CustomerService;
  31. @RestController
  32. @RequestMapping("api/admin/customer")
  33. public class CustomerApiController extends BaseController{
  34. @Resource
  35. private CustomerService customerService;
  36. @Resource
  37. private BusinessService businessService;
  38. /** 私有个人客户列表 **/
  39. @RequestMapping(value = "/listPrivatePersonalCustomer" , method = RequestMethod.POST)
  40. public Result listPrivatePersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  41. Result res = new Result();
  42. res.setData(customerService.listPrivatePersonalCustomer(cli, pageNo, pageSize));
  43. return res;
  44. }
  45. /** 公共个人客户列表 **/
  46. @RequestMapping(value = "/listPublicPersonalCustomer" , method = RequestMethod.POST)
  47. public Result listPublicPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  48. Result res = new Result();
  49. res.setData(customerService.listPublicPersonalCustomer(cli, pageNo, pageSize));
  50. return res;
  51. }
  52. /** 个人客户查询 **/
  53. @RequestMapping(value = "/listAllPersonalCustomer" , method = RequestMethod.POST)
  54. public Result listAllPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  55. Result res = new Result();
  56. res.setData(customerService.listAllPersonalCustomer(cli, pageNo, pageSize));
  57. return res;
  58. }
  59. /** 私有单位客户列表 **/
  60. @RequestMapping(value = "/listPrivateOrganizationCustomer" , method = RequestMethod.POST)
  61. public Result listPrivateOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  62. Result res = new Result();
  63. res.setData(customerService.listPrivateOrganizationCustomer(cli, pageNo, pageSize));
  64. return res;
  65. }
  66. /** 公共单位客户列表 **/
  67. @RequestMapping(value = "/listPublicOrganizationCustomer" , method = RequestMethod.POST)
  68. public Result listPublicOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  69. Result res = new Result();
  70. res.setData(customerService.listPublicOrganizationCustomer(cli, pageNo, pageSize));
  71. return res;
  72. }
  73. /** 单位客户查询 **/
  74. @RequestMapping(value = "/listAllOrganizationCustomer" , method = RequestMethod.POST)
  75. public Result listAllOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  76. Result res = new Result();
  77. res.setData(customerService.listAllOrganizationCustomer(cli, pageNo, pageSize));
  78. return res;
  79. }
  80. /** 客户即时检索 **/
  81. @RequestMapping(value = "/findCustomerByName",method = RequestMethod.GET)
  82. public Result findCustomerByName(String name){
  83. Result res = new Result();
  84. res.setData(customerService.findCustomerByName(name));
  85. return res;
  86. }
  87. /** 添加客户基本信息
  88. * @throws Exception
  89. * @throws NumberFormatException **/
  90. @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
  91. public Result addCustomer(String name,String contacts,String contactMobile,String type) throws Exception{
  92. Result res = new Result();
  93. customerService.addCustomer(name, contacts, contactMobile, Integer.parseInt(type));
  94. return res;
  95. }
  96. /** 个人客户详情信息 **/
  97. @RequestMapping(value = "/findPersonalCustomerDetail" ,method = RequestMethod.GET)
  98. public Result findPersonalCustomerDetail(String uid){
  99. Result res = new Result();
  100. res.setData(customerService.findPersonalCustomerDetail(uid));
  101. return res;
  102. }
  103. /** 单位客户详情信息 **/
  104. @RequestMapping(value = "/findOrganizationCustomerDetail", method = RequestMethod.GET)
  105. public Result findOrganizationCustomerDetail(String uid){
  106. Result res = new Result();
  107. res.setData(customerService.findOrganizationCustomerDetail(uid));
  108. return res;
  109. }
  110. /** 修改单位客户信息 **/
  111. @RequestMapping(value = "/updateOrganizationCustomer", method = RequestMethod.POST)
  112. public Result updateOrganizationCustomer(CustomerOrganizationDetailBo bo){
  113. Result res = new Result();
  114. if(StringUtils.isBlank(bo.getId()) || StringUtils.isBlank(bo.getUid())){
  115. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  116. return res;
  117. }
  118. customerService.updateOrganizationCustomer(bo);
  119. return res;
  120. }
  121. /** 查看跟进记录 **/
  122. @RequestMapping(value = "/listFollowHistory", method = RequestMethod.GET)
  123. public Result listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId){
  124. Result res = new Result();
  125. res.setData(customerService.listFollowHistory(pageNo,pageSize,uid,businessGlossoryId));
  126. return res;
  127. }
  128. /** 查看客户账户信息 **/
  129. @RequestMapping(value = "/findUserAccountDetail", method = RequestMethod.GET)
  130. public Result findUserAcountDetail(String uid){
  131. Result res = new Result();
  132. UserDetailBo bo = new UserDetailBo();
  133. User user = customerService.findUserAccountDetail(uid);
  134. try {
  135. BeanUtilsExt.copyProperties(bo, user);
  136. } catch (InvocationTargetException | IllegalAccessException e) {
  137. e.printStackTrace();
  138. }
  139. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  140. bo.setCreateTimes(format.format(user.getCreateTime()));
  141. res.setData(bo);
  142. return res;
  143. }
  144. /** 修改客户账户信息 **/
  145. @RequestMapping(value = "/updateUserAccount", method = RequestMethod.POST)
  146. public Result updateUserAccount(User user){
  147. Result res = new Result();
  148. customerService.updateUserAccount(user);
  149. return res;
  150. }
  151. /** 查看客户联系人列表 **/
  152. @RequestMapping(value = "/findCustomerContacts", method = RequestMethod.GET)
  153. public Result findCustomerContacts(String uid){
  154. Result res = new Result();
  155. res.setData(customerService.findCustomerContacts(uid));
  156. return res;
  157. }
  158. /** 进入添加拜访记录 **/
  159. @RequestMapping(value = "/toAddFollow", method = RequestMethod.GET)
  160. public Result toAddFollow(String uid){
  161. Result res = new Result();
  162. if(StringUtils.isBlank(uid)){
  163. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  164. return res;
  165. }
  166. User user = customerService.findUserAccountDetail(uid);
  167. FollowBusinessBo fbb = new FollowBusinessBo();
  168. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  169. fbb.setFollowTime(format.format(new Date()));
  170. fbb.setIdentityName(user.getIdentifyName());
  171. fbb.setUid(uid);
  172. fbb.setUserBusinessList(businessService.findBusinessByUAid(uid, TokenManager.getAdminId()));
  173. res.setData(fbb);
  174. return res;
  175. }
  176. /** 添加拜访记录
  177. * @throws ParseException
  178. * @throws Exception **/
  179. @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
  180. public Result addFollow(String userBusinessList,String uid,String ocbId,String contactType,String result,String followTime) throws BusinessException{
  181. Result res = new Result();
  182. if(StringUtils.isBlank(uid) || StringUtils.isBlank(ocbId)){
  183. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  184. return res;
  185. }
  186. JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
  187. List<UserBusiness> list = new ArrayList<UserBusiness>();
  188. if (ja != null && !ja.isEmpty()) {
  189. UserBusiness userBusiness = null;
  190. for (int idx = 0; idx < ja.size(); idx++) {
  191. userBusiness = ja.getJSONObject(idx).toJavaObject(UserBusiness.class);
  192. for(UserBusiness ub:list){
  193. if(ub.getBusinessGlossoryId() == userBusiness.getBusinessGlossoryId()){
  194. res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
  195. return res;
  196. }
  197. }
  198. list.add(userBusiness);
  199. }
  200. }
  201. FollowBusinessBo fbb = new FollowBusinessBo();
  202. fbb.setOcbId(ocbId);
  203. fbb.setUid(uid);
  204. fbb.setContactType(contactType);
  205. fbb.setResult(result);
  206. fbb.setFollowTime(followTime);
  207. fbb.setUserBusinessList(list);
  208. customerService.addFollow(fbb);
  209. return res;
  210. }
  211. /** 进入修改拜访记录 **/
  212. @RequestMapping(value = "/toUpdateFollow", method = RequestMethod.GET)
  213. public Result toUpdateFollow(String followId){
  214. Result res = new Result();
  215. FollowBusinessBo fbb = customerService.findFollowById(followId);
  216. fbb.setUserBusinessList(customerService.findBusinessByFollowId(followId));
  217. res.setData(fbb);
  218. return res;
  219. }
  220. /** 修改拜访记录
  221. * @throws ParseException
  222. * @throws BusinessException
  223. */
  224. @RequestMapping(value = "/updateFollow", method = RequestMethod.POST)
  225. public Result updateFollow(String userBusinessList,String followId,String followTime,String uid,String contactType,String result) throws BusinessException{
  226. Result res = new Result();
  227. if(StringUtils.isBlank(uid) || StringUtils.isBlank(followId)){
  228. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  229. return res;
  230. }
  231. JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
  232. List<UserBusiness> list = new ArrayList<UserBusiness>();
  233. if (ja != null && !ja.isEmpty()) {
  234. UserBusiness userBusiness = null;
  235. for (int idx = 0; idx < ja.size(); idx++) {
  236. userBusiness = ja.getJSONObject(idx).toJavaObject(UserBusiness.class);
  237. for(UserBusiness ub:list){
  238. if(ub.getBusinessGlossoryId() == userBusiness.getBusinessGlossoryId()){
  239. res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
  240. return res;
  241. }
  242. }
  243. list.add(userBusiness);
  244. }
  245. }
  246. FollowBusinessBo fbb = new FollowBusinessBo();
  247. fbb.setFollowTime(followTime);
  248. fbb.setUid(uid);
  249. fbb.setContactType(contactType);
  250. fbb.setResult(result);
  251. fbb.setUserBusinessList(list);
  252. fbb.setFollowId(followId);
  253. customerService.updateFollow(fbb);
  254. return res;
  255. }
  256. /** 查询客户的所有联系人 **/
  257. @RequestMapping(value = "/findAllContacts", method = RequestMethod.GET)
  258. public Result findAllContacts(String uid){
  259. Result res = new Result();
  260. res.setData(customerService.findAllContacts(uid));
  261. return res;
  262. }
  263. /** 修改企业联系人 **/
  264. @RequestMapping(value = "/updateCustomerContacts", method = RequestMethod.POST)
  265. public Result updateCustomerContacts(String contactList,String uid){
  266. Result res = new Result();
  267. if(StringUtils.isBlank(uid)){
  268. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  269. return res;
  270. }
  271. JSONArray ja = (JSONArray) JSON.parse(contactList);
  272. List<OrganizationContactBook> ocbList = new ArrayList<OrganizationContactBook>();
  273. OrganizationContactBook ocb = null;
  274. if(ja != null & !ja.isEmpty()){
  275. for (int idx = 0; idx < ja.size(); idx++) {
  276. ocb = ja.getJSONObject(idx).toJavaObject(OrganizationContactBook.class);
  277. if(StringUtils.isBlank(ocb.getMobile()) || StringUtils.isBlank(ocb.getName())){
  278. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名和手机号码为必填"));
  279. return res;
  280. }
  281. if(StringUtils.isBlank(ocb.getUid())) ocb.setUid(uid);
  282. ocbList.add(ocb);
  283. }
  284. }
  285. customerService.updateCustomerContacts(ocbList,uid);
  286. return res;
  287. }
  288. }