lyh
2 天以前 582bb2627712f66157b5608c8f5798775fc38266
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java
@@ -1,30 +1,48 @@
package org.jeecg.modules.eam.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.FileUploadResult;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.*;
import org.jeecg.modules.eam.dto.EamRepairOrderDto;
import org.jeecg.modules.eam.dto.EamReportRepairDto;
import org.jeecg.modules.eam.dto.EchartsDto;
import org.jeecg.modules.eam.entity.*;
import org.jeecg.modules.eam.mapper.EamReportRepairMapper;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
import org.jeecg.modules.eam.service.IEamReportRepairService;
import org.jeecg.modules.eam.request.EamReportRepairRequest;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.entity.SysAnnouncementSend;
import org.jeecg.modules.system.service.IBaseFactoryService;
import org.jeecg.modules.system.service.IBaseFactoryUserService;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @Description: 故障报修
@@ -37,6 +55,23 @@
    @Resource
    private IEamEquipmentExtendService eamEquipmentExtendService;
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    private IEamReportProductHazardsService iEamReportProductHazardsService;
    @Autowired
    private IEamReportAccidentsRegisterService iEamReportAccidentsRegisterService;
    @Autowired
    @Lazy
    private IEamRepairOrderService iEamRepairOrderService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
    @Autowired
    private IEamReportThreeNoSpareService eamReportThreeNoSpareService;
    @Autowired
    private IEamBaseHFCodeService hfCodeService;
    /**
     * 分页列表
     *
@@ -45,21 +80,29 @@
     * @return
     */
    @Override
    public IPage<EamReportRepair> pageList(Page<EamReportRepair> page, EamReportRepairQuery query) {
        QueryWrapper<EamReportRepair> queryWrapper = new QueryWrapper<>();
    public IPage<EamReportRepairDto> pageList(Page<EamReportRepairDto> page, EamReportRepairQuery query) {
        QueryWrapper<EamReportRepairDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0);
        //用户数据权限
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return page;
        }
        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
            //选择了设备,根据设备id过滤设备
            List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(","));
            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
            queryWrapper.in("e.equipment_code", equipArr);
        } else {
            //没有选择设备,根据车间过滤设备
            queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId());
            //没有选择设备,根据中心过滤设备
            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
            if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
                Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCode);
            } else {
                return page;
            }
        }
        //查询条件过滤
        if (query != null) {
@@ -120,10 +163,7 @@
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultName("周保执行报修处理");
        entity.setFaultDescription(sb.toString());
        entity.setFaultType(CommonConstant.DEFAULT_1);
        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
@@ -145,10 +185,7 @@
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultName("点检执行报修处理");
        entity.setFaultDescription(sb.toString());
        entity.setFaultType(CommonConstant.DEFAULT_1);
        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
@@ -158,21 +195,69 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
    public EamReportRepair add(EamReportRepair eamReportRepair) {
        eamReportRepair.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
    public EamReportRepair add(EamReportRepairRequest eamReportRepairRequest) {
        EamReportRepair eamReportRepair = new EamReportRepair();
        BeanUtils.copyProperties(eamReportRepairRequest, eamReportRepair);
        eamReportRepair.setDelFlag(CommonConstant.DEL_FLAG_0);
        // 附件处理
        if (eamReportRepair.getImageFilesResult() != null) {
            List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult();
            ObjectMapper mapper = new ObjectMapper();
            try {
                String referenceFile = mapper.writeValueAsString(imageFilesResult);
                eamReportRepair.setImageFiles(referenceFile);
            } catch (JsonProcessingException e) {
                return null;
            }
        }
        eamReportRepair.setReportStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name());
        this.baseMapper.insert(eamReportRepair);
        if(StrUtil.isNotEmpty(eamReportRepair.getIsProcessed())&&("1").equals(eamReportRepair.getIsProcessed())){
            //添加产品安全隐患确认
            EamReportProductHazards eamReportProductHazards=new EamReportProductHazards();
            eamReportProductHazards.setEquipmentId(eamReportRepair.getEquipmentId());
            eamReportProductHazards.setReportId(eamReportRepair.getId());
            eamReportProductHazards.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.PENDING_SUBMIT.name());
            EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_PRODUCT_HAZARDS.name());
            if (eamBaseHFCode == null) {
                throw new JeecgBootException("未配置产品安全隐患确认的HF编码,添加失败!");
            }
            eamReportProductHazards.setHfCode(eamBaseHFCode.getHfCode());
            iEamReportProductHazardsService.save(eamReportProductHazards);
        }
        if (StrUtil.isNotEmpty(eamReportRepair.getIsAccidentsRegister())&&("1").equals(eamReportRepair.getIsAccidentsRegister())) {
            //添加设备事故登记表
            EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister();
            BeanUtils.copyProperties(eamReportRepairRequest, eamReportAccidentsRegister);
            eamReportAccidentsRegister.setId(null);
            eamReportAccidentsRegister.setReportId(eamReportRepair.getId());
            eamReportAccidentsRegister.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            eamReportAccidentsRegister.setRegisterStatus(EamReportAccidentsRegisterEnum.PENDING_SUBMIT.name());
            EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_ACCIDENTS_REGISTER.name());
            if (eamBaseHFCode == null) {
                throw new JeecgBootException("未配置设备事故登记表的HF编码,添加失败!");
            }
            eamReportAccidentsRegister.setHfCode(eamBaseHFCode.getHfCode());
            iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister);
            //生成三不原则
            EamReportThreeNoSpare eamReportThreeNoSpare = new EamReportThreeNoSpare();
            BeanUtils.copyProperties(eamReportRepairRequest, eamReportThreeNoSpare);
            eamReportThreeNoSpare.setId(null);
            eamReportThreeNoSpare.setReportId(eamReportRepair.getId());
            eamReportThreeNoSpare.setPreventionMeasures(eamReportAccidentsRegister.getTakeSteps());
            eamReportThreeNoSpare.setSubmitStatus(EamReportThreeNoSpareEnum.PENDING_SUBMIT.name());
            eamReportThreeNoSpare.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            EamBaseHFCode threeHfCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_THREE_NO_SPARE.name());
            if (threeHfCode == null) {
                throw new JeecgBootException("未配置三不放过原则表的HF编码,添加失败!");
            }
            eamReportThreeNoSpare.setHfCode(threeHfCode.getHfCode());
            eamReportThreeNoSpareService.save(eamReportThreeNoSpare);
        }
        //生成维修工单
        EamRepairOrder eamRepairOrder=new EamRepairOrder();
        BeanUtils.copyProperties(eamReportRepairRequest, eamRepairOrder);
        String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.REPAIR_ORDER_CODE_RULE);
        eamRepairOrder.setRepairCode(codeSeq);
        eamRepairOrder.setId(null);
        eamRepairOrder.setDelFlag(CommonConstant.DEL_FLAG_0);
        eamRepairOrder.setReportId(eamReportRepair.getId());
        eamRepairOrder.setReportPerson(eamReportRepair.getCreateBy());
        eamRepairOrder.setFaultPhenomenon(eamReportRepair.getFaultDescription());
        eamRepairOrder.setFaultStartTime(eamReportRepair.getFaultStartTime());
        eamRepairOrder.setClaimStatus("0");
        eamRepairOrder.setRepairStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name());
        iEamRepairOrderService.save(eamRepairOrder);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(eamReportRepair.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return eamReportRepair;
@@ -180,21 +265,53 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean edit(EamReportRepair eamReportRepair) {
        // 附件处理
        if (eamReportRepair.getImageFilesResult() != null) {
            List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult();
            ObjectMapper mapper = new ObjectMapper();
            try {
                String referenceFile = mapper.writeValueAsString(imageFilesResult);
                eamReportRepair.setImageFiles(referenceFile);
            } catch (JsonProcessingException e) {
                return false;
    public boolean edit(EamReportRepairDto eamReportRepairDto) {
        LambdaUpdateWrapper<EamReportRepair> updateWrapper = new UpdateWrapper().lambda();
        EamReportRepair eamReportRepair=new EamReportRepair();
        BeanUtils.copyProperties(eamReportRepairDto, eamReportRepair);
        if(StrUtil.isNotEmpty(eamReportRepairDto.getIsProcessed())){
            //todo 缺少对应流程判断
            if ("0".equals(eamReportRepairDto.getIsProcessed())) {
                updateWrapper.set(EamReportRepair::getBatchNumber,null);
                updateWrapper.set(EamReportRepair::getProcessingPart,null);
                updateWrapper.set(EamReportRepair::getQuantity, null);
            }
        } else {
            eamReportRepair.setImageFiles(null);
            //直接删除再添加
            iEamReportProductHazardsService.remove(new QueryWrapper<EamReportProductHazards>().eq("report_id",eamReportRepairDto.getId())
                    .eq("equipment_id",eamReportRepairDto.getEquipmentId()));
            //添加产品安全隐患确认
            EamReportProductHazards eamReportProductHazards=new EamReportProductHazards();
            eamReportProductHazards.setEquipmentId(eamReportRepairDto.getEquipmentId());
            eamReportProductHazards.setReportId(eamReportRepairDto.getId());
            eamReportProductHazards.setId(null);
            iEamReportProductHazardsService.save(eamReportProductHazards);
        }
        this.baseMapper.updateById(eamReportRepair);
        if (StrUtil.isNotEmpty(eamReportRepairDto.getIsAccidentsRegister())) {
            //todo 缺少对应流程判断
            if ("0".equals(eamReportRepairDto.getIsAccidentsRegister())) {
                updateWrapper.set(EamReportRepair::getScrapPartNumber,null);
                updateWrapper.set(EamReportRepair::getScrapPartValue, null);
                updateWrapper.set(EamReportRepair::getScrapPartQuantity, null);
            }
            //直接删除再添加
            iEamReportAccidentsRegisterService.remove(new QueryWrapper<EamReportAccidentsRegister>()
                    .eq("report_id",eamReportRepairDto.getId()).eq("equipment_id",eamReportRepairDto.getEquipmentId()));
            //添加设备事故登记表
            EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister();
            BeanUtils.copyProperties(eamReportRepairDto, eamReportAccidentsRegister);
            eamReportAccidentsRegister.setReportId(eamReportRepairDto.getId());
            eamReportAccidentsRegister.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            eamReportAccidentsRegister.setId(null);
            iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister);
        }
        updateWrapper.eq(EamReportRepair::getId,eamReportRepairDto.getId());
        this.update(eamReportRepair,updateWrapper);
        //修改维修工单
        EamRepairOrder eamRepairOrder=iEamRepairOrderService.
                getOne(new QueryWrapper<EamRepairOrder>().eq("report_id",eamReportRepairDto.getId()));
        eamRepairOrder.setFaultStartTime(eamReportRepairDto.getFaultStartTime());
        eamRepairOrder.setFaultPhenomenon(eamReportRepairDto.getFaultDescription());
        iEamRepairOrderService.updateById(eamRepairOrder);
        return true;
    }
@@ -213,10 +330,7 @@
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultName("二保执行报修处理");
        entity.setFaultDescription(sb.toString());
        entity.setFaultType(CommonConstant.DEFAULT_1);
        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
@@ -238,13 +352,109 @@
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultName("三保执行报修处理");
        entity.setFaultDescription(sb.toString());
        entity.setFaultType(CommonConstant.DEFAULT_1);
        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return entity;
    }
    public List<EchartsDto> reportRepairList() {
        List<EchartsDto> echartsDtoList = new ArrayList<>();
        // 用户数据权限检查
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return echartsDtoList; // 返回空列表而非null
        }
        QueryWrapper<EamReportRepairDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0);
        // 设备过滤逻辑
        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
            queryWrapper.in("e.equipment_code", equipArr);
        } else {
            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService
                    .list(new LambdaQueryWrapper<BaseFactoryUser>()
                            .eq(BaseFactoryUser::getUserId, sysUser.getId()));
            if (CollectionUtils.isEmpty(baseFactoryUserList)) {
                return echartsDtoList; // 返回空列表而非null
            }
            Set<String> factoryIds = baseFactoryUserList.stream()
                    .map(BaseFactoryUser::getFactoryId)
                    .collect(Collectors.toSet());
            Set<String> factoryCodes = baseFactoryService.listByIds(factoryIds)
                    .stream()
                    .map(BaseFactory::getOrgCode)
                    .collect(Collectors.toSet());
            queryWrapper.in("e.factory_org_code", factoryCodes);
        }
        // 获取基础数据
        List<EamReportRepairDto> baseList = this.baseMapper.queryList(queryWrapper);
        int totalCount = baseList.size();
        // 获取停机数量
        int shutdownCount = this.baseMapper.queryList(
                queryWrapper.clone().eq("breakdown_flag", "1")
        ).size();
        // 计算运行数量
        int runningCount = totalCount - shutdownCount;
        // 处理零值情况
        if (totalCount == 0) {
            // 添加所有零值数据项
            addZeroValueData(echartsDtoList, "报修总数", "bx");
            addZeroValueData(echartsDtoList, "停机总数", "stop");
            addZeroValueData(echartsDtoList, "运行总数", "run");
            return echartsDtoList;
        }
        // 计算百分比
        BigDecimal total = new BigDecimal(totalCount);
        String bxPercentage = calculatePercentage(totalCount, BigDecimal.valueOf(totalCount));
        String stopPercentage = calculatePercentage(shutdownCount, BigDecimal.valueOf(totalCount));
        String runPercentage = calculatePercentage(runningCount, BigDecimal.valueOf(totalCount));
        // 构建返回数据
        echartsDtoList.add(createEchartsDto("报修总数", "bx", totalCount, bxPercentage));
        echartsDtoList.add(createEchartsDto("停机总数", "stop", shutdownCount, stopPercentage));
        echartsDtoList.add(createEchartsDto("运行总数", "run", runningCount, runPercentage));
        return echartsDtoList;
    }
    // 辅助方法:添加零值数据
    private void addZeroValueData(List<EchartsDto> list, String name, String code) {
        EchartsDto dto = new EchartsDto();
        dto.setName(name);
        dto.setCode(code);
        dto.setValue("0");
        dto.setPercentage("0.00%");
        list.add(dto);
    }
    // 辅助方法:计算百分比
    private String calculatePercentage(int value, BigDecimal total) {
        return new BigDecimal(value)
                .multiply(new BigDecimal(100))
                .divide(total, 2, RoundingMode.HALF_UP) + "%";
    }
    // 辅助方法:创建EchartsDto对象
    private EchartsDto createEchartsDto(String name, String code, int value, String percentage) {
        EchartsDto dto = new EchartsDto();
        dto.setName(name);
        dto.setCode(code);
        dto.setValue(String.valueOf(value));
        dto.setPercentage(percentage);
        return dto;
    }
}