Lius
2025-04-23 a90ae030ad64da0e44f48f4b1bb044753c1acff2
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamReportRepairController.java
@@ -5,6 +5,8 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -13,6 +15,7 @@
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.TranslateDictTextUtils;
import org.jeecg.modules.eam.constant.ReportRepairEnum;
import org.jeecg.modules.eam.entity.EamReportRepair;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
@@ -41,6 +44,12 @@
    @Resource
    private IEamReportRepairService eamReportRepairService;
    @Resource
    private ObjectMapper objectMapper;
    @Resource
    private TranslateDictTextUtils translateDictTextUtils;
    /**
     * 分页列表查询
@@ -71,19 +80,10 @@
    @ApiOperation(value = "故障报修-添加", notes = "故障报修-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody EamReportRepair eamReportRepair) {
        eamReportRepair.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        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 Result.OK("添加失败!");
            }
        EamReportRepair b = eamReportRepairService.add(eamReportRepair);
        if(b == null) {
            return Result.error("添加失败!");
        }
        eamReportRepairService.save(eamReportRepair);
        return Result.OK("添加成功!");
    }
@@ -97,7 +97,10 @@
    @ApiOperation(value = "故障报修-编辑", notes = "故障报修-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<?> edit(@RequestBody EamReportRepair eamReportRepair) {
        eamReportRepairService.updateById(eamReportRepair);
        boolean b = eamReportRepairService.edit(eamReportRepair);
        if(!b) {
            return Result.error("编辑失败!");
        }
        return Result.OK("编辑成功!");
    }
@@ -111,7 +114,7 @@
    @ApiOperation(value = "故障报修-作废", notes = "故障报修-作废")
    @DeleteMapping(value = "/abolish")
    public Result<?> abolish(@RequestParam(name = "id", required = true) String id) {
        eamReportRepairService.update(new LambdaUpdateWrapper<EamReportRepair>().set(EamReportRepair::getReportStatus, ReportRepairEnum.ABOLISH.name()).eq(EamReportRepair::getId, id));
        eamReportRepairService.update(new LambdaUpdateWrapper<EamReportRepair>().set(EamReportRepair::getReportStatus, ReportRepairEnum.ABOLISH.name()).eq(EamReportRepair::getId, id).eq(EamReportRepair::getReportStatus, ReportRepairEnum.WAIT_REPAIR.name()));
        return Result.OK("作废成功!");
    }
@@ -126,7 +129,11 @@
    @DeleteMapping(value = "/abolishBatch")
    public Result<?> abolishBatch(@RequestParam(name = "ids", required = true) String ids) {
        List<EamReportRepair> eamReportRepairs = eamReportRepairService.listByIds(Arrays.asList(ids.split(",")));
        eamReportRepairs.forEach(eamReportRepair -> eamReportRepair.setReportStatus(ReportRepairEnum.ABOLISH.name()));
        eamReportRepairs.forEach(eamReportRepair -> {
            if(ReportRepairEnum.ABOLISH.name().equals(eamReportRepair.getReportStatus())) {
                eamReportRepair.setReportStatus(ReportRepairEnum.ABOLISH.name());
            }
        });
        this.eamReportRepairService.updateBatchById(eamReportRepairs);
        return Result.OK("批量作废成功!");
    }
@@ -142,7 +149,21 @@
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        EamReportRepair eamReportRepair = eamReportRepairService.getById(id);
        return Result.OK(eamReportRepair);
        if (eamReportRepair == null) {
            return Result.error("未找到对应数据!");
        }
        try {
            String json = objectMapper.writeValueAsString(eamReportRepair);
            JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
            translateDictTextUtils.translateField("createBy", eamReportRepair.getCreateBy(), item, "sys_user,realname,username");
            translateDictTextUtils.translateField("breakdownFlag", eamReportRepair.getBreakdownFlag(), item, "breakdown_flag");
            translateDictTextUtils.translateField("faultType", eamReportRepair.getFaultType(), item, "fault_reason_category");
            translateDictTextUtils.translateField("reportStatus", eamReportRepair.getReportStatus(), item, "report_repair_status");
            translateDictTextUtils.translateField("equipmentId", eamReportRepair.getEquipmentId(), item, "eam_equipment,id,equipment_code");
            return Result.OK(item);
        } catch (Exception e) {
            return Result.error("数据转译失败!");
        }
    }
    /**