This commit is contained in:
kuang.yife 2024-10-28 16:45:10 +08:00
parent b57f751831
commit 1a18fbb03b
3 changed files with 54 additions and 10 deletions

View File

@ -1,11 +1,18 @@
package com.ghy.goods.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import com.ghy.common.utils.DateUtils;
import com.ghy.goods.domain.DeptCategoryInsuranceRelation;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.IDeptCategoryInsuranceRelationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -14,6 +21,8 @@ import com.ghy.goods.domain.CategoryInsuranceRelation;
import com.ghy.goods.service.ICategoryInsuranceRelationService;
import com.ghy.common.core.text.Convert;
import javax.annotation.Resource;
/**
* 总类目保险关联关系Service业务层处理
*
@ -26,6 +35,12 @@ public class CategoryInsuranceRelationServiceImpl implements ICategoryInsuranceR
@Autowired
private CategoryInsuranceRelationMapper categoryInsuranceRelationMapper;
@Resource
private IDeptCategoryInsuranceRelationService deptCategoryInsuranceRelationService;
@Resource
private DeptGoodsCategoryService deptGoodsCategoryService;
/**
* 查询总类目保险关联关系
*
@ -105,20 +120,46 @@ public class CategoryInsuranceRelationServiceImpl implements ICategoryInsuranceR
CategoryInsuranceRelation param = new CategoryInsuranceRelation();
param.setGoodsCategoryId(categoryId);
List<CategoryInsuranceRelation> oldRecord = categoryInsuranceRelationMapper.selectCategoryInsuranceRelationList(param);
Map<Long, CategoryInsuranceRelation> insuranceRelationMap = oldRecord.stream().collect(Collectors.toMap(CategoryInsuranceRelation::getInsuranceId, Function.identity(), (x1, x2)->x1));
// 已存在的id
List<Long> oldIds = oldRecord.stream().map(CategoryInsuranceRelation::getInsuranceId).collect(Collectors.toList());
// 新的
List<Long> newIds = new ArrayList<>();
if(StringUtils.isNotEmpty(insuranceIds)){
for (String id : insuranceIds.split(",")) {
newIds.add(Long.valueOf(id));
}
}
// 删除旧的
List<Long> delOlds = oldIds.stream().filter(x->!newIds.contains(x)).collect(Collectors.toList());
// 增加新的
List<Long> addNews = newIds.stream().filter(x->!oldIds.contains(x)).collect(Collectors.toList());
// 删除历史记录
if(CollectionUtil.isNotEmpty(oldRecord)){
String [] arr = new String[oldRecord.size()];
for (int index = 0; index < oldRecord.size(); index ++){
arr[index] = oldRecord.get(index).getId().toString();
if(CollectionUtil.isNotEmpty(delOlds)){
String [] arr = new String[delOlds.size()];
for (int index = 0; index < delOlds.size(); index ++){
arr[index] = insuranceRelationMap.get(delOlds.get(index)).getId().toString();
// 删除关联的平台类目的
// 查找类目
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(categoryId);
if(deptGoodsCategory != null){
DeptCategoryInsuranceRelation deptCategoryInsuranceRelation = new DeptCategoryInsuranceRelation();
deptCategoryInsuranceRelation.setDeptCategoryId(deptGoodsCategory.getDeptGoodsCategoryId());
deptCategoryInsuranceRelation.setInsuranceId(delOlds.get(index));
List<DeptCategoryInsuranceRelation> delList = deptCategoryInsuranceRelationService.selectDeptCategoryInsuranceRelationList(deptCategoryInsuranceRelation);
delList.forEach(model->{
deptCategoryInsuranceRelationService.deleteDeptCategoryInsuranceRelationById(model.getId());
});
}
}
categoryInsuranceRelationMapper.deleteCategoryInsuranceRelationByIds(arr);
}
// 增加新记录
if(StringUtils.isNotEmpty(insuranceIds)){
String [] insuranceStr = insuranceIds.split(",");
for (String str : insuranceStr) {
if(CollectionUtil.isNotEmpty(addNews)){
for (Long id : addNews) {
CategoryInsuranceRelation model = new CategoryInsuranceRelation();
model.setInsuranceId(Long.valueOf(str));
model.setInsuranceId(id);
model.setGoodsCategoryId(categoryId);
categoryInsuranceRelationMapper.insertCategoryInsuranceRelation(model);
}

View File

@ -190,6 +190,9 @@
<if test="goodsCategoryName != null and goodsCategoryName != ''">
AND gc.goods_category_name LIKE concat('%', #{goodsCategoryName}, '%')
</if>
<if test="goodsCategoryId != null">
AND gc.goods_category_id = #{goodsCategoryId}
</if>
<if test="status != null and status != ''">
AND gc.status = #{status}
</if>
@ -213,7 +216,7 @@
<select id="selectOneByGoodsCategoryId" resultMap="DeptGoodsCategoryResult">
<include refid="selectJoin"/>
WHERE gc.goods_category_id = #{goodsCategoryId} LIMIT 1
WHERE gc.goods_category_id = #{goodsCategoryId} and dept_id = 101 LIMIT 1
</select>
<select id="selectByDeptId" resultMap="DeptGoodsCategoryResult">

View File

@ -453,7 +453,7 @@
<if test="orderMode != null">#{orderMode},</if>
<if test="payMode != null">#{payMode},</if>
<if test="consultMode != null">#{consultMode},</if>
<if test="insuranceId != null">#{consultMode},</if>
<if test="insuranceId != null">#{insuranceId},</if>
<if test="orderStatus != null">#{orderStatus},</if>
<if test="payType != null">#{payType},</if>
<if test="payStatus != null">#{payStatus},</if>