|
@@ -0,0 +1,174 @@
|
|
|
+package com.fjhx.service.product.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.base.Condition;
|
|
|
+import com.fjhx.constants.StatusConstant;
|
|
|
+import com.fjhx.entity.product.ProductCombination;
|
|
|
+import com.fjhx.entity.product.ProductInfo;
|
|
|
+import com.fjhx.mapper.product.ProductInfoMapper;
|
|
|
+import com.fjhx.params.product.ProductCombinationEx;
|
|
|
+import com.fjhx.params.product.ProductInfoVo;
|
|
|
+import com.fjhx.service.product.ProductCombinationService;
|
|
|
+import com.fjhx.service.product.ProductInfoService;
|
|
|
+import com.fjhx.uitl.code.CodeEnum;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
+import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
+import com.fjhx.utils.wrapperUtil.KeywordData;
|
|
|
+import org.springblade.system.entity.Dept;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author ${author}
|
|
|
+ * @since 2022-11-29
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, ProductInfo> implements ProductInfoService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ISysClient iSysClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductCombinationService productCombinationService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<Map<String, Object>> getPage(Map<String, Object> condition) {
|
|
|
+ IWrapper<ProductInfo> wrapper = IWrapper.getWrapper(condition);
|
|
|
+ wrapper
|
|
|
+ .keyword(new KeywordData(ProductInfo::getName), new KeywordData(ProductInfo::getCode))
|
|
|
+ .eq(ProductInfo::getDeptId)
|
|
|
+ .eq(ProductInfo::getType)
|
|
|
+ .like(ProductInfo::getName)
|
|
|
+ .like(ProductInfo::getCode)
|
|
|
+ .ge(ProductInfo::getPurchasePrice, condition.get("purchasePriceMin"))
|
|
|
+ .le(ProductInfo::getPurchasePrice, condition.get("purchasePriceMax"))
|
|
|
+ .ge(ProductInfo::getSellingPrice, condition.get("sellingPriceMin"))
|
|
|
+ .le(ProductInfo::getSellingPrice, condition.get("sellingPriceMax"))
|
|
|
+ .ge(ProductInfo::getJdPurchasePrice, condition.get("jdPurchasePriceMin"))
|
|
|
+ .le(ProductInfo::getJdPurchasePrice, condition.get("jdPurchasePriceMax"))
|
|
|
+ .eq(ProductInfo::getCombination)
|
|
|
+ .periodTime(ProductInfo::getClearancePeriod)
|
|
|
+ .func(ObjectUtil.isNotEmpty(condition.get("lifeCycle")), q -> {
|
|
|
+ Integer lifeCycle = Convert.toInt(condition.get("lifeCycle"));
|
|
|
+ // 新品
|
|
|
+ if (ObjectUtil.equals(lifeCycle, 1)) {
|
|
|
+ q.gt("new_products_day - datediff(now(), computing_time)", 0);
|
|
|
+ }
|
|
|
+ // 成长
|
|
|
+ else if (ObjectUtil.equals(lifeCycle, 2)) {
|
|
|
+ q.gt("(new_products_day + grow_up_day) - datediff(now(), computing_time)", 0);
|
|
|
+ }
|
|
|
+ // 成熟
|
|
|
+ else {
|
|
|
+ q.le("(new_products_day + grow_up_day) - datediff(now(), computing_time)", 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Page<Map<String, Object>> page = baseMapper.getPage(createPage(condition), wrapper);
|
|
|
+
|
|
|
+ List<Map<String, Object>> records = page.getRecords();
|
|
|
+
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值部门名称
|
|
|
+ List<Long> deptIdList = records.stream().map(item -> Convert.toLong(item.get("deptId"))).collect(Collectors.toList());
|
|
|
+ Map<Long, Dept> deptMap = iSysClient.getDeptByIdsToMap(deptIdList);
|
|
|
+
|
|
|
+ for (Map<String, Object> record : records) {
|
|
|
+ Dept dept = deptMap.get(Convert.toLong(record.get("deptId")));
|
|
|
+ record.put("deptName", dept == null ? "" : dept.getDeptName());
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(ProductInfoVo productInfoVo) {
|
|
|
+
|
|
|
+ synchronized (this) {
|
|
|
+ productInfoVo.setCode(CodeEnum.PRODUCT.getCode(productInfoVo.getCode()));
|
|
|
+ productInfoVo.setComputingTime(new Date());
|
|
|
+ save(productInfoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StatusConstant.YES.equals(productInfoVo.getCombination())) {
|
|
|
+ List<ProductCombination> productCombinationList = productInfoVo.getProductCombinationList();
|
|
|
+ Assert.notEmpty(productCombinationList, "组合信息不能为空");
|
|
|
+
|
|
|
+ for (ProductCombination productCombination : productCombinationList) {
|
|
|
+ productCombination.setProductId(productInfoVo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ productCombinationService.saveBatch(productCombinationList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(ProductInfoVo productInfoVo) {
|
|
|
+
|
|
|
+ updateById(productInfoVo);
|
|
|
+
|
|
|
+ if (StatusConstant.YES.equals(productInfoVo.getCombination())) {
|
|
|
+ List<ProductCombination> productCombinationList = productInfoVo.getProductCombinationList();
|
|
|
+ Assert.notEmpty(productCombinationList, "组合信息不能为空");
|
|
|
+
|
|
|
+ List<Long> productCombinationIdList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (ProductCombination productCombination : productCombinationList) {
|
|
|
+ productCombination.setProductId(productInfoVo.getId());
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(productCombination.getId())) {
|
|
|
+ productCombinationIdList.add(productCombination.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ productCombinationService.remove(q -> q
|
|
|
+ .eq(ProductCombination::getProductId, productInfoVo.getId())
|
|
|
+ .notIn(ProductCombination::getId, productCombinationIdList));
|
|
|
+
|
|
|
+ productCombinationService.saveOrUpdateBatch(productCombinationList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(ProductInfoVo productInfoVo) {
|
|
|
+ // TODO 有库存不允许删除
|
|
|
+ removeById(productInfoVo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ProductCombinationEx> getCombinationPage(Condition condition) {
|
|
|
+ // 产品id
|
|
|
+ Long id = condition.getLong("id");
|
|
|
+ Assert.notEmpty(id, "产品id不能为空");
|
|
|
+
|
|
|
+ IWrapper<Object> wrapper = IWrapper.getWrapper();
|
|
|
+ wrapper.eq("pc", ProductCombination::getProductId, id);
|
|
|
+
|
|
|
+ return baseMapper.getCombinationPage(createPage(condition), wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|