Commit bbaecc6f by zhangkb

添加对标计算前删除相关对标单元数据逻辑处理

parent bf92a8fa
......@@ -78,4 +78,12 @@ public class DriveIndCalResultCtrl {
@RequestParam Integer date){
return driveIndCalResultService.findByCompareIdAndDate(compareId, date);
}
@ApiOperation(value = "根据对标单元id和年份删除相关数据", notes = "根据对标单元id和年份删除相关数据")
@PostMapping(value = "/deleteCompareUnitData")
public void deleteCompareUnitData(@RequestParam List<String> compareIds,
@RequestParam Integer currentDate,@RequestParam Integer sameDate,
@RequestParam String code) {
driveIndCalResultService.deleteCompareUnitData(compareIds, currentDate, sameDate, code);
}
}
......@@ -63,4 +63,7 @@ public interface DriveIndCalResultDefMapper extends BaseMapper<DriveIndCalResult
//根据指标编号和对标单位根据对标时间降序获取指标考核结果
public List<DriveIndCalResultDef> findByIndIdAndCompareObjOrderByDateDesc(@Param("indId") String indId,
@Param("compareObj") String compareObj,@Param("code") String code);
//根据对标单元id和对标日期删除相关考核结果数据
public void deleteByCompareIdInAndDateIn(Map<String,Object> param);
}
package com.keymobile.indicators.model.mapper.indmapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -17,4 +18,7 @@ public interface ObjScoreCalResultMapper extends BaseMapper<ObjScoreCalResult>{
public void batchSave(@Param("datas")List<ObjScoreCalResult> datas);
public void batchUpdate(@Param("datas")List<ObjScoreCalResult> datas);
//根据对标单元id和对标日期删除相关单位评分结果数据
public void deleteByCompareIdInAndDateIn(Map<String,Object> param);
}
package com.keymobile.indicators.model.mapper.report;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -18,4 +19,7 @@ public interface ReportOneMapper extends BaseMapper<IndicatorsReportOne>{
public void batchSave(@Param("datas")List<IndicatorsReportOne> datas);
public void batchUpdate(@Param("datas")List<IndicatorsReportOne> datas);
//根据对标单元id和对标日期删除相关报表结果数据
public void deleteByCompareIdInAndDateIn(Map<String,Object> param);
}
package com.keymobile.indicators.model.mapper.report;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -17,4 +18,7 @@ public interface ReportTwoMapper extends BaseMapper<IndicatorsReportTwo>{
public void batchSave(@Param("datas")List<IndicatorsReportTwo> datas);
public void batchUpdate(@Param("datas")List<IndicatorsReportTwo> datas);
//根据对标单元id和对标日期删除相关单位评分结果数据
public void deleteByCompareIdInAndDateIn(Map<String,Object> param);
}
package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,6 +16,9 @@ import com.keymobile.indicators.akka.message.indicators.StartCompareUnitCalMsg;
import com.keymobile.indicators.model.entity.indicators.CompareUnitDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.mapper.indmapper.DriveIndCalResultDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.ObjScoreCalResultMapper;
import com.keymobile.indicators.model.mapper.report.ReportOneMapper;
import com.keymobile.indicators.model.mapper.report.ReportTwoMapper;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
......@@ -24,6 +30,12 @@ public class DriveIndCalResultService {
@Autowired
private DriveIndCalResultDefMapper driveIndCalResultDefMapper;
@Autowired
private ObjScoreCalResultMapper objScoreCalResultMapper;
@Autowired
private ReportOneMapper reportOneMapper;
@Autowired
private ReportTwoMapper reportTwoMapper;
public int saveOrUpdate(DriveIndCalResultDef driveIndCalResult) {
if(driveIndCalResult.getId()==null) {
......@@ -73,15 +85,27 @@ public class DriveIndCalResultService {
return driveIndCalResultDefMapper.findByCompareIdAndDate(compareId, date);
}
public void compareUnitListCal(List<CompareUnitDef> compareUnitList,String code,String isTest) {
public void compareUnitListCal(List<CompareUnitDef> compareUnitList,String code,
String isTest) throws Exception {
if(!compareUnitList.isEmpty()) {
List<CompareUnitDef> sameCompareUnitList = new ArrayList<>();
List<String> compareIds = new ArrayList<>();
Integer currentDate = null;
Integer sameDate = null;
//将对标单元的日期改成同期
for(CompareUnitDef unitDef : compareUnitList) {
Integer date = unitDef.getDate()-100;
unitDef.setDate(date);
sameCompareUnitList.add(unitDef);
compareIds.add(unitDef.getCompareId());
currentDate = unitDef.getDate();
sameDate = date;
}
//对标运算前先删除相关旧数据
this.deleteCompareUnitData(compareIds, currentDate, sameDate, code);
Thread.sleep(3000);
//启动回流actor
final ActorSystem system = ActorSystem.create("CompareUnitCalAkka");//创建akka
StartCompareUnitCalMsg startCompareUnitCalMsg = new StartCompareUnitCalMsg(
......@@ -92,4 +116,29 @@ public class DriveIndCalResultService {
logger.info("开始对标单元综合计算...");
}
}
//删除对应对标单元的数据,便于重新计算
public void deleteCompareUnitData(List<String> compareIds,
Integer currentDate,Integer sameDate,String code) {
if(StringUtils.isNotBlank(code) && !compareIds.isEmpty() &&
currentDate!=null && sameDate!=null) {
List<Integer> dates = new ArrayList<>();
Map<String,Object> param1 = new HashMap<>();
Map<String,Object> param2 = new HashMap<>();
dates.add(currentDate);
param1.put("code", code);
param1.put("compareIds", compareIds);
param1.put("dates", dates);
dates.add(sameDate);
param2.put("code", code);
param2.put("compareIds", compareIds);
param2.put("dates", dates);
//删除数据
reportOneMapper.deleteByCompareIdInAndDateIn(param1);
reportTwoMapper.deleteByCompareIdInAndDateIn(param1);
driveIndCalResultDefMapper.deleteByCompareIdInAndDateIn(param2);
objScoreCalResultMapper.deleteByCompareIdInAndDateIn(param2);
}
}
}
......@@ -236,4 +236,21 @@
code = #{code}
ORDER BY date desc
</select>
<delete id="deleteByCompareIdInAndDateIn" parameterType="map">
delete
from
drive_ind_cal_result_def
where
code = #{code} and
compare_id in
<foreach item="compareId" collection="compareIds" open="(" close=")" separator=",">
#{compareId}
</foreach>
and
date in
<foreach item="date" collection="dates" open="(" close=")" separator=",">
#{date}
</foreach>
</delete>
</mapper>
\ No newline at end of file
......@@ -61,4 +61,21 @@
where id = ${val.id}
</foreach>
</update>
<delete id="deleteByCompareIdInAndDateIn" parameterType="map">
delete
from
obj_score_cal_result
where
code = #{code} and
compare_id in
<foreach item="compareId" collection="compareIds" open="(" close=")" separator=",">
#{compareId}
</foreach>
and
date in
<foreach item="date" collection="dates" open="(" close=")" separator=",">
#{date}
</foreach>
</delete>
</mapper>
\ No newline at end of file
......@@ -101,4 +101,21 @@
where id = ${val.id}
</foreach>
</update>
<delete id="deleteByCompareIdInAndDateIn" parameterType="map">
delete
from
indicators_report_one
where
code = #{code} and
compare_unit_id in
<foreach item="compareId" collection="compareIds" open="(" close=")" separator=",">
#{compareId}
</foreach>
and
compare_date in
<foreach item="date" collection="dates" open="(" close=")" separator=",">
#{date}
</foreach>
</delete>
</mapper>
\ No newline at end of file
......@@ -124,4 +124,21 @@
where id = ${val.id}
</foreach>
</update>
<delete id="deleteByCompareIdInAndDateIn" parameterType="map">
delete
from
indicators_report_two
where
code = #{code} and
compare_unit_id in
<foreach item="compareId" collection="compareIds" open="(" close=")" separator=",">
#{compareId}
</foreach>
and
compare_date in
<foreach item="date" collection="dates" open="(" close=")" separator=",">
#{date}
</foreach>
</delete>
</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