选装售后
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.

AflSignReboundInfoServiceImpl.java 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package com.qtzl.alterSales.manager.service;
  2. import cn.com.taiji.common.manager.net.http.ServiceHandleException;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import com.qtzl.alterSales.dao.entity.second.AflSignReboundInfo;
  5. import com.qtzl.alterSales.dao.repo.jpa.second.AflSignReboundInfoRepo;
  6. import com.qtzl.alterSales.manager.enums.IsDeleteEnum;
  7. import com.qtzl.alterSales.manager.enums.StatusEnum;
  8. import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
  9. import com.qtzl.alterSales.manager.model.protocol.sales.*;
  10. import com.qtzl.alterSales.manager.service.third.ConstantConfig;
  11. import com.qtzl.alterSales.manager.service.third.FmsService;
  12. import com.qtzl.alterSales.manager.tools.ExcelUtils;
  13. import com.qtzl.alterSales.manager.vo.AflSignReboundInfoVo;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.slf4j.Logger;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.stereotype.Service;
  18. import javax.annotation.Resource;
  19. import java.io.File;
  20. import java.util.Date;
  21. import java.util.List;
  22. @Service
  23. public class AflSignReboundInfoServiceImpl implements AflSignReboundInfoService{
  24. @Resource
  25. AflSignReboundInfoRepo aflSignReboundInfoRepo;
  26. @Resource
  27. FmsService fmsService;
  28. @Resource
  29. ConstantConfig constantConfig;
  30. @Override
  31. public void save(AflSignReboundInfoSaveOrUpdateRequest request) throws ServiceHandleException {
  32. verify(request);
  33. AflSignReboundInfo aflSignReboundInfo = aflSignReboundInfoRepo.findByChannelCode(request.getChannelCode());
  34. if (null != aflSignReboundInfo) {
  35. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在该渠道的签约回跳配置,不允许重复,请核实");
  36. }
  37. aflSignReboundInfo = new AflSignReboundInfo();
  38. BeanUtils.copyProperties(request, aflSignReboundInfo);
  39. aflSignReboundInfo.setStatus(StatusEnum.ENABLE.getCode());
  40. aflSignReboundInfo.setIsDelete(IsDeleteEnum.NO.getCode());
  41. aflSignReboundInfo.setInsertTime(new Date());
  42. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  43. }
  44. @Override
  45. public void update(AflSignReboundInfoSaveOrUpdateRequest request) throws ServiceHandleException {
  46. if (StringUtils.isEmpty(request.getUpdator())){
  47. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
  48. }
  49. AflSignReboundInfo aflSignReboundInfo = findById(request.getId());
  50. if (!aflSignReboundInfo.getChannelCode().equals(request.getChannelCode())){
  51. AflSignReboundInfo byProductCode = aflSignReboundInfoRepo.findByChannelCode(request.getChannelCode());
  52. if (byProductCode!=null){
  53. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在该渠道的签约回跳配置,不允许重复,请核实");
  54. }
  55. }
  56. BeanUtils.copyProperties(request,aflSignReboundInfo);
  57. aflSignReboundInfo.setUpdator(request.getUpdator());
  58. aflSignReboundInfo.setUpdatedTime(new Date());
  59. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  60. }
  61. @Override
  62. public void delete(AflSignReboundInfoDeleteRequest request) throws ServiceHandleException {
  63. if (StringUtils.isEmpty(request.getUpdator())){
  64. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
  65. }
  66. AflSignReboundInfo aflSignReboundInfo = findById(request.getId());
  67. aflSignReboundInfo.setIsDelete(IsDeleteEnum.YES.getCode());
  68. aflSignReboundInfo.setUpdator(request.getUpdator());
  69. aflSignReboundInfo.setUpdatedTime(new Date());
  70. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  71. }
  72. @Override
  73. public void updateStatus(AflSignReboundInfoUpdateStatusRequest request) throws ServiceHandleException {
  74. AflSignReboundInfo aflSignReboundInfo = findById(request.getId());
  75. if (aflSignReboundInfo.getStatus()==request.getStatus()||request.getStatus()==null) {
  76. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态没有发生改变");
  77. }
  78. aflSignReboundInfo.setStatus(request.getStatus());
  79. aflSignReboundInfo.setUpdator(request.getUpdator());
  80. aflSignReboundInfo.setUpdatedTime(new Date());
  81. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  82. }
  83. public AflSignReboundInfo findById(String id) throws ServiceHandleException {
  84. if (StringUtils.isEmpty(id)) {
  85. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请指定签约回跳配置编号");
  86. }
  87. AflSignReboundInfo aflSignReboundInfo = aflSignReboundInfoRepo.findByIdAndIsDelete(id);
  88. if (null == aflSignReboundInfo) {
  89. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("接入签约回跳配置不存在");
  90. }
  91. return aflSignReboundInfo;
  92. }
  93. private void verify(AflSignReboundInfoSaveOrUpdateRequest request) throws ServiceHandleException {
  94. if (StringUtils.isEmpty(request.getChannelCode())) {
  95. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("渠道编码不能为空");
  96. }
  97. if (StringUtils.isEmpty(request.getCallbackUrl())) {
  98. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("回跳地址不能为空");
  99. }
  100. if (StringUtils.isEmpty(request.getVehicleBrand())) {
  101. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("车辆品牌不能为空");
  102. }
  103. if (StringUtils.isEmpty(request.getCreator())) {
  104. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("创建人不能为空");
  105. }
  106. }
  107. @Override
  108. public String export(AflSignReboundInfoFindPageViewRequest request, Logger logger) throws ServiceHandleException {
  109. String pathFile =null;
  110. try {
  111. AflSignReboundInfoFindPageRequest queryRequest = new AflSignReboundInfoFindPageRequest();
  112. BeanUtil.copyProperties(request, queryRequest);
  113. List<AflSignReboundInfoVo> signReboundInfoVos = aflSignReboundInfoRepo.list(queryRequest);
  114. if (signReboundInfoVos==null||signReboundInfoVos.size()==0) {
  115. pathFile = ExcelUtils.export(null, "签约回跳",constantConfig.getFilePath() ,null, AflSignReboundInfoVo.class);
  116. } else {
  117. logger.info("选装-签约回跳管理导出返回参数:{}",signReboundInfoVos.toString());
  118. pathFile = ExcelUtils.export(null, "签约回跳",constantConfig.getFilePath(), signReboundInfoVos, AflSignReboundInfoVo.class);
  119. }
  120. if (StringUtils.isEmpty(pathFile)){
  121. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("签约回跳管理导出失败");
  122. }
  123. String s = null;
  124. try {
  125. s = fmsService.uploadFile(constantConfig.getUploadFile(),pathFile, 90000);
  126. } catch (ServiceHandleException e) {
  127. logger.error("选装-签约回跳管理导出失败:{}", e.getMessage());
  128. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
  129. }
  130. if (StringUtils.isEmpty(s)){
  131. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("签约回跳管理导出失败");
  132. }
  133. return s;
  134. } catch (Exception e) {
  135. if (e instanceof ServiceHandleException) {
  136. throw e;
  137. }
  138. logger.error("选装-签约回跳管理导出失败:{}", e.getMessage());
  139. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("签约回跳管理导出失败");
  140. }finally {
  141. File file = null;
  142. try {
  143. file = new File(pathFile);
  144. } catch (Exception e) {
  145. }
  146. if (file!=null){
  147. file.delete();
  148. }
  149. }
  150. }
  151. }