提交 b344ac59 authored 作者: zhouzhigang's avatar zhouzhigang

资源导入添加字段:目录、简介、分类

上级 f4ab1270
......@@ -6,6 +6,8 @@ import com.zrqx.core.exception.BaseException;
import com.zrqx.core.model.resource.diytype.DiyType;
import com.zrqx.core.model.resource.diytype.GoodsDiyTypeRelation;
import com.zrqx.core.util.datatype.ArrayUtils;
import com.zrqx.core.util.datatype.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -15,6 +17,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component
public class DiyTypeManage {
......@@ -78,7 +82,7 @@ public class DiyTypeManage {
/**
* 添加商品自定义分类
* @param goodsId
* @param
* @param diyTypeId
* @return
* @author lw
......@@ -189,5 +193,90 @@ public class DiyTypeManage {
}
return diyType;
}
/**
* 功能描述: <br>
* 〈〉保存图书与自定义分类的关系
* @Param: [goodsIds, diyTypeIds]
* @Return: boolean
* @Author: zzg
* @Date: 2020/12/21 16:12
*/
public boolean saveDiyTypes(List<String> goodsIds, String diyTypes){
if (StringUtils.isEmpty(diyTypes)) return true;
goodsIds.forEach(id -> {
GoodsDiyTypeRelation record = new GoodsDiyTypeRelation();
record.setGoodsid(id);
List<GoodsDiyTypeRelation> list = goodsDiyTypeRelationMapper.select(record);
if(list != null && list.size() > 0){
goodsDiyTypeRelationMapper.delete(record);
}
String[] types = diyTypes.split("-");
List<String> vList = Stream.of(types).collect(Collectors.toList());
String str = vList.get(vList.size() - 1);//获取集合中的最后一个元素
DiyType diyType = new DiyType();
diyType.setShowName(str);
List<DiyType> voList = diyTypeMapper.select(diyType);
if(1 == voList.size()){ //如果集合长度为1,则说明数据库中对应的自定义分类只有一个,直接进行绑定即可
GoodsDiyTypeRelation entity = new GoodsDiyTypeRelation();
entity.setGoodsid(id);
entity.setDiytypeid(voList.get(0).getId());
entity.setCode(voList.get(0).getCode());
entity.setId(null);
entity.setUpdateTime(new Date());
goodsDiyTypeRelationMapper.insertSelective(entity);
}else{ //集合长度大于1 说明数据库中的自定义分类有重复,需要根据它的上级分类去确定唯一值
String val1 = null;//分类
String val2 = null;//分类
String val3 = null;//分类
String val4 = null;//分类
for (int i = 0; i < voList.size(); i++) {
StringBuffer sb = new StringBuffer();
val1 = voList.get(i).getShowName();
if(voList.get(i).getParentId() != 0){
DiyType diyType1 = diyTypeMapper.selectByPrimaryKey(voList.get(i).getParentId());
val2 = diyType1.getShowName();
if(diyType1.getParentId() != 0){
DiyType diyType2 = diyTypeMapper.selectByPrimaryKey(diyType1.getParentId());
val3 = diyType2.getShowName();
if(diyType2.getParentId() != 0){
DiyType diyType3 = diyTypeMapper.selectByPrimaryKey(diyType2.getParentId());
val4 = diyType3.getShowName();
}
}
}
if(StringUtils.isNotEmpty(val4)){
sb.append(val4);
sb.append("-");
}
if(StringUtils.isNotEmpty(val3)){
sb.append(val3);
sb.append("-");
}
if(StringUtils.isNotEmpty(val2)){
sb.append(val2);
sb.append("-");
}
if(StringUtils.isNotEmpty(val1)){
sb.append(val1);
}
if(sb.toString().equals(diyTypes)){//判断导入的自定义分类跟拼接的自定义分类相同的话,进行绑定
GoodsDiyTypeRelation entity = new GoodsDiyTypeRelation();
entity.setGoodsid(id);
entity.setDiytypeid(voList.get(i).getId());
entity.setCode(voList.get(i).getCode());
entity.setId(null);
entity.setUpdateTime(new Date());
goodsDiyTypeRelationMapper.insertSelective(entity);
break;
}
}
}
});
return true;
}
}
......@@ -613,7 +613,7 @@ public class PhyResourceServiceImpl extends BaseModelServiceImpl<PhyResource, St
List<Integer> diyTypeIds = new ArrayList<Integer>();
goodsIds.add(phyResource.getId());
diyTypeIds.add(Integer.parseInt(diytypeId));
diyTypeManage.updateDiyTypes(goodsIds, diyTypeIds);
diyTypeManage.saveDiyTypes(goodsIds, importPhyResourceExcelVo.getDiyTypes());
List<Integer> lables = formatLable(type);
labelManage.updateLabels(goodsIds, lables);
} catch (Exception e) {
......
......@@ -72,4 +72,13 @@ public class ImportPhyResourceExcelVo {
private String keywords;
@ExcelResources(title = "国家级技工教育规划教材", order = 18)
private String countryStatus;
@ExcelResources(title = "目录", order = 19)
private String menu;
@ExcelResources(title = "简介", order = 20)
private String introduction;
@ExcelResources(title = "分类", order = 21)
private String diyTypes;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论