phpcjl
2024-12-11 212d4cd9160f5c6f2247c87d252d6f97834299b4
1.后台管理-商品管理
8个文件已修改
198 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Goods.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsBargainPrice.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsBargainPriceDetail.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/mapper/GoodsMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/GoodsService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsMapper.xml 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Goods.java
@@ -9,6 +9,7 @@
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
 * <p>
@@ -122,5 +123,17 @@
    @TableField(exist = false)
    private Integer vipId;
    @TableField(exist = false)
    private List<GoodsShop> goodsShopList;
    @TableField(exist = false)
    private List<GoodsAppUser> goodsAppUserList;
    @TableField(exist = false)
    private List<GoodsVip> goodsVipList;
    @TableField(exist = false)
    private List<GoodsArea> goodsAreaList;
}
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsBargainPrice.java
@@ -8,6 +8,7 @@
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
 * <p>
@@ -20,7 +21,7 @@
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_goods_bargain_price")
@ApiModel(value="GoodsBargainPrice对象", description="")
@ApiModel(value="门店特殊价格对象", description="")
public class GoodsBargainPrice implements Serializable {
    private static final long serialVersionUID = 1L;
@@ -66,5 +67,8 @@
    @TableField("create_user_id")
    private Integer createUserId;
    @TableField(exist = false)
    private List<GoodsBargainPriceDetail> goodsBargainPriceDetailList;
}
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsBargainPriceDetail.java
@@ -23,7 +23,7 @@
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_goods_bargain_price_detail")
@ApiModel(value="GoodsBargainPriceDetail对象", description="")
@ApiModel(value="门店特殊价格明细对象", description="")
public class GoodsBargainPriceDetail implements Serializable {
    private static final long serialVersionUID = 1L;
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java
@@ -2,6 +2,8 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
@@ -35,8 +37,49 @@
     * 添加商品
     */
    @PostMapping("/addGoods")
    @ApiOperation(value = "添加商品", tags = {"管理后台-发布商品"})
    @ApiOperation(value = "添加商品", tags = {"管理后台-商品管理-发布商品"})
    public R<Void> addGoods(@RequestBody Goods goods) {
        goodsService.addGoods(goods);
        return R.ok();
    }
    /**
     * 后台管理商品列表
     */
    @GetMapping("/manageGoodsList")
    @ApiOperation(value = "后台管理商品列表", tags = {"管理后台-商品管理-商品列表"})
    public R<IPage<Goods>> manageGoodsList(@ApiParam("页码") @RequestParam Integer PageNum,
                                           @ApiParam("每一页数据大小") Integer pageSize,
                                           Goods goods){
        return R.ok(goodsService.getManageGoodsList(new Page<>(PageNum, pageSize), goods));
    }
    /**
     * 后台商品详情
     */
    @GetMapping("/manageGoodsDetail/{goodsId}")
    @ApiOperation(value = "后台商品详情", tags = {"管理后台-商品管理-商品详情"})
    public R<Goods> manageGoodsDetail(@PathVariable("goodsId") Long goodsId){
        return R.ok(goodsService.getManageGoodsDetail(goodsId));
    }
    /**
     * 后台商品修改
     */
    @PutMapping("/manageGoodsUpdate")
    @ApiOperation(value = "后台商品修改", tags = {"管理后台-商品管理-商品修改"})
    public R<Void> manageGoodsUpdate(@RequestBody Goods goods){
        goodsService.updateManageGoods(goods);
        return R.ok();
    }
    /**
     * 后台商品删除
     */
    @DeleteMapping("/manageGoodsDelete/{goodsId}")
    @ApiOperation(value = "后台商品删除", tags = {"管理后台-商品管理-商品删除"})
    public R<Void> manageGoodsDelete(@PathVariable("goodsId") Long goodsId){
        goodsService.removeById(goodsId);
        return R.ok();
    }
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/mapper/GoodsMapper.java
@@ -1,6 +1,7 @@
package com.ruoyi.other.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.other.api.domain.Goods;
import org.apache.ibatis.annotations.Param;
@@ -16,4 +17,6 @@
 */
public interface GoodsMapper extends BaseMapper<Goods> {
    List<Goods> selectListByShopId(@Param("shopId") Integer shopId,@Param("vip") Integer vip);
    IPage<Goods> selectManageGoodsList(@Param("page") IPage<Goods> page, @Param("goods") Goods goods);
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/GoodsService.java
@@ -1,5 +1,7 @@
package com.ruoyi.other.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.other.api.domain.Goods;
import com.ruoyi.other.vo.GoodsVO;
@@ -21,4 +23,12 @@
    GoodsVO goodsDetail(Long goodsId);
    List<Goods> getGoodsListByShopId(Integer shopId);
    void addGoods(Goods goods);
    void updateManageGoods(Goods goods);
    IPage<Goods> getManageGoodsList(Page<Goods> page, Goods goods);
    Goods getManageGoodsDetail(Long goodsId);
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java
@@ -1,6 +1,8 @@
package com.ruoyi.other.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.feignClient.AppUserClient;
import com.ruoyi.account.api.model.AppUser;
@@ -16,17 +18,17 @@
import com.ruoyi.other.mapper.GoodsMapper;
import com.ruoyi.other.mapper.GoodsShopMapper;
import com.ruoyi.other.mapper.ShopMapper;
import com.ruoyi.other.service.GoodsService;
import com.ruoyi.other.service.GoodsVipService;
import com.ruoyi.other.service.VipSettingService;
import com.ruoyi.other.service.*;
import com.ruoyi.other.vo.GoodsVO;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -56,7 +58,13 @@
    @Resource
    private GoodsShopMapper goodsShopMapper;
    @Resource
    private GoodsShopService goodsShopService;
    @Resource
    private GoodsAppUserService goodsAppUserService;
    @Resource
    private ShopMapper shopMapper;
    @Resource
    private GoodsAreaService goodsAreaService;
    @Resource
    private RemoteOrderGoodsClient remoteOrderGoodsClient;
@@ -143,4 +151,77 @@
        return goodsMapper.selectListByShopId(shopId, vipSetting.getId());
    }
    @Override
    public IPage<Goods> getManageGoodsList(Page<Goods> page, Goods goods) {
        return goodsMapper.selectManageGoodsList(page, goods);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addGoods(Goods goods) {
        goods.setSaleNum(0);
        goods.setStatus(GoodsStatus.DOWN.getCode());
        goodsMapper.insert(goods);
        // 指定门店
        List<GoodsShop> goodsShopList = goods.getGoodsShopList();
        goodsShopService.saveBatch(goodsShopList);
        // 指定用户
        List<GoodsAppUser> goodsAppUserList = goods.getGoodsAppUserList();
        goodsAppUserService.saveBatch(goodsAppUserList);
        // 会员价格配置
        List<GoodsVip> goodsVipList = goods.getGoodsVipList();
        goodsVipService.saveBatch(goodsVipList);
        // 特殊地区售价设置
        List<GoodsArea> goodsAreaList = goods.getGoodsAreaList();
        goodsAreaService.saveBatch(goodsAreaList);
    }
    @Override
    public void updateManageGoods(Goods goods) {
        goodsMapper.updateById(goods);
        // 指定门店
        List<GoodsShop> goodsShopList = goods.getGoodsShopList();
        goodsShopService.updateBatchById(goodsShopList);
        // 指定用户
        List<GoodsAppUser> goodsAppUserList = goods.getGoodsAppUserList();
        goodsAppUserService.updateBatchById(goodsAppUserList);
        // 会员价格配置
        List<GoodsVip> goodsVipList = goods.getGoodsVipList();
        goodsVipService.updateBatchById(goodsVipList);
        // 特殊地区售价设置
        List<GoodsArea> goodsAreaList = goods.getGoodsAreaList();
        goodsAreaService.updateBatchById(goodsAreaList);
    }
    @Override
    public Goods getManageGoodsDetail(Long goodsId) {
        Goods goods = getById(goodsId);
        // 指定门店
        List<GoodsShop> goodsShops = goodsShopService.list(new LambdaQueryWrapper<GoodsShop>()
                .eq(GoodsShop::getGoodsId, goodsId));
        goods.setGoodsShopList(goodsShops);
        // 指定用户
        List<GoodsAppUser> goodsAppUserList = goodsAppUserService.list(new LambdaQueryWrapper<GoodsAppUser>()
                .eq(GoodsAppUser::getGoodsId, goodsId));
        goods.setGoodsAppUserList(goodsAppUserList);
        // 会员价格
        List<GoodsVip> goodsVipList = goodsVipService.list(new LambdaQueryWrapper<GoodsVip>()
                .eq(GoodsVip::getGoodsId, goodsId));
        goods.setGoodsVipList(goodsVipList);
        // 特殊地区售价设置
        List<GoodsArea> goodsAreaList = goodsAreaService.list(new LambdaQueryWrapper<GoodsArea>()
                .eq(GoodsArea::getGoodsId, goodsId));
        goods.setGoodsAreaList(goodsAreaList);
        return goods;
    }
}
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsMapper.xml
@@ -22,4 +22,36 @@
        </if>
        ORDER BY tg.sale_num DESC
    </select>
    <select id="selectManageGoodsList" resultType="com.ruoyi.other.api.domain.Goods">
        SELECT
            tg.id,
            tg.`name`,
            tg.type,
            tgc.`name`,
            tg.operating_cost,
            tg.shop_cost,
            tg.`status`
        FROM
            t_goods tg
                LEFT JOIN t_goods_category tgc ON tg.goods_category_id = tgc.id
        <where>
            <if test="">
                <if test="goods.id != null">
                    and tg.id = #{goods.id}
                </if>
                <if test="goods.name != null and goods.name != ''">
                    and tg.`name` like concat('%',#{goods.name},'%')
                </if>
                <if test="goods.type != null">
                    and tg.type = #{goods.type}
                </if>
                <if test="goods.goodsCategoryId != null">
                    and tg.goodsCategoryId = #{goods.goodsCategoryId}
                </if>
                <if test="goods.status != null">
                    and tg.`status` = #{goods.status}
                </if>
            </if>
        </where>
    </select>
</mapper>