package com.yeejoin.amos.boot.module.jg.biz.edit.process.equip;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.utils.SnowflakeIdUtil;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.common.api.enums.CylinderTypeEnum;
import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgUseInfoServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.*;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquCodeTypeEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;

import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class EquipChangeDataUpdateServiceImpl {

    private final ESEquipmentCategory esEquipmentCategory;

    private final IdxBizJgDesignInfoMapper idxBizJgDesignInfoMapper;

    private final IdxBizJgFactoryInfoMapper jgFactoryInfoMapper;

    private final IdxBizJgRegisterInfoMapper idxBizJgRegisterInfoMapper;

    private final IdxBizJgOtherInfoMapper idxBizJgOtherInfoMapper;

    private final CommonMapper commonMapper;

    private final EquipmentCategoryMapper equipmentCategoryMapper;

    private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService;

    private final InspectionDetectionInfoMapper inspectionDetectionInfoMapper;

    private final SnowflakeIdUtil sequence;

    public void updateRegisterChangeData(String record, EquipRegisterChangeDataDto registerChangeDataDto) {
        LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(IdxBizJgRegisterInfo::getRecord, record);
        updateWrapper.set(IdxBizJgRegisterInfo::getEquCodeType, registerChangeDataDto.getEquCodeType());
        updateWrapper.set(IdxBizJgRegisterInfo::getEquCode, registerChangeDataDto.getEquCode());
        updateWrapper.set(IdxBizJgRegisterInfo::getEquCategory, registerChangeDataDto.getEquCategory());
        updateWrapper.set(IdxBizJgRegisterInfo::getEquDefine, registerChangeDataDto.getEquDefine());
        updateWrapper.set(IdxBizJgRegisterInfo::getProductName, registerChangeDataDto.getProductName());
        updateWrapper.set(IdxBizJgRegisterInfo::getEquType, registerChangeDataDto.getEquType());
        updateWrapper.set(IdxBizJgRegisterInfo::getEquPrice, registerChangeDataDto.getEquPrice());
        updateWrapper.set(IdxBizJgRegisterInfo::getProductPhoto, registerChangeDataDto.getProductPhoto());
        updateWrapper.set(IdxBizJgRegisterInfo::getOtherAccessoriesReg, registerChangeDataDto.getOtherAccessoriesReg());
        updateWrapper.set(IdxBizJgRegisterInfo::getInstallationIsComplete, registerChangeDataDto.getInstallationIsComplete());
        updateWrapper.set(IdxBizJgRegisterInfo::getTag1, registerChangeDataDto.getTag1());
        idxBizJgRegisterInfoMapper.update(null, updateWrapper);
        updateRegisterEsData(record, registerChangeDataDto);
    }


    public void updateDesignChangeData(String record, EquipDesignChangeDataDto equipDesignChangeDataDto) {
        LambdaUpdateWrapper<IdxBizJgDesignInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(IdxBizJgDesignInfo::getRecord, record);
        updateWrapper.set(IdxBizJgDesignInfo::getDesignDate, equipDesignChangeDataDto.getDesignDate());
        updateWrapper.set(IdxBizJgDesignInfo::getDesignDoc, equipDesignChangeDataDto.getDesignDoc());
        updateWrapper.set(IdxBizJgDesignInfo::getDesignUnitCreditCode, equipDesignChangeDataDto.getDesignUnitCreditCode());
        updateWrapper.set(IdxBizJgDesignInfo::getDesignUnitName, equipDesignChangeDataDto.getDesignUnitName());
        updateWrapper.set(IdxBizJgDesignInfo::getDesignUseDate, equipDesignChangeDataDto.getDesignUseDate());
        updateWrapper.set(IdxBizJgDesignInfo::getDesignLicenseNum, equipDesignChangeDataDto.getDesignLicenseNum());
        updateWrapper.set(IdxBizJgDesignInfo::getAppraisalUnit, equipDesignChangeDataDto.getAppraisalUnit());
        updateWrapper.set(IdxBizJgDesignInfo::getOtherAccessoriesDes, equipDesignChangeDataDto.getOtherAccessoriesDes());
        updateWrapper.set(IdxBizJgDesignInfo::getAppraisalDate, equipDesignChangeDataDto.getAppraisalDate());
        updateWrapper.set(IdxBizJgDesignInfo::getDrawingDo, equipDesignChangeDataDto.getDrawingDo());
        updateWrapper.set(IdxBizJgDesignInfo::getDesignStandard, equipDesignChangeDataDto.getDesignStandard());
        updateWrapper.set(equipDesignChangeDataDto.getDesignIsComplete() != null, IdxBizJgDesignInfo::getDesignIsComplete, equipDesignChangeDataDto.getDesignIsComplete());
        idxBizJgDesignInfoMapper.update(null, updateWrapper);
    }

    public void updateFactoryChangeData(String record, EquipFactoryChangeDataDto equipFactoryChangeDataDto) {
        LambdaUpdateWrapper<IdxBizJgFactoryInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(IdxBizJgFactoryInfo::getRecord, record);
        // 影响设备代码的生成
        updateWrapper.set(IdxBizJgFactoryInfo::getProduceDate, StringUtils.isNotEmpty(equipFactoryChangeDataDto.getProduceDate()) ? DateUtil.parse(equipFactoryChangeDataDto.getProduceDate(), "yyyy-MM-dd") : null);
        updateWrapper.set(IdxBizJgFactoryInfo::getProduceUnitName, equipFactoryChangeDataDto.getProduceUnitName());
        updateWrapper.set(IdxBizJgFactoryInfo::getProduceCountry, equipFactoryChangeDataDto.getProduceCountry());
        updateWrapper.set(IdxBizJgFactoryInfo::getProduceUnitCreditCode, equipFactoryChangeDataDto.getProduceUnitCreditCode());
        updateWrapper.set(IdxBizJgFactoryInfo::getProduceLicenseNum, equipFactoryChangeDataDto.getProduceLicenseNum());
        updateWrapper.set(IdxBizJgFactoryInfo::getProductQualityYieldProve, equipFactoryChangeDataDto.getProductQualityYieldProve());
        updateWrapper.set(IdxBizJgFactoryInfo::getFactoryStandard, equipFactoryChangeDataDto.getFactoryStandard());
        updateWrapper.set(IdxBizJgFactoryInfo::getFactoryNum, equipFactoryChangeDataDto.getFactoryNum());
        updateWrapper.set(IdxBizJgFactoryInfo::getFactSupervisionInspectionReport, equipFactoryChangeDataDto.getFactSupervisionInspectionReport());
        updateWrapper.set(IdxBizJgFactoryInfo::getOtherAccessoriesFact, equipFactoryChangeDataDto.getOtherAccessoriesFact());
        updateWrapper.set(IdxBizJgFactoryInfo::getImported, equipFactoryChangeDataDto.getImported());
        updateWrapper.set(IdxBizJgFactoryInfo::getInsUseMaintainExplain, equipFactoryChangeDataDto.getInsUseMaintainExplain());
        updateWrapper.set(IdxBizJgFactoryInfo::getBoilerEnergyEfficiencyCertificate, equipFactoryChangeDataDto.getBoilerEnergyEfficiencyCertificate());
        updateWrapper.set(equipFactoryChangeDataDto.getFactoryIsComplete() != null, IdxBizJgFactoryInfo::getFactoryIsComplete, equipFactoryChangeDataDto.getFactoryIsComplete());
        jgFactoryInfoMapper.update(null, updateWrapper);
        this.updateFactoryEsData(record, equipFactoryChangeDataDto);
    }

    private void updateFactoryEsData(String record, EquipFactoryChangeDataDto equipFactoryChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setPRODUCE_DATE(equipFactoryChangeDataDto.getProduceDate());
            esEquipmentCategoryDto.setFACTORY_NUM(equipFactoryChangeDataDto.getFactoryNum());
            esEquipmentCategoryDto.setPRODUCE_UNIT_NAME(equipFactoryChangeDataDto.getProduceUnitName());
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }

    public void updateFactoryEsData(String record, IdxBizJgFactoryInfo equipFactoryChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setPRODUCE_DATE(DateUtil.formatDate(equipFactoryChangeDataDto.getProduceDate()));
            esEquipmentCategoryDto.setFACTORY_NUM(equipFactoryChangeDataDto.getFactoryNum());
            esEquipmentCategoryDto.setPRODUCE_UNIT_NAME(equipFactoryChangeDataDto.getProduceUnitName());
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }


    public void updateRegisterEsData(String record, EquipRegisterChangeDataDto registerChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setPRODUCT_NAME(registerChangeDataDto.getProductName());
            esEquipmentCategoryDto.setEQU_CODE(registerChangeDataDto.getEquCode());
            esEquipmentCategoryDto.setEQU_TYPE(registerChangeDataDto.getEquType());
            esEquipmentCategoryDto.setEQU_CATEGORY_CODE(registerChangeDataDto.getEquCategory());
            esEquipmentCategoryDto.setEQU_DEFINE_CODE(registerChangeDataDto.getEquDefine());
            esEquipmentCategoryDto.setTag1(registerChangeDataDto.getTag1());
            // 冗余设备类别名称
            if (StringUtils.isEmpty(registerChangeDataDto.getEquCategory())) {
                esEquipmentCategoryDto.setEQU_CATEGORY(null);
            } else {
                EquipmentCategory category = getEquipmentCategory(registerChangeDataDto.getEquCategory());
                if (category != null) {
                    esEquipmentCategoryDto.setEQU_CATEGORY(category.getName());
                }
            }
            // 冗余设备品种名称
            if (StringUtils.isEmpty(registerChangeDataDto.getEquDefine())) {
                esEquipmentCategoryDto.setEQU_DEFINE(null);
            } else {
                EquipmentCategory category = getEquipmentCategory(registerChangeDataDto.getEquDefine());
                if (category != null) {
                    esEquipmentCategoryDto.setEQU_DEFINE(category.getName());
                }
            }
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }

    public void updateRegisterEsData(String record, IdxBizJgRegisterInfo registerChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setPRODUCT_NAME(registerChangeDataDto.getProductName());
            esEquipmentCategoryDto.setEQU_CODE(registerChangeDataDto.getEquCode());
            esEquipmentCategoryDto.setEQU_TYPE(registerChangeDataDto.getEquType());
            esEquipmentCategoryDto.setEQU_CATEGORY_CODE(registerChangeDataDto.getEquCategory());
            esEquipmentCategoryDto.setEQU_DEFINE_CODE(registerChangeDataDto.getEquDefine());
            esEquipmentCategoryDto.setUSE_ORG_CODE(registerChangeDataDto.getUseOrgCode());
            // 冗余设备类别名称
            if (StringUtils.isEmpty(registerChangeDataDto.getEquCategory())) {
                esEquipmentCategoryDto.setEQU_CATEGORY(null);
            } else {
                EquipmentCategory category = getEquipmentCategory(registerChangeDataDto.getEquCategory());
                if (category != null) {
                    esEquipmentCategoryDto.setEQU_CATEGORY(category.getName());
                }
            }
            // 冗余设备品种名称
            if (StringUtils.isEmpty(registerChangeDataDto.getEquDefine())) {
                esEquipmentCategoryDto.setEQU_DEFINE(null);
            } else {
                EquipmentCategory category = getEquipmentCategory(registerChangeDataDto.getEquDefine());
                if (category != null) {
                    esEquipmentCategoryDto.setEQU_DEFINE(category.getName());
                }
            }
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }

    public void updateRegisterEsDataPieLine(ProjectContraptionChangeDataDto registerChangeDataDto) {
        // es 数据更新
        List<ESEquipmentCategoryDto> pieLines = esEquipmentCategory.findAllByProjectContraptionId(registerChangeDataDto.getProjectContraptionId());
        for (ESEquipmentCategoryDto esEquipmentCategoryDto : pieLines) {
            esEquipmentCategoryDto.setPROJECT_CONTRAPTION(registerChangeDataDto.getProjectContraption());
        }
        if (!pieLines.isEmpty()) {
            esEquipmentCategory.saveAll(pieLines);
        }
    }

    private EquipmentCategory getEquipmentCategory(String categoryCode) {
        return equipmentCategoryMapper.selectOne(new LambdaQueryWrapper<EquipmentCategory>().eq(EquipmentCategory::getCode, categoryCode));
    }


    public void updateTechParamByRecord(String tableName, String record, List<FieldChangeMeta> fieldChangeMetas) {
        List<DynamicColumnDto> columns = fieldChangeMetas.stream().map(c -> {
            DynamicColumnDto columnDto = new DynamicColumnDto();
            columnDto.setColumnName(String.format("\"%s\"", StrUtil.toUnderlineCase(c.getColumnKey()).toUpperCase()));
            columnDto.setColumnValue(c.getColumnNewValue());
            return columnDto;
        }).collect(Collectors.toList());
        //  sql 动态构建入库
        commonMapper.updateTechParamDynamic(tableName, record, columns);
    }

    public void checkFactoryChangeData(String record, EquipFactoryChangeDataDto equipFactoryChangeDataDto, String equList, String equCategory, String equDefine) {
        // 气瓶时检验出厂编号-普通气瓶，车用气瓶不再此范围内
        if (CylinderTypeEnum.CYLINDER.getCode().equals(equCategory) && StringUtils.isNotEmpty(equipFactoryChangeDataDto.getFactoryNum())) {
            boolean isUsed = this.checkFactoryNumUnique(equipFactoryChangeDataDto.getFactoryNum(), record, equipFactoryChangeDataDto.getProduceUnitCreditCode());
            if (isUsed) {
                throw new BadRequest("出厂编号/产品编码在该企业中已存在！");
            }
        }
    }

    public void checkFactoryChangeData(String record, IdxBizJgFactoryInfo equipFactoryChangeDataDto, String equList, String equCategory, String equDefine) {
        // 气瓶时检验出厂编号-普通气瓶，车用气瓶不再此范围内
        if (CylinderTypeEnum.CYLINDER.getCode().equals(equCategory) && StringUtils.isNotEmpty(equipFactoryChangeDataDto.getFactoryNum())) {
            boolean isUsed = this.checkFactoryNumUnique(equipFactoryChangeDataDto.getFactoryNum(), record, equipFactoryChangeDataDto.getProduceUnitCreditCode());
            if (isUsed) {
                throw new BadRequest("出厂编号/产品编码在该企业中已存在！");
            }
        }
    }

    /**
     * 普通气瓶检验-同制造单位下唯一
     *
     * @param factoryNum            出厂编号
     * @param produceUnitCreditCode 制造单位编码
     * @return 是否被占用
     */
    private boolean checkFactoryNumUnique(String factoryNum, String record, String produceUnitCreditCode) {
        return commonMapper.checkFactoryNumUnique(factoryNum, record, produceUnitCreditCode) > 0;
    }


    public void checkRegisterChangeData(String record, EquipRegisterChangeDataDto registerChangeDataDto) {
        // 自行输入时，检验设备代码的全局唯一性
        if (registerChangeDataDto.getEquCodeType().equals(EquCodeTypeEnum.INPUT.getCode()) && StringUtils.isNotEmpty(registerChangeDataDto.getEquCode())) {
            Boolean isUsed = this.checkEquCodeUniqueness(registerChangeDataDto.getEquCode(), record);
            if (isUsed) {
                throw new BadRequest("设备代码：" + registerChangeDataDto.getEquCode() + "在系统中已存在！");
            }
        }
    }

    public void checkRegisterChangeData(String record, IdxBizJgRegisterInfo registerChangeDataDto) {
        // 自行输入时，检验设备代码的全局唯一性
        if (registerChangeDataDto.getEquCodeType().equals(EquCodeTypeEnum.INPUT.getCode()) && StringUtils.isNotEmpty(registerChangeDataDto.getEquCode())) {
            Boolean isUsed = this.checkEquCodeUniqueness(registerChangeDataDto.getEquCode(), record);
            if (isUsed) {
                throw new BadRequest("设备代码：" + registerChangeDataDto.getEquCode() + "在系统中已存在！");
            }
        }
    }


    private Boolean checkEquCodeUniqueness(String equCode, String record) {
        // 根据设备代码检查唯一性
        return idxBizJgRegisterInfoMapper.selectByEquCodeAndClaimStatus(equCode, "", record) > 0;
    }

    public void checkDesignChangeData(String record, EquipDesignChangeDataDto equipDesignChangeDataDto) {
    }

    public void checkDesignChangeData(String record, IdxBizJgDesignInfo equipDesignChangeDataDto) {
    }

    public void updatePieLineDesignData(String record, PieLineDesignChangeDataDto equipDesignChangeDataDto) {
        LambdaUpdateWrapper<IdxBizJgDesignInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(IdxBizJgDesignInfo::getRecord, record);
        updateWrapper.set(IdxBizJgDesignInfo::getDesignUnitName, equipDesignChangeDataDto.getDesignUnitName());
        updateWrapper.set(IdxBizJgDesignInfo::getRecDate, new Date());
        idxBizJgDesignInfoMapper.update(null, updateWrapper);
    }

    public void updateUseInfoChangeData(String record, EquipUseInfoChangeDataDto equipUseInfoChangeDataDto) {
        LambdaUpdateWrapper<IdxBizJgUseInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(IdxBizJgUseInfo::getRecord, record);
        updateWrapper.set(IdxBizJgUseInfo::getUseUnitCreditCode, equipUseInfoChangeDataDto.getUseUnitCreditCode());
        updateWrapper.set(IdxBizJgUseInfo::getUseUnitName, equipUseInfoChangeDataDto.getUseUnitName());
        updateWrapper.set(IdxBizJgUseInfo::getUseInnerCode, equipUseInfoChangeDataDto.getUseInnerCode());
        idxBizJgUseInfoService.update(updateWrapper);
        this.updateUseInfoEsData(record, equipUseInfoChangeDataDto);
    }

    public void updateUseInfoEsData(String record, IdxBizJgUseInfo equipUseInfoChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setUSE_UNIT_CREDIT_CODE(equipUseInfoChangeDataDto.getUseUnitCreditCode());
            esEquipmentCategoryDto.setUSC_UNIT_NAME(equipUseInfoChangeDataDto.getUseUnitName());
            esEquipmentCategoryDto.setUSE_INNER_CODE(equipUseInfoChangeDataDto.getUseInnerCode());
            esEquipmentCategoryDto.setUSE_PLACE(equipUseInfoChangeDataDto.getProvinceName() + "/" + equipUseInfoChangeDataDto.getCityName() + "/" + equipUseInfoChangeDataDto.getCountyName() + "/" + equipUseInfoChangeDataDto.getStreetName());
            esEquipmentCategoryDto.setUSE_PLACE_CODE(equipUseInfoChangeDataDto.getProvince() + "#" + equipUseInfoChangeDataDto.getCity() + "#" + equipUseInfoChangeDataDto.getCounty() + "#" + equipUseInfoChangeDataDto.getFactoryUseSiteStreet());
            esEquipmentCategoryDto.setADDRESS(equipUseInfoChangeDataDto.getAddress());
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }

    private void updateUseInfoEsData(String record, EquipUseInfoChangeDataDto equipUseInfoChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setUSE_UNIT_CREDIT_CODE(equipUseInfoChangeDataDto.getUseUnitCreditCode());
            esEquipmentCategoryDto.setUSC_UNIT_NAME(equipUseInfoChangeDataDto.getUseUnitName());
            esEquipmentCategoryDto.setUSE_INNER_CODE(equipUseInfoChangeDataDto.getUseInnerCode());
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }

    public void updateOrSaveInspectInfo(String record, EquipInspectChangeDataDto equipUseInfoChangeDataDto) {
        if (equipUseInfoChangeDataDto.getJySeq() != null) {
            // 更新逻辑
            InspectionDetectionInfo inspectionDetectionInfoDb = inspectionDetectionInfoMapper.selectById(equipUseInfoChangeDataDto.getJySeq());
            String inspectionSeq = inspectionDetectionInfoDb.getSequenceNbr();
            Bean.copyExistPropertis(equipUseInfoChangeDataDto, inspectionDetectionInfoDb);
            inspectionDetectionInfoDb.setSequenceNbr(inspectionSeq);
            inspectionDetectionInfoDb.setRecord(record);
            inspectionDetectionInfoDb.setRecDate(new Date());
            inspectionDetectionInfoMapper.updateById(inspectionDetectionInfoDb);
        } else {
            // 插入逻辑
            InspectionDetectionInfo inspectionDetectionInfo = new InspectionDetectionInfo();
            Bean.copyExistPropertis(equipUseInfoChangeDataDto, inspectionDetectionInfo);
            inspectionDetectionInfo.setRecord(record);
            inspectionDetectionInfo.setRecDate(new Date());
            inspectionDetectionInfo.setSequenceNbr(sequence.nextId() + "");
            inspectionDetectionInfoMapper.insert(inspectionDetectionInfo);
        }
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            esEquipmentCategoryDto.setNEXT_INSPECT_DATE(DateUtil.parse(DateUtil.format(equipUseInfoChangeDataDto.getNextInspectDate(), DatePattern.NORM_DATE_PATTERN)).getTime());
            esEquipmentCategory.save(esEquipmentCategoryDto);
        }
    }

    public void updateInspectInfoEs(String record, IdxBizJgInspectionDetectionInfo equipUseInfoChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            if(equipUseInfoChangeDataDto.getNextInspectDate() != null) {
                esEquipmentCategoryDto.setNEXT_INSPECT_DATE(DateUtil.parse(DateUtil.format(equipUseInfoChangeDataDto.getNextInspectDate(), DatePattern.NORM_DATE_PATTERN)).getTime());
                esEquipmentCategory.save(esEquipmentCategoryDto);
            }
        }
    }

    public void updateSupervisionInfoEs(String record, IdxBizJgSupervisionInfo equipSupervisionInfoChangeDataDto) {
        // es 数据更新
        Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
        if (optional.isPresent()) {
            ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
            if(equipSupervisionInfoChangeDataDto.getOrgBranchCode() != null) {
                esEquipmentCategoryDto.setOrgBranchCode(equipSupervisionInfoChangeDataDto.getOrgBranchCode());
                esEquipmentCategoryDto.setORG_BRANCH_NAME(equipSupervisionInfoChangeDataDto.getOrgBranchName());
                esEquipmentCategory.save(esEquipmentCategoryDto);
            }
        }
    }

    public void updateOtherInfoChangeData(String record, EquipOtherInfoChangeDataDto otherInfoChangeDataDto) {
        LambdaUpdateWrapper<IdxBizJgOtherInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(IdxBizJgOtherInfo::getRecord, record);
        updateWrapper.set(IdxBizJgOtherInfo::getInformationManageCode, otherInfoChangeDataDto.getInformationManageCode());
        updateWrapper.set(IdxBizJgOtherInfo::getCylinderStampAttachment, otherInfoChangeDataDto.getCylinderStampAttachment());
        updateWrapper.set(IdxBizJgOtherInfo::getInformationSituation, otherInfoChangeDataDto.getInformationSituation());
        idxBizJgOtherInfoMapper.update(null, updateWrapper);
    }
}
