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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. if (request.getStatus()==null){
  40. aflSignReboundInfo.setStatus(StatusEnum.ENABLE.getCode());
  41. }
  42. aflSignReboundInfo.setIsDelete(IsDeleteEnum.NO.getCode());
  43. aflSignReboundInfo.setInsertTime(new Date());
  44. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  45. }
  46. @Override
  47. public void update(AflSignReboundInfoSaveOrUpdateRequest request) throws ServiceHandleException {
  48. if (StringUtils.isEmpty(request.getUpdator())){
  49. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
  50. }
  51. AflSignReboundInfo aflSignReboundInfo = findById(request.getId());
  52. if (!aflSignReboundInfo.getChannelCode().equals(request.getChannelCode())){
  53. AflSignReboundInfo byProductCode = aflSignReboundInfoRepo.findByChannelCode(request.getChannelCode());
  54. if (byProductCode!=null){
  55. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在该渠道的签约回跳配置,不允许重复,请核实");
  56. }
  57. }
  58. BeanUtils.copyProperties(request,aflSignReboundInfo);
  59. aflSignReboundInfo.setUpdator(request.getUpdator());
  60. aflSignReboundInfo.setUpdatedTime(new Date());
  61. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  62. }
  63. @Override
  64. public void delete(AflSignReboundInfoDeleteRequest request) throws ServiceHandleException {
  65. if (StringUtils.isEmpty(request.getUpdator())){
  66. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
  67. }
  68. AflSignReboundInfo aflSignReboundInfo = findById(request.getId());
  69. aflSignReboundInfo.setIsDelete(IsDeleteEnum.YES.getCode());
  70. aflSignReboundInfo.setUpdator(request.getUpdator());
  71. aflSignReboundInfo.setUpdatedTime(new Date());
  72. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  73. }
  74. @Override
  75. public void updateStatus(AflSignReboundInfoUpdateStatusRequest request) throws ServiceHandleException {
  76. AflSignReboundInfo aflSignReboundInfo = findById(request.getId());
  77. if (aflSignReboundInfo.getStatus()==request.getStatus()||request.getStatus()==null) {
  78. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态没有发生改变");
  79. }
  80. aflSignReboundInfo.setStatus(request.getStatus());
  81. aflSignReboundInfo.setUpdator(request.getUpdator());
  82. aflSignReboundInfo.setUpdatedTime(new Date());
  83. aflSignReboundInfoRepo.save(aflSignReboundInfo);
  84. }
  85. public AflSignReboundInfo findById(String id) throws ServiceHandleException {
  86. if (StringUtils.isEmpty(id)) {
  87. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请指定签约回跳配置编号");
  88. }
  89. AflSignReboundInfo aflSignReboundInfo = aflSignReboundInfoRepo.findByIdAndIsDelete(id);
  90. if (null == aflSignReboundInfo) {
  91. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("接入签约回跳配置不存在");
  92. }
  93. return aflSignReboundInfo;
  94. }
  95. private void verify(AflSignReboundInfoSaveOrUpdateRequest request) throws ServiceHandleException {
  96. if (StringUtils.isEmpty(request.getChannelCode())) {
  97. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("渠道编码不能为空");
  98. }
  99. if (StringUtils.isEmpty(request.getCallbackUrl())) {
  100. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("回跳地址不能为空");
  101. }
  102. if (StringUtils.isEmpty(request.getVehicleBrand())) {
  103. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("车辆品牌不能为空");
  104. }
  105. if (StringUtils.isEmpty(request.getCreator())) {
  106. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("创建人不能为空");
  107. }
  108. }
  109. @Override
  110. public String export(AflSignReboundInfoFindPageViewRequest request, Logger logger) throws ServiceHandleException {
  111. String pathFile =null;
  112. try {
  113. AflSignReboundInfoFindPageRequest queryRequest = new AflSignReboundInfoFindPageRequest();
  114. BeanUtil.copyProperties(request, queryRequest);
  115. List<AflSignReboundInfoVo> signReboundInfoVos = aflSignReboundInfoRepo.list(queryRequest);
  116. if (signReboundInfoVos==null||signReboundInfoVos.size()==0) {
  117. pathFile = ExcelUtils.export(null, "签约回跳",constantConfig.getFilePath() ,null, AflSignReboundInfoVo.class);
  118. } else {
  119. logger.info("选装-签约回跳管理导出返回参数:{}",signReboundInfoVos.toString());
  120. pathFile = ExcelUtils.export(null, "签约回跳",constantConfig.getFilePath(), signReboundInfoVos, AflSignReboundInfoVo.class);
  121. }
  122. if (StringUtils.isEmpty(pathFile)){
  123. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("签约回跳管理导出失败");
  124. }
  125. String s = null;
  126. try {
  127. s = fmsService.uploadFile(constantConfig.getUploadFile(),pathFile, 90000);
  128. } catch (ServiceHandleException e) {
  129. logger.error("选装-签约回跳管理导出失败:{}", e.getMessage());
  130. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
  131. }
  132. if (StringUtils.isEmpty(s)){
  133. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("签约回跳管理导出失败");
  134. }
  135. return s;
  136. } catch (Exception e) {
  137. if (e instanceof ServiceHandleException) {
  138. throw e;
  139. }
  140. logger.error("选装-签约回跳管理导出失败:{}", e.getMessage());
  141. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("签约回跳管理导出失败");
  142. }finally {
  143. File file = null;
  144. try {
  145. file = new File(pathFile);
  146. } catch (Exception e) {
  147. }
  148. if (file!=null){
  149. file.delete();
  150. }
  151. }
  152. }
  153. }