Commit 710abc78 by zhangkb

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

parent 4c2dbb08
......@@ -30,11 +30,19 @@ public class IndicatorsDefCtrl {
@Autowired
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")
public void createBaseInd(@RequestBody BaseIndDef baseIndDef,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user) throws Exception{
baseIndDefService.saveOrUpdate(baseIndDef, catalogId, catalogIdPath, user);
@RequestParam String catalogIdPath,@RequestParam String user,
@RequestParam String isUpdate) throws Exception{
baseIndDefService.saveOrUpdate(baseIndDef, catalogId, catalogIdPath, user, isUpdate);
}
@ApiOperation(value = "删除基础指标", notes = "删除基础指标")
......@@ -57,12 +65,19 @@ public class IndicatorsDefCtrl {
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")
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{
driveIndDefService.saveOrUpdate(driveIndDef, catalogId, catalogIdPath, user,shortboardIds);
driveIndDefService.saveOrUpdate(driveIndDef, catalogId, catalogIdPath, user, isUpdate, shortboardIds);
}
@ApiOperation(value = "删除考核指标", notes = "删除考核指标")
......
......@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import com.keymobile.indicators.model.entity.indicators.BaseIndDef;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
......@@ -16,4 +17,6 @@ public interface BaseIndDefMapper extends BaseMapper<BaseIndDef>{
public int getByKeywordCount(Map<String,Object> param);
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;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import feign.Param;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
......@@ -16,4 +17,6 @@ public interface DriveIndDefMapper extends BaseMapper<DriveIndDef>{
public int getByKeywordCount(Map<String,Object> param);
public void deleteByCatalogIdIn(List<Integer> catalogIds);
public String getMaxIndId(@Param("code")String code,@Param("length")int length);
}
......@@ -19,32 +19,43 @@ public class BaseIndDefService {
@Autowired
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{
if(StringUtils.isBlank(baseIndDef.getIndId())) {
return "indId can not be null";
}
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef==null) {
baseIndDef.setCreater(user);
baseIndDef.setCreateTime(new Date());
baseIndDef.setUpdater(user);
baseIndDef.setUpdateTime(new Date());
baseIndDef.setVersion("1.0");
baseIndDef.setCatalogId(catalogId);
baseIndDef.setCatalogIdPath(catalogIdPath);
baseIndDefMapper.insert(baseIndDef);
}else {
//生成版本
if(baseIndDefVersionService.save(dbBaseIndDef)) {
String oldVersion = dbBaseIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
//如果是新增,需要判断库中是否已存在指标编号
if("0".equals(isUpdate)) {//新增
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef!=null) {
return "indId is exist,create base indicators fail";
}else {
baseIndDef.setCreater(user);
baseIndDef.setCreateTime(new Date());
baseIndDef.setUpdater(user);
baseIndDef.setUpdateTime(new Date());
baseIndDef.setVersion(newVersion);
baseIndDef.setVersion("1.0");
baseIndDef.setCatalogId(catalogId);
baseIndDef.setCatalogIdPath(catalogIdPath);
baseIndDefMapper.updateByPrimaryKey(baseIndDef);
baseIndDefMapper.insert(baseIndDef);
}
}else {//修改
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef!=null) {
//生成版本
if(baseIndDefVersionService.save(dbBaseIndDef)) {
String oldVersion = dbBaseIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
baseIndDef.setUpdater(user);
baseIndDef.setUpdateTime(new Date());
baseIndDef.setVersion(newVersion);
baseIndDef.setCatalogId(catalogId);
baseIndDef.setCatalogIdPath(catalogIdPath);
baseIndDefMapper.updateByPrimaryKey(baseIndDef);
}
}else {
return "base ind is not exist,update ind fail";
}
}
return "success;indId:"+baseIndDef.getIndId();
......@@ -83,4 +94,19 @@ public class BaseIndDefService {
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,31 +37,40 @@ public class DriveIndDefService {
private ShortboardRuleMapper shortboardRuleMapper;
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())) {
return "indId can not be null";
}
DriveIndDef dbBaseIndDef = this.getById(driveIndDef.getIndId());
if(dbBaseIndDef==null) {
driveIndDef.setCreater(user);
driveIndDef.setCreateTime(new Date());
driveIndDef.setUpdater(user);
driveIndDef.setUpdateTime(new Date());
driveIndDef.setVersion("1.0");
driveIndDef.setCatalogId(catalogId);
driveIndDef.setCatalogIdPath(catalogIdPath);
driveIndDefMapper.insert(driveIndDef);
}else {
//生成版本
if(driveIndDefVersionService.save(dbBaseIndDef)) {
String oldVersion = dbBaseIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
if("0".equals(isUpdate)) {//新建
DriveIndDef dbDriveIndDef = this.getById(driveIndDef.getIndId());
if(dbDriveIndDef==null) {
return "indId is exist,create drive indicators fail";
}else {
driveIndDef.setCreater(user);
driveIndDef.setCreateTime(new Date());
driveIndDef.setUpdater(user);
driveIndDef.setUpdateTime(new Date());
driveIndDef.setVersion(newVersion);
driveIndDef.setVersion("1.0");
driveIndDef.setCatalogId(catalogId);
driveIndDef.setCatalogIdPath(catalogIdPath);
driveIndDefMapper.updateByPrimaryKey(driveIndDef);
driveIndDefMapper.insert(driveIndDef);
}
}else {
DriveIndDef dbDriveIndDef = this.getById(driveIndDef.getIndId());
if(dbDriveIndDef!=null) {
//生成版本
if(driveIndDefVersionService.save(dbDriveIndDef)) {
String oldVersion = dbDriveIndDef.getVersion();
String newVersion = String.valueOf(Double.valueOf(oldVersion)+1);//旧版本+1
driveIndDef.setUpdater(user);
driveIndDef.setUpdateTime(new Date());
driveIndDef.setVersion(newVersion);
driveIndDef.setCatalogId(catalogId);
driveIndDef.setCatalogIdPath(catalogIdPath);
driveIndDefMapper.updateByPrimaryKey(driveIndDef);
}
}else {
return "drive ind is not exist,update ind fail";
}
}
//插入短板筛选规则
......@@ -178,4 +187,22 @@ public class DriveIndDefService {
}
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 @@
#{id}
</foreach>
</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>
\ No newline at end of file
......@@ -34,4 +34,10 @@
#{id}
</foreach>
</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>
\ 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