直播添加商品相关操作
This commit is contained in:
@ -17,3 +17,5 @@
|
||||
|
||||
INSERT INTO `menu` VALUES (242, b'0', '直播管理', 'wechat/live/index', 48, 999, 'weixin', 'wxlive', b'0', b'0', 'Wxlive', '2020-08-10 17:20:54', NULL, 1, NULL, 0);
|
||||
|
||||
INSERT INTO `menu` VALUES
|
||||
(243, b'0', '直播商品管理', 'wechat/goods/index', 48, 999, 'weixin', 'wxlivegoods', b'0', b'0', 'WxliveGoods', '2020-08-10 17:20:54', NULL, 1, NULL, 0);
|
||||
|
44
sql/yx_wechat_live_goods.sql
Normal file
44
sql/yx_wechat_live_goods.sql
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : 本地
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 50729
|
||||
Source Host : localhost:3306
|
||||
Source Schema : yshopb2c
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 50729
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 11/08/2020 19:07:20
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for yx_wechat_live_goods
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `yx_wechat_live_goods`;
|
||||
CREATE TABLE `yx_wechat_live_goods` (
|
||||
`goods_id` bigint(9) NOT NULL COMMENT '直播商品id',
|
||||
`product_id` bigint(9) NULL DEFAULT NULL COMMENT '关联商品id',
|
||||
`cover_imge_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品图片',
|
||||
`url` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品小程序路径',
|
||||
`price_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '价格类型 1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传)',
|
||||
`price` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
|
||||
`price2` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品名称',
|
||||
`third_party_tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '1, 2:表示是为api添加商品,否则是直播控制台添加的商品',
|
||||
`audit_id` bigint(20) NULL DEFAULT NULL COMMENT '审核单id',
|
||||
`audit_status` int(1) UNSIGNED ZEROFILL NULL DEFAULT NULL COMMENT '审核状态 0:未审核,1:审核中,2:审核通过,3审核失败',
|
||||
PRIMARY KEY (`goods_id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of yx_wechat_live_goods
|
||||
-- ----------------------------
|
||||
INSERT INTO `yx_wechat_live_goods` VALUES (4, 30, 'http://127.0.0.1:8001/file/pic/20200811184905881166.png', 'pages/shop/GoodsCon/index.html?id=30', '1', '200', NULL, '测试商品', NULL, 447126638, NULL);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.domain;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.validation.constraints.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
@Data
|
||||
@TableName("yx_wechat_live_goods")
|
||||
public class YxWechatLiveGoods implements Serializable {
|
||||
|
||||
/** 直播商品id */
|
||||
@TableId(type = IdType.INPUT)
|
||||
private Long goodsId;
|
||||
|
||||
|
||||
/** 关联商品id */
|
||||
private Long productId;
|
||||
|
||||
|
||||
/** 商品图片 */
|
||||
@TableField(exist = false)
|
||||
private String coverImgUrl;
|
||||
|
||||
|
||||
/** 商品图片 */
|
||||
@NotBlank
|
||||
private String coverImgeUrl;
|
||||
|
||||
/** 商品小程序路径 */
|
||||
@NotBlank
|
||||
private String url;
|
||||
|
||||
|
||||
/** 价格类型 1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传) */
|
||||
@NotBlank
|
||||
private String priceType;
|
||||
|
||||
|
||||
@NotBlank
|
||||
private String price;
|
||||
|
||||
|
||||
private String price2;
|
||||
|
||||
|
||||
/** 商品名称 */
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
|
||||
/** 1, 2:表示是为api添加商品,否则是直播控制台添加的商品 */
|
||||
private String thirdPartyTag;
|
||||
|
||||
|
||||
/** 审核单id */
|
||||
private Long auditId;
|
||||
|
||||
|
||||
/** 审核状态 0:未审核,1:审核中,2:审核通过,3审核失败 */
|
||||
private Integer auditStatus;
|
||||
|
||||
|
||||
public void copy(YxWechatLiveGoods source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -82,4 +82,12 @@ public class YxWechatLiveController {
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("同步数据")
|
||||
@GetMapping("/synchro")
|
||||
public ResponseEntity<Object> synchroWxOlLive() {
|
||||
yxWechatLiveService.synchroWxOlLive();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.rest;
|
||||
import java.util.Arrays;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLiveGoods;
|
||||
import co.yixiang.modules.wechat.service.YxWechatLiveGoodsService;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsQueryCriteria;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsDto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Api(tags = "yxWechatLiveGoods管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/yxWechatLiveGoods")
|
||||
public class YxWechatLiveGoodsController {
|
||||
|
||||
private final YxWechatLiveGoodsService yxWechatLiveGoodsService;
|
||||
private final IGenerator generator;
|
||||
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLiveGoods:list')")
|
||||
public void download(HttpServletResponse response, YxWechatLiveGoodsQueryCriteria criteria) throws IOException {
|
||||
yxWechatLiveGoodsService.download(generator.convert(yxWechatLiveGoodsService.queryAll(criteria), YxWechatLiveGoodsDto.class), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询yxWechatLiveGoods")
|
||||
@ApiOperation("查询yxWechatLiveGoods")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLiveGoods:list')")
|
||||
public ResponseEntity<Object> getYxWechatLiveGoodss(YxWechatLiveGoodsQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(yxWechatLiveGoodsService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增yxWechatLiveGoods")
|
||||
@ApiOperation("新增yxWechatLiveGoods")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLiveGoods:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody YxWechatLiveGoods resources){
|
||||
return new ResponseEntity<>(yxWechatLiveGoodsService.saveGoods(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改yxWechatLiveGoods")
|
||||
@ApiOperation("修改yxWechatLiveGoods")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLiveGoods:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody YxWechatLiveGoods resources){
|
||||
yxWechatLiveGoodsService.updateById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除yxWechatLiveGoods")
|
||||
@ApiOperation("删除yxWechatLiveGoods")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLiveGoods:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
|
||||
Arrays.asList(ids).forEach(id->{
|
||||
yxWechatLiveGoodsService.removeById(id);
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("同步数据")
|
||||
@PostMapping("/synchro")
|
||||
public ResponseEntity<Object> synchroWxOlLiveGoods(@RequestBody Integer[] ids) {
|
||||
yxWechatLiveGoodsService.synchroWxOlLive(Arrays.asList(ids));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLiveGoods;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsDto;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
public interface YxWechatLiveGoodsService extends BaseService<YxWechatLiveGoods>{
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(YxWechatLiveGoodsQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<YxWechatLiveGoodsDto>
|
||||
*/
|
||||
List<YxWechatLiveGoods> queryAll(YxWechatLiveGoodsQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<YxWechatLiveGoodsDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
boolean saveGoods(YxWechatLiveGoods resources);
|
||||
|
||||
boolean synchroWxOlLive(List<Integer> goodsIds);
|
||||
}
|
@ -23,6 +23,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||
*/
|
||||
public interface YxWechatLiveService extends BaseService<YxWechatLive>{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
boolean synchroWxOlLive();
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
|
@ -37,6 +37,9 @@ public class WxMaLiveInfo implements Serializable {
|
||||
*/
|
||||
private String shareImg;
|
||||
|
||||
/**
|
||||
* 101:直播中,102:未开始,103已结束,104禁播,105:暂停,106:异常,107:已过期
|
||||
*/
|
||||
private Integer liveStatus;
|
||||
/**
|
||||
* 直播计划开始时间(开播时间需要在当前时间的10分钟后 并且 开始时间不能在 6 个月后)
|
||||
@ -92,12 +95,33 @@ public class WxMaLiveInfo implements Serializable {
|
||||
@Data
|
||||
public static class Goods implements Serializable {
|
||||
private static final long serialVersionUID = 5769245932149287574L;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer goodsId;
|
||||
/**
|
||||
* 填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;图片规则:图片尺寸最大300像素*300像素;
|
||||
*/
|
||||
private String coverImgUrl;
|
||||
/**
|
||||
* 商品详情页的小程序路径,路径参数存在 url 的,该参数的值需要进行 encode 处理再填入
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传)
|
||||
*/
|
||||
private Integer priceType;
|
||||
/**
|
||||
* 数字,最多保留两位小数,单位元
|
||||
*/
|
||||
private String price;
|
||||
/**
|
||||
* 数字,最多保留两位小数,单位元
|
||||
*/
|
||||
private String price2;
|
||||
/**
|
||||
* 商品名称,最长14个汉字,1个汉字相当于2个字符
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 1, 2:表示是为api添加商品,否则是在MP添加商品
|
||||
|
@ -20,7 +20,13 @@ public class WxMaLiveResult implements Serializable {
|
||||
private Integer errcode;
|
||||
private String errmsg;
|
||||
private Integer total;
|
||||
/**
|
||||
* 审核单ID
|
||||
*/
|
||||
private Integer auditId;
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Integer goodsId;
|
||||
private List<Goods> goods;
|
||||
|
||||
@ -84,7 +90,7 @@ public class WxMaLiveResult implements Serializable {
|
||||
private static final long serialVersionUID = 7745775280267417154L;
|
||||
private String name;
|
||||
@SerializedName("roomid")
|
||||
private Integer roomId;
|
||||
private Integer roomid;
|
||||
@SerializedName("cover_img")
|
||||
private String coverImg;
|
||||
@SerializedName("share_img")
|
||||
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
@Data
|
||||
public class YxWechatLiveGoodsDto implements Serializable {
|
||||
|
||||
/** 直播商品id */
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long goodsId;
|
||||
|
||||
/** 关联商品id */
|
||||
private Long productId;
|
||||
|
||||
/** 商品图片 */
|
||||
private String coverImgeUrl;
|
||||
|
||||
/** 商品小程序路径 */
|
||||
private String url;
|
||||
|
||||
/** 价格类型 1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传) */
|
||||
private String priceType;
|
||||
|
||||
private String price;
|
||||
|
||||
private String price2;
|
||||
|
||||
/** 商品名称 */
|
||||
private String name;
|
||||
|
||||
/** 1, 2:表示是为api添加商品,否则是直播控制台添加的商品 */
|
||||
private String thirdPartyTag;
|
||||
|
||||
/** 审核单id */
|
||||
private Long auditid;
|
||||
|
||||
/** 审核状态 0:未审核,1:审核中,2:审核通过,3审核失败 */
|
||||
private Integer auditStatus;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
import co.yixiang.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
@Data
|
||||
public class YxWechatLiveGoodsQueryCriteria{
|
||||
|
||||
/** 模糊 */
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLive;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLiveGoods;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.modules.wechat.service.WxMaLiveGoodsService;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveResult;
|
||||
import co.yixiang.tools.config.WxMaConfiguration;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import co.yixiang.common.utils.QueryHelpPlus;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import co.yixiang.modules.wechat.service.YxWechatLiveGoodsService;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsDto;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsQueryCriteria;
|
||||
import co.yixiang.modules.wechat.service.mapper.YxWechatLiveGoodsMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
// 默认不使用缓存
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
//@CacheConfig(cacheNames = "yxWechatLiveGoods")
|
||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
|
||||
public class YxWechatLiveGoodsServiceImpl extends BaseServiceImpl<YxWechatLiveGoodsMapper, YxWechatLiveGoods> implements YxWechatLiveGoodsService {
|
||||
|
||||
private final IGenerator generator;
|
||||
@Value("${file.path}")
|
||||
private String uploadDirStr;
|
||||
private final WxMaLiveGoodsService wxMaLiveGoodsService;
|
||||
public YxWechatLiveGoodsServiceImpl(IGenerator generator, WxMaLiveGoodsService wxMaLiveGoodsService) {
|
||||
this.generator = generator;
|
||||
this.wxMaLiveGoodsService = wxMaLiveGoodsService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步商品更新审核状态
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
public boolean synchroWxOlLive(List<Integer> goodsIds) {
|
||||
try {
|
||||
WxMaLiveResult liveInfos = wxMaLiveGoodsService.getGoodsWareHouse(goodsIds);
|
||||
List<YxWechatLiveGoods> convert = generator.convert(liveInfos.getGoods(), YxWechatLiveGoods.class);
|
||||
convert.forEach(i ->{
|
||||
i.setCoverImgeUrl(i.getCoverImgUrl());
|
||||
});
|
||||
this.saveOrUpdateBatch(convert);
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
//@Cacheable
|
||||
public Map<String, Object> queryAll(YxWechatLiveGoodsQueryCriteria criteria, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<YxWechatLiveGoods> page = new PageInfo<>(queryAll(criteria));
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", generator.convert(page.getList(), YxWechatLiveGoodsDto.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
public List<YxWechatLiveGoods> queryAll(YxWechatLiveGoodsQueryCriteria criteria){
|
||||
return baseMapper.selectList(QueryHelpPlus.getPredicate(YxWechatLiveGoods.class, criteria));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void download(List<YxWechatLiveGoodsDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (YxWechatLiveGoodsDto yxWechatLiveGoods : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("关联商品id", yxWechatLiveGoods.getProductId());
|
||||
map.put("商品图片", yxWechatLiveGoods.getCoverImgeUrl());
|
||||
map.put("商品小程序路径", yxWechatLiveGoods.getUrl());
|
||||
map.put("价格类型 1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传)", yxWechatLiveGoods.getPriceType());
|
||||
map.put(" price", yxWechatLiveGoods.getPrice());
|
||||
map.put(" price2", yxWechatLiveGoods.getPrice2());
|
||||
map.put("商品名称", yxWechatLiveGoods.getName());
|
||||
map.put("1, 2:表示是为api添加商品,否则是直播控制台添加的商品", yxWechatLiveGoods.getThirdPartyTag());
|
||||
map.put("审核单id", yxWechatLiveGoods.getAuditid());
|
||||
map.put("审核状态 0:未审核,1:审核中,2:审核通过,3审核失败", yxWechatLiveGoods.getAuditStatus());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveGoods(YxWechatLiveGoods resources) {
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
try {
|
||||
resources.setCoverImgUrl(uploadPhotoToWx(wxMaService,resources.getCoverImgeUrl()).getMediaId());
|
||||
WxMaLiveInfo.Goods goods = generator.convert(resources, WxMaLiveInfo.Goods.class);
|
||||
WxMaLiveResult wxMaLiveResult = wxMaLiveGoodsService.addGoods(goods);
|
||||
resources.setGoodsId(Long.valueOf(wxMaLiveResult.getGoodsId()));
|
||||
resources.setAuditId(Long.valueOf(wxMaLiveResult.getAuditId()));
|
||||
this.save(resources);
|
||||
} catch (WxErrorException e) {
|
||||
throw new BadRequestException(e.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传临时素材
|
||||
* @param wxMaService WxMaService
|
||||
* @param picPath 图片路径
|
||||
* @return WxMpMaterialUploadResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
private WxMediaUploadResult uploadPhotoToWx(WxMaService wxMaService, String picPath) throws WxErrorException {
|
||||
String filename = String.valueOf( (int)System.currentTimeMillis() ) + ".png";
|
||||
String downloadPath = uploadDirStr + filename;
|
||||
long size = HttpUtil.downloadFile(picPath, cn.hutool.core.io.FileUtil.file(downloadPath));
|
||||
picPath = downloadPath;
|
||||
File picFile = new File( picPath );
|
||||
log.info( "picFile name : {}", picFile.getName() );
|
||||
WxMediaUploadResult wxMediaUploadResult = wxMaService.getMediaService().uploadMedia( WxConsts.MediaFileType.IMAGE, picFile );
|
||||
log.info( "wxMpMaterialUploadResult : {}", JSONUtil.toJsonStr( wxMediaUploadResult ) );
|
||||
return wxMediaUploadResult;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.modules.wechat.service.WxMaLiveService;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveResult;
|
||||
import co.yixiang.tools.config.WxMaConfiguration;
|
||||
import co.yixiang.utils.DateUtils;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
@ -68,14 +69,35 @@ public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper,
|
||||
this.wxMaLiveService = wxMaLiveService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步直播间
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
public boolean synchroWxOlLive() {
|
||||
try {
|
||||
List<WxMaLiveResult.RoomInfo> liveInfos = wxMaLiveService.getLiveInfos();
|
||||
List<YxWechatLive> convert = generator.convert(liveInfos, YxWechatLive.class);
|
||||
convert.forEach(i ->{
|
||||
i.setAnchorImge(i.getAnchorImg());
|
||||
i.setCoverImge(i.getCoverImg());
|
||||
i.setShareImge(i.getShareImg());
|
||||
});
|
||||
this.saveOrUpdateBatch(convert);
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
//@Cacheable
|
||||
public Map<String, Object> queryAll(YxWechatLiveQueryCriteria criteria, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<YxWechatLive> page = new PageInfo<>(queryAll(criteria));
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", generator.convert(page.getList(), YxWechatLiveDto.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
// List<WxMaLiveResult.RoomInfo> liveInfos = wxMaLiveService.getLiveInfos();
|
||||
map.put("content", generator.convert(page.getList(), YxWechatLiveDto.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
|
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.mapper;
|
||||
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLiveGoods;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-11
|
||||
*/
|
||||
@Repository
|
||||
public interface YxWechatLiveGoodsMapper extends CoreMapper<YxWechatLiveGoods> {
|
||||
|
||||
}
|
Reference in New Issue
Block a user