|
|
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.pms.controller.admin.qhse.soc;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.net.URLEncodeUtil;
|
|
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
@@ -11,14 +13,16 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.soc.vo.IotSocSummaryPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.soc.vo.IotSocSummaryRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.soc.vo.IotSocSummarySaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.soc.IotSocSourceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.soc.IotSocSummaryDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.soc.IotSocSourceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.service.qhse.soc.IotSocSummaryService;
|
|
|
import cn.iocoder.yudao.module.pms.util.SafetyObservationCardGenerator;
|
|
|
-import com.google.common.collect.ImmutableList;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -29,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -45,6 +50,8 @@ public class IotSocSummaryController {
|
|
|
|
|
|
@Resource
|
|
|
private IotSocSummaryService iotSocSummaryService;
|
|
|
+ @Autowired
|
|
|
+ private IotSocSourceMapper iotSocSourceMapper;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建SOC卡汇总")
|
|
|
@@ -114,7 +121,8 @@ public class IotSocSummaryController {
|
|
|
String date = DateUtil.format(iotSocSummary.getObservationDate(), "yyyy-MM-dd HH:mm:ss");
|
|
|
String remark = iotSocSummary.getRemark();
|
|
|
|
|
|
- List<SafetyObservationCardGenerator.CheckItem> checkItems = buildCheckItems();
|
|
|
+ List<SafetyObservationCardGenerator.CheckItem> checkItems = buildCheckItems(iotSocSummary);
|
|
|
+
|
|
|
byte[] docBytes = SafetyObservationCardGenerator.generateCardToBytes(checkItems, person, date, remark);
|
|
|
|
|
|
// ========== 以下是 KKFileView 必须的标准格式 ==========
|
|
|
@@ -142,7 +150,7 @@ public class IotSocSummaryController {
|
|
|
String date = DateUtil.format(iotSocSummary.getObservationDate(), "yyyy-MM-dd HH:mm:ss");
|
|
|
String remark = iotSocSummary.getRemark();
|
|
|
|
|
|
- List<SafetyObservationCardGenerator.CheckItem> checkItems = buildCheckItems();
|
|
|
+ List<SafetyObservationCardGenerator.CheckItem> checkItems = buildCheckItems(iotSocSummary);
|
|
|
byte[] docBytes = SafetyObservationCardGenerator.generateCardToBytes(checkItems, person, date, remark);
|
|
|
|
|
|
String fileName = URLEncodeUtil.encode("行为安全观察与沟通卡" + StringUtils.substring(date, 0, 10) + person + ".docx");
|
|
|
@@ -158,11 +166,33 @@ public class IotSocSummaryController {
|
|
|
}
|
|
|
}
|
|
|
// 示例:构建检查项(实际业务中需从前端参数/数据库获取)
|
|
|
- private List<SafetyObservationCardGenerator.CheckItem> buildCheckItems() {
|
|
|
- return ImmutableList.of(
|
|
|
- new SafetyObservationCardGenerator.CheckItem("个人防护", "头部", "Personal Protection Equipment", "Head"),
|
|
|
- new SafetyObservationCardGenerator.CheckItem("规范操作", "其他", "Tools and Equipment", "Other"),
|
|
|
- new SafetyObservationCardGenerator.CheckItem("作业场所", "地面滑(水/雨/雪/油污等)", "Housekeeping", "Slippery floor (Water / Rain / Snow / Oil etc.)")
|
|
|
- );
|
|
|
+ private List<SafetyObservationCardGenerator.CheckItem> buildCheckItems(IotSocSummaryDO iotSocSummaryDO) {
|
|
|
+ if (StringUtils.isBlank(iotSocSummaryDO.getSocClass())) {
|
|
|
+ throw new ServiceException(new ErrorCode(2, "没有SOC类型"));
|
|
|
+ }
|
|
|
+ String[] split = iotSocSummaryDO.getSocClass().split(",");
|
|
|
+ List<SafetyObservationCardGenerator.CheckItem> checkItems = new ArrayList<>();
|
|
|
+ for (String s : split) {
|
|
|
+ IotSocSourceDO iotSocSourceDO = iotSocSourceMapper.selectById(Long.parseLong(s.trim()));
|
|
|
+ if (StringUtils.isBlank(iotSocSourceDO.getRemark())) {
|
|
|
+ //获取父类的SOC类型
|
|
|
+ IotSocSourceDO iotSocSourceDO1 = iotSocSourceMapper.selectById(iotSocSourceDO.getParentId());
|
|
|
+ //继续获取上一级
|
|
|
+ IotSocSourceDO iotSocSourceDO2 = iotSocSourceMapper.selectById(iotSocSourceDO1.getParentId());
|
|
|
+ SafetyObservationCardGenerator.CheckItem checkItem = new SafetyObservationCardGenerator.CheckItem(iotSocSourceDO2.getName(), iotSocSourceDO1.getName(), iotSocSourceDO2.getRemark(), iotSocSourceDO1.getRemark());
|
|
|
+ checkItems.add(checkItem);
|
|
|
+ } else {
|
|
|
+ IotSocSourceDO iotSocSourceDO1 = iotSocSourceMapper.selectById(iotSocSourceDO.getParentId());
|
|
|
+ SafetyObservationCardGenerator.CheckItem checkItem = new SafetyObservationCardGenerator.CheckItem(iotSocSourceDO1.getName(), iotSocSourceDO.getName(), iotSocSourceDO1.getRemark(), iotSocSourceDO.getRemark());
|
|
|
+ checkItems.add(checkItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return checkItems;
|
|
|
+// return ImmutableList.of(
|
|
|
+// new SafetyObservationCardGenerator.CheckItem("个人防护", "头部", "Personal Protection Equipment", "Head"),
|
|
|
+// new SafetyObservationCardGenerator.CheckItem("规范操作", "其他", "Tools and Equipment", "Other"),
|
|
|
+// new SafetyObservationCardGenerator.CheckItem("作业场所", "地面滑(水/雨/雪/油污等)", "Housekeeping", "Slippery floor (Water / Rain / Snow / Oil etc.)")
|
|
|
}
|
|
|
+
|
|
|
}
|