diff --git a/consumer/src/main/resources/application.yml b/consumer/src/main/resources/application.yml index f808afe7..79a1af45 100644 --- a/consumer/src/main/resources/application.yml +++ b/consumer/src/main/resources/application.yml @@ -77,7 +77,7 @@ spring: default-datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + url: jdbc:mysql://127.0.0.1:3306/Bulbasaur?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai username: root password: lilishop maxActive: 20 diff --git a/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java b/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java index da71b825..b4aa4a7e 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/entity/dos/Commodity.java @@ -17,7 +17,7 @@ import javax.persistence.Table; */ @Data @Entity -@ApiModel(value = "直播商品") +@ApiModel(value = "Commodity", description = "直播商品") @TableName("li_commodity") @Table(name = "li_commodity") public class Commodity extends BaseEntity { diff --git a/framework/src/main/java/cn/lili/modules/broadcast/entity/dto/CommodityDTO.java b/framework/src/main/java/cn/lili/modules/broadcast/entity/dto/CommodityDTO.java new file mode 100644 index 00000000..fb326888 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/broadcast/entity/dto/CommodityDTO.java @@ -0,0 +1,19 @@ +package cn.lili.modules.broadcast.entity.dto; + +import lombok.Data; + +/** + * 直播商品DTO + * 用于获取直播商品状态时使用 + * + * @author Bulbasaur + * @date: 2021/5/25 12:12 下午 + */ +@Data +public class CommodityDTO { + + private Integer goods_id; + private String name; + private String url; + private Integer audit_status; +} diff --git a/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java b/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java index 530d59d6..621533a9 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/mapper/CommodityMapper.java @@ -15,8 +15,8 @@ import java.util.List; */ public interface CommodityMapper extends BaseMapper { - @Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1' AND store_id =#{storeId}") - List getAuditCommodity(String storeId); + @Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1'") + List getAuditCommodity(); @Select("SELECT * FROM li_commodity c WINNER JOIN li_studio_commodity sc ON sc.goods_id = c.live_goods_id WHERE sc.room_id =#{roomId}") List getCommodityByRoomId(Integer roomId); diff --git a/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java b/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java index 8bde1e8b..8ff14e31 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/service/CommodityService.java @@ -1,6 +1,8 @@ package cn.lili.modules.broadcast.service; +import cn.lili.common.vo.PageVO; import cn.lili.modules.broadcast.entity.dos.Commodity; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -30,4 +32,13 @@ public interface CommodityService extends IService { * 查询微信小程序直播商品审核状态 */ void getGoodsWareHouse(); + + /** + * 查看直播商品分页 + * @param pageVO 分页 + * @param name 商品名称 + * @param auditStatus 审核状态 + * @return 直播商品分页 + */ + IPage commodityList(PageVO pageVO,String name,String auditStatus); } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java index baa954ce..4fb61043 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java @@ -1,18 +1,25 @@ package cn.lili.modules.broadcast.serviceimpl; import cn.hutool.core.convert.Convert; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import cn.lili.common.security.context.UserContext; +import cn.lili.common.utils.PageUtil; +import cn.lili.common.vo.PageVO; import cn.lili.modules.broadcast.entity.dos.Commodity; +import cn.lili.modules.broadcast.entity.dto.CommodityDTO; import cn.lili.modules.broadcast.mapper.CommodityMapper; import cn.lili.modules.broadcast.service.CommodityService; import cn.lili.modules.broadcast.util.WechatLivePlayerUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; -import java.util.Map; /** * 直播商品业务层实现 @@ -28,7 +35,7 @@ public class CommodityServiceImpl extends ServiceImpl commodityList) { - for (Commodity commodity:commodityList) { + for (Commodity commodity : commodityList) { JSONObject json = wechatLivePlayerUtil.addGoods(commodity); commodity.setLiveGoodsId(Convert.toInt(json.getStr("goodsId"))); commodity.setAuditId(json.getStr("auditId")); @@ -49,18 +56,27 @@ public class CommodityServiceImpl extends ServiceImpl goodsIdList = this.baseMapper.getAuditCommodity(UserContext.getCurrentUser().getStoreId()); - //同步状态 - JSONObject json = wechatLivePlayerUtil.getGoodsWareHouse(goodsIdList); - //修改状态 - List> list = (List) json.get("goods"); - for (Map map : list) { - //修改审核状态 - this.update(this.lambdaUpdate() - .eq(Commodity::getLiveGoodsId, map.get("goods_id")) - .set(Commodity::getAuditStatus, map.get("audit_status"))); + List goodsIdList = this.baseMapper.getAuditCommodity(); + if (goodsIdList.size() > 0) { + //同步状态 + JSONObject json = wechatLivePlayerUtil.getGoodsWareHouse(goodsIdList); + //修改状态 + List commodityDTOList = JSONUtil.toList((JSONArray) json.get("goods"), CommodityDTO.class); + for (CommodityDTO commodityDTO : commodityDTOList) { + //修改审核状态 + this.update(new LambdaUpdateWrapper() + .eq(Commodity::getLiveGoodsId, commodityDTO.getGoods_id()) + .set(Commodity::getAuditStatus, commodityDTO.getAudit_status())); + } } } + @Override + public IPage commodityList(PageVO pageVO, String name, String auditStatus) { + return this.page(PageUtil.initPage(pageVO), + new LambdaQueryWrapper().like(name!=null,Commodity::getName,name) + .eq(auditStatus!=null,Commodity::getAuditStatus,auditStatus)); + } + } diff --git a/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java b/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java index 4852a419..7faceeb4 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/util/WechatLivePlayerUtil.java @@ -164,8 +164,12 @@ public class WechatLivePlayerUtil { String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=" + token; //新建微信商品DTO GoodsInfo goodsInfo = new GoodsInfo(commodity); + //上传微信临时图片 goodsInfo.setCoverImgUrl(wechatMediaUtil.uploadMedia(token,"image",commodity.getGoodsImage())); - String content = HttpUtils.doPostWithJson(url, goodsInfo); + Map map=new HashMap<>(); + //调用新增直播商品接口 + map.put("goodsInfo",goodsInfo); + String content = HttpUtils.doPostWithJson(url, map); JSONObject json = new JSONObject(content); log.info("微信小程序添加直播商品结果:" + content); return json; @@ -182,6 +186,8 @@ public class WechatLivePlayerUtil { String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP); //发送url String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=" + token; + Map map=new HashMap<>(); + map.put("goodsId",goodsId); String content = HttpUtils.doPostWithJson(url, goodsId); JSONObject json = new JSONObject(content); log.info("微信小程序删除直播商品结果:" + content); @@ -199,7 +205,9 @@ public class WechatLivePlayerUtil { String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP); //发送url String url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=" + token; - String content = HttpUtils.doPostWithJson(url, goodsIdList); + Map map=new HashMap<>(); + map.put("goods_ids",goodsIdList); + String content = HttpUtils.doPostWithJson(url, map); JSONObject json = new JSONObject(content); log.info("微信小程序查询直播商品结果:" + content); return json; diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 17ca7d27..8823ee9c 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -572,6 +572,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i StringBuilder goodsName = new StringBuilder(goods.getGoodsName()); //规格商品缩略图 String thumbnail = ""; + String small = ""; //规格值 Map specMap = new HashMap<>(); //商品属性 @@ -591,6 +592,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i throw new ServiceException("sku图片至少为一个"); } thumbnail = goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getThumbnail(); + small = goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getSmall(); } else { //设置商品名称 goodsName.append(" ").append(m.getValue()); @@ -615,6 +617,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //设置规格信息 sku.setGoodsName(goodsName.toString()); sku.setThumbnail(thumbnail); + sku.setSmall(small); //规格信息 sku.setId(Convert.toStr(map.get("id"), "").toString()); diff --git a/seller-api/src/main/java/cn/lili/controller/other/broadcast/CommodityController.java b/seller-api/src/main/java/cn/lili/controller/other/broadcast/CommodityController.java index 0e59756d..5876edf5 100644 --- a/seller-api/src/main/java/cn/lili/controller/other/broadcast/CommodityController.java +++ b/seller-api/src/main/java/cn/lili/controller/other/broadcast/CommodityController.java @@ -3,16 +3,16 @@ package cn.lili.controller.other.broadcast; import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultUtil; import cn.lili.common.exception.ServiceException; -import cn.lili.common.utils.PageUtil; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.broadcast.entity.dos.Commodity; import cn.lili.modules.broadcast.service.CommodityService; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -32,14 +32,19 @@ public class CommodityController { private CommodityService commodityService; @ApiOperation(value = "获取店铺直播商品列表") + @ApiImplicitParams({ + @ApiImplicitParam(name = "name", value = "商品名称", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "auditStatus", value = "直播商品状态", dataType = "String", paramType = "query") + }) @GetMapping - public ResultMessage> page(PageVO pageVO) { - return ResultUtil.data(commodityService.page(PageUtil.initPage(pageVO))); + public ResultMessage> page(String auditStatus, String name, PageVO pageVO) { + return ResultUtil.data(commodityService.commodityList(pageVO, name, auditStatus)); } @ApiOperation(value = "添加店铺直播商品") + @ApiImplicitParam(name = "commodityList", value = "直播商品列表", paramType = "body", allowMultiple = true, dataType = "Commodity") @PostMapping - public ResultMessage addCommodity(@Validated List commodityList) { + public ResultMessage addCommodity(@RequestBody List commodityList) { if (commodityService.addCommodity(commodityList)) { return ResultUtil.success(ResultCode.SUCCESS); } @@ -47,8 +52,9 @@ public class CommodityController { } @ApiOperation(value = "删除店铺直播商品") - @DeleteMapping - public ResultMessage delete(String goodsId) { + @ApiImplicitParam(name = "goodsId", value = "直播商品ID", dataType = "String", paramType = "path") + @DeleteMapping("/{goodsId}") + public ResultMessage delete(@PathVariable String goodsId) { if (commodityService.deleteCommodity(goodsId)) { return ResultUtil.success(ResultCode.SUCCESS); }