Commit 710abc78 by zhangkb

新增基础和考核指标自增指标编号接口以及修改基础和考核指标新增逻辑。

parent 4c2dbb08
...@@ -30,11 +30,19 @@ public class IndicatorsDefCtrl { ...@@ -30,11 +30,19 @@ public class IndicatorsDefCtrl {
@Autowired @Autowired
private DriveIndCalResultService driveIndCalResultService; private DriveIndCalResultService driveIndCalResultService;
@ApiOperation(value = "新建基础指标", notes = "新建基础指标") @ApiOperation(value = "获取基础指标最大id", notes = "获取基础指标最大id")
@PostMapping(value = "/getBaseIndMaxId")
public String getBaseIndMaxId(@RequestParam String code,
@RequestParam Integer length) throws Exception{
return baseIndDefService.getBaseIndMaxIndId(code, length);
}
@ApiOperation(value = "新建基础指标(isUpdate:0 新增 1修改)", notes = "新建基础指标(isUpdate:0 新增 1修改)")
@PostMapping(value = "/createBaseInd") @PostMapping(value = "/createBaseInd")
public void createBaseInd(@RequestBody BaseIndDef baseIndDef,@RequestParam Integer catalogId, public void createBaseInd(@RequestBody BaseIndDef baseIndDef,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user) throws Exception{ @RequestParam String catalogIdPath,@RequestParam String user,
baseIndDefService.saveOrUpdate(baseIndDef, catalogId, catalogIdPath, user); @RequestParam String isUpdate) throws Exception{
baseIndDefService.saveOrUpdate(baseIndDef, catalogId, catalogIdPath, user, isUpdate);
} }
@ApiOperation(value = "删除基础指标", notes = "删除基础指标") @ApiOperation(value = "删除基础指标", notes = "删除基础指标")
...@@ -57,12 +65,19 @@ public class IndicatorsDefCtrl { ...@@ -57,12 +65,19 @@ public class IndicatorsDefCtrl {
return baseIndDefService.getByPageAndKeyword(catalogId, keyword, page, rows); return baseIndDefService.getByPageAndKeyword(catalogId, keyword, page, rows);
} }
@ApiOperation(value = "新建考核指标", notes = "新建考核指标") @ApiOperation(value = "获取考核指标最大id", notes = "获取考核指标最大id")
@PostMapping(value = "/getDriveIndMaxId")
public String getDriveIndMaxId(@RequestParam String code,
@RequestParam Integer length) throws Exception{
return driveIndDefService.getDriveIndMaxIndId(code, length);
}
@ApiOperation(value = "新建考核指标(isUpdate:0 新增 1修改)", notes = "新建考核指标(isUpdate:0 新增 1修改)")
@PostMapping(value = "/createDriveInd") @PostMapping(value = "/createDriveInd")
public void createDriveInd(@RequestBody DriveIndDef driveIndDef,@RequestParam Integer catalogId, public void createDriveInd(@RequestBody DriveIndDef driveIndDef,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user, @RequestParam String catalogIdPath,@RequestParam String user,@RequestParam String isUpdate,
@RequestParam String shortboardIds) throws Exception{ @RequestParam String shortboardIds) throws Exception{
driveIndDefService.saveOrUpdate(driveIndDef, catalogId, catalogIdPath, user,shortboardIds); driveIndDefService.saveOrUpdate(driveIndDef, catalogId, catalogIdPath, user, isUpdate, shortboardIds);
} }
@ApiOperation(value = "删除考核指标", notes = "删除考核指标") @ApiOperation(value = "删除考核指标", notes = "删除考核指标")
......
...@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.indicators.BaseIndDef; import com.keymobile.indicators.model.entity.indicators.BaseIndDef;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper; import tk.mybatis.mapper.common.BaseMapper;
@Mapper @Mapper
...@@ -16,4 +17,6 @@ public interface BaseIndDefMapper extends BaseMapper<BaseIndDef>{ ...@@ -16,4 +17,6 @@ public interface BaseIndDefMapper extends BaseMapper<BaseIndDef>{
public int getByKeywordCount(Map<String,Object> param); public int getByKeywordCount(Map<String,Object> param);
public void deleteByCatalogIdIn(List<Integer> catalogIds); public void deleteByCatalogIdIn(List<Integer> catalogIds);
public String getMaxIndId(@Param("code")String code,@Param("length")int length);
} }
...@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef; import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper; import tk.mybatis.mapper.common.BaseMapper;
@Mapper @Mapper
...@@ -16,4 +17,6 @@ public interface DriveIndDefMapper extends BaseMapper<DriveIndDef>{ ...@@ -16,4 +17,6 @@ public interface DriveIndDefMapper extends BaseMapper<DriveIndDef>{
public int getByKeywordCount(Map<String,Object> param); public int getByKeywordCount(Map<String,Object> param);
public void deleteByCatalogIdIn(List<Integer> catalogIds); public void deleteByCatalogIdIn(List<Integer> catalogIds);
public String getMaxIndId(@Param("code")String code,@Param("length")int length);
} }
...@@ -19,13 +19,18 @@ public class BaseIndDefService { ...@@ -19,13 +19,18 @@ public class BaseIndDefService {
@Autowired @Autowired
private BaseIndDefVersionService baseIndDefVersionService; private BaseIndDefVersionService baseIndDefVersionService;
public String saveOrUpdate(BaseIndDef baseIndDef,Integer catalogId,String catalogIdPath,String user) public String saveOrUpdate(BaseIndDef baseIndDef,Integer catalogId,
String catalogIdPath,String user,String isUpdate)
throws Exception{ throws Exception{
if(StringUtils.isBlank(baseIndDef.getIndId())) { if(StringUtils.isBlank(baseIndDef.getIndId())) {
return "indId can not be null"; return "indId can not be null";
} }
//如果是新增,需要判断库中是否已存在指标编号
if("0".equals(isUpdate)) {//新增
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId()); BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef==null) { if(dbBaseIndDef!=null) {
return "indId is exist,create base indicators fail";
}else {
baseIndDef.setCreater(user); baseIndDef.setCreater(user);
baseIndDef.setCreateTime(new Date()); baseIndDef.setCreateTime(new Date());
baseIndDef.setUpdater(user); baseIndDef.setUpdater(user);
...@@ -34,7 +39,10 @@ public class BaseIndDefService { ...@@ -34,7 +39,10 @@ public class BaseIndDefService {
baseIndDef.setCatalogId(catalogId); baseIndDef.setCatalogId(catalogId);
baseIndDef.setCatalogIdPath(catalogIdPath); baseIndDef.setCatalogIdPath(catalogIdPath);
baseIndDefMapper.insert(baseIndDef); baseIndDefMapper.insert(baseIndDef);
}else { }
}else {//修改
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef!=null) {
//生成版本 //生成版本
if(baseIndDefVersionService.save(dbBaseIndDef)) { if(baseIndDefVersionService.save(dbBaseIndDef)) {
String oldVersion = dbBaseIndDef.getVersion(); String oldVersion = dbBaseIndDef.getVersion();
...@@ -46,6 +54,9 @@ public class BaseIndDefService { ...@@ -46,6 +54,9 @@ public class BaseIndDefService {
baseIndDef.setCatalogIdPath(catalogIdPath); baseIndDef.setCatalogIdPath(catalogIdPath);
baseIndDefMapper.updateByPrimaryKey(baseIndDef); baseIndDefMapper.updateByPrimaryKey(baseIndDef);
} }
}else {
return "base ind is not exist,update ind fail";
}
} }
return "success;indId:"+baseIndDef.getIndId(); return "success;indId:"+baseIndDef.getIndId();
} }
...@@ -83,4 +94,19 @@ public class BaseIndDefService { ...@@ -83,4 +94,19 @@ public class BaseIndDefService {
return resultMap; return resultMap;
} }
public String getBaseIndMaxIndId(String code,int length) {
if(code.length()>=length) {
return "id的编码不能大于等于id的长度";
}
String maxId = baseIndDefMapper.getMaxIndId(code+"%", length);
if(StringUtils.isBlank(maxId)) {
String addZero = "";
for(int i=0;i<(length-code.length()-1);i++) {
addZero += "0";
}
maxId = code+addZero+"1";
}
return maxId;
}
} }
...@@ -37,12 +37,15 @@ public class DriveIndDefService { ...@@ -37,12 +37,15 @@ public class DriveIndDefService {
private ShortboardRuleMapper shortboardRuleMapper; private ShortboardRuleMapper shortboardRuleMapper;
public String saveOrUpdate(DriveIndDef driveIndDef,Integer catalogId,String catalogIdPath, public String saveOrUpdate(DriveIndDef driveIndDef,Integer catalogId,String catalogIdPath,
String user,String shortboardIds)throws Exception{ String user,String isUpdate,String shortboardIds)throws Exception{
if(StringUtils.isBlank(driveIndDef.getIndId())) { if(StringUtils.isBlank(driveIndDef.getIndId())) {
return "indId can not be null"; return "indId can not be null";
} }
DriveIndDef dbBaseIndDef = this.getById(driveIndDef.getIndId()); if("0".equals(isUpdate)) {//新建
if(dbBaseIndDef==null) { DriveIndDef dbDriveIndDef = this.getById(driveIndDef.getIndId());
if(dbDriveIndDef==null) {
return "indId is exist,create drive indicators fail";
}else {
driveIndDef.setCreater(user); driveIndDef.setCreater(user);
driveIndDef.setCreateTime(new Date()); driveIndDef.setCreateTime(new Date());
driveIndDef.setUpdater(user); driveIndDef.setUpdater(user);
...@@ -51,10 +54,13 @@ public class DriveIndDefService { ...@@ -51,10 +54,13 @@ public class DriveIndDefService {
driveIndDef.setCatalogId(catalogId); driveIndDef.setCatalogId(catalogId);
driveIndDef.setCatalogIdPath(catalogIdPath); driveIndDef.setCatalogIdPath(catalogIdPath);
driveIndDefMapper.insert(driveIndDef); driveIndDefMapper.insert(driveIndDef);
}
}else { }else {
DriveIndDef dbDriveIndDef = this.getById(driveIndDef.getIndId());
if(dbDriveIndDef!=null) {
//生成版本 //生成版本
if(driveIndDefVersionService.save(dbBaseIndDef)) { if(driveIndDefVersionService.save(dbDriveIndDef)) {
String oldVersion = dbBaseIndDef.getVersion(); String oldVersion = dbDriveIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1 String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
driveIndDef.setUpdater(user); driveIndDef.setUpdater(user);
driveIndDef.setUpdateTime(new Date()); driveIndDef.setUpdateTime(new Date());
...@@ -63,6 +69,9 @@ public class DriveIndDefService { ...@@ -63,6 +69,9 @@ public class DriveIndDefService {
driveIndDef.setCatalogIdPath(catalogIdPath); driveIndDef.setCatalogIdPath(catalogIdPath);
driveIndDefMapper.updateByPrimaryKey(driveIndDef); driveIndDefMapper.updateByPrimaryKey(driveIndDef);
} }
}else {
return "drive ind is not exist,update ind fail";
}
} }
//插入短板筛选规则 //插入短板筛选规则
if(StringUtils.isNotBlank(shortboardIds)) { if(StringUtils.isNotBlank(shortboardIds)) {
...@@ -178,4 +187,22 @@ public class DriveIndDefService { ...@@ -178,4 +187,22 @@ public class DriveIndDefService {
} }
return result; return result;
} }
public String getDriveIndMaxIndId(String code,int length) {
code = "A"+code;
if(code.length()>=length) {
return "id的编码不能大于等于id的长度";
}
String maxId = driveIndDefMapper.getMaxIndId(code+"%", length);
if(StringUtils.isBlank(maxId)) {
String addZero = "";
for(int i=0;i<(length-code.length()-1);i++) {
addZero += "0";
}
maxId = code+addZero+"1";
}else {
maxId = "A"+maxId;
}
return maxId;
}
} }
...@@ -34,4 +34,10 @@ ...@@ -34,4 +34,10 @@
#{id} #{id}
</foreach> </foreach>
</delete> </delete>
<select id="getMaxIndId" resultType="java.lang.String">
select (max(CAST(ind_id as SIGNED INTEGER))+1) as maxId
from base_ind_def
where ind_id like #{code} and LENGTH(ind_id)=#{length}
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -34,4 +34,10 @@ ...@@ -34,4 +34,10 @@
#{id} #{id}
</foreach> </foreach>
</delete> </delete>
<select id="getMaxIndId" resultType="java.lang.String">
select (max(CAST(SUBSTRING(ind_id,2) as SIGNED INTEGER))+1) as maxId
from drive_ind_def
where ind_id like #{code} and LENGTH(ind_id)=#{length};
</select>
</mapper> </mapper>
\ No newline at end of file
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