|
|
@@ -0,0 +1,242 @@
|
|
|
+package cn.start.tz.module.pressure2.service.userwallthicknesstemplate;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.start.tz.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.userwallthicknesstemplate.vo.*;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.boilertaskorder.vo.WallThicknessReqVO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.userwallthicknesstemplate.UserWallThicknessTemplateDO;
|
|
|
+import cn.start.tz.framework.common.pojo.PageResult;
|
|
|
+import cn.start.tz.framework.common.pojo.PageParam;
|
|
|
+import cn.start.tz.framework.common.util.object.BeanUtils;
|
|
|
+
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.userwallthicknesstemplate.UserWallThicknessTemplateMapper;
|
|
|
+
|
|
|
+import static cn.start.tz.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.start.tz.module.pressure2.enums.ErrorCodeConstants.*;
|
|
|
+import static cn.start.tz.module.system.enums.ErrorCodeConstants.USER_NOT_LOGIN;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户壁厚测定点数模版 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 特种管理员
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class UserWallThicknessTemplateServiceImpl extends ServiceImpl<UserWallThicknessTemplateMapper, UserWallThicknessTemplateDO> implements UserWallThicknessTemplateService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserWallThicknessTemplateMapper userWallThicknessTemplateMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String createUserWallThicknessTemplate(UserWallThicknessTemplateSaveReqVO createReqVO) {
|
|
|
+ // 插入
|
|
|
+ UserWallThicknessTemplateDO userWallThicknessTemplate = BeanUtils.toBean(createReqVO, UserWallThicknessTemplateDO.class);
|
|
|
+ userWallThicknessTemplateMapper.insert(userWallThicknessTemplate);
|
|
|
+ // 返回
|
|
|
+ return userWallThicknessTemplate.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateUserWallThicknessTemplate(UserWallThicknessTemplateSaveReqVO updateReqVO) {
|
|
|
+ // 校验存在
|
|
|
+ validateUserWallThicknessTemplateExists(updateReqVO.getId());
|
|
|
+ // 更新
|
|
|
+ UserWallThicknessTemplateDO updateObj = BeanUtils.toBean(updateReqVO, UserWallThicknessTemplateDO.class);
|
|
|
+ userWallThicknessTemplateMapper.updateById(updateObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteUserWallThicknessTemplate(String id) {
|
|
|
+ // 校验存在
|
|
|
+ validateUserWallThicknessTemplateExists(id);
|
|
|
+ // 删除
|
|
|
+ userWallThicknessTemplateMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateUserWallThicknessTemplateExists(String id) {
|
|
|
+ if (userWallThicknessTemplateMapper.selectById(id) == null) {
|
|
|
+ throw exception(USER_WALL_THICKNESS_TEMPLATE_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserWallThicknessTemplateDO getUserWallThicknessTemplate(String id) {
|
|
|
+ return userWallThicknessTemplateMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<UserWallThicknessTemplateDO> getUserWallThicknessTemplatePage(UserWallThicknessTemplatePageReqVO pageReqVO) {
|
|
|
+ return userWallThicknessTemplateMapper.selectPage(pageReqVO);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public PageResult<UserWallThicknessTemplateRespVO> getTemplateByTemplateIdAndCurrentUser(
|
|
|
+ String templateId, UserWallThicknessTemplatePageReqVO pageReqVO) {
|
|
|
+ // 获取当前登录用户ID
|
|
|
+ String currentUserId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
+ if (StrUtil.isEmpty(currentUserId)) {
|
|
|
+ throw exception(USER_NOT_LOGIN);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置当前用户ID到查询条件中
|
|
|
+ pageReqVO.setUserId(currentUserId);
|
|
|
+
|
|
|
+ PageResult<UserWallThicknessTemplateDO> pageResult =
|
|
|
+ userWallThicknessTemplateMapper.selectPageByTemplateIdAndCurrentUser(templateId, pageReqVO);
|
|
|
+ return BeanUtils.toBean(pageResult, UserWallThicknessTemplateRespVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public com.alibaba.fastjson2.JSONObject generateWallThicknessParams(List<WallThicknessReqVO> wallThicknessList) {
|
|
|
+ com.alibaba.fastjson2.JSONObject params = new com.alibaba.fastjson2.JSONObject();
|
|
|
+ if (wallThicknessList == null || wallThicknessList.isEmpty()) {
|
|
|
+ params.put("table", "[]");
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+ String wallThicknessJson = getWallThicknessJsonStr(wallThicknessList);
|
|
|
+ params.put("table", wallThicknessJson);
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 壁厚测定JSON生成(参考压力模块 TaskOrderServiceImpl)
|
|
|
+ */
|
|
|
+ private String getWallThicknessJsonStr(List<WallThicknessReqVO> reqVOList) {
|
|
|
+ if (reqVOList == null || reqVOList.isEmpty()) {
|
|
|
+ com.alibaba.fastjson2.JSONArray arr = new com.alibaba.fastjson2.JSONArray();
|
|
|
+ return arr.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只有一个系列且code为空:走简化路径
|
|
|
+ if (reqVOList.size() == 1 && StrUtil.isEmpty(reqVOList.get(0).getCode())) {
|
|
|
+ return wallThicknessJsonSimple(reqVOList.get(0).getPoints());
|
|
|
+ }
|
|
|
+
|
|
|
+ com.alibaba.fastjson2.JSONArray voList = new com.alibaba.fastjson2.JSONArray();
|
|
|
+
|
|
|
+ // 第一个系列:直接生成完整数据
|
|
|
+ WallThicknessReqVO firstReqVO = reqVOList.get(0);
|
|
|
+ generateCompleteSeriesData(firstReqVO, voList);
|
|
|
+
|
|
|
+ // 处理后续系列
|
|
|
+ for (int i = 1; i < reqVOList.size(); i++) {
|
|
|
+ WallThicknessReqVO currentReqVO = reqVOList.get(i);
|
|
|
+ WallThicknessReqVO prevReqVO = reqVOList.get(i - 1);
|
|
|
+
|
|
|
+ if (currentReqVO.getPoints() <= prevReqVO.getPoints()) {
|
|
|
+ fillSeriesToPreviousAndGenerateRemaining(prevReqVO, currentReqVO, voList);
|
|
|
+ } else {
|
|
|
+ generateCompleteSeriesData(currentReqVO, voList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return voList.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 壁厚测定简化版JSON:仅根据点数生成简单编号 (1), (2), ...
|
|
|
+ */
|
|
|
+ private String wallThicknessJsonSimple(Integer points) {
|
|
|
+ com.alibaba.fastjson2.JSONArray voList = new com.alibaba.fastjson2.JSONArray();
|
|
|
+ int objCount = (points + 5) / 6; // 每个对象最多6个字段,向上取整
|
|
|
+
|
|
|
+ for (int i = 0; i < objCount; i++) {
|
|
|
+ com.alibaba.fastjson2.JSONObject vo = new com.alibaba.fastjson2.JSONObject();
|
|
|
+ for (int j = 0; j < 6; j++) {
|
|
|
+ int currentColumn = (i * 6) + j + 1;
|
|
|
+ if (currentColumn > points) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String pointValue = "(" + currentColumn + ")";
|
|
|
+ String fieldName = "value" + ((j * 2) + 1);
|
|
|
+ vo.put(fieldName, pointValue);
|
|
|
+ }
|
|
|
+ voList.add(vo);
|
|
|
+ }
|
|
|
+ return voList.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 为单个系列生成完整数据
|
|
|
+ */
|
|
|
+ private void generateCompleteSeriesData(WallThicknessReqVO reqVO, com.alibaba.fastjson2.JSONArray voList) {
|
|
|
+ String code = reqVO.getCode();
|
|
|
+ int columnNum = reqVO.getColumnNum();
|
|
|
+ int points = reqVO.getPoints();
|
|
|
+
|
|
|
+ int objCount = (columnNum + 5) / 6; // 每6列一个对象
|
|
|
+
|
|
|
+ for (int k = 0; k < objCount; k++) {
|
|
|
+ for (int i = 0; i < points; i++) {
|
|
|
+ com.alibaba.fastjson2.JSONObject vo = new com.alibaba.fastjson2.JSONObject();
|
|
|
+ for (int j = 0; j < 6; j++) {
|
|
|
+ int currentColumn = (k * 6) + j + 1;
|
|
|
+ if (currentColumn > columnNum) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String pointValue = code + currentColumn + "-" + (i + 1);
|
|
|
+ String fieldName = "value" + ((j * 2) + 1);
|
|
|
+ vo.put(fieldName, pointValue);
|
|
|
+ }
|
|
|
+ voList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将当前系列拼接到前一系列的空位中,如有剩余再生成独立对象
|
|
|
+ */
|
|
|
+ private void fillSeriesToPreviousAndGenerateRemaining(WallThicknessReqVO prevReqVO,
|
|
|
+ WallThicknessReqVO currentReqVO, com.alibaba.fastjson2.JSONArray voList) {
|
|
|
+ String currentCode = currentReqVO.getCode();
|
|
|
+ int currentColumnNum = currentReqVO.getColumnNum();
|
|
|
+
|
|
|
+ // 找到拼接起点:从前一系列最后一个对象组开始,找第一个有空位的对象索引
|
|
|
+ int lastObjStartIndex = voList.size() - prevReqVO.getPoints();
|
|
|
+ if (lastObjStartIndex < 0) {
|
|
|
+ lastObjStartIndex = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算已有对象中被填充的字段数(从最后一个对象组末尾计算)
|
|
|
+ int filledFields = 0;
|
|
|
+ com.alibaba.fastjson2.JSONObject lastVO = (com.alibaba.fastjson2.JSONObject) voList.get(voList.size() - 1);
|
|
|
+ for (int j = 0; j < 6; j++) {
|
|
|
+ String fieldName = "value" + ((j * 2) + 1);
|
|
|
+ if (lastVO.containsKey(fieldName) && lastVO.getString(fieldName) != null) {
|
|
|
+ filledFields++;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int availableSlots = 6 - filledFields;
|
|
|
+ int columnsToFill = Math.min(currentColumnNum, availableSlots);
|
|
|
+
|
|
|
+ // 填充当前系列数据到已有对象的空位
|
|
|
+ for (int pointIndex = 0; pointIndex < currentReqVO.getPoints(); pointIndex++) {
|
|
|
+ com.alibaba.fastjson2.JSONObject targetVO =
|
|
|
+ (com.alibaba.fastjson2.JSONObject) voList.get(lastObjStartIndex + pointIndex);
|
|
|
+ for (int colIndex = 0; colIndex < columnsToFill; colIndex++) {
|
|
|
+ String fieldName = "value" + ((filledFields + colIndex) * 2 + 1);
|
|
|
+ String value = currentCode + (colIndex + 1) + "-" + (pointIndex + 1);
|
|
|
+ targetVO.put(fieldName, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果还有剩余列没填完,生成独立的剩余对象
|
|
|
+ int remainingColumns = currentColumnNum - columnsToFill;
|
|
|
+ if (remainingColumns > 0) {
|
|
|
+ WallThicknessReqVO remainingVO = new WallThicknessReqVO();
|
|
|
+ remainingVO.setCode(currentCode);
|
|
|
+ remainingVO.setColumnNum(remainingColumns);
|
|
|
+ remainingVO.setPoints(currentReqVO.getPoints());
|
|
|
+ generateCompleteSeriesData(remainingVO, voList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|