fix bug
This commit is contained in:
parent
b57f751831
commit
1a18fbb03b
|
|
@ -1,11 +1,18 @@
|
||||||
package com.ghy.goods.service.impl;
|
package com.ghy.goods.service.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.ghy.common.utils.DateUtils;
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -14,6 +21,8 @@ import com.ghy.goods.domain.CategoryInsuranceRelation;
|
||||||
import com.ghy.goods.service.ICategoryInsuranceRelationService;
|
import com.ghy.goods.service.ICategoryInsuranceRelationService;
|
||||||
import com.ghy.common.core.text.Convert;
|
import com.ghy.common.core.text.Convert;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 总类目保险关联关系Service业务层处理
|
* 总类目保险关联关系Service业务层处理
|
||||||
*
|
*
|
||||||
|
|
@ -26,6 +35,12 @@ public class CategoryInsuranceRelationServiceImpl implements ICategoryInsuranceR
|
||||||
@Autowired
|
@Autowired
|
||||||
private CategoryInsuranceRelationMapper categoryInsuranceRelationMapper;
|
private CategoryInsuranceRelationMapper categoryInsuranceRelationMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IDeptCategoryInsuranceRelationService deptCategoryInsuranceRelationService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DeptGoodsCategoryService deptGoodsCategoryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询总类目保险关联关系
|
* 查询总类目保险关联关系
|
||||||
*
|
*
|
||||||
|
|
@ -105,20 +120,46 @@ public class CategoryInsuranceRelationServiceImpl implements ICategoryInsuranceR
|
||||||
CategoryInsuranceRelation param = new CategoryInsuranceRelation();
|
CategoryInsuranceRelation param = new CategoryInsuranceRelation();
|
||||||
param.setGoodsCategoryId(categoryId);
|
param.setGoodsCategoryId(categoryId);
|
||||||
List<CategoryInsuranceRelation> oldRecord = categoryInsuranceRelationMapper.selectCategoryInsuranceRelationList(param);
|
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)){
|
if(CollectionUtil.isNotEmpty(delOlds)){
|
||||||
String [] arr = new String[oldRecord.size()];
|
String [] arr = new String[delOlds.size()];
|
||||||
for (int index = 0; index < oldRecord.size(); index ++){
|
for (int index = 0; index < delOlds.size(); index ++){
|
||||||
arr[index] = oldRecord.get(index).getId().toString();
|
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);
|
categoryInsuranceRelationMapper.deleteCategoryInsuranceRelationByIds(arr);
|
||||||
}
|
}
|
||||||
// 增加新记录
|
// 增加新记录
|
||||||
if(StringUtils.isNotEmpty(insuranceIds)){
|
if(CollectionUtil.isNotEmpty(addNews)){
|
||||||
String [] insuranceStr = insuranceIds.split(",");
|
for (Long id : addNews) {
|
||||||
for (String str : insuranceStr) {
|
|
||||||
CategoryInsuranceRelation model = new CategoryInsuranceRelation();
|
CategoryInsuranceRelation model = new CategoryInsuranceRelation();
|
||||||
model.setInsuranceId(Long.valueOf(str));
|
model.setInsuranceId(id);
|
||||||
model.setGoodsCategoryId(categoryId);
|
model.setGoodsCategoryId(categoryId);
|
||||||
categoryInsuranceRelationMapper.insertCategoryInsuranceRelation(model);
|
categoryInsuranceRelationMapper.insertCategoryInsuranceRelation(model);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,9 @@
|
||||||
<if test="goodsCategoryName != null and goodsCategoryName != ''">
|
<if test="goodsCategoryName != null and goodsCategoryName != ''">
|
||||||
AND gc.goods_category_name LIKE concat('%', #{goodsCategoryName}, '%')
|
AND gc.goods_category_name LIKE concat('%', #{goodsCategoryName}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="goodsCategoryId != null">
|
||||||
|
AND gc.goods_category_id = #{goodsCategoryId}
|
||||||
|
</if>
|
||||||
<if test="status != null and status != ''">
|
<if test="status != null and status != ''">
|
||||||
AND gc.status = #{status}
|
AND gc.status = #{status}
|
||||||
</if>
|
</if>
|
||||||
|
|
@ -213,7 +216,7 @@
|
||||||
|
|
||||||
<select id="selectOneByGoodsCategoryId" resultMap="DeptGoodsCategoryResult">
|
<select id="selectOneByGoodsCategoryId" resultMap="DeptGoodsCategoryResult">
|
||||||
<include refid="selectJoin"/>
|
<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>
|
||||||
|
|
||||||
<select id="selectByDeptId" resultMap="DeptGoodsCategoryResult">
|
<select id="selectByDeptId" resultMap="DeptGoodsCategoryResult">
|
||||||
|
|
|
||||||
|
|
@ -453,7 +453,7 @@
|
||||||
<if test="orderMode != null">#{orderMode},</if>
|
<if test="orderMode != null">#{orderMode},</if>
|
||||||
<if test="payMode != null">#{payMode},</if>
|
<if test="payMode != null">#{payMode},</if>
|
||||||
<if test="consultMode != null">#{consultMode},</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="orderStatus != null">#{orderStatus},</if>
|
||||||
<if test="payType != null">#{payType},</if>
|
<if test="payType != null">#{payType},</if>
|
||||||
<if test="payStatus != null">#{payStatus},</if>
|
<if test="payStatus != null">#{payStatus},</if>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue