Commit ca9bfce7 by zhangkb

添加短板预警记录实体和相关接口

parent edd8c30c
......@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRecord;
import com.keymobile.indicators.model.entity.shortboard.ShortboardUnit;
import com.keymobile.indicators.model.entity.shortboard.ShortboardUnitCatalog;
import com.keymobile.indicators.service.hytobacco.ShortboardRuleService;
......@@ -97,14 +98,17 @@ public class ShortboardUnitCtrl {
@ApiOperation(value = "根据给定的短板规则筛选短板单位(预览)", notes = "根据给定的短板规则筛选短板单位(预览)")
@PostMapping(value = "/getObjFromShortboardRule")
public List<Map<String,Object>> getObjFromShortboardRule(@RequestParam int date,@RequestParam List<String> compareObjs,
@RequestParam List<String> driveIds,@RequestParam List<Integer> shortboardRuleIds)throws Exception{
return shortboardRuleService.getObjFromShortboardRule(date, compareObjs, driveIds, shortboardRuleIds);
public List<ShortboardRecord> getObjFromShortboardRule(@RequestParam int date,@RequestParam List<String> compareObjs,
@RequestParam List<String> driveIds,@RequestParam List<Integer> shortboardRuleIds,
@RequestParam String code,@RequestParam(required=false) String user)throws Exception{
return shortboardRuleService.getObjFromShortboardRule(date, compareObjs, driveIds,
shortboardRuleIds, code,user);
}
@ApiOperation(value = "根据给定的短板单元id计算短板对象", notes = "根据给定的短板单元id计算短板对象")
@PostMapping(value = "/getShortboardFromUnitId")
public List<Map<String,Object>> getShortboardFromUnitId(@RequestParam Integer unitId)throws Exception{
return shortboardUnitService.getShortboardObjFromUnit(unitId);
@ApiOperation(value = "保存预览数据生成短板预警池数据", notes = "保存预览数据生成短板预警池数据")
@PostMapping(value = "/getShortboardWarnning")
public List<ShortboardRecord> getShortboardWarnning(@RequestParam Integer unitId,
@RequestParam(required=false) String user)throws Exception{
return shortboardUnitService.getShortboardObjFromUnit(unitId,user);
}
}
package com.keymobile.indicators.model.entity.shortboard;
import java.util.Date;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
/**
*author:zhangkb time:2020-7-6 desc:短板筛选记录实体
*/
@Data
@Table(name ="short_board_record")
public class ShortboardRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Integer shortboardUnitId;//短表单元id
private String compareObj;//对标实体
private String driveId;//指标id
private String driveName;//指标名称
private String value;//对标值
private Integer date;//对标日期
private String compareCalResultJson;//对标结果实体json
private String shortboardRuleIds;//短板规则id
private String shortboardName;//短板名称
private String shortboardDesc;//短板描述
private String shortboardType;//短板类型:0:均值 1:最大值 2:最小值 3:排名 4:历史同期
private String isIssue;//是否下发 0:否 1:是
private String code;//标识编码
private String lastUpdater;
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
}
package com.keymobile.indicators.model.mapper.indmapper;
import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRecord;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ShortboardRecordMapper extends BaseMapper<ShortboardRecord>{
}
......@@ -17,6 +17,7 @@ import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.shortboard.ShortboardDriveIndRel;
import com.keymobile.indicators.model.entity.shortboard.ShortboardItem;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRecord;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRule;
import com.keymobile.indicators.model.mapper.indmapper.DriveIndCalResultDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardDriveIndRelMapper;
......@@ -80,22 +81,31 @@ public class ShortboardRuleService {
}
//根据给定的短板规则筛选短板单位
public List<Map<String,Object>> getObjFromShortboardRule(int date,
List<String> compareObjs,List<String> driveIds,List<Integer> shortboardRuleIds)throws Exception{
List<Map<String,Object>> result = new ArrayList<>();
public List<ShortboardRecord> getObjFromShortboardRule(Integer date,
List<String> compareObjs,List<String> driveIds,
List<Integer> shortboardRuleIds,String code,String user)throws Exception{
List<ShortboardRecord> result = new ArrayList<>();
Gson gson = new Gson();
int status = 0;
List<DriveIndCalResultDef> compareCalResults = new ArrayList<>();
for(String driveId : driveIds) {
List<Integer> shortboardRuleIdList = new ArrayList<>();//保存短板筛选规则id
DriveIndDef driveIndDef = driveIndDefService.getById(driveId);
if(driveIndDef!=null) {
StringBuilder shortboardRuleIdString = new StringBuilder("");
StringBuilder shortboardName = new StringBuilder("");
StringBuilder shortboardDesc = new StringBuilder("");
StringBuilder shortboardType = new StringBuilder("");
for(Integer sbRuleId : shortboardRuleIds) {
ShortboardRule shortboardRule = this.getById(sbRuleId);
if(shortboardRule!=null) {
shortboardRuleIdList.add(shortboardRule.getId());
shortboardRuleIdString.append(shortboardRule.getId()).append(";");//拼接短板规则id
if(StringUtils.isNotBlank(shortboardRule.getShortboardItemJson())) {
shortboardName.append(shortboardRule.getRuleName()).append(";");//拼接短板名称
shortboardDesc.append(shortboardRule.getRuleDesc()).append(";");//拼接短板描述
List<ShortboardItem> shortboardItems = gson.
fromJson(shortboardRule.getShortboardItemJson(), new TypeToken<List<ShortboardItem>>(){}.getType());
for(ShortboardItem shortboardItem : shortboardItems) {
shortboardType.append(shortboardItem.getType()).append(";");//拼接短板类型
List<DriveIndCalResultDef> driveIndCalResults = this.selectShortboardObj(
shortboardItem, compareObjs, driveId, date);
if(status==0) {
......@@ -109,12 +119,27 @@ public class ShortboardRuleService {
}
}
if(!compareCalResults.isEmpty()) {
Map<String,Object> map = new HashMap<>();
map.put("driveId", driveId);
map.put("shortboardRuleId", shortboardRuleIdList);
map.put("compareCalResults", compareCalResults);
map.put("date", date);
result.add(map);
for(DriveIndCalResultDef driveIndCalDef : compareCalResults) {
ShortboardRecord shortboardRecord = new ShortboardRecord();
shortboardRecord.setCompareObj(driveIndCalDef.getCompareObj());
shortboardRecord.setDriveId(driveIndDef.getIndId());
shortboardRecord.setDriveName(driveIndDef.getIndName());
shortboardRecord.setValue(driveIndCalDef.getValue());
shortboardRecord.setDate(date);
shortboardRecord.setCompareCalResultJson(gson.toJson(driveIndCalDef));
shortboardRecord.setShortboardRuleIds(shortboardRuleIdString.toString());
shortboardRecord.setShortboardName(shortboardName.toString());
shortboardRecord.setShortboardDesc(shortboardDesc.toString());
shortboardRecord.setShortboardType(shortboardType.toString());
shortboardRecord.setIsIssue("0");
shortboardRecord.setCode(code);
shortboardRecord.setLastUpdater(user);
result.add(shortboardRecord);
}
}
}
}
return result;
......
......@@ -13,7 +13,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRecord;
import com.keymobile.indicators.model.entity.shortboard.ShortboardUnit;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardRecordMapper;
import com.keymobile.indicators.model.mapper.indmapper.ShortboardUnitMapper;
import com.keymobile.indicators.utils.DateUtils;
......@@ -25,6 +27,8 @@ public class ShortboardUnitService {
private ShortboardUnitMapper shortboardUnitMapper;
@Autowired
private ShortboardRuleService shortboardRuleService;
@Autowired
private ShortboardRecordMapper shortboardRecordMapper;
public Integer saveOrUpdate(ShortboardUnit shortboardUnit,String code,Integer catalogId,
String catalogIdPath,String user) {
......@@ -69,9 +73,9 @@ public class ShortboardUnitService {
return null;
}
//根据短板规则单元获取
public List<Map<String,Object>> getShortboardObjFromUnit(Integer id) throws Exception{
List<Map<String,Object>> result = new ArrayList<>();
//保存预览数据生成短板预警池数据
public List<ShortboardRecord> getShortboardObjFromUnit(Integer id,String user) throws Exception{
List<ShortboardRecord> result = new ArrayList<>();
ShortboardUnit shortboardUnit = this.getById(id);//根据短板单元id获取短板单元
if(shortboardUnit!=null) {
List<String> compareObjList = new ArrayList<>();
......@@ -99,7 +103,13 @@ public class ShortboardUnitService {
}
if(!compareObjList.isEmpty() && !driveIndIdList.isEmpty() && !shortboardIdList.isEmpty()) {
result = shortboardRuleService.getObjFromShortboardRule(shortboardUnit.getDate(),
compareObjList, driveIndIdList, shortboardIdList);
compareObjList, driveIndIdList, shortboardIdList,shortboardUnit.getCode(),user);
}
if(!result.isEmpty()) {
for(ShortboardRecord shortboardRecord : result) {
shortboardRecord.setShortboardUnitId(id);
shortboardRecordMapper.insert(shortboardRecord);
}
}
}
return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment