|
|
@@ -1,6 +1,8 @@
|
|
|
package cn.iocoder.yudao.module.pms.controller.admin.qhse.measure;
|
|
|
|
|
|
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;
|
|
|
@@ -9,8 +11,10 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.stat.DeptUtil;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.measure.IotMeasureBookDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.qhse.measure.IotMeasureBookMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.service.qhse.ChineseLetterUtil;
|
|
|
import cn.iocoder.yudao.module.pms.service.qhse.measure.IotMeasureBookService;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
@@ -24,6 +28,7 @@ import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.Parameters;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.Data;
|
|
|
+import 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;
|
|
|
@@ -31,14 +36,17 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.annotation.security.PermitAll;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static cn.hutool.extra.pinyin.PinyinUtil.isChinese;
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.module.pms.service.qhse.ChineseLetterUtil.getFirstLetterPinyin;
|
|
|
|
|
|
|
|
|
@Tag(name = "管理后台 - 计量器具台账")
|
|
|
@@ -57,6 +65,8 @@ public class IotMeasureBookController {
|
|
|
private DictDataService dictDataService;
|
|
|
@Autowired
|
|
|
private DeptApi deptApi;
|
|
|
+ @Autowired
|
|
|
+ private DeptUtil deptUtil;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建计量器具台账")
|
|
|
@@ -183,4 +193,83 @@ public class IotMeasureBookController {
|
|
|
private Long count;
|
|
|
private Integer sort;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/init")
|
|
|
+ @PermitAll
|
|
|
+ public void init() {
|
|
|
+ List<DeptRespDTO> deptList = deptApi.getDeptList();
|
|
|
+ deptList.stream().filter(e -> "2".equals(e.getType())||"3".equals(e.getType())).forEach(f ->{
|
|
|
+ //获取该部门下的所有证书
|
|
|
+ List<IotMeasureBookDO> iotMeasureBookDOS = iotMeasureBookMapper.selectList("dept_id", f.getId());
|
|
|
+ Map<String, List<IotMeasureBookDO>> collect = iotMeasureBookDOS.stream().collect(Collectors.groupingBy(IotMeasureBookDO::getClassify));
|
|
|
+ String code;
|
|
|
+
|
|
|
+ if (Objects.nonNull(f.getId())) {
|
|
|
+ DeptRespDTO dept = deptApi.getDept(f.getId());
|
|
|
+ if (Objects.nonNull(dept)) {
|
|
|
+ //获取队伍代码大写
|
|
|
+ String convert = ChineseLetterUtil.convert(dept.getName());
|
|
|
+ //获取公司代码大写
|
|
|
+ String company = deptUtil.getCompanyCode(f.getId()).toUpperCase();
|
|
|
+ //获取项目部代码大写
|
|
|
+ String jsaNo = getJSANo(f.getId());
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (jsaNo != null && !jsaNo.trim().isEmpty()) {
|
|
|
+ for (char c : jsaNo.toCharArray()) {
|
|
|
+ if (isChinese(c)) {
|
|
|
+ // 中文转拼音首字母(大写)
|
|
|
+ sb.append(getFirstLetterPinyin(c));
|
|
|
+ } else {
|
|
|
+ // 非中文直接保留
|
|
|
+ sb.append(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(jsaNo)){throw new ServiceException(new ErrorCode(2,"获取项目部编号失败"));}
|
|
|
+ code = company+sb.toString()+convert;
|
|
|
+ } else {
|
|
|
+ code = "";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ code = "";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(code)) {
|
|
|
+ collect.forEach((key, value) -> {
|
|
|
+ for (int i = 0; i < value.size(); i++) {
|
|
|
+ IotMeasureBookDO iotMeasureBookDO = value.get(i);
|
|
|
+ iotMeasureBookDO.setMeasureCode(code+key+(i+1));
|
|
|
+ iotMeasureBookMapper.updateById(iotMeasureBookDO);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getJSANo(Long loginUserDeptId) {
|
|
|
+ String companyCode = deptUtil.getCompanyCode(loginUserDeptId);
|
|
|
+ if ("jt".equals(companyCode)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ DeptRespDTO dept = deptApi.getDept(loginUserDeptId);
|
|
|
+ if (Objects.isNull(dept)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ Long parentId = dept.getParentId();
|
|
|
+ if (Objects.isNull(parentId)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ DeptRespDTO dept1 = deptApi.getDeptNoPermission(parentId);
|
|
|
+ if (Objects.isNull(dept1)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String name = dept1.getName();
|
|
|
+ if (name.contains("项目部")) {
|
|
|
+ companyCode = StringUtils.substringBeforeLast(name, "项目部");
|
|
|
+ } else {
|
|
|
+ companyCode = ChineseLetterUtil.convert(name);
|
|
|
+ }
|
|
|
+
|
|
|
+ return companyCode;
|
|
|
+ }
|
|
|
}
|