Commit b6ae7575 by dengwei

修复删除权重配置时,关联数据未被删除的bug

parent 56646b51
......@@ -22,4 +22,10 @@ public interface ObjScoreIndWeightDetailMapper extends BaseMapper<ObjScoreIndWei
*/
void deleteByCfgId(@Param("cfgId") Integer cfgId);
/**
* 根据权重配置ID集合批量删除权重数据填报
* @param ids 权重配置ID集合
*/
void batchDeleteByCfgIds(@Param("ids") List<Integer> ids);
}
......@@ -2,6 +2,7 @@ package com.keymobile.indicators.model.mapper.weight;
import com.keymobile.indicators.model.entity.weight.WeightExcelIndicator;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.BaseMapper;
import java.util.List;
......@@ -22,4 +23,10 @@ public interface WeightExcelIndicatorMapper extends BaseMapper<WeightExcelIndica
*/
void deleteByTempId(Integer tempId);
/**
* 根据模板ID集合删除模板关联指标项
* @param ids
*/
void batchDeleteByTempIds(@Param("ids") List<Integer> ids);
}
......@@ -2,6 +2,7 @@ package com.keymobile.indicators.model.mapper.weight;
import com.keymobile.indicators.model.entity.weight.WeightExcelObj;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.BaseMapper;
import java.util.List;
......@@ -22,4 +23,6 @@ public interface WeightExcelObjMapper extends BaseMapper<WeightExcelObj> {
*/
void deleteByTempId(Integer tempId);
void batchDeleteByTempIds(@Param("ids") List<Integer> ids);
}
......@@ -4,6 +4,8 @@ import com.keymobile.indicators.model.entity.weight.WeightExcelTemplate;
import org.apache.ibatis.annotations.Mapper;
import tk.mybatis.mapper.common.BaseMapper;
import java.util.List;
@Mapper
public interface WeightExcelTemplateMapper extends BaseMapper<WeightExcelTemplate> {
......@@ -25,4 +27,11 @@ public interface WeightExcelTemplateMapper extends BaseMapper<WeightExcelTemplat
* @param weightId 权重ID
*/
void deleteByWeightId(Integer weightId);
/**
* 根据权重配置ID获取已废弃的模板ID集合(state = 3)
* @param weightId 权重配置ID
* @return 已废弃的模板ID集合
*/
List<Integer> selectAllIdByWeightId(Integer weightId);
}
......@@ -17,12 +17,6 @@ public interface WeightIndValueMapper extends BaseMapper<WeightIndValue> {
void batchInsert(@Param("valueList") List<WeightIndValue> valueList);
/**
* 根据 指标id 机构编码 时间维度删除
* @param newValues
**/
void batchDelete(@Param("newValues") List<WeightIndValue> newValues);
/**
* 根据权重配置ID删除权重数据填报
* @param weightId 权重配置ID
*/
......@@ -35,4 +29,6 @@ public interface WeightIndValueMapper extends BaseMapper<WeightIndValue> {
*/
List<WeightIndValue> findByWeightId(@Param("weightId") Integer weightId);
void batchDeleteByWeightIds(@Param("ids") List<Integer> ids);
}
......@@ -5,9 +5,14 @@ import com.keymobile.indicators.model.entity.ObjScoreIndWeightCfg;
import com.keymobile.indicators.model.entity.dataenter.TaskRuleGroupObj;
import com.keymobile.indicators.model.entity.dataenter.TaskRuleIndicator;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.weight.WeightExcelTemplate;
import com.keymobile.indicators.model.entity.weight.WeightIndValue;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
import com.keymobile.indicators.model.mapper.indicators.ObjScoreIndWeightCfgMapper;
import com.keymobile.indicators.model.mapper.weight.ObjScoreIndWeightDetailMapper;
import com.keymobile.indicators.model.mapper.weight.WeightExcelIndicatorMapper;
import com.keymobile.indicators.model.mapper.weight.WeightExcelObjMapper;
import com.keymobile.indicators.model.mapper.weight.WeightExcelTemplateMapper;
import com.keymobile.indicators.model.mapper.weight.WeightIndValueMapper;
import com.keymobile.indicators.service.ObjScoreIndWeightCfgService;
import com.keymobile.indicators.service.dataenter.TaskRuleGroupObjService;
......@@ -45,6 +50,14 @@ public class ObjScoreIndWeightCfgServiceImpl implements ObjScoreIndWeightCfgServ
private TaskRuleGroupObjService taskRuleGroupObjService;
@Autowired
private WeightIndValueService weightIndValueService;
@Autowired
private WeightExcelObjMapper excelObjMapper;
@Autowired
private WeightExcelIndicatorMapper excelIndicatorMapper;
@Autowired
private ObjScoreIndWeightDetailMapper weightDetailMapper;
@Autowired
private WeightExcelTemplateMapper excelTemplateMapper;
@Override
public void deleteById(Integer id) {
......@@ -146,6 +159,24 @@ public class ObjScoreIndWeightCfgServiceImpl implements ObjScoreIndWeightCfgServ
@Override
public void delete(List<Integer> ids) {
weightCfgMapper.deleteByIdIn(ids);
deleteCorrelationTableByWeightId(ids);
}
/**
* 根据权重ID删除权重关联表(obj_score_ind_weight_cfg(主表), obj_score_ind_weight_detail, weight_data_excel_ind, weight_data_excel_obj, weight_data_excel_temp, weight_ind_value)中的数据
* @param ids 权重ID集合
*/
private void deleteCorrelationTableByWeightId(List<Integer> ids) {
weightIndValueMapper.batchDeleteByWeightIds(ids);
weightDetailMapper.batchDeleteByCfgIds(ids);
List<Integer> tempIds = new ArrayList<>();
for (Integer weightId : ids) {
WeightExcelTemplate template = excelTemplateMapper.getByWeightId(weightId);
tempIds.add(template.getId());
excelTemplateMapper.deleteByWeightId(weightId);
}
excelIndicatorMapper.batchDeleteByTempIds(tempIds);
excelObjMapper.batchDeleteByTempIds(tempIds);
}
@Override
......
......@@ -65,6 +65,7 @@ public class WeightExcelTemplateServiceImpl implements WeightExcelTemplateServic
// 需要保证weight_data_excel_temp表中weight_id关联的数据唯一
// 先删除(将表数据state修改为3-废弃),再添加
excelTemplateMapper.deleteByWeightId(template.getWeightId());
deleteOldIndAndOldObj(template);
Date now = new Date();
String currentUserId = SystemUserUtil.getCurrentUserId();
template.setUpdater(currentUserId);
......@@ -77,6 +78,16 @@ public class WeightExcelTemplateServiceImpl implements WeightExcelTemplateServic
}
/**
* 在新增模板前,需要把模板指标关联表和模板对象关联表数据清除(逻辑删除)
* @param template
*/
private void deleteOldIndAndOldObj(WeightExcelTemplate template) {
List<Integer> ids = excelTemplateMapper.selectAllIdByWeightId(template.getWeightId());
excelIndicatorMapper.batchDeleteByTempIds(ids);
excelObjMapper.batchDeleteByTempIds(ids);
}
/**
* 插入指标和对象信息
* @param template
* @param now
......
......@@ -18,5 +18,14 @@
delete from obj_score_ind_weight_detail where cfg_id = #{cfgId}
</delete>
<delete id="batchDeleteByCfgIds" parameterType="list">
delete
from obj_score_ind_weight_detail
where cfg_id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
......@@ -10,10 +10,19 @@
</select>
<delete id="deleteByTempId" parameterType="java.lang.Integer">
delete
from weight_data_excel_ind
where temp_id = #{tempId}
</delete>
<update id="deleteByTempId" parameterType="java.lang.Integer">
update weight_data_excel_ind
set state = 3
where temp_id = #{tempId} and state = 1
</update>
<update id="batchDeleteByTempIds" parameterType="java.util.List">
update weight_data_excel_ind
set state = 3
where state = 1 and temp_id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
\ No newline at end of file
......@@ -10,10 +10,19 @@
</select>
<delete id="deleteByTempId" parameterType="java.lang.Integer">
delete
from weight_data_excel_obj
where temp_id = #{tempId}
</delete>
<update id="deleteByTempId" parameterType="java.lang.Integer">
update weight_data_excel_obj
set state = 3
where state = 1 and temp_id = #{tempId}
</update>
<update id="batchDeleteByTempIds" parameterType="java.util.List">
update weight_data_excel_obj
set state = 3
where state = 1 and temp_id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
\ No newline at end of file
......@@ -20,4 +20,10 @@
where state = 1 and weight_id = #{weightId}
</update>
<select id="selectAllIdByWeightId" parameterType="java.lang.Integer" resultType="java.lang.Integer">
select id
from weight_data_excel_temp
where state = 3 and weight_id = #{weightId}
</select>
</mapper>
\ No newline at end of file
......@@ -15,21 +15,23 @@
</foreach>
</insert>
<delete id="batchDelete" parameterType="com.keymobile.indicators.model.entity.weight.WeightIndValue" >
<foreach collection="newValues" item="val" separator=";">
delete from weight_ind_value
where weight_id=#{val.weightId} and ind_id = #{val.indId} and obj_id = #{val.objId}
</foreach>
</delete>
<delete id="deleteByWeightId" parameterType="java.lang.Integer">
delete from weight_ind_value where weight_id = #{weightId}
</delete>
<update id="deleteByWeightId" parameterType="java.lang.Integer">
update weight_ind_value
set state = 3
where state = 1 and weight_id = #{weightId}
</update>
<select id="findByWeightId" parameterType="java.lang.Integer" resultType="com.keymobile.indicators.model.entity.weight.WeightIndValue">
select * from weight_ind_value where weight_id = #{weightId}
select * from weight_ind_value where weight_id = #{weightId} and state = 1
</select>
<update id="batchDeleteByWeightIds" parameterType="java.util.List">
update weight_ind_value
set state = 3
where state = 1 and weight_id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</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