jiangqs
2023-06-04 2f9365906f6e5203c3cff9cdb474c360180b80df
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java
@@ -4,12 +4,15 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.goods.domain.dto.*;
import com.ruoyi.goods.domain.pojo.goods.GoodsTotal;
import com.ruoyi.goods.domain.vo.*;
import com.ruoyi.goods.mapper.goods.GoodsMapper;
import com.ruoyi.goods.service.activity.ActivityGoodsService;
import com.ruoyi.goods.service.goods.GoodsFileService;
import com.ruoyi.goods.service.goods.GoodsService;
import com.ruoyi.goods.service.goods.GoodsTotalService;
import com.ruoyi.goods.service.goods.ShopGoodsService;
import com.ruoyi.system.api.constant.AppErrorConstant;
import com.ruoyi.system.api.domain.poji.activity.ActivityGoods;
@@ -53,6 +56,9 @@
    @Resource
    private RemoteConfigService remoteConfigService;
    @Resource
    private GoodsTotalService goodsTotalService;
    /**
     * 获取推荐商品列表
@@ -253,14 +259,60 @@
    }
    /**
     * 平台编辑商品
     * @param mgtGoodsEditDto
     */
    * @description: editMgtGoods
    * @param: mgtGoodsEditDto
    * @return: void
    * @author jqs34
    * @date: 2023/6/4 15:37
    */
    @Override
    public void editMgtGoods(MgtGoodsEditDto mgtGoodsEditDto){
        Goods goods;
        Boolean newGoods = false;
        String goodsId = mgtGoodsEditDto.getGoodsId();
        // 判断是否有商品ID 没有则新建
        if(goodsId != null){
            goods = this.getById(goodsId);
        }else{
            goods = new Goods();
            goodsId = IdUtils.simpleUUID();
            goods.setGoodsId(goodsId);
            goods.setDelFlag(0);
            goods.setCreateTime(DateUtils.getNowDate());
            goods.setCreateUserId(mgtGoodsEditDto.getUserId());
            newGoods = true;
        }
        goods.setUpdateTime(DateUtils.getNowDate());
        goods.setUpdateUserId(mgtGoodsEditDto.getUserId());
        goods.setGoodsStatus(mgtGoodsEditDto.getGoodsStatus());
        goods.setGoodsType(mgtGoodsEditDto.getGoodsType());
        goods.setGoodsClassId(mgtGoodsEditDto.getGoodsClassId());
        goods.setGoodsName(mgtGoodsEditDto.getGoodsName());
        goods.setCycleNumFlag(mgtGoodsEditDto.getCycleNumFlag());
        goods.setServiceNum(mgtGoodsEditDto.getServiceNum());
        goods.setGoodsIntroduction(mgtGoodsEditDto.getGoodsIntroduction());
        goods.setSalesPrice(mgtGoodsEditDto.getSalesPrice());
        goods.setMininumPrice(mgtGoodsEditDto.getMininumPrice());
        if(mgtGoodsEditDto.getSubscription()!=null&&mgtGoodsEditDto.getSubscription().compareTo(BigDecimal.valueOf(0))>0){
            goods.setSubscriptionFlag(1);
        }else{
            goods.setSubscriptionFlag(0);
        }
        goods.setSubscription(mgtGoodsEditDto.getSubscription());
        goods.setGoodsDetail(mgtGoodsEditDto.getGoodsDetail());
        goods.setRecommendFlag(mgtGoodsEditDto.getRecommendFlag());
        goods.setGoodsNurses(mgtGoodsEditDto.getGoodsNurses());
        goods.setGoodsTags(mgtGoodsEditDto.getGoodsNurses());
        this.saveOrUpdate(goods);
        //如果是新建商品创建商品统计
        if(newGoods){
            GoodsTotal goodsTotal = new GoodsTotal();
            goodsTotal.setGoodsId(goodsId);
            goodsTotal.setBuyCount(0);
            goodsTotal.setBuyNumCount(0);
            goodsTotal.setBuyUserCount(0);
            goodsTotal.setBuyMoneyTotal(new BigDecimal("0.00"));
            goodsTotalService.saveOrUpdate(goodsTotal);
        }
    }
}