Browse Source

添加商品下拉接口

yuanliang 1 year ago
parent
commit
7c3b2c1a76

+ 18 - 0
mec-application/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -130,4 +130,22 @@ public class GoodsController extends BaseController {
         return succeed(goodsService.queryGoodsSubByPage(query));
 
     }
+
+    @ApiOperation(value = "查询商品类型")
+    @GetMapping("/queryGoodsTypeList")
+    public Object queryGoodsTypeList() {
+        return goodsService.queryGoodsTypeList();
+    }
+
+    @ApiOperation(value = "查询商品分类")
+    @GetMapping("/queryGoodsCategoryList")
+    public Object queryGoodsCategoryList() {
+        return goodsService.queryGoodsCategoryList();
+    }
+
+    @ApiOperation(value = "查询商品品牌")
+    @GetMapping("/queryGoodsBrandList")
+    public Object queryGoodsBrandList() {
+        return goodsService.queryGoodsBrandList();
+    }
 }

+ 8 - 3
mec-application/src/main/java/com/ym/mec/web/controller/ImportController.java

@@ -69,9 +69,14 @@ public class ImportController extends BaseController {
 
     @ApiOperation(value = "导入商品")
     @PostMapping(value = "goodsV2")
-    @PreAuthorize("@pcs.hasPermissions('import/goodsV2')")
-    public HttpResponseResult<List<Goods>> importGoodsV2(@RequestParam("file") MultipartFile file) throws Exception {
-        return succeed(goodsService.importGoodsV2(file, sysUserService.getUserId()));
+//    @PreAuthorize("@pcs.hasPermissions('import/goodsV2')")
+    public HttpResponseResult<String> importGoodsV2(@RequestParam("file") MultipartFile file) throws Exception {
+        String errFile = goodsService.importGoodsV2(file, sysUserService.getUserId());
+        if (StringUtils.isEmpty(errFile)) {
+            return succeed();
+        } else {
+            return failed(errFile);
+        }
     }
 
     @ApiOperation(value = "导入财务支出")

+ 19 - 0
mec-application/src/main/resources/columnMapper.ini

@@ -14,6 +14,25 @@
 商品描述 = brief
 商品详情 = desc
 
+[组合商品导入模板]
+组合商品名称 = name
+组合商品货号 = sn
+组合商品市场价 = marketPrice
+组合商品零售价 = discountPrice
+组合商品团购价 = groupPurchasePrice
+组合商品品牌 = brand
+组合商品类型 = type
+组合商品分类 = goodsCategoryName
+组合商品型号 = specification
+移动端可用分部 = educationShowOrganName
+课程收费团可用分部 = courseFeeShowOrganName
+会员收费乐团可售分部 = memberFeeShowOrganName
+免费乐团可售分部 = freeFeeShowOrganName
+乐器置换可售分部 = replacementShowOrganName
+
+组合商品描述 = brief
+组合商品详情 = desc
+组合商品图片 = image
 
 [财务支出导入模板]
 财务流程编号 = financialProcessNo

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/TemplateTypeEnum.java

@@ -4,6 +4,7 @@ import com.ym.mec.common.enums.BaseEnum;
 
 public enum TemplateTypeEnum implements BaseEnum<String, TemplateTypeEnum> {
     GOODS("GOODS","商品导入模板"),
+    GOODS_GROUP("GOODS_GROUP","组合商品导入模板"),
     ROUTE_ORDER("ROUTE_ORDER","财务管理导入模板"),
     FINANCIAL_EXPENDITURE("FINANCIAL_EXPENDITURE","财务支出导入模板"),
     REDEMPTIONCODE("REDEMPTION_CODE", "兑换码分配模板表"),

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/wrapper/GoodsWrapper.java

@@ -13,6 +13,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 public class GoodsWrapper {
@@ -91,7 +92,7 @@ public class GoodsWrapper {
         private String memo;
 
         @ApiModelProperty(value = "发布时间")
-        private java.util.Date publishTime;
+        private Date publishTime;
 
         @ApiModelProperty(value = "附件商品列表编号(用逗号分开)")
         private String complementGoodsIdList;

+ 10 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -4,7 +4,9 @@ import java.util.List;
 
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
 import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
+import com.ym.mec.common.dto.BrandDto;
 import com.ym.mec.common.dto.PmsProductDto;
+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.page.PageInfo;
@@ -81,9 +83,9 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * 导入组合商品
      * @param file 文件
      * @param userId 导入人信息
-     * @return 商品列表
+     * @return 失败时的回执文件路径
      */
-    List<Goods> importGoodsV2(MultipartFile file, Integer userId);
+    String importGoodsV2(MultipartFile file, Integer userId) throws Exception;
 
 
     /**
@@ -152,4 +154,10 @@ public interface GoodsService extends BaseService<Integer, Goods> {
     Boolean goodsStatusSynchronize(List<GoodsSubModel> goodsSubModelList);
 
     Boolean goodsStockCountSynchronize(List<GoodsSubStockModel> goodsSubStockModels);
+
+    List<ProductCategoryDto> queryGoodsTypeList();
+
+    List<BrandDto> queryGoodsBrandList();
+
+    Object queryGoodsCategoryList();
 }

+ 165 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -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;
+	}
 }

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -1036,7 +1036,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                 OrderCreate orderCreate = new OrderCreate();
                 String orderNo = idGeneratorService.generatorId("payment") + "";
                 orderCreate.setOrderNo(orderNo);
-                orderCreate.setOrchestraId(musicGroup.getId());
+//                orderCreate.setOrchestraId(musicGroup.getId());
                 orderCreate.setMemberId(musicGroup.getSchoolId().longValue());
                 orderCreate.setTotalAmount(calender.getCurrentTotalAmount());
                 orderCreate.setOrderFormType("MEC");

+ 3 - 3
mec-client-api/src/main/java/com/ym/mec/mall/MallFeignService.java

@@ -33,17 +33,17 @@ public interface MallFeignService {
      * @param orderNo 订单编号
      * @return status 订单状态  0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单
      */
-    @GetMapping(value = "/product/updateOrderStatus", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
+    @GetMapping(value = "/open/product/updateOrderStatus", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
     boolean productUpdateOrderStatus(@RequestParam("orderNo") String orderNo,@RequestParam("status") Integer status);
 
 
     //根据品牌名称分页获取品牌列表
-    @RequestMapping(value = "/brand/list", method = RequestMethod.GET)
+    @RequestMapping(value = "/open/brand/list", method = RequestMethod.GET)
     List<BrandDto> getList();
 
 
     // 查询所有一级分类及子分类
-    @RequestMapping(value = "/productCategory/list/withChildren", method = RequestMethod.GET)
+    @RequestMapping(value = "/open/productCategory/list/withChildren", method = RequestMethod.GET)
     @ResponseBody
     List<ProductCategoryDto> listWithChildren();
 

+ 1 - 1
mec-common/audit-log/src/main/java/com/yonge/log/interceptor/AuditLogInterceptor.java

@@ -41,7 +41,7 @@ public class AuditLogInterceptor extends HandlerInterceptorAdapter {
 
     @Override
     public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
-        syncSaveLog(request, handler);
+//        syncSaveLog(request, handler);
     }
 
     public void syncSaveLog(HttpServletRequest request, Object handler) {