Commit b5561002 authored by tangwei's avatar tangwei

修改权重编辑你接口

parent aad83460
package com.yeejoin.amos.boot.module.jxiop.biz.controller; package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
...@@ -17,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -17,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
...@@ -121,10 +123,24 @@ public class IdxBizFanWeightController extends BaseController { ...@@ -121,10 +123,24 @@ public class IdxBizFanWeightController extends BaseController {
@Transactional @Transactional
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ApiOperation(httpMethod = "PUT", value = "根据sequenceNbr更新", notes = "根据sequenceNbr更新") @ApiOperation(httpMethod = "POST", value = "根据sequenceNbr更新", notes = "根据sequenceNbr更新")
public ResponseModel<IdxBizFanWeight> update(@RequestBody List<IdxBizFanWeight> list) { public ResponseModel<IdxBizFanWeight> update(@RequestBody Map<String,List<IdxBizFanWeight>> map) {
//获取所属,同类指标 //获取所属,同类指标
if(list!=null&&list.size()>0){ if(map!=null){
List<IdxBizFanWeight> list= map.get("data");
//判断是否同一层级
String flagtype=null;
for (IdxBizFanWeight idxBizFanWeight : list) {
if(flagtype==null){
flagtype= idxBizFanWeight.getArae()+idxBizFanWeight.getStation()+idxBizFanWeight.getEquipmentName()+idxBizFanWeight.getSubarray()+idxBizFanWeight.getPointName()+idxBizFanWeight.getType();
}else{
if(!flagtype.equals(idxBizFanWeight.getArae()+idxBizFanWeight.getStation()+idxBizFanWeight.getEquipmentName()+idxBizFanWeight.getSubarray()+idxBizFanWeight.getPointName()+idxBizFanWeight.getType())){
throw new BadRequest("配置权重必须是同一个层级的数据");
}
}
}
Float value= list.stream().map(e->e.getValue()).reduce(Float::sum).get();
IdxBizFanWeight reviewDto= list.get(0); IdxBizFanWeight reviewDto= list.get(0);
LambdaQueryWrapper<IdxBizFanWeight> qu=new LambdaQueryWrapper<>(); LambdaQueryWrapper<IdxBizFanWeight> qu=new LambdaQueryWrapper<>();
qu.eq(!StringUtils.isEmpty(reviewDto.getType()),IdxBizFanWeight::getType,reviewDto.getType()); qu.eq(!StringUtils.isEmpty(reviewDto.getType()),IdxBizFanWeight::getType,reviewDto.getType());
...@@ -135,12 +151,22 @@ public class IdxBizFanWeightController extends BaseController { ...@@ -135,12 +151,22 @@ public class IdxBizFanWeightController extends BaseController {
qu.eq(!StringUtils.isEmpty(reviewDto.getPointName()),IdxBizFanWeight::getPointName,reviewDto.getPointName()); qu.eq(!StringUtils.isEmpty(reviewDto.getPointName()),IdxBizFanWeight::getPointName,reviewDto.getPointName());
List<IdxBizFanWeight> listdata = idxBizFanWeightMapper.selectList(qu); List<IdxBizFanWeight> listdata = idxBizFanWeightMapper.selectList(qu);
Float value= list.stream().map(e->e.getValue()).reduce(Float::sum).get();
//设置权重值, //设置权重值,
int num= listdata.size()-list.size(); int num= listdata.size()-list.size();
//值不能大于1
if(value>1){
throw new BadRequest("超出权重最大值限制,层级下权重等级总和为1");
}
if(value!=1&&num!=0){
throw new BadRequest("超出权重最大值限制,层级下权重等级总和为1");
}
//剩余权重值 //剩余权重值
float formattedNum = Float.parseFloat(new DecimalFormat("0.0000").format((1-value)/num)); float formattedNum =num!=0? Float.parseFloat(new DecimalFormat("0.0000").format((1-value)/num)):0;
for (IdxBizFanWeight listdatum : listdata) { for (IdxBizFanWeight listdatum : listdata) {
for (IdxBizFanWeight idxBizPvWeight : list) { for (IdxBizFanWeight idxBizPvWeight : list) {
......
package com.yeejoin.amos.boot.module.jxiop.biz.controller; package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
...@@ -19,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -19,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
...@@ -132,28 +134,50 @@ public class IdxBizPvWeightController extends BaseController { ...@@ -132,28 +134,50 @@ public class IdxBizPvWeightController extends BaseController {
} }
@Transactional @Transactional
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping (value = "/update") @PostMapping (value = "/update")
@ApiOperation(httpMethod = "PUT", value = "根据sequenceNbr更新", notes = "根据sequenceNbr更新") @ApiOperation(httpMethod = "POST", value = "根据sequenceNbr更新", notes = "根据sequenceNbr更新")
public ResponseModel<IdxBizPvWeight> update(@RequestBody List<IdxBizPvWeight> list) { public ResponseModel<IdxBizPvWeight> update(@RequestBody Map<String,List<IdxBizPvWeight>> map) {
//获取所属,同类指标 //获取所属,同类指标
if(list!=null&&list.size()>0){ if(map!=null){
List<IdxBizPvWeight> list= map.get("data");
//判断是否同一层级
String flagtype=null;
for (IdxBizPvWeight idxBizPvWeight : list) {
if(flagtype==null){
flagtype= idxBizPvWeight.getArae()+idxBizPvWeight.getStation()+idxBizPvWeight.getEquipmentName()+idxBizPvWeight.getSubarray()+idxBizPvWeight.getPointName()+idxBizPvWeight.getType();
}else{
if(!flagtype.equals(idxBizPvWeight.getArae()+idxBizPvWeight.getStation()+idxBizPvWeight.getEquipmentName()+idxBizPvWeight.getSubarray()+idxBizPvWeight.getPointName()+idxBizPvWeight.getType())){
throw new BadRequest("配置权重必须是同一个层级的数据");
}
}
}
Float value= list.stream().map(e->e.getValue()).reduce(Float::sum).get();
IdxBizPvWeight reviewDto= list.get(0); IdxBizPvWeight reviewDto= list.get(0);
LambdaQueryWrapper<IdxBizPvWeight> qu=new LambdaQueryWrapper<>(); LambdaQueryWrapper<IdxBizPvWeight> qu=new LambdaQueryWrapper<>();
qu.eq(!StringUtils.isEmpty(reviewDto.getType()),IdxBizPvWeight::getType,reviewDto.getType()); qu.eq(!StringUtils.isEmpty(reviewDto.getType()),IdxBizPvWeight::getType,reviewDto.getType());
qu.eq(!StringUtils.isEmpty(reviewDto.getArae()),IdxBizPvWeight::getArae,reviewDto.getArae()); qu.eq(!StringUtils.isEmpty(reviewDto.getArae()),IdxBizPvWeight::getArae,reviewDto.getArae());
qu.eq(!StringUtils.isEmpty(reviewDto.getStation()),IdxBizPvWeight::getStation,reviewDto.getStation()); qu.eq(!StringUtils.isEmpty(reviewDto.getStation()), IdxBizPvWeight::getStation,reviewDto.getStation());
qu.eq(!StringUtils.isEmpty(reviewDto.getSubarray()),IdxBizPvWeight::getSubarray,reviewDto.getSubarray()); qu.eq(!StringUtils.isEmpty(reviewDto.getSubarray()),IdxBizPvWeight::getSubarray,reviewDto.getSubarray());
qu.eq(!StringUtils.isEmpty(reviewDto.getEquipmentName()),IdxBizPvWeight::getEquipmentName,reviewDto.getEquipmentName()); qu.eq(!StringUtils.isEmpty(reviewDto.getEquipmentName()),IdxBizPvWeight::getEquipmentName,reviewDto.getEquipmentName());
qu.eq(!StringUtils.isEmpty(reviewDto.getPointName()),IdxBizPvWeight::getPointName,reviewDto.getPointName()); qu.eq(!StringUtils.isEmpty(reviewDto.getPointName()),IdxBizPvWeight::getPointName,reviewDto.getPointName());
List<IdxBizPvWeight> listdata = idxBizPvWeightMapper.selectList(qu); List<IdxBizPvWeight> listdata = idxBizPvWeightMapper.selectList(qu);
Float value= list.stream().map(e->e.getValue()).reduce(Float::sum).get();
//设置权重值, //设置权重值,
int num= listdata.size()-list.size(); int num= listdata.size()-list.size();
//剩余权重值
float formattedNum = Float.parseFloat(new DecimalFormat("0.0000").format((1-value)/num)); //值不能大于1
if(value>1){
throw new BadRequest("超出权重最大值限制,层级下权重等级总和为1");
}
if(value!=1&&num!=0){
throw new BadRequest("超出权重最大值限制,层级下权重等级总和为1");
}
//剩余权重值
float formattedNum =num!=0? Float.parseFloat(new DecimalFormat("0.0000").format((1-value)/num)):0;
for (IdxBizPvWeight listdatum : listdata) { for (IdxBizPvWeight listdatum : listdata) {
for (IdxBizPvWeight idxBizPvWeight : list) { for (IdxBizPvWeight idxBizPvWeight : list) {
...@@ -167,7 +191,10 @@ public class IdxBizPvWeightController extends BaseController { ...@@ -167,7 +191,10 @@ public class IdxBizPvWeightController extends BaseController {
} }
idxBizPvWeightMapper.updateById(listdatum); idxBizPvWeightMapper.updateById(listdatum);
} }
} }
return ResponseHelper.buildResponse(null); return ResponseHelper.buildResponse(null);
} }
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
......
...@@ -64,5 +64,6 @@ public class IdxBizFanWeight { ...@@ -64,5 +64,6 @@ public class IdxBizFanWeight {
*/ */
@TableField("VALUE") @TableField("VALUE")
private Float value; private Float value;
@TableField(exist=false)
private String Symbol_key;
} }
...@@ -65,6 +65,6 @@ public class IdxBizPvWeight { ...@@ -65,6 +65,6 @@ public class IdxBizPvWeight {
*/ */
@TableField("VALUE") @TableField("VALUE")
private Float value; private Float value;
@TableField(exist=false)
private String Symbol_key;
} }
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