CustomerApiController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. package com.goafanti.customer.controller;
  2. import java.io.IOException;
  3. import java.lang.reflect.InvocationTargetException;
  4. import java.text.ParseException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9. import java.util.Set;
  10. import java.util.TreeSet;
  11. import javax.annotation.Resource;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import com.alibaba.fastjson.JSON;
  19. import com.alibaba.fastjson.JSONArray;
  20. import com.goafanti.admin.service.AftFileService;
  21. import com.goafanti.common.bo.Error;
  22. import com.goafanti.common.bo.Result;
  23. import com.goafanti.common.constant.AFTConstants;
  24. import com.goafanti.common.constant.ErrorConstants;
  25. import com.goafanti.common.controller.BaseApiController;
  26. import com.goafanti.common.error.BusinessException;
  27. import com.goafanti.common.model.AftFile;
  28. import com.goafanti.common.model.OrganizationContactBook;
  29. import com.goafanti.common.model.User;
  30. import com.goafanti.common.model.UserBusiness;
  31. import com.goafanti.common.utils.BeanUtilsExt;
  32. import com.goafanti.common.utils.ExcelUtils;
  33. import com.goafanti.common.utils.StringUtils;
  34. import com.goafanti.core.shiro.token.TokenManager;
  35. import com.goafanti.customer.bo.CustomerExcelBo;
  36. import com.goafanti.customer.bo.CustomerListIn;
  37. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  38. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  39. import com.goafanti.customer.bo.FollowBusinessBo;
  40. import com.goafanti.customer.bo.UserDetailBo;
  41. import com.goafanti.customer.service.BusinessService;
  42. import com.goafanti.customer.service.CustomerService;
  43. @RestController
  44. @RequestMapping("api/admin/customer")
  45. public class CustomerApiController extends BaseApiController{
  46. @Resource
  47. private CustomerService customerService;
  48. @Resource
  49. private BusinessService businessService;
  50. @Resource
  51. private AftFileService aftFileService;
  52. @Value(value = "${upload.private.path}")
  53. private String uploadPrivatePath = null;
  54. /** 私有个人客户列表 **/
  55. @RequestMapping(value = "/listPrivatePersonalCustomer" , method = RequestMethod.POST)
  56. public Result listPrivatePersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  57. Result res = new Result();
  58. res.setData(customerService.listPrivatePersonalCustomer(cli, pageNo, pageSize));
  59. return res;
  60. }
  61. /** 公共个人客户列表 **/
  62. @RequestMapping(value = "/listPublicPersonalCustomer" , method = RequestMethod.POST)
  63. public Result listPublicPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  64. Result res = new Result();
  65. res.setData(customerService.listPublicPersonalCustomer(cli, pageNo, pageSize));
  66. return res;
  67. }
  68. /** 个人客户查询 **/
  69. @RequestMapping(value = "/listAllPersonalCustomer" , method = RequestMethod.POST)
  70. public Result listAllPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  71. Result res = new Result();
  72. res.setData(customerService.listAllPersonalCustomer(cli, pageNo, pageSize));
  73. return res;
  74. }
  75. /** 私有单位客户列表 **/
  76. @RequestMapping(value = "/listPrivateOrganizationCustomer" , method = RequestMethod.POST)
  77. public Result listPrivateOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  78. Result res = new Result();
  79. res.setData(customerService.listPrivateOrganizationCustomer(cli, pageNo, pageSize));
  80. return res;
  81. }
  82. /** 公共单位客户列表 **/
  83. @RequestMapping(value = "/listPublicOrganizationCustomer" , method = RequestMethod.POST)
  84. public Result listPublicOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  85. Result res = new Result();
  86. res.setData(customerService.listPublicOrganizationCustomer(cli, pageNo, pageSize));
  87. return res;
  88. }
  89. /** 单位客户查询 **/
  90. @RequestMapping(value = "/listAllOrganizationCustomer" , method = RequestMethod.POST)
  91. public Result listAllOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  92. Result res = new Result();
  93. res.setData(customerService.listAllOrganizationCustomer(cli, pageNo, pageSize));
  94. return res;
  95. }
  96. /** 客户即时检索 **/
  97. @RequestMapping(value = "/findCustomerByName",method = RequestMethod.GET)
  98. public Result findCustomerByName(String name){
  99. Result res = new Result();
  100. res.setData(customerService.findCustomerByName(name));
  101. return res;
  102. }
  103. /** 添加客户基本信息
  104. * @throws Exception
  105. * @throws NumberFormatException **/
  106. @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
  107. public Result addCustomer(String name,String contacts,String contactMobile,String type,String societyTag) throws Exception{
  108. Result res = new Result();
  109. if(StringUtils.isBlank(name) || StringUtils.isBlank(contacts)
  110. || StringUtils.isBlank(contactMobile) || StringUtils.isBlank(societyTag)){
  111. res.getError().add(buildError("客户名称、联系人、联系电话、社会性质不能为空"));
  112. return res;
  113. }
  114. customerService.addCustomer(name, contacts, contactMobile, Integer.parseInt(type),societyTag);
  115. return res;
  116. }
  117. /** 个人客户详情信息 **/
  118. @RequestMapping(value = "/findPersonalCustomerDetail" ,method = RequestMethod.GET)
  119. public Result findPersonalCustomerDetail(String uid){
  120. Result res = new Result();
  121. res.setData(customerService.findPersonalCustomerDetail(uid));
  122. return res;
  123. }
  124. /** 单位客户详情信息 **/
  125. @RequestMapping(value = "/findOrganizationCustomerDetail", method = RequestMethod.GET)
  126. public Result findOrganizationCustomerDetail(String uid){
  127. Result res = new Result();
  128. res.setData(customerService.findOrganizationCustomerDetail(uid));
  129. return res;
  130. }
  131. /** 修改单位客户信息 **/
  132. @RequestMapping(value = "/updateOrganizationCustomer", method = RequestMethod.POST)
  133. public Result updateOrganizationCustomer(CustomerOrganizationDetailBo bo){
  134. Result res = new Result();
  135. if(StringUtils.isBlank(bo.getId()) || StringUtils.isBlank(bo.getUid())){
  136. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  137. return res;
  138. }
  139. customerService.updateOrganizationCustomer(bo);
  140. return res;
  141. }
  142. /** 修改个人客户信息 **/
  143. @RequestMapping(value = "/updatePersonalCustomer", method = RequestMethod.POST)
  144. public Result updatePersonalCustomer(CustomerPersonalDetailBo bo){
  145. Result res = new Result();
  146. if(StringUtils.isBlank(bo.getUid()) || StringUtils.isBlank(bo.getId())){
  147. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  148. return res;
  149. }
  150. customerService.updatePersonalCustomer(bo);
  151. return res;
  152. }
  153. /** 查看跟进记录 **/
  154. @RequestMapping(value = "/listFollowHistory", method = RequestMethod.GET)
  155. public Result listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId){
  156. Result res = new Result();
  157. res.setData(customerService.listFollowHistory(pageNo,pageSize,uid,businessGlossoryId));
  158. return res;
  159. }
  160. /** 查看客户账户信息 **/
  161. @RequestMapping(value = "/findUserAccountDetail", method = RequestMethod.GET)
  162. public Result findUserAcountDetail(String uid){
  163. Result res = new Result();
  164. UserDetailBo bo = new UserDetailBo();
  165. User user = customerService.findUserAccountDetail(uid);
  166. try {
  167. BeanUtilsExt.copyProperties(bo, user);
  168. } catch (InvocationTargetException | IllegalAccessException e) {
  169. e.printStackTrace();
  170. }
  171. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  172. bo.setCreateTimes(format.format(user.getCreateTime()));
  173. res.setData(bo);
  174. return res;
  175. }
  176. /** 修改客户账户信息 **/
  177. @RequestMapping(value = "/updateUserAccount", method = RequestMethod.POST)
  178. public Result updateUserAccount(User user){
  179. Result res = new Result();
  180. customerService.updateUserAccount(user);
  181. return res;
  182. }
  183. /** 查看客户联系人列表 **/
  184. @RequestMapping(value = "/findCustomerContacts", method = RequestMethod.GET)
  185. public Result findCustomerContacts(String uid){
  186. Result res = new Result();
  187. res.setData(customerService.findCustomerContacts(uid));
  188. return res;
  189. }
  190. /** 进入添加拜访记录 **/
  191. @RequestMapping(value = "/toAddFollow", method = RequestMethod.GET)
  192. public Result toAddFollow(String uid){
  193. Result res = new Result();
  194. if(StringUtils.isBlank(uid)){
  195. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  196. return res;
  197. }
  198. User user = customerService.findUserAccountDetail(uid);
  199. FollowBusinessBo fbb = new FollowBusinessBo();
  200. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  201. fbb.setFollowTime(format.format(new Date()));
  202. fbb.setIdentifyName(user.getIdentifyName());
  203. fbb.setUid(uid);
  204. fbb.setUserBusinessList(businessService.findBusinessByUAid(uid, TokenManager.getAdminId()));
  205. res.setData(fbb);
  206. return res;
  207. }
  208. /** 添加拜访记录
  209. * @throws ParseException
  210. * @throws Exception **/
  211. @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
  212. public Result addFollow(String userBusinessList,String uid,String ocbId,String contactType,String result,String followTime) throws BusinessException{
  213. Result res = new Result();
  214. if(StringUtils.isBlank(uid) || StringUtils.isBlank(ocbId)){
  215. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  216. return res;
  217. }
  218. JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
  219. List<UserBusiness> list = new ArrayList<UserBusiness>();
  220. if (ja != null && !ja.isEmpty()) {
  221. UserBusiness userBusiness = null;
  222. for (int idx = 0; idx < ja.size(); idx++) {
  223. userBusiness = ja.getJSONObject(idx).toJavaObject(UserBusiness.class);
  224. for(UserBusiness ub:list){
  225. if(ub.getBusinessGlossoryId() == userBusiness.getBusinessGlossoryId()){
  226. res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
  227. return res;
  228. }
  229. }
  230. list.add(userBusiness);
  231. }
  232. }
  233. FollowBusinessBo fbb = new FollowBusinessBo();
  234. fbb.setOcbId(ocbId);
  235. fbb.setUid(uid);
  236. fbb.setContactType(contactType);
  237. fbb.setResult(result);
  238. fbb.setFollowTime(followTime);
  239. fbb.setUserBusinessList(list);
  240. customerService.addFollow(fbb);
  241. return res;
  242. }
  243. /** 进入修改拜访记录 **/
  244. @RequestMapping(value = "/toUpdateFollow", method = RequestMethod.GET)
  245. public Result toUpdateFollow(String followId){
  246. Result res = new Result();
  247. FollowBusinessBo fbb = customerService.findFollowById(followId);
  248. fbb.setUserBusinessList(customerService.findBusinessByFollowId(followId));
  249. res.setData(fbb);
  250. return res;
  251. }
  252. /** 修改拜访记录
  253. * @throws ParseException
  254. * @throws BusinessException
  255. */
  256. @RequestMapping(value = "/updateFollow", method = RequestMethod.POST)
  257. public Result updateFollow(String userBusinessList,String followId,String followTime,String uid,String contactType,String result) throws BusinessException{
  258. Result res = new Result();
  259. if(StringUtils.isBlank(uid) || StringUtils.isBlank(followId)){
  260. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  261. return res;
  262. }
  263. JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
  264. List<UserBusiness> list = new ArrayList<UserBusiness>();
  265. if (ja != null && !ja.isEmpty()) {
  266. UserBusiness userBusiness = null;
  267. for (int idx = 0; idx < ja.size(); idx++) {
  268. userBusiness = ja.getJSONObject(idx).toJavaObject(UserBusiness.class);
  269. for(UserBusiness ub:list){
  270. if(ub.getBusinessGlossoryId() == userBusiness.getBusinessGlossoryId()){
  271. res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
  272. return res;
  273. }
  274. }
  275. list.add(userBusiness);
  276. }
  277. }
  278. FollowBusinessBo fbb = new FollowBusinessBo();
  279. fbb.setFollowTime(followTime);
  280. fbb.setUid(uid);
  281. fbb.setContactType(contactType);
  282. fbb.setResult(result);
  283. fbb.setUserBusinessList(list);
  284. fbb.setFollowId(followId);
  285. customerService.updateFollow(fbb);
  286. return res;
  287. }
  288. /** 删除跟进记录 **/
  289. @RequestMapping(value = "/deleteFollow", method = RequestMethod.GET)
  290. public Result deleteFollow(String followId){
  291. Result res = new Result();
  292. if(StringUtils.isBlank(followId)){
  293. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  294. return res;
  295. }
  296. customerService.deleteFollow(followId);
  297. return res;
  298. }
  299. /** 查询客户的所有联系人 **/
  300. @RequestMapping(value = "/findAllContacts", method = RequestMethod.GET)
  301. public Result findAllContacts(String uid){
  302. Result res = new Result();
  303. res.setData(customerService.findAllContacts(uid));
  304. return res;
  305. }
  306. /** 修改企业联系人 **/
  307. @RequestMapping(value = "/updateCustomerContacts", method = RequestMethod.POST)
  308. public Result updateCustomerContacts(String contactList,String uid){
  309. Result res = new Result();
  310. if(StringUtils.isBlank(uid)){
  311. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  312. return res;
  313. }
  314. JSONArray ja = (JSONArray) JSON.parse(contactList);
  315. List<OrganizationContactBook> ocbList = new ArrayList<OrganizationContactBook>();
  316. OrganizationContactBook ocb = null;
  317. if(ja != null & !ja.isEmpty()){
  318. for (int idx = 0; idx < ja.size(); idx++) {
  319. ocb = ja.getJSONObject(idx).toJavaObject(OrganizationContactBook.class);
  320. if(StringUtils.isBlank(ocb.getMobile()) || StringUtils.isBlank(ocb.getName())){
  321. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名和手机号码为必填"));
  322. return res;
  323. }
  324. if(StringUtils.isBlank(ocb.getUid())) ocb.setUid(uid);
  325. ocbList.add(ocb);
  326. }
  327. }
  328. customerService.updateCustomerContacts(ocbList,uid);
  329. return res;
  330. }
  331. /** 领取客户 **/
  332. @RequestMapping(value = "/receiveCustomer", method = RequestMethod.GET)
  333. public Result receiveCustomer(String uid){
  334. Result res = new Result();
  335. if(StringUtils.isBlank(uid)){
  336. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  337. return res;
  338. }
  339. customerService.updateByOperatorType(uid, AFTConstants.USER_RECEIVE);
  340. return res;
  341. }
  342. /** 删除客户 **/
  343. @RequestMapping(value = "/deleteCustomer", method = RequestMethod.GET)
  344. public Result deleteCustomer(String uid){
  345. Result res = new Result();
  346. if(StringUtils.isBlank(uid)){
  347. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  348. return res;
  349. }
  350. customerService.updateByOperatorType(uid, AFTConstants.USER_DELETE);
  351. return res;
  352. }
  353. /**
  354. * 上传excel文档
  355. * @param req
  356. * @return
  357. */
  358. @RequestMapping(value = "/uploadExcel",method = RequestMethod.POST)
  359. public Result uploadExcel(HttpServletRequest req){
  360. Result res = new Result();
  361. String excelPath = handleFile(res, "/customer_sys_file/", true, req, "");
  362. ExcelUtils utils = new ExcelUtils();
  363. Set<CustomerExcelBo> boSet;
  364. try {
  365. boSet = utils.parseExcel(uploadPrivatePath + excelPath);
  366. String errorMessage = "";
  367. if(boSet.size()>100) errorMessage += "导入数据不能超过一百条;";
  368. errorMessage += utils.getVacantRows();
  369. if(StringUtils.isNotBlank(errorMessage)) {
  370. res.getError().add(new Error(errorMessage));
  371. return res;
  372. }
  373. Set<Integer> existRows = new TreeSet<Integer>(); //数据库已存在
  374. Set<Integer> filterRows = new TreeSet<Integer>(); //过滤提示
  375. customerService.checkCustomer(boSet,existRows,filterRows);
  376. if(existRows.size()>0){
  377. errorMessage = StringUtils.join(existRows.toArray(),",")+ " 行客户业务已存在;";
  378. res.getError().add(new Error(errorMessage));
  379. return res;
  380. }
  381. if(filterRows.size()>0){
  382. errorMessage = StringUtils.join(filterRows.toArray(),",")+ " 行已经被系统过滤;";
  383. res.getError().add(new Error(errorMessage));
  384. return res;
  385. }
  386. customerService.saveUploadData(boSet);
  387. } catch (IOException e) {
  388. e.printStackTrace();
  389. }
  390. return res;
  391. }
  392. /**
  393. * 下载科技成果批量导入Excel模板
  394. */
  395. @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
  396. public Result downloadTemplateFile(HttpServletResponse response,String type) {
  397. Result res = new Result();
  398. if(AFTConstants.USER_TYPE_ORGANIZATION.equals(type)){
  399. AftFile af = aftFileService.selectAftFileBySign("organization_customer_template");
  400. if (null == af) {
  401. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  402. } else {
  403. String path = af.getFilePath();
  404. String suffix = path.substring(path.lastIndexOf("."));
  405. String fileName = af.getFileName() + suffix;
  406. downloadFile(response, fileName, path);
  407. }
  408. }else if(AFTConstants.USER_TYPE_PERSONAL.equals(type)){
  409. AftFile af = aftFileService.selectAftFileBySign("personal_customer_template");
  410. if (null == af) {
  411. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  412. } else {
  413. String path = af.getFilePath();
  414. String suffix = path.substring(path.lastIndexOf("."));
  415. String fileName = af.getFileName() + suffix;
  416. downloadFile(response, fileName, path);
  417. }
  418. }
  419. return res;
  420. }
  421. /** 转为公共客户 **/
  422. @RequestMapping(value = "/transferToPublic", method = RequestMethod.GET)
  423. public Result transferToPublic(String uid){
  424. Result res = new Result();
  425. if(StringUtils.isBlank(uid)){
  426. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  427. }
  428. customerService.updateByOperatorType(uid, AFTConstants.USER_TRANSFER_TO_PUBLIC);
  429. return res;
  430. }
  431. }