选装售后
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AflBlackInfoServiceImpl.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.qtzl.alterSales.manager.service;
  2. import cn.com.taiji.common.manager.net.http.ServiceHandleException;
  3. import com.google.common.collect.Lists;
  4. import com.qtzl.alterSales.dao.entity.second.AflBlackInfo;
  5. import com.qtzl.alterSales.dao.repo.jpa.second.AflBlackInfoRepo;
  6. import com.qtzl.alterSales.manager.enums.BlacklistOpType;
  7. import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
  8. import com.qtzl.alterSales.manager.model.protocol.sales.AflBlackInfoFindPageViewRequest;
  9. import com.qtzl.alterSales.manager.service.third.ConstantConfig;
  10. import com.qtzl.alterSales.manager.service.third.FmsService;
  11. import com.qtzl.alterSales.manager.tools.ExcelUtils;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.slf4j.Logger;
  14. import org.springframework.data.domain.Sort;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import javax.persistence.criteria.Predicate;
  18. import java.io.File;
  19. import java.time.LocalDateTime;
  20. import java.util.List;
  21. @Service
  22. public class AflBlackInfoServiceImpl implements AflBlackInfoService{
  23. @Resource
  24. AflBlackInfoRepo aflBlackInfoRepo;
  25. @Resource
  26. FmsService fmsService;
  27. @Resource
  28. ConstantConfig constantConfig;
  29. @Override
  30. public String export(AflBlackInfoFindPageViewRequest request, Logger logger) throws ServiceHandleException {
  31. String pathFile =null;
  32. try {
  33. long count = count(request);
  34. if (count> 10000l){
  35. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败,数据大于10000不允许导出");
  36. }
  37. List<AflBlackInfo> aflBlackInfos = select(request);
  38. if (aflBlackInfos==null||aflBlackInfos.size()==0) {
  39. pathFile = ExcelUtils.export(null, "状态名单",constantConfig.getFilePath() ,null, AflBlackInfo.class);
  40. } else {
  41. pathFile = ExcelUtils.export(null, "状态名单",constantConfig.getFilePath(), aflBlackInfos, AflBlackInfo.class);
  42. }
  43. if (StringUtils.isEmpty(pathFile)){
  44. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败");
  45. }
  46. String s = null;
  47. try {
  48. s = fmsService.uploadFile(constantConfig.getUploadFile(),pathFile, 90000);
  49. } catch (ServiceHandleException e) {
  50. logger.error("选装-状态名单管理导出失败:{}", e.getMessage());
  51. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
  52. }
  53. if (StringUtils.isEmpty(s)){
  54. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败");
  55. }
  56. return s;
  57. } catch (Exception e) {
  58. if (e instanceof ServiceHandleException) {
  59. throw e;
  60. }
  61. logger.error("选装-状态名单管理导出失败:{}", e.getMessage());
  62. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败");
  63. }finally {
  64. File file = null;
  65. try {
  66. file = new File(pathFile);
  67. } catch (Exception e) {
  68. }
  69. if (file!=null){
  70. file.delete();
  71. }
  72. }
  73. }
  74. private List<AflBlackInfo> select(AflBlackInfoFindPageViewRequest request) throws ServiceHandleException {
  75. return aflBlackInfoRepo.findAll(((root, query, cb) -> {
  76. List<Predicate> list = Lists.newArrayList();
  77. if (!StringUtils.isEmpty(request.getAgreementNum())) {
  78. list.add(cb.equal(root.<String>get("agreementNum"), request.getAgreementNum()));
  79. }
  80. if (!StringUtils.isEmpty(request.getIdNum())) {
  81. list.add(cb.equal(root.<String>get("idNum"), request.getIdNum()));
  82. }
  83. if (!StringUtils.isEmpty(request.getMobile())) {
  84. list.add(cb.equal(root.<String>get("mobile"), request.getMobile()));
  85. }
  86. if (request.getOpType()!=null) {
  87. list.add(cb.equal(root.<BlacklistOpType>get("opType"), request.getOpType()));
  88. }
  89. if (request.getInsertTimeEnd()!=null) {
  90. list.add(cb.lessThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeEnd()));
  91. }
  92. if (request.getInsertTimeStart()!=null) {
  93. list.add(cb.greaterThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeStart()));
  94. }
  95. Predicate[] p = new Predicate[list.size()];
  96. return cb.and(list.toArray(p));
  97. }), Sort.by(Sort.Direction.DESC, "insertTime"));
  98. }
  99. private long count(AflBlackInfoFindPageViewRequest request) throws ServiceHandleException {
  100. return aflBlackInfoRepo.count(((root, query, cb) -> {
  101. List<Predicate> list = Lists.newArrayList();
  102. if (!StringUtils.isEmpty(request.getAgreementNum())) {
  103. list.add(cb.equal(root.<String>get("agreementNum"), request.getAgreementNum()));
  104. }
  105. if (!StringUtils.isEmpty(request.getIdNum())) {
  106. list.add(cb.equal(root.<String>get("idNum"), request.getIdNum()));
  107. }
  108. if (!StringUtils.isEmpty(request.getMobile())) {
  109. list.add(cb.equal(root.<String>get("mobile"), request.getMobile()));
  110. }
  111. if (request.getOpType()!=null) {
  112. list.add(cb.equal(root.<BlacklistOpType>get("opType"), request.getOpType()));
  113. }
  114. if (request.getInsertTimeEnd()!=null) {
  115. list.add(cb.lessThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeEnd()));
  116. }
  117. if (request.getInsertTimeStart()!=null) {
  118. list.add(cb.greaterThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeStart()));
  119. }
  120. Predicate[] p = new Predicate[list.size()];
  121. return cb.and(list.toArray(p));
  122. }));
  123. }
  124. }