Pārlūkot izejas kodu

新增商品规格调价

FengChaoYu 2 dienas atpakaļ
vecāks
revīzija
8c746d7d21

+ 26 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsPriceChangeBean.java

@@ -0,0 +1,26 @@
+package com.gree.mall.manager.bean.goods;
+
+import com.gree.mall.manager.plus.entity.GoodsPriceChange;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class GoodsPriceChangeBean extends GoodsPriceChange {
+
+    @ApiModelProperty(value = "商品名称")
+    private String goodsName;
+
+    @ApiModelProperty(value = "商品规格名称")
+    private String name;
+
+    @ApiModelProperty(value = "物料规格名称")
+    private String specValue;
+
+    @ApiModelProperty(value = "明细")
+    private List<GoodsPriceChangeBean> items;
+
+}

+ 20 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsPriceChangeItemBean.java

@@ -0,0 +1,20 @@
+package com.gree.mall.manager.bean.goods;
+
+import com.gree.mall.manager.plus.entity.GoodsPriceChange;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class GoodsPriceChangeItemBean extends GoodsPriceChange {
+
+    @ApiModelProperty(value = "商品名称")
+    private String goodsName;
+
+    @ApiModelProperty(value = "商品规格名称")
+    private String name;
+
+}

+ 63 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsPriceChangeVO.java

@@ -0,0 +1,63 @@
+package com.gree.mall.manager.bean.goods;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.gree.mall.manager.annotation.ZfireField;
+import com.gree.mall.manager.enums.ExamineStatusEnum;
+import com.gree.mall.manager.plus.entity.GoodsPriceChange;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@ZfireField(tbName = "a")
+public class GoodsPriceChangeVO {
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "id")
+    private String id;
+
+    @ApiModelProperty(value = "单据编号")
+    private String sheetId;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "商品id")
+    private String goodsId;
+
+    @ZfireField(tbName = "b", isShow = false)
+    @ApiModelProperty(value = "商品id")
+    private String goodsName;
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "商品规格id")
+    private String goodsSpecId;
+
+    @ZfireField(tbName = "c", isShow = false)
+    @ApiModelProperty(value = "商品规格名称")
+    private String name;
+
+//    @ApiModelProperty(value = "旧销售价")
+//    private BigDecimal oldPrice;
+//
+//    @ApiModelProperty(value = "销售价")
+//    private BigDecimal price;
+
+    @ApiModelProperty(value = "状态")
+    private ExamineStatusEnum status;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+}

+ 3 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsSpecVO.java

@@ -16,6 +16,9 @@ import java.math.BigDecimal;
 @Data
 public class GoodsSpecVO extends GoodsSpec {
 
+    @ApiModelProperty("商品名称")
+    private String goodsName;
+
     @ApiModelProperty("仓库名称")
     private String storageName;
 

+ 8 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CommonMapper.java

@@ -596,4 +596,12 @@ public interface CommonMapper {
      * @return
      */
     IPage<UserCompanyCreditBillItemVO> userCompanyCreditBillItemPage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+    /**
+     * 商品规格价格变更列表
+     * @param page
+     * @param zfireParamBean
+     * @return
+     */
+    IPage<GoodsPriceChangeVO> goodsPriceChangePage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
 }

+ 10 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CustomGoodsMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.manager.bean.goods.GoodsSpecBean;
+import com.gree.mall.manager.bean.goods.GoodsSpecVO;
 import com.gree.mall.manager.bean.goods.GoodsTypeCount;
 import com.gree.mall.manager.plus.entity.Goods;
 import com.gree.mall.manager.plus.entity.GoodsCategory;
@@ -82,4 +83,13 @@ public interface CustomGoodsMapper {
     public GoodsCategory queryGoodsCategoryByGoodsId(@Param("goodsId") String goodsId);
 
 
+    /**
+     * 查询商品规格列表
+     * @param page
+     * @param categoryId
+     * @param keyword
+     * @param companyWechatId
+     * @return
+     */
+    IPage<GoodsSpecVO> querySpecList(Page page, String categoryId, String keyword, String companyWechatId);
 }

+ 10 - 1
mall-server-api/src/main/java/com/gree/mall/manager/controller/goods/GoodsController.java

@@ -162,5 +162,14 @@ public class GoodsController {
         return ResponseHelper.success();
     }
 
-
+    @PostMapping("/list/spec/select")
+    @ApiOperation(value = "选择商品规格列表")
+    public ResponseHelper<IPage<GoodsSpecVO>> listSpecSelect(
+            @ApiParam(value = "商品名称") @RequestParam(required = false) String keyword,
+            @ApiParam(value = "商品分类id") @RequestParam(required = false) String categoryId,
+            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize
+    ) throws Exception {
+        return ResponseHelper.success(goodsLogic.goodsSpecList(categoryId,keyword,pageNum, pageSize));
+    }
 }

+ 112 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/goods/GoodsPriceChangeController.java

@@ -0,0 +1,112 @@
+package com.gree.mall.manager.controller.goods;
+
+import cn.hutool.core.lang.TypeReference;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.annotation.ZfireList;
+import com.gree.mall.manager.bean.goods.GoodsPriceChangeBean;
+import com.gree.mall.manager.bean.goods.GoodsPriceChangeVO;
+import com.gree.mall.manager.constant.Constant;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.helper.ResponseHelper;
+import com.gree.mall.manager.logic.goods.GoodsPriceChangeLogic;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.integration.redis.util.RedisLockRegistry;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+
+@Slf4j
+@RestController
+@Api(value = "商品价格变更API", tags ={"商品价格变更API"} )
+@RequestMapping(value = "/goods/price/change", produces = "application/json; charset=utf-8")
+public class GoodsPriceChangeController {
+
+    @Resource
+    GoodsPriceChangeLogic goodsPriceChangeLogic;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
+
+    @ZfireList
+    @PostMapping("/list")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<Page<GoodsPriceChangeVO>> list(
+            @RequestBody ZfireParamBean zfireParamBean
+    ) throws RemoteServiceException {
+        IPage<GoodsPriceChangeVO> page = goodsPriceChangeLogic.list(zfireParamBean);
+        return ResponseHelper.success(page, new TypeReference<GoodsPriceChangeVO>() {
+        });
+    }
+
+    @ApiOperation(value = "详情")
+    @PostMapping("/detail")
+    public ResponseHelper<GoodsPriceChangeBean> detail(
+            @ApiParam(value="sheetId",required = true) @RequestParam String sheetId
+    ) {
+        GoodsPriceChangeBean bean = goodsPriceChangeLogic.detail(sheetId);
+        return ResponseHelper.success(bean);
+    }
+
+    @ApiOperation(value = "添加")
+    @PostMapping("/add")
+    public ResponseHelper<String> add(
+            @RequestBody GoodsPriceChangeBean bean
+    ) {
+        String id = goodsPriceChangeLogic.add(bean);
+        return ResponseHelper.success(id);
+    }
+
+    @ApiOperation(value = "编辑明细")
+    @PostMapping("/edit/item")
+    public ResponseHelper editItem(
+            @ApiParam(value="id", required = true) @RequestParam String id,
+            @ApiParam(value="新售价") @RequestParam(required = false) BigDecimal price,
+            @ApiParam(value="备注") @RequestParam(required = false) String remark
+    ) {
+        goodsPriceChangeLogic.editItem(id, price, remark);
+        return ResponseHelper.success();
+    }
+
+    @ApiOperation(value = "删除明细")
+    @PostMapping("/del/item")
+    public ResponseHelper delItem(
+            @ApiParam(value="id", required = true) @RequestParam String id
+    ) {
+        goodsPriceChangeLogic.delItem(id);
+        return ResponseHelper.success();
+    }
+
+    @ApiOperation(value = "删除单据")
+    @PostMapping("/del")
+    public ResponseHelper del(
+            @ApiParam(value="sheetId", required = true) @RequestParam String sheetId
+    ) {
+        goodsPriceChangeLogic.del(sheetId);
+        return ResponseHelper.success();
+    }
+
+    @ApiOperation(value = "审核")
+    @PostMapping("/examine")
+    public ResponseHelper examine(
+            @ApiParam(value="sheetId", required = true) @RequestParam String sheetId
+    ) throws Exception {
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_COMMON + sheetId);
+        if(!obtain.tryLock(10, TimeUnit.SECONDS)){
+            return ResponseHelper.error("系统繁忙,请稍后再试");
+        }
+        try {
+            goodsPriceChangeLogic.examine(sheetId);
+        }finally {
+            obtain.unlock();
+        }
+
+        return ResponseHelper.success();
+    }
+}

+ 5 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/goods/GoodsLogic.java

@@ -646,4 +646,9 @@ public class GoodsLogic {
         return goodsList;
     }
 
+    public IPage<GoodsSpecVO> goodsSpecList(String categoryId, String keyword, Integer pageNum, Integer pageSize) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        IPage<GoodsSpecVO> page = customGoodsMapper.querySpecList(new Page(pageNum, pageSize), categoryId, keyword, adminUser.getCompanyWechatId());
+        return page;
+    }
 }

+ 178 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/goods/GoodsPriceChangeLogic.java

@@ -0,0 +1,178 @@
+package com.gree.mall.manager.logic.goods;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.bean.admin.AdminUserCom;
+import com.gree.mall.manager.bean.goods.GoodsPriceChangeBean;
+import com.gree.mall.manager.bean.goods.GoodsPriceChangeVO;
+import com.gree.mall.manager.bean.listvo.UserCustomerVO;
+import com.gree.mall.manager.commonmapper.CommonMapper;
+import com.gree.mall.manager.constant.Constant;
+import com.gree.mall.manager.enums.ExamineStatusEnum;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.plus.entity.Goods;
+import com.gree.mall.manager.plus.entity.GoodsPriceChange;
+import com.gree.mall.manager.plus.entity.GoodsSpec;
+import com.gree.mall.manager.plus.service.GoodsPriceChangeService;
+import com.gree.mall.manager.plus.service.GoodsService;
+import com.gree.mall.manager.plus.service.GoodsSpecService;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import com.gree.mall.manager.zfire.util.FieldUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class GoodsPriceChangeLogic {
+
+    private final CommonLogic commonLogic;
+    private final CommonMapper commonMapper;
+    private final GoodsPriceChangeService goodsPriceChangeService;
+    private final GoodsService goodsService;
+    private final GoodsSpecService goodsSpecService;
+
+    public IPage<GoodsPriceChangeVO> list(ZfireParamBean zfireParamBean) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        zfireParamBean.setCompanyWechatId(adminUser.getCompanyWechatId());
+        FieldUtils.supplyParam(zfireParamBean, UserCustomerVO.class);
+
+        IPage<GoodsPriceChangeVO> page = commonMapper.goodsPriceChangePage(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
+        return page;
+    }
+
+    public GoodsPriceChangeBean detail(String sheetId) {
+        final List<GoodsPriceChange> changeList = goodsPriceChangeService.lambdaQuery()
+                .eq(GoodsPriceChange::getSheetId, sheetId)
+                .orderByAsc(GoodsPriceChange::getId)
+                .list();
+
+        final List<Goods> goodsList = goodsService.lambdaQuery()
+                .in(Goods::getGoodsId, changeList.stream().map(GoodsPriceChange::getGoodsId).collect(Collectors.toList()))
+                .list();
+
+        final List<GoodsSpec> goodsSpecList = goodsSpecService.lambdaQuery()
+                .in(GoodsSpec::getGoodsSpecId, changeList.stream().map(GoodsPriceChange::getGoodsSpecId).collect(Collectors.toList()))
+                .list();
+
+        final Map<String, String> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getGoodsId, Goods::getGoodsName));
+        final Map<String, GoodsSpec> goodsSpecMap = goodsSpecList.stream().collect(Collectors.toMap(GoodsSpec::getGoodsSpecId, Function.identity()));
+
+        GoodsPriceChangeBean bean = new GoodsPriceChangeBean();
+
+        BeanUtils.copyProperties(changeList.get(0), bean);
+
+        List<GoodsPriceChangeBean> items = new ArrayList<>();
+        for (GoodsPriceChange change : changeList) {
+            final String goodsName = goodsMap.get(change.getGoodsId());
+            final GoodsSpec goodsSpec = goodsSpecMap.get(change.getGoodsSpecId());
+            GoodsPriceChangeBean item = new GoodsPriceChangeBean();
+            BeanUtils.copyProperties(change, item);
+            item.setGoodsName(goodsName);
+            item.setName(goodsSpec.getName());
+            item.setSpecValue(goodsSpec.getSpecValue());
+            items.add(item);
+        }
+
+        bean.setItems(items);
+
+        return bean;
+    }
+
+    @Transactional
+    public String add(GoodsPriceChangeBean bean) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        final String no = commonLogic.generateNo("", "GOODS_PRICE_CHANGE", 16);
+        List<GoodsPriceChangeBean> items = bean.getItems();
+
+        for (GoodsPriceChangeBean item : items) {
+            if (item.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
+                throw new RemoteServiceException(item.getGoodsName() + "规格: " + item.getName() + "售价必须大于0");
+            }
+            item.setId(IdWorker.getIdStr())
+                    .setSheetId(no)
+                    .setCompanyWechatId(adminUser.getCompanyWechatId())
+                    .setCompanyName(adminUser.getCompanyName())
+                    .setRemark(bean.getRemark());
+        }
+
+        goodsPriceChangeService.saveBatch(items.stream()
+                .map(v -> {
+                    GoodsPriceChange change = new GoodsPriceChange();
+                    BeanUtils.copyProperties(v, change);
+                    return change;
+                }).collect(Collectors.toList()));
+
+        return no;
+    }
+
+    public void editItem(String id, BigDecimal price, String remark) {
+        if (Objects.nonNull(price)) {
+            if (price.compareTo(BigDecimal.ZERO) <= 0) {
+                throw new RemoteServiceException("售价必须大于0");
+            }
+            GoodsPriceChange change = new GoodsPriceChange();
+            change.setId(id)
+                    .setPrice(price);
+            goodsPriceChangeService.updateById(change);
+        } else {
+            goodsPriceChangeService.lambdaUpdate()
+                    .set(GoodsPriceChange::getRemark, remark)
+                    .eq(GoodsPriceChange::getSheetId, id)
+                    .update();
+        }
+    }
+
+    public void delItem(String id) {
+        goodsPriceChangeService.removeById(id);
+    }
+
+    @Transactional
+    public void examine(String sheetId) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<GoodsPriceChange> changeList = goodsPriceChangeService.lambdaQuery()
+                .eq(GoodsPriceChange::getSheetId, sheetId)
+                .eq(GoodsPriceChange::getCompanyWechatId, adminUser.getCompanyWechatId())
+                .eq(GoodsPriceChange::getStatus, ExamineStatusEnum.SAVE.getKey())
+                .list();
+
+        if (CollectionUtil.isEmpty(changeList)) {
+            throw new RemoteServiceException("单据不存在");
+        }
+
+        List<GoodsSpec> goodsSpecList = new ArrayList<>();
+        for (GoodsPriceChange change : changeList) {
+            GoodsSpec spec = new GoodsSpec();
+            spec.setGoodsSpecId(change.getGoodsSpecId())
+                    .setPrice(change.getPrice());
+            goodsSpecList.add(spec);
+
+            change.setStatus(ExamineStatusEnum.OK.getKey());
+        }
+
+        goodsSpecService.saveOrUpdateBatch(goodsSpecList);
+
+        goodsPriceChangeService.saveOrUpdateBatch(changeList);
+    }
+
+    @Transactional
+    public void del(String sheetId) {
+        goodsPriceChangeService.lambdaUpdate()
+                .eq(GoodsPriceChange::getSheetId, sheetId)
+                .remove();
+    }
+}

+ 13 - 0
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -1132,4 +1132,17 @@
         ${ex.orderBy}
     </select>
 
+    <select id="goodsPriceChangePage" resultType="com.gree.mall.manager.bean.goods.GoodsPriceChangeVO">
+        SELECT
+        ${ex.selected}
+        FROM goods_price_change a LEFT JOIN goods b ON a.goods_id = b.goods_id
+        LEFT JOIN goods_spec c ON a.goods_spec_id = c.goods_spec_id
+        ${ex.query}
+        GROUP BY a.sheet_id
+        <if test="ex.orderBy == null or ex.orderBy ==''">
+            ORDER BY a.create_time DESC
+        </if>
+        ${ex.orderBy}
+    </select>
+
 </mapper>

+ 20 - 0
mall-server-api/src/main/resources/mapper/CustomGoodsMapper.xml

@@ -128,4 +128,24 @@
             where b.goods_id=#{goodsId}
     </select>
 
+    <select id="querySpecList" resultType="com.gree.mall.manager.bean.goods.GoodsSpecVO">
+        SELECT
+           a.goods_id,
+           a.goods_spec_id,
+           b.goods_name,
+           a.price,
+           a.name,
+           a.spec_value
+        FROM goods_spec a LEFT JOIN goods b ON a.goods_id = b.goods_id
+        WHERE b.del = 0 AND  a.del = 0
+        <if test="keyword != null and keyword !=''">
+            AND b.goods_name LIKE concat('%',#{keyword,jdbcType=VARCHAR},'%')
+        </if>
+        <if test="categoryId != null and categoryId !=''">
+            AND b.category_id = #{categoryId}
+        </if>
+        AND b.company_wechat_id = #{companyWechatId}
+
+    </select>
+
 </mapper>