14 changed files with 421 additions and 24 deletions
@ -0,0 +1,13 @@ |
|||||
|
package com.qs.serve.modules.bms.common; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/7/17 |
||||
|
*/ |
||||
|
public interface CenterExtendBuildType { |
||||
|
|
||||
|
String DATA = "data"; |
||||
|
String TREE = "tree"; |
||||
|
String ERROR = "err"; |
||||
|
|
||||
|
} |
@ -0,0 +1,145 @@ |
|||||
|
package com.qs.serve.modules.bms.entity; |
||||
|
|
||||
|
import java.time.LocalDate; |
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* 后继成本中心 实体类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-07-17 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("bms_center_extend_build") |
||||
|
public class BmsCenterExtendBuild implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** 编号 */ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
|
||||
|
/** 创建类型 data,tree */ |
||||
|
private String buildType; |
||||
|
|
||||
|
/** 来源id */ |
||||
|
@NotNull(message = "来源id不能为空") |
||||
|
private Long sourceId; |
||||
|
|
||||
|
/** 祖级id */ |
||||
|
@Length(max = 255,message = "祖级id长度不能超过255字") |
||||
|
private String pathIds; |
||||
|
|
||||
|
/** 成本中心类型 */ |
||||
|
@NotBlank(message = "成本中心类型不能为空") |
||||
|
@Length(max = 255,message = "成本中心类型长度不能超过255字") |
||||
|
private String centerType; |
||||
|
|
||||
|
/** 成本中心id */ |
||||
|
@NotBlank(message = "成本中心id不能为空") |
||||
|
@Length(max = 32,message = "成本中心id长度不能超过32字") |
||||
|
private String centerId; |
||||
|
|
||||
|
/** 成本中心编码 */ |
||||
|
@NotBlank(message = "成本中心编码不能为空") |
||||
|
@Length(max = 50,message = "成本中心编码长度不能超过50字") |
||||
|
private String centerCode; |
||||
|
|
||||
|
/** 成本中心名称 */ |
||||
|
@NotBlank(message = "成本中心名称不能为空") |
||||
|
@Length(max = 200,message = "成本中心名称长度不能超过200字") |
||||
|
private String centerName; |
||||
|
|
||||
|
/** 开始时间 */ |
||||
|
@NotNull(message = "开始时间不能为空") |
||||
|
@Length(max = 0,message = "开始时间长度不能超过0字") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
private LocalDateTime startTime; |
||||
|
|
||||
|
/** 结束时间 */ |
||||
|
@Length(max = 0,message = "结束时间长度不能超过0字") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
private LocalDateTime stopTime; |
||||
|
|
||||
|
/** 结束标识 */ |
||||
|
@NotNull(message = "结束标识不能为空") |
||||
|
private Integer stopFlag; |
||||
|
|
||||
|
/** 权重 */ |
||||
|
@NotNull(message = "权重不能为空") |
||||
|
private BigDecimal weightRate; |
||||
|
|
||||
|
/** 备注 */ |
||||
|
@Length(max = 600,message = "备注长度不能超过600字") |
||||
|
private String remark; |
||||
|
|
||||
|
/** 创建时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private LocalDateTime createTime; |
||||
|
|
||||
|
/** 最后更新时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private LocalDateTime updateTime; |
||||
|
|
||||
|
/** 所属租户 */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String tenantId; |
||||
|
|
||||
|
/** 创建人 */ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private String createBy; |
||||
|
|
||||
|
/** 更新人 */ |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private String updateBy; |
||||
|
|
||||
|
/** 逻辑删除标记(0:显示;1:隐藏) */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String delFlag; |
||||
|
|
||||
|
|
||||
|
public static BmsCenterExtendBuild toNewObject(BmsCenterExtendBuild source){ |
||||
|
BmsCenterExtendBuild centerExtendBuild = new BmsCenterExtendBuild(); |
||||
|
centerExtendBuild.setId(source.getId()); |
||||
|
centerExtendBuild.setSourceId(source.getSourceId()); |
||||
|
centerExtendBuild.setPathIds(source.getPathIds()); |
||||
|
centerExtendBuild.setCenterType(source.getCenterType()); |
||||
|
centerExtendBuild.setCenterId(source.getCenterId()); |
||||
|
centerExtendBuild.setCenterCode(source.getCenterCode()); |
||||
|
centerExtendBuild.setCenterName(source.getCenterName()); |
||||
|
centerExtendBuild.setStartTime(source.getStartTime()); |
||||
|
centerExtendBuild.setStopTime(source.getStopTime()); |
||||
|
centerExtendBuild.setStopFlag(source.getStopFlag()); |
||||
|
centerExtendBuild.setWeightRate(source.getWeightRate()); |
||||
|
centerExtendBuild.setRemark(source.getRemark()); |
||||
|
centerExtendBuild.setCreateTime(source.getCreateTime()); |
||||
|
centerExtendBuild.setUpdateTime(source.getUpdateTime()); |
||||
|
centerExtendBuild.setTenantId(source.getTenantId()); |
||||
|
centerExtendBuild.setCreateBy(source.getCreateBy()); |
||||
|
centerExtendBuild.setUpdateBy(source.getUpdateBy()); |
||||
|
centerExtendBuild.setDelFlag(source.getDelFlag()); |
||||
|
return centerExtendBuild; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,72 @@ |
|||||
|
package com.qs.serve.modules.bms.entity.vo; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.SqlCondition; |
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.qs.serve.common.model.dto.TreeNode; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/7/17 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class BmsCenterExtendTreeVo extends TreeNode { |
||||
|
|
||||
|
/** 来源id */ |
||||
|
@NotNull(message = "来源id不能为空") |
||||
|
private Long sourceId; |
||||
|
|
||||
|
/** 成本中心类型 */ |
||||
|
@NotBlank(message = "成本中心类型不能为空") |
||||
|
@Length(max = 255,message = "成本中心类型长度不能超过255字") |
||||
|
private String centerType; |
||||
|
|
||||
|
/** 成本中心id */ |
||||
|
@NotBlank(message = "成本中心id不能为空") |
||||
|
@Length(max = 32,message = "成本中心id长度不能超过32字") |
||||
|
private String centerId; |
||||
|
|
||||
|
/** 成本中心编码 */ |
||||
|
@NotBlank(message = "成本中心编码不能为空") |
||||
|
@Length(max = 50,message = "成本中心编码长度不能超过50字") |
||||
|
@TableField(condition = SqlCondition.LIKE) |
||||
|
private String centerCode; |
||||
|
|
||||
|
/** 成本中心名称 */ |
||||
|
@NotBlank(message = "成本中心名称不能为空") |
||||
|
@Length(max = 200,message = "成本中心名称长度不能超过200字") |
||||
|
@TableField(condition = SqlCondition.LIKE) |
||||
|
private String centerName; |
||||
|
|
||||
|
/** 开始时间 */ |
||||
|
@NotNull(message = "开始时间不能为空") |
||||
|
@Length(max = 0,message = "开始时间长度不能超过0字") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
private LocalDateTime startTime; |
||||
|
|
||||
|
/** 结束时间 */ |
||||
|
@Length(max = 0,message = "结束时间长度不能超过0字") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
private LocalDateTime stopTime; |
||||
|
|
||||
|
/** 结束标识 */ |
||||
|
@NotNull(message = "结束标识不能为空") |
||||
|
private Integer stopFlag; |
||||
|
|
||||
|
/** 权重 */ |
||||
|
@NotNull(message = "权重不能为空") |
||||
|
private BigDecimal weightRate; |
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.bms.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qs.serve.modules.bms.entity.BmsCenterExtendBuild; |
||||
|
|
||||
|
/** |
||||
|
* 后继成本中心 Mapper |
||||
|
* @author YenHex |
||||
|
* @date 2023-07-17 |
||||
|
*/ |
||||
|
public interface BmsCenterExtendBuildMapper extends BaseMapper<BmsCenterExtendBuild> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,19 @@ |
|||||
|
package com.qs.serve.modules.bms.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.bms.entity.BmsCenterExtendBuild; |
||||
|
|
||||
|
/** |
||||
|
* 后继成本中心 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2023-07-17 |
||||
|
*/ |
||||
|
public interface BmsCenterExtendBuildService extends IService<BmsCenterExtendBuild> { |
||||
|
|
||||
|
/** |
||||
|
* 初始化建数据,调用时,清空本`bms_center_extend_build`表 |
||||
|
*/ |
||||
|
void initData(); |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,93 @@ |
|||||
|
package com.qs.serve.modules.bms.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.modules.bms.common.CenterExtendBuildType; |
||||
|
import com.qs.serve.modules.bms.entity.vo.BmsCenterExtendTreeVo; |
||||
|
import com.qs.serve.modules.bms.service.BmsCenterExtendService; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import com.qs.serve.modules.bms.entity.BmsCenterExtendBuild; |
||||
|
import com.qs.serve.modules.bms.service.BmsCenterExtendBuildService; |
||||
|
import com.qs.serve.modules.bms.mapper.BmsCenterExtendBuildMapper; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 后继成本中心 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-07-17 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class BmsCenterExtendBuildServiceImpl extends ServiceImpl<BmsCenterExtendBuildMapper,BmsCenterExtendBuild> implements BmsCenterExtendBuildService { |
||||
|
|
||||
|
private final BmsCenterExtendService centerExtendService; |
||||
|
|
||||
|
@Override |
||||
|
public void initData() { |
||||
|
List<BmsCenterExtendTreeVo> treeVoList = centerExtendService.transferTree(); |
||||
|
List<BmsCenterExtendBuild> buildList = new ArrayList<>(); |
||||
|
this.recursionBuildExtendCenter(treeVoList, buildList, null); |
||||
|
} |
||||
|
|
||||
|
private void recursionBuildExtendCenter(List<BmsCenterExtendTreeVo> treeVoList, List<BmsCenterExtendBuild> buildList, BmsCenterExtendBuild parent) { |
||||
|
//存放上级对象
|
||||
|
for (BmsCenterExtendTreeVo source : treeVoList) { |
||||
|
BmsCenterExtendBuild build = new BmsCenterExtendBuild(); |
||||
|
build.setBuildType(CenterExtendBuildType.TREE); |
||||
|
build.setSourceId(source.getSourceId()); |
||||
|
if(parent !=null){ |
||||
|
String[] pathIds = parent.getPathIds().split("_"); |
||||
|
for (String pathId : pathIds) { |
||||
|
if(pathId.equals(source.getId())){ |
||||
|
build.setBuildType(CenterExtendBuildType.ERROR); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
}else { |
||||
|
build.setPathIds("0_" + source.getId()); |
||||
|
} |
||||
|
build.setCenterType(source.getCenterType()); |
||||
|
build.setCenterId(source.getCenterId()); |
||||
|
build.setCenterCode(source.getCenterCode()); |
||||
|
build.setCenterName(source.getCenterName()); |
||||
|
build.setStartTime(source.getStartTime()); |
||||
|
build.setStopTime(source.getStopTime()); |
||||
|
build.setStopFlag(source.getStopFlag()); |
||||
|
build.setWeightRate(source.getWeightRate()); |
||||
|
buildList.add(build); |
||||
|
//判断是否最后一级
|
||||
|
if(source.getChildren()==null||source.getChildren().size()==0){ |
||||
|
//自下而上查询返回所有占比
|
||||
|
BmsCenterExtendBuild buildData = new BmsCenterExtendBuild(); |
||||
|
buildData.setBuildType(CenterExtendBuildType.DATA); |
||||
|
buildData.setSourceId(source.getSourceId()); |
||||
|
buildData.setCenterType(source.getCenterType()); |
||||
|
buildData.setCenterId(source.getCenterId()); |
||||
|
buildData.setCenterCode(source.getCenterCode()); |
||||
|
buildData.setCenterName(source.getCenterName()); |
||||
|
buildData.setStartTime(source.getStartTime()); |
||||
|
buildData.setStopTime(source.getStopTime()); |
||||
|
buildData.setStopFlag(source.getStopFlag()); |
||||
|
buildData.setWeightRate(source.getWeightRate()); |
||||
|
buildList.add(buildData); |
||||
|
//TODO
|
||||
|
BigDecimal weightRate = source.getWeightRate(); |
||||
|
String pid = source.getParentId(); |
||||
|
for (BmsCenterExtendTreeVo treeVo : treeVoList) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
}else { |
||||
|
//递归调用
|
||||
|
this.recursionBuildExtendCenter(treeVoList, buildList, build); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue