AdminCustomerApiController.java 55 KB

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