Commit b6ae7575 by dengwei

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

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