123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- package com.qtzl.alterSales.manager.service;
-
- import cn.com.taiji.common.manager.net.http.ServiceHandleException;
- import cn.hutool.core.bean.BeanUtil;
- import com.qtzl.alterSales.dao.entity.second.AflApplicationFunction;
- import com.qtzl.alterSales.dao.repo.jpa.second.AflApplicationFunctionRepo;
- import com.qtzl.alterSales.manager.enums.IsDeleteEnum;
- import com.qtzl.alterSales.manager.enums.StatusEnum;
- import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
- import com.qtzl.alterSales.manager.model.protocol.sales.*;
- import com.qtzl.alterSales.manager.service.third.ConstantConfig;
- import com.qtzl.alterSales.manager.service.third.FmsService;
- import com.qtzl.alterSales.manager.tools.ExcelUtils;
- import com.qtzl.alterSales.manager.vo.AflApplicationFunctionVo;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
-
- import javax.annotation.Resource;
- import java.io.File;
- import java.time.LocalDateTime;
- import java.util.List;
-
- @Service
- public class AflApplicationFunctionServiceImpl implements AflApplicationFunctionService {
-
- @Resource
- AflApplicationFunctionRepo aflApplicationFunctionRepo;
-
- @Resource
- FmsService fmsService;
-
- @Resource
- ConstantConfig constantConfig;
-
- @Override
- public void save(AflApplicationFunctionSaveOrUpdateRequest request) throws ServiceHandleException {
- if (StringUtils.isEmpty(request.getCreator())) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("创建人不能为空");
- }
- verify(request);
- AflApplicationFunction aflApplicationFunction = aflApplicationFunctionRepo.findByFunctionalityCode(request.getFunctionalityCode());
- if (null != aflApplicationFunction) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在应用功能管理配置,不允许重复,请核实");
- }
- aflApplicationFunction = new AflApplicationFunction();
- BeanUtils.copyProperties(request, aflApplicationFunction);
- if (request.getStatus()==null){
- aflApplicationFunction.setStatus(StatusEnum.ENABLE.getCode());
- }
- aflApplicationFunction.setIsDelete(IsDeleteEnum.NO.getCode());
- aflApplicationFunctionRepo.save(aflApplicationFunction);
- }
-
- @Override
- public void update(AflApplicationFunctionSaveOrUpdateRequest request) throws ServiceHandleException {
- if (StringUtils.isEmpty(request.getUpdator())){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
- }
- verify(request);
- AflApplicationFunction aflApplicationFunction = findById(request.getId());
- if (!aflApplicationFunction.getFunctionalityCode().equals(request.getFunctionalityCode())){
- AflApplicationFunction byProductCode = aflApplicationFunctionRepo.findByFunctionalityCode(request.getFunctionalityCode());
- if (byProductCode!=null){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("已存在应用功能配置,不允许重复,请核实");
- }
- }
- BeanUtils.copyProperties(request,aflApplicationFunction);
- aflApplicationFunction.setUpdator(request.getUpdator());
- aflApplicationFunction.setUpdateTime(LocalDateTime.now());
- aflApplicationFunctionRepo.save(aflApplicationFunction);
- }
-
- @Override
- public void delete(AflApplicationFunctionDeleteRequest request) throws ServiceHandleException {
- if (StringUtils.isEmpty(request.getUpdator())){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("修改人不能为空");
- }
- AflApplicationFunction aflApplicationFunction = findById(request.getId());
- aflApplicationFunction.setIsDelete(IsDeleteEnum.YES.getCode());
- aflApplicationFunction.setUpdator(request.getUpdator());
- aflApplicationFunction.setUpdateTime(LocalDateTime.now());
- try {
- aflApplicationFunctionRepo.save(aflApplicationFunction);
- } catch (Exception e) {
- e.printStackTrace();
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用功能管理配置删除错误。");
- }
- }
-
- @Override
- public void updateStatus(AflApplicationFunctionUpdateStatusRequest request) throws ServiceHandleException {
- AflApplicationFunction aflApplicationFunction = findById(request.getId());
- if (aflApplicationFunction.getStatus()==request.getStatus()||request.getStatus()==null) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态没有发生改变");
- }
- aflApplicationFunction.setStatus(request.getStatus());
- aflApplicationFunction.setUpdator(request.getUpdator());
- aflApplicationFunction.setUpdateTime(LocalDateTime.now());
- aflApplicationFunctionRepo.save(aflApplicationFunction);
- }
-
- public AflApplicationFunction findById(String id) throws ServiceHandleException {
- if (StringUtils.isEmpty(id)) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请输入应用管理配置编号");
- }
- AflApplicationFunction aflApplicationFunction = aflApplicationFunctionRepo.findByIdAndIsDelete(id);
- if (null == aflApplicationFunction) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用管理配置不存在");
- }
- return aflApplicationFunction;
- }
-
- private void verify(AflApplicationFunctionSaveOrUpdateRequest request) throws ServiceHandleException {
-
- if (StringUtils.isEmpty(request.getApplicationCode())) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用编码不能为空");
- }
- if (StringUtils.isEmpty(request.getFunctionalityCode())) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("功能编号不能为空");
- }
-
- }
-
- @Override
- public String export(AflApplicationFunctionFindPageViewRequest request, Logger logger) throws ServiceHandleException {
- String pathFile =null;
- try {
- List<AflApplicationFunctionVo> aflMobileApplicationInfos = select(request);
- if (aflMobileApplicationInfos==null||aflMobileApplicationInfos.size()==0) {
- pathFile = ExcelUtils.export(null, "应用功能配置",constantConfig.getFilePath() ,null, AflApplicationFunctionVo.class);
- } else {
- logger.info("选装-应用功能配置导出返回参数:{}",aflMobileApplicationInfos.toString());
- pathFile = ExcelUtils.export(null, "应用功能配置",constantConfig.getFilePath(), aflMobileApplicationInfos, AflApplicationFunctionVo.class);
- }
- if (StringUtils.isEmpty(pathFile)){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用功能配置导出失败");
- }
- String s = null;
- try {
- s = fmsService.uploadFile(constantConfig.getUploadFile(),pathFile, 90000);
- } catch (ServiceHandleException e) {
- logger.error("选装-应用功能配置导出失败:{}", e.getMessage());
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
- }
-
- if (StringUtils.isEmpty(s)){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用功能配置导出失败");
- }
- return s;
- } catch (Exception e) {
- if (e instanceof ServiceHandleException) {
- throw e;
- }
- logger.error("选装-应用功能配置导出失败:{}", e.getMessage());
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("应用功能配置导出失败");
- }finally {
- File file = null;
- try {
- file = new File(pathFile);
- } catch (Exception e) {
- }
- if (file!=null){
- file.delete();
- }
- }
- }
- private List<AflApplicationFunctionVo> select(AflApplicationFunctionFindPageViewRequest request) {
- AflApplicationFunctionFindPageRequest queryRequest = new AflApplicationFunctionFindPageRequest();
- BeanUtil.copyProperties(request, queryRequest);
- return aflApplicationFunctionRepo.list(queryRequest);
- }
- }
|