CustomerController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. package com.jkcredit.invoice.controller.business;
  2. import cn.afterturn.easypoi.excel.entity.ExportParams;
  3. import cn.com.taiji.sdk.model.comm.protocol.eoms.company.B2bCompanyModel;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.jkcredit.invoice.annotation.LoginRequired;
  7. import com.jkcredit.invoice.annotation.annotationdes.AuthenticationInterceptor;
  8. import com.jkcredit.invoice.model.entity.CustomerRecharge;
  9. import com.jkcredit.invoice.model.entity.customer.Customer;
  10. import com.jkcredit.invoice.model.entity.customer.CustomerEtcChangeInfo;
  11. import com.jkcredit.invoice.model.entity.customer.CustomerRec;
  12. import com.jkcredit.invoice.model.entity.manager.Param;
  13. import com.jkcredit.invoice.model.entity.user.User;
  14. import com.jkcredit.invoice.service.customer.CustomerChangeInfoService;
  15. import com.jkcredit.invoice.service.customer.CustomerRecService;
  16. import com.jkcredit.invoice.service.customer.CustomerRechargeService;
  17. import com.jkcredit.invoice.service.customer.CustomerService;
  18. import com.jkcredit.invoice.service.lowerservice.CheckHasAuthRole;
  19. import com.jkcredit.invoice.service.lowerservice.CustomeLowerService;
  20. import com.jkcredit.invoice.service.manager.ParamService;
  21. import com.jkcredit.invoice.util.DateUtil;
  22. import com.jkcredit.invoice.util.ExportUtil;
  23. import com.jkcredit.invoice.util.RespR;
  24. import com.jkcredit.invoice.util.WordUtil;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.apache.commons.lang.StringUtils;
  29. import org.apache.poi.util.IOUtils;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.web.bind.annotation.*;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.ByteArrayInputStream;
  34. import java.io.IOException;
  35. import java.io.InputStream;
  36. import java.io.OutputStream;
  37. import java.net.URLEncoder;
  38. import java.util.*;
  39. import static com.jkcredit.invoice.common.CommonConst.*;
  40. /**
  41. * 客户操作
  42. */
  43. @Api(tags = "客户操作")
  44. @RestController
  45. @RequestMapping(value = {"/customer"})
  46. /**
  47. * @Description 客户操作
  48. * @Author mashengyi
  49. * @Date 2022/2/8 18:16
  50. * @Param
  51. * @Return
  52. * @Exception
  53. *
  54. */
  55. @Slf4j
  56. public class CustomerController {
  57. @Autowired
  58. CustomerService customerService;
  59. @Autowired
  60. CustomerRechargeService customerRechargeService;
  61. @Autowired
  62. CustomeLowerService lowerService;
  63. @Autowired
  64. CustomerRecService customerRecService;
  65. @Autowired
  66. CustomerChangeInfoService customerChangeInfoService;
  67. @Autowired
  68. private ParamService paramService;
  69. @Autowired
  70. private CheckHasAuthRole checkHasAuthRole;
  71. /**
  72. * 分页查询客户
  73. *
  74. * @param page 参数集
  75. * @return 用户集合
  76. */
  77. @PostMapping("/findCustomer")
  78. @ApiOperation(value = "分页查询客户", notes = "分页查询客户")
  79. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  80. public RespR getCustomersByPage(Page page, Customer customer) {
  81. return new RespR(customerService.findAllCustomers(page, customer));
  82. }
  83. /**
  84. * 分页查询客户
  85. *
  86. * @param page 参数集
  87. * @return 用户集合
  88. */
  89. @PostMapping("/findCustomerRecharge")
  90. @ApiOperation(value = "分页查询客户充值信息", notes = "分页查询客户充值信息")
  91. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  92. public RespR findCustomerRecharge(Page page, CustomerRecharge customerRecharge) {
  93. return new RespR(customerRechargeService.findAllCustomerRecharge(page, customerRecharge));
  94. }
  95. /**
  96. * 分页查询客户
  97. *
  98. * @param page 参数集
  99. * @return 用户集合
  100. */
  101. @PostMapping("/findCustomerRechargeMoney")
  102. @ApiOperation(value = "分页查询客户端客户充值信息", notes = "分页查询客户端客户充值信息")
  103. @LoginRequired
  104. public RespR findCustomerRechargeMoney(Page page, CustomerRecharge customerRecharge, User user) {
  105. checkHasAuthRole.checkCustomerRole(user, customerRecharge.getCustomerName());
  106. return new RespR(customerRechargeService.findAllCustomerRechargeMoney(page, customerRecharge));
  107. }
  108. /**
  109. * 导出客户信息
  110. *
  111. * @param
  112. * @return 用户集合
  113. */
  114. @GetMapping("/findCustomerRecListExport")
  115. @ApiOperation(value = "客户信息导出", notes = "客户信息导出")
  116. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  117. public void findCustomerRechargeExport(String customerName, String companyName, String companyBelongName, HttpServletResponse response) throws Exception {
  118. CustomerRec customerRec = new CustomerRec();
  119. customerRec.setCustomerName(customerName);
  120. customerRec.setCompanyBelongName(companyBelongName);
  121. customerRec.setCompanyName(companyName);
  122. List<CustomerRec> customerRecs = customerRecService.findAllCustomerRecForExport(customerRec);
  123. if (customerRecs != null && customerRecs.size() > 0) {
  124. customerRecs.stream().forEach(customerRec1 -> {
  125. if (NO_CAR.equals(customerRec1.getBussinessType())) {
  126. customerRec1.setBussinessType("无车");
  127. } else if (SELF_CAR.equals(customerRec1.getBussinessType())) {
  128. customerRec1.setBussinessType("自有车");
  129. }
  130. });
  131. }
  132. ExportParams exportParams = new ExportParams("客户信息", "客户信息");
  133. ExportUtil.exportExcel(customerRecs, CustomerRec.class, "客户信息导出", exportParams, response);
  134. }
  135. /**
  136. * 分页查询客户注册信息
  137. *
  138. * @param page 参数集
  139. * @return 用户集合
  140. */
  141. @PostMapping("/findCustomerRecList")
  142. @ApiOperation(value = "分页查询客户注册信息", notes = "分页查询客户注册信息")
  143. @LoginRequired
  144. public RespR findCustomerRecList(Page page, CustomerRec customerRec, User user) {
  145. checkHasAuthRole.checkCustomerRole(user, customerRec.getCustomerName());
  146. return new RespR(customerRecService.findAllCustomerRec(page, customerRec));
  147. }
  148. /**
  149. * 添加客户
  150. *
  151. * @return 用户集合
  152. */
  153. @PostMapping("/addCustomer")
  154. @ApiOperation(value = "添加客户", notes = "添加客户")
  155. @LoginRequired
  156. public RespR addCustomer(@RequestBody Customer customer, User user) {
  157. checkHasAuthRole.checkCustomerRole(user, customer.getCustomerName());
  158. return new RespR(customerService.addCustomers(customer), "客户添加失败,请查看是否重复");
  159. }
  160. /**
  161. * 修改客户状态
  162. *
  163. * @return 用户集合
  164. */
  165. @PostMapping("/updateCustomer")
  166. @ApiOperation(value = "更新用户", notes = "更新用户")
  167. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  168. public RespR updateCustomer(@RequestBody Customer customer) {
  169. return new RespR(customerService.updateCustomer(customer));
  170. }
  171. /**
  172. * 修改客户状态
  173. *
  174. * @return 用户集合
  175. */
  176. @PostMapping("/customeRecStop")
  177. @ApiOperation(value = "停用备案用户", notes = "停用备案用户")
  178. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  179. public RespR customeRecStop(@RequestBody CustomerRec customerRec) {
  180. customerRec.setRecStatus(4);
  181. return customerService.updateCustomerRecStatus(customerRec);
  182. }
  183. /**
  184. * 修改客户状态
  185. *
  186. * @return 用户集合
  187. */
  188. @PostMapping("/customeRecStart")
  189. @ApiOperation(value = "启用备案用户", notes = "启用备案用户")
  190. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  191. public RespR customeRecStart(@RequestBody CustomerRec customerRec) {
  192. customerRec.setRecStatus(1);
  193. return customerService.updateCustomerRecStatus(customerRec);
  194. }
  195. /**
  196. * 修改客户状态
  197. *
  198. * @return 用户集合customerRecAdd
  199. */
  200. @PostMapping("/customerRecAdd")
  201. @ApiOperation(value = "手工添加备案信息", notes = "手工添加备案信息")
  202. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  203. public RespR customerRecAdd(@RequestBody CustomerRec customerRec) {
  204. customerRec.setInterType(1);
  205. List<CustomerRec> customerRecList = new ArrayList<>();
  206. customerRecList.add(customerRec);
  207. return lowerService.customeRec(customerRecList);
  208. }
  209. /**
  210. * 修改客户状态
  211. *
  212. * @return 用户集合customerRecAdd
  213. */
  214. @PostMapping("/customeRecQueryUpper")
  215. @ApiOperation(value = "查询备案信息", notes = "手工添加备案信息")
  216. @LoginRequired
  217. public RespR customeRecQueryUpper(@RequestBody CustomerRec customerRec, User user) {
  218. checkHasAuthRole.checkCustomerRole(user, customerRec.getCustomerName());
  219. RespR<List<B2bCompanyModel>> respR = customerService.customerRecQuery(customerRec);
  220. if (respR.getCode() == 1) {
  221. return respR;
  222. } else {
  223. List<B2bCompanyModel> resArr = respR.getData();
  224. if (resArr == null || resArr.size() == 0) {
  225. return new RespR(false, "未注册,无法回填");
  226. } else {
  227. if (resArr.size() >= 1) {
  228. resArr.forEach(b2bCompanyModel -> {
  229. if (b2bCompanyModel.getCompanyType().equals(customerRec.getCompanyType())) {
  230. customerRec.setCompanyType(b2bCompanyModel.getCompanyType());
  231. customerRec.setOperatingRangeType(b2bCompanyModel.getOperatingRangeType());
  232. customerRec.setCompanyLeader(b2bCompanyModel.getContact());
  233. customerRec.setCompanyLeaderPhone(b2bCompanyModel.getEmergencyTel());
  234. customerRec.setCompanyAdress(b2bCompanyModel.getBuyerAddr());
  235. customerRec.setCompanyPhone(b2bCompanyModel.getBuyerTel());
  236. customerRec.setCompanyOpenbank(b2bCompanyModel.getBuyerBank());
  237. customerRec.setCompanyOpenbankAcc(b2bCompanyModel.getBuyerBankAccount());
  238. customerRec.setCompanyPhone(b2bCompanyModel.getTel());
  239. }
  240. });
  241. }
  242. return new RespR(customerRec);
  243. }
  244. }
  245. }
  246. /**
  247. * 充值
  248. *
  249. * @return 用户集合
  250. */
  251. @PostMapping("/customRecharge")
  252. @ApiOperation(value = "账号充值", notes = "账号充值")
  253. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  254. public RespR customRecharge(@RequestBody CustomerRecharge customerRecharge) {
  255. return new RespR(customerService.customRecharge(customerRecharge));
  256. }
  257. @PostMapping("/customeRec")
  258. @ApiOperation(value = "用户备案确认", notes = "用户备案确认")
  259. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  260. public RespR customeRec(@RequestBody CustomerRec customerRec) {
  261. return customerService.customeRec(customerRec);
  262. }
  263. @PostMapping("/contractAdd")
  264. @ApiOperation(value = "协议上传确认", notes = "协议上传确认")
  265. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  266. public RespR contractAdd(@RequestBody CustomerRec customerRec) {
  267. return customerService.contractAdd(customerRec);
  268. }
  269. @PostMapping("/contractStatusFail")
  270. @ApiOperation(value = "协议上传失败状态确认", notes = "协议上传失败状态确认")
  271. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  272. public RespR contractStatusFail(@RequestBody CustomerRec customerRec) {
  273. return customerService.contractStatusFail(customerRec);
  274. }
  275. @PostMapping("/contractStatusProcess")
  276. @ApiOperation(value = "协议上传成功,审批中状态确认", notes = "协议上传成功,审批中状态确认")
  277. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  278. public RespR contractStatusProcess(@RequestBody CustomerRec customerRec) {
  279. return customerService.contractStatusProcess(customerRec);
  280. }
  281. @PostMapping("/contractStatusSuccess")
  282. @ApiOperation(value = "备案成功状态确认", notes = "备案成功状态确认")
  283. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  284. public RespR contractStatusSuccess(@RequestBody CustomerRec customerRec) {
  285. return customerService.contractStatusSuccess(customerRec);
  286. }
  287. @GetMapping("/contractDownload")
  288. @ApiOperation(value = "协议下载", notes = "协议下载")
  289. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  290. public RespR contractDownload(String customerRecId, HttpServletResponse response) {
  291. CustomerRec customerRec = (CustomerRec) customerService.contractDownload(customerRecId).getData();
  292. String fileName = customerRec.getLowerFileName();
  293. InputStream inputStream = null;
  294. OutputStream outputStream = null;
  295. if (customerRec.getLowerBase64Str() != null) {
  296. try {
  297. //将base64编码的字符串解码成字节数组
  298. byte[] byteArray = new sun.misc.BASE64Decoder().decodeBuffer(customerRec.getLowerBase64Str());
  299. inputStream = new ByteArrayInputStream(byteArray);
  300. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
  301. outputStream = response.getOutputStream();
  302. IOUtils.copy(inputStream, outputStream);
  303. response.flushBuffer();
  304. return new RespR(true);
  305. } catch (IOException e) {
  306. log.error("协议下载CustomerController.contractDownload协议下载失败{}", e.getMessage());
  307. } finally {
  308. IOUtils.closeQuietly(inputStream);
  309. IOUtils.closeQuietly(outputStream);
  310. }
  311. }
  312. return new RespR(false);
  313. }
  314. @GetMapping("/generateWord")
  315. @ApiOperation(value = "文档下载", notes = "文档下载")
  316. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  317. public RespR generateWord(String customerRecId, HttpServletResponse response) {
  318. CustomerRec customerRec = (CustomerRec) customerService.generateWordDownload(customerRecId).getData();
  319. if (null == customerRec || null == customerRec.getServiceStartTime() || null == customerRec.getServiceEndTime()) {
  320. return new RespR(false, "企业维护信息缺失服务时间,请手动维护");
  321. }
  322. String fileName = "合作说明.doc";
  323. Map<String, String> dataMap = new HashMap<>(10);
  324. dataMap.put("a", customerRec.getCompanyBelongName());
  325. dataMap.put("b", customerRec.getCompanyName());
  326. dataMap.put("c", customerRec.getCompanyReferencenum());
  327. dataMap.put("d", customerRec.getCompanyAdress());
  328. dataMap.put("e", customerRec.getCompanyPhone());
  329. dataMap.put("f", customerRec.getCompanyOpenbank());
  330. dataMap.put("g", customerRec.getCompanyOpenbankAcc());
  331. dataMap.put("j", customerRec.getServiceStartTime().substring(0, 10));
  332. dataMap.put("k", customerRec.getServiceEndTime().substring(0, 10));
  333. Calendar now = Calendar.getInstance();
  334. dataMap.put("l", now.get(Calendar.YEAR) + "");
  335. dataMap.put("h", (now.get(Calendar.MONTH) + 1) + "");
  336. dataMap.put("i", now.get(Calendar.DAY_OF_MONTH) + "");
  337. OutputStream outputStream = null;
  338. try {
  339. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
  340. outputStream = response.getOutputStream();
  341. WordUtil.exportSimpleWord(dataMap, "/static/templates/excel/", outputStream);
  342. response.flushBuffer();
  343. } catch (Exception e) {
  344. log.error("文档下载CustomerController.generateWord文档下载失败{}", e.getMessage());
  345. } finally {
  346. IOUtils.closeQuietly(outputStream);
  347. }
  348. return new RespR(false);
  349. }
  350. /**
  351. * 分页查询客户备案预警信息
  352. *
  353. * @param page 参数集
  354. * @return 用户集合
  355. */
  356. @PostMapping("/findCustomerRecTimeList")
  357. @ApiOperation(value = "客户备案预警查询", notes = "客户备案预警查询")
  358. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  359. public RespR findCustomerRecTimeList(Page page, CustomerRec customerRec) {
  360. IPage ipage = null;
  361. if ((StringUtils.isNotEmpty(customerRec.getServiceEndTime()) && !NULL.equals(customerRec.getServiceEndTime())) ||
  362. (StringUtils.isNotEmpty(customerRec.getCompanyName()) && !NULL.equals(customerRec.getCompanyName())) ||
  363. (StringUtils.isNotEmpty(customerRec.getCompanyBelongName()) && !NULL.equals(customerRec.getCompanyBelongName()))) {
  364. if (StringUtils.isNotEmpty(customerRec.getServiceEndTime()) && !NULL.equals(customerRec.getServiceEndTime())) {
  365. String[] res = customerRec.getServiceEndTime().split(",");
  366. customerRec.setServiceEndTimeStart(res[0]);
  367. customerRec.setServiceEndTimeEnd(res[1].replace("00:00:00", "23:59:59"));
  368. }
  369. ipage = customerRecService.findAllCustomerRecWarning(page, customerRec);
  370. } else {
  371. Param param = paramService.getParamsByParamName("CUST_EARLY_WARNING");
  372. ipage = customerRecService.findAllCustomerRecWarning(page, customerRec);
  373. List<CustomerRec> lists = ipage.getRecords();
  374. if (lists.size() > 0) {
  375. //遍历删除
  376. Iterator<CustomerRec> iterator = lists.iterator();
  377. while (iterator.hasNext()) {
  378. CustomerRec customerRec1 = iterator.next();
  379. if (((DateUtil.daysBetween(customerRec1.getServiceEndTime(), new Date()) < 0))
  380. || (Integer.valueOf(param.getParamValue()) <= (DateUtil.daysBetween(customerRec1.getServiceEndTime(), new Date())))) {
  381. iterator.remove();//使用迭代器的删除方法删除
  382. }
  383. }
  384. }
  385. ipage.setTotal(lists.size());
  386. }
  387. return new RespR(ipage);
  388. }
  389. /**
  390. * 分页查询余额告警用户
  391. *
  392. * @param page 参数集
  393. * @return 用户集合
  394. */
  395. @PostMapping("/findCustomerMoney")
  396. @ApiOperation(value = "分页查询余额告警用户", notes = "分页查询余额告警用户")
  397. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  398. public RespR getCustomerMoneysByPage(Page page, Customer customer) {
  399. Param param = paramService.getParamsByParamName("CUST_MONEY_WARNING");
  400. IPage ipage = null;
  401. if (customer.getMoneyUpper() == null || customer.getMoneyUpper() == -1) {
  402. customer.setMoneyUpper(Double.valueOf(param.getParamValue()));
  403. ipage = customerService.findAllNomoneyCustomers(page, customer);
  404. } else if (customer.getMoneyUpper() == null || customer.getMoneyUpper() == 0) {
  405. ipage = customerService.findAllNomoneyCustomersByZero(page, customer);
  406. } else {
  407. ipage = customerService.findAllNomoneyCustomers(page, customer);
  408. }
  409. return new RespR(ipage);
  410. }
  411. /**
  412. * @param customerRec
  413. * @return
  414. */
  415. @PostMapping("/customeRecQueryListByPage")
  416. @ApiOperation(value = "用户备案列表分页查询", notes = "用户备案列表分页查询")
  417. @LoginRequired
  418. public RespR customeRecQueryListByPage(Page page, CustomerRec customerRec, User user) {
  419. checkHasAuthRole.checkCustomerRole(user, customerRec.getCustomerName());
  420. IPage ipage = customerRecService.findAllCustomerRec(page, customerRec);
  421. return new RespR(ipage);
  422. }
  423. /**
  424. * @param customerEtcChangeInfo
  425. * @return
  426. */
  427. @PostMapping("/customerChangeList")
  428. @ApiOperation(value = "用户换卡信息列表查询", notes = "用户换卡信息列表查询")
  429. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  430. public RespR customeChangeInfoListByPage(Page page, CustomerEtcChangeInfo customerEtcChangeInfo) {
  431. IPage ipage = customerChangeInfoService.findAllCustomerChangeInfo(page, customerEtcChangeInfo);
  432. return new RespR(ipage);
  433. }
  434. @PostMapping("/customerChangeInfo")
  435. @ApiOperation(value = "用户换卡信息查询", notes = "用户换卡信息查询")
  436. @LoginRequired(role = AuthenticationInterceptor.AUTH_ADMIN)
  437. public RespR customerChangeInfo(String applyId) {
  438. List<Map<String, String>> cards = customerChangeInfoService.selectChangeCards(applyId);
  439. return new RespR(cards);
  440. }
  441. }