|
@@ -0,0 +1,157 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.manager.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.manager.entity.NodeBaseInfo;
|
|
|
+import org.springblade.manager.entity.WbsTreeContract;
|
|
|
+import org.springblade.manager.service.IWbsTreeContractService;
|
|
|
+import org.springblade.manager.vo.NodeBaseInfoVO;
|
|
|
+import org.springblade.manager.mapper.NodeBaseInfoMapper;
|
|
|
+import org.springblade.manager.service.INodeBaseInfoService;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2025-03-10
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class NodeBaseInfoServiceImpl extends BaseServiceImpl<NodeBaseInfoMapper, NodeBaseInfo> implements INodeBaseInfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWbsTreeContractService iWbsTreeContractService;
|
|
|
+ @Override
|
|
|
+ public IPage<NodeBaseInfoVO> selectNodeBaseInfoPage(IPage<NodeBaseInfoVO> page, NodeBaseInfoVO nodeBaseInfo) {
|
|
|
+ return page.setRecords(baseMapper.selectNodeBaseInfoPage(page, nodeBaseInfo));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public NodeBaseInfo getOrSaveNodeBaseInfo(Long pKeyId) {
|
|
|
+ NodeBaseInfo nodeBaseInfo = baseMapper.selectOne(new QueryWrapper<NodeBaseInfo>().eq("node_id", pKeyId));
|
|
|
+ if(nodeBaseInfo!=null){
|
|
|
+ return nodeBaseInfo;
|
|
|
+ }
|
|
|
+ //查出当前节点的所有父节点
|
|
|
+ WbsTreeContract wbsTreeContract = iWbsTreeContractService.getBaseMapper().selectById(pKeyId);
|
|
|
+ if(wbsTreeContract!=null&&wbsTreeContract.getAncestors()!=null){
|
|
|
+ String ancestors = wbsTreeContract.getAncestors();
|
|
|
+ String[] nodeIds = ancestors.split(",");
|
|
|
+ // 使用MyBatis Plus的查询构建器
|
|
|
+ QueryWrapper<WbsTreeContract> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("project_id",wbsTreeContract.getProjectId());
|
|
|
+ queryWrapper.eq("contract_id",wbsTreeContract.getContractId());
|
|
|
+ queryWrapper.in("id", Arrays.asList(nodeIds));
|
|
|
+ List<WbsTreeContract> wbsTreeContracts = iWbsTreeContractService.getBaseMapper().selectList(queryWrapper);
|
|
|
+ if(wbsTreeContracts.size()>0){
|
|
|
+ NodeBaseInfo info = new NodeBaseInfo();
|
|
|
+ info.setId(SnowFlakeUtil.getId());
|
|
|
+ info.setNodeId(pKeyId);
|
|
|
+ for (WbsTreeContract contract : wbsTreeContracts) {
|
|
|
+ if(contract.getNodeType()==1){
|
|
|
+ info.setUnit(contract.getNodeName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(contract.getNodeType()==18){
|
|
|
+ info.setSubUnit(contract.getNodeName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(contract.getNodeType()==2){
|
|
|
+ info.setDivision(contract.getNodeName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(contract.getNodeType()==3){
|
|
|
+ info.setSubDivision(contract.getNodeName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(contract.getNodeType()==4){
|
|
|
+ info.setItem(contract.getNodeName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(contract.getNodeType()==5){
|
|
|
+ info.setSubItem(contract.getNodeName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(contract.getNodeType()==6){
|
|
|
+ info.setProcesses(contract.getNodeName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseMapper.insert(info);
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getNodeBaseInfoByPkeyId(Long pkeyId, Long nodeId, Integer autoType, BigDecimal min, BigDecimal max) {
|
|
|
+ String result="";
|
|
|
+ if(autoType!=8){
|
|
|
+ NodeBaseInfo nodeBaseInfo = baseMapper.selectOne(new QueryWrapper<NodeBaseInfo>().eq("node_id", nodeId));
|
|
|
+ if(nodeBaseInfo!=null){
|
|
|
+ if(autoType==1){
|
|
|
+ result= nodeBaseInfo.getUnit();
|
|
|
+ }
|
|
|
+ if(autoType==2){
|
|
|
+ result= nodeBaseInfo.getSubUnit();
|
|
|
+ }
|
|
|
+ if (autoType==3){
|
|
|
+ result= nodeBaseInfo.getDivision();
|
|
|
+ }
|
|
|
+ if(autoType==4){
|
|
|
+ result= nodeBaseInfo.getSubDivision();
|
|
|
+ }
|
|
|
+ if(autoType==5){
|
|
|
+ result= nodeBaseInfo.getItem();
|
|
|
+ }
|
|
|
+ if (autoType==6){
|
|
|
+ result= nodeBaseInfo.getSubItem();
|
|
|
+ }
|
|
|
+ if (autoType==7){
|
|
|
+ result= nodeBaseInfo.getProcesses();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (min.compareTo(max) >= 0) {
|
|
|
+ throw new IllegalArgumentException("max must be greater than min");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算区间范围
|
|
|
+ BigDecimal range = max.subtract(min);
|
|
|
+
|
|
|
+ // 生成随机数并调整范围
|
|
|
+ BigDecimal randomFactor = new BigDecimal(Math.random());
|
|
|
+ BigDecimal randomValue = min.add(range.multiply(randomFactor));
|
|
|
+
|
|
|
+ // 设置精度和舍入模式 保留两位小数
|
|
|
+ result= randomValue.setScale(2, RoundingMode.HALF_UP).toString();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|