|
@@ -4,30 +4,47 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
|
|
|
+import com.ym.mec.biz.dal.dao.OrganizationDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.TeacherDao;
|
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
|
-import com.ym.mec.biz.dal.dto.ComplementGoodsDto;
|
|
|
import com.ym.mec.biz.dal.dto.GoodsSellDto;
|
|
|
+import com.ym.mec.biz.dal.dto.SubjectGoodsDto;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsSub;
|
|
|
import com.ym.mec.biz.dal.entity.Organization;
|
|
|
import com.ym.mec.biz.dal.entity.SellOrder;
|
|
|
-import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
+import com.ym.mec.biz.dal.enums.GoodsType;
|
|
|
+import com.ym.mec.biz.dal.enums.MessageTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SellStatus;
|
|
|
+import com.ym.mec.biz.dal.enums.StockType;
|
|
|
+import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.YesOrNoEnum;
|
|
|
import com.ym.mec.biz.dal.mapper.GoodsSubMapper;
|
|
|
+import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.GoodsQuery;
|
|
|
import com.ym.mec.biz.dal.page.GoodsQueryInfo;
|
|
|
import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
|
|
|
-import com.ym.mec.biz.service.*;
|
|
|
+import com.ym.mec.biz.service.GoodsCategoryService;
|
|
|
+import com.ym.mec.biz.service.GoodsService;
|
|
|
+import com.ym.mec.biz.service.SysConfigService;
|
|
|
+import com.ym.mec.biz.service.SysMessageService;
|
|
|
+import com.ym.mec.biz.service.SysTenantConfigService;
|
|
|
+import com.ym.mec.biz.service.UploadFileService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.dto.BrandDto;
|
|
|
import com.ym.mec.common.dto.PmsProductDto;
|
|
|
import com.ym.mec.common.dto.PmsProductQueryParamDto;
|
|
|
+import com.ym.mec.common.dto.ProductCategoryDto;
|
|
|
import com.ym.mec.common.entity.GoodsSubModel;
|
|
|
import com.ym.mec.common.entity.GoodsSubStockModel;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
-import com.ym.mec.common.page.QueryInfo;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
@@ -36,8 +53,8 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.excel.POIUtil;
|
|
|
import com.ym.mec.util.ini.IniFileUtil;
|
|
|
-
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.math.NumberUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.PictureData;
|
|
|
import org.slf4j.Logger;
|
|
@@ -88,6 +105,9 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsSubMapper goodsSubMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsCategoryService goodsCategoryService;
|
|
|
@Override
|
|
|
public BaseDAO<Integer, Goods> getDAO() {
|
|
|
return goodsDao;
|
|
@@ -548,8 +568,131 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public List<Goods> importGoodsV2(MultipartFile file, Integer userId) {
|
|
|
+ public String importGoodsV2(MultipartFile file, Integer userId) throws Exception {
|
|
|
+ Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
+ if (sheetsListMap.values().isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询商品分类
|
|
|
+ GoodsCategoryQueryInfo goodsCategoryQueryInfo = new GoodsCategoryQueryInfo();
|
|
|
+ goodsCategoryQueryInfo.setDelFlag(YesOrNoEnum.NO);
|
|
|
+ goodsCategoryQueryInfo.setPage(1);
|
|
|
+ goodsCategoryQueryInfo.setRows(9999);
|
|
|
+ Map<String, Integer> categoryIdNameMap = goodsCategoryService.querySubjectGoods(goodsCategoryQueryInfo).getRows()
|
|
|
+ .stream().collect(Collectors.toMap(SubjectGoodsDto::getGoodsCategoryName, SubjectGoodsDto::getGoodsCategoryId));
|
|
|
+ Set<String> categoryNames = categoryIdNameMap.keySet();
|
|
|
+
|
|
|
+ // 查询员工机构
|
|
|
+ Map<String, Integer> orgNameIdMap = organizationDao.findAllOrgans(TenantContextHolder.getTenantId()).stream()
|
|
|
+ .collect(Collectors.toMap(Organization::getName, Organization::getId));
|
|
|
+
|
|
|
+
|
|
|
+ InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
+ Map<String, String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.GOODS_GROUP.getMsg());
|
|
|
+
|
|
|
+ List<String> errors = new ArrayList<>();
|
|
|
+ List<GoodsWrapper.Goods> goodsList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<Map<String, Object>>> sheetData : sheetsListMap.entrySet()) {
|
|
|
+ LinkedHashMap<Integer, List<String>> errMap = new LinkedHashMap<>();
|
|
|
+ List<Map<String, Object>> rows = sheetData.getValue();
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> firstRow = rows.get(0);
|
|
|
+ // 缺省字段
|
|
|
+ Set<String> templateFields = columns.keySet();
|
|
|
+ List<String> defaultField = templateFields.stream().filter(firstRow::containsKey).collect(Collectors.toList());
|
|
|
+ if (!defaultField.isEmpty()) {
|
|
|
+ errors.add("导入字段缺省:" + String.join(",", defaultField));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ String lineErrMsg = "第%行存在错误:";
|
|
|
+ List<String> errList = new ArrayList<>();
|
|
|
+ Map<String,String> fieldTypeMap = new HashMap<>();
|
|
|
+ GoodsWrapper.Goods beforeGoods = null;
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ GoodsWrapper.Goods goods = new GoodsWrapper.Goods();
|
|
|
+ Map<String, Object> row = rows.get(i);
|
|
|
+ if (row.size() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Map.Entry<String, Object> entry : row.entrySet()) {
|
|
|
+ String fieldName = entry.getKey();
|
|
|
+ if (!templateFields.contains(fieldName)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String fieldCode = columns.get(fieldName);
|
|
|
+ String value = entry.getValue().toString();
|
|
|
+ if (beforeGoods == null) {
|
|
|
+
|
|
|
+ }
|
|
|
+ if (beforeGoods == null && StringUtils.isEmpty(value)) {
|
|
|
+ errList.add("字段‘" + fieldName + "’为空");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("marketPrice".equals(fieldCode)
|
|
|
+ || "discountPrice".equals(fieldCode)
|
|
|
+ || "groupPurchasePrice".equals(fieldCode)) {
|
|
|
+ if (NumberUtils.isNumber(value)) {
|
|
|
+ BigDecimal marketPrice = new BigDecimal(value);
|
|
|
+ if (BigDecimal.ZERO.compareTo(marketPrice) > 0) {
|
|
|
+ errList.add("字段‘" + fieldName + "’不能为负数");
|
|
|
+ } else {
|
|
|
+// ReflectionUtil.invoke(goods, "set" + fieldCode.substring(0, 1).toUpperCase() + fieldCode.substring(1), new Class[]{BigDecimal.class}, new Object[] {marketPrice});
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ errList.add("字段‘" + fieldName + "’类型错误");
|
|
|
+ }
|
|
|
+ } else if ("type".equals(fieldCode)) {
|
|
|
+ boolean match = Arrays.stream(GoodsType.values()).allMatch(next -> next.getDesc().equals(value));
|
|
|
+ if (match) {
|
|
|
+ goods.setType(GoodsType.valueOf(value));
|
|
|
+ } else {
|
|
|
+ errList.add("字段‘" + fieldName + "’类型不支持");
|
|
|
+ }
|
|
|
+ } else if ("goodsCategoryName".equals(fieldCode)) {
|
|
|
+ if(categoryNames.contains(value)){
|
|
|
+ goods.setGoodsCategoryId(categoryIdNameMap.get(value));
|
|
|
+ }else {
|
|
|
+ errList.add("字段‘" + fieldName + "’类型不支持");
|
|
|
+ }
|
|
|
+ } else if ("educationShowOrganName".equals(fieldCode)
|
|
|
+ || "courseFeeShowOrganName".equals(fieldCode)
|
|
|
+ || "memberFeeShowOrganName".equals(fieldCode)
|
|
|
+ || "freeFeeShowOrganName".equals(fieldCode)
|
|
|
+ || "replacementShowOrganName".equals(fieldCode)
|
|
|
+ ) {
|
|
|
+ List<String> orgIds = new ArrayList<>();
|
|
|
+ for (String orgName : value.split(",")) {
|
|
|
+ if (!orgNameIdMap.containsKey(orgName)) {
|
|
|
+ errList.add("字段‘" + fieldName + "’分部‘" + value + "’不支持");
|
|
|
+ } else {
|
|
|
+ orgIds.add(orgNameIdMap.get(orgName).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String valueField = fieldCode.replaceAll("Name", "Id");
|
|
|
+ valueField = "set" + valueField.substring(0, 1).toUpperCase() + valueField.substring(1);
|
|
|
+// ReflectionUtil.invoke(goods, valueField, new Class[]{String.class}, new Object[]{String.join("", value)});
|
|
|
+ }
|
|
|
+
|
|
|
+ beforeGoods = JSON.parseObject(JSON.toJSONString(goods),GoodsWrapper.Goods.class);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (goodsList.isEmpty()) {
|
|
|
+ throw new BizException("未解析到文件");
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -954,4 +1097,19 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goodsDao.updateStock(updateGoods);
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProductCategoryDto> queryGoodsTypeList() {
|
|
|
+ return mallFeignService.listWithChildren();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BrandDto> queryGoodsBrandList() {
|
|
|
+ return mallFeignService.getList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object queryGoodsCategoryList() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|