选装售后
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AflApplicationFunctionServiceImpl.java 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.AflApplicationFunction;
  5. import com.qtzl.alterSales.dao.repo.jpa.second.AflApplicationFunctionRepo;
  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.AflApplicationFunctionVo;
  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.time.LocalDateTime;
  21. import java.util.List;
  22. @Service
  23. public class AflApplicationFunctionServiceImpl implements AflApplicationFunctionService {
  24. @Resource
  25. AflApplicationFunctionRepo aflApplicationFunctionRepo;
  26. @Resource
  27. FmsService fmsService;
  28. @Resource
  29. ConstantConfig constantConfig;
  30. @Override
  31. public void save(AflApplicationFunctionSaveOrUpdateRequest request) throws ServiceHandleException {
  32. if (StringUtils.isEmpty(request.getCreator())) {
  33. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("创建人不能为空");
  34. }
  35. verify(request);
  36. AflApplicationFunction aflApplicationFunction = aflApplicationFunctionRepo.findByFunctionalityCode(request.getFunctionalityCode());
  37. if (null != aflApplicationFunction) {
  38. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在应用功能管理配置,不允许重复,请核实");
  39. }
  40. aflApplicationFunction = new AflApplicationFunction();
  41. BeanUtils.copyProperties(request, aflApplicationFunction);
  42. if (request.getStatus()==null){
  43. aflApplicationFunction.setStatus(StatusEnum.ENABLE.getCode());
  44. }
  45. aflApplicationFunction.setIsDelete(IsDeleteEnum.NO.getCode());
  46. aflApplicationFunctionRepo.save(aflApplicationFunction);
  47. }
  48. @Override
  49. public void update(AflApplicationFunctionSaveOrUpdateRequest request) throws ServiceHandleException {
  50. if (StringUtils.isEmpty(request.getUpdator())){
  51. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
  52. }
  53. verify(request);
  54. AflApplicationFunction aflApplicationFunction = findById(request.getId());
  55. if (!aflApplicationFunction.getFunctionalityCode().equals(request.getFunctionalityCode())){
  56. AflApplicationFunction byProductCode = aflApplicationFunctionRepo.findByFunctionalityCode(request.getFunctionalityCode());
  57. if (byProductCode!=null){
  58. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在应用功能配置,不允许重复,请核实");
  59. }
  60. }
  61. BeanUtils.copyProperties(request,aflApplicationFunction);
  62. aflApplicationFunction.setUpdator(request.getUpdator());
  63. aflApplicationFunction.setUpdateTime(LocalDateTime.now());
  64. aflApplicationFunctionRepo.save(aflApplicationFunction);
  65. }
  66. @Override
  67. public void delete(AflApplicationFunctionDeleteRequest request) throws ServiceHandleException {
  68. if (StringUtils.isEmpty(request.getUpdator())){
  69. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
  70. }
  71. AflApplicationFunction aflApplicationFunction = findById(request.getId());
  72. aflApplicationFunction.setIsDelete(IsDeleteEnum.YES.getCode());
  73. aflApplicationFunction.setUpdator(request.getUpdator());
  74. aflApplicationFunction.setUpdateTime(LocalDateTime.now());
  75. try {
  76. aflApplicationFunctionRepo.save(aflApplicationFunction);
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用功能管理配置删除错误。");
  80. }
  81. }
  82. @Override
  83. public void updateStatus(AflApplicationFunctionUpdateStatusRequest request) throws ServiceHandleException {
  84. AflApplicationFunction aflApplicationFunction = findById(request.getId());
  85. if (aflApplicationFunction.getStatus()==request.getStatus()||request.getStatus()==null) {
  86. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态没有发生改变");
  87. }
  88. aflApplicationFunction.setStatus(request.getStatus());
  89. aflApplicationFunction.setUpdator(request.getUpdator());
  90. aflApplicationFunction.setUpdateTime(LocalDateTime.now());
  91. aflApplicationFunctionRepo.save(aflApplicationFunction);
  92. }
  93. public AflApplicationFunction findById(String id) throws ServiceHandleException {
  94. if (StringUtils.isEmpty(id)) {
  95. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请输入应用管理配置编号");
  96. }
  97. AflApplicationFunction aflApplicationFunction = aflApplicationFunctionRepo.findByIdAndIsDelete(id);
  98. if (null == aflApplicationFunction) {
  99. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用管理配置不存在");
  100. }
  101. return aflApplicationFunction;
  102. }
  103. private void verify(AflApplicationFunctionSaveOrUpdateRequest request) throws ServiceHandleException {
  104. if (StringUtils.isEmpty(request.getApplicationCode())) {
  105. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用编码不能为空");
  106. }
  107. if (StringUtils.isEmpty(request.getFunctionalityCode())) {
  108. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("功能编号不能为空");
  109. }
  110. }
  111. @Override
  112. public String export(AflApplicationFunctionFindPageViewRequest request, Logger logger) throws ServiceHandleException {
  113. String pathFile =null;
  114. try {
  115. List<AflApplicationFunctionVo> aflMobileApplicationInfos = select(request);
  116. if (aflMobileApplicationInfos==null||aflMobileApplicationInfos.size()==0) {
  117. pathFile = ExcelUtils.export(null, "应用功能配置",constantConfig.getFilePath() ,null, AflApplicationFunctionVo.class);
  118. } else {
  119. logger.info("选装-应用功能配置导出返回参数:{}",aflMobileApplicationInfos.toString());
  120. pathFile = ExcelUtils.export(null, "应用功能配置",constantConfig.getFilePath(), aflMobileApplicationInfos, AflApplicationFunctionVo.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. private List<AflApplicationFunctionVo> select(AflApplicationFunctionFindPageViewRequest request) {
  154. AflApplicationFunctionFindPageRequest queryRequest = new AflApplicationFunctionFindPageRequest();
  155. BeanUtil.copyProperties(request, queryRequest);
  156. return aflApplicationFunctionRepo.list(queryRequest);
  157. }
  158. }