AdminCustomerApiController.java 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. package com.goafanti.customer.controller;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.lang.reflect.InvocationTargetException;
  5. import java.text.DateFormat;
  6. import java.text.ParseException;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Arrays;
  10. import java.util.Calendar;
  11. import java.util.Date;
  12. import java.util.List;
  13. import java.util.Set;
  14. import java.util.TreeSet;
  15. import javax.annotation.Resource;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import com.goafanti.common.utils.*;
  19. import com.goafanti.core.mybatis.page.Pagination;
  20. import com.goafanti.customer.bo.*;
  21. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  22. import org.springframework.beans.factory.annotation.Value;
  23. import org.springframework.validation.BindingResult;
  24. import org.springframework.validation.annotation.Validated;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestMethod;
  27. import org.springframework.web.bind.annotation.RestController;
  28. import com.alibaba.fastjson.JSON;
  29. import com.alibaba.fastjson.JSONArray;
  30. import com.goafanti.admin.service.AdminService;
  31. import com.goafanti.admin.service.AttachmentService;
  32. import com.goafanti.common.bo.Error;
  33. import com.goafanti.common.bo.Result;
  34. import com.goafanti.common.constant.AFTConstants;
  35. import com.goafanti.common.constant.ErrorConstants;
  36. import com.goafanti.common.controller.BaseApiController;
  37. import com.goafanti.common.enums.AttachmentType;
  38. import com.goafanti.common.error.BusinessException;
  39. import com.goafanti.common.model.Attachment;
  40. import com.goafanti.common.model.OrganizationContactBook;
  41. import com.goafanti.common.model.User;
  42. import com.goafanti.core.shiro.token.TokenManager;
  43. import com.goafanti.customer.service.CustomerService;
  44. @RestController
  45. @RequestMapping("/api/admin/customer")
  46. public class AdminCustomerApiController extends BaseApiController{
  47. @Resource
  48. private CustomerService customerService;
  49. @Resource
  50. private AttachmentService aftFileService;
  51. @Value(value = "${upload.private.path}")
  52. private String uploadPrivatePath = null;
  53. @Value(value = "${user.receive.max}")
  54. private Integer USER_RECEIVE_MAX = null;
  55. @Resource
  56. private AdminService adminService;
  57. @Value(value = "${aesSecretKey}")
  58. private String secretKey = null;
  59. /** 私有个人客户列表 **/
  60. @RequestMapping(value = "/listPrivatePersonalCustomer" , method = RequestMethod.POST)
  61. public Result listPrivatePersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  62. Result res = new Result();
  63. res.setData(customerService.listPrivatePersonalCustomer(cli, pageNo, pageSize));
  64. return res;
  65. }
  66. /** 公共个人客户列表 **/
  67. @RequestMapping(value = "/listPublicPersonalCustomer" , method = RequestMethod.POST)
  68. public Result listPublicPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  69. Result res = new Result();
  70. res.setData(customerService.listPublicPersonalCustomer(cli, pageNo, pageSize));
  71. return res;
  72. }
  73. /** 个人客户查询 **/
  74. @RequestMapping(value = "/listAllPersonalCustomer" , method = RequestMethod.POST)
  75. public Result listAllPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  76. Result res = new Result();
  77. res.setData(customerService.listAllPersonalCustomer(cli, pageNo, pageSize));
  78. return res;
  79. }
  80. /** 签单的个人客户 **/
  81. @RequestMapping(value = "/listSignPersonalCustomer", method = RequestMethod.POST)
  82. public Result listSignPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  83. Result res = new Result();
  84. res.setData(customerService.listSignPersonalCustomer(cli, pageNo, pageSize));
  85. return res;
  86. }
  87. /** 管理个人客户查询 **/
  88. @RequestMapping(value = "/listAllManagePersonalCustomer" , method = RequestMethod.POST)
  89. public Result listAllManagePersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  90. Result res = new Result();
  91. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN) && !TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)){
  92. cli.setAid(TokenManager.getAdminId());
  93. }
  94. res.setData(customerService.listAllManagePersonalCustomer(cli, pageNo, pageSize));
  95. return res;
  96. }
  97. /** 专家查询 **/
  98. @RequestMapping(value = "/listExpertCustomer" , method = RequestMethod.POST)
  99. public Result listExpertCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  100. Result res = new Result();
  101. res.setData(customerService.listAllManagePersonalCustomer(cli, pageNo, pageSize));
  102. return res;
  103. }
  104. /** 个人客户详情信息 **/
  105. @RequestMapping(value = "/findPersonalCustomerDetail" ,method = RequestMethod.GET)
  106. public Result findPersonalCustomerDetail(String uid){
  107. Result res = new Result();
  108. res.setData(customerService.findPersonalCustomerDetail(uid));
  109. return res;
  110. }
  111. /**
  112. * 私有单位客户列表
  113. * 私有客户列表
  114. **/
  115. @RequestMapping(value = "/listPrivateOrganizationCustomer" , method = RequestMethod.POST)
  116. public Result listPrivateOrganizationCustomer(CustomerListIn cli ,Integer sort,Integer sortType,Integer pageNo, Integer pageSize){
  117. Result res = new Result();
  118. //
  119. res.setData(customerService.listPrivateOrganizationCustomer(cli, sort, sortType, 0, pageNo, pageSize));
  120. return res;
  121. }
  122. /**
  123. * 私有渠道客户列表
  124. *
  125. **/
  126. @RequestMapping(value = "/channelUserList" , method = RequestMethod.GET)
  127. public Result channelUserList(InputChannelListBo in ){
  128. Result res = new Result();
  129. in.setNewChannel(1);
  130. in.setShareType(0);
  131. res.setData(customerService.channelUserList(in));
  132. return res;
  133. }
  134. /**
  135. * 公共渠道客户列表
  136. *
  137. **/
  138. @RequestMapping(value = "/publicChannelUserList" , method = RequestMethod.GET)
  139. public Result publicChannelUserList(InputChannelListBo in ){
  140. Result res = new Result();
  141. in.setNewChannel(1);
  142. //获取公共
  143. in.setShareType(1);
  144. res.setData(customerService.channelUserList(in));
  145. return res;
  146. }
  147. /**
  148. * 渠道客户查询
  149. *
  150. **/
  151. @RequestMapping(value = "/selectChannelUserList" , method = RequestMethod.GET)
  152. public Result selectChannelUserList(InputChannelListBo in ){
  153. Result res = new Result();
  154. in.setNewChannel(1);
  155. if (in.getName()==null||in.getName().length()<2){
  156. res.getError().add(buildError("搜索名字必须大于2个字符"));
  157. return res;
  158. }
  159. res.setData(customerService.selectChannelUserList(in));
  160. return res;
  161. }
  162. /** 跟进管理列表
  163. * 跟进列表
  164. **/
  165. @RequestMapping(value = "/listFollowManagement" , method = RequestMethod.GET)
  166. public Result listFollowManagement(CustomerListIn cli ,Integer sort,Integer sortType,Integer pageNo, Integer pageSize){
  167. Result res = new Result();
  168. res.setData(customerService.listPrivateOrganizationCustomer(cli, sort, sortType, 1, pageNo, pageSize));
  169. return res;
  170. }
  171. /**
  172. * 私有单位客户导出xls
  173. * @throws IOException
  174. */
  175. @RequestMapping(value = "/privateUnitCustomerOutXls" , method = RequestMethod.GET)
  176. public Result privateUnitCustomerOutXls(CustomerListIn cli ,Integer sort,Integer sortType,Integer pageNo, Integer pageSize,HttpServletResponse response) throws IOException{
  177. Result res = new Result();
  178. XSSFWorkbook wb = customerService.privateUnitCustomerOutXls(cli, sort, sortType, pageNo, pageSize);
  179. String fileName = "我的客户列表 " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + ".xls";
  180. OutputStream out = null;
  181. try {
  182. out = response.getOutputStream();
  183. } catch (IOException e) {
  184. e.printStackTrace();
  185. }
  186. response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
  187. response.setContentType("application/octet-stream;charset=utf-8");
  188. try {
  189. // 返回数据流
  190. wb.write(out);
  191. out.flush();
  192. out.close();
  193. } finally {
  194. out.flush();
  195. out.close();
  196. }
  197. return res;
  198. }
  199. /** 公共单位客户列表 **/
  200. @RequestMapping(value = "/listPublicOrganizationCustomer" , method = RequestMethod.POST)
  201. public Result listPublicOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  202. Result res = new Result();
  203. res.setData(customerService.listPublicOrganizationCustomer(cli, pageNo, pageSize));
  204. return res;
  205. }
  206. /** 单位客户查询 **/
  207. @RequestMapping(value = "/listAllOrganizationCustomer" , method = RequestMethod.POST)
  208. public Result listAllOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  209. Result res = new Result();
  210. if (StringUtils.isBlank(cli.getName())){
  211. res.setData( new Pagination<>());
  212. return res;
  213. }
  214. res.setData(customerService.listAllOrganizationCustomer(cli, pageNo, pageSize));
  215. return res;
  216. }
  217. /** 管理单位客户查询 **/
  218. @RequestMapping(value = "/listAllManageOrganizationCustomer" , method = RequestMethod.POST)
  219. public Result listAllManageOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  220. Result res = new Result();
  221. res.setData(customerService.listAllManageOrganizationCustomer(cli, pageNo, pageSize));
  222. return res;
  223. }
  224. /** 签单的单位客户 **/
  225. @RequestMapping(value = "/listSignOrganizationCustomer", method = RequestMethod.POST)
  226. public Result listSignOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
  227. Result res = new Result();
  228. res.setData(customerService.listSignOrganizationCustomer(cli, pageNo, pageSize));
  229. return res;
  230. }
  231. /** 签单客户转交 **/
  232. @RequestMapping(value = "/customerHandOver", method = RequestMethod.POST)
  233. public Result listSignPersonalCustomer(String userIds ,String receiveId){
  234. Result res = new Result();
  235. res.setData(customerService.customerHandOver( userIds , receiveId));
  236. return res;
  237. }
  238. /** 客户即时检索 **/
  239. @RequestMapping(value = "/findCustomerByName",method = RequestMethod.GET)
  240. public Result findCustomerByName(String name){
  241. Result res = new Result();
  242. res.setData(customerService.findCustomerByName(name));
  243. return res;
  244. }
  245. /** 客户即时检索(可签单客户) **/
  246. @RequestMapping(value = "/getCustomerByName",method = RequestMethod.GET)
  247. public Result getCustomerByName(String name,Integer type){
  248. Result res = new Result();
  249. if(type == null){
  250. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  251. return res;
  252. }
  253. if(name.length()<2) return res;
  254. if(type == 0) res.setData(customerService.getPrivateCustomerByName(name));
  255. if(type == 1) res.setData(customerService.getSignedCustomerByName(name));
  256. if(type == 2) res.setData(customerService.getChannelCustomerByName(name));
  257. return res;
  258. }
  259. /** 客户查询 **/
  260. @RequestMapping(value = "/getUserByName",method = RequestMethod.GET)
  261. public Result getUserByName(String name){
  262. Result res = new Result();
  263. if(StringUtils.isEmpty(name)){
  264. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称","名称"));
  265. return res;
  266. }
  267. if(name.length()<2) return res;
  268. res.data(customerService.getUserByName(name));
  269. return res;
  270. }
  271. /**
  272. * 客户查询
  273. * @param name 查询名称
  274. * @param type 分类 0默认 1小程序App
  275. * @param pageNo
  276. * @param pageSize
  277. * @return
  278. */
  279. @RequestMapping(value = "/getUserByNames",method = RequestMethod.GET)
  280. public Result getUserByName(String name,Integer type,Integer pageNo,Integer pageSize){
  281. Result res = new Result();
  282. if(StringUtils.isEmpty(name)){
  283. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称","名称"));
  284. return res;
  285. }
  286. if(name.length()<2) return res;
  287. res.data(customerService.getUserByNames(name,type,pageNo,pageSize));
  288. return res;
  289. }
  290. /** 添加客户基本信息
  291. * @throws Exception
  292. * @throws NumberFormatException **/
  293. @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
  294. public Result addCustomer(InputAddCustomer in) {
  295. Result res = new Result();
  296. if(StringUtils.isBlank(in.getName()) || StringUtils.isBlank(in.getContacts())
  297. || StringUtils.isBlank(in.getContactMobile()) ||null==in.getProvince()||null==in.getCity()||null==in.getArea()
  298. || StringUtils.isBlank(in.getBusinessScope())||null==in.getOrgCode()
  299. || StringUtils.isBlank(in.getIntendedProject())){
  300. res.getError().add(buildError("","创建客户参数不全"));
  301. return res;
  302. }
  303. if (customerService.checkMax(null,TokenManager.getAdminId())) {
  304. res.getError().add(buildError("","私有客户已达最大限制"));
  305. return res;
  306. }
  307. if (customerService.checkOrgCode(in.getOrgCode())){
  308. res.getError().add(buildError("","统一信用代码已存在"));
  309. return res;
  310. }
  311. //新增为私有客户
  312. in.setShareType(0);
  313. //将新增客户的空格去除
  314. res.data(customerService.addCustomer(in));
  315. return res;
  316. }
  317. @RequestMapping(value = "/addChannel", method = RequestMethod.POST)
  318. public Result addChannel(@Validated InputAddCustomer in, BindingResult bindingResult) {
  319. Result res = new Result();
  320. if (bindingResult.hasErrors()) {
  321. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  322. ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
  323. return res;
  324. }
  325. if (customerService.checkUserName(in.getName())){
  326. res.getError().add(buildError("客户名称已存在"));
  327. return res;
  328. }
  329. in.setType(1);
  330. //新增为私有客户
  331. in.setShareType(0);
  332. in.setNewChannel(1);
  333. //将新增客户的空格去除
  334. res.data(customerService.addCustomer(in));
  335. return res;
  336. }
  337. /** 单位客户详情信息 **/
  338. @RequestMapping(value = "/findOrganizationCustomerDetail", method = RequestMethod.GET)
  339. public Result findOrganizationCustomerDetail(String uid){
  340. Result res = new Result();
  341. res.setData(customerService.findOrganizationCustomerDetail(uid));
  342. return res;
  343. }
  344. /** 修改单位客户信息 **/
  345. @RequestMapping(value = "/updateOrganizationCustomer", method = RequestMethod.POST)
  346. public Result updateOrganizationCustomer(CustomerOrganizationDetailBo bo){
  347. Result res = new Result();
  348. if(StringUtils.isBlank(bo.getId()) || StringUtils.isBlank(bo.getUid())){
  349. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  350. return res;
  351. }
  352. customerService.updateOrganizationCustomer(bo);
  353. return res;
  354. }
  355. /** 修改个人客户信息 **/
  356. @RequestMapping(value = "/updatePersonalCustomer", method = RequestMethod.POST)
  357. public Result updatePersonalCustomer(CustomerPersonalDetailBo bo){
  358. Result res = new Result();
  359. if(StringUtils.isBlank(bo.getUid()) || StringUtils.isBlank(bo.getId())){
  360. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  361. return res;
  362. }
  363. customerService.updatePersonalCustomer(bo);
  364. return res;
  365. }
  366. /** 查看跟进记录 **/
  367. @RequestMapping(value = "/listFollowHistory", method = RequestMethod.GET)
  368. public Result listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessProjectId,Integer type){
  369. Result res = new Result();
  370. res.setData(customerService.listFollowHistory(pageNo,pageSize,uid,businessProjectId,type));
  371. return res;
  372. }
  373. /** 指导已读 **/
  374. @RequestMapping(value = "/pushGuidance", method = RequestMethod.POST)
  375. public Result pushGuidance(String uid){
  376. Result res = new Result();
  377. if (StringUtils.isBlank(uid)) {
  378. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户编号"));
  379. return res;
  380. }
  381. res.setData(customerService.pushGuidance(uid));
  382. return res;
  383. }
  384. /** 新增指导意见 **/
  385. @RequestMapping(value = "/addGuidance", method = RequestMethod.POST)
  386. public Result addGuidance(String followId,String guidance){
  387. Result res = new Result();
  388. if (StringUtils.isBlank(followId)||StringUtils.isBlank(guidance)) {
  389. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号、指导意见","编号、指导意见"));
  390. return res;
  391. }
  392. res.setData(customerService.addGuidance( followId, guidance));
  393. return res;
  394. }
  395. /** 查看客户账户信息 **/
  396. @RequestMapping(value = "/findUserAccountDetail", method = RequestMethod.GET)
  397. public Result findUserAcountDetail(String uid){
  398. Result res = new Result();
  399. UserDetailBo bo = new UserDetailBo();
  400. User user = customerService.findUserAccountDetail(uid);
  401. try {
  402. BeanUtilsExt.copyProperties(bo, user);
  403. } catch (InvocationTargetException | IllegalAccessException e) {
  404. e.printStackTrace();
  405. }
  406. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  407. bo.setCreateTimes(format.format(user.getCreateTime()));
  408. res.setData(bo);
  409. return res;
  410. }
  411. /** 修改客户账户信息 **/
  412. @RequestMapping(value = "/updateUserAccount", method = RequestMethod.POST)
  413. public Result updateUserAccount(User user){
  414. Result res = new Result();
  415. customerService.updateUserAccount(user);
  416. return res;
  417. }
  418. /** 查看客户联系人列表 **/
  419. @RequestMapping(value = "/findCustomerContacts", method = RequestMethod.GET)
  420. public Result findCustomerContacts(String uid){
  421. Result res = new Result();
  422. res.setData(customerService.findCustomerContacts(uid));
  423. return res;
  424. }
  425. /** 针对已作拜访的业务作跟进 **/
  426. @RequestMapping(value = "/toAddFollowOnHistory", method = RequestMethod.GET)
  427. public Result toAddFollowOnHistory(String uid){
  428. Result res = new Result();
  429. if(StringUtils.isBlank(uid)){
  430. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  431. return res;
  432. }
  433. User user = customerService.findUserAccountDetail(uid);
  434. FollowBusinessBo fbb = new FollowBusinessBo();
  435. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  436. fbb.setFollowTime(format.format(new Date()));
  437. fbb.setIdentifyName(user.getIdentifyName());
  438. fbb.setUid(uid);
  439. fbb.setUserBusinessList(customerService.findBusinessByUAid(uid, TokenManager.getAdminId()));
  440. res.setData(fbb);
  441. return res;
  442. }
  443. /** 针对已锁定的业务作跟进 **/
  444. @RequestMapping(value = "/toAddFollowOnLock", method = RequestMethod.GET)
  445. public Result toAddFollowOnLock(String uid){
  446. Result res = new Result();
  447. if(StringUtils.isBlank(uid)){
  448. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  449. return res;
  450. }
  451. User user = customerService.findUserAccountDetail(uid);
  452. FollowBusinessBo fbb = new FollowBusinessBo();
  453. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  454. fbb.setFollowTime(format.format(new Date()));
  455. fbb.setIdentifyName(user.getIdentifyName());
  456. fbb.setUid(uid);
  457. fbb.setUserBusinessList(customerService.findLockedBusinessByUAid(uid, TokenManager.getAdminId()));
  458. res.setData(fbb);
  459. return res;
  460. }
  461. /** 添加拜访记录、客户跟进
  462. * @throws ParseException
  463. * @throws Exception **/
  464. @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
  465. public Result addFollow(String userBusinessList,String uid,String ocbId,String contactType,String result,String followTime) throws BusinessException{
  466. Result res = new Result();
  467. if(StringUtils.isBlank(uid) || StringUtils.isBlank(ocbId)){
  468. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  469. return res;
  470. }
  471. JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
  472. List<BusinessListBo> list = new ArrayList<BusinessListBo>();
  473. if (ja != null && !ja.isEmpty()) {
  474. BusinessListBo userBusiness = null;
  475. for (int idx = 0; idx < ja.size(); idx++) {
  476. userBusiness = ja.getJSONObject(idx).toJavaObject(BusinessListBo.class);
  477. for(BusinessListBo ub:list){
  478. if(ub.getBusinessProjectId() == userBusiness.getBusinessProjectId()){
  479. res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
  480. return res;
  481. }
  482. }
  483. list.add(userBusiness);
  484. }
  485. }
  486. FollowBusinessBo fbb = new FollowBusinessBo();
  487. fbb.setOcbId(ocbId);
  488. fbb.setUid(uid);
  489. fbb.setContactType(contactType);
  490. fbb.setResult(result);
  491. fbb.setFollowTime(followTime);
  492. fbb.setUserBusinessList(list);
  493. customerService.addFollow(fbb,null,1);
  494. return res;
  495. }
  496. /** 进入修改拜访记录 **/
  497. @RequestMapping(value = "/toUpdateFollow", method = RequestMethod.GET)
  498. public Result toUpdateFollow(String followId){
  499. Result res = new Result();
  500. FollowBusinessBo fbb = customerService.findFollowById(followId);
  501. fbb.setUserBusinessList(customerService.findBusinessByFollowId(followId));
  502. res.setData(fbb);
  503. return res;
  504. }
  505. /** 修改拜访记录
  506. * @throws ParseException
  507. * @throws BusinessException
  508. */
  509. @RequestMapping(value = "/updateFollow", method = RequestMethod.POST)
  510. public Result updateFollow(String userBusinessList,String followId,String followTime,String uid,String contactType,String result) throws BusinessException{
  511. Result res = new Result();
  512. if(StringUtils.isBlank(uid) || StringUtils.isBlank(followId)){
  513. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  514. return res;
  515. }
  516. JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
  517. List<BusinessListBo> list = new ArrayList<BusinessListBo>();
  518. if (ja != null && !ja.isEmpty()) {
  519. BusinessListBo userBusiness = null;
  520. for (int idx = 0; idx < ja.size(); idx++) {
  521. userBusiness = ja.getJSONObject(idx).toJavaObject(BusinessListBo.class);
  522. for(BusinessListBo ub:list){
  523. if(ub.getBusinessProjectId() == userBusiness.getBusinessProjectId()){
  524. res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
  525. return res;
  526. }
  527. }
  528. list.add(userBusiness);
  529. }
  530. }
  531. FollowBusinessBo fbb = new FollowBusinessBo();
  532. fbb.setFollowTime(followTime);
  533. fbb.setUid(uid);
  534. fbb.setContactType(contactType);
  535. fbb.setResult(result);
  536. fbb.setUserBusinessList(list);
  537. fbb.setFollowId(followId);
  538. customerService.updateFollow(fbb);
  539. return res;
  540. }
  541. /** 删除跟进记录 **/
  542. @RequestMapping(value = "/deleteFollow", method = RequestMethod.GET)
  543. public Result deleteFollow(String followId){
  544. Result res = new Result();
  545. if(StringUtils.isBlank(followId)){
  546. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  547. return res;
  548. }
  549. customerService.deleteFollow(followId);
  550. return res;
  551. }
  552. /** 查询客户的所有联系人 **/
  553. @RequestMapping(value = "/findAllContacts", method = RequestMethod.GET)
  554. public Result findAllContacts(String uid){
  555. Result res = new Result();
  556. res.setData(customerService.findAllContacts(uid));
  557. return res;
  558. }
  559. /** 修改企业联系人 **/
  560. @RequestMapping(value = "/updateCustomerContacts", method = RequestMethod.POST)
  561. public Result updateCustomerContacts(String contactList,String uid){
  562. Result res = new Result();
  563. if(StringUtils.isBlank(uid)){
  564. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  565. return res;
  566. }
  567. JSONArray ja = (JSONArray) JSON.parse(contactList);
  568. List<OrganizationContactBook> ocbList = new ArrayList<OrganizationContactBook>();
  569. OrganizationContactBook ocb = null;
  570. if(ja != null & !ja.isEmpty()){
  571. for (int idx = 0; idx < ja.size(); idx++) {
  572. ocb = ja.getJSONObject(idx).toJavaObject(OrganizationContactBook.class);
  573. if(StringUtils.isBlank(ocb.getMobile()) || StringUtils.isBlank(ocb.getName())){
  574. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名和手机号码为必填"));
  575. return res;
  576. }
  577. if(StringUtils.isBlank(ocb.getUid())) ocb.setUid(uid);
  578. ocbList.add(ocb);
  579. }
  580. }
  581. customerService.updateCustomerContacts(ocbList,uid);
  582. return res;
  583. }
  584. /**
  585. * 领取客户
  586. * @param uid 客户编号
  587. * @param oldAid 原来的客户归属人
  588. * @return
  589. */
  590. @RequestMapping(value = "/receiveCustomer", method = RequestMethod.GET)
  591. public Result receiveCustomer(String uid, String oldAid) {
  592. Result res = new Result();
  593. if (StringUtils.isBlank(uid) || StringUtils.isBlank("oldAid")) {
  594. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  595. return res;
  596. }
  597. Integer check =customerService.receiveEveryDay(uid);
  598. if (check!=0){
  599. if (check==-1){
  600. res.getError().add(buildError(ErrorConstants.CUSTOMER_ALREADY_RECEIVE));
  601. return res;
  602. }else if (check==-2){
  603. res.getError().add(buildError(ErrorConstants.CUSTOM_EREXCESS, USER_RECEIVE_MAX.toString(),USER_RECEIVE_MAX.toString()));
  604. return res;
  605. }else if (check==-3){
  606. res.getError().add(buildError("", "私有客户已达最大限制"));
  607. return res;
  608. }else if (check==-4){
  609. res.getError().add(buildError("", "外联客户丢失后不可再领取"));
  610. return res;
  611. }else {
  612. res.getError().add(buildError("领取参数异常,请联系管理员"));
  613. return res;
  614. }
  615. }
  616. customerService.updateByOperatorType(uid, null, oldAid, AFTConstants.USER_RECEIVE, null);
  617. return res;
  618. }
  619. /**
  620. * 领取为渠道
  621. * @param uid
  622. * @return
  623. */
  624. @RequestMapping(value = "/receiveAsChannel",method=RequestMethod.POST)
  625. public Result receiveAsChannel(String uid){
  626. Result res = new Result();
  627. if (uid ==null ){
  628. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"客户"));
  629. return res;
  630. }
  631. res.data(customerService.pushReceiveAsChannel(uid));
  632. return res;
  633. }
  634. /**
  635. * 上传excel文档
  636. * @param req
  637. * @return
  638. */
  639. @RequestMapping(value = "/uploadExcel",method = RequestMethod.POST)
  640. public Result uploadExcel(HttpServletRequest req){
  641. Result res = new Result();
  642. String excelPath = handleFile(res, "/customer_sys_file/", true, req, "");
  643. ExcelUtils utils = new ExcelUtils();
  644. Set<CustomerExcelBo> boSet;
  645. try {
  646. boSet = utils.parseExcel(uploadPrivatePath + excelPath);
  647. String errorMessage = "";
  648. if(boSet.size()>100) errorMessage += "导入数据不能超过一百条;";
  649. errorMessage += utils.getVacantRows();
  650. if(StringUtils.isNotBlank(errorMessage)) {
  651. res.getError().add(new Error(errorMessage));
  652. return res;
  653. }
  654. Set<Integer> existRows = new TreeSet<Integer>(); //数据库已存在
  655. Set<Integer> filterRows = new TreeSet<Integer>(); //过滤提示
  656. customerService.checkCustomer(boSet,existRows,filterRows);
  657. if(existRows.size()>0){
  658. errorMessage = StringUtils.join(existRows.toArray(),",")+ " 行客户业务已存在;";
  659. res.getError().add(new Error(errorMessage));
  660. return res;
  661. }
  662. if(filterRows.size()>0){
  663. errorMessage = StringUtils.join(filterRows.toArray(),",")+ " 行已经被系统过滤;";
  664. res.getError().add(new Error(errorMessage));
  665. return res;
  666. }
  667. customerService.saveUploadData(boSet);
  668. } catch (IOException e) {
  669. e.printStackTrace();
  670. }
  671. return res;
  672. }
  673. /**
  674. * 下载科技成果批量导入Excel模板
  675. */
  676. @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
  677. public Result downloadTemplateFile(HttpServletResponse response,String type) {
  678. Result res = new Result();
  679. if(AFTConstants.USER_TYPE_ORGANIZATION.equals(type)){
  680. Attachment af = aftFileService.selectAftFileBySign("organization_customer_template");
  681. if (null == af) {
  682. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  683. } else {
  684. String path = af.getFilePath();
  685. String suffix = path.substring(path.lastIndexOf("."));
  686. String fileName = af.getFileName() + suffix;
  687. downloadFile(response, fileName, path);
  688. }
  689. }else if(AFTConstants.USER_TYPE_PERSONAL.equals(type)){
  690. Attachment af = aftFileService.selectAftFileBySign("personal_customer_template");
  691. if (null == af) {
  692. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
  693. } else {
  694. String path = af.getFilePath();
  695. String suffix = path.substring(path.lastIndexOf("."));
  696. String fileName = af.getFileName() + suffix;
  697. downloadFile(response, fileName, path);
  698. }
  699. }
  700. return res;
  701. }
  702. /** 转为公共客户 **/
  703. @RequestMapping(value = "/transferToPublic", method = RequestMethod.GET)
  704. public Result transferToPublic(String uid,String aid){
  705. Result res = new Result();
  706. if(StringUtils.isBlank(uid) || StringUtils.isBlank("aid")){
  707. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  708. }
  709. customerService.updateByOperatorType(uid, aid,null, AFTConstants.USER_TRANSFER_TO_PUBLIC,null);
  710. return res;
  711. }
  712. /** 图片上传 **/
  713. @RequestMapping(value = "/uploadCustomerImg", method = RequestMethod.POST)
  714. public Result uploadCustomerImg(HttpServletRequest req,String sign){
  715. Result res = new Result();
  716. res.setData(handleFile(res, "/customer_sys_file/", false, req, sign));
  717. return res;
  718. }
  719. /**
  720. *
  721. * @param startDate 开始日期
  722. * @param endDate 结束日期
  723. * @param timeSpan 时间差
  724. * @param depNo 部门编号
  725. * @param pageNo 页码
  726. * @param pageSize 页数
  727. * @return
  728. * @throws ParseException
  729. */
  730. @RequestMapping(value = "/customerStatistics",method = RequestMethod.GET)
  731. public Result customerStatistics(String startDate,String endDate,String timeSpan,String depNo,String businessGlossoryId,Integer pageNo, Integer pageSize) throws ParseException{
  732. Result res = new Result();
  733. Date sDate = null;
  734. Date eDate = null;
  735. DateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDD);
  736. if(StringUtils.isNotBlank(startDate)) sDate = format.parse(startDate);
  737. if(StringUtils.isNotBlank(endDate)) eDate = format.parse(endDate);
  738. if(StringUtils.isBlank(startDate)&&StringUtils.isBlank(endDate)){
  739. Date date = new Date();
  740. if(timeSpan.equals(DateUtils.DAY_SPAN)){
  741. sDate = DateUtils.getYesterday();
  742. }else if(timeSpan.equals(DateUtils.WEEK_SPAN)){
  743. sDate = DateUtils.getLastDayOfLastWeek(date);
  744. }else if(timeSpan.equals(DateUtils.MONTH_SPAN)){
  745. sDate = DateUtils.getLastDayOfLastMonth(date);
  746. }else if(timeSpan.equals(DateUtils.QUARTER_SPAN)){
  747. sDate = DateUtils.getLastDayOfLastQuarter(date);
  748. }else if(timeSpan.equals(DateUtils.YEAR_SPAN)){
  749. sDate = DateUtils.getLastDayOfLastYear(date);
  750. }
  751. }
  752. res.setData(customerService.customerStatistics(sDate,eDate,depNo,businessGlossoryId,pageNo,pageSize));
  753. return res;
  754. }
  755. /**
  756. *
  757. * @param startDate 开始日期
  758. * @param endDate 结束日期
  759. * @param timeSpan 时间差
  760. * @param depNo 部门编号
  761. * @param businessGlossoryId 业务编号
  762. * @param pageNo 页码
  763. * @param pageSize 页数
  764. * @return
  765. * @throws ParseException
  766. */
  767. @RequestMapping(value = "/businessStatistic", method = RequestMethod.GET)
  768. public Result businessStatistic(String startDate,String endDate,String timeSpan,String depNo,String businessGlossoryId,Integer pageNo, Integer pageSize) throws ParseException{
  769. Result res = new Result();
  770. Date sDate = null;
  771. Date eDate = null;
  772. DateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDD);
  773. if(StringUtils.isNotBlank(startDate)) sDate = format.parse(startDate);
  774. if(StringUtils.isNotBlank(endDate)) eDate = format.parse(endDate);
  775. if(StringUtils.isBlank(startDate)&&StringUtils.isBlank(endDate)){
  776. Date date = new Date();
  777. if(timeSpan.equals(DateUtils.DAY_SPAN)){
  778. sDate = DateUtils.getYesterday();
  779. }else if(timeSpan.equals(DateUtils.WEEK_SPAN)){
  780. sDate = DateUtils.getLastDayOfLastWeek(date);
  781. }else if(timeSpan.equals(DateUtils.MONTH_SPAN)){
  782. sDate = DateUtils.getLastDayOfLastMonth(date);
  783. }else if(timeSpan.equals(DateUtils.QUARTER_SPAN)){
  784. sDate = DateUtils.getLastDayOfLastQuarter(date);
  785. }else if(timeSpan.equals(DateUtils.YEAR_SPAN)){
  786. sDate = DateUtils.getLastDayOfLastYear(date);
  787. }
  788. }
  789. res.setData(customerService.businessStatistic(sDate,eDate,depNo,businessGlossoryId,pageNo,pageSize));
  790. return res;
  791. }
  792. /**
  793. *
  794. * @param startDate 开始日期
  795. * @param endDate 结束日期
  796. * @param timeSpan 时间差
  797. * @param depNo 部门编号
  798. * @param pageNo 页码
  799. * @param pageSize 页数
  800. * @return
  801. * @throws ParseException
  802. */
  803. @RequestMapping(value = "/followStatistic",method = RequestMethod.GET)
  804. public Result followStatistic(String startDate,String endDate,String timeSpan,String depNo,Integer pageNo, Integer pageSize) throws ParseException{
  805. Result res = new Result();
  806. Date sDate = null;
  807. Date eDate = null;
  808. DateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDD);
  809. if(StringUtils.isNotBlank(startDate)) sDate = format.parse(startDate);
  810. if(StringUtils.isNotBlank(endDate)) eDate = format.parse(endDate);
  811. if(StringUtils.isBlank(startDate)&&StringUtils.isBlank(endDate)){
  812. Date date = new Date();
  813. if(timeSpan.equals(DateUtils.DAY_SPAN)){
  814. sDate = DateUtils.getYesterday();
  815. }else if(timeSpan.equals(DateUtils.WEEK_SPAN)){
  816. sDate = DateUtils.getLastDayOfLastWeek(date);
  817. }else if(timeSpan.equals(DateUtils.MONTH_SPAN)){
  818. sDate = DateUtils.getLastDayOfLastMonth(date);
  819. }else if(timeSpan.equals(DateUtils.QUARTER_SPAN)){
  820. sDate = DateUtils.getLastDayOfLastQuarter(date);
  821. }else if(timeSpan.equals(DateUtils.YEAR_SPAN)){
  822. sDate = DateUtils.getLastDayOfLastYear(date);
  823. }
  824. }
  825. res.setData(customerService.followStatistic(sDate, eDate, depNo, pageNo, pageSize));
  826. return res;
  827. }
  828. /**
  829. * 管理员列表
  830. * @param adminName 名称
  831. * @param status 0 正常 1锁定 2全部
  832. * @return
  833. */
  834. @RequestMapping(value = "/listAdminByName",method = RequestMethod.GET)
  835. public Result listAdminByName(String adminName,Integer status){
  836. Result res = new Result();
  837. adminName=adminName.trim();
  838. if(StringUtils.isNotBlank(adminName))res.setData(adminService.listAdminByName(adminName,status));
  839. return res;
  840. }
  841. /**
  842. * 客户转交
  843. * @param uid 用户编号
  844. * @param aid
  845. * @param operatorType 3私有 4签单
  846. * @param oldAid
  847. * @param data 资料同步转移 0无 1资料转交 2订单转交 3全部转交
  848. * @return
  849. */
  850. @RequestMapping(value = "/transferToOther", method = RequestMethod.GET)
  851. public Result transferToOther(String uid,String aid,Integer operatorType,Integer data,String oldAid){
  852. Result res = new Result();
  853. if(StringUtils.isBlank(uid) || StringUtils.isBlank(aid)){
  854. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "客户编号或管理员编号"));
  855. return res;
  856. }
  857. //默认为私有转交,4为签单转交
  858. if (operatorType==null) {
  859. operatorType=AFTConstants.USER_TRANSFER_TO_OTHER;
  860. }
  861. if ((operatorType ==AFTConstants.USER_TRANSFER_TO_OTHER||operatorType ==AFTConstants.USER_RECEIVE)
  862. && customerService.checkMax(uid,aid)) {
  863. res.getError().add(buildError("","对方私有客户已达最大限制"));
  864. return res;
  865. }
  866. if(data==null)data=0;
  867. res.setData(customerService.updateByOperatorType(uid, aid, oldAid, operatorType, data));
  868. return res;
  869. }
  870. /**
  871. * 客户转交记录
  872. * @param uid 客户编号
  873. * @return
  874. */
  875. @RequestMapping(value = "/transferList", method = RequestMethod.GET)
  876. public Result transferList(String uid){
  877. Result res = new Result();
  878. if(StringUtils.isBlank(uid) ){
  879. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"客户编号", "客户编号"));
  880. return res;
  881. }
  882. res.data(customerService.transferList( uid));
  883. return res;
  884. }
  885. /** 查询我的业务列表 **/
  886. @RequestMapping(value = "/listBusiness", method = RequestMethod.POST)
  887. public Result listBusiness(BusinessListBo blo,Integer pageNo, Integer pageSize){
  888. Result res = new Result();
  889. res.setData(customerService.listBusiness(blo, pageNo, pageSize));
  890. return res;
  891. }
  892. /** 查询所有的业务列表 **/
  893. @RequestMapping(value = "/listAllBusiness", method = RequestMethod.POST)
  894. public Result listAllBusiness(BusinessListBo blo,Integer pageNo, Integer pageSize){
  895. Result res = new Result();
  896. res.setData(customerService.listAllBusiness(blo, pageNo, pageSize));
  897. return res;
  898. }
  899. /** 业务管理列表 **/
  900. @RequestMapping(value = "/listManageBusiness", method = RequestMethod.POST)
  901. public Result listManageBusiness(BusinessListBo blo,Integer pageNo, Integer pageSize){
  902. Result res = new Result();
  903. res.setData(customerService.listManageBusiness(blo, pageNo, pageSize));
  904. return res;
  905. }
  906. /** 查询业务字典 **/
  907. @RequestMapping(value = "/findBusinessGlossory",method = RequestMethod.GET)
  908. public Result findBusinessGlossory(){
  909. Result res = new Result();
  910. res.setData(customerService.findBusinessGlossory());
  911. return res;
  912. }
  913. /** 新增客户意向 **/
  914. @RequestMapping(value = "/addBusinessAndFollow", method = RequestMethod.POST)
  915. public Result addBusinessAndFollow(BussinessFollowBo bfb){
  916. Result res = new Result();
  917. if(StringUtils.isBlank(bfb.getBusinessProjectId()) || StringUtils.isBlank(bfb.getUid())){
  918. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  919. return res;
  920. }
  921. if(customerService.judgeBusiness(bfb.getUid(), bfb.getBusinessProjectId())>0){
  922. res.getError().add(new Error("该项业务已经被跟进"));
  923. return res;
  924. }
  925. try {
  926. customerService.addBusinessAndFollow(bfb);
  927. } catch (ParseException e) {
  928. e.printStackTrace();
  929. }
  930. return res;
  931. }
  932. /** 进入新增意向服务 **/
  933. @RequestMapping(value = "/toAddBusinessAndFollow", method = RequestMethod.GET)
  934. public Result toAddBusinessAndFollow(){
  935. Result res = new Result();
  936. BussinessFollowBo bo = new BussinessFollowBo();
  937. bo.setAdminName(TokenManager.getAdminToken().getName());
  938. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  939. bo.setCreateTime(format.format(new Date()));
  940. bo.setFollowTime(bo.getCreateTime());
  941. res.setData(bo);
  942. return res;
  943. }
  944. /** 进入修改业务意向 **/
  945. @RequestMapping(value = "/toUpdateBusiness", method = RequestMethod.GET)
  946. public Result toUpdateBusiness(String businessId){
  947. Result res = new Result();
  948. res.setData(customerService.findBusinessDetail(businessId));
  949. return res;
  950. }
  951. /** 修改业务意向 **/
  952. @RequestMapping(value = "/updateBusiness", method = RequestMethod.POST)
  953. public Result updateBusiness(BussinessFollowBo bfb){
  954. Result res = new Result();
  955. customerService.updateBusiness(bfb);
  956. return res;
  957. }
  958. /** 进入跟进单个客户意向 **/
  959. @RequestMapping(value = "/toAddFollowOneBusiness", method = RequestMethod.GET)
  960. public Result toAddFollowOneBusiness(String businessId){
  961. Result res = new Result();
  962. BussinessFollowBo bo = customerService.findBusinessDetail(businessId);
  963. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  964. bo.setFollowTime(format.format(new Date()));
  965. res.setData(bo);
  966. return res;
  967. }
  968. /** 跟进单个客户意向 **/
  969. @RequestMapping(value = "/addFollowOneBusiness", method = RequestMethod.POST)
  970. public Result addFollowOneBusiness(BussinessFollowBo bfb){
  971. Result res = new Result();
  972. if(StringUtils.isBlank(bfb.getBusinessId()) ||
  973. StringUtils.isBlank(bfb.getUid()) || StringUtils.isBlank(bfb.getOcbId())){
  974. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
  975. return res;
  976. }
  977. try {
  978. customerService.addFollowOneBusiness(bfb);
  979. } catch (ParseException e) {
  980. e.printStackTrace();
  981. }
  982. return res;
  983. }
  984. /** 进入修改某个客户一个业务的当次拜访 **/
  985. @RequestMapping(value = "/toUpdateFollowOneBusiness", method = RequestMethod.GET)
  986. public Result toUpdateFollowOneBusiness(String ufbId){
  987. Result res = new Result();
  988. if(StringUtils.isBlank(ufbId)) {
  989. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  990. return res;
  991. }
  992. res.setData(customerService.findFollowOneBusiness(ufbId));
  993. return res;
  994. }
  995. /** 修改某个客户一个业务的当次拜访 **/
  996. @RequestMapping(value = "/updateFollowOneBusiness", method = RequestMethod.POST)
  997. public Result updateFollowOneBusiness(BussinessFollowBo bfb){
  998. Result res = new Result();
  999. if(StringUtils.isBlank(bfb.getFollowId()) || StringUtils.isBlank(bfb.getUfbId())){
  1000. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1001. return res;
  1002. }
  1003. customerService.updateFollowOneBusiness(bfb);
  1004. return res;
  1005. }
  1006. /** 删除某个客户一个业务的当次拜访 **/
  1007. @RequestMapping(value = "/deleteFollowOneBusiness", method = RequestMethod.GET)
  1008. public Result deleteFollowOneBusiness(String ufbId){
  1009. Result res = new Result();
  1010. if(StringUtils.isBlank(ufbId)){
  1011. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1012. return res;
  1013. }
  1014. customerService.deleteFollowOneBusiness(ufbId);
  1015. return res;
  1016. }
  1017. /** 添加单个联系人 **/
  1018. @RequestMapping(value = "/addOneContact", method = RequestMethod.POST)
  1019. public Result addOneContact(OrganizationContactBook ocb){
  1020. Result res = new Result();
  1021. if(StringUtils.isBlank(ocb.getUid())){
  1022. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1023. return res;
  1024. }
  1025. if(StringUtils.isBlank(ocb.getName()) || StringUtils.isBlank(ocb.getMobile())){
  1026. res.getError().add(buildError("联系人号码和联系人姓名不能为空"));
  1027. return res;
  1028. }
  1029. customerService.addOneContact(ocb);
  1030. return res;
  1031. }
  1032. /** 删除单个联系人 **/
  1033. @RequestMapping(value = "/deleteOneContact", method = RequestMethod.GET)
  1034. public Result deleteOneContact(String ocbId){
  1035. Result res = new Result();
  1036. if(StringUtils.isBlank(ocbId)){
  1037. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1038. return res;
  1039. }
  1040. customerService.deleteOneContact(ocbId);
  1041. return res;
  1042. }
  1043. /** 修改主要联系人 **/
  1044. @RequestMapping(value = "/updateMainContact", method = RequestMethod.GET)
  1045. public Result updateMainContact(String ocbId,String uid){
  1046. Result res = new Result();
  1047. if(StringUtils.isBlank(uid) || StringUtils.isBlank(ocbId)){
  1048. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1049. return res;
  1050. }
  1051. customerService.updateMainContact(ocbId,uid);
  1052. return res;
  1053. }
  1054. /** 删除 业务 **/
  1055. @RequestMapping(value = "/deleteBusiness", method =RequestMethod.GET)
  1056. public Result deleteBusiness(String businessId){
  1057. Result res = new Result();
  1058. if(StringUtils.isBlank(businessId)){
  1059. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1060. return res;
  1061. }
  1062. customerService.deleteBusiness(businessId);
  1063. return res;
  1064. }
  1065. /** 停止业务 **/
  1066. @RequestMapping(value = "/stopBusiness", method = RequestMethod.GET)
  1067. public Result stopBusiness(String businessId){
  1068. Result res = new Result();
  1069. if(StringUtils.isBlank(businessId)){
  1070. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
  1071. return res;
  1072. }
  1073. customerService.updateBusinessToStop(businessId);
  1074. return res;
  1075. }
  1076. /** 客户分配查询(本部门) **/
  1077. @RequestMapping(value = "/findAdminName" , method = RequestMethod.POST)
  1078. public Result findAdminName(){
  1079. Result res = new Result();
  1080. res.setData(customerService.findAdminName());
  1081. return res;
  1082. }
  1083. /** 分配个人客户 **/
  1084. @RequestMapping(value = "/updatePersonalCustomerz", method = RequestMethod.POST)
  1085. public Result updatePersonalCustomerz(CustomerPersonalDetailBo bo){
  1086. Result res = new Result();
  1087. if(StringUtils.isBlank(bo.getUid()) || StringUtils.isBlank(bo.getId())){
  1088. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  1089. return res;
  1090. }
  1091. customerService.updatePersonalCustomerz(bo);
  1092. return res;
  1093. }
  1094. /** 客户录入审核 **/
  1095. @RequestMapping(value = "/findEnteringAudit" , method = RequestMethod.POST)
  1096. public Result findEnteringAudit(CustomerListOut clo,Integer pageNo, Integer pageSize){
  1097. Result res = new Result();
  1098. res.setData(customerService.findEnteringAudit(clo, pageNo, pageSize));
  1099. return res;
  1100. }
  1101. /** 修改客户录入审核状态 **/
  1102. @RequestMapping(value = "/updateEnteringAudit", method = RequestMethod.POST)
  1103. public Result updateEnteringAudit(User bo){
  1104. Result res = new Result();
  1105. if(StringUtils.isBlank(bo.getId())){
  1106. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  1107. return res;
  1108. }
  1109. res.data(customerService.updateEnteringAudit(bo));
  1110. return res;
  1111. }
  1112. /** 审核拒绝客户查询 **/
  1113. @RequestMapping(value = "/findEnteringAuditIsNo" , method = RequestMethod.POST)
  1114. public Result findEnteringAuditIsNo(CustomerListOut clo,Integer pageNo, Integer pageSize){
  1115. Result res = new Result();
  1116. res.setData(customerService.findEnteringAuditIsNo(clo, pageNo, pageSize));
  1117. return res;
  1118. }
  1119. /** 修改拒绝客户信息 **/
  1120. @RequestMapping(value = "/updateRefusedCustomer", method = RequestMethod.POST)
  1121. public Result updateRefusedCustomer(String id,String nickname,String mobile,String societyTag){
  1122. Result res = new Result();
  1123. if(StringUtils.isBlank(nickname)){
  1124. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"名称"));
  1125. return res;
  1126. }
  1127. if(StringUtils.isBlank(mobile)){
  1128. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"电话"));
  1129. return res;
  1130. }
  1131. if(StringUtils.isBlank(societyTag)){
  1132. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"社会性质"));
  1133. return res;
  1134. }
  1135. customerService.updateRefusedCustomer(id, nickname, mobile, societyTag);
  1136. return res;
  1137. }
  1138. /** 查询客户的锁定业务 **/
  1139. @RequestMapping(value = "/getLockedProject", method = RequestMethod.GET)
  1140. public Result getLockedProject(String uid){
  1141. Result res = new Result();
  1142. if(StringUtils.isBlank(uid)){
  1143. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"用户ID"));
  1144. return res;
  1145. }
  1146. res.setData(customerService.selectLockedProject(uid));
  1147. return res;
  1148. }
  1149. /** 客户二次签项目业务 **/
  1150. @RequestMapping(value = "/againProjectTask", method = RequestMethod.GET)
  1151. public Result againProjectTask(String uid,String projectId,String aid){
  1152. Result res = new Result();
  1153. if(StringUtils.isBlank(uid)||StringUtils.isBlank(projectId)){
  1154. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"参数"));
  1155. return res;
  1156. }
  1157. res.setData(customerService.updateAgainProjectTask(uid,projectId,aid));
  1158. return res;
  1159. }
  1160. /** 客户资料转交 **/
  1161. @RequestMapping(value = "/updateInformationMaintainerr", method = RequestMethod.POST)
  1162. public Result updateInformationMaintainerr(String id,String aid){
  1163. Result res = new Result();
  1164. if(StringUtils.isBlank(id) || StringUtils.isBlank(aid)){
  1165. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
  1166. return res;
  1167. }
  1168. res.data(customerService.updateInformationMaintainerr(id,aid));
  1169. return res;
  1170. }
  1171. /** 个人单位客户信息列表 **/
  1172. @RequestMapping(value = "/listCustomerInformation", method = RequestMethod.POST)
  1173. public Result listCustomerInformation(CustomerListIn cli,Integer pageNo, Integer pageSize){
  1174. Result res = new Result();
  1175. res.data(customerService.listCustomerInformation(cli,pageNo,pageSize));
  1176. return res;
  1177. }
  1178. /** 部门单位客户信息列表 **/
  1179. @RequestMapping(value = "/listDepCustomerInformation", method = RequestMethod.POST)
  1180. public Result listDepCustomerInformation(CustomerListIn cli,Integer pageNo, Integer pageSize){
  1181. Result res = new Result();
  1182. res.data(customerService.listDepCustomerInformation(cli,pageNo,pageSize));
  1183. return res;
  1184. }
  1185. /** 修改客户等级 **/
  1186. @RequestMapping(value = "/updateUserLevel", method = RequestMethod.GET)
  1187. public Result updateUserLevel(User u){
  1188. Result res = new Result();
  1189. if(StringUtils.isBlank(u.getId())){
  1190. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"用户ID错误","用户ID"));
  1191. return res;
  1192. }
  1193. if(null==u.getLevel()){
  1194. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"用户等级错误","用户等级"));
  1195. return res;
  1196. }
  1197. res.data(customerService.updateUserLevel(u));
  1198. return res;
  1199. }
  1200. /** 释放客户 **/
  1201. @RequestMapping(value = "/pushReleaseUser", method = RequestMethod.GET)
  1202. public Result pushReleaseUser(String id){
  1203. Result res = new Result();
  1204. if(StringUtils.isBlank(id)){
  1205. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"用户ID错误","用户ID"));
  1206. return res;
  1207. }
  1208. res.data(customerService.pushReleaseUser(id));
  1209. return res;
  1210. }
  1211. /**
  1212. * 企业项目申报材料上传
  1213. *
  1214. * @param req
  1215. * @param uid
  1216. * @return
  1217. */
  1218. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  1219. public Result cognizanceFile(HttpServletRequest req, String uid, String id, String sign) {
  1220. Result res = new Result();
  1221. AttachmentType attachmentType = AttachmentType.getField(sign);
  1222. if (attachmentType == AttachmentType.ORGANIZATION_APPLICATION) {
  1223. res.setData(handleFiles(res, "/orgApplication/", true, req, sign, uid));
  1224. } else {
  1225. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  1226. }
  1227. return res;
  1228. }
  1229. /**
  1230. * 企业项目申报材料预览授权
  1231. *
  1232. * @param id
  1233. * @param sign
  1234. * @return
  1235. */
  1236. @RequestMapping(value = "/techProject", method = RequestMethod.GET)
  1237. public Result previewTechProject(String id, String sign) {
  1238. Result res = new Result();
  1239. if (StringUtils.isEmpty(id)) {
  1240. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "企业项目申报材料ID"));
  1241. return res;
  1242. }
  1243. AttachmentType attachmentType = AttachmentType.getField(sign);
  1244. if (attachmentType == AttachmentType.ORGANIZATION_APPLICATION) {
  1245. String time = String.valueOf(Calendar.getInstance().getTime().getTime());
  1246. String auth = SHA256Util.toHash(sign + "|" + id + "|" + secretKey, time);
  1247. res.setData("sign=" + sign + "&token2=" + id + "&auth=" + auth + "&temp=" + time);
  1248. } else {
  1249. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  1250. }
  1251. return res;
  1252. }
  1253. /**
  1254. * 查看营销员客户统计
  1255. * @param depId
  1256. * @param startTime
  1257. * @param endTime
  1258. * @param pageSize
  1259. * @param pageNo
  1260. * @return
  1261. */
  1262. @RequestMapping(value = "/selectAdminCustomerStatistics", method = RequestMethod.GET)
  1263. public Result selectAdminCustomerstatistics(String depId, String startTime,String endTime, Integer pageSize, Integer pageNo) {
  1264. Result res = new Result();
  1265. res.data(adminService.selectAdminCustomerStatistics( depId, startTime, endTime, pageSize, pageNo));
  1266. return res;
  1267. }
  1268. /**
  1269. * 查看客户统计
  1270. * @param depId 部门编号
  1271. * @param startTime 开始时间
  1272. * @param endTime 结束时间
  1273. * @return
  1274. */
  1275. @RequestMapping(value = "/selectAllUser", method = RequestMethod.GET)
  1276. public Result selectAllUser(String depId, String startTime,String endTime,String aName ) {
  1277. Result res = new Result();
  1278. res.data(adminService.selectAllUser( depId, startTime, endTime, aName));
  1279. return res;
  1280. }
  1281. /**
  1282. * 查看客户日期内新增客户
  1283. * @param startTime
  1284. * @param endTime
  1285. * @param type 0私有 1渠道 2签单 3私有新增 4渠道新增 5私有面谈 6渠道面谈 7私有领取
  1286. * @param pageSize
  1287. * @param pageNo
  1288. * @return
  1289. */
  1290. @RequestMapping(value = "/selectAdminCustomerList", method = RequestMethod.GET)
  1291. public Result selectAdminCustomerList(String aid, String startTime,String endTime,Integer type, Integer pageSize, Integer pageNo) {
  1292. Result res = new Result();
  1293. res.data(adminService.selectAdminCustomerList( aid, startTime, endTime, type, pageSize, pageNo));
  1294. return res;
  1295. }
  1296. /**
  1297. *
  1298. * @param inputId 业务转移客户id(接收者)
  1299. * @param uid 被转移的客户
  1300. * @param pid 呗转移的业务
  1301. * @return
  1302. */
  1303. @RequestMapping(value = "/privateBusinessTransfer", method = RequestMethod.POST)
  1304. public Result privateBusinessTransfer(String inputId,String uid,String pid ) {
  1305. Result res = new Result();
  1306. if (StringUtils.isBlank(inputId)) {
  1307. res.getError().add(buildError("请确认正确的接收者。","请确认正确的接收者。"));
  1308. return res;
  1309. }
  1310. int i= customerService.updatePrivateBusinessTransfer( inputId, uid, pid );
  1311. if (i<1) {
  1312. res.getError().add(buildError("请确认客户与业务归属是否正确。","请确认客户与业务归属是否正确。"));
  1313. return res;
  1314. }
  1315. res.data(i);
  1316. return res;
  1317. }
  1318. /**
  1319. * 渠道客户列表
  1320. **/
  1321. @RequestMapping(value = "/listChannelCustomer" , method = RequestMethod.POST)
  1322. public Result listChannelCustomer(InputListChannel in){
  1323. Result res = new Result();
  1324. res.setData(customerService.listChannelCustomer(in));
  1325. return res;
  1326. }
  1327. /**
  1328. * 渠道客户统计列表
  1329. **/
  1330. @RequestMapping(value = "/listChannelCounts" , method = RequestMethod.GET)
  1331. public Result listChannelCounts(InputChannelCounts in){
  1332. Result res = new Result();
  1333. res.setData(customerService.listChannelCounts(in));
  1334. return res;
  1335. }
  1336. /**
  1337. * 渠道客户转交
  1338. * @param userIds 用户编号集
  1339. * @param receiveId 接受者
  1340. * @param remarks 备注
  1341. * @param type 0 分配 1转交 2回退
  1342. * @return
  1343. */
  1344. @RequestMapping(value = "/channelCustomerDeliver", method = RequestMethod.POST)
  1345. public Result channelCustomerDeliver(String userIds ,String receiveId,String remarks,Integer type){
  1346. Result res = new Result();
  1347. if (StringUtils.isBlank(userIds)) {
  1348. res.getError().add(buildError("","用户编号不存在"));
  1349. return res;
  1350. }
  1351. String [] str=userIds.split(",");
  1352. List<String> uids=Arrays.asList(str);
  1353. if (type==1&&customerService.checkChannel(uids)) {
  1354. res.getError().add(buildError("","已跟进,禁止分配!"));
  1355. return res;
  1356. }
  1357. if (type==2&&customerService.checkRecovery(uids)) {
  1358. res.getError().add(buildError("","不允许二次回退"));
  1359. return res;
  1360. }
  1361. res.setData(customerService.pushChannelDeliver( uids , receiveId,remarks,type));
  1362. return res;
  1363. }
  1364. /** 修改客户名称 **/
  1365. @RequestMapping(value = "/updateUserName", method = RequestMethod.POST)
  1366. public Result updateUserName(String uid,String userName){
  1367. Result res = new Result();
  1368. if(StringUtils.isBlank(uid) || StringUtils.isBlank(userName)){
  1369. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,null,"uid或者名称"));
  1370. return res;
  1371. }
  1372. if (userName!=null){
  1373. userName=userName.trim();
  1374. }
  1375. if(customerService.checkUserName(userName)){
  1376. res.getError().add(buildError(ErrorConstants.CUSTOMER_ALREADY_EXIST,null,"["+userName+"]"));
  1377. return res;
  1378. }
  1379. res.data(customerService.updateUserName(uid,userName));
  1380. return res;
  1381. }
  1382. @RequestMapping(value = "/checkUserName",method = RequestMethod.GET)
  1383. public Result checkUserName(String userName){
  1384. Result res =new Result();
  1385. res.data(customerService.checkUserName(userName));
  1386. return res;
  1387. }
  1388. /** 修改客户关键资料 **/
  1389. @RequestMapping(value = "/updateUserDate", method = RequestMethod.POST)
  1390. public Result updateUserDate(String uid,Integer province,Integer city,Integer area,String businessScope,String intendedProject,String introduction
  1391. ,Integer channelType,String orgCode){
  1392. Result res = new Result();
  1393. if (orgCode!=null){
  1394. orgCode=orgCode.trim();
  1395. if (customerService.checkOrgCode(orgCode)){
  1396. res.getError().add(buildError("","统一信用代码已存在"));
  1397. return res;
  1398. }
  1399. }
  1400. res.data(customerService.updateUserDate(uid, province, city, area, businessScope, intendedProject,introduction,channelType,orgCode));
  1401. return res;
  1402. }
  1403. /** 客户名称列表 **/
  1404. @RequestMapping(value = "/listUserName", method = RequestMethod.GET)
  1405. public Result listUserName(String uid){
  1406. Result res = new Result();
  1407. if(StringUtils.isBlank(uid) || StringUtils.isBlank(uid)){
  1408. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"uid","uid"));
  1409. return res;
  1410. }
  1411. res.data(customerService.listUserName(uid));
  1412. return res;
  1413. }
  1414. /**
  1415. * 客户主营产品列表
  1416. * @return
  1417. */
  1418. @RequestMapping(value = "/mainProductsList", method = RequestMethod.GET)
  1419. public Result mainProductsList(InputMainProductsList in){
  1420. Result res = new Result();
  1421. res.data(customerService.mainProductsList(in));
  1422. return res;
  1423. }
  1424. /**
  1425. * 用户信息日志
  1426. * @param uid
  1427. * @return
  1428. */
  1429. @RequestMapping(value = "/userDateLogList",method = RequestMethod.GET)
  1430. public Result userDateLogList(String uid){
  1431. Result res =new Result();
  1432. res.data(customerService.userDateLogList(uid));
  1433. return res;
  1434. }
  1435. /**
  1436. * 修改用户主营产品
  1437. * @param id
  1438. * @param businessScope
  1439. * @return
  1440. */
  1441. @RequestMapping(value = "/updateUserBusinessScope",method = RequestMethod.POST)
  1442. public Result updateUserBusinessScope(String id,String businessScope){
  1443. Result res=new Result();
  1444. if (id==null||businessScope==null){
  1445. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"参数","参数"));
  1446. return res;
  1447. }
  1448. res.data(customerService.updateuserBusinessScope(id,businessScope));
  1449. return res;
  1450. }
  1451. @RequestMapping(value = "/queryUserMax",method = RequestMethod.GET)
  1452. public Result queryUserMax(){
  1453. Result res =new Result();
  1454. res.setData(customerService.queryUserMax());
  1455. return res;
  1456. }
  1457. }