package cn.iocoder.yudao.module.mes.controller.admin.safety;
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.hazard.MesSafetyHazardCheckReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.hazard.MesSafetyHazardPageReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.hazard.MesSafetyHazardRectifyReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.hazard.MesSafetyHazardRespVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.hazard.MesSafetyHazardSaveReqVO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkshopDO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.safety.MesSafetyHazardDO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.safety.MesSafetyRiskDO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.safety.MesSafetyRiskUnitDO;
|
import cn.iocoder.yudao.module.mes.dal.mysql.md.workstation.MesMdWorkshopMapper;
|
import cn.iocoder.yudao.module.mes.service.safety.MesSafetyHazardService;
|
import cn.iocoder.yudao.module.mes.service.safety.MesSafetyRiskService;
|
import cn.iocoder.yudao.module.mes.service.safety.MesSafetyRiskUnitService;
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import jakarta.annotation.Resource;
|
import jakarta.validation.Valid;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.time.LocalDate;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
/**
|
* 安全生产 - 隐患 Controller
|
*
|
* @author 超级管理员
|
*/
|
@Tag(name = "管理后台 - 安全生产-隐患排查治理")
|
@RestController
|
@RequestMapping("/mes/safety/hazard")
|
@Validated
|
public class MesSafetyHazardController {
|
|
@Resource
|
private MesSafetyHazardService hazardService;
|
|
@Resource
|
private MesSafetyRiskUnitService riskUnitService;
|
|
@Resource
|
private MesSafetyRiskService riskService;
|
|
@Resource
|
private MesMdWorkshopMapper workshopMapper;
|
|
@Resource
|
private AdminUserApi adminUserApi;
|
|
@PostMapping("/create")
|
@Operation(summary = "登记隐患")
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:create')")
|
public CommonResult<Long> createHazard(@Valid @RequestBody MesSafetyHazardSaveReqVO createReqVO) {
|
return success(hazardService.createHazard(createReqVO));
|
}
|
|
@PutMapping("/update")
|
@Operation(summary = "更新隐患")
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:update')")
|
public CommonResult<Boolean> updateHazard(@Valid @RequestBody MesSafetyHazardSaveReqVO updateReqVO) {
|
hazardService.updateHazard(updateReqVO);
|
return success(true);
|
}
|
|
@DeleteMapping("/delete")
|
@Operation(summary = "删除隐患")
|
@Parameter(name = "id", description = "编号", required = true)
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:delete')")
|
public CommonResult<Boolean> deleteHazard(@RequestParam("id") Long id) {
|
hazardService.deleteHazard(id);
|
return success(true);
|
}
|
|
@PutMapping("/rectify")
|
@Operation(summary = "提交整改")
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:rectify')")
|
public CommonResult<Boolean> rectifyHazard(@Valid @RequestBody MesSafetyHazardRectifyReqVO reqVO) {
|
hazardService.rectifyHazard(reqVO);
|
return success(true);
|
}
|
|
@PutMapping("/check")
|
@Operation(summary = "整改验收")
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:check')")
|
public CommonResult<Boolean> checkHazard(@Valid @RequestBody MesSafetyHazardCheckReqVO reqVO) {
|
hazardService.checkHazard(reqVO);
|
return success(true);
|
}
|
|
@GetMapping("/get")
|
@Operation(summary = "获得隐患")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:query')")
|
public CommonResult<MesSafetyHazardRespVO> getHazard(@RequestParam("id") Long id) {
|
MesSafetyHazardDO hazard = hazardService.getHazard(id);
|
if (hazard == null) {
|
return success(null);
|
}
|
List<MesSafetyHazardRespVO> list = buildRespList(Collections.singletonList(hazard));
|
return success(list.isEmpty() ? null : list.get(0));
|
}
|
|
@GetMapping("/page")
|
@Operation(summary = "获得隐患分页")
|
@PreAuthorize("@ss.hasPermission('mes:safety-hazard:query')")
|
public CommonResult<PageResult<MesSafetyHazardRespVO>> getHazardPage(@Valid MesSafetyHazardPageReqVO pageReqVO) {
|
PageResult<MesSafetyHazardDO> pageResult = hazardService.getHazardPage(pageReqVO);
|
List<MesSafetyHazardRespVO> list = buildRespList(pageResult.getList());
|
return success(new PageResult<>(list, pageResult.getTotal()));
|
}
|
|
/**
|
* 转换为 VO 并填充车间、人员、关联风险信息、超期标记
|
*/
|
private List<MesSafetyHazardRespVO> buildRespList(List<MesSafetyHazardDO> list) {
|
if (list == null || list.isEmpty()) {
|
return Collections.emptyList();
|
}
|
List<MesSafetyHazardRespVO> respList = BeanUtils.toBean(list, MesSafetyHazardRespVO.class);
|
|
// 车间名称
|
Set<Long> workshopIds = list.stream().map(MesSafetyHazardDO::getWorkshopId)
|
.filter(Objects::nonNull).collect(Collectors.toSet());
|
Map<Long, String> workshopNameMap = new HashMap<>();
|
if (!workshopIds.isEmpty()) {
|
List<MesMdWorkshopDO> workshops = workshopMapper.selectByIds(workshopIds);
|
workshops.forEach(w -> workshopNameMap.put(w.getId(), w.getName()));
|
}
|
|
// 人员姓名(发现人 / 整改责任人 / 验收人)
|
Set<Long> userIds = new HashSet<>();
|
list.forEach(h -> {
|
if (h.getFounderUserId() != null) userIds.add(h.getFounderUserId());
|
if (h.getChargeUserId() != null) userIds.add(h.getChargeUserId());
|
if (h.getCheckUserId() != null) userIds.add(h.getCheckUserId());
|
});
|
Map<Long, AdminUserRespDTO> userMap = userIds.isEmpty()
|
? Collections.emptyMap() : adminUserApi.getUserMap(userIds);
|
|
// 风险单元名称
|
Set<Long> unitIds = list.stream().map(MesSafetyHazardDO::getUnitId)
|
.filter(Objects::nonNull).collect(Collectors.toSet());
|
Map<Long, MesSafetyRiskUnitDO> unitMap = riskUnitService.getRiskUnitMap(unitIds);
|
|
LocalDate today = LocalDate.now();
|
for (MesSafetyHazardRespVO vo : respList) {
|
vo.setWorkshopName(workshopNameMap.get(vo.getWorkshopId()));
|
AdminUserRespDTO founder = userMap.get(vo.getFounderUserId());
|
if (founder != null) vo.setFounderUserName(founder.getNickname());
|
AdminUserRespDTO charge = userMap.get(vo.getChargeUserId());
|
if (charge != null) vo.setChargeUserName(charge.getNickname());
|
AdminUserRespDTO checker = userMap.get(vo.getCheckUserId());
|
if (checker != null) vo.setCheckUserName(checker.getNickname());
|
|
MesSafetyRiskUnitDO unit = unitMap.get(vo.getUnitId());
|
if (unit != null) vo.setUnitName(unit.getName());
|
|
if (vo.getRiskId() != null) {
|
MesSafetyRiskDO risk = riskService.getRisk(vo.getRiskId());
|
if (risk != null) vo.setRiskName(risk.getName());
|
}
|
|
// 超期判断:有期限、未闭环、且期限早于今天
|
vo.setOverdue(vo.getDeadline() != null
|
&& !MesSafetyHazardDO.STATUS_CLOSED.equals(vo.getStatus())
|
&& vo.getDeadline().isBefore(today));
|
}
|
return respList;
|
}
|
|
}
|