治理设备管理指标分组功能
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.njcn.csdevice.pojo.param;
|
||||
|
||||
import com.njcn.web.constant.ValidMessage;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 重新分组
|
||||
*
|
||||
* @author xuyang
|
||||
* @date 2023/6/19
|
||||
*/
|
||||
@Data
|
||||
public class GroupArrParam {
|
||||
|
||||
@ApiModelProperty("setId")
|
||||
@NotBlank(message = ValidMessage.ID_NOT_BLANK)
|
||||
private String setId;
|
||||
|
||||
@ApiModelProperty("data")
|
||||
@NotEmpty(message = "数据不能为空")
|
||||
private List<ArrItem> data;
|
||||
|
||||
|
||||
@Data
|
||||
public static class ArrItem {
|
||||
private String id;
|
||||
private String name;
|
||||
private List<String> children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.csdevice.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组和指标关系表
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-19
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_gro_arr")
|
||||
public class CsGroArr {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 组id
|
||||
*/
|
||||
private String groupId;
|
||||
|
||||
/**
|
||||
* 指标id
|
||||
*/
|
||||
private String arrayId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.njcn.csdevice.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据分组表
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-16
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_group")
|
||||
public class CsGroup {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 数据集id
|
||||
*/
|
||||
private String dataSetId;
|
||||
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
private String groupName;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 是否展示
|
||||
*/
|
||||
private Integer isShow;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.csdevice.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/6/16 15:48
|
||||
*/
|
||||
@Data
|
||||
public class CsGroupVO {
|
||||
|
||||
private String id;
|
||||
|
||||
private String pid;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<CsGroupVO> children = new ArrayList<>();
|
||||
|
||||
}
|
||||
@@ -21,4 +21,10 @@ public class DeviceManagerDetailVO {
|
||||
|
||||
@ApiModelProperty("单位")
|
||||
private String unit;
|
||||
|
||||
@ApiModelProperty("开始次数")
|
||||
private String startTimes;
|
||||
|
||||
@ApiModelProperty("结束次数")
|
||||
private String endTimes;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.csdevice.controller.equipment;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.csdevice.pojo.param.GroupArrParam;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import com.njcn.csdevice.service.ICsGroArrService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.njcn.web.controller.BaseController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组和指标关系表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-19
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/csGroArr")
|
||||
@Api(tags = "组和指标关系")
|
||||
@AllArgsConstructor
|
||||
public class CsGroArrController extends BaseController {
|
||||
|
||||
private final ICsGroArrService csGroArrService;
|
||||
|
||||
@PostMapping("/updateGroArr")
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@ApiOperation("更新组和指标关系")
|
||||
@ApiImplicitParam(name = "groupArrParam", value = "重新分组信息", required = true)
|
||||
public HttpResult<String> updateGroArr(@RequestBody GroupArrParam groupArrParam) {
|
||||
String methodDescribe = getMethodDescribe("updateGroArr");
|
||||
LogUtil.njcnDebug(log, "{},分组信息为:{}", methodDescribe, groupArrParam);
|
||||
csGroArrService.updateGroArr(groupArrParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.csdevice.controller.equipment;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import com.njcn.csdevice.service.ICsGroupService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据分组表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-16
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/csGroup")
|
||||
@Api(tags = "指标分组")
|
||||
@AllArgsConstructor
|
||||
public class CsGroupController extends BaseController {
|
||||
|
||||
private final ICsGroupService csGroupService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getGroup")
|
||||
@ApiOperation("查询分组")
|
||||
@ApiImplicitParam(name = "dataSet", value = "数据集id", required = true)
|
||||
public HttpResult<List<CsGroupVO>> getGroupData(@RequestParam("dataSet") String dataSet){
|
||||
String methodDescribe = getMethodDescribe("getGroupData");
|
||||
List<CsGroupVO> list = csGroupService.getGroupData(dataSet);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface CsDataArrayMapper extends BaseMapper<CsDataArray> {
|
||||
|
||||
List<CsDataArray> getDictData(@Param("id") String id);
|
||||
|
||||
List<CsDataArray> getGroupData(@Param("id") String id);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.csdevice.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.csdevice.pojo.po.CsGroArr;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组和指标关系表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-19
|
||||
*/
|
||||
public interface CsGroArrMapper extends BaseMapper<CsGroArr> {
|
||||
|
||||
List<CsGroupVO> getGroupArrayList(@Param("list") List<String> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.csdevice.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.csdevice.pojo.po.CsGroup;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据分组表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-16
|
||||
*/
|
||||
public interface CsGroupMapper extends BaseMapper<CsGroup> {
|
||||
|
||||
List<CsGroupVO> getGroupData(@Param("dataSet") String dataSet);
|
||||
|
||||
List<CsGroupVO> getGroupData2(@Param("dataSet") String dataSet);
|
||||
|
||||
List<CsGroupVO> getArrayData(@Param("list") List<String> list);
|
||||
|
||||
void insertList(@Param("list") List<CsGroup> list);
|
||||
}
|
||||
@@ -47,4 +47,22 @@
|
||||
where
|
||||
pid = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getGroupData" resultType="CsDataArray">
|
||||
select
|
||||
id ,
|
||||
name,
|
||||
another_name,
|
||||
phase
|
||||
from
|
||||
cs_data_array t0
|
||||
where
|
||||
pid = #{id} and stat_method = 'avg'
|
||||
group by
|
||||
id,
|
||||
name,
|
||||
another_name,
|
||||
phase
|
||||
order by min(sort)
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.csdevice.mapper.CsGroArrMapper">
|
||||
|
||||
<select id="getGroupArrayList" resultType="CsGroupVO">
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.csdevice.mapper.CsGroupMapper">
|
||||
|
||||
<select id="getGroupData" resultType="CsGroupVO">
|
||||
select
|
||||
id,
|
||||
'0' pid,
|
||||
group_name name
|
||||
from
|
||||
cs_group
|
||||
where
|
||||
data_set_id = #{dataSet}
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<select id="getGroupData2" resultType="CsGroupVO">
|
||||
select
|
||||
id,
|
||||
'0' pid,
|
||||
group_name name
|
||||
from
|
||||
cs_group
|
||||
where
|
||||
data_set_id = #{dataSet} and is_show = 1
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<select id="getArrayData" resultType="CsGroupVO">
|
||||
select
|
||||
t1.id,
|
||||
t0.group_id pid,
|
||||
case when t1.phase in ('A', 'B', 'C') then concat(t1.phase, "相", t1.another_name)
|
||||
when t1.phase in ('M', 'T') then t1.another_name
|
||||
else concat(t1.phase, t1.another_name)
|
||||
end name
|
||||
from
|
||||
cs_gro_arr t0
|
||||
left join
|
||||
cs_data_array t1 on t0.array_id = t1.id
|
||||
left join
|
||||
cs_group t2 on t0.group_id = t2.id
|
||||
where
|
||||
t0.group_id in
|
||||
<foreach collection='list' item='item' index="index" open='(' separator=',' close=')'>
|
||||
#{item}
|
||||
</foreach>
|
||||
and
|
||||
t2.is_show = 1
|
||||
order by t1.sort
|
||||
</select>
|
||||
|
||||
<insert id="insertList">
|
||||
insert into cs_group
|
||||
(
|
||||
id,
|
||||
data_set_id,
|
||||
group_name,
|
||||
sort,
|
||||
is_show
|
||||
)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(
|
||||
#{item.id},
|
||||
#{item.dataSetId},
|
||||
#{item.groupName},
|
||||
#{item.sort},
|
||||
#{item.isShow}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -35,6 +35,14 @@ public interface ICsDataArrayService extends IService<CsDataArray> {
|
||||
|
||||
List<DataArrayTreeVO> getDataArray(List<String> list);
|
||||
|
||||
/**
|
||||
* 根据数据集id获取分组数据
|
||||
* @param dataSet
|
||||
* @return
|
||||
*/
|
||||
List<CsDataArray> getGroupData(String dataSet);
|
||||
|
||||
|
||||
// List<CsDataArray> getDataArrayById(String pid, String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.njcn.csdevice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csdevice.pojo.param.GroupArrParam;
|
||||
import com.njcn.csdevice.pojo.po.CsGroArr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组和指标关系表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-19
|
||||
*/
|
||||
public interface ICsGroArrService extends IService<CsGroArr> {
|
||||
|
||||
/**
|
||||
* 批量新增
|
||||
* @param list 数据集
|
||||
*/
|
||||
void insertList(List<CsGroArr> list);
|
||||
|
||||
/**
|
||||
* 更新组和指标关系
|
||||
* @param groupArrParam 组和指标关系
|
||||
*/
|
||||
void updateGroArr(GroupArrParam groupArrParam);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.csdevice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csdevice.pojo.po.CsGroup;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据分组表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-16
|
||||
*/
|
||||
public interface ICsGroupService extends IService<CsGroup> {
|
||||
|
||||
/**
|
||||
* 根据数据集id查询分组详情
|
||||
* @param dataSet
|
||||
*/
|
||||
List<CsGroupVO> getGroupData(String dataSet);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.mapper.CsDataArrayMapper;
|
||||
import com.njcn.csdevice.pojo.dto.DataArrayDTO;
|
||||
@@ -13,6 +14,7 @@ import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -50,6 +52,18 @@ public class CsDataArrayServiceImpl extends ServiceImpl<CsDataArrayMapper, CsDat
|
||||
}
|
||||
vo.setType(item.getType());
|
||||
vo.setUnit(item.getUnit());
|
||||
if (Objects.isNull(item.getHarmStart()) && Objects.isNull(item.getHarmEnd())){
|
||||
vo.setStartTimes("-");
|
||||
vo.setEndTimes("-");
|
||||
} else {
|
||||
if(Objects.equals(item.getHarmStart(),1) && Objects.equals(item.getHarmEnd(),50)) {
|
||||
vo.setStartTimes("0.5");
|
||||
vo.setEndTimes("49.5");
|
||||
} else {
|
||||
vo.setStartTimes(Integer.toString(item.getHarmStart()));
|
||||
vo.setEndTimes(Integer.toString(item.getHarmEnd()));
|
||||
}
|
||||
}
|
||||
list.add(vo);
|
||||
});
|
||||
return list;
|
||||
@@ -103,6 +117,11 @@ public class CsDataArrayServiceImpl extends ServiceImpl<CsDataArrayMapper, CsDat
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsDataArray> getGroupData(String dataSet) {
|
||||
return this.baseMapper.getGroupData(dataSet);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<CsDataArray> getDataArrayById(String pid, String name) {
|
||||
// return this.lambdaQuery().eq(CsDataArray::getPid,pid).eq(CsDataArray::getName,name).list();
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.mapper.CsGroArrMapper;
|
||||
import com.njcn.csdevice.mapper.CsGroupMapper;
|
||||
import com.njcn.csdevice.pojo.param.GroupArrParam;
|
||||
import com.njcn.csdevice.pojo.po.CsGroArr;
|
||||
import com.njcn.csdevice.pojo.po.CsGroup;
|
||||
import com.njcn.csdevice.service.ICsGroArrService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 组和指标关系表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-19
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class CsGroArrServiceImpl extends ServiceImpl<CsGroArrMapper, CsGroArr> implements ICsGroArrService {
|
||||
|
||||
private final CsGroupMapper csGroupMapper;
|
||||
|
||||
@Override
|
||||
public void insertList(List<CsGroArr> list) {
|
||||
this.saveBatch(list,1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGroArr(GroupArrParam groupArrParam) {
|
||||
List<GroupArrParam.ArrItem> list = groupArrParam.getData();
|
||||
List<String> groupIdList = list.stream().map(GroupArrParam.ArrItem::getId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<CsGroArr> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.in(CsGroArr::getGroupId, groupIdList);
|
||||
this.baseMapper.delete(lambdaQueryWrapper);
|
||||
csGroupMapper.deleteBatchIds(groupIdList);
|
||||
|
||||
List<CsGroup> listGroup = new ArrayList<>();
|
||||
List<CsGroArr> arrList = new ArrayList<>();
|
||||
|
||||
Integer sort = 0;
|
||||
for (GroupArrParam.ArrItem item : list) {
|
||||
if (CollectionUtil.isNotEmpty(item.getChildren())) {
|
||||
CsGroup csGroup = new CsGroup();
|
||||
csGroup.setId(IdUtil.simpleUUID());
|
||||
csGroup.setGroupName(item.getName());
|
||||
csGroup.setDataSetId(groupArrParam.getSetId());
|
||||
csGroup.setSort(sort);
|
||||
csGroup.setIsShow(1);
|
||||
sort++;
|
||||
listGroup.add(csGroup);
|
||||
|
||||
for (String idItem : item.getChildren()) {
|
||||
CsGroArr groupArr = new CsGroArr();
|
||||
groupArr.setGroupId(csGroup.getId());
|
||||
groupArr.setArrayId(idItem);
|
||||
arrList.add(groupArr);
|
||||
}
|
||||
}
|
||||
}
|
||||
csGroupMapper.insertList(listGroup);
|
||||
this.saveBatch(arrList,1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.mapper.CsGroupMapper;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsGroArr;
|
||||
import com.njcn.csdevice.pojo.po.CsGroup;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import com.njcn.csdevice.service.ICsDataArrayService;
|
||||
import com.njcn.csdevice.service.ICsGroArrService;
|
||||
import com.njcn.csdevice.service.ICsGroupService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据分组表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-06-16
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> implements ICsGroupService {
|
||||
|
||||
private final ICsDataArrayService csDataArrayService;
|
||||
|
||||
private final ICsGroArrService csGroArrService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<CsGroupVO> getGroupData(String dataSet) {
|
||||
List<CsGroupVO> list = this.baseMapper.getGroupData(dataSet);
|
||||
List<CsGroupVO> result = new ArrayList<>();
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
result = insertGroupData(dataSet);
|
||||
} else {
|
||||
List<CsGroupVO> list2 = this.baseMapper.getGroupData2(dataSet);
|
||||
if (CollectionUtil.isNotEmpty(list2)){
|
||||
List<String> groupList = list2.stream().map(CsGroupVO::getId).collect(Collectors.toList());
|
||||
List<CsGroupVO> arrayList = this.baseMapper.getArrayData(groupList);
|
||||
result = list2.stream().peek((item -> item.setChildren(getChildrenes(item.getId(), arrayList)))).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<CsGroupVO> getChildrenes(String tabId, List<CsGroupVO> all) {
|
||||
return all.stream().filter(item -> item.getPid().equals(tabId)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//fixme 目前组的数据插入写在这里,先查询数据集是否分组,分组了直接查询,没分组先分组再展示数据。后期根据业务需求在做调整
|
||||
public List<CsGroupVO> insertGroupData(String dataSet) {
|
||||
AtomicReference<Integer> sort = new AtomicReference<>(0);
|
||||
List<CsGroup> ls = new ArrayList<>();
|
||||
List<CsGroupVO> result = new ArrayList<>();
|
||||
List<CsGroArr> groArrList = new ArrayList<>();
|
||||
//取平均值
|
||||
List<CsDataArray> arrayList = csDataArrayService.getGroupData(dataSet);
|
||||
Map<String,List<CsDataArray>> map = arrayList.stream().collect(Collectors.groupingBy(CsDataArray::getAnotherName,LinkedHashMap::new,Collectors.toList()));
|
||||
map.forEach((k,v)->{
|
||||
//录入组数据
|
||||
String groupId = IdUtil.simpleUUID();
|
||||
CsGroup csGroup = new CsGroup();
|
||||
csGroup.setId(groupId);
|
||||
csGroup.setDataSetId(dataSet);
|
||||
csGroup.setGroupName(k);
|
||||
csGroup.setSort(sort.getAndSet(sort.get() + 1));
|
||||
csGroup.setIsShow(1);
|
||||
ls.add(csGroup);
|
||||
//录入组和指标关系
|
||||
v.forEach(item->{
|
||||
CsGroArr csGroArr = new CsGroArr();
|
||||
csGroArr.setGroupId(groupId);
|
||||
csGroArr.setArrayId(item.getId());
|
||||
groArrList.add(csGroArr);
|
||||
});
|
||||
//展示组和指标关系
|
||||
List<CsGroupVO> vo2 = new ArrayList<>();
|
||||
CsGroupVO csGroupVo = new CsGroupVO();
|
||||
csGroupVo.setId(groupId);
|
||||
csGroupVo.setPid("0");
|
||||
csGroupVo.setName(k);
|
||||
v.forEach(item->{
|
||||
CsGroupVO csGroupVo2 = new CsGroupVO();
|
||||
csGroupVo2.setId(item.getDataId());
|
||||
csGroupVo2.setPid(groupId);
|
||||
if(Objects.equals(item.getPhase(),"M") || Objects.equals(item.getPhase(),"T") ) {
|
||||
csGroupVo2.setName(item.getAnotherName());
|
||||
} else {
|
||||
csGroupVo2.setName(item.getPhase() + "相" +item.getAnotherName());
|
||||
}
|
||||
vo2.add(csGroupVo2);
|
||||
});
|
||||
csGroupVo.setChildren(vo2);
|
||||
result.add(csGroupVo);
|
||||
});
|
||||
csGroArrService.insertList(groArrList);
|
||||
this.saveBatch(ls,1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user