package com.securitycontrol.system.base.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.securitycontrol.common.core.constant.Constant;
import com.securitycontrol.common.core.constant.HttpStatus;
import com.securitycontrol.common.core.constant.SecurityConstants;
import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.common.core.utils.ImportExcelUtils;
import com.securitycontrol.common.core.utils.StringUtils;
import com.securitycontrol.common.core.utils.aes.DateTimeHelper;
import com.securitycontrol.common.core.utils.uuid.IdUtils;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.security.utils.ValidatorsUtils;
import com.securitycontrol.entity.system.base.dto.GxPlanDto;
import com.securitycontrol.entity.system.base.dto.ProDto;
import com.securitycontrol.entity.system.base.dto.ProGxPlanDto;
import com.securitycontrol.entity.system.base.vo.GxPlanVo;
import com.securitycontrol.entity.system.base.vo.ProImportVo;
import com.securitycontrol.entity.system.base.vo.ProVo;
import com.securitycontrol.entity.system.vo.ResourceFileVo;
import com.securitycontrol.system.api.RemoteFileService;
import com.securitycontrol.system.api.domain.SysFile;
import com.securitycontrol.system.base.mapper.IProMapper;
import com.securitycontrol.system.base.service.IProService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

import static com.securitycontrol.common.core.utils.uuid.IdUtils.*;

/**
 * @author：cwchen
 * @date：2024-03-11-10:11
 * @version：1.0
 * @description：工程管理-业务逻辑层
 */
@Service(value = "IProService")
@Slf4j
public class ProServiceImpl implements IProService {

    @Resource(name = "IProMapper")
    private IProMapper mapper;

    @Resource(name = "ValidatorsUtils")
    private ValidatorsUtils validatorsUtils;


    @Value("${file.temp_file_path}")
    private String tempFilePath;

    @Autowired
    private RemoteFileService remoteFileService;

    private Map<String, Map<String, String>> proStatusList = new HashMap<>(16);


    @Override
    public List<ProVo> getProLists(ProDto dto) {
        List<ProVo> list = new ArrayList<>();
        try {
            list = mapper.getProLists(dto);
            list.forEach(item -> {
                List<Integer> fileNums = mapper.getProFiles(item.getProId());
                item.setProImgFileNum(fileNums.get(0));
                item.setProFileNum(fileNums.get(1));
            });
        } catch (Exception e) {
            log.error("获取工程列表",e);
        }
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addOrUpdatePro(MultipartFile[] files, int[] types, String params) {
        List<String> uploadFiles = new ArrayList<>();
        try {
            ProVo vo = JSON.parseObject(params, ProVo.class);
            String validResult = validatorsUtils.valid(vo, ProVo.Query.class);
            if (StringUtils.isNotBlank(validResult)) {
                return AjaxResult.error(validResult);
            }
            String proId = getUUId();
            int result = mapper.proIsExist(vo);
            if (result > 0) {
                return AjaxResult.error("标段编码已存在");
            }
            if (StringUtils.isBlank(vo.getProId())) {
                if (files == null || types == null) {
                    return AjaxResult.error("图片未上传");
                }
                vo.setType(1);
                vo.setProId(proId);
            } else {
                vo.setType(2);
                if (StringUtils.isNotEmpty(vo.getDelFiles())) {
                    String[] delFiles = vo.getDelFiles().split(",");
                    for (String fileId : delFiles) {
                        mapper.delFile(fileId);
                        remoteFileService.delFile(fileId, SecurityConstants.INNER);
                    }
                }
            }
            // 上传文件
            if (files != null && types != null) {
                Result uploadResult = remoteFileService.mostUploadFile(files, SecurityConstants.INNER);
                if (uploadResult != null && uploadResult.getCode() == HttpStatus.ERROR) {
                    log.error("工程文件上传失败");
                } else if (uploadResult != null && uploadResult.getCode() == HttpStatus.SUCCESS && uploadResult.getData() != null) {
                    String jsonString = JSON.toJSONString(uploadResult.getData());
                    JSONArray jsonArray = JSON.parseArray(jsonString);
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JSONObject item = jsonArray.getJSONObject(i);
                        int type = types[i];
                        if (item != null) {
                            uploadFiles.add(item.getString("fileId"));
                            ResourceFileVo fileVo = new ResourceFileVo();
                            String resourceId = getUUId();
                            fileVo.setResourceId(resourceId);
                            fileVo.setFileType(1);
                            fileVo.setFileId(item.getString("fileId"));
                            fileVo.setFileSuffix(item.getString("suffix"));
                            fileVo.setFileName(item.getString("fileName"));
                            fileVo.setSourceId(vo.getType() == 1 ? proId : vo.getProId());
                            fileVo.setUpdateTime(DateTimeHelper.getNowTime());
                            fileVo.setSourceType(type == 1 ? "工程图片" : "工程平面图");
                            mapper.addFiles(fileVo);
                        }
                    }
                }
            }
            // 保存工程数据
            mapper.addOrUpdatePro(vo);
        } catch (Exception e) {
            log.error("新增/修改工程", e);
            // 删除文件
            if (CollectionUtils.isNotEmpty(uploadFiles)) {
                uploadFiles.forEach(item -> {
                    if (item != null) {
                        remoteFileService.delFile(item, SecurityConstants.INNER);
                    }
                });
            }
            //手动回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    @Override
    public AjaxResult getProById(ProDto dto) {
        ProVo vo = new ProVo();
        try {
            vo = mapper.getProById(dto);
            List<ResourceFileVo> resourceFileVos = mapper.getFiles(vo.getProId());
            if (CollectionUtils.isNotEmpty(resourceFileVos)) {
                List<ProVo.FileData> list = new ArrayList<>();
                for (ResourceFileVo fileVo : resourceFileVos) {
                    String base64 = null;
                    Result<SysFile> result = remoteFileService.getImgBase64(fileVo.getFileId(), SecurityConstants.INNER);
                    if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
                        String jsonString = JSON.toJSONString(result.getData());
                        JSONObject item = JSON.parseObject(jsonString);
                        base64 = item.getString("url");
                    }
                    ProVo.FileData fileData = new ProVo.FileData();
                    fileData.setFileId(fileVo.getFileId());
                    fileData.setBase64Url(base64);
                    fileData.setFileSourceType(fileVo.getSourceType());
                    list.add(fileData);
                }
                vo.setFileData(list);
            }
        } catch (Exception e) {
            log.error("工程详情",e);
        }
        return AjaxResult.success(vo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult delPro(ProDto dto) {
        try {
            if (StringUtils.isEmpty(dto.getProId()) || StringUtils.isEmpty(dto.getBidCode())) {
                return AjaxResult.error("参数不完整");
            }
            int num = mapper.isHasGxPlan(dto);
            if (num > 0) {
                return AjaxResult.error("工程下包含工序计划");
            }
            mapper.delPro(dto);
            // 查询工程文件
            List<ResourceFileVo> files = mapper.getFiles(dto.getProId());
            if (CollectionUtils.isNotEmpty(files)) {
                files.forEach(item -> {
                    mapper.delFile(item.getFileId());
                    remoteFileService.delFile(item.getFileId(), SecurityConstants.INNER);
                });
            }

        } catch (Exception e) {
            log.error("删除工程", e);
            //手动回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult delProGxPlan(ProGxPlanDto dto) {
        try {
            mapper.delProGxPlan(dto);
        } catch (Exception e) {
            log.error("删除工程工序计划", e);
            //手动回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return AjaxResult.success();
    }

    @Override
    public AjaxResult viewProFile(ProDto dto) {
        List<ProVo.FileData> list = new ArrayList<>();
        try {
            List<ResourceFileVo> resourceFileVos = mapper.getFiles(dto.getProId());
            if (CollectionUtils.isNotEmpty(resourceFileVos)) {
                for (ResourceFileVo fileVo : resourceFileVos) {
                    if (Objects.equals(dto.getFileType(), fileVo.getSourceType())) {
                        String base64 = null;
                        Result<SysFile> result = remoteFileService.getImgBase64(fileVo.getFileId(), SecurityConstants.INNER);
                        if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
                            String jsonString = JSON.toJSONString(result.getData());
                            JSONObject item = JSON.parseObject(jsonString);
                            base64 = item.getString("url");
                        }
                        ProVo.FileData fileData = new ProVo.FileData();
                        fileData.setFileId(fileVo.getFileId());
                        fileData.setBase64Url(base64);
                        fileData.setFileSourceType(fileVo.getSourceType());
                        list.add(fileData);
                    }
                }
            }
        } catch (Exception e) {
            log.error("工程图片/平面图预览",e);
        }
        return AjaxResult.success(list);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult importProData(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        List<String> errorList = new ArrayList<>();
        try {
            List<JSONObject> lstObj = (List<JSONObject>) ImportExcelUtils.readExcel(file, ProImportVo.class, tempFilePath);
            List<JSONObject> lstError = new ArrayList<>();
            List<ProImportVo> list = new ArrayList<>();
            if (lstObj != null && lstObj.size() > 0) {
                lstError = getLstError(lstObj);
                if (CollectionUtils.isNotEmpty(lstError)) {
                    return AjaxResult.error("excel数据有误，请仔细检查", lstError);
                }
                proStatusList = mapper.getProStatus();
                for (JSONObject obj : lstObj) {
                    ProImportVo vo = new ProImportVo();
                    ProVo proVo = new ProVo();
                    vo = setProData(vo, obj);
                    BeanUtils.copyProperties(vo, proVo);
                    if (vo.getFile() != null) {
                        Result result = remoteFileService.singleUploadFile(vo.getFile(), SecurityConstants.INNER);
                        if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
                            String jsonString = JSON.toJSONString(result.getData());
                            JSONObject item = JSON.parseObject(jsonString);
                            if (item != null) {
                                errorList.add(item.getString("fileId"));
                                ResourceFileVo fileVo = setResourceData(item, vo.getProId(), 2);
                                mapper.addFiles(fileVo);
                            }
                        }
                    }
                    List<MultipartFile> files = vo.getFiles();
                    if (CollectionUtils.isNotEmpty(files)) {
                        for (MultipartFile multipartFile : files) {
                            Result result = remoteFileService.singleUploadFile(multipartFile, SecurityConstants.INNER);
                            if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
                                String jsonString = JSON.toJSONString(result.getData());
                                JSONObject item = JSON.parseObject(jsonString);
                                if (item != null) {
                                    errorList.add(item.getString("fileId"));
                                    ResourceFileVo fileVo = setResourceData(item, vo.getProId(), 1);
                                    mapper.addFiles(fileVo);
                                }
                            }
                        }
                    }
                    mapper.addOrUpdatePro(proVo);
                }
            }
        } catch (Exception e) {
            log.error("工程文件导入", e);
            // 删除文件
            if (CollectionUtils.isNotEmpty(errorList)) {
                errorList.forEach(item -> {
                    remoteFileService.delFile(item,SecurityConstants.INNER);
                });
            }
            //手动回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }


    public List<JSONObject> getLstError(List<JSONObject> lstObj) {
        List<JSONObject> lstError = new ArrayList<>();
        for (JSONObject obj : lstObj) {
            JSONObject errorObj0 = validateData(obj, "proName", "工程名称", 50, 0);
            if (errorObj0 != null) {
                lstError.add(errorObj0);
                continue;
            }
            JSONObject errorObj = validateData(obj, "org", "建管单位", 0, 0);
            if (errorObj != null) {
                lstError.add(errorObj);
                continue;
            }
            JSONObject errorObj2 = validateData(obj, "bidCode", "标段编码", 50, 1);
            if (errorObj2 != null) {
                lstError.add(errorObj2);
                continue;
            }

            JSONObject errorObj3 = validateData(obj, "signCode", "单项编码", 50, 0);
            if (errorObj3 != null) {
                lstError.add(errorObj3);
                continue;
            }
            JSONObject errorObj4 = validateData(obj, "proCode", "工程编码", 50, 0);
            if (errorObj4 != null) {
                lstError.add(errorObj4);
                continue;
            }
            JSONObject errorObj5 = validateData(obj, "proCost", "工程成本", 50, 0);
            if (errorObj5 != null) {
                lstError.add(errorObj5);
                continue;
            }
            JSONObject errorObj6 = validateData(obj, "sgUnit", "施工单位", 30, 0);
            if (errorObj6 != null) {
                lstError.add(errorObj6);
                continue;
            }
            JSONObject errorObj7 = validateData(obj, "jlUnit", "监理单位", 30, 0);
            if (errorObj7 != null) {
                lstError.add(errorObj7);
                continue;
            }
            JSONObject errorObj8 = validateData(obj, "proType", "工程类型", 10, 0);
            if (errorObj8 != null) {
                lstError.add(errorObj8);
                continue;
            }
            JSONObject errorObj9 = validateData(obj, "proScale", "工程规模", 300, 0);
            if (errorObj9 != null) {
                lstError.add(errorObj9);
                continue;
            }
            JSONObject errorObj10 = validateData(obj, "manager", "项目经理", 10, 0);
            if (errorObj10 != null) {
                lstError.add(errorObj10);
                continue;
            }
            JSONObject errorObj11 = validateData(obj, "proBrief", "工程简介", 0, 0);
            if (errorObj11 != null) {
                lstError.add(errorObj11);
                continue;
            }
            JSONObject errorObj12 = validateData(obj, "status", "工程状态", 10, 0);
            if (errorObj12 != null) {
                lstError.add(errorObj12);
                continue;
            }
            JSONObject errorObj13 = validateData(obj, "planStartTime", "计划开始时间", 0, 0);
            if (errorObj13 != null) {
                lstError.add(errorObj13);
                continue;
            }
        }
        return lstError;
    }

    public JSONObject validateData(JSONObject obj, String dataValue, String dataName, int length, int type) {
        if (StringUtils.isBlank(obj.getString(dataValue))) {
            JSONObject error = new JSONObject();
            error.put("errorRow", obj.getString("rowNo"));
            error.put("errorLine", dataName);
            error.put("errorData", "");
            error.put("errorMsg", dataName + "不能为空");
            return error;
        }
        if (StringUtils.isNotEmpty(obj.getString(dataValue)) && obj.getString(dataValue).length() > length && length > 0) {
            JSONObject error = new JSONObject();
            error.put("errorRow", obj.getString("rowNo"));
            error.put("errorLine", dataName);
            error.put("errorData", obj.getString(dataValue));
            error.put("errorMsg", dataName + "字符长度不能超过" + length);
            return error;
        }
        if (StringUtils.isNotEmpty(obj.getString(dataValue)) && type > 0) {
            ProVo proVo = new ProVo();
            proVo.setBidCode(obj.getString(dataValue));
            int result = mapper.proIsExist(proVo);
            if (result > 0) {
                JSONObject error = new JSONObject();
                error.put("errorRow", obj.getString("rowNo"));
                error.put("errorLine", dataName);
                error.put("errorData", obj.getString(dataValue));
                error.put("errorMsg", dataName + "已存在");
                return error;
            }
        }
        return null;
    }

    public ProImportVo setProData(ProImportVo vo, JSONObject obj) {
        String proId = getUUId();
        vo.setProId(proId);
        vo.setOrg(getBuildCode(obj.getString("org")));
        vo.setBidCode(obj.getString("bidCode"));
        vo.setSignCode(obj.getString("signCode"));
        vo.setProCode(obj.getString("proCode"));
        vo.setProName(obj.getString("proName"));
        vo.setProCost(obj.getString("proCost"));
        vo.setSgUnit(obj.getString("sgUnit"));
        vo.setJlUnit(obj.getString("jlUnit"));
        vo.setProType(obj.getString("proType"));
        vo.setProScale(obj.getString("proScale"));
        vo.setManager(obj.getString("manager"));
        vo.setProBrief(obj.getString("proBrief"));
        Map<String, String> map = proStatusList.get(obj.getString("status"));
        if(map !=null){
            vo.setStatus(String.valueOf(map.get("id")));
        }
        vo.setPlanStartTime(obj.getString("planStartTime"));
        vo.setPlanEndTime(obj.getString("planEndTime"));
        vo.setStartTime(obj.getString("startTime"));
        vo.setEndTime(obj.getString("endTime"));
        vo.setBidType(getBidAndSubType(obj.getString("bidType"),1));
        vo.setSgManage(obj.getString("sgManage"));
        vo.setJlManage(obj.getString("jlManage"));
        vo.setSubType(getBidAndSubType(obj.getString("subType"),2));
        vo.setTcDate(obj.getString("tcDate"));
        vo.setFile(obj.get("file") != null ? (MultipartFile) obj.get("file") : null);
        List<MultipartFile> files = new ArrayList<MultipartFile>();
        if (obj.get(Constant.FILE_2) != null) {
            files.add((MultipartFile) obj.get(Constant.FILE_2));
        }
        if (obj.get(Constant.FILE_3) != null) {
            files.add((MultipartFile) obj.get(Constant.FILE_3));
        }
        if (obj.get(Constant.FILE_4) != null) {
            files.add((MultipartFile) obj.get(Constant.FILE_4));
        }
        if (obj.get(Constant.FILE_5) != null) {
            files.add((MultipartFile) obj.get(Constant.FILE_5));
        }
        if (obj.get(Constant.FILE_6) != null) {
            files.add((MultipartFile) obj.get(Constant.FILE_6));
        }
        if (obj.get(Constant.FILE_7) != null) {
            files.add((MultipartFile) obj.get(Constant.FILE_7));
        }
        vo.setFiles(files);
        vo.setType(1);
        return vo;
    }

    public ResourceFileVo setResourceData(JSONObject item, String proId, int type) {
        ResourceFileVo fileVo = new ResourceFileVo();
        String resourceId = getUUId();
        fileVo.setResourceId(resourceId);
        fileVo.setFileType(1);
        fileVo.setFileId(item.getString("fileId"));
        fileVo.setFileSuffix(item.getString("suffix"));
        fileVo.setFileName(item.getString("fileName"));
        fileVo.setSourceId(proId);
        fileVo.setUpdateTime(DateTimeHelper.getNowTime());
        fileVo.setSourceType(type == 1 ? "工程图片" : "工程平面图");
        return fileVo;
    }

    public static String getBuildCode(String buildName) {
        if (!StringUtils.isEmpty(buildName)) {
            for (String build : Constant.BUILD_ARR) {
                if (build.contains(buildName)) {
                    return build.split(",")[0];
                }
            }
        }
        return null;
    }

    public static String getBidAndSubType(String name,int type) {
        if (!StringUtils.isEmpty(name)) {
            for (String value : type == 1 ? Constant.BID_TYPE_ARR : Constant.SUB_TYPE_ARR) {
                if (value.contains(name)) {
                    return value.split(",")[0];
                }
            }
        }
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult editProStatus(ProVo vo) {
        try {
            mapper.editProStatus(vo);
        } catch (Exception e) {
            log.error("工程完工", e);
            //手动回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    @Override
    public List<GxPlanVo> getGxPlanLists(GxPlanDto dto) {
        List<GxPlanVo> list = new ArrayList<>();
        try {
            list = mapper.getGxPlanLists(dto);
        } catch (Exception e) {
            log.error("获取工序列表",e);
        }
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addOrUpdateGxPlan(GxPlanVo vo) {
        try {
            String validResult = validatorsUtils.valid(vo, GxPlanVo.Query.class);
            if (StringUtils.isNotBlank(validResult)) {
                return AjaxResult.error(validResult);
            }
            int result = mapper.getTowerIsExist(vo);
            if(result > 0){
                return AjaxResult.error("杆塔或工序不能重复选择");
            }
            List<Map<String, String>> weightList = mapper.getGxWeight(vo.getBidCode());
            if (CollectionUtils.isNotEmpty(weightList)) {
                Boolean isFlag = isExceedData(weightList, vo.getPlanId(), vo.getGxWeight());
                if (isFlag) {
                    return AjaxResult.error("计划作业权重超过100%");
                }
            }
            if (StringUtils.isEmpty(vo.getPlanId())) {
                String gxPlanId = getUUId();
                vo.setPlanId(gxPlanId);
                vo.setType(1);
            } else {
                vo.setType(2);
            }
            mapper.addOrUpdateGxPlan(vo);
        } catch (Exception e) {
            log.error("工序计划", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    /**
     * 计算计划权重占比
     *
     * @param weightList
     * @param planId
     * @param gxWeightData
     * @return Boolean
     * @description
     * @author cwchen
     * @date 2024/3/20 9:52
     */
    public static Boolean isExceedData(List<Map<String, String>> weightList, String planId, String gxWeightData) {
        BigDecimal data = BigDecimal.valueOf(0);
        for (Map<String, String> map : weightList) {
            String gxWeight = map.get("gxWeight");
            String id = map.get("planId");
            if (isNumeric(gxWeight)) {
                if (StringUtils.isEmpty(planId)) {
                    BigDecimal value = BigDecimal.valueOf(Double.parseDouble(gxWeight));
                    data = data.add(value);
                } else if (StringUtils.isNotEmpty(planId) && !Objects.equals(planId, id)) {
                    BigDecimal value = BigDecimal.valueOf(Double.parseDouble(gxWeight));
                    data = data.add(value);
                }
            }
        }
        if (isNumeric(gxWeightData)) {
            BigDecimal value = BigDecimal.valueOf(Double.parseDouble(gxWeightData));
            data = data.add(value);
        }
        if (data.doubleValue() > Constant.MAX_VALUE) {
            return true;
        }
        return false;
    }

    /**
     * 判断字符串是否为数字
     *
     * @param str
     * @return boolean
     * @description
     * @author cwchen
     * @date 2024/3/20 9:56
     */
    public static boolean isNumeric(String str) {
        try {
            Double.parseDouble(str);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    @Override
    public AjaxResult getGxPlanById(GxPlanDto dto) {
        GxPlanVo vo = new GxPlanVo();
        try {
            vo = mapper.getGxPlanById(dto);
        } catch (Exception e) {
            log.error("工序计划详情",e);
        }
        return AjaxResult.success(vo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult delGxPlanById(GxPlanDto dto) {
        try {
            int result = mapper.hasGxProgress(dto);
            if (result > 0) {
                return AjaxResult.error("当前工序计划存在填报进度");
            }
            mapper.delGxPlanById(dto);
        } catch (Exception e) {
            log.error("工序计划", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }
}
