记得上下班打卡 | git大法好,push需谨慎

Commit fdb748b6 authored by zhengfuxin's avatar zhengfuxin

创建新的 项目

parent 652e1507
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liquidnet-bus-api</artifactId>
<groupId>com.liquidnet</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liquidnet-service-smile-api</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-goblin-do</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.liquidnet.service.goblin.constant;
public class GoblinRedisConst {
public static final String PREFIX = "goblin:";
/* ----------------------------------------------------------------- */
/**
* 认证中店铺UID关系缓存
* {goblin:bsc:ustore:${uid}, List<store_id>}
*/
public static final String BASIC_USTORE = PREFIX.concat("bsc:ustore:");
/**
* 平台商品标签信息
* {goblin:bsc:self_tag, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.vo.GoblinSelfTagVo>)}
*/
public static final String BASIC_SELF_TAG = PREFIX.concat("bsc:self_tag");
/**
* 平台专属标签信息
* {goblin:bsc:self_etag, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.vo.GoblinSelfTagVo>)}
*/
public static final String BASIC_SELF_EXTAG = PREFIX.concat("bsc:self_etag");
/**
* 平台商品分类信息
* {goblin:bsc:self_g_c, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.vo.GoblinSelfGoodsCategoryVo>)}
*/
public static final String BASIC_SELF_GOODS_CATEGORY = PREFIX.concat("bsc:self_g_c");
/**
* 平台商品分类信息
* {goblin:bsc:self_g_c_s:${cate_id}, com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo}
*/
public static final String BASIC_SELF_GOODS_CATEGORY_SPEC = PREFIX.concat("bsc:self_g_c_s:");
/**
* 平台服务支持信息
* {goblin:bsc:sev_sup, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.vo.GoblinServiceSupportVo>)}
*/
public static final String BASIC_SERVICE_SUPPORT = PREFIX.concat("bsc:sev_sup");
/**
* 店铺信息
* {goblin:bsc:store:${store_id}, com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo}
*/
public static final String BASIC_STORE = PREFIX.concat("bsc:store:");
/**
* 店铺配置信息
* {goblin:bsc:store_cf:${store_id}, com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo}
*/
public static final String BASIC_STORE_CONF = PREFIX.concat("bsc:store_cf:");
/**
* 店铺商品分类信息
* {goblin:bsc:store_g_c:${store_id}, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.vo.GoblinStoreGoodsCategoryVo>)}
*/
public static final String BASIC_STORE_GOODS_CATEGORY = PREFIX.concat("bsc:store_g_c:");
/**
* SPU信息
* {goblin:bsc:goods:${spu_id}, com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo}
*/
public static final String BASIC_GOODS = PREFIX.concat("bsc:goods:");
public static final String BASIC_GOODS_UNSHELVES = PREFIX.concat("bsc:goods_unshelves:");
/**
* SKU信息
* {goblin:bsc:goods_sku:${sku_id}, com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo}
*/
public static final String BASIC_GOODS_SKU = PREFIX.concat("bsc:goods_sku:");
public static final String BASIC_GOODS_SKU_UNSHELVES = PREFIX.concat("bsc:goods_sku_unshelves:");
/* ----------------------------------------------------------------- */
/**
* 店铺公告
* {goblin:store_ntc:${store_id}, com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo}
*/
public static final String STORE_NOTICE = PREFIX.concat("store_ntc:");
/* ----------------------------------------------------------------- */
public static final String FRONT_TOP_BANNER = PREFIX.concat("front_top_banner"); //前端顶部banner
public static final String FRONT_MIDDLE_BANNER = PREFIX.concat("front_middle_banner"); //前端中部banner
public static final String FRONT_NAVIGATION = PREFIX.concat("front_navigation"); //前端banner
public static final String FRONT_HOTWORD = PREFIX.concat("front_hot_word"); //前端banner
public static final String FRONT_HOTWORD_INDEX = PREFIX.concat("front_hot_word_index"); //前端banner index
public static final String FRONT_FRONT_SECKILL = PREFIX.concat("front_front_seckill"); //前端 首页秒杀
public static final String FRONT_SECKILL = PREFIX.concat("front_seckill"); //前端 秒杀列表
public static final String SELECT_GOODS = PREFIX.concat("select_goods"); //配置的精选商品
public static final String SELECT_GOODS_PAGE1 = PREFIX.concat("select_goods_page1"); //精选商品 第一页
public static final String SELECT_GOODS_SORT = PREFIX.concat("select_goods_sort"); //精选商品 排序规则
public static final String SELECT_GOODS_SPUIDS = PREFIX.concat("select_goods_SPUIDS"); //精选商品 spuids
public static final String MOUDLE_INDEX = PREFIX.concat("moudle_index"); //moudle_index 组件排序
public static final String COMPLIATIONS = PREFIX.concat("goblinFrontCompilations"); // 合集
public static final String FRONT_GOBLINFRONTCUBE = PREFIX.concat("goblinFrontCube"); // 魔方
public static final String FRONT_GOBLIN_RECOMMEND= PREFIX.concat("goblinFrontRECOMMMEND"); // 新品推荐
public static final String FRONT_SHOPCART = PREFIX.concat("goblin_shopcart:"); // 购物车
public static final String FRONT_SHOPCART_TWO = PREFIX.concat("goblin_shopcartTwo:"); // 购物车第二部
/* ----------------------------------------------------------------- */
public static final String REDIS_GOBLIN_MARKET_RELATION = PREFIX.concat("market:relation:");//商铺活动-商铺款式关联关系
public static final String REDIS_GOBLIN_SELF_MARKET = PREFIX.concat("self:market:");//官方活动
public static final String REDIS_GOBLIN_ZHENGZAI_RELATION = PREFIX.concat("zhengzai:market:");//活动-正在下单-可参加商户
public static final String REDIS_GOBLIN_STORE_SELF_RELATION = PREFIX.concat("zhengzai:storeId:");//活动-当前商铺能参与的官方活动id列表
public static final String REDIS_GOBLIN_STORE_MARKET = PREFIX.concat("store:market:");//商铺活动
public static final String REDIS_GOBLIN_ZHENGZAI_LIST = PREFIX.concat("zhengzai:list");//全部正在下单内容
public static final String REDIS_GOBLIN_STORE_MARKET_ISCONFIG = PREFIX.concat("store:is_config:");//商铺活动-该活动配置了款式的商品
public static final String REDIS_GOBLIN_BUY_COUNT = PREFIX.concat("uid:");//用户sku购买数量 key:uid:skuId:$skuId
public static final String REDIS_GOBLIN_SALE_COUNT = PREFIX.concat("sale:skuId:");//用户sku购买数量 key:sale:skuId:$skuId
public static final String REDIS_GOBLIN_SALE_SPU_COUNT = PREFIX.concat("sale:skuId:");//用户sku购买数量 key:sale:skuId:$spuId
public static final String REDIS_GOBLIN_ORDER = PREFIX.concat("order:");//用户sku购买数量 key:$orderId
public static final String REDIS_GOBLIN_ORDER_BACK = PREFIX.concat("order:back:");//用户sku购买数量 key:$backOrderId
public static final String REDIS_GOBLIN_ORDER_SKU = PREFIX.concat("orderSku:");//用户sku购买数量 key:$orderSkuId
public static final String REDIS_GOBLIN_ORDER_UN_PAY = PREFIX.concat("order:un:pay:");//未支付订单id列表 key:$randomKey
public static final String REDIS_GOBLIN_ORDER_LIST = PREFIX.concat("order:id:list:");//用户订单id列表 key:$uid
public static final String REDIS_GOBLIN_ORDER_ZHENGZAI_LIST = PREFIX.concat("order:zhengzai:list:");//用户订单id列表 key:$uid
public static final String REDIS_GOBLIN_ORDER_MASTER = PREFIX.concat("order:masterCode:");//用户订单id列表 key:$masterCode
public static final String REDIS_GOBLIN_ORDER_OFFCODE = PREFIX.concat("order:offCode:");//用户订单id列表 key:$wtrieOffCode
public static final String REDIS_GOBLIN_BACK_ORDER_ID = PREFIX.concat("order:backIds:");//用户订单下的退款订单id key:$orderId
public static final String REDIS_CAN_BUY = PREFIX.concat("canBuy:");//可以购买的用户 key:$skuId:$mobile
public static final String REDIS_ZZ_MUSIC_TAG = PREFIX.concat("music:tag:ZZ:");//根据场次音乐人标签搜索列表 key:$musicTag:$performanceId
public static final String REDIS_GOBLIN_MAIL = PREFIX.concat("mail:orderId:");//快递 $key:$orderId
public static final String REDIS_GOBLIN_TEMP_COUPON_MARKET = PREFIX.concat("temp:coupon:marketId:");//id 列表 $key:$marketId
public static final String REDIS_GOBLIN_TEMP_COUPON = PREFIX.concat("temp:coupon:");//详情 $key:$ucouponId
/* ----------------------------------------------------------------- */
/**
* SKU剩余库存
*/
public static final String REAL_STOCK_SKU = PREFIX.concat("real_stock_sku:");
public static final String SKU_RELATION = PREFIX.concat("sku:relation:");//$key:$skuId
/* ----------------------------------------------------------------- */
/**
* 商铺活动:优惠券基本信息
* {goblin:s_coupon:${store_coupon_id}, com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponVo}
*/
public static final String STORE_COUPON = PREFIX.concat("s_coupon:");
/**
* 商铺活动:优惠券适用商品ID集合
* {goblin:s_coupon_r:${store_coupon_id}, JsonUtils.toJson(List<String:spu_id>)}
*/
public static final String STORE_COUPON_RULE = PREFIX.concat("s_coupon_r:");
/**
* 商铺活动:优惠券剩余库存
*/
public static final String STORE_COUPON_STOCK = PREFIX.concat("s_coupon_stock:");
/* ----------------------------------------------------------------- */
/**
* 商铺活动ID集合
* {goblin:store_markets:${store_id}, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.GoblinGoodsMarketDto>)}
*/
public static final String STORE_MARKETS = PREFIX.concat("store_markets:");
/* ----------------------------------------------------------------- */
/**
* 商城用户券
* {golblin:user_coupon:${uid}, JsonUtils.toJson(List<com.liquidnet.service.goblin.dto.vo.GoblinUserCouponVo>)}
*/
public static final String USER_COUPON = PREFIX.concat("user_coupon:");
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
}
package com.liquidnet.service.goblin.constant;
public class GoblinStatusConst {
/* ----------------------------------------------------------------- */
public enum CommonStatus {
COMMON_LIMIT_UN(0, "不限购"),
COMMON_TYPE_ALL(0, "购买条件-全部用户"),
COMMON_TYPE_MEMBER(1, "购买条件-会员用户"),
COMMON_TYPE_CAN(2, "购买条件-指定用户"),
;
private final int value;
private final String desc;
CommonStatus(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return value;
}
public String getDesc() {
return desc;
}
}
public enum Status {
ORDER_STATUS_0(0, "待付款(用户刚下单)"),
ORDER_STATUS_2(2, "代发货(用户付完款 等待商城发货)"),
ORDER_STATUS_3(3, "代收货(商城已经发货 等待用户确认收货)"),
ORDER_STATUS_4(4, "已完成(用户已经确认收货 订单结束)"),
ORDER_STATUS_5(5, "取消订单(用户未付款前取消订单)"),
ORDER_STATUS_6(6, "退款通过(用户已经付款但是商城还未发货,用户发出退款申请,商城同意退款)"),
ORDER_STATUS_7(7, "退货通过(用户已经确认收货后用户发出退货申请,商城同意所有退货申请 ,一个订单可能有多个单品)"),
ORDER_STATUS_61(61, "发起-退款(用户已经付款但是商城还未发货,用户发出退款申请,商城同意退款)"),
ORDER_STATUS_71(71, "发起-退货(用户已经确认收货后用户发出退货申请,商城同意所有退货申请 ,一个订单可能有多个单品)"),
ORDER_LOG_STATUS_11(11, "确认付款"),
ORDER_LOG_STATUS_12(12, "修改金额"),
ORDER_LOG_STATUS_13(13, "发货"),
ORDER_LOG_STATUS_14(14, "取消订单"),
ORDER_LOG_STATUS_15(15, "修改物流单号"),
ORDER_LOG_STATUS_16(16, "核销虚拟商品订单"),
ORDER_LOG_STATUS_17(17, "修改收货地址"),
ORDER_LOG_STATUS_20(20, "商家发起退款"),
ORDER_LOG_STATUS_201(201, "商家同意退款"),
ORDER_LOG_STATUS_21(21, "退款申请"),
ORDER_LOG_STATUS_22(22, "退款成功"),
ORDER_LOG_STATUS_23(23, "退款拒绝"),
ORDER_LOG_STATUS_24(24, "退货申请"),
ORDER_LOG_STATUS_25(25, "退货拒绝"),
ORDER_LOG_STATUS_26(26, "退货审核通过等待用户填写物流"),
ORDER_LOG_STATUS_27(27, "待收货"),
ORDER_LOG_STATUS_28(28, "退货完成"),
ORDER_LOG_STATUS_29(29, "退款拒绝"),
ORDER_BACK_STATUS_0(0, "商家发起退款(退款中)"),
ORDER_BACK_STATUS_1(1, "退款申请(用户发送退款请求)"),
ORDER_BACK_STATUS_2(2, "退款成功(商家同意退款)"),
ORDER_BACK_STATUS_3(3, "退款拒绝(商家拒绝退款)"),
ORDER_BACK_STATUS_4(4, "退货申请(用户发起退货请求)"),
ORDER_BACK_STATUS_5(5, "退货拒绝(商家拒绝退货)"),
ORDER_BACK_STATUS_6(6, "退货审核通过等待用户填写物流"),
ORDER_BACK_STATUS_7(7, "待收货(退货中)"),
ORDER_BACK_STATUS_8(8, "退货完成"),
ORDER_BACK_STATUS_9(9, "退款拒绝"),
ORDER_BACK_STATUS_10(10, "退款失败"),
ORDER_BACK_STATUS_11(11, "取消退款"),
;
private final int value;
private final String desc;
Status(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return value;
}
public String getDesc() {
return desc;
}
}
public enum Type {
OPERATION_TYPE_1(1, "用户"),
OPERATION_TYPE_2(2, "商家"),
BACK_REASON_TYPE_1(1, "不想买了"),
BACK_REASON_TYPE_2(2, "收货人信息有误"),
BACK_REASON_TYPE_3(3, "未按指定时间发货"),
BACK_REASON_TYPE_4(4, "其他"),
BACK_REASON_TYPE_5(5, "不想买了"),
BACK_REASON_TYPE_6(6, "商品质量问题"),
BACK_REASON_TYPE_7(7, "收到商品与描述不符"),
BACK_REASON_TYPE_8(8, "商铺发起"),//todo
BACK_REASON_TYPE_9(9, "系统自动申请"),
BACK_TYPE_1(1, "退款"),
BACK_TYPE_2(2, "退货"),
;
private final int value;
private final String desc;
Type(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return value;
}
public String getDesc() {
return desc;
}
}
public enum MarketingStatus {
SELF_TYPE_ZHENGZAI(1, "正在下单"),
STORE_TYPE_PURCHASE(2, "限时秒杀"),
STORE_PURCHASE_STATUS_ALL(-1, "全部"),
STORE_PURCHASE_STATUS_UN_START(0, "等待开始"),
STORE_PURCHASE_STATUS_ING_START(1, "活动中"),
STORE_PURCHASE_STATUS_END_START(2, "活动结束"),
STORE_PURCHASE_STATUS_STOP(7, "停用"),
;
private final int value;
private final String desc;
MarketingStatus(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return value;
}
public String getDesc() {
return desc;
}
}
public enum MarketPreStatus {
MARKET_PRE_ZHENGZAI("ZZ", "正在下单前缀"),
MARKET_PRE_PURCHASE("PC", "限时秒杀前缀"),
;
private final String value;
private final String desc;
MarketPreStatus(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return value;
}
public String getDesc() {
return desc;
}
public static String getPre(String goblinId) {
if (goblinId.contains(MARKET_PRE_ZHENGZAI.getValue())) {
return MARKET_PRE_ZHENGZAI.getValue();
} else if (goblinId.contains(MARKET_PRE_PURCHASE.getValue())) {
return MARKET_PRE_PURCHASE.getValue();
}
return null;
}
}
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
}
package com.liquidnet.service.goblin.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ApiModel(value = "GoblinGoodsSpecDto", description = "商品SKU规格")
@Data
public class GoblinGoodsSpecDto implements Serializable, Cloneable {
private static final long serialVersionUID = 8425727558228094904L;
@ApiModelProperty(position = 11, value = "规格名称")
@NotBlank(message = "规格名称不能为空")
private String specName;
@ApiModelProperty(position = 11, value = "规格值名称")
@NotBlank(message = "规格值不能为空")
private String specVname;
private static final GoblinGoodsSpecDto obj = new GoblinGoodsSpecDto();
public static GoblinGoodsSpecDto getNew() {
try {
return (GoblinGoodsSpecDto) obj.clone();
} catch (CloneNotSupportedException e) {
return new GoblinGoodsSpecDto();
}
}
}
package com.liquidnet.service.goblin.dto.manage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
@ApiModel(value = "AddressVo")
@Data
public class AddressVo {
@ApiModelProperty(value = "收货人姓名")
private String name;
@ApiModelProperty(value = "代理id")
private String province;
@ApiModelProperty(value = "省份行政编码")
private String county;
@ApiModelProperty(value = "城市")
private String city;
@ApiModelProperty(value = "收货地址")
private String address;
@ApiModelProperty(value = "区县")
private String phone;
@ApiModelProperty(value = "区县行政编码")
private String countyId;
}
package com.liquidnet.service.goblin.dto.manage.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@ApiModel(value = "GoblinMgtCategorySpecVo", description = "分类关联的规格信息")
@Data
public class GoblinMgtCategorySpecVo implements Serializable, Cloneable {
private static final long serialVersionUID = -1807588898644126000L;
@ApiModelProperty(position = 11, value = "分类ID")
private String cateId;
@ApiModelProperty(position = 13, value = "规格名称List")
private List<String> specNameList;
public GoblinMgtCategorySpecVo setCateId(String cateId) {
this.cateId = cateId;
return this;
}
public GoblinMgtCategorySpecVo setSpecNameList(List<String> specNameList) {
this.specNameList = specNameList;
return this;
}
private static final GoblinMgtCategorySpecVo obj = new GoblinMgtCategorySpecVo();
public static GoblinMgtCategorySpecVo getNew() {
try {
return (GoblinMgtCategorySpecVo) obj.clone();
} catch (CloneNotSupportedException e) {
return new GoblinMgtCategorySpecVo();
}
}
}
package com.liquidnet.service.goblin.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.List;
@Data
@EqualsAndHashCode
public class ArDataVo implements Cloneable {
@ApiModelProperty(position = 1, value = "Spuvo")
private List<GoblinGoodsInfoVo> goodsInfoVos;
@ApiModelProperty(position = 2, value = "券vo")
private List<TempCouponVo> tempCouponVos;
private static final ArDataVo obj = new ArDataVo();
public static ArDataVo getNew() {
try {
return (ArDataVo) obj.clone();
} catch (CloneNotSupportedException e) {
return new ArDataVo();
}
}
}
package com.liquidnet.service.goblin.enums;
/**
* 店铺配置信息
*
* @author zhanggb
* Created by IntelliJ IDEA at 2022/1/12
*/
public enum GoblinStoreConf {
/**
* 状态:营业状态
* 同步`GoblinStoreInfoVo.status`
*/
BUSINESS_STATUS,
/**
* 开关:联系客服
*/
ONOFF_CUSTOMER_SEV,
/**
* 开关:售罄展示
*/
ONOFF_SOLD_OUT_SHOW,
/**
* 指标:库存不足
*/
LIMIT_WARNING_STOCK,
}
package com.liquidnet.service.goblin.param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@Api
public class BackCouponParam implements Serializable, Cloneable {
@ApiModelProperty(dataType = "String", name = "uCouponIds", value = "券唯一表示id(逗号隔开的字符串)",example = "1",required = true)
@NotNull @NotBlank
private String uCouponIds;
@ApiModelProperty(dataType = "String", name = "uid", value = "用户id",example = "10",required = true)
@NotNull @NotBlank
private String uid;
private static final BackCouponParam obj = new BackCouponParam();
public static BackCouponParam getNew() {
try {
return (BackCouponParam) obj.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return new BackCouponParam();
}
public String getuCouponIds() {
return uCouponIds;
}
public void setuCouponIds(String uCouponIds) {
this.uCouponIds = uCouponIds;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}
package com.liquidnet.service.goblin.service;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUseResultVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUserCouponVo;
import com.liquidnet.service.goblin.param.BackCouponParam;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public interface GoblinCouponService {
//根据spuId获取 该spu可参与的券活动
ArrayList<String> getSpuType(String spuId, String storeId);
//获取 类型券列表
ArrayList<GoblinStoreCouponVo> getSpuByType(String spuId, String storeId, String type);
//领取券
Boolean receiveCoupon(String uid, List<GoblinUserCouponVo> userCouponVoList, GoblinStoreCouponVo storeCouponVo);
//我的券列表 [类型 1可用 2过期/已使用]
List<GoblinUserCouponVo> getList(String type);
//是否可用券 [价格] [spuId逗号隔开] [uid]
GoblinUserCouponVo canUse(BigDecimal totalPrice, String spuId, String uid,String storeId);
//可用券列表 [价格] [spuId逗号隔开] [uid]
List<GoblinUserCouponVo> useList(BigDecimal totalPrice, String spuId, String uid);
//使用券 [券id] [消费内容] [价格] [spuId逗号隔开]
GoblinUseResultVo useCoupon(String ucouponId,String content, BigDecimal totalPrice, String spuId, String uid);
//回退券 [list<Data>] [券id , 用户id]
Boolean backCoupon(List<BackCouponParam> params);
}
package com.liquidnet.service.goblin.service.manage;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreZhengzaiCommonParam;
import com.liquidnet.service.goblin.dto.vo.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.List;
public interface IGoblinInnerService {
ResponseDto<String> insertCoupon(MultipartFile file, String performanceId);
ResponseDto<ArDataVo> getArData(String tag, String performanceId);
ResponseDto<TempCouponVo> getTempCouponData(String ucouponId);
}
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<module>liquidnet-service-slime-api</module> <module>liquidnet-service-slime-api</module>
<module>liquidnet-service-stone-api</module> <module>liquidnet-service-stone-api</module>
<module>liquidnet-service-goblin-api</module> <module>liquidnet-service-goblin-api</module>
<module>liquidnet-service-smile-api</module>
</modules> </modules>
<dependencies> <dependencies>
<dependency> <dependency>
......
server:
port: ${liquidnet.info.port}
tomcat:
uri-encoding: UTF-8
maxThreads: 2000 #默认200
minSpareThreads: 200 #默认10
maxConnections: 20000 #默认10000
acceptCount: 5000 #默认100
processorCache: -1 #默认200
servlet:
context-path: ${liquidnet.info.context}
# -----------------------------------------------------------
knife4j:
enable: true
production: ${liquidnet.knife4j.disable}
basic:
enable: true
username: ${liquidnet.security.username}
password: ${liquidnet.security.password}
# -----------------------------------------------------------
logging:
# config: ${liquidnet.logfile.config}
file:
name: ${liquidnet.logfile.path}/${liquidnet.logfile.name}.log
max-size: ${liquidnet.logfile.file-max-size}
pattern:
file: '%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %X{lnsTranceId} [%logger{56}:%line] - %msg%n'
console: '%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %X{lnsTranceId} [%logger{56}:%line] - %msg%n'
rolling-file-name: ${liquidnet.logfile.path}/${liquidnet.logfile.name}-%d{yyyy-MM-dd}.%i.log
level:
root: error
#以下是为指定包设置日志级别
com.liquidnet.service.feign: error
com.liquidnet: ${liquidnet.logfile.level}
# -----------------------------------------------------------
eureka:
# client:
# register-with-eureka: true
# fetch-registry: true
# serviceUrl:
# defaultZone: http://${liquidnet.security.username}:${liquidnet.security.password}@${liquidnet.eureka.host}/eureka-server/eureka
instance:
hostname: ${spring.cloud.client.ip-address}
lease-expiration-duration-in-seconds: 15 #服务过期时间配置,超过这个时间没有接收到心跳EurekaServer就会将这个实例剔除
lease-renewal-interval-in-seconds: 5 #服务刷新时间配置,每隔这个时间会主动心跳一次
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${spring.application.instance_id:${server.port}}
# -----------------------------------------------------------
#actuator/info
info:
app:
name: ${liquidnet.info.name}
company:
name: zhengzai.tv
build:
groupId: '@project.groupId@'
artifactId: '@project.artifactId@'
version: '@project.version@'
# -----------------------------------------------------------
mybatis-plus:
mapper-locations: classpath:com.liquidnet.service.smile.mapper/*Mapper.xml
# -----------------------------------------------------------
spring:
application:
name: ${liquidnet.info.name}
servlet:
multipart:
max-file-size: 5MB
max-request-size: 10MB
profiles:
include: common-service #这里加载management相关公共配置
autoconfigure:
exclude:
- org.springframework.cloud.bus.BusAutoConfiguration
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
redis:
database: 15
dbs: ${liquidnet.redis.smile.dbs}
port: ${liquidnet.redis.smile.port}
host: ${liquidnet.redis.smile.host}
password: ${liquidnet.redis.smile.password}
lettuce:
pool:
max-active: 16
max-wait: -1
max-idle: 8
min-idle: 4
data:
mongodb:
uri: mongodb://${liquidnet.mongodb.user}:${liquidnet.mongodb.pwd}@${liquidnet.mongodb.host}/?authSource=admin&maxPoolSize=200&waitQueueMultiple=100
sslEnabled: ${liquidnet.mongodb.sslEnabled}
database: ${liquidnet.mongodb.database}
# -----------------------------------------------------------
# -----------------------------------------------------------
global-auth:
exclude-url-pattern:
- ${liquidnet.info.context}/doc.html
- ${liquidnet.info.context}/webjars/**
- ${liquidnet.info.context}/swagger-resources/**
- ${liquidnet.info.context}/v2/api-docs*
- ${liquidnet.info.context}/inner/**
oncheck-url-pattern:
-
# -----------------------------------------------------------
# -----------------------------------------------------------
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liquidnet-service-smile</artifactId>
<groupId>com.liquidnet</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liquidnet-service-smile-impl</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-swagger</artifactId>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-goblin-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-smile-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-adam-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-service-candy-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-sms</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.liquidnet.service;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.ArrayList;
import java.util.List;
public class MybatisPlusCodeGenerator {
/**
* @param moduleRootPath 项目模块根路径 到 /src 之前 ex:E:\projects\trlabs-bus-v1\trlabs-bus-service\trlabs-common\trlabs-mybatis
* @param dsc 数据源
* @param parentName 相当于业务模块名 com.liquidnet.service.adam 全限定类名
* @param tableNames 表名
*/
public static void doGenerator(String moduleRootPath,
DataSourceConfig dsc,
String parentName,
String[] tableNames) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置BankMybatisPlusCodeGenerator
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(moduleRootPath + "/src/main/java");
gc.setAuthor("liquidnet");
gc.setOpen(false);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent(parentName);
mpg.setPackageInfo(pc);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
// 如果模板引擎是 freemarker
String templatePath = "/templates/mapper.xml.ftl";
// 自定义输出配置
List<FileOutConfig> focList = new ArrayList<>();
// 自定义配置会被优先输出
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return moduleRootPath + "/src/main/resources/com/liquidnet/service/goblin/mapper/" + pc.getModuleName()
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setInclude(tableNames);
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
public static void main(String[] args) {
DataSourceConfig dsc = new DataSourceConfig();
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUrl("jdbc:mysql://39.107.71.112:3308/dev_ln_scene?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=CST");
dsc.setUsername("testmall");
dsc.setPassword("zhengzai!mYT");
String resourcePath = "/Users/hujiachen/Downloads/tmp";
String directory = "com.liquidnet.service.goblin";
String[] dbTableArray = new String[]{
"goblin_marketing_zhengzai_relation"
};
doGenerator(resourcePath, dsc, directory, dbTableArray);
}
}
package com.liquidnet.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.core.env.Environment;
import java.net.InetAddress;
import java.util.Arrays;
@Slf4j
@EnableFeignClients
@SpringBootApplication(scanBasePackages = {"com.liquidnet"})
public class ServiceGoblinApplication implements CommandLineRunner {
@Autowired
private Environment environment;
public static void main(String[] args) {
SpringApplication.run(ServiceGoblinApplication.class, args);
}
@Override
public void run(String... strings) {
try {
log.info("\n----------------------------------------------------------\n\t" +
"Application '{}' is running! Access URLs:\n\t" +
"Local: \t\thttp://127.0.0.1:{}\n\t" +
"External: \thttp://{}:{}{}/doc.html\n\t" +
"Profile(s): \t{}\n----------------------------------------------------------",
environment.getProperty("spring.application.name"),
environment.getProperty("server.port"),
InetAddress.getLocalHost().getHostAddress(),
environment.getProperty("server.port"),
environment.getProperty("server.servlet.context-path"),
Arrays.toString(environment.getActiveProfiles()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.liquidnet.service.goblin.config;
import com.liquidnet.common.web.config.WebMvcConfig;
import com.liquidnet.common.web.filter.GlobalAuthorityInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@Configuration
public class GoblinWebMvcConfig extends WebMvcConfig {
@Autowired
public GlobalAuthorityInterceptor globalAuthorityInterceptor;
@Override
protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(this.globalAuthorityInterceptor).addPathPatterns("/**");
super.addInterceptors(registry);
}
}
package com.liquidnet.service.goblin.controller;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.IGoblinAppZhengzaiService;
import com.liquidnet.service.goblin.service.IGoblinOrderAppService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
@Slf4j
@Api(tags = "正在下单相关")
@RestController
@RequestMapping("/zhengzai/app")
public class GoblinAppZhengzaiController {
@Autowired
IGoblinAppZhengzaiService goblinAppZhengzaiService;
// @Autowired
// IGoblinOrderService goblinOrderService;
@Autowired
IGoblinOrderAppService goblinOrderAppService;
@GetMapping("market/list")
@ApiOperation("正在下单-活动列表")
public ResponseDto<List<GoblinSelfMarketingVo>> getZhengzaiMarketList() {
return ResponseDto.success(goblinAppZhengzaiService.getZhengzaiMarketList());
}
@GetMapping("store/list")
@ApiOperation("正在下单-参与活动的店铺")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
})
public ResponseDto<List<GoblinShowStoreInfoVo>> getStoreList(@RequestParam("marketId") @Valid String marketId) {
return ResponseDto.success(goblinAppZhengzaiService.getStoreList(marketId));
}
@GetMapping("spu/list")
@ApiOperation("正在下单-参与活动的spu")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
})
public ResponseDto<List<GoblinZhengzaiGoodVo>> getStoreList(@RequestParam("marketId") @Valid String marketId,
@RequestParam("storeId") @Valid String storeId) {
return ResponseDto.success(goblinAppZhengzaiService.getSpuList(marketId, storeId));
}
@PostMapping("listByCode")
@ApiOperation("列表[根据masterCode]")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderMasterCode", value = "主订单号"),
})
public ResponseDto<List<GoblinAppOrderListVo>> orderListByMaster(@RequestParam("orderMasterCode") @Valid String orderMasterCode) {
return goblinOrderAppService.orderListByMaster(orderMasterCode);
}
@PostMapping("details")
@ApiOperation("详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id", example = "1"),
})
public ResponseDto<GoblinAppOrderDetailsVo> orderDetails(@RequestParam("orderId") @Valid String orderId) {
String uid = CurrentUtil.getCurrentUid();
return goblinOrderAppService.orderDetails(orderId, uid);
}
@PostMapping("orderPush")
@ApiOperation("正在下单-出货")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "offCode", value = "取货码", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
})
public ResponseDto<Boolean> orderPush(@RequestParam("offCode") @Valid String offCode,
@RequestParam("marketId") @Valid String marketId) {
return goblinAppZhengzaiService.orderPush(offCode, "ZZ" +marketId);
}
@PostMapping("orderPushDetails")
@ApiOperation("正在下单-出货详情")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "offCode", value = "取货码", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
})
public ResponseDto<List<GoblinZhengzaiPushVo>> orderPushDetails(@RequestParam("offCode") @Valid String offCode,
@RequestParam("marketId") @Valid String marketId) {
return goblinAppZhengzaiService.orderPushDetails(offCode, "ZZ" + marketId);
}
@PostMapping("orderBind")
@ApiOperation("正在下单-绑定订单号")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "masterCode", value = "masterCode", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "uid", example = "1"),
})
public ResponseDto<Boolean> orderBind(@RequestParam("masterCode") @Valid String masterCode,
@RequestParam("uid") @Valid String uid) {
return goblinAppZhengzaiService.orderBind(uid, masterCode);
}
@PostMapping("mailData")
@ApiOperation("快递详情")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "orderId", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "mailId", value = "mailId", example = "1"),
})
public ResponseDto<List<GoblinMailVo>> getMail(@RequestParam("orderId") @Valid String orderId,
@RequestParam("mailId") @Valid String mailId) {
return goblinOrderAppService.getMail(orderId, mailId);
}
}
package com.liquidnet.service.goblin.controller;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUseResultVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUserCouponVo;
import com.liquidnet.service.goblin.param.BackCouponParam;
import com.liquidnet.service.goblin.service.GoblinCouponService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Slf4j
@Api(tags = "店铺券")
@RestController
@RequestMapping("/store/coupon")
public class GoblinCouponController {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinCouponService goblinCouponService;
@PostMapping("type")
@ApiOperation("商品可参与券类型")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺id"),
})
public ResponseDto<ArrayList<String>> getSpuType(@RequestParam("spuId") @Valid String spuId,
@RequestParam("storeId") @Valid String storeId) {
return ResponseDto.success(goblinCouponService.getSpuType(spuId, storeId));
}
@PostMapping("type/list")
@ApiOperation("券列表[根据类型]")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "type", value = "券类型[0-全部|1-代金券|2-折扣券|3-满减券]"),
})
public ResponseDto<ArrayList<GoblinStoreCouponVo>> getSpuByType(@RequestParam("spuId") @Valid String spuId,
@RequestParam("storeId") @Valid String storeId,
@RequestParam("type") @Valid String type) {
ArrayList<GoblinStoreCouponVo> storeCouponVos = goblinCouponService.getSpuByType(spuId, storeId, type);
if (!CollectionUtils.isEmpty(storeCouponVos)) {
String currentUid = CurrentUtil.getCurrentUid();
if (StringUtils.isNotEmpty(currentUid)) {
List<GoblinUserCouponVo> userCouponVos = goblinRedisUtils.getUserCouponVos(currentUid);
if (!CollectionUtils.isEmpty(userCouponVos))
for (GoblinStoreCouponVo storeCouponVo : storeCouponVos)
for (GoblinUserCouponVo userCouponVo : userCouponVos)
if (storeCouponVo.getStoreCouponId().equals(userCouponVo.getStoreCouponId())) {
storeCouponVo.setReceiveCount(storeCouponVo.getReceiveCount() + 1);
break;
}
}
}
return ResponseDto.success(storeCouponVos);
}
@PostMapping("receive")
@ApiOperation("领取券")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeCouponId", value = "平台券ID"),
// @ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "number", value = "数量"),
})
public ResponseDto<Boolean> receive(@NotBlank(message = "平台券ID不能为空") @RequestParam("storeCouponId") String storeCouponId) {
// public ResponseDto<Boolean> checkOrderResult(@RequestParam("storeCouponId") @Valid String storeCouponId,
// @RequestParam("number") @Valid Integer number) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreCouponVo storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null == storeCouponVo) {
log.warn("商城:用户领取优惠券:优惠券不存在:[uid={},storeCouponId={}]", uid, storeCouponId);
return ResponseDto.failure(ErrorMapping.get("140050"));
}
if (!storeCouponVo.getState().equals("1")) {
return ResponseDto.failure(ErrorMapping.get("140051"));
}
List<GoblinUserCouponVo> userCouponVos = goblinRedisUtils.getUserCouponVos(uid);
if (!CollectionUtils.isEmpty(userCouponVos)) {
ArrayList<GoblinUserCouponVo> userCouponVosTmp = ObjectUtil.getGoblinUserCouponVo();
userCouponVosTmp.addAll(userCouponVos);
userCouponVosTmp.removeIf(vo -> vo.getStoreCouponId().equals(storeCouponId));
if ((userCouponVos.size() - userCouponVosTmp.size()) >= storeCouponVo.getReceiveLimit()) {
return ResponseDto.failure(ErrorMapping.get("140052"));
}
}
if (storeCouponVo.getStock().equals(0) || goblinRedisUtils.getStoreCouponStock(storeCouponId) > 0) {
Boolean resultFlg = goblinCouponService.receiveCoupon(uid, userCouponVos, storeCouponVo);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
return ResponseDto.failure(ErrorMapping.get("140053"));
}
@PostMapping("fetched")
@ApiOperation(value = "POS机代领券", notes = "返回当前领取的可用券信息")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeCouponId", value = "平台券ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "UID"),
})
public ResponseDto<GoblinUserCouponVo> fetched(@NotBlank(message = "店铺ID不能为空") @RequestParam("storeId") String storeId,
@NotBlank(message = "平台券ID不能为空") @RequestParam("storeCouponId") String storeCouponId,
@NotBlank(message = "UID不能为空") @RequestParam("uid") String uid) {
// if (!goblinRedisUtils.hasStoreId(CurrentUtil.getCurrentUid(), storeId)) {
// return ResponseDto.failure(ErrorMapping.get("149002"));
// }
// TODO: 2022/3/5 ==zhanggb.UID校验真实性
GoblinStoreCouponVo storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null == storeCouponVo) {
log.warn("商城:用户领取优惠券:优惠券不存在:[uid={},storeCouponId={}]", uid, storeCouponId);
return ResponseDto.failure(ErrorMapping.get("140050"));
}
if (null != storeId && !storeId.equals(storeCouponVo.getStoreId())) {
log.warn("商城:POS机代领优惠券:非法请求,非本店铺优惠券:[uid={},storeCouponId={}]", uid, storeCouponId);
return ResponseDto.failure(ErrorMapping.get("140050"));
}
if (!storeCouponVo.getState().equals("1")) {
return ResponseDto.failure(ErrorMapping.get("140051"));
}
List<GoblinUserCouponVo> userCouponVos = goblinRedisUtils.getUserCouponVos(uid);
if (!CollectionUtils.isEmpty(userCouponVos)) {
List<GoblinUserCouponVo> userCouponVoList = userCouponVos.stream().filter(vo -> vo.getStoreCouponId().equals(storeCouponId)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(userCouponVoList) && userCouponVoList.size() >= storeCouponVo.getReceiveLimit()) {
Optional<GoblinUserCouponVo> userCouponVoOptional = userCouponVoList.stream().filter(vo -> vo.getState().equals(1)).findAny();
return userCouponVoOptional.map(ResponseDto::success).orElseGet(() -> ResponseDto.failure(ErrorMapping.get("140054")));
}
}
if (storeCouponVo.getStock().equals(0) || goblinRedisUtils.getStoreCouponStock(storeCouponId) > 0) {
if (goblinCouponService.receiveCoupon(uid, userCouponVos, storeCouponVo)) {
List<GoblinUserCouponVo> userCouponVoList = userCouponVos.stream()
.filter(vo -> vo.getStoreCouponId().equals(storeCouponId) && vo.getState().equals(1)).collect(Collectors.toList());
return ResponseDto.success(userCouponVoList.get(0));
}
return ResponseDto.failure(ErrorMapping.get("140053"));
}
return ResponseDto.failure(ErrorMapping.get("140053"));
}
@PostMapping("my/list")
@ApiOperation("我的券券列表[根据类型]")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "type", value = "类型 1可用 2过期/已使用"),
})
public ResponseDto<List<GoblinUserCouponVo>> getList(@RequestParam("type") @Valid String type) {
return ResponseDto.success(goblinCouponService.getList(type));
}
@PostMapping("can/use")
@ApiOperation("是否可用券[计算价格最高并返回vo]")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Number", name = "totalPrice", value = "spuId"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "逗号隔开"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "用户id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺id"),
})
public ResponseDto<GoblinUserCouponVo> canUse(@RequestParam("totalPrice") @Valid BigDecimal totalPrice,
@RequestParam("spuId") @Valid String spuId,
@RequestParam("storeId") @Valid String storeId,
@RequestParam(value = "uid", required = false) @Valid String uid) {
if (uid == null) {
uid = CurrentUtil.getCurrentUid();
}
return ResponseDto.success(goblinCouponService.canUse(totalPrice, spuId, uid,storeId));
}
@PostMapping("useList")
@ApiOperation("可用券列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Number", name = "totalPrice", value = "应付价格"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "逗号隔开"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "uid", value = "用户id")
})
public ResponseDto<List<GoblinUserCouponVo>> useList(@RequestParam("totalPrice") @Valid BigDecimal totalPrice,
@RequestParam("spuId") @Valid String spuId,
@RequestParam(value = "uid", required = false) String uid) {
if (uid == null) {
uid = CurrentUtil.getCurrentUid();
}
return ResponseDto.success(goblinCouponService.useList(totalPrice, spuId, uid));
}
@PostMapping("useCoupon")
@ApiOperation("用券")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "ucouponId", value = "券id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "content", value = "消费内容"),
@ApiImplicitParam(type = "form", required = true, dataType = "Number", name = "totalPrice", value = "总价格"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId逗号隔开"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "uid"),
})
public ResponseDto<GoblinUseResultVo> checkOrderResult(@RequestParam("ucouponId") @Valid String ucouponId,
@RequestParam("content") @Valid String content,
@RequestParam("totalPrice") @Valid BigDecimal totalPrice,
@RequestParam("spuId") @Valid String spuId,
@RequestParam("uid") @Valid String uid) {
return ResponseDto.success(goblinCouponService.useCoupon(ucouponId, content, totalPrice, spuId, uid));
}
@PostMapping("backCoupon")
@ApiOperation("退券")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<Boolean> checkOrderResult(@RequestBody @Valid List<BackCouponParam> backCouponParam) {
if (backCouponParam.size() > 100) {
return ResponseDto.failure("数据量不得大于100");
}
return ResponseDto.success(goblinCouponService.backCoupon(backCouponParam));
}
}
package com.liquidnet.service.goblin.controller;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinFrontHotWord;
import com.liquidnet.service.goblin.service.GoblinFrontService;
import com.liquidnet.service.goblin.service.impl.GoblinFrontServiceImpl;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
* @author zhangfuxin
* @Description:前端接口
* @date 2021/12/27 下午6:25
*/
@Api(tags = "前端接口管理")
@RestController
@RequestMapping("/front")
public class GoblinFrontController {
@Autowired
private RedisUtil redisUtil;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinFrontServiceImpl goblinFrontService;
@GetMapping("getTopBanner")
@ApiOperation("获取顶部banner")
public ResponseDto<ArrayList<GoblinFrontBannerVo>> getBanner() {
return ResponseDto.success(goblinFrontService.getListBanner());
}
@GetMapping("getMiddleBanner")
@ApiOperation("获取中部banner")
public ResponseDto<ArrayList<GoblinFrontBannerVo>> getMiddleBanner() {
return ResponseDto.success(goblinFrontService.getMiddleBanner());
}
@GetMapping("getHotWord")
@ApiOperation("获得热词")
public ResponseDto<GoblinFrontHotWord> getHotWord() {
return ResponseDto.success(goblinFrontService.getHotWord());
}
@GetMapping("getNavigation")
@ApiOperation("获得金刚栏")
public ResponseDto<GoblinFrontNavigationVoo> getNavigation() {
return ResponseDto.success(goblinFrontService.getNavigation());
}
@GetMapping("getSeckilll")
@ApiOperation("获得秒杀首页要用的")
public ResponseDto<GoblinFrontSeckillVo> getSeckilll() throws ParseException {
return ResponseDto.success(goblinFrontService.getSeckilll());
}
@GetMapping("getSelectGoods")
@ApiOperation("获得精选商品列表(pageNumber从0开始)")
public ResponseDto<GoblinFrontSelectGoodVo> getSelectGoods(@RequestParam(name = "pageSize", required = true) int pageSize, @RequestParam(name = "pageNumber", required = true) int pageNumber) throws ParseException {
return ResponseDto.success(goblinFrontService.getSelectGoods(pageNumber, pageSize));
}
@GetMapping("getGoodsDetail")
@ApiOperation("获得商品详情")
public ResponseDto<GoblinFrontGoodDetailVo> getGoodsDetail(@RequestParam(name = "spuId", required = true) String spuId) throws ParseException {
return ResponseDto.success(goblinFrontService.getGoodsDetail(spuId));
}
@GetMapping("getMoudleIndex")
@ApiOperation("获取组件排序")
public ResponseDto getMoudleIndex() throws ParseException {
return ResponseDto.success(goblinFrontService.getMoudleIndex());
}
@GetMapping("getCube")
@ApiOperation("获取魔方")
public ResponseDto<GoblinFrontCubeVo> getCube() throws ParseException {
return ResponseDto.success(goblinFrontService.getCube());
}
@GetMapping("getRecommend")
@ApiOperation("获取新品推荐")
public ResponseDto<GoblinFrontCubeVo> getRecommend() throws ParseException {
return ResponseDto.success(goblinFrontService.getRecommend());
}
@GetMapping("getCategoryList")
@ApiOperation("获取分类列表商品( 1、销量优先、2、新品优先、3、价格降序、4、价格升序)")
public ResponseDto<GoblinFrontCategoryListVo> getCategoryList(@RequestParam(name = "type", required = true) String type, @RequestParam(name = "categoryId", required = true) String categoryId, @RequestParam(name = "page", required = true) int page, @RequestParam(name = "pageSize", required = true) int pageSize) throws ParseException {
return ResponseDto.success(goblinFrontService.getCategoryList(type, categoryId, page, pageSize));
}
@GetMapping("getMusicList")
@ApiOperation("获取音乐标签列表( 1、销量优先、2、新品优先、3、价格降序、4、价格升序)")
public ResponseDto<GoblinFrontCategoryListVo> getMusicList(@RequestParam(name = "type", required = true) String type, @RequestParam(name = "musicId", required = true) String musicId, @RequestParam(name = "page", required = true) int page, @RequestParam(name = "pageSize", required = true) int pageSize) throws ParseException {
return ResponseDto.success(goblinFrontService.getMusic(musicId, type, page, pageSize));
}
@GetMapping("getCategory")
@ApiOperation("获取分类子集")
public ResponseDto<GoblinCategoryzfVo> getCategory(@RequestParam(name = "categoryId", required = true) String categoryId) throws ParseException {
return ResponseDto.success(goblinFrontService.getCategory(categoryId));
}
@GetMapping("getStore")
@ApiOperation("获得店铺详情")
public ResponseDto<GoblinStoreInfoVo> getStore(@RequestParam(name = "storeId", required = true) String storeId) throws ParseException {
return ResponseDto.success(goblinFrontService.getStore(storeId));
}
@GetMapping("getStoreCategory")
@ApiOperation("获得店铺分类")
public ResponseDto<List<GoblinStoreGoodsCategoryVo>> getStoreCategory(@RequestParam(name = "storeId", required = true) String storeId) throws ParseException {
return ResponseDto.success(goblinFrontService.getStoreCategory(storeId));
}
@GetMapping("getStoreGoodes")
@ApiOperation("获得店铺商品")
public ResponseDto<GoblinFrontCategoryListVo> getStoreGoodes(@RequestParam(name = "storeId", required = true) String storeId, @RequestParam(name = "categoryId", required = false) String categoryId, @RequestParam(name = "name", required = false) String name) throws ParseException {
return ResponseDto.success(goblinFrontService.getStoreGoodes(storeId, categoryId, name));
}
@GetMapping("searchGoodesName")
@ApiOperation("搜索商品名字、或商铺名字")
public ResponseDto<List<GoblinGoodsInfoListVo>> searchGoodesName(@RequestParam(name = "name", required = true) String name) throws ParseException {
if (StringUtil.isNotBlank(name)) {
return ResponseDto.success(goblinFrontService.searchGoodesName(name));
}
return ResponseDto.success(null);
}
@GetMapping("tagPerformance")
@ApiOperation("标签,演出id获取演出列表")
public ResponseDto<List<GoblinGoodsInfoVo>> getGoodByMusicTagP(@RequestParam(name = "musicTag", required = true) String musicTag,
@RequestParam(name = "performanceId", required = true) String performanceId) {
return ResponseDto.success(goblinFrontService.getGoodByMusicTagP(musicTag, performanceId));
}
}
package com.liquidnet.service.goblin.controller;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.GoblinShoppingCartVoo;
import com.liquidnet.service.goblin.service.impl.GoblinFrontServiceImpl;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author zhangfuxin
* @Description:前端接口
* @date 2021/12/27 下午6:25
*/
@Api(tags = "前端需要登陆接口管理")
@RestController
@RequestMapping("/frontLogin")
public class GoblinFrontLoginController {
@Autowired
private RedisUtil redisUtil;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinFrontServiceImpl goblinFrontService;
@GetMapping("addShopCart")
@ApiOperation("加入购物车")
public ResponseDto addShopCart(@RequestParam(name = "spuId", required = true) String spuId, @RequestParam(name = "storeId", required = true) String storeId, @RequestParam(name = "skuId", required = true) String skuId, @RequestParam(name = "number", required = false) Integer number, @RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return goblinFrontService.addShoopCart(spuId, storeId, skuId, number, userId, type);
}
@GetMapping("updateShopCart")
@ApiOperation("修改购物车")
public ResponseDto updateShopCart(@RequestParam(name = "spuId", required = true) String spuId, @RequestParam(name = "storeId", required = true) String storeId, @RequestParam(name = "skuId", required = true) String skuId, @RequestParam(name = "number", required = false) Integer number, @RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return ResponseDto.success(goblinFrontService.updateShopCart(spuId, storeId, skuId, number, userId, type));
}
@GetMapping("getShopCartCount")
@ApiOperation("获取购物车数量")
public ResponseDto getShopCartCount(@RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return ResponseDto.success(goblinFrontService.getShopCartCount(userId, type));
}
@PostMapping("deleteShopCart")
@ApiOperation("删除购物车")
public ResponseDto deleteShopCart(@RequestParam(name = "skuIds", required = false) String skuIds, @RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return ResponseDto.success(goblinFrontService.delteShoppingCart(skuIds.split(","), userId, type));
}
@PostMapping("saveData")
@ApiOperation("保存数据购物车过度")
public ResponseDto saveData(@RequestParam(name = "data", required = false) String data, @RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return ResponseDto.success(goblinFrontService.saveDate(data, userId, type));
}
@PostMapping("getData")
@ApiOperation("获得购物车过度")
public ResponseDto getData(@RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return goblinFrontService.getDate(userId, type);
}
@GetMapping("getShopCart")
@ApiOperation("获得购物车列表")
public ResponseDto<GoblinShoppingCartVoo> getShopCart(@RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
return ResponseDto.success(goblinFrontService.getShoppCart(userId, type));
}
@GetMapping("deleteShopCartTest")
@ApiOperation("请勿调用,测试用")
public ResponseDto<GoblinShoppingCartVoo> deleteShopCart(@RequestParam(name = "type", required = true) String type) {
String userId = CurrentUtil.getCurrentUid();
String pre = GoblinStatusConst.MarketPreStatus.getPre(type);
if (pre != null) {
type = type.split(pre)[0];
}
redisUtil.del(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type));
return ResponseDto.success(null);
}
}
package com.liquidnet.service.goblin.controller;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.codec.vo.EncryptedReq;
import com.liquidnet.service.goblin.dto.manage.GoblinOrderParam;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.param.GoblinAppOrderRefundParam;
import com.liquidnet.service.goblin.param.PayAgainParam;
import com.liquidnet.service.goblin.param.SyncOrderParam;
import com.liquidnet.service.goblin.service.IGoblinOrderAppService;
import com.liquidnet.service.goblin.service.IGoblinOrderService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
@Slf4j
@Api(tags = "订单相关-App")
@RestController
@RequestMapping("/order")
public class GoblinOrderAppController {
@Autowired
IGoblinOrderAppService goblinOrderAppService;
@PostMapping("list")
@ApiOperation("列表")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数", example = "1"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "pre", value = "活动前缀[ZZ-正在下单|不传为普通订单]", example = "ZZ"),
})
public ResponseDto<PageInfo<GoblinAppOrderListVo>> orderList(@RequestParam("page") @Valid int page,
@RequestParam(value = "pre", required = false) String pre) {
return goblinOrderAppService.orderList(page, pre);
}
@PostMapping("listByCode")
@ApiOperation("列表[根据masterCode]")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderMasterCode", value = "主订单号"),
})
public ResponseDto<List<GoblinAppOrderListVo>> orderListByMaster(@RequestParam("orderMasterCode") @Valid String orderMasterCode) {
return goblinOrderAppService.orderListByMaster(orderMasterCode);
}
@PostMapping("details")
@ApiOperation("详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id", example = "1"),
})
public ResponseDto<GoblinAppOrderDetailsVo> orderDetails(@RequestParam("orderId") @Valid String orderId) {
String uid = CurrentUtil.getCurrentUid();
return goblinOrderAppService.orderDetails(orderId, uid);
}
@PostMapping("getProduce")
@ApiOperation("已收货")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id", example = "1"),
})
public ResponseDto<Boolean> getProduce(@RequestParam("orderId") @Valid String orderId) {
String uid = CurrentUtil.getCurrentUid();
return goblinOrderAppService.getProduce(orderId, uid);
}
@PostMapping("applyRefund")
@ApiOperation("退款申请")
public ResponseDto<Boolean> applyRefund(@RequestBody GoblinAppOrderRefundParam param) {
return goblinOrderAppService.applyRefund(param);
}
@PostMapping("againRefund")
@ApiOperation("再次退款申请")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderBackId", value = "退款订单id", example = "1"),
})
public ResponseDto<Boolean> againRefund(@RequestBody GoblinAppOrderRefundParam param) {
return goblinOrderAppService.againRefund(param);
}
@PostMapping("refundDetails")
@ApiOperation("退款详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id", example = "1"),
})
public ResponseDto<List<GoblinBackOrderVo>> refundDetails(@RequestParam("orderId") @Valid String orderId) {
return goblinOrderAppService.refundDetails(orderId);
}
@PostMapping("mailData")
@ApiOperation("快递详情")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "orderId", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "mailId", value = "mailId", example = "1"),
})
public ResponseDto<List<GoblinMailVo>> getMail(@RequestParam("orderId") @Valid String orderId,
@RequestParam("mailId") @Valid String mailId) {
return goblinOrderAppService.getMail(orderId, mailId);
}
}
package com.liquidnet.service.goblin.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.GoblinCouponService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotBlank;
import java.util.List;
@ApiSupport(order = 145001)
@Api(tags = "商城:POS机相关")
@Slf4j
@RestController
@RequestMapping("store/pos")
public class GoblinPosController {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinCouponService goblinCouponService;
@PostMapping("coupon/receive")
@ApiOperation("领券")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeCouponId", value = "平台券id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "UID"),
})
public ResponseDto<GoblinUserCouponVo> checkOrderResult(@NotBlank(message = "参数无效:storeCouponId") @RequestParam("storeCouponId") String storeCouponId,
@NotBlank(message = "参数无效:uid") @RequestParam("uid") String uid) {
String currentUid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(currentUid);
GoblinStoreCouponVo storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null == storeCouponVo) {
log.warn("商城:POS机相关:领取券:优惠券不存在:[uid={},storeCouponId={}]", uid, storeCouponId);
return ResponseDto.failure(ErrorMapping.get("140050"));
} else if (null == storeInfoVo) {
log.warn("商城:POS机相关:领取券:未创建店铺不可领取优惠券:[uid={},storeCouponId={}]", uid, storeCouponId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "店铺不存在");
} else if (!storeCouponVo.getStoreId().equals(storeInfoVo.getStoreId())) {
log.warn("商城:POS机相关:领取券:非本店铺优惠券不可领取:[uid={},storeId={},storeCouponId={}]", uid, storeInfoVo.getStoreId(), storeCouponId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺优惠券不可领取");
} else if (!storeCouponVo.getState().equals("1")) {
return ResponseDto.failure(ErrorMapping.get("140051"));
}
// TODO: 2022/2/24 zhanggb==暂不进行UID真实校验
List<GoblinUserCouponVo> userCouponVos = goblinRedisUtils.getUserCouponVos(uid);
if (!CollectionUtils.isEmpty(userCouponVos)) {
int beforeSize = userCouponVos.size();
userCouponVos.removeIf(vo -> vo.getStoreCouponId().equals(storeCouponId));
if ((beforeSize - userCouponVos.size()) >= storeCouponVo.getReceiveLimit()) {
return ResponseDto.failure(ErrorMapping.get("140052"));
}
}
if (storeCouponVo.getStock().equals(0) || goblinRedisUtils.getStoreCouponStock(storeCouponId) > 0) {
Boolean resultFlg = goblinCouponService.receiveCoupon(uid, userCouponVos, storeCouponVo);
return resultFlg ? ResponseDto.success(userCouponVos.stream().filter(r -> r.getStoreCouponId().equals(storeCouponId)).findFirst().get()) : ResponseDto.failure();
}
return ResponseDto.failure(ErrorMapping.get("140053"));
}
@ApiOperationSupport(order = 1)
@ApiOperation(value = "商品信息")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "skuids", value = "多个skuId以,分隔"),
})
@PostMapping("goods/skuinfo")
public ResponseDto<List<GoblinPosGoodsVo>> skuInfoList(@NotBlank(message = "参数无效:skuIds") @RequestBody String skuids) {
log.info("商城:POS机相关:SKU列表[skuIds={}]", skuids);
String currentUid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(currentUid);
if (null == storeInfoVo) {
log.warn("商城:POS机相关:SKU明细:店铺不存在[uid={},skuIds={}]", currentUid, skuids);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "店铺不存在");
}
String storeId = storeInfoVo.getStoreId();
String[] skuIdArr = skuids.split(",");
List<GoblinPosGoodsVo> posGoodsVoList = ObjectUtil.getGoblinPosGoodsVoArrayList();
for (String skuId : skuIdArr) {
GoblinGoodsSkuInfoVo goodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null != goodsSkuInfoVo && goodsSkuInfoVo.getDelFlg().equals("0") && storeId.equals(goodsSkuInfoVo.getStoreId())) {
String spuId = goodsSkuInfoVo.getSpuId();
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null != goodsInfoVo && goodsInfoVo.getDelFlg().equals("0")) {
GoblinPosGoodsVo posGoodsVo = GoblinPosGoodsVo.getNew();
posGoodsVo.setSkuId(skuId);
posGoodsVo.setName(goodsSkuInfoVo.getName());
posGoodsVo.setPrice(goodsSkuInfoVo.getPrice());
posGoodsVo.setSpuId(spuId);
posGoodsVo.setSpuName(goodsInfoVo.getName());
posGoodsVoList.add(posGoodsVo);
}
}
}
return ResponseDto.success(posGoodsVoList);
}
}
package com.liquidnet.service.goblin.controller;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinOrderParam;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.IGoblinOrderAppService;
import com.liquidnet.service.goblin.service.IGoblinStoreZhengzaiService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
@Slf4j
@Api(tags = "正在下单相关-商铺")
@RestController
@RequestMapping("/zhengzai/store")
public class GoblinStoreZhengzaiController {
@Autowired
IGoblinStoreZhengzaiService goblinStoreZhengzaiService;
// @Autowired
// IGoblinOrderService goblinOrderService;
@Autowired
IGoblinOrderAppService goblinOrderAppService;
@GetMapping("market/list")
@ApiOperation("正在下单-活动列表")
public ResponseDto<List<GoblinSelfMarketingVo>> getZhengzaiMarketList() {
return goblinStoreZhengzaiService.getZhengzaiMarketList();
}
@GetMapping("spu/list")
@ApiOperation("正在下单-参与活动的spu")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
})
public ResponseDto<List<GoblinZhengzaiGoodVo>> getStoreList(@RequestParam("marketId") @Valid String marketId) {
return goblinStoreZhengzaiService.getSpuList(marketId);
}
@PostMapping("list")
@ApiOperation("订单列表[商铺]")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数", example = "1"),
})
public ResponseDto<List<GoblinAppOrderListVo>> orderList(@RequestParam("page") @Valid int page) {
return goblinStoreZhengzaiService.orderList(page);
}
@PostMapping("orderPush")
@ApiOperation("正在下单-出货")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderMasterCode", value = "主订单号"),
})
public ResponseDto<Boolean> orderPush(@RequestParam("orderMasterCode") @Valid String orderMasterCode) {
return goblinStoreZhengzaiService.orderPush(orderMasterCode);
}
@PostMapping("listByCode")
@ApiOperation("列表[根据masterCode]")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderMasterCode", value = "主订单号"),
})
public ResponseDto<List<GoblinAppOrderListVo>> orderListByMaster(@RequestParam("orderMasterCode") @Valid String orderMasterCode) {
return goblinOrderAppService.orderListByMaster(orderMasterCode);
}
@PostMapping("details")
@ApiOperation("订单详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id", example = "1"),
})
public ResponseDto<GoblinAppOrderDetailsVo> orderDetails(@RequestParam("orderId") @Valid String orderId) {
return goblinOrderAppService.orderDetails(orderId, null);
}
@PostMapping("paySuccess")
@ApiOperation("汇付支付成功回调")
@ResponseBody
public String refundDetails(HttpServletRequest request) {
return goblinOrderAppService.huiFuSync(request);
}
}
package com.liquidnet.service.goblin.controller.Inner;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreZhengzaiCommonParam;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.manage.IGoblinInnerService;
import com.liquidnet.service.goblin.service.manage.IGoblinZhengzaiService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
/**
* 正在下单活动管理
*/
@Slf4j
@RestController
@Api(tags = "活动-内部接口调用")
@RequestMapping("inner")
public class GoblinInnerZhengzaiController {
@Autowired
IGoblinZhengzaiService goblinZhengzaiService;
@Autowired
IGoblinInnerService goblinInnerService;
@PostMapping("config/del/noAuth")
@ApiOperation("活动详情-正在下单-删除商铺spu")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1"),
})
public ResponseDto<Boolean> zhengzaiStoreDelNoAuth(@RequestParam("storeId") @Valid String storeId,
@RequestParam("selfMarketId") @Valid String selfMarketId,
@RequestParam("spuId") @Valid String spuId) {
return goblinZhengzaiService.zhengzaiSpuDel(selfMarketId, storeId, spuId);
}
@GetMapping("config/spu")
@ApiOperation("活动详情-正在下单-获取商铺spu")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数", example = "1")
})
public ResponseDto<PageInfo<GoblinMarketSpuListVo>> zhengzaiStoreConfigSpuList(@RequestParam("storeId") @Valid String storeId,
@RequestParam("selfMarketId") @Valid String selfMarketId,
@RequestParam("page") @Valid int page) {
return goblinZhengzaiService.zhengzaiSpuList(selfMarketId, storeId, page);
}
@GetMapping("config/sku")
@ApiOperation("活动详情-正在下单-获取商铺sku")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1")
})
public ResponseDto<List<GoblinSelfZhengzaiSkuVo>> zhengzaiStoreConfigSkuList(@RequestParam("storeId") @Valid String storeId,
@RequestParam("spuId") @Valid String spuId,
@RequestParam("selfMarketId") @Valid String selfMarketId) {
return goblinZhengzaiService.zhengzaiSkuList(selfMarketId, storeId, spuId);
}
@PostMapping("add/temp/coupon")
@ApiOperation("添加活动临时券")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", dataType = "File", name = "file", value = "文件", required = true),
@ApiImplicitParam(type = "form", dataType = "String", name = "performanceId", value = "演出id", required = true),
})
public ResponseDto<String> insertCoupon(@RequestParam("file") MultipartFile file,
@RequestParam("performanceId") String performanceId) {
return goblinInnerService.insertCoupon(file, performanceId);
}
@PostMapping("ar/data")
@ApiOperation("获取ar相关离线数据")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", dataType = "String", name = "tag", value = "标签", required = true),
@ApiImplicitParam(type = "form", dataType = "String", name = "performanceId", value = "演出id", required = true),
})
public ResponseDto<ArDataVo> getArData(@RequestParam("tag") String tag,
@RequestParam("performanceId") String performanceId) {
return goblinInnerService.getArData(tag, performanceId);
}
@PostMapping("temp/coupon/data")
@ApiOperation("获取临时券数据")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", dataType = "String", name = "ucouponId", value = "券id", required = true),
})
public ResponseDto<TempCouponVo> getArData(@RequestParam("ucouponId") String ucouponId) {
return goblinInnerService.getTempCouponData(ucouponId);
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinBackOrderDetailsVo;
import com.liquidnet.service.goblin.dto.vo.GoblinBackOrderVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreBackOrderListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreOrderListVo;
import com.liquidnet.service.goblin.param.RefundCallbackParam;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreBackOrderService;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.math.BigDecimal;
@ApiSupport(order = 149101)
@Api(tags = "店铺-退款订单")
@Slf4j
@Validated
@RestController
@RequestMapping("store/orderBack")
public class GoblinStoreBackOrderController {
@Autowired
IGoblinStoreBackOrderService goblinStoreBackOrderService;
@ApiOperation(value = "订单列表")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderBackCode", value = "订单退款编号"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "type", value = "退款类型[1-退款|2-退货|3-退款退货]"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "cst", value = "申请起始时间"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "cet", value = "申请终止时间"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderCode", value = "订单编号"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "spuName", value = "商品名称"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "status", value = "订单状态[1-待处理|2-已退款|9-已拒绝|11-已取消|0-退款中|7-退货中]"),
})
@GetMapping(value = "list")
public ResponseDto<PageInfo<GoblinStoreBackOrderListVo>> orderBackList(@RequestParam(value = "page", required = true) @Valid Integer page,
@RequestParam(value = "orderBackCode", required = false) String orderBackCode,
@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "cst", required = false) String cst,
@RequestParam(value = "cet", required = false) String cet,
@RequestParam(value = "orderCode", required = false) String orderCode,
@RequestParam(value = "spuName", required = false) String spuName,
@RequestParam(value = "status", required = false) Integer status) {
return goblinStoreBackOrderService.orderBackList(page, orderBackCode, type, cst, cet, orderCode, spuName, status);
}
@ApiOperation(value = "退款订单详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "backOrderId", value = "订单id"),
})
@GetMapping(value = "details")
public ResponseDto<GoblinBackOrderDetailsVo> orderList(@RequestParam(value = "backOrderId", required = true) @Valid String backOrderId) {
return goblinStoreBackOrderService.orderDetails(backOrderId);
}
@ApiOperation(value = "同意退款")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "backOrderId", value = "订单id"),
})
@GetMapping(value = "agree")
public ResponseDto<Boolean> agreeRefund(@RequestParam(value = "backOrderId", required = true) @Valid String backOrderId) {
return goblinStoreBackOrderService.agreeRefund(backOrderId);
}
@ApiOperation(value = "拒绝退款")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "backOrderId", value = "订单id"),
})
@GetMapping(value = "refused")
public ResponseDto<Boolean> refusedRefund(@RequestParam(value = "backOrderId", required = true) @Valid String backOrderId) {
return goblinStoreBackOrderService.refusedRefund(backOrderId);
}
@ApiOperation(value = "修改金额")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "backOrderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "changeType", value = "类型[1-物流金额|2-退款金额]"),
@ApiImplicitParam(type = "form", required = true, dataType = "Number", name = "refundPrice", value = "价格"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderSkuId", value = "orderSkuId"),
})
@GetMapping(value = "change")
public ResponseDto<Boolean> changeRefund(@RequestParam(value = "backOrderId", required = true) @Valid String backOrderId,
@RequestParam(value = "changeType", required = true) @Valid Integer changeType,
@RequestParam(value = "refundPrice", required = true) @Valid BigDecimal refundPrice,
@RequestParam(value = "orderSkuId", required = false) String orderSkuId) {
if (changeType == 1) {
return goblinStoreBackOrderService.changeExpressRefund(backOrderId, refundPrice);
} else if (changeType == 2) {
return goblinStoreBackOrderService.changeSkuRefund(backOrderId, refundPrice, orderSkuId);
} else {
return ResponseDto.failure("参数异常");
}
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfGoodsCategoryVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreGoodsCategoryVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtCategoryService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ApiSupport(order = 149005)
@Api(tags = "店铺商品分类")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt/category")
public class GoblinStoreMgtCategoryController {
@Autowired
IGoblinStoreMgtCategoryService goblinStoreMgtCategoryService;
@Autowired
GoblinRedisUtils goblinRedisUtils;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "列表")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
})
@GetMapping("list")
public ResponseDto<List<GoblinStoreGoodsCategoryVo>> list(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId) {
return ResponseDto.success(goblinStoreMgtCategoryService.list(storeId));
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "添加")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "catefid", value = "平台分类ID[30]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "catesid", value = "平台分类ID[30]"),
// @ApiImplicitParam(type = "form", required = false, dataType = "String", name = "catetid", value = "平台分类ID[30]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "catename", value = "店铺分类名称[50]"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "sort", value = "排序[数值越小,排序越前]"),
})
@GetMapping("add")
public ResponseDto<Object> add(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId,
@NotBlank(message = "平台分类ID不能为空") @RequestParam String catefid,
@NotBlank(message = "平台分类不能为空") @RequestParam String catesid,
// @NotBlank(message = "平台分类不能为空") @RequestParam String catetid,
@NotBlank(message = "店铺分类名称不能为空") @RequestParam String catename,
@Min(value = 1, message = "排序不能小于0") @RequestParam(required = false) Integer sort) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinRedisUtils.getSelfGoodsCategoryVos();
if (CollectionUtils.isEmpty(selfGoodsCategoryVos)) {
log.warn("店铺商品分类管理:添加:平台分类未创建[UID={},storeId={},catefid={},catesid={},catename={}]", currentUid, storeId, catefid, catesid, catename);
return ResponseDto.failure(ErrorMapping.get("149001"));
}
List<String> catePidList = Arrays.asList(catefid, catesid);
Map<String, GoblinSelfGoodsCategoryVo> filterMap = selfGoodsCategoryVos.stream()
.filter(r -> catePidList.contains(r.getCateId())).collect(Collectors.toMap(GoblinSelfGoodsCategoryVo::getCateId, Function.identity()));
if (CollectionUtils.isEmpty(filterMap) || filterMap.size() < 2) {
log.warn("店铺商品分类管理:添加:平台分类ID有误[UID={},storeId={},catefid={},catesid={},catename={}]", currentUid, storeId, catefid, catesid, catename);
return ResponseDto.failure(ErrorMapping.get("149001"));
}
ArrayList<GoblinStoreGoodsCategoryVo> addStoreGoodsCategoryVoList = ObjectUtil.getGoblinStoreGoodsCategoryVoArrayList();
LocalDateTime now = LocalDateTime.now();
List<GoblinStoreGoodsCategoryVo> storeGoodsCategoryVosCache = goblinRedisUtils.getStoreGoodsCategoryVos(storeId);
if (CollectionUtils.isEmpty(storeGoodsCategoryVosCache)) {// 不存在店铺商品分类,则直接初始化
filterMap.forEach((k, v) -> {
GoblinStoreGoodsCategoryVo storeGoodsCategoryVo = GoblinStoreGoodsCategoryVo.getNew().copy(v);
storeGoodsCategoryVo.setDelFlg("0");
storeGoodsCategoryVo.setStoreId(storeId);
storeGoodsCategoryVo.setCreatedBy(currentUid);
storeGoodsCategoryVo.setCreatedAt(now);
addStoreGoodsCategoryVoList.add(storeGoodsCategoryVo);
});
} else {// 存在则判断,是否为已存在的父级分类
if (storeGoodsCategoryVosCache.stream().anyMatch(r -> r.getName().equals(catename))) {
log.warn("店铺商品分类管理:添加:分类名称重复[UID={},storeId={},catefid={},catesid={},catename={}]", currentUid, storeId, catefid, catesid, catename);
return ResponseDto.failure(ErrorMapping.get("149008"));
}
Map<String, GoblinStoreGoodsCategoryVo> existFilterMap = storeGoodsCategoryVosCache.stream().filter(r -> catePidList.contains(r.getCateId()))
.collect(Collectors.toMap(GoblinStoreGoodsCategoryVo::getCateId, Function.identity()));
GoblinStoreGoodsCategoryVo fStoreGoodsCategoryVo = existFilterMap.get(catefid);
GoblinStoreGoodsCategoryVo sStoreGoodsCategoryVo = existFilterMap.get(catesid);
if (null == fStoreGoodsCategoryVo) {
GoblinStoreGoodsCategoryVo storeGoodsCategoryVo = GoblinStoreGoodsCategoryVo.getNew().copy(filterMap.get(catefid));
storeGoodsCategoryVo.setDelFlg("0");
storeGoodsCategoryVo.setStoreId(storeId);
storeGoodsCategoryVo.setCreatedBy(currentUid);
storeGoodsCategoryVo.setCreatedAt(now);
addStoreGoodsCategoryVoList.add(storeGoodsCategoryVo);
}
if (null == sStoreGoodsCategoryVo) {
GoblinStoreGoodsCategoryVo storeGoodsCategoryVo = GoblinStoreGoodsCategoryVo.getNew().copy(filterMap.get(catesid));
storeGoodsCategoryVo.setDelFlg("0");
storeGoodsCategoryVo.setStoreId(storeId);
storeGoodsCategoryVo.setCreatedBy(currentUid);
storeGoodsCategoryVo.setCreatedAt(now);
addStoreGoodsCategoryVoList.add(storeGoodsCategoryVo);
}
}
GoblinStoreGoodsCategoryVo storeGoodsCategoryVo = GoblinStoreGoodsCategoryVo.getNew();
storeGoodsCategoryVo.setStoreId(storeId);
storeGoodsCategoryVo.setCateId(IDGenerator.nextMilliId2());
storeGoodsCategoryVo.setName(catename);
storeGoodsCategoryVo.setSort(null == sort ? 1 : sort);
storeGoodsCategoryVo.setGrade("3");
storeGoodsCategoryVo.setCatePid(catesid);
storeGoodsCategoryVo.setNeIsbn("0");
storeGoodsCategoryVo.setDelFlg("0");
storeGoodsCategoryVo.setCreatedBy(currentUid);
storeGoodsCategoryVo.setCreatedAt(now);
addStoreGoodsCategoryVoList.add(storeGoodsCategoryVo);
goblinStoreMgtCategoryService.add(storeId, addStoreGoodsCategoryVoList, storeGoodsCategoryVosCache);
return ResponseDto.success(storeGoodsCategoryVo.getCateId());
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "编辑")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "cateid", value = "店铺分类ID[30]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "catename", value = "店铺分类名称[50]"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "sort", value = "排序[数值越小,排序越前]"),
})
@GetMapping("edit")
public ResponseDto<Object> edit(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId,
@NotBlank(message = "店铺分类ID不能为空") @RequestParam String cateid,
@NotBlank(message = "店铺分类名称不能为空") @RequestParam String catename,
@Min(value = 1, message = "排序不能小于0") @RequestParam(required = false) Integer sort) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
List<GoblinStoreGoodsCategoryVo> storeGoodsCategoryVosCache = goblinRedisUtils.getStoreGoodsCategoryVos(storeId);
if (CollectionUtils.isEmpty(storeGoodsCategoryVosCache)) {
log.warn("店铺商品分类管理:编辑:请先添加商品分类[UID={},storeId={},cateid={},catename={}]", currentUid, storeId, cateid, catename);
return ResponseDto.failure(ErrorMapping.get("149001"));
}
Optional<GoblinStoreGoodsCategoryVo> filterOpt = storeGoodsCategoryVosCache.stream().filter(r -> r.getCateId().equals(cateid)).findAny();
if (!filterOpt.isPresent()) {
log.warn("店铺商品分类管理:编辑:不存在的分类ID[UID={},storeId={},cateid={},catename={}]", currentUid, storeId, cateid, catename);
return ResponseDto.failure(ErrorMapping.get("149001"));
}
GoblinStoreGoodsCategoryVo updateStoreGoodsCategoryVo = filterOpt.get();
updateStoreGoodsCategoryVo.setName(catename);
updateStoreGoodsCategoryVo.setSort(null == sort ? 1 : sort);
updateStoreGoodsCategoryVo.setUpdatedBy(currentUid);
updateStoreGoodsCategoryVo.setUpdatedAt(LocalDateTime.now());
boolean result = goblinStoreMgtCategoryService.edit(updateStoreGoodsCategoryVo, storeGoodsCategoryVosCache);
return result ? ResponseDto.success(result) : ResponseDto.failure();
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "删除")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "cateid", value = "店铺分类ID[30]"),
})
@GetMapping("del")
public ResponseDto<Object> del(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId,
@NotBlank(message = "店铺分类ID不能为空") @RequestParam String cateid) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
boolean resultFlg = goblinStoreMgtCategoryService.del(currentUid, storeId, cateid);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.IdentityUtils;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCertificationParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCompleteParam;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtCertificationService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.List;
@ApiSupport(order = 149001)
@Api(tags = "店铺认证")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt/cert")
public class GoblinStoreMgtCertificationController {
@Autowired
IGoblinStoreMgtCertificationService goblinStoreMgtCertificationService;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
GoblinRedisUtils goblinRedisUtils;
public static final List<String> ENABLE_CERT_STATUS = Arrays.asList("0", "2");
@ApiOperationSupport(order = 1)
@ApiOperation(value = "店铺认证第一步:认证资料")
@PostMapping("fstep")
public ResponseDto<String> certificationFirstStep(@Valid @RequestBody GoblinStoreMgtCertificationParam certificationParam) {
String currentUid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(currentUid);
if (null != storeInfoVo && !ENABLE_CERT_STATUS.contains(storeInfoVo.getStatus())) {
log.warn("店铺认证:无效请求:店铺已认证,无需再次认证[UID={},storeId={},storeStatus={}]", currentUid, storeInfoVo.getStoreId(), storeInfoVo.getStatus());
return ResponseDto.failure(ErrorMapping.get("149001"));
}
if (log.isDebugEnabled()) {
log.debug("店铺认证[UID={},GoblinStoreMgtCertificationParam:{}]", currentUid, JsonUtils.toJson(certificationParam));
}
if (certificationParam.getPersonCertType().equals("1")) {
String personName = certificationParam.getPersonName();
String personCertCode = certificationParam.getPersonCertCode();
String respStr = IdentityUtils.aliThird(personName, personCertCode);
JsonNode respJNode = JsonUtils.fromJson(respStr, JsonNode.class);
if (null == respJNode || !"0".equals(String.valueOf(respJNode.get("error_code")))) {
log.info("###实名认证失败[UID={},name={},idcard={},respStr={}]", currentUid, personName, personCertCode, respStr);
return ResponseDto.failure(ErrorMapping.get("149004"));
}
}
storeInfoVo = goblinStoreMgtCertificationService.certificationInformationProcessing(certificationParam, storeInfoVo);
return ResponseDto.success(storeInfoVo.getStoreId());
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "店铺认证第二步:完善信息")
@PostMapping("sstep")
public ResponseDto<Object> certificationSecondStep(@Valid @RequestBody GoblinStoreMgtCompleteParam completeParam) {
String currentUid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(currentUid);
if (null == storeInfoVo) {
log.warn("店铺认证:完善信息:店铺信息不存在,请按流程完成第一步:[UID={}]", currentUid);
return ResponseDto.failure(ErrorMapping.get("149001"));
}
if (!ENABLE_CERT_STATUS.contains(storeInfoVo.getStatus())) {
log.warn("店铺认证:无效请求:店铺已认证,无需再次认证[UID={},storeId={},storeStatus={}]", currentUid, storeInfoVo.getStoreId(), storeInfoVo.getStatus());
return ResponseDto.failure(ErrorMapping.get("149001"));
}
if (log.isDebugEnabled()) {
log.debug("店铺认证[UID={},GoblinStoreMgtCompleteParam:{}]", currentUid, JsonUtils.toJson(completeParam));
}
boolean resultFlg = goblinStoreMgtCertificationService.certificationCompleteProcessing(completeParam, storeInfoVo);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "店铺认证编辑中:资料详情")
@PostMapping("einfo")
public ResponseDto<GoblinStoreInfoVo> certificationInfo() {
return ResponseDto.success(goblinRedisUtils.getStoreInfoVoByUid(CurrentUtil.getCurrentUid()));
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "店铺认证认证中:店铺状态", notes = "认证状态[-1-未申请|0-填写资料中|1-店铺审核中|2-审核不通过|3-审核通过|4-停业|5-营业]")
@PostMapping("status")
public ResponseDto<String> certificationStatus() {
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(CurrentUtil.getCurrentUid());
return ResponseDto.success(null == storeInfoVo ? "-1" : storeInfoVo.getStatus());
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "删除店铺")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
})
@PostMapping("cancel")
public ResponseDto<Object> certificationCancel(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVo(storeId);
if (null == storeInfoVo || Arrays.asList("3","4","5").contains(storeInfoVo.getStatus())) {
return ResponseDto.success();// 店铺认证通过后不允许删除
}
log.info("删除店铺[UID={},storeId={}]", currentUid, storeId);
boolean resultFlg = goblinStoreMgtCertificationService.certificationCancelProcessing(storeId, currentUid);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtConfigEditParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtNoticeActionParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtNoticeAddParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtNoticeFilterParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtThumbVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCertInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreConfigVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreNoticeVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtNoticeService;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ApiSupport(order = 149002)
@Api(tags = "店铺管理")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt")
public class GoblinStoreMgtController {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
IGoblinStoreMgtService goblinStoreMgtService;
@Autowired
IGoblinStoreMgtNoticeService goblinStoreMgtNoticeService;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "店铺管理:店铺列表")
@GetMapping(value = {"list"})
public ResponseDto<List<GoblinStoreMgtThumbVo>> thumbList() {
ArrayList<GoblinStoreMgtThumbVo> storeMgtThumbList = ObjectUtil.getGoblinStoreMgtThumbVoArrayList();
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(CurrentUtil.getCurrentUid());
if (null != storeInfoVo) {
storeMgtThumbList.add(GoblinStoreMgtThumbVo.getNew().copy(storeInfoVo));
}
return ResponseDto.success(storeMgtThumbList);
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "店铺管理:店铺信息")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
})
@GetMapping(value = {"info"})
public ResponseDto<GoblinStoreMgtInfoVo> info(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
log.warn("店铺管理:店铺信息:无权查看该店铺[UID={},storeId={}]", currentUid, storeId);
return ResponseDto.failure(ErrorMapping.get("149002"));
}
return ResponseDto.success(GoblinStoreMgtInfoVo.getNew().copy(goblinRedisUtils.getStoreInfoVo(storeId)));
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "店铺管理:店铺信息:修改")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeName", value = "店铺名称[128]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "logoPic", value = "店铺LOGO[256]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "backgroundPic", value = "店铺背景图[256]"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "introduce", value = "店铺介绍[2000]"),
})
@GetMapping(value = {"info/edit"})
public ResponseDto<Object> infoEdit(@NotBlank(message = "店铺名称不能为空") @Size(max = 128, message = "店铺名称过长") @RequestParam String storeName,
@NotBlank(message = "店铺LOGO不能为空") @Size(max = 256, message = "店铺LOGOURL过长") @RequestParam String logoPic,
@NotBlank(message = "店铺背景图不能为空") @Size(max = 256, message = "店铺背景图URL过长") @RequestParam String backgroundPic,
@NotBlank(message = "店铺介绍不能为空") @Size(max = 2000, message = "店铺介绍内容过长") @RequestParam String introduce,
@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVo(storeId);
storeInfoVo.setStoreName(storeName);
storeInfoVo.setLogoPic(logoPic);
storeInfoVo.setBackgroundPic(backgroundPic);
storeInfoVo.setIntroduce(introduce);
storeInfoVo.setUpdatedBy(currentUid);
storeInfoVo.setUpdatedAt(LocalDateTime.now());
return goblinStoreMgtService.updateStoreMgtInfo(storeInfoVo) ? ResponseDto.success() : ResponseDto.failure(ErrorMapping.get("149003"));
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "店铺管理:认证信息")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
})
@GetMapping(value = {"info/cer"})
public ResponseDto<GoblinStoreCertInfoVo> certInfo(@NotBlank(message = "店铺ID不能为空") @Size(max = 64) @RequestParam String storeId) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
log.warn("店铺管理:认证信息:无权查看该店铺[UID={},storeId={}]", currentUid, storeId);
return ResponseDto.failure(ErrorMapping.get("149002"));
}
return ResponseDto.success(GoblinStoreCertInfoVo.getNew().copy(goblinRedisUtils.getStoreInfoVo(storeId)));
}
@ApiOperationSupport(order = 5)
@ApiOperation(value = "店铺管理:店铺设置:详情", notes = "BUSINESS_STATUS(状态:营业状态[4-停业|5-营业])、ONOFF_CUSTOMER_SEV(开关:联系客服)、ONOFF_SOLD_OUT_SHOW(开关:售罄展示)、LIMIT_WARNING_STOCK(指标:库存不足)")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID[64]"),
})
@GetMapping(value = {"conf"})
public ResponseDto<Map<String, String>> conf(@NotBlank(message = "店铺ID不能为空") @Size(max = 64) @RequestParam String storeId) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
log.warn("店铺管理:店铺设置:无权查看该店铺[UID={},storeId={}]", currentUid, storeId);
return ResponseDto.failure(ErrorMapping.get("149002"));
}
List<GoblinStoreConfigVo> storeConfigVos = goblinRedisUtils.getStoreConfigVos(storeId);
return ResponseDto.success(storeConfigVos.stream().collect(Collectors.toMap(GoblinStoreConfigVo::getConfigKey, GoblinStoreConfigVo::getConfigVal)));
}
@ApiOperationSupport(order = 6)
@ApiOperation(value = "店铺管理:店铺设置:编辑")
@PostMapping(value = {"conf/edit"})
public ResponseDto<Object> confEdit(@Valid @RequestBody GoblinStoreMgtConfigEditParam param) {
String currentUid = CurrentUtil.getCurrentUid();
String storeId = param.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
log.warn("店铺管理:店铺设置:无权编辑该店铺[UID={},storeId={}]", currentUid, storeId);
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("店铺管理:店铺设置:编辑[UID={},GoblinStoreMgtConfigEditParam={}]", currentUid, JsonUtils.toJson(param));
}
HashMap<String, String> updateConfMap = CollectionUtil.mapStringString();
param.getConfMap().forEach((ck, cv) -> {
switch (ck) {
case "BUSINESS_STATUS":
if (Arrays.asList("4", "5").contains(cv)) {
// TODO: 2022/2/23 ==zhanggb 暂不启用停业功能
// updateConfMap.put(ck, cv);
updateConfMap.put(ck, "5");
}
break;
case "ONOFF_CUSTOMER_SEV":
case "ONOFF_SOLD_OUT_SHOW":
if (Arrays.asList("ON", "OFF").contains(cv)) {
updateConfMap.put(ck, cv);
}
case "LIMIT_WARNING_STOCK":
int limitWarningStock = -1;
try {
limitWarningStock = Integer.parseInt(cv);
} catch (NumberFormatException e) {
}
if (limitWarningStock >= 0) {
updateConfMap.put(ck, cv);
}
break;
}
});
if (CollectionUtils.isEmpty(updateConfMap)) {
log.warn("店铺管理:店铺设置:编辑[UID={},param={}],无效操作:无效配置", currentUid, JsonUtils.toJson(param));
return ResponseDto.failure(ErrorMapping.get("149001"));
}
boolean resultFlg = goblinStoreMgtService.updateStoreMgtConfig(currentUid, storeId, updateConfMap);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
@ApiOperationSupport(order = 7)
@ApiOperation(value = "店铺管理:公告通知:列表")
@PostMapping(value = {"notice/list"})
public ResponseDto<PagedResult<GoblinStoreNoticeVo>> noticeList(@Valid @RequestBody GoblinStoreMgtNoticeFilterParam noticeFilterParam) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, noticeFilterParam.getStoreId())) {
log.warn("店铺管理:公告通知:列表:无权查看该店铺[UID={},storeId={}]", currentUid, noticeFilterParam.getStoreId());
return ResponseDto.success();
}
if (log.isDebugEnabled()) {
log.debug("店铺管理:公告通知:列表[UID={},noticeFilterParam={}]", currentUid, JsonUtils.toJson(noticeFilterParam));
}
return ResponseDto.success(goblinStoreMgtNoticeService.pageList(noticeFilterParam));
}
@ApiOperationSupport(order = 8)
@ApiOperation(value = "店铺管理:公告通知:添加")
@PostMapping(value = {"notice/add"})
public ResponseDto<Object> noticeAdd(@Valid @RequestBody GoblinStoreMgtNoticeAddParam noticeAddParam) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, noticeAddParam.getStoreId())) {
log.warn("店铺管理:公告通知:添加:无权操作该店铺[UID={},storeId={}]", currentUid, noticeAddParam.getStoreId());
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("店铺管理:公告通知:添加[UID={},noticeAddParam={}]", currentUid, JsonUtils.toJson(noticeAddParam));
}
if (noticeAddParam.getLongLasting().equals("0") && null == noticeAddParam.getCancellTime()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "结束时间不能为空");
}
LocalDateTime now = LocalDateTime.now();
GoblinStoreNoticeVo addStoreNoticeVo = GoblinStoreNoticeVo.getNew();
addStoreNoticeVo.setStoreId(noticeAddParam.getStoreId());
addStoreNoticeVo.setNoticeId(IDGenerator.nextMilliId());
addStoreNoticeVo.setContent(noticeAddParam.getContent());
addStoreNoticeVo.setReleaseTime(DateUtil.Formatter.yyyyMMddHHmmss.parse(noticeAddParam.getReleaseTime()));
addStoreNoticeVo.setLongLasting(noticeAddParam.getLongLasting());
if (noticeAddParam.getLongLasting().equals("0")) {
addStoreNoticeVo.setCancellTime(DateUtil.Formatter.yyyyMMddHHmmss.parse(noticeAddParam.getCancellTime()));
}
addStoreNoticeVo.setStatus(addStoreNoticeVo.getReleaseTime().compareTo(now) > 0 ? "0" : "1");
addStoreNoticeVo.setDelFlg("0");
addStoreNoticeVo.setCreatedBy(currentUid);
addStoreNoticeVo.setCreatedAt(now);
goblinStoreMgtNoticeService.addSave(addStoreNoticeVo);
return ResponseDto.success(addStoreNoticeVo.getNoticeId());
}
@ApiOperationSupport(order = 9)
@ApiOperation(value = "店铺管理:公告通知:编辑")
@PostMapping(value = {"notice/edit"})
public ResponseDto<Object> noticeEdit(@Valid @RequestBody GoblinStoreMgtNoticeAddParam noticeEditParam) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, noticeEditParam.getStoreId())) {
log.warn("店铺管理:公告通知:编辑:无权操作该店铺[UID={},storeId={}]", currentUid, noticeEditParam.getStoreId());
return ResponseDto.failure(ErrorMapping.get("149002"));
}
List<GoblinStoreNoticeVo> noticeVos = goblinRedisUtils.getStoreNoticeVos(noticeEditParam.getStoreId(), LocalDateTime.now());
if (CollectionUtils.isEmpty(noticeVos)) {
log.warn("店铺管理:公告通知:编辑:无效操作,请先添加公告[UID={},noticeEditParam={}]", currentUid, JsonUtils.toJson(noticeEditParam));
return ResponseDto.failure(ErrorMapping.get("149001"));
}
if (log.isDebugEnabled()) {
log.debug("店铺管理:公告通知:编辑[UID={},noticeEditParam={}]", currentUid, JsonUtils.toJson(noticeEditParam));
}
Optional<GoblinStoreNoticeVo> optional = noticeVos.stream().filter(r -> r.getNoticeId().equals(noticeEditParam.getNoticeId())).findAny();
if (!optional.isPresent() || optional.get().getStatus().equals("1")) {
log.warn("店铺管理:公告通知:编辑:无效操作,公告已发布或不存在[UID={},noticeEditParam={}]", currentUid, JsonUtils.toJson(noticeEditParam));
return ResponseDto.failure(ErrorMapping.get("149001"));
}
LocalDateTime now = LocalDateTime.now();
GoblinStoreNoticeVo updateStoreNoticeVo = GoblinStoreNoticeVo.getNew();
updateStoreNoticeVo.setStoreId(noticeEditParam.getStoreId());
updateStoreNoticeVo.setNoticeId(noticeEditParam.getNoticeId());
updateStoreNoticeVo.setContent(noticeEditParam.getContent());
updateStoreNoticeVo.setReleaseTime(DateUtil.Formatter.yyyyMMddHHmmss.parse(noticeEditParam.getReleaseTime()));
updateStoreNoticeVo.setLongLasting(noticeEditParam.getLongLasting());
if (noticeEditParam.getLongLasting().equals("0")) {
updateStoreNoticeVo.setCancellTime(DateUtil.Formatter.yyyyMMddHHmmss.parse(noticeEditParam.getCancellTime()));
}
updateStoreNoticeVo.setStatus(updateStoreNoticeVo.getReleaseTime().compareTo(now) > 0 ? "0" : "1");
updateStoreNoticeVo.setUpdatedBy(currentUid);
updateStoreNoticeVo.setUpdatedAt(now);
boolean resultFlg = goblinStoreMgtNoticeService.editSave(updateStoreNoticeVo);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
@ApiOperationSupport(order = 10)
@ApiOperation(value = "店铺管理:公告通知:管理")
@PostMapping(value = {"notice/operate"})
public ResponseDto<Object> noticeOperate(@Valid @RequestBody GoblinStoreMgtNoticeActionParam noticeActionParam) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, noticeActionParam.getStoreId())) {
log.warn("店铺管理:公告通知:管理:无权操作该店铺[UID={},storeId={}]", currentUid, noticeActionParam.getStoreId());
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("店铺管理:公告通知:管理[UID={},noticeActionParam={}]", currentUid, JsonUtils.toJson(noticeActionParam));
}
boolean operateResultFlg;
switch (noticeActionParam.getAction()) {
case "RELEASE":
operateResultFlg = goblinStoreMgtNoticeService.releaseProcessing(currentUid, noticeActionParam.getStoreId(), noticeActionParam.getNoticeIdList());
break;
case "REMOVE":
operateResultFlg = goblinStoreMgtNoticeService.removeProcessing(currentUid, noticeActionParam.getStoreId(), noticeActionParam.getNoticeIdList());
break;
default:
log.warn("Invalid operation[UID={},noticeActionParam={}]", currentUid, JsonUtils.toJson(noticeActionParam));
return ResponseDto.failure(ErrorMapping.get("149001"));
}
return operateResultFlg ? ResponseDto.success() : ResponseDto.failure();
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtCouponListVoExcel;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtGoodsListVoExcel;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponActionParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponAddParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponFilterParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponBasicVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponVo;
import com.liquidnet.service.goblin.service.manage.IGoblinstoreMgtCouponService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Iterator;
import java.util.List;
@ApiSupport(order = 149006)
@Api(tags = "商铺活动:优惠券管理")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt/coupon")
public class GoblinStoreMgtCouponController {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
IGoblinstoreMgtCouponService goblinstoreMgtCouponService;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "优惠券列表")
@PostMapping("list")
public ResponseDto<PagedResult<GoblinStoreMgtCouponListVo>> list(@Valid @RequestBody GoblinStoreMgtCouponFilterParam mgtCouponFilterParam) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, mgtCouponFilterParam.getStoreId())) {
return ResponseDto.success();
}
if (log.isDebugEnabled()) {
log.debug("商铺活动:优惠券列表:[mgtCouponFilterParam={}]", JsonUtils.toJson(mgtCouponFilterParam));
}
return ResponseDto.success(goblinstoreMgtCouponService.couponList(mgtCouponFilterParam));
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "优惠券导出")
@PostMapping("export")
public void export(@Valid @RequestBody GoblinStoreMgtCouponFilterParam mgtCouponFilterParam, HttpServletResponse response) {
String currentUid = CurrentUtil.getCurrentUid();
ServletOutputStream servletOutputStream = null;
try {
if (!goblinRedisUtils.hasStoreId(currentUid, mgtCouponFilterParam.getStoreId())) {
log.warn("商铺活动:优惠券导出:无权操作该店铺,请核实[UID={},GoblinStoreMgtCouponFilterParam={}]", currentUid, JsonUtils.toJson(mgtCouponFilterParam));
return;
}
if (log.isDebugEnabled()) {
log.debug("商铺活动:优惠券导出:[mgtCouponFilterParam={}]", JsonUtils.toJson(mgtCouponFilterParam));
}
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=".concat(DateUtil.Formatter.ddHHmmssTrim.format(LocalDateTime.now()))
.concat(new String(("优惠券数据").getBytes("gb2312"), StandardCharsets.ISO_8859_1)).concat(ExcelTypeEnum.XLSX.getValue()));
response.setContentType(MediaType.MULTIPART_FORM_DATA_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
servletOutputStream = response.getOutputStream();
mgtCouponFilterParam.setPageNum(1);
mgtCouponFilterParam.setPageSize(5000);
PagedResult<GoblinStoreMgtCouponListVo> pagedResult = goblinstoreMgtCouponService.couponList(mgtCouponFilterParam);
List<GoblinStoreMgtCouponListVo> rows = pagedResult.getList();
List<GoblinStoreMgtCouponListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtCouponListVoExcelArrayList();
rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtCouponListVoExcel.getNew().copy(row)));
EasyExcel.write(servletOutputStream, GoblinStoreMgtGoodsListVoExcel.class).sheet("优惠券数据").doWrite(rowsToExcels);
} catch (IOException e) {
log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage());
} finally {
if (null != servletOutputStream) {
try {
servletOutputStream.close();
} catch (Exception ignored) {
}
}
}
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "优惠券管理")
@PostMapping("action")
public ResponseDto<Object> action(@Valid @RequestBody GoblinStoreMgtCouponActionParam mgtCouponActionParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtCouponActionParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
List<String> storeCouponIdList = mgtCouponActionParam.getStoreCouponIdList();
if (CollectionUtils.isEmpty(storeCouponIdList)) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请选择优惠券操作");
}
if (log.isDebugEnabled()) {
log.debug("商铺活动:优惠券管理:[GoblinStoreMgtCouponActionParam={}]", JsonUtils.toJson(mgtCouponActionParam));
}
switch (mgtCouponActionParam.getAction()) {//ENABLED|DISABLED|REMOVE
case "ENABLED":
for (String storeCouponId : storeCouponIdList) {
GoblinStoreCouponVo storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null == storeCouponVo) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数有误:优惠券不存在");
}
if (!storeCouponVo.getStoreId().equals(storeId)) {
log.warn("商铺活动:优惠券管理:启用警告:非本店铺活动,无权操作[UID={},storeCouponId={}]", currentUid, storeCouponId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺活动,无权操作");
}
if (!storeCouponVo.getState().equals("3")) {// 只针对停用的优惠券
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "只限已停用状态执行该操作");
}
}
goblinstoreMgtCouponService.couponActivityProcessing(mgtCouponActionParam, currentUid);
break;
case "DISABLED":
for (String storeCouponId : storeCouponIdList) {
GoblinStoreCouponVo storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null == storeCouponVo) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数有误:优惠券不存在");
}
if (!storeCouponVo.getStoreId().equals(storeId)) {
log.warn("商铺活动:优惠券管理:停用警告:非本店铺活动,无权操作[UID={},storeCouponId={}]", currentUid, storeCouponId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺活动,无权操作");
}
// if (storeCouponVo.getState().equals("1")) {// 该优惠券活动中
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "该优惠券活动中不可停用");
// }
if (storeCouponVo.getState().equals("3")) {// 该优惠券已停用
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "该优惠券已停用");
}
}
goblinstoreMgtCouponService.couponActivityProcessing(mgtCouponActionParam, currentUid);
break;
case "REMOVE":
for (String storeCouponId : storeCouponIdList) {
GoblinStoreCouponVo storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null == storeCouponVo) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数有误:优惠券不存在");
}
if (!storeCouponVo.getStoreId().equals(storeId)) {
log.warn("商铺活动:优惠券管理:删除警告:非本店铺活动,无权操作[UID={},storeCouponId={}]", currentUid, storeCouponId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺活动,无权操作");
}
if (storeCouponVo.getState().equals("1")) {// 活动中不可删除
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "活动中不允许删除,请停用或活动结束后操作");
}
}
goblinstoreMgtCouponService.couponRemove(mgtCouponActionParam, currentUid);
break;
default:
log.warn("商铺活动:优惠券管理:Invalid operation[UID={},storeMgtGoodsActionParam={}]", currentUid, JsonUtils.toJson(mgtCouponActionParam));
return ResponseDto.failure(ErrorMapping.get("149001"));
}
return ResponseDto.success();
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "新增优惠券")
@PutMapping("add")
public ResponseDto<Object> add(@Valid @RequestBody GoblinStoreMgtCouponAddParam mgtCouponAddParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtCouponAddParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("商铺活动:新增优惠券:[mgtCouponAddParam={}]", JsonUtils.toJson(mgtCouponAddParam));
}
GoblinStoreCouponBasicVo storeCouponBasicVo = mgtCouponAddParam.initStoreCouponBasicInfo();
switch (storeCouponBasicVo.getType()) {
case "1":// 代金
if (null == mgtCouponAddParam.getValFace()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "减免金额不能为空");
}
storeCouponBasicVo.setValFace(mgtCouponAddParam.getValFace());
storeCouponBasicVo.setDeduction(mgtCouponAddParam.getValFace());
break;
case "2":// 折扣
if (null == mgtCouponAddParam.getDiscount()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "折扣额度不能为空");
}
storeCouponBasicVo.setDiscount(mgtCouponAddParam.getDiscount());
BigDecimal deduction = mgtCouponAddParam.getDeduction();
storeCouponBasicVo.setDeduction(null == deduction ? BigDecimal.ZERO : deduction);
break;
case "3":// 满减
if (null == mgtCouponAddParam.getValOver() || null == mgtCouponAddParam.getValMinus()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "满减额度不能为空");
}
storeCouponBasicVo.setTriggers(mgtCouponAddParam.getValOver());
storeCouponBasicVo.setValOver(mgtCouponAddParam.getValOver());
storeCouponBasicVo.setValMinus(mgtCouponAddParam.getValMinus());
storeCouponBasicVo.setDeduction(mgtCouponAddParam.getValMinus());
break;
}
LocalDateTime startTime = storeCouponBasicVo.getStartTime(), endTime = storeCouponBasicVo.getEndTime();
if (startTime.isEqual(endTime) || startTime.isAfter(endTime) || endTime.isBefore(LocalDateTime.now())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "活动开始、结束时间无效");
}
List<String> spuIdList = storeCouponBasicVo.getSpuIdList();
if (storeCouponBasicVo.getUseScope().equals("1") && !CollectionUtils.isEmpty(spuIdList)) {
Iterator<String> iterator = spuIdList.iterator();
while (iterator.hasNext()) {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(iterator.next());
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")) {
iterator.remove();
}
}
// spuIdList.removeIf(spuId -> null == goblinRedisUtils.getGoodsInfoVo(spuId));
storeCouponBasicVo.setSpuIdList(spuIdList);
}
goblinstoreMgtCouponService.couponAdd(currentUid, storeCouponBasicVo);
return ResponseDto.success(storeCouponBasicVo.getStoreCouponId());
}
@ApiOperationSupport(order = 5)
@ApiOperation(value = "优惠券详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeCouponId", value = "优惠券ID"),
})
@GetMapping("info")
public ResponseDto<GoblinStoreMgtCouponInfoVo> info(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId,
@NotBlank(message = "优惠券ID不能为空") @RequestParam String storeCouponId) {
if (!goblinRedisUtils.hasStoreId(CurrentUtil.getCurrentUid(), storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("商铺活动:优惠券详情:[storeId={},storeCouponId={}]", storeId, storeCouponId);
}
return ResponseDto.success(goblinstoreMgtCouponService.couponInfo(storeId, storeCouponId));
}
@ApiOperationSupport(order = 6)
@ApiOperation(value = "优惠券编辑")
@PostMapping("edit")
public ResponseDto<Object> edit(@Valid @RequestBody GoblinStoreMgtCouponAddParam mgtCouponEditParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtCouponEditParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
String storeCouponId = mgtCouponEditParam.getStoreCouponId();
GoblinStoreCouponVo storeCouponVo;
if (StringUtils.isBlank(storeCouponId)
|| null == (storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId))
|| !storeId.equals(storeCouponVo.getStoreId())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数无效:优惠券ID");
}
if (storeCouponVo.getState().equals("1")) {// 活动中不可编辑
return ResponseDto.failure(ErrorMapping.get("149017"));
}
if (!storeCouponVo.getType().equals(mgtCouponEditParam.getType())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "卡券类型不可变更");
}
if (log.isDebugEnabled()) {
log.debug("商铺活动:优惠券编辑:[mgtCouponEditParam={}]", JsonUtils.toJson(mgtCouponEditParam));
}
GoblinStoreCouponBasicVo storeCouponBasicVo = mgtCouponEditParam.initStoreCouponBasicInfo();
LocalDateTime startTime = storeCouponBasicVo.getStartTime(), endTime = storeCouponBasicVo.getEndTime();
if (startTime.isEqual(endTime) || startTime.isAfter(endTime) || endTime.isBefore(LocalDateTime.now())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "活动开始、结束时间无效");
}
LocalDateTime befStartTime = storeCouponVo.getStartTime();
if (befStartTime.minusMinutes(10).isAfter(storeCouponBasicVo.getStartTime())) {
storeCouponBasicVo.setStartTime(startTime);
}
storeCouponBasicVo.setType(storeCouponVo.getType());
storeCouponBasicVo.setState(storeCouponVo.getState());
storeCouponBasicVo.setStock(storeCouponVo.getStock());// 这里库存不允许编辑修改,只可在列表页编辑'增减库存'
// storeCouponBasicVo.setTriggers(storeCouponVo.getTriggers());
// storeCouponBasicVo.setValFace(storeCouponVo.getValFace());
// storeCouponBasicVo.setDiscount(storeCouponVo.getDiscount());
// storeCouponBasicVo.setValOver(storeCouponVo.getValOver());
// storeCouponBasicVo.setValMinus(storeCouponVo.getValMinus());
// storeCouponBasicVo.setDeduction(storeCouponVo.getDeduction());
switch (storeCouponBasicVo.getType()) {
case "1":// 代金
if (null == mgtCouponEditParam.getValFace()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "减免金额不能为空");
}
storeCouponBasicVo.setValFace(mgtCouponEditParam.getValFace());
storeCouponBasicVo.setDeduction(mgtCouponEditParam.getValFace());
break;
case "2":// 折扣
if (null == mgtCouponEditParam.getDiscount()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "折扣额度不能为空");
}
storeCouponBasicVo.setDiscount(mgtCouponEditParam.getDiscount());
BigDecimal deduction = mgtCouponEditParam.getDeduction();
storeCouponBasicVo.setDeduction(null == deduction ? BigDecimal.ZERO : deduction);
break;
case "3":// 满减
if (null == mgtCouponEditParam.getValOver() || null == mgtCouponEditParam.getValMinus()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "满减额度不能为空");
}
storeCouponBasicVo.setTriggers(mgtCouponEditParam.getValOver());
storeCouponBasicVo.setValOver(mgtCouponEditParam.getValOver());
storeCouponBasicVo.setValMinus(mgtCouponEditParam.getValMinus());
storeCouponBasicVo.setDeduction(mgtCouponEditParam.getValMinus());
break;
}
storeCouponBasicVo.setStoreCouponId(storeCouponId);
storeCouponBasicVo.setStoreCouponNo(storeCouponVo.getStoreCouponNo());
List<String> spuIdList = storeCouponBasicVo.getSpuIdList();
if (storeCouponBasicVo.getUseScope().equals("1") && null != spuIdList) {
Iterator<String> iterator = spuIdList.iterator();
while (iterator.hasNext()) {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(iterator.next());
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")) {
iterator.remove();
}
}
// spuIdList.removeIf(spuId -> null == goblinRedisUtils.getGoodsInfoVo(spuId));
storeCouponBasicVo.setSpuIdList(spuIdList);
}
boolean resultFlg = goblinstoreMgtCouponService.couponEdit(currentUid, storeCouponBasicVo);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
@ApiOperationSupport(order = 7)
@ApiOperation(value = "优惠券库存编辑")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeCouponId", value = "优惠券ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "operStock", value = "增减库存"),
})
@PostMapping("edit_stock")
public ResponseDto<Object> editStock(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId,
@NotBlank(message = "优惠券ID不能为空") @RequestParam String storeCouponId,
@NotNull(message = "增减库存值不能为空") @RequestParam Integer operStock) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
GoblinStoreCouponVo storeCouponVo;
if (null == (storeCouponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数无效:优惠券ID");
}
if (!storeId.equals(storeCouponVo.getStoreId())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数有误:无权编辑优惠券");
}
if (operStock == 0) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "参数无效:增减库存不能为0");
}
int operStockVal = Math.abs(operStock), surplusStock = goblinRedisUtils.getStoreCouponStock(storeCouponId);
if (operStock < 0 && (operStockVal > surplusStock || operStockVal > storeCouponVo.getStock())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), String.format("参数无效:该优惠券总库存%s,剩余库存%s", storeCouponVo.getStock(), surplusStock));
}
boolean resultFlg = goblinstoreMgtCouponService.couponEditStock(storeCouponVo, currentUid, operStock);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfGoodsCategoryVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfTagVo;
import com.liquidnet.service.goblin.dto.vo.GoblinServiceSupportVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.List;
@ApiSupport(order = 149003)
@Api(tags = "附加数据")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt/extra")
public class GoblinStoreMgtExtraController {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
IGoblinStoreMgtExtraService goblinStoreMgtExtraService;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "平台商品分类")
@GetMapping("sg_categorys")
public ResponseDto<List<GoblinSelfGoodsCategoryVo>> selfGoodsCategoryList() {
return ResponseDto.success(goblinStoreMgtExtraService.listCategoryVo());
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "平台分类规格")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "cateId", value = "分类ID"),
})
@GetMapping("sg_catespecs")
public ResponseDto<GoblinMgtCategorySpecVo> categorySpecList(@RequestParam String cateId) {
if (StringUtils.isBlank(cateId)) return ResponseDto.success();
return ResponseDto.success(goblinMongoUtils.getCategorySpecVo(cateId));
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "服务支持列表")
@PostMapping("list")
public ResponseDto<List<GoblinServiceSupportVo>> list() {
return ResponseDto.success(goblinStoreMgtExtraService.listServiceSupportVo());
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "标签数据", notes = "获取商品标签与音乐人、艺人、IP")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "keyword", value = "标签关键字"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "belong", value = "标签所属[0-普通标签|1-专属标签]", allowableValues = "0,1"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "range", value = "查询标签类型范围,belong=1时有效,多个以,分隔[1-音乐人|2-艺术家|3-品牌方|4-厂牌|5-AR]", example = "1,2,3,4,5"),
})
@GetMapping("tags")
public ResponseDto<List<GoblinSelfTagVo>> tagList(@RequestParam(required = false) String keyword,
@NotBlank(message = "标签所属参数无效")
@Pattern(regexp = "\\b(0|1)\\b", message = "标签所属[0-普通标签|1-专属标签]")
@RequestParam String belong,
@RequestParam(defaultValue = "1,2,3,4") String range) {
return ResponseDto.success(goblinStoreMgtExtraService.listTagVo(keyword, belong, range.split(",")));
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtGoodsListVoExcel;
import com.liquidnet.service.goblin.dto.manage.*;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService;
import com.liquidnet.service.goblin.service.manage.IGoblinstoreMgtGoodsService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ApiSupport(order = 149004)
@Api(tags = "商品管理")
@Slf4j
@Validated
@RestController
@RequestMapping("store/mgt/goods")
public class GoblinStoreMgtGoodsController {
@Autowired
IGoblinstoreMgtGoodsService goblinstoreMgtGoodsService;
@Autowired
IGoblinStoreMgtExtraService goblinStoreMgtExtraService;
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "SPU列表")
@PostMapping("list")
public ResponseDto<PagedResult<GoblinStoreMgtGoodsListVo>> list(@Valid @RequestBody GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeMgtGoodsFilterParam.getStoreId())) {
log.warn("商品管理:SPU列表:无权操作该店铺,请核实[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
return ResponseDto.success();
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU列表:[GoblinStoreMgtGoodsFilterParam={}]", JsonUtils.toJson(storeMgtGoodsFilterParam));
}
return ResponseDto.success(goblinstoreMgtGoodsService.goodsList(storeMgtGoodsFilterParam));
}
@ApiOperationSupport(order = 2)
@ApiOperation(value = "SPU导出")
@PostMapping("export")
public void export(@Valid @RequestBody GoblinStoreMgtGoodsFilterParam storeMgtGoodsFilterParam, HttpServletResponse response) {
String currentUid = CurrentUtil.getCurrentUid();
ServletOutputStream servletOutputStream = null;
try {
if (!goblinRedisUtils.hasStoreId(currentUid, storeMgtGoodsFilterParam.getStoreId())) {
log.warn("商品管理:SPU导出:无权操作该店铺,请核实[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
return;
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU导出:[UID={},GoblinStoreMgtGoodsFilterParam={}]", currentUid, JsonUtils.toJson(storeMgtGoodsFilterParam));
}
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=".concat(DateUtil.Formatter.ddHHmmssTrim.format(LocalDateTime.now()))
.concat(new String(("商品数据").getBytes("gb2312"), StandardCharsets.ISO_8859_1)).concat(ExcelTypeEnum.XLSX.getValue()));
response.setContentType(MediaType.MULTIPART_FORM_DATA_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
servletOutputStream = response.getOutputStream();
storeMgtGoodsFilterParam.setPageNum(1);
storeMgtGoodsFilterParam.setPageSize(5000);
PagedResult<GoblinStoreMgtGoodsListVo> pagedResult = goblinstoreMgtGoodsService.goodsList(storeMgtGoodsFilterParam);
List<GoblinStoreMgtGoodsListVo> rows = pagedResult.getList();
List<GoblinStoreMgtGoodsListVoExcel> rowsToExcels = ObjectUtil.getGoblinStoreMgtGoodsListVoExcelArrayList();
rows.forEach(row -> rowsToExcels.add(GoblinStoreMgtGoodsListVoExcel.getNew().copy(row)));
EasyExcel.write(servletOutputStream, GoblinStoreMgtGoodsListVoExcel.class).sheet("商品数据").doWrite(rowsToExcels);
} catch (IOException e) {
log.error("商品管理:SPU导出:异常[UID={},ex.msg={}]", currentUid, e.getLocalizedMessage());
} finally {
if (null != servletOutputStream) {
try {
servletOutputStream.close();
} catch (Exception ignored) {
}
}
}
}
@ApiOperationSupport(order = 3)
@ApiOperation(value = "SPU管理")
@PostMapping("operate")
public ResponseDto<Object> action(@Valid @RequestBody GoblinStoreMgtGoodsActionParam mgtGoodsActionParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtGoodsActionParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
List<String> spuIdList = mgtGoodsActionParam.getSpuIdList();
if (CollectionUtils.isEmpty(spuIdList)) {
return ResponseDto.failure(ErrorMapping.get("149009"));
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU管理:[UID={},GoblinStoreMgtGoodsActionParam={}]", currentUid, JsonUtils.toJson(mgtGoodsActionParam));
}
boolean resultFlg;
List<String> spuNoList = CollectionUtil.arrayListString();
switch (mgtGoodsActionParam.getAction()) {
case "ONSHELVES":
for (String spuId : spuIdList) {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")) {
log.warn("商品管理:SPU管理:上架警告:商品不存在或已删除[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品不存在或已删除");
}
if (!goodsInfoVo.getStoreId().equals(storeId)) {
log.warn("商品管理:SPU管理:上架警告:非本店铺商品,无权操作[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺商品,无权操作");
}
if (goodsInfoVo.getShelvesStatus().equals("3")) {
log.warn("商品管理:SPU管理:上架警告:请先将商品下架后操作[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "无效操作,商品已上架");
}
spuNoList.add(goodsInfoVo.getSpuNo());
}
resultFlg = goblinstoreMgtGoodsService.goodsShelvesProcessing(mgtGoodsActionParam, currentUid, true, spuNoList);
break;
case "UNSHELVE":
for (String spuId : spuIdList) {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")) {
log.warn("商品管理:SPU管理:下架警告:商品不存在或已删除[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品不存在或已删除");
}
if (!goodsInfoVo.getStoreId().equals(storeId)) {
log.warn("商品管理:SPU管理:下架警告:非本店铺商品,无权操作[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺商品,无权操作");
}
if (!goodsInfoVo.getShelvesStatus().equals("3")) {// 非上架中不允许下架
log.warn("商品管理:SPU管理:下架警告:非上架中商品不允许此操作[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非上架中商品不允许此操作");
}
spuNoList.add(goodsInfoVo.getSpuNo());
}
resultFlg = goblinstoreMgtGoodsService.goodsShelvesProcessing(mgtGoodsActionParam, currentUid, false, spuNoList);
break;
case "REMOVE":
for (String spuId : spuIdList) {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")) {
log.warn("商品管理:SPU管理:删除警告:商品不存在或已删除[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品不存在或已删除");
}
if (!goodsInfoVo.getStoreId().equals(storeId)) {
log.warn("商品管理:SPU管理:删除警告:非本店铺商品,无权操作[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "非本店铺商品,无权操作");
}
if (goodsInfoVo.getShelvesStatus().equals("3")) {// 上架中不允许删除
log.warn("商品管理:SPU管理:删除警告:请先将商品下架后操作[UID={},spuId={}]", currentUid, spuId);
return ResponseDto.failure(ErrorMapping.get("149016"));
}
spuNoList.add(goodsInfoVo.getSpuNo());
}
resultFlg = goblinstoreMgtGoodsService.goodsRemove(mgtGoodsActionParam, currentUid, spuNoList);
break;
default:
log.warn("商品管理:SPU管理:Invalid operation[UID={},mgtGoodsActionParam={}]", currentUid, JsonUtils.toJson(mgtGoodsActionParam));
return ResponseDto.failure(ErrorMapping.get("149001"));
}
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
@ApiOperationSupport(order = 4)
@ApiOperation(value = "SPU添加")
@PutMapping("add")
public ResponseDto<Object> add(@Valid @RequestBody GoblinStoreMgtGoodsAddParam storeMgtGoodsAddParam) {
String currentUid = CurrentUtil.getCurrentUid();
String storeId = storeMgtGoodsAddParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU添加:[GoblinStoreMgtGoodsAddParam={}]", JsonUtils.toJson(storeMgtGoodsAddParam));
}
List<GoblinStoreMgtGoodsAddSkuParam> skuParamList = storeMgtGoodsAddParam.getSkuParamList();
if (CollectionUtils.isEmpty(skuParamList)) {
return ResponseDto.failure(ErrorMapping.get("149006"));
}
if (CollectionUtils.isEmpty(storeMgtGoodsAddParam.getImageList())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品图片不能为空");
}
{// 分类、ISBN校验
String cateSid = storeMgtGoodsAddParam.getCateSid(), cateTid = storeMgtGoodsAddParam.getCateTid();
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinStoreMgtExtraService.listCategoryVo();
Optional<GoblinSelfGoodsCategoryVo> categoryVoOptional = selfGoodsCategoryVos.stream()
.filter(r -> r.getCateId().equals(storeMgtGoodsAddParam.getCateFid()) && r.getGrade().equals("1")).findAny();
if (!categoryVoOptional.isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品一级分类无效");
}
GoblinSelfGoodsCategoryVo selfGoodsCategoryVo = categoryVoOptional.get();
if (selfGoodsCategoryVo.getNeIsbn().equals("1") && skuParamList.stream().anyMatch(r -> StringUtils.isBlank(r.getSkuIsbn()))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
if (StringUtils.isNotBlank(cateSid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateSid) && r.getGrade().equals("2")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品二级分类无效");
}
selfGoodsCategoryVo = categoryVoOptional.get();
if (selfGoodsCategoryVo.getNeIsbn().equals("1") && skuParamList.stream().anyMatch(r -> StringUtils.isBlank(r.getSkuIsbn()))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
if (StringUtils.isNotBlank(cateTid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateTid) && r.getGrade().equals("3")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品三级分类无效");
}
selfGoodsCategoryVo = categoryVoOptional.get();
if (selfGoodsCategoryVo.getNeIsbn().equals("1") && skuParamList.stream().anyMatch(r -> StringUtils.isBlank(r.getSkuIsbn()))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
// if (selfGoodsCategoryVos.stream().noneMatch(r -> r.getCateId().equals(storeMgtGoodsAddParam.getCateFid()) && r.getGrade().equals("1"))) {
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品一级分类无效");
// }
// if (StringUtils.isNotBlank(cateSid) && selfGoodsCategoryVos.stream().noneMatch(r -> r.getCateId().equals(cateSid) && r.getGrade().equals("2"))) {
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品二级分类无效");
// }
// if (StringUtils.isNotBlank(cateTid) && selfGoodsCategoryVos.stream().noneMatch(r -> r.getCateId().equals(cateTid) && r.getGrade().equals("3"))) {
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品三级分类无效");
// }
}
// GoblinGoodsInfoVo mgtGoodsInfoVo = goblinMongoUtils.getMgtGoodsInfoVo(storeId, storeMgtGoodsAddParam.getName());
if (goblinMongoUtils.countMgtGoodsInfoVo(storeMgtGoodsAddParam.getName()) > 0) {
return ResponseDto.failure(ErrorMapping.get("149007"));
}
if (storeMgtGoodsAddParam.getShelvesHandle().equals("3") && null == storeMgtGoodsAddParam.getShelvesTime()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "预约上架时间未指定");
}
LocalDateTime now = LocalDateTime.now();
GoblinGoodsInfoVo goodsInfoVo = storeMgtGoodsAddParam.initGoodsInfoVo();
goodsInfoVo.setCreatedBy(currentUid);
goodsInfoVo.setCreatedAt(now);
ArrayList<GoblinGoodsSpecVo> goodsSpecVoList = ObjectUtil.getGoblinGoodsSpecVoArrayList();
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList();
storeMgtGoodsAddParam.initGoodsSkuInfoVo(goodsInfoVo, goodsSkuInfoVoList, goodsSpecVoList);
{// 标签处理
List<String> goodsTagIdList = storeMgtGoodsAddParam.getTagList(),
goodsExtagIdList = storeMgtGoodsAddParam.getExtagList(),
goodsArtagIdList = storeMgtGoodsAddParam.getExtagList();
if (!CollectionUtils.isEmpty(goodsTagIdList)) {
List<GoblinSelfTagVo> selfGoodsTagVos = goblinRedisUtils.getSelfTagVos();
List<GoblinGoodsTagVo> goodsTagVoList = ObjectUtil.getGoblinGoodsTagVoArrayList();
for (int i = 0; i < goodsTagIdList.size(); i++)
for (GoblinSelfTagVo r : selfGoodsTagVos)
if (r.getTagId().equals(goodsTagIdList.get(i)) && r.getTagBelong().equals("0")) {
goodsTagVoList.add(GoblinGoodsTagVo.getNew().copy(r).setSort(i));
break;
}
goodsInfoVo.setTagVoList(goodsTagVoList);
}
if (!CollectionUtils.isEmpty(goodsExtagIdList)) {
List<GoblinSelfTagVo> selfExtagVos = goblinRedisUtils.getSelfExtagVos();
List<GoblinGoodsExtagVo> goodsExtagVoList = ObjectUtil.getGoblinGoodsExtagVoArrayList();
for (int i = 0; i < goodsExtagIdList.size(); i++)
for (GoblinSelfTagVo r : selfExtagVos)
if (r.getTagId().equals(goodsExtagIdList.get(i)) && r.getTagBelong().equals("1") && !r.getTagType().equals("5")) {
goodsExtagVoList.add(GoblinGoodsExtagVo.getNew().copy(r).setSort(i));
break;
}
goodsInfoVo.setExtagVoList(goodsExtagVoList);
}
if (!CollectionUtils.isEmpty(goodsArtagIdList)) {
List<GoblinSelfTagVo> selfExtagVos = goblinRedisUtils.getSelfExtagVos();
List<GoblinGoodsExtagVo> goodsArtagVoList = ObjectUtil.getGoblinGoodsExtagVoArrayList();
for (int i = 0; i < goodsArtagIdList.size(); i++)
for (GoblinSelfTagVo r : selfExtagVos)
if (r.getTagId().equals(goodsArtagIdList.get(i)) && r.getTagBelong().equals("1")) {
goodsArtagVoList.add(GoblinGoodsExtagVo.getNew().copy(r).setSort(i));
break;
}
goodsInfoVo.setArtagVoList(goodsArtagVoList);
}
}
// 服务保障处理
List<String> ssidList = storeMgtGoodsAddParam.getSsidList();
if (!CollectionUtils.isEmpty(ssidList)) {
goodsInfoVo.setServiceSupportVoList(goblinMongoUtils.getServiceSupportVos(ssidList));
}
goblinstoreMgtGoodsService.goodsAdd(goodsInfoVo, goodsSkuInfoVoList);
return ResponseDto.success(goodsInfoVo.getSpuId());
}
@ApiOperationSupport(order = 5)
@ApiOperation(value = "SPU详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "商品ID"),
})
@GetMapping("info")
public ResponseDto<GoblinStoreMgtGoodsInfoVo> info(@NotBlank(message = "店铺ID不能为空") @RequestParam String storeId,
@NotBlank(message = "商品ID不能为空") @RequestParam String spuId) {
if (!goblinRedisUtils.hasStoreId(CurrentUtil.getCurrentUid(), storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (log.isDebugEnabled()) {
log.debug("商品管理:SPU详情:[spuId={}]", spuId);
}
return ResponseDto.success(goblinstoreMgtGoodsService.goodsInfo(storeId, spuId));
}
@ApiOperationSupport(order = 6)
@ApiOperation(value = "商品编辑:SPU编辑", notes = "只修改商品信息,不包含规格相关信息")
@PostMapping("edit_spu")
public ResponseDto<Object> editSpu(@Valid @RequestBody GoblinStoreMgtGoodsAddParam mgtGoodsAddParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtGoodsAddParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (CollectionUtils.isEmpty(mgtGoodsAddParam.getImageList())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品图片不能为空");
}
GoblinGoodsInfoVo mgtGoodsInfoVo;
if (StringUtils.isBlank(mgtGoodsAddParam.getSpuId())
|| null == (mgtGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(mgtGoodsAddParam.getSpuId()))
|| !mgtGoodsInfoVo.getStoreId().equals(storeId)
|| !mgtGoodsInfoVo.getDelFlg().equals("0")) {
return ResponseDto.failure(ErrorMapping.get("149010"));
}
if (!mgtGoodsInfoVo.getName().equals(mgtGoodsAddParam.getName())
// && null != goblinMongoUtils.getMgtGoodsInfoVo(storeId, mgtGoodsAddParam.getName())) {
&& goblinMongoUtils.countMgtGoodsInfoVo(mgtGoodsAddParam.getName()) > 0) {
return ResponseDto.failure(ErrorMapping.get("149007"));
}
if (!mgtGoodsAddParam.getShelvesHandle().equals(mgtGoodsInfoVo.getShelvesHandle())
&& mgtGoodsInfoVo.getShelvesStatus().equals("3")) {
// return ResponseDto.failure(ErrorMapping.get("149016"));
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "上架处理方式只限商品未上架时变更");
}
List<String> skuIdList = mgtGoodsInfoVo.getSkuIdList();
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVos = CollectionUtils.isEmpty(skuIdList) ? null : goblinMongoUtils.getGoodsSkuInfoVos(skuIdList);
boolean hasSkuFlg = !CollectionUtils.isEmpty(goodsSkuInfoVos);
{// 分类、ISBN校验
String cateSid = mgtGoodsAddParam.getCateSid(), cateTid = mgtGoodsAddParam.getCateTid();
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinStoreMgtExtraService.listCategoryVo();
Optional<GoblinSelfGoodsCategoryVo> categoryVoOptional = selfGoodsCategoryVos.stream()
.filter(r -> r.getCateId().equals(mgtGoodsAddParam.getCateFid()) && r.getGrade().equals("1")).findAny();
if (!categoryVoOptional.isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品一级分类无效");
}
GoblinSelfGoodsCategoryVo selfGoodsCategoryVo = categoryVoOptional.get();
if (selfGoodsCategoryVo.getNeIsbn().equals("1") && hasSkuFlg && goodsSkuInfoVos.stream().anyMatch(r -> StringUtils.isBlank(r.getSkuIsbn()))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
if (StringUtils.isNotBlank(cateSid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateSid) && r.getGrade().equals("2")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品二级分类无效");
}
selfGoodsCategoryVo = categoryVoOptional.get();
if (selfGoodsCategoryVo.getNeIsbn().equals("1") && hasSkuFlg && goodsSkuInfoVos.stream().anyMatch(r -> StringUtils.isBlank(r.getSkuIsbn()))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
if (StringUtils.isNotBlank(cateTid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateTid) && r.getGrade().equals("3")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品三级分类无效");
}
selfGoodsCategoryVo = categoryVoOptional.get();
if (selfGoodsCategoryVo.getNeIsbn().equals("1") && hasSkuFlg && goodsSkuInfoVos.stream().anyMatch(r -> StringUtils.isBlank(r.getSkuIsbn()))) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
// if (selfGoodsCategoryVos.stream().noneMatch(r -> r.getCateId().equals(mgtGoodsAddParam.getCateFid()) && r.getGrade().equals("1"))) {
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品分类1无效");
// }
// if (StringUtils.isNotBlank(cateSid) && selfGoodsCategoryVos.stream().noneMatch(r -> r.getCateId().equals(cateSid) && r.getGrade().equals("2"))) {
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品分类2无效");
// }
// if (StringUtils.isNotBlank(cateTid) && selfGoodsCategoryVos.stream().noneMatch(r -> r.getCateId().equals(cateTid) && r.getGrade().equals("3"))) {
// return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品分类3无效");
// }
}
if (log.isDebugEnabled()) {
log.debug("商品管理:商品编辑:SPU编辑:[GoblinStoreMgtGoodsAddParam={}]", JsonUtils.toJson(mgtGoodsAddParam));
}
boolean resultFlg = goblinstoreMgtGoodsService.goodsEditSpu(currentUid, mgtGoodsAddParam, mgtGoodsInfoVo);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
@ApiOperationSupport(order = 7)
@ApiOperation(value = "商品编辑:SKU编辑", notes = "只修改单品信息,不包含商品信息")
@PostMapping("edit_sku")
public ResponseDto<Object> editSku(@Valid @RequestBody GoblinStoreMgtGoodsEditSkuParam mgtGoodsEditSkuParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtGoodsEditSkuParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
String paramSkuId = mgtGoodsEditSkuParam.getSkuId();
GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo;
if (StringUtils.isBlank(paramSkuId)
|| null == (mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(paramSkuId))
|| !mgtGoodsSkuInfoVo.getStoreId().equals(storeId)
|| !mgtGoodsSkuInfoVo.getDelFlg().equals("0")) {
return ResponseDto.failure(ErrorMapping.get("149011"));
}
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(mgtGoodsSkuInfoVo.getSpuId());
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")) {
return ResponseDto.failure(ErrorMapping.get("149010"));
}
{// 分类、ISBN校验
String cateFid = goodsInfoVo.getCateFid(), cateSid = goodsInfoVo.getCateSid(), cateTid = goodsInfoVo.getCateTid();
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinStoreMgtExtraService.listCategoryVo();
Optional<GoblinSelfGoodsCategoryVo> categoryVoOptional = selfGoodsCategoryVos.stream()
.filter(r -> r.getCateId().equals(cateFid) && r.getGrade().equals("1")).findAny();
if (!categoryVoOptional.isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品一级分类无效");
}
if (categoryVoOptional.get().getNeIsbn().equals("1") && StringUtils.isBlank(mgtGoodsEditSkuParam.getSkuIsbn())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
if (StringUtils.isNotBlank(cateSid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateSid) && r.getGrade().equals("2")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品二级分类无效");
}
if (categoryVoOptional.get().getNeIsbn().equals("1") && StringUtils.isBlank(mgtGoodsEditSkuParam.getSkuIsbn())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
if (StringUtils.isNotBlank(cateTid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateTid) && r.getGrade().equals("3")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品三级分类无效");
}
if (categoryVoOptional.get().getNeIsbn().equals("1") && StringUtils.isBlank(mgtGoodsEditSkuParam.getSkuIsbn())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
}
if (log.isDebugEnabled()) {
log.debug("商品管理:商品编辑:SKU编辑:[GoblinStoreMgtGoodsEditSkuParam={}]", JsonUtils.toJson(mgtGoodsEditSkuParam));
}
mgtGoodsEditSkuParam.setStock(mgtGoodsSkuInfoVo.getStock());
mgtGoodsEditSkuParam.setSkuStock(mgtGoodsSkuInfoVo.getSkuStock());
mgtGoodsEditSkuParam.setWarningStock(mgtGoodsSkuInfoVo.getWarningStock());
Integer operStock = mgtGoodsEditSkuParam.getOperStock();
if (null != operStock && operStock != 0) {// 处理库存
int operStockVal = Math.abs(operStock);
Integer stock = mgtGoodsSkuInfoVo.getStock();// 总库存
Integer skuStock = mgtGoodsSkuInfoVo.getSkuStock();// SKU总库存
int surplusStock = goblinRedisUtils.getSkuStock(null, paramSkuId);// 当前剩余库存
if (operStock < 0 && surplusStock > 0 && surplusStock >= operStockVal) {// SKU实时库存充足时允许扣减
if (goblinRedisUtils.decrSkuStock(null, paramSkuId, operStockVal) < 0) {// 过程中库存不足时,回滚库存,编辑无效
goblinRedisUtils.incrSkuStock(null, paramSkuId, operStockVal);
return ResponseDto.failure(ErrorMapping.get("149012"));
} else {
mgtGoodsEditSkuParam.setSkuStock(skuStock - operStockVal);
mgtGoodsEditSkuParam.setStock(stock - operStockVal);
}
} else if (operStock > 0) {// 增加
goblinRedisUtils.incrSkuStock(null, paramSkuId, operStockVal);
mgtGoodsEditSkuParam.setSkuStock(skuStock + operStockVal);
mgtGoodsEditSkuParam.setStock(stock + operStockVal);
} else {
return ResponseDto.failure(ErrorMapping.get("149012"));
}
}
Map<String, String> delSpuSpecMap = CollectionUtil.mapStringString();
Map<String, String> addSpuSpecMap = CollectionUtil.mapStringString();
{// 规格校验、处理
Map<String, String> befSkuSpecNameVnameMap = mgtGoodsSkuInfoVo.getSkuSpecList().stream()
.collect(Collectors.toMap(GoblinGoodsSpecDto::getSpecName, GoblinGoodsSpecDto::getSpecVname));
List<GoblinGoodsSpecDto> paramSkuSpecList = mgtGoodsEditSkuParam.getSkuSpecList();
Set<String> befSkuSpecNameSet = befSkuSpecNameVnameMap.keySet();
Map<String, String> paramUpdateSkuSpecMap = CollectionUtil.mapStringString();
Map<String, String> paramSkuSpecMap = CollectionUtil.mapStringString();
for (GoblinGoodsSpecDto paramSkuSpecDto : paramSkuSpecList) {
String paramSkuSpecDtoSpecName = paramSkuSpecDto.getSpecName();
String paramSkuSpecDtoSpecVname = paramSkuSpecDto.getSpecVname();
if (!befSkuSpecNameSet.contains(paramSkuSpecDtoSpecName)) return ResponseDto.failure(ErrorMapping.get("149014"));
paramSkuSpecMap.put(paramSkuSpecDtoSpecName, paramSkuSpecDtoSpecVname);
if (!befSkuSpecNameVnameMap.get(paramSkuSpecDtoSpecName).equals(paramSkuSpecDtoSpecVname)) {
paramUpdateSkuSpecMap.put(paramSkuSpecDtoSpecName, paramSkuSpecDtoSpecVname);
}
}
if (!paramUpdateSkuSpecMap.isEmpty()) {
List<String> skuIdList = goodsInfoVo.getSkuIdList();// SPU下所有SKUID
ArrayList<String> skuIdListTmp = CollectionUtil.arrayListString();
skuIdListTmp.addAll(skuIdList);
skuIdListTmp.removeIf(r -> r.equals(paramSkuId));
Map<String, Set<String>> remainSkuSpecNameVnameMap = new HashMap<>();
List<GoblinGoodsSkuInfoVo> remainGoodsSkuInfoVos = CollectionUtils.isEmpty(skuIdListTmp)
? ObjectUtil.getGoblinGoodsSkuInfoVoArrayList() : goblinMongoUtils.getGoodsSkuInfoVos(skuIdListTmp);
int remainGoodsSkuInfoVoSize = remainGoodsSkuInfoVos.size();
for (int i = 0; i < remainGoodsSkuInfoVoSize; i++) {
GoblinGoodsSkuInfoVo remainGoodsSkuInfoVo = remainGoodsSkuInfoVos.get(i);
if (remainGoodsSkuInfoVo.getDelFlg().equals("0")) {// 有效SKU
boolean existingSkuSpecFlg = true;
List<GoblinGoodsSpecDto> remainGoodsSkuSpecDtoList = remainGoodsSkuInfoVo.getSkuSpecList();
for (GoblinGoodsSpecDto remainGoodsSkuSpecDto : remainGoodsSkuSpecDtoList) {
String remainGoodsSkuSpecDtoSpecName = remainGoodsSkuSpecDto.getSpecName();
String remainGoodsSkuSpecDtoSpecVname = remainGoodsSkuSpecDto.getSpecVname();
if (!paramSkuSpecMap.get(remainGoodsSkuSpecDtoSpecName).equals(remainGoodsSkuSpecDtoSpecVname)) {
existingSkuSpecFlg = false;// 多个规格中只要又一个规格不一样即通过
}
Set<String> remainSkuSpecVnameTmpSet = remainSkuSpecNameVnameMap.get(remainGoodsSkuSpecDtoSpecName);
if (CollectionUtils.isEmpty(remainSkuSpecVnameTmpSet)) {
remainSkuSpecVnameTmpSet = CollectionUtil.getStringArraySet();
}
remainSkuSpecVnameTmpSet.add(remainGoodsSkuSpecDtoSpecVname);
remainSkuSpecNameVnameMap.put(remainGoodsSkuSpecDtoSpecName, remainSkuSpecVnameTmpSet);
}
if (existingSkuSpecFlg) {
log.warn("商品管理:商品编辑:SKU编辑:重复的规格信息[paramSkuId={},paramSkuSpecMap={} <==> existSkuId={},existSkuSpecDtoList={}]",
paramSkuId, paramSkuSpecMap, remainGoodsSkuInfoVo.getSkuId(), JsonUtils.toJson(remainGoodsSkuSpecDtoList));
return ResponseDto.failure(ErrorMapping.get("149015"));
}
}
}
List<GoblinGoodsSpecVo> spuSpecVoList = goodsInfoVo.getSpecVoList();// SPU规格集
for (Map.Entry<String, String> entrie : paramUpdateSkuSpecMap.entrySet()) {
String paramUpdateSkuSpecName = entrie.getKey(), paramUpdateSkuSpecVname = entrie.getValue();
String befSkuSpecVname = befSkuSpecNameVnameMap.get(paramUpdateSkuSpecName);
Set<String> remainSkuSpecVnameSet = remainSkuSpecNameVnameMap.get(paramUpdateSkuSpecName);
if (CollectionUtils.isEmpty(remainSkuSpecVnameSet) || !remainSkuSpecVnameSet.contains(befSkuSpecVname)) {// 其他SKU规格值中不存在当前编辑SKU旧规格值,则删除该规格值
delSpuSpecMap.put(paramUpdateSkuSpecName, befSkuSpecVname);
for (GoblinGoodsSpecVo spuSpecVo : spuSpecVoList) {
if (spuSpecVo.getSpecName().equals(paramUpdateSkuSpecName)) {
List<GoblinGoodsSpecValueVo> spuSpecVoSpecValueList = spuSpecVo.getSpecValues();
spuSpecVoSpecValueList.removeIf(r -> r.getSpecVname().equals(befSkuSpecVname));
spuSpecVoSpecValueList.sort(Comparator.comparing(GoblinGoodsSpecValueVo::getSpecVsort));
for (int i = 0; i < spuSpecVoSpecValueList.size(); i++)
spuSpecVoSpecValueList.get(i).setSpecVsort(i);
break;
}
}
}
if (CollectionUtils.isEmpty(remainSkuSpecVnameSet) || !remainSkuSpecVnameSet.contains(paramUpdateSkuSpecVname)) {// 其他SKU规格值中不存在当前编辑SKU新规格值,则新增该规格值
addSpuSpecMap.put(paramUpdateSkuSpecName, paramUpdateSkuSpecVname);
for (GoblinGoodsSpecVo spuSpecVo : spuSpecVoList) {
if (spuSpecVo.getSpecName().equals(paramUpdateSkuSpecName)) {
List<GoblinGoodsSpecValueVo> spuSpecVoSpecValueList = spuSpecVo.getSpecValues();
spuSpecVoSpecValueList.add(GoblinGoodsSpecValueVo.getNew().setSpecVname(paramUpdateSkuSpecVname).setSpecVsort(spuSpecVoSpecValueList.size() * 100));
spuSpecVoSpecValueList.sort(Comparator.comparing(GoblinGoodsSpecValueVo::getSpecVsort));
for (int i = 0; i < spuSpecVoSpecValueList.size(); i++)
spuSpecVoSpecValueList.get(i).setSpecVsort(i);
break;
}
}
}
}
} else {
mgtGoodsEditSkuParam.setSkuSpecList(null);
}
}
String buyRoster = mgtGoodsEditSkuParam.getBuyRoster(), befBuyRoster = mgtGoodsSkuInfoVo.getBuyRoster();
if (!mgtGoodsEditSkuParam.getBuyFactor().equals("2") || StringUtils.equals(befBuyRoster, buyRoster) || !buyRoster.startsWith("http")) {
mgtGoodsEditSkuParam.setBuyRoster(null);
}
if (goblinstoreMgtGoodsService.goodsEditSku(currentUid, mgtGoodsEditSkuParam, mgtGoodsSkuInfoVo, goodsInfoVo, delSpuSpecMap, addSpuSpecMap)) {
mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(paramSkuId);
mgtGoodsSkuInfoVo.setSurplusStock(goblinRedisUtils.getSkuStock(null, paramSkuId));
return ResponseDto.success(mgtGoodsSkuInfoVo);
} else {
if (null != operStock && operStock != 0) {// 处理库存:回滚
int operStockVal = Math.abs(operStock);
if (operStock > 0) {// 增加的减回去
goblinRedisUtils.decrSkuStock(null, paramSkuId, operStockVal);
} else {// 扣减的加回去
goblinRedisUtils.incrSkuStock(null, paramSkuId, operStockVal);
}
}
return ResponseDto.failure(ErrorMapping.get("149013"));
}
}
@ApiOperationSupport(order = 8)
@ApiOperation(value = "商品编辑:SKU添加")
@PutMapping("edit_sku/add")
public ResponseDto<Object> editSkuAdd(@Valid @RequestBody GoblinStoreMgtGoodsEditSkuParam mgtGoodsEditSkuParam) {
String currentUid = CurrentUtil.getCurrentUid(), storeId = mgtGoodsEditSkuParam.getStoreId();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (mgtGoodsEditSkuParam.getPrice().compareTo(BigDecimal.ZERO) <= 0
|| mgtGoodsEditSkuParam.getPriceMember().compareTo(BigDecimal.ZERO) <= 0) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "价格无效");
}
if (null == mgtGoodsEditSkuParam.getStock() || mgtGoodsEditSkuParam.getStock() <= 0) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "库存无效");
}
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(mgtGoodsEditSkuParam.getSpuId());
if (null == goodsInfoVo || !goodsInfoVo.getDelFlg().equals("0")
|| !goodsInfoVo.getStoreId().equals(storeId)) {
return ResponseDto.failure(ErrorMapping.get("149010"));
}
{// 分类、ISBN校验
String cateFid = goodsInfoVo.getCateFid(), cateSid = goodsInfoVo.getCateSid(), cateTid = goodsInfoVo.getCateTid();
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinStoreMgtExtraService.listCategoryVo();
Optional<GoblinSelfGoodsCategoryVo> categoryVoOptional = selfGoodsCategoryVos.stream()
.filter(r -> r.getCateId().equals(cateFid) && r.getGrade().equals("1")).findAny();
if (!categoryVoOptional.isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品一级分类无效");
}
if (categoryVoOptional.get().getNeIsbn().equals("1") && StringUtils.isBlank(mgtGoodsEditSkuParam.getSkuIsbn())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
if (StringUtils.isNotBlank(cateSid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateSid) && r.getGrade().equals("2")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品二级分类无效");
}
if (categoryVoOptional.get().getNeIsbn().equals("1") && StringUtils.isBlank(mgtGoodsEditSkuParam.getSkuIsbn())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
if (StringUtils.isNotBlank(cateTid)) {
if (!(categoryVoOptional = selfGoodsCategoryVos.stream().filter(r -> r.getCateId().equals(cateTid) && r.getGrade().equals("3")).findAny()).isPresent()) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "商品三级分类无效");
}
if (categoryVoOptional.get().getNeIsbn().equals("1") && StringUtils.isBlank(mgtGoodsEditSkuParam.getSkuIsbn())) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "请核实输入ISBN");
}
}
}
List<String> skuIdList = goodsInfoVo.getSkuIdList();
List<GoblinGoodsSpecDto> paramSkuSpecDtoList = mgtGoodsEditSkuParam.getSkuSpecList();
for (String skuId : skuIdList) {// 比对所有SKU规格信息
GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (mgtGoodsSkuInfoVo.getSkuSpecList().size() != paramSkuSpecDtoList.size()) {
log.warn("商品管理:商品编辑:SKU添加:规格信息有误[skuSpecMap={},paramSkuSpecMap={}]", JsonUtils.toJson(mgtGoodsSkuInfoVo.getSkuSpecList()), JsonUtils.toJson(paramSkuSpecDtoList));
return ResponseDto.failure(ErrorMapping.get("149014"));
}
Map<String, String> skuSpecMap = mgtGoodsSkuInfoVo.getSkuSpecList().stream()
.collect(Collectors.toMap(GoblinGoodsSpecDto::getSpecName, GoblinGoodsSpecDto::getSpecVname, (k1, k2) -> k2));
boolean diffSpecFlg = false;
for (GoblinGoodsSpecDto goodsSpecDto : paramSkuSpecDtoList) {
String skuSpecVname = skuSpecMap.get(goodsSpecDto.getSpecName());
if (null == skuSpecVname) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "规格无效");
}
if (!skuSpecVname.equals(goodsSpecDto.getSpecVname())) {
diffSpecFlg = true;// 多个规格中只要存在一个不一致,即可跳过,标记为允许添加
break;
}
}
if (!diffSpecFlg) {
log.warn("商品管理:商品编辑:SKU添加:重复的规格信息[skuSpecMap={},paramSkuSpecMap={}]", skuSpecMap, JsonUtils.toJson(paramSkuSpecDtoList));
return ResponseDto.failure(ErrorMapping.get("149015"));
}
}
List<GoblinGoodsSpecVo> specVoList = goodsInfoVo.getSpecVoList();
if (CollectionUtils.isEmpty(specVoList)) {
if (null == specVoList) specVoList = ObjectUtil.getGoblinGoodsSpecVoArrayList();
int size = paramSkuSpecDtoList.size();
for (int i = 0; i < size; i++) {
GoblinGoodsSpecDto specDto = paramSkuSpecDtoList.get(i);
ArrayList<GoblinGoodsSpecValueVo> specValueVoList = ObjectUtil.getGoblinGoodsSpecValueVoArrayList();
specValueVoList.add(GoblinGoodsSpecValueVo.getNew().setSpecVname(specDto.getSpecVname()).setSpecVsort(i));
specVoList.add(GoblinGoodsSpecVo.getNew().setSpecName(specDto.getSpecName()).setSpecSort(i).setSpecValues(specValueVoList));
}
} else {
Map<String, String> paramSkuSpecMap = paramSkuSpecDtoList.stream()
.collect(Collectors.toMap(GoblinGoodsSpecDto::getSpecName, GoblinGoodsSpecDto::getSpecVname, (k1, k2) -> k2));
for (GoblinGoodsSpecVo specVo : specVoList) {// 同步添加SPU规格信息
List<GoblinGoodsSpecValueVo> specValues = specVo.getSpecValues();
String paramSkuSpecVname = paramSkuSpecMap.get(specVo.getSpecName());
if (StringUtils.isBlank(paramSkuSpecVname)) {
return ResponseDto.failure(ErrorCode.HTTP_PARAM_ERROR.getCode(), "规格无效");
}
if (specValues.stream().noneMatch(r -> r.getSpecVname().equals(paramSkuSpecVname))) {
specValues.add(GoblinGoodsSpecValueVo.getNew().setSpecVname(paramSkuSpecVname).setSpecVsort(specValues.size()));
}
}
}
if (log.isDebugEnabled()) {
log.debug("商品管理:商品编辑:SKU添加:[GoblinStoreMgtGoodsEditSkuParam={}]", JsonUtils.toJson(mgtGoodsEditSkuParam));
}
goblinstoreMgtGoodsService.goodsEditSkuAdd(currentUid, mgtGoodsEditSkuParam, goodsInfoVo);
return ResponseDto.success();
}
@ApiOperationSupport(order = 9)
@ApiOperation(value = "商品编辑:SKU删除")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "skuId", value = "单品ID"),
})
@PostMapping("edit_sku/del")
public ResponseDto<Object> editSkuDel(@NotBlank(message = "店铺ID不能为空") String storeId,
@NotBlank(message = "单品ID不能为空") String skuId) {
String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null == mgtGoodsSkuInfoVo || !mgtGoodsSkuInfoVo.getDelFlg().equals("0") || !mgtGoodsSkuInfoVo.getStoreId().equals(storeId)) {
return ResponseDto.failure(ErrorMapping.get("149011"));
}
if (mgtGoodsSkuInfoVo.getShelvesStatus().equals("3")) {
return ResponseDto.failure(ErrorMapping.get("149016"));
}
GoblinGoodsInfoVo mgtGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(mgtGoodsSkuInfoVo.getSpuId());
if (null == mgtGoodsInfoVo || !mgtGoodsInfoVo.getDelFlg().equals("0")) {
log.warn("商品管理:商品编辑:SKU删除警告:SPU不存在或已删除[uid={},skuId={}]", currentUid, skuId);
return ResponseDto.failure(ErrorMapping.get("149010"));
}
boolean delResultFlg = goblinstoreMgtGoodsService.goodsEditSkuDel(currentUid, mgtGoodsSkuInfoVo, mgtGoodsInfoVo);
return delResultFlg ? ResponseDto.success() : ResponseDto.failure(ErrorMapping.get("149003"));
}
// @ApiOperationSupport(order = 10)
// @ApiOperation(value = "商品编辑:SKU批改")
// @ApiImplicitParams({
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "店铺ID"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "商品ID"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "batField", value = "批量修改属性"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "batFieldVal", value = "批量修改属性值"),
// })
// @PostMapping("edit_sku/bat")
// public ResponseDto<Object> editSkuBat(@NotBlank(message = "店铺ID不能为空") String storeId,
// @NotBlank(message = "商品ID不能为空") String spuId,
// @NotBlank(message = "批量修改属性不能为空") String batField,
// @NotBlank(message = "批量修改属性值不能为空") String batFieldVal) {
// if (!goblinRedisUtils.hasStoreId(CurrentUtil.getCurrentUid(), storeId)) {
// return ResponseDto.failure(ErrorMapping.get("149002"));
// }
// goblinstoreMgtGoodsService.goodsEditSkuBat(spuId, batField, batFieldVal)
// return ResponseDto.success();
// }
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinOrderLogVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMoneyService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.HashMap;
@ApiSupport(order = 149102)
@Api(tags = "店铺资金模块")
@Slf4j
@Validated
@RestController
@RequestMapping("store/money")
public class GoblinStoreMoneyController {
@Autowired
IGoblinStoreMoneyService goblinStoreMoneyService;
@GetMapping("money")
@ApiOperation("商品资金总收入")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "spuId", value = "spuId"),
})
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<HashMap<String,String>> money(@RequestParam(value = "spuId", required = false) String spuId) {
return goblinStoreMoneyService.money(spuId);
}
@GetMapping("spu/list")
@ApiOperation("商品资金列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "spuName", value = "商品名称"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "st", value = "起始时间"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "et", value = "终止时间"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数"),
})
public ResponseDto<PageInfo<GoblinOrderLogVo>> getSpuList(@RequestParam(value = "spuName", required = false) String spuName,
@RequestParam(value = "st", required = false) String st,
@RequestParam(value = "et", required = false) String et,
@RequestParam(value = "page") Integer page) {
return goblinStoreMoneyService.getSpuList(spuName, st, et, page);
}
@GetMapping("orderOpera/list")
@ApiOperation("商品订单操作日志列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "spuId", value = "spuId"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderCode", value = "订单号"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "type", value = "交易类型[1-订单交易,2-订单退款,3-正在下单[订单交易],4-正在下单[订单退款]]"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "st", value = "起始时间"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "et", value = "终止时间"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "type2", value = "[1-收入|2-支出]"),
})
public ResponseDto<PageInfo<GoblinOrderLogVo>> getOrderOperaList(@RequestParam(value = "spuId", required = true) String spuId,
@RequestParam(value = "orderCode", required = false) String orderCode,
@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "st", required = false) String st,
@RequestParam(value = "et", required = false) String et,
@RequestParam(value = "page") Integer page) {
return goblinStoreMoneyService.getOrderOperaList(spuId, orderCode, type, st, et, page);
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinMailVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreOrderListVo;
import com.liquidnet.service.goblin.param.RefundCallbackParam;
import com.liquidnet.service.goblin.service.IGoblinOrderService;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreOrderService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
@ApiSupport(order = 149101)
@Api(tags = "店铺-订单")
@Slf4j
@Validated
@RestController
@RequestMapping("store/order")
public class GoblinStoreOrderController {
@Autowired
IGoblinStoreOrderService goblinStoreOrderService;
// @Autowired
// IGoblinOrderService goblinOrderService;
@ApiOperation(value = "订单列表")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderCode", value = "订单编号"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "type", value = "订单类型[0-全部|1-普通订单]"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "cst", value = "下单起始时间"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "cet", value = "下单终止时间"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "expressContacts", value = "收货人姓名"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "phone", value = "手机号"),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "status", value = "订单状态[0-代付款|2-待发货|3-已发货|4-已完成]"),
})
@GetMapping(value = "list")
public ResponseDto<PageInfo<GoblinStoreOrderListVo>> orderList(@RequestParam(value = "page", required = true) @Valid Integer page,
@RequestParam(value = "orderCode", required = false) String orderCode,
@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "cst", required = false) String cst,
@RequestParam(value = "cet", required = false) String cet,
@RequestParam(value = "expressContacts", required = false) String expressContacts,
@RequestParam(value = "phone", required = false) String phone,
@RequestParam(value = "status", required = false) Integer status) {
return goblinStoreOrderService.orderList(page, orderCode, type, cst, cet, expressContacts, phone, status);
}
@ApiOperation(value = "订单详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
})
@GetMapping(value = "details")
public ResponseDto<GoblinStoreOrderListVo> orderDetails(@RequestParam(value = "orderId", required = true) @Valid String orderId) {
return goblinStoreOrderService.orderDetails(orderId);
}
@ApiOperation(value = "取消订单")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
})
@GetMapping(value = "cancel")
public ResponseDto<Boolean> orderCancel(@RequestParam(value = "orderId", required = true) @Valid String orderId) {
return goblinStoreOrderService.orderCancel(orderId);
}
@ApiOperation(value = "修改快递价格")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = true, dataType = "BigDecimal", name = "price", value = "快递金额"),
})
@GetMapping(value = "change/expressPrice")
public ResponseDto<Boolean> changeExpressPrice(@RequestParam(value = "orderId", required = true) @Valid String orderId,
@RequestParam(value = "price", required = true) @Valid BigDecimal price) {
return goblinStoreOrderService.changeExpressPrice(orderId, price);
}
@ApiOperation(value = "修改sku价格")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderSkuId", value = "orderSkuId"),
@ApiImplicitParam(type = "form", required = true, dataType = "BigDecimal", name = "price", value = "修改金额"),
})
@GetMapping(value = "change/skuPrice")
public ResponseDto<Boolean> changeSkuPrice(@RequestParam(value = "orderId", required = true) @Valid String orderId,
@RequestParam(value = "orderSkuId", required = true) @Valid String orderSkuId,
@RequestParam(value = "price", required = true) @Valid BigDecimal price) {
return goblinStoreOrderService.changeSkuPrice(orderId, orderSkuId, price);
}
@ApiOperation(value = "修改收货地址")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "expressAddressDetail", value = "详细快递地址"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "expressContacts", value = "联系人"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "expressPhone", value = "联系人电话"),
})
@GetMapping(value = "change/address")
public ResponseDto<Boolean> changeAddress(@RequestParam(value = "orderId", required = true) @Valid String orderId,
@RequestParam(value = "expressContacts", required = true) @Valid String expressContacts,
@RequestParam(value = "expressPhone", required = true) @Valid String expressPhone,
@RequestParam(value = "expressAddressDetail", required = true) @Valid String expressAddressDetail) {
return goblinStoreOrderService.changeAddress(orderId, expressContacts, expressPhone, expressAddressDetail);
}
@ApiOperation(value = "退款(sku/整单)")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderSkuId", value = "orderSkuId[整单退不传]"),
@ApiImplicitParam(type = "form", required = true, dataType = "BigDecimal", name = "price", value = "退款金额"),
})
@GetMapping(value = "refund/sku")
public ResponseDto<Boolean> refundOrderSku(@RequestParam(value = "orderId", required = true) @Valid String orderId,
@RequestParam(value = "orderSkuId", required = false) String orderSkuId,
@RequestParam(value = "price", required = true) @Valid BigDecimal price) {
return goblinStoreOrderService.refundOrderSku(orderId, orderSkuId, price);
}
@ApiOperation(value = "发货")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "orderSkuIds", value = "逗号隔开orderSkuId"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "mailNo", value = "快递单号"),
})
@GetMapping(value = "express")
public ResponseDto<Boolean> express(@RequestParam(value = "orderId", required = true) @Valid String orderId,
@RequestParam(value = "orderSkuIds", required = false) @Valid String orderSkuIds,
@RequestParam(value = "mailNo", required = true) @Valid String mailNo) {
return goblinStoreOrderService.express(orderId, orderSkuIds, mailNo);
}
@ApiOperation(value = "修改快递单号")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "mailId", value = "快递id"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "mailNo", value = "快递单号"),
})
@GetMapping(value = "express/change")
public ResponseDto<Boolean> changeExpressMailNo(@RequestParam(value = "orderId", required = true) @Valid String orderId,
@RequestParam(value = "mailId", required = false) @Valid String mailId,
@RequestParam(value = "mailNo", required = true) @Valid String mailNo) {
return goblinStoreOrderService.changeExpressMailNo(orderId, mailId, mailNo);
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStorePurchaseCommonParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStorePurchaseParam;
import com.liquidnet.service.goblin.dto.vo.GoblinMarketSpuListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreMarketVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStorePurchaseSkuVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStorePurchasingService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* 商铺活动管理
*/
@ApiSupport(order = 149202)
@Slf4j
@RestController
@Api(tags = "活动-限时秒杀")
@RequestMapping("store/marketing")
public class GoblinStorePurchasingController {
@Autowired
IGoblinStorePurchasingService goblinStorePurchasingService;
@GetMapping("purchasing/list")
@ApiOperation("活动详情-限时秒杀列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "page", value = "页数", example = "1"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "purchaseName", value = "活动名称", example = ""),
@ApiImplicitParam(type = "form", required = false, dataType = "Integer", name = "status", value = "活动状态[-1-全部|0-等待开始|1-活动中|2-活动结束|7-停用]", example = ""),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "startTime", value = "活动开始时间", example = ""),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "endTime", value = "活动结束时间", example = ""),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "createdAt", value = "活动创建时间", example = ""),
})
public ResponseDto<PageInfo<GoblinStoreMarketVo>> purchasingList(@RequestParam(value = "page", required = false) @Valid Integer page,
@RequestParam(value = "purchaseName", required = false) String purchaseName,
@RequestParam(value = "status", required = true) Integer status,
@RequestParam(value = "startTime", required = false) String st,
@RequestParam(value = "endTime", required = false) String et,
@RequestParam(value = "createdAt", required = false) String ct) {
return goblinStorePurchasingService.purchasingList(page, purchaseName, status, st, et, ct);
}
@PostMapping("purchasing/status")
@ApiOperation("活动操作-限时秒杀")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = ""),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = ""),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "status", value = "活动状态[0-等待开始(启用)|7-停用|-1-删除]", example = ""),
})
public ResponseDto<Boolean> purchasingStatus(@RequestParam(value = "marketId") @Valid String marketId,
@RequestParam(value = "storeId") @Valid String storeId,
@RequestParam(value = "status") @Valid Integer status) {
return goblinStorePurchasingService.purchasingStatus(marketId, storeId, status);
}
@PostMapping("purchasing")
@ApiOperation("创建活动-限时秒杀")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<Boolean> purchasingInsert(@RequestBody GoblinStorePurchaseParam goblinStorePurchaseParam) {
return goblinStorePurchasingService.purchasingInsert(goblinStorePurchaseParam.getName(), goblinStorePurchaseParam.getStoreId(), goblinStorePurchaseParam.getStartTime(), goblinStorePurchaseParam.getEndTime(), goblinStorePurchaseParam.getIsPre(), goblinStorePurchaseParam.getPreTime());
}
@PutMapping("purchasing")
@ApiOperation("修改活动-限时秒杀")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<String> purchasingUpdate(@RequestBody GoblinStorePurchaseParam goblinStorePurchaseParam) {
goblinStorePurchasingService.purchasingUpdate(goblinStorePurchaseParam.getMarketId(), goblinStorePurchaseParam.getName(), goblinStorePurchaseParam.getStoreId(), goblinStorePurchaseParam.getStartTime(), goblinStorePurchaseParam.getEndTime(), goblinStorePurchaseParam.getIsPre(), goblinStorePurchaseParam.getPreTime());
return ResponseDto.success();
}
@GetMapping("purchasing/details")
@ApiOperation("活动详情-限时秒杀")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
})
public ResponseDto<GoblinStoreMarketVo> purchasingDetails(@RequestParam("marketId") @Valid String marketId) {
return goblinStorePurchasingService.purchasingDetails(marketId);
}
@GetMapping("purchasing/spu")
@ApiOperation("活动详情-限时秒杀-spu列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数", example = "1"),
})
public ResponseDto<List<GoblinMarketSpuListVo>> purchasingSpuList(@RequestParam("marketId") @Valid String marketId,
@RequestParam("storeId") @Valid String storeId,
@RequestParam("page") @Valid Integer page) {
return goblinStorePurchasingService.purchasingSpuList(marketId, storeId, page);
}
@GetMapping("purchasing/sku")
@ApiOperation("活动详情-限时秒杀-sku列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuMarketId", example = "1"),
})
public ResponseDto<List<GoblinStorePurchaseSkuVo>> purchasingSkuList(@RequestParam("marketId") @Valid String marketId,
@RequestParam("storeId") @Valid String storeId,
@RequestParam("spuMarketId") @Valid String spuId) {
return goblinStorePurchasingService.purchasingSkuList(marketId, storeId, spuId);
}
@PostMapping("purchasing/sku")
@ApiOperation("活动详情-限时秒杀-sku新增")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<Boolean> purchasingSkuInsert(@RequestBody GoblinStorePurchaseCommonParam params) {
return goblinStorePurchasingService.purchasingSkuInsert(params);
}
@PutMapping("purchasing/sku")
@ApiOperation("活动详情-限时秒杀-sku修改")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<Boolean> purchasingSkuUpdate(@RequestBody GoblinStorePurchaseCommonParam params) {
return goblinStorePurchasingService.purchasingSkuUpdate(params);
}
@DeleteMapping("purchasing/spu")
@ApiOperation("活动详情-限时秒杀-spu删除")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1")
})
public ResponseDto<Boolean> purchasingSpuDel(@RequestParam("marketId") @Valid String marketId,
@RequestParam("storeId") @Valid String storeId,
@RequestParam("spuId") @Valid String spuId) {
return goblinStorePurchasingService.purchasingSpuDel(marketId, storeId, spuId);
}
}
package com.liquidnet.service.goblin.controller.manage;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreZhengzaiCommonParam;
import com.liquidnet.service.goblin.dto.vo.GoblinMarketSpuListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfMarketingVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfZhengzaiSkuVo;
import com.liquidnet.service.goblin.service.manage.IGoblinZhengzaiService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* 正在下单活动管理
*/
@ApiSupport(order = 149201)
@Slf4j
@RestController
@Api(tags = "活动-正在下单")
@RequestMapping("store/zhengzai")
public class GoblinZhengzaiController {
@Autowired
IGoblinZhengzaiService goblinZhengzaiService;
@GetMapping("list")
@ApiOperation("活动详情-正在下单-可参与活动列表")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1")
})
public ResponseDto<List<GoblinSelfMarketingVo>> zhengzaiCanJoin(@RequestParam("storeId") @Valid String storeId) {
return ResponseDto.success(goblinZhengzaiService.zhengzaiCanJoin(storeId));
}
@GetMapping("detals")
@ApiOperation("活动详情-正在下单-可参与活动详情")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1")
})
public ResponseDto<GoblinSelfMarketingVo> zhengzaiCanJoinDetails(@RequestParam("storeId") @Valid String storeId,
@RequestParam("selfMarketId") @Valid String selfMarketId) {
return ResponseDto.success(goblinZhengzaiService.zhengzaiCanJoinDetails(selfMarketId, storeId));
}
@GetMapping("config/spu")
@ApiOperation("活动详情-正在下单-获取商铺spu")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integer", name = "page", value = "页数", example = "1")
})
public ResponseDto<PageInfo<GoblinMarketSpuListVo>> zhengzaiStoreConfigSpuList(@RequestParam("storeId") @Valid String storeId,
@RequestParam("selfMarketId") @Valid String selfMarketId,
@RequestParam("page") @Valid int page) {
return goblinZhengzaiService.zhengzaiSpuList(selfMarketId, storeId, page);
}
@GetMapping("config/sku")
@ApiOperation("活动详情-正在下单-获取商铺sku")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1")
})
public ResponseDto<List<GoblinSelfZhengzaiSkuVo>> zhengzaiStoreConfigSkuList(@RequestParam("storeId") @Valid String storeId,
@RequestParam("spuId") @Valid String spuId,
@RequestParam("selfMarketId") @Valid String selfMarketId) {
return goblinZhengzaiService.zhengzaiSkuList(selfMarketId, storeId, spuId);
}
@PostMapping("config/insert")
@ApiOperation("活动详情-正在下单-添加商铺sku")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<Boolean> zhengzaiStoreInsert(@RequestBody GoblinStoreZhengzaiCommonParam params) {
return goblinZhengzaiService.zhengzaiSkuInsert(params);
}
@PostMapping("config/update")
@ApiOperation("活动详情-正在下单-修改商铺sku")
@ApiResponse(code = 200, message = "接口返回对象参数")
public ResponseDto<Boolean> zhengzaiStoreUpdate(@RequestBody GoblinStoreZhengzaiCommonParam params) {
return goblinZhengzaiService.zhengzaiSkuUpdate(params);
}
@PostMapping("config/del")
@ApiOperation("活动详情-正在下单-删除商铺spu")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "storeId", value = "商铺id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "selfMarketId", value = "官方活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1"),
})
public ResponseDto<Boolean> zhengzaiStoreDel(@RequestParam("storeId") @Valid String storeId,
@RequestParam("selfMarketId") @Valid String selfMarketId,
@RequestParam("spuId") @Valid String spuId) {
return goblinZhengzaiService.zhengzaiSpuDel(selfMarketId, storeId, spuId);
}
}
package com.liquidnet.service.goblin.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
@Getter
@Setter
@EqualsAndHashCode
public class GoblinStoreMgtCouponListVoExcel implements Serializable, Cloneable {
private static final long serialVersionUID = 3264197773499339729L;
@ExcelProperty("卡券编码")
private String storeCouponNo;
@ExcelProperty("卡券名称")
private String title;
@ExcelProperty("卡券状态")
private String state;
@ExcelProperty("开始时间")
private String startTime;
@ExcelProperty("结束时间")
private String endTime;
@ExcelProperty("创建时间")
private String createdAt;
@ExcelProperty("领取数量")
private int receiveNum;
@ExcelProperty("使用数量")
private int usedNum;
@ExcelProperty("总库存")
private Integer stock;
private static final GoblinStoreMgtCouponListVoExcel obj = new GoblinStoreMgtCouponListVoExcel();
public static GoblinStoreMgtCouponListVoExcel getNew() {
try {
return (GoblinStoreMgtCouponListVoExcel) obj.clone();
} catch (CloneNotSupportedException e) {
return new GoblinStoreMgtCouponListVoExcel();
}
}
public GoblinStoreMgtCouponListVoExcel copy(GoblinStoreMgtCouponListVo source) {
if (null == source) return this;
this.setStoreCouponNo(source.getStoreCouponNo());
this.setTitle(source.getTitle());
switch (source.getState()) {
case "0":
this.setState("等待开始");break;
case "1":
this.setState("活动中");break;
case "2":
this.setState("活动结束");break;
case "3":
this.setState("已上架");break;
default:
this.setState("停用");break;
}
DateUtil.Formatter yyyyMMddHHmmss = DateUtil.Formatter.yyyyMMddHHmmss;
this.setStartTime(yyyyMMddHHmmss.format(source.getStartTime()));
this.setEndTime(yyyyMMddHHmmss.format(source.getEndTime()));
this.setCreatedAt(yyyyMMddHHmmss.format(source.getCreatedAt()));
this.setReceiveNum(source.getReceiveNum());
this.setUsedNum(source.getUsedNum());
this.setStock(source.getStock());
return this;
}
}
package com.liquidnet.service.goblin.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.math.BigDecimal;
@Getter
@Setter
@EqualsAndHashCode
public class GoblinStoreMgtGoodsListVoExcel implements Serializable, Cloneable {
private static final long serialVersionUID = -5926827517337445529L;
@ExcelProperty("店铺ID")
private String storeId;
@ExcelProperty("商品ID")
private String spuId;
@ExcelProperty("商品编码")
private String spuNo;
@ExcelProperty("封面图片")
private String coverPic;
@ExcelProperty("商品名称")
private String name;
@ExcelProperty("分类")
private String cateMerge;
@ExcelProperty("价格区间")
private String priceRange;
// @ExcelProperty("审核状态")
// private String status;
// @ExcelProperty("审核拒绝原因")
// private String reason;
@ExcelProperty("上架状态")
private String shelvesStatus;
@ExcelProperty("总库存")
private Integer totalStock;
@ExcelProperty("剩余库存")
private Integer surplusStock;
private static final GoblinStoreMgtGoodsListVoExcel obj = new GoblinStoreMgtGoodsListVoExcel();
public static GoblinStoreMgtGoodsListVoExcel getNew() {
try {
return (GoblinStoreMgtGoodsListVoExcel) obj.clone();
} catch (CloneNotSupportedException e) {
return new GoblinStoreMgtGoodsListVoExcel();
}
}
public GoblinStoreMgtGoodsListVoExcel copy(GoblinStoreMgtGoodsListVo source) {
if (null == source) return this;
this.setStoreId(source.getStoreId());
this.setSpuId(source.getSpuId());
this.setSpuNo(source.getSpuNo());
this.setCoverPic(source.getCoverPic());
this.setName(source.getName());
this.setCateMerge(StringUtils.defaultString(source.getCateFid(), "") + "/"
+ StringUtils.defaultString(source.getCateSid(), "") + "/"
+ StringUtils.defaultString(source.getCateTid(), ""));
this.setPriceRange("¥" + source.getPriceGe().toString() + " - ¥" + source.getPriceLe().toString());
switch (source.getShelvesStatus()) {
case "0":
this.setShelvesStatus("待上架");break;
case "1":
this.setShelvesStatus("已下架");break;
case "2":
this.setShelvesStatus("违规");break;
case "3":
this.setShelvesStatus("已上架");break;
default:
this.setShelvesStatus("其它");break;
}
this.setTotalStock(source.getTotalStock());
this.setSurplusStock(source.getSurplusStock());
return this;
}
}
package com.liquidnet.service.goblin.service.impl;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.IGoblinAppZhengzaiService;
import com.liquidnet.service.goblin.util.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import static com.liquidnet.commons.lang.util.DateUtil.DTF_YMD_HMS;
@Service
public class GoblinAppZhengzaiServiceImpl implements IGoblinAppZhengzaiService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinOrderUtils orderUtils;
@Override
public List<GoblinSelfMarketingVo> getZhengzaiMarketList() {
List<GoblinSelfMarketingVo> list = redisUtils.getGoblinSelfMarketingVoList();
List<GoblinSelfMarketingVo> voList = ObjectUtil.getGoblinSelfMarketingVoList();
LocalDateTime now = LocalDateTime.now();
for (GoblinSelfMarketingVo item : list) {
if (LocalDateTime.parse(item.getStartTime(), DTF_YMD_HMS).isBefore(now) && LocalDateTime.parse(item.getEndTime(), DTF_YMD_HMS).isAfter(now) && (item.getStatus() == null || item.getStatus() != 7)) {
voList.add(item);
}
}
return voList;
}
@Override
public List<GoblinShowStoreInfoVo> getStoreList(String marketId) {
List<GoblinMarketRelationVo> relationVo = redisUtils.getMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketId);
List<String> storeIdList = relationVo.stream().map(GoblinMarketRelationVo::getStoreId).distinct().collect(Collectors.toList());
List<GoblinShowStoreInfoVo> voList = ObjectUtil.getGoblinShowStoreInfoVoArrayList();
for (String storeId : storeIdList) {
if (storeId == null) {
continue;
}
GoblinStoreInfoVo vo = redisUtils.getStoreInfoVo(storeId);
if (vo.getStatus().equals("5") || vo.getStatus().equals("3")) {
GoblinShowStoreInfoVo returnVo = GoblinShowStoreInfoVo.getNew();
BeanUtils.copyProperties(vo, returnVo);
voList.add(returnVo);
}
}
return voList;
}
@Override
public List<GoblinZhengzaiGoodVo> getSpuList(String marketId, String storeId) {
List<GoblinMarketRelationVo> relationVo = redisUtils.getMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketId);
List<String> spuIdList = relationVo.stream().map(GoblinMarketRelationVo::getSpuId).collect(Collectors.toList());
List<GoblinZhengzaiGoodVo> voList = ObjectUtil.getGoblinZhengzaiGoodVoArrayList();
for (String spuId : spuIdList) {
GoblinGoodsInfoVo vo = redisUtils.getGoodsInfoVo(spuId);
if (vo.getShelvesStatus().equals("3") && storeId.equals(vo.getStoreId())) {
GoblinZhengzaiGoodVo returnVo = GoblinZhengzaiGoodVo.getNew();
BeanUtils.copyProperties(vo, returnVo);
voList.add(returnVo);
}
}
return voList;
}
@Override
public ResponseDto<Boolean> orderPush(String offCode, String marketId) {
String[] orderIds = redisUtils.getOffCode(offCode);
LocalDateTime now = LocalDateTime.now();
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlDataOrder = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> sqlDataSku = CollectionUtil.linkedListObjectArr();
sqls.add(SqlMapping.get("goblin_order.store.orderStatus"));
sqls.add(SqlMapping.get("goblin_order.store.orderSkuStatus"));
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("参数错误");
}
if (orderIds == null) {
return ResponseDto.failure("订单不存在");
} else {
for (String orderId : orderIds) {
GoblinStoreOrderVo storeOrderVo = redisUtils.getGoblinOrder(orderId);
if (!storeInfoVo.getStoreId().equals(storeOrderVo.getStoreId())) {
return ResponseDto.failure("店铺异常");
}
if (storeOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_STATUS_0.getValue())) {
return ResponseDto.failure("出货失败,订单未支付");
}
if (storeOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_STATUS_4.getValue())) {
return ResponseDto.failure("出货失败,订单已核销");
}
if (!storeOrderVo.getMarketId().equals(marketId)) {
return ResponseDto.failure("出货失败,活动不符");
}
storeOrderVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_4.getValue());
sqlDataOrder.add(new Object[]{
storeOrderVo.getStatus(), now,
storeOrderVo.getOrderId(), now, now
});
List<String> skuIds = storeOrderVo.getOrderSkuVoIds();
for (String skuId : skuIds) {
GoblinOrderSkuVo skuInfoVo = redisUtils.getGoblinOrderSkuVo(skuId);
skuInfoVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_4.getValue());
sqlDataSku.add(new Object[]{
skuInfoVo.getStatus(), now,
skuInfoVo.getOrderSkuId(), now, now
});
redisUtils.setGoblinOrderSku(skuInfoVo.getOrderSkuId(), skuInfoVo);
mongoUtils.updateGoblinOrderSkuVo(skuInfoVo.getOrderSkuId(), skuInfoVo);
}
redisUtils.setGoblinOrder(storeOrderVo.getOrderId(), storeOrderVo);
mongoUtils.updateGoblinStoreOrderVo(storeOrderVo.getOrderId(), storeOrderVo);
}
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.gets(sqls, sqlDataOrder, sqlDataSku));
}
return ResponseDto.success(true);
}
@Override
public ResponseDto<List<GoblinZhengzaiPushVo>> orderPushDetails(String offCode, String marketId) {
String[] orderIds = redisUtils.getOffCode(offCode);
List<GoblinZhengzaiPushVo> listVo = ObjectUtil.getGoblinZhengzaiPushVoArrayList();
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("参数错误");
}
if (orderIds == null) {
return ResponseDto.failure("订单不存在");
} else {
for (String orderId : orderIds) {
GoblinStoreOrderVo storeOrderVo = redisUtils.getGoblinOrder(orderId);
if (!storeInfoVo.getStoreId().equals(storeOrderVo.getStoreId())) {
return ResponseDto.failure("店铺异常");
}
if (storeOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_STATUS_0.getValue())) {
return ResponseDto.failure("订单未支付");
}
// if (storeOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_STATUS_4.getValue())) {
// return ResponseDto.failure("出货失败,订单已核销");
// }
if (!storeOrderVo.getMarketId().equals(marketId)) {
return ResponseDto.failure("活动不符");
}
List<String> skuIds = storeOrderVo.getOrderSkuVoIds();
for (String skuId : skuIds) {
GoblinZhengzaiPushVo vo = GoblinZhengzaiPushVo.getNew();
GoblinOrderSkuVo skuInfoVo = redisUtils.getGoblinOrderSkuVo(skuId);
vo.setSkuName(skuInfoVo.getSkuName());
vo.setNum(skuInfoVo.getNum());
vo.setSkuSpecs(skuInfoVo.getSkuSpecs());
vo.setSpuName(skuInfoVo.getSpuName());
vo.setStatus(skuInfoVo.getStatus());
listVo.add(vo);
}
}
}
return ResponseDto.success(listVo);
}
@Override
public ResponseDto<Boolean> orderBind(String uid, String masterCode) {
String[] orderIds = redisUtils.getMasterCode(masterCode);
LocalDateTime now = LocalDateTime.now();
BigDecimal priceActual = BigDecimal.ZERO;
if (orderIds == null) {
return ResponseDto.failure("订单不存在");
} else {
for (String orderId : orderIds) {
GoblinStoreOrderVo storeOrderVo = redisUtils.getGoblinOrder(orderId);
if (storeOrderVo.getUserId().equals(uid)) {
continue;
}
storeOrderVo.setUserId(orderId);
priceActual = priceActual.add(storeOrderVo.getPriceActual());
//mongo
mongoUtils.updateGoblinStoreOrderVo(storeOrderVo.getOrderId(), storeOrderVo);
//redis
redisUtils.setGoblinOrder(storeOrderVo.getOrderId(), storeOrderVo);
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.zhengzai.bind",
uid, now, storeOrderVo.getOrderId(), now, now));
}
if (priceActual.compareTo(BigDecimal.ZERO) != 0) {
orderUtils.doTask(uid, priceActual);
}
}
return ResponseDto.success();
}
}
package com.liquidnet.service.goblin.service.impl;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.param.BackCouponParam;
import com.liquidnet.service.goblin.service.GoblinCouponService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
@Slf4j
@Service
public class GoblinCouponImpl implements GoblinCouponService {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
QueueUtils queueUtils;
@Override
public ArrayList<String> getSpuType(String spuId, String storeId) {
ArrayList<String> returnList = CollectionUtil.arrayListString();
String pre = GoblinStatusConst.MarketPreStatus.getPre(spuId);
if (pre != null) {
spuId = spuId.split(pre)[0];
}
List<GoblinStoreCouponVo> listVo = goblinRedisUtils.getGoodsMarketsForCoupon(spuId, storeId);
LocalDateTime now = LocalDateTime.now();
for (GoblinStoreCouponVo vo : listVo) {
if (!returnList.contains(vo.getType()) && "1".equals(vo.getReceiveCurb())
&& now.isAfter(vo.getStartTime()) && now.isBefore(vo.getEndTime())) {
returnList.add(vo.getType());
}
}
return returnList;
}
@Override
public ArrayList<GoblinStoreCouponVo> getSpuByType(String spuId, String storeId, String type) {
ArrayList<GoblinStoreCouponVo> returnList = ObjectUtil.getGoblinStoreCouponVoArrayList();
String pre = GoblinStatusConst.MarketPreStatus.getPre(spuId);
if (pre != null) {
spuId = spuId.split(pre)[0];
}
List<GoblinStoreCouponVo> listVo = goblinRedisUtils.getGoodsMarketsForCoupon(spuId, storeId);
LocalDateTime now = LocalDateTime.now();
for (GoblinStoreCouponVo vo : listVo) {
if ((vo.getType().equals(type) || type.equals("0")) && "1".equals(vo.getReceiveCurb())
&& now.isAfter(vo.getStartTime()) && now.isBefore(vo.getEndTime())) {
vo.setStock(null);
returnList.add(vo);
}
}
return returnList;
}
@Override
public Boolean receiveCoupon(String uid, List<GoblinUserCouponVo> userCouponVoList, GoblinStoreCouponVo storeCouponVo) {
String storeCouponId = storeCouponVo.getStoreCouponId();
if (storeCouponVo.getStock().equals(0) || goblinRedisUtils.decrStoreCouponStock(storeCouponId, 1) >= 0) {
LocalDateTime now = LocalDateTime.now();
GoblinUserCouponBasicVo receiveUserCouponBasicVo = GoblinUserCouponBasicVo.getNew().initByStoreCouponVo(storeCouponVo);
receiveUserCouponBasicVo.setUid(uid);
receiveUserCouponBasicVo.setBindAt(now);
receiveUserCouponBasicVo.setOperator(uid);
receiveUserCouponBasicVo.setCreatedAt(now);
userCouponVoList.add(GoblinUserCouponVo.getNew().copy(receiveUserCouponBasicVo));
// long s = System.nanoTime();
goblinMongoUtils.insertUserCouponVo(receiveUserCouponBasicVo);
// log.info("MDB.I耗时:{}ms", (System.nanoTime() - s) / 1000000);
// s = System.nanoTime();
goblinRedisUtils.setUserCouponVos(uid, userCouponVoList);
// log.info("RDS.S耗时:{}ms", (System.nanoTime() - s) / 1000000);
LinkedList<Object[]> initUserCouponObjs = CollectionUtil.linkedListObjectArr();
initUserCouponObjs.add(new Object[]{
receiveUserCouponBasicVo.getUcouponId(), receiveUserCouponBasicVo.getStoreCouponId(), receiveUserCouponBasicVo.getUid(),
receiveUserCouponBasicVo.getState(), receiveUserCouponBasicVo.getBindAt(), receiveUserCouponBasicVo.getDuedAt(),
receiveUserCouponBasicVo.getOperator(), receiveUserCouponBasicVo.getCreatedAt()
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_user_coupon.insert", initUserCouponObjs));
return true;
}
if (!storeCouponVo.getStock().equals(0)) {
goblinRedisUtils.incrStoreCouponStock(storeCouponId, 1);
}
return false;
}
@Override
public List<GoblinUserCouponVo> getList(String type) {
String uid = CurrentUtil.getCurrentUid();
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid);
List<GoblinUserCouponVo> returnList = ObjectUtil.getGoblinUserCouponVo();
// HashMap<String, String> storeIdNameMap = CollectionUtil.mapStringString();
// GoblinStoreInfoVo storeInfoVoTmp;
for (GoblinUserCouponVo vo : voList) {
// if (StringUtils.isNotEmpty(vo.getStoreId())) {
// storeInfoVoTmp = goblinRedisUtils.getStoreInfoVo(vo.getStoreId());
// vo.setStoreName(storeIdNameMap.getOrDefault(vo.getStoreId(), null == storeInfoVoTmp ? null : storeInfoVoTmp.getStoreName()));
// }
if ("1".equals(type)) {
if (vo.getState().equals(1)) {
returnList.add(vo);
}
} else {
if (vo.getState().equals(3) || vo.getState().equals(5)) {
returnList.add(vo);
}
}
}
return returnList;
}
@Override
public GoblinUserCouponVo canUse(BigDecimal totalPrice, String spuId, String uid, String storeId) {
BigDecimal maxPrice = BigDecimal.ZERO;
GoblinUserCouponVo returnVo = GoblinUserCouponVo.getNew();
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid);
for (GoblinUserCouponVo vo : voList) {
//判断券状态 和 触发金额
if (vo.getState().equals(1) && vo.getTriggers().compareTo(totalPrice) <= 0 && vo.getStoreId().equals(storeId)) {
if (vo.getUseScope().equals("0")) {
BigDecimal tempPrice = BigDecimal.ZERO;
if (vo.getType().equals("1")) {//代金券
tempPrice = vo.getValFace();
} else if (vo.getType().equals("2")) {//折扣
tempPrice = totalPrice.multiply(vo.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP);
if (tempPrice.compareTo(vo.getDeduction()) > 0) {
tempPrice = vo.getDeduction();
}
} else if (vo.getType().equals("3") && vo.getTriggers().compareTo(totalPrice) <= 0) {//满减
tempPrice = vo.getValMinus();
}
if (maxPrice.compareTo(tempPrice) < 0) {
maxPrice = tempPrice;
returnVo = vo;
}
} else {
List<String> spuIds = goblinRedisUtils.getStoreCouponSpuIds(vo.getStoreCouponId());
if (spuId == null) {
continue;
}
//判断是否在可用商品内
for (String item : spuIds) {
List<String> spuList = Arrays.asList(spuId.split(","));
if (spuList.contains(item)) {
BigDecimal tempPrice = BigDecimal.ZERO;
if (vo.getType().equals("1")) {//代金券
tempPrice = vo.getValFace();
} else if (vo.getType().equals("2")) {//折扣
tempPrice = totalPrice.multiply(vo.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP);
if (tempPrice.compareTo(vo.getDeduction()) > 0) {
tempPrice = vo.getDeduction();
}
} else if (vo.getType().equals("3") && vo.getTriggers().compareTo(totalPrice) <= 0) {//满减
tempPrice = vo.getValMinus();
}
if (maxPrice.compareTo(tempPrice) < 0) {
maxPrice = tempPrice;
returnVo = vo;
}
}
}
}
}
}
return returnVo;
}
@Override
public List<GoblinUserCouponVo> useList(BigDecimal totalPrice, String spuId, String uid) {
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid);
List<GoblinUserCouponVo> returnList = ObjectUtil.getGoblinUserCouponVo();
for (GoblinUserCouponVo vo : voList) {
//判断券状态 和 触发金额
if (vo.getState().equals(1) && vo.getTriggers().compareTo(totalPrice) <= 0) {
if (vo.getUseScope().equals("0")) {
returnList.add(vo);
} else {
List<String> spuIds = goblinRedisUtils.getStoreCouponSpuIds(vo.getStoreCouponId());
if (spuId == null) {
break;
}
//判断是否在可用商品内
for (String item : spuIds) {
List<String> spuList = Arrays.asList(spuId.split(","));
if (spuList.contains(item)) {
returnList.add(vo);
break;
}
}
}
}
}
returnList.sort(Comparator.comparing(GoblinUserCouponVo::getState));
return returnList;
}
@Override
public GoblinUseResultVo useCoupon(String ucouponId, String content, BigDecimal totalPrice, String spuId, String uid) {
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid);
GoblinUseResultVo returnVo = GoblinUseResultVo.getNew();
returnVo.setValue(BigDecimal.ZERO);
returnVo.setCouType("-1");
for (GoblinUserCouponVo vo : voList) {
if (vo.getUcouponId().equals(ucouponId)) {
//判断券状态 和 触发金额
if ((vo.getState().equals(1)) && vo.getTriggers().compareTo(totalPrice) <= 0) {
if (vo.getUseScope().equals("0")) {
if (vo.getType().equals("1")) {//代金券
returnVo.setValue(vo.getValFace());
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("2")) {//折扣
BigDecimal tempPrice = totalPrice.multiply(vo.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP);
if (tempPrice.compareTo(vo.getDeduction()) > 0) {
tempPrice = vo.getDeduction();
}
returnVo.setValue(tempPrice);
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("3") && vo.getTriggers().compareTo(totalPrice) <= 0) {//满减
returnVo.setValue(vo.getValMinus());
returnVo.setCouType(vo.getType());
}
vo.setState(5);
vo.setUsedFor(content);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now(), vo.getUcouponId()));
break;
} else {
List<String> spuIds = goblinRedisUtils.getStoreCouponSpuIds(vo.getStoreCouponId());
if (spuId == null) {
continue;
}
//判断是否在可用商品内
List<String> spuList = Arrays.asList(spuId.split(","));
for (String item : spuIds) {
if (spuList.contains(item)) {
if (vo.getType().equals("1")) {//代金券
returnVo.setValue(vo.getValFace());
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("2")) {//折扣
BigDecimal tempPrice = totalPrice.multiply(vo.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP);
if (tempPrice.compareTo(vo.getDeduction()) > 0) {
tempPrice = vo.getDeduction();
}
returnVo.setValue(tempPrice);
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("3") && vo.getTriggers().compareTo(totalPrice) <= 0) {//满减
returnVo.setValue(vo.getValMinus());
returnVo.setCouType(vo.getType());
}
vo.setState(5);
vo.setUsedFor(content);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now(), vo.getUcouponId()));
}
break;
}
}
}
break;
}
}
if (!returnVo.getCouType().equals("-1")) {
goblinRedisUtils.setUserCouponVos(uid, voList);
}
return returnVo;
}
@Override
public Boolean backCoupon(List<BackCouponParam> params) {
try {
for (BackCouponParam item : params) {
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(item.getUid());
for (GoblinUserCouponVo vo : voList) {
if (vo.getUcouponId().equals(item.getuCouponIds())) {
if (LocalDateTime.now().isBefore(vo.getDuedAt())) {
vo.setState(1);
vo.setUsedFor("");
goblinRedisUtils.setUserCouponVos(item.getUid(), voList);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now(), vo.getUcouponId()));
}
break;
}
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
package com.liquidnet.service.goblin.service.impl;
import com.alibaba.fastjson.JSON;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.*;
import com.liquidnet.service.goblin.enums.GoblinStoreConf;
import com.liquidnet.service.goblin.service.GoblinCouponService;
import com.liquidnet.service.goblin.service.GoblinFrontService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import com.mongodb.BasicDBObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Collation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Pattern;
@Service
@Slf4j
public class GoblinFrontServiceImpl implements GoblinFrontService {
@Autowired
private RedisUtil redisUtil;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
GoblinCouponService goblinCouponService;
@Override
public ArrayList<GoblinFrontBannerVo> getListBanner() {
List<GoblinFrontBanner> list=goblinRedisUtils.getListBanner();
if(null==list){
return null;
}
LocalDateTime nowTime= LocalDateTime.now();
ArrayList<GoblinFrontBanner> goblinFrontBannerArrayList= ObjectUtil.getGoblinFrontBannerArrayList();
//查看是否有失效的时间
for(GoblinFrontBanner goblinFrontBanner:list){
if(null!=goblinFrontBanner.getEndTime()&&null!=goblinFrontBanner.getStartTime()){
if( nowTime.isAfter(goblinFrontBanner.getEndTime())){
}else{
if(nowTime.isBefore(goblinFrontBanner.getStartTime())){
}else{
goblinFrontBannerArrayList.add(goblinFrontBanner);
}
}
}else{
goblinFrontBannerArrayList.add(goblinFrontBanner);
}
}
ArrayList<GoblinFrontBannerVo> list1= ObjectUtil.goblinFrontBannerVoArrayList();
for(GoblinFrontBanner goblinFrontBanner:goblinFrontBannerArrayList){
GoblinFrontBannerVo goblinFrontBannerVo=GoblinFrontBannerVo.getNew();
BeanUtils.copyProperties(goblinFrontBanner,goblinFrontBannerVo);
list1.add(goblinFrontBannerVo);
}
return list1;
}
public ArrayList<GoblinFrontBannerVo> getMiddleBanner() {
List<GoblinFrontBanner> list=goblinRedisUtils.getMiddleBanner();
if(null==list){
return null;
}
LocalDateTime nowTime= LocalDateTime.now();
ArrayList<GoblinFrontBanner> goblinFrontBannerArrayList= ObjectUtil.getGoblinFrontBannerArrayList();
//查看是否有失效的时间
for(GoblinFrontBanner goblinFrontBanner:list){
if(null!=goblinFrontBanner.getEndTime()){
if( nowTime.isAfter(goblinFrontBanner.getEndTime())){
}else{
if(nowTime.isBefore(goblinFrontBanner.getStartTime())){
}else{
goblinFrontBannerArrayList.add(goblinFrontBanner);
}
}
}else{
goblinFrontBannerArrayList.add(goblinFrontBanner);
}
}
ArrayList<GoblinFrontBannerVo> list1= ObjectUtil.goblinFrontBannerVoArrayList();
for(GoblinFrontBanner goblinFrontBanner:goblinFrontBannerArrayList){
GoblinFrontBannerVo goblinFrontBannerVo=GoblinFrontBannerVo.getNew();
BeanUtils.copyProperties(goblinFrontBanner,goblinFrontBannerVo);
list1.add(goblinFrontBannerVo);
}
return list1;
}
@Override
public GoblinFrontHotWord getHotWord() {
List<GoblinFrontHotWord> list=goblinRedisUtils.getHotWord();
// int index= (int) redisUtil.get(GoblinRedisConst.FRONT_HOTWORD_INDEX);
//获得value
/* index++;
String hotWord="";
redisUtil.set(GoblinRedisConst.FRONT_HOTWORD_INDEX,index);
if(index<list.size()){
hotWord= list.get(index).getWord();
}else{
hotWord= list.get(0).getWord();
}*/
if(null==list||list.size()==0){
return null;
}else{
return list.get(0);
}
}
@Override
public GoblinFrontNavigationVoo getNavigation() {
if(!redisUtil.hasKey(GoblinRedisConst.FRONT_NAVIGATION)){
return null;
}
GoblinFrontNavigationVoo goblinFrontNavigationVoo=GoblinFrontNavigationVoo.getNew();
List<GoblinFrontNavigation> list = (List<GoblinFrontNavigation>) redisUtil.get(GoblinRedisConst.FRONT_NAVIGATION);
ArrayList<GoblinFrontNavigationVo> list1=ObjectUtil.getgoblinFrontNavigationVoArrayList();
for(GoblinFrontNavigation navigation:list){
goblinFrontNavigationVoo.setDisplayType(navigation.getDisplayType());
GoblinFrontNavigationVo goblinFrontNavigationVo=GoblinFrontNavigationVo.getNew();
BeanUtils.copyProperties(navigation,goblinFrontNavigationVo);
list1.add(goblinFrontNavigationVo);
}
goblinFrontNavigationVoo.setList(list1);
return goblinFrontNavigationVoo;
}
@Override
public GoblinFrontSeckillVo getSeckilll() throws ParseException {
//获得秒杀列表绑定
List<GoblinFrontSeckill> list= (List<GoblinFrontSeckill>) redisUtil.get(GoblinRedisConst.FRONT_SECKILL);
GoblinFrontSeckillVo goblinFrontSeckillVo=GoblinFrontSeckillVo.getNew();
ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList=ObjectUtil.goblinGoodsInfoVoArrayList();
//判断是否有
if(null!=list&&list.size()>0){
//遍历秒杀, 找到对应的 官方、商铺
GoblinFrontSeckill goblinFrontSeckill=list.get(0);
boolean openBoolean=goblinFrontSeckill.getActivityType()==2;
String ids=goblinFrontSeckill.getSelfActivityids();
if(StringUtil.isNotBlank(ids)){
String[] idss=ids.split(",");
for(String id:idss){
String type=id.split("_")[0];
String idM=id.split("_")[1];
if(type.equals("g")){
//找到对应官方的活动 判断时间是否过期,
GoblinSelfMarketingVo goblinSelfMarketingVo=goblinRedisUtils.getSelfMarket(idM);
if(!StringUtil.isNotBlank(goblinFrontSeckillVo.getStartTime())){
goblinFrontSeckillVo.setStartTime(goblinSelfMarketingVo.getStartTime());
goblinFrontSeckillVo.setEndTime(goblinSelfMarketingVo.getEndTime());
}
if(goblinSelfMarketingVo==null){
break;
}
if(!openBoolean){
//效验该活动是否在当前时间
if(!belongCalendar(goblinSelfMarketingVo.getStartTime(),goblinSelfMarketingVo.getEndTime())){
//如果不是在当前时间
break;
}
}
//查看 活动绑定的 spu sku
List<GoblinMarketRelationVo> list1=goblinRedisUtils.getMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(),goblinSelfMarketingVo.getSelfMarketId());
//遍历 活动表
for(GoblinMarketRelationVo goblinMarketRelationVo:list1){
//找到对应的spu商品
GoblinGoodsInfoVo goblinGoodsInfoVo=goblinRedisUtils.getGoodsInfoVo(goblinMarketRelationVo.getSpuId());
//遍历sku 找到
List<String> skuList=goblinMarketRelationVo.getSkuList();
int sellPrice=0;
int i=0;
for(String skuId:skuList){
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo= goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if(null!=goblinGoodsSkuInfoVo){
if(i==0){
sellPrice=goblinGoodsSkuInfoVo.getSellPrice().intValue();
}
if(sellPrice>goblinGoodsSkuInfoVo.getSellPrice().intValue()){
sellPrice=goblinGoodsSkuInfoVo.getSellPrice().intValue();
}
}
}
goblinGoodsInfoVo.setSellPrice(new BigDecimal(sellPrice));
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo);
}
}else if(type.equals("s")){
//商铺活动的vo
GoblinStoreMarketVo goblinStoreMarketVo=goblinRedisUtils.getGoblinStoreMarketVo(idM);
if(!StringUtil.isNotBlank(goblinFrontSeckillVo.getStartTime())){
goblinFrontSeckillVo.setStartTime(goblinStoreMarketVo.getStartTime());
goblinFrontSeckillVo.setEndTime(goblinStoreMarketVo.getEndTime());
}
if(goblinStoreMarketVo==null){
break;
}
boolean isGet=false;
if(openBoolean){
//不做效验时间直接放true
isGet=true;
}else if(goblinStoreMarketVo.getIsPre()==1&&afterCalendar(goblinStoreMarketVo.getPreTime())&&beforeCalendar(goblinStoreMarketVo.getEndTime())){
isGet=true;
}else if(goblinStoreMarketVo.getIsPre()==0&&belongCalendar(goblinStoreMarketVo.getStartTime(),goblinStoreMarketVo.getEndTime())){
isGet=true;
}
if(isGet){
//获取商铺 对应关系
List<GoblinMarketRelationVo> list1=goblinRedisUtils.getMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(),goblinStoreMarketVo.getStoreMarketId());
//获得商品
//遍历 活动表
for(GoblinMarketRelationVo goblinMarketRelationVo:list1){
//找到对应的spu商品
GoblinGoodsInfoVo goblinGoodsInfoVo=goblinRedisUtils.getGoodsInfoVo(goblinMarketRelationVo.getSpuId());
//遍历sku 找到
List<String> skuList=goblinMarketRelationVo.getSkuList();
int sellPrice=0;
int i=0;
for(String skuId:skuList){
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo= goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if(null!=goblinGoodsSkuInfoVo){
if(i==0){
sellPrice=goblinGoodsSkuInfoVo.getSellPrice().intValue();
}
if(sellPrice>goblinGoodsSkuInfoVo.getSellPrice().intValue()){
sellPrice=goblinGoodsSkuInfoVo.getSellPrice().intValue();
}
}
}
goblinGoodsInfoVo.setSellPrice(new BigDecimal(sellPrice));
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo);
}
}
}
}
goblinFrontSeckillVo.setGoblinGoodsInfoVoList(goblinGoodsInfoVoArrayList);
}
}
return goblinFrontSeckillVo;
}
//获取库存设置的报警数量
public int getStockCount(String storeId){
String configVal="";
List<GoblinStoreConfigVo> listVo=goblinRedisUtils.getStoreConfigVos(storeId);
//ONOFF_SOLD_OUT_SHOW ON 开启
for(GoblinStoreConfigVo goblinStoreConfigVo:listVo){
//获取是 售罄是否开启
if(goblinStoreConfigVo.getConfigKey().equals(GoblinStoreConf.LIMIT_WARNING_STOCK)){
configVal=goblinStoreConfigVo.getConfigVal();
}
}
if(StringUtil.isNotBlank(configVal)){
return Integer.parseInt(configVal);
}else{
return -1;
}
}
/**
* 获得商品详情
*/
public GoblinFrontGoodDetailVo getGoodsDetail(String spuId){
Integer buyCount=0;
GoblinFrontGoodDetailVo goblinFrontGoodDetailVo=GoblinFrontGoodDetailVo.getNew();
GoblinGoodsInfoVo goblinGoodsInfoVo=goblinRedisUtils.getGoodsInfoVo(spuId);
GoblinGoodsInfoDetailVo goblinGoodsInfoDetailVo=GoblinGoodsInfoDetailVo.getNew();
//skuIdList
if(null!=goblinGoodsInfoVo){
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoDetailVo);
goblinFrontGoodDetailVo.setGoblinGoodsInfoVo(goblinGoodsInfoDetailVo);
// int limit= getStockCount(goblinGoodsInfoVo.getStoreId());
List<String> skuIdList=goblinGoodsInfoVo.getSkuIdList();
ArrayList<GoblinGoodsSkuInfoDetailVo> list=ObjectUtil.goblinGoodsSkuInfoDetailVos();
for(String sku:skuIdList){
String userId=CurrentUtil.getCurrentUid();
if(StringUtils.isNotBlank(userId)){
buyCount=goblinRedisUtils.getSkuCountByUid(userId, sku);
}
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo=goblinRedisUtils.getGoodsSkuInfoVo(sku);
if(null!=goblinGoodsSkuInfoVo&&goblinGoodsSkuInfoVo.getDelFlg().equals("0")&&goblinGoodsSkuInfoVo.getShelvesStatus().equals("3")){
//获取 sku 库存数量
String pre = GoblinStatusConst.MarketPreStatus.getPre(spuId);
int stock=goblinRedisUtils.getSkuStock(pre,goblinGoodsSkuInfoVo.getSkuId());
log.debug("skuId:{},库存数量{}",goblinGoodsSkuInfoVo.getSkuId(),stock);
GoblinGoodsSkuInfoDetailVo goblinGoodsSkuInfoDetailVo=GoblinGoodsSkuInfoDetailVo.getNew();
BeanUtils.copyProperties(goblinGoodsSkuInfoVo,goblinGoodsSkuInfoDetailVo);
if(0!=goblinGoodsSkuInfoDetailVo.getBuyLimit()){
if(null==buyCount){
buyCount=0;
}
goblinGoodsSkuInfoDetailVo.setCanBuy(goblinGoodsSkuInfoDetailVo.getBuyLimit()-buyCount);
}else{goblinGoodsSkuInfoDetailVo.setCanBuy(-9999);}
if(stock<=0){
goblinGoodsSkuInfoDetailVo.setStockLess(true);
}else{
goblinGoodsSkuInfoDetailVo.setStockLess(false);
}
list.add(goblinGoodsSkuInfoDetailVo);
}
}
//goblinGoodsInfoVo
GoblinStoreInfoVo goblinStoreInfoVo=this.getStore(goblinGoodsInfoVo.getStoreId());
if(null!=goblinStoreInfoVo){
goblinFrontGoodDetailVo.setStoreName(goblinStoreInfoVo.getStoreName());
}
goblinFrontGoodDetailVo.setGoblinGoodsSkuInfoVolist(list);
}
ArrayList<String> list=goblinCouponService.getSpuType(spuId,goblinGoodsInfoDetailVo.getStoreId());
goblinFrontGoodDetailVo.setGetSpuType(list);
return goblinFrontGoodDetailVo;
}
/**
* 获取组件排序
*/
public List getMoudleIndex(){
if(!redisUtil.hasKey(GoblinRedisConst.MOUDLE_INDEX)){
return null;
}
//GoblinGoodsInfoVo goblinGoodsInfoVo=goblinRedisUtils.get(spuId);
List<GoblinFrontMoudleIndex> list= (List<GoblinFrontMoudleIndex>) redisUtil.get(GoblinRedisConst.MOUDLE_INDEX);
return list;
}
/***
* @author zhangfuxin
* @Description:获取魔方
* @date 2022/1/10 下午4:49
*/
public GoblinFrontCubeVo getRecommend(){
GoblinFrontCubeVo goblinFrontCubeVo=GoblinFrontCubeVo.getNew();
ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList= ObjectUtil.getGoblinGoodsInfoVos();
if(!redisUtil.hasKey(GoblinRedisConst.FRONT_GOBLIN_RECOMMEND)){
return null;
}
List<GoblinFrontCube> list= (List<GoblinFrontCube>) redisUtil.get(GoblinRedisConst.FRONT_GOBLIN_RECOMMEND);
if(list.size()>0){
BeanUtils.copyProperties(list.get(0),goblinFrontCubeVo);
for(String spuid:goblinFrontCubeVo.getSpuId().split(",")){
GoblinGoodsInfoVo goblinGoodsInfoVo= goblinRedisUtils.getGoodsInfoVo(spuid);
if(null!=goblinGoodsInfoVo){
GoblinGoodsInfoVo goblinGoodsInfoVo1=GoblinGoodsInfoVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoVo1);
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo1);
}
}
goblinFrontCubeVo.setGoblinGoodsInfoVoList(goblinGoodsInfoVoArrayList);
}
return goblinFrontCubeVo;
}
/***
* @author zhangfuxin
* @Description:获取魔方
* @date 2022/1/10 下午4:49
*/
public GoblinFrontCubeVo getCube(){
GoblinFrontCubeVo goblinFrontCubeVo=GoblinFrontCubeVo.getNew();
ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList= ObjectUtil.getGoblinGoodsInfoVos();
if(!redisUtil.hasKey(GoblinRedisConst.FRONT_GOBLINFRONTCUBE)){
return null;
}
List<GoblinFrontCube> list= (List<GoblinFrontCube>) redisUtil.get(GoblinRedisConst.FRONT_GOBLINFRONTCUBE);
if(list.size()>0){
BeanUtils.copyProperties(list.get(0),goblinFrontCubeVo);
for(String spuid:goblinFrontCubeVo.getSpuId().split(",")){
GoblinGoodsInfoVo goblinGoodsInfoVo= goblinRedisUtils.getGoodsInfoVo(spuid);
if(null!=goblinGoodsInfoVo){
GoblinGoodsInfoVo goblinGoodsInfoVo1=GoblinGoodsInfoVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoVo1);
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo1);
}
}
goblinFrontCubeVo.setGoblinGoodsInfoVoList(goblinGoodsInfoVoArrayList);
}
return goblinFrontCubeVo;
}
public GoblinStoreInfoVo getStore(String storId){
Query query = new Query();
query.addCriteria(Criteria.where("storeId").is(storId).and("spuAppear").is("0").and("delFlg").is("0").and("shelvesStatus").is("3"));
long count = mongoTemplate.count(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
GoblinStoreInfoVo goblinStoreInfoVo=goblinRedisUtils.getStoreInfoVo(storId);
//GoblinStoreNoticeVo goblinStoreNoticeVo=goblinRedisUtils.getStoreNoticeVo(storId,LocalDateTime.now());
goblinStoreInfoVo.setCount((int) count);
return goblinStoreInfoVo;
}
/***
* @author zhangfuxin
* @Description:获得商铺分类
* @date 2022/1/18 下午1:44
*/
public List<GoblinStoreGoodsCategoryVo> getStoreCategory(String storId){
//店铺分类数据源
List<GoblinStoreGoodsCategoryVo> list=goblinRedisUtils.getStoreGoodsCategoryVos(storId);
return list;
}
/**
* 找到分类
*/
public GoblinCategoryzfVo getCategory(String categoryId){
GoblinCategoryzfVo goblinCategoryzfVo=GoblinCategoryzfVo.getNew();
ArrayList<GoblinSelfGoodsCategoryVo> list1=ObjectUtil.getGoblinSelfGoodsCategoryVoArrayList();
//先找到 当前的分类id
GoblinSelfGoodsCategoryVo pa=null;
//获取到分类
List<GoblinSelfGoodsCategoryVo> list=goblinRedisUtils.getSelfGoodsCategoryVos();
for(GoblinSelfGoodsCategoryVo goblinSelfGoodsCategoryVo:list){
if (categoryId.equals(goblinSelfGoodsCategoryVo.getCateId())) {
goblinCategoryzfVo.setGoblinSelfGoodsCategoryVo(goblinSelfGoodsCategoryVo);
pa=goblinSelfGoodsCategoryVo;
}
}
//找到 该分类的子集
if(null!=pa){
for(GoblinSelfGoodsCategoryVo goblinSelfGoodsCategoryVo:list){
if(pa.getCateId().equals(goblinSelfGoodsCategoryVo.getCatePid())){
list1.add(goblinSelfGoodsCategoryVo);
}
}
}
goblinCategoryzfVo.setList(list1);
return goblinCategoryzfVo;
}
public List<GoblinGoodsInfoListVo> searchGoodesName(String name){
List<String> listStore=mongoUtils.getStoreInfoVoRegexName(name);
Pattern pattern = Pattern.compile("^.*"+name+".*$", Pattern.CASE_INSENSITIVE);
Query query = new Query();
query.addCriteria(new Criteria().orOperator(
Criteria.where("name").regex(pattern),
Criteria.where("storeId").in(listStore),
Criteria.where("extagVoList.tagName").is(name)
));
// query.addCriteria(Criteria.where("name").regex(pattern).and("spuAppear").is("0").and("delFlg").is("0").and("shelvesStatus").is("3"));
query.addCriteria(Criteria.where("spuAppear").is("0").and("delFlg").is("0").and("shelvesStatus").is("3"));
query.with(Sort.by(
Sort.Order.desc("count"),
Sort.Order.desc("createdAt")
));
List<GoblinGoodsInfoVo> list = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
ArrayList<GoblinGoodsInfoListVo> list1=ObjectUtil.getGoblinGoodsInfoListVo();
//遍历
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
//有音乐人的放前面
if(null!=goblinGoodsInfoVo.getExtagVoList()&&goblinGoodsInfoVo.getExtagVoList().size()>0){
GoblinStoreInfoVo goblinStoreInfoVo=goblinRedisUtils.getStoreInfoVo(goblinGoodsInfoVo.getStoreId());
if(null!=goblinStoreInfoVo){
goblinGoodsInfoVo.setStoreName(goblinStoreInfoVo.getStoreName());
}
GoblinGoodsInfoListVo goblinGoodsInfoListVo= GoblinGoodsInfoListVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoListVo);
list1.add(goblinGoodsInfoListVo);
}
}
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
if(null!=goblinGoodsInfoVo.getExtagVoList()&&goblinGoodsInfoVo.getExtagVoList().size()>0){
}else{
//无音乐人标签的
GoblinStoreInfoVo goblinStoreInfoVo=goblinRedisUtils.getStoreInfoVo(goblinGoodsInfoVo.getStoreId());
if(null!=goblinStoreInfoVo){
goblinGoodsInfoVo.setStoreName(goblinStoreInfoVo.getStoreName());
}
GoblinGoodsInfoListVo goblinGoodsInfoListVo= GoblinGoodsInfoListVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoListVo);
list1.add(goblinGoodsInfoListVo);
}
}
return list1;
}
public GoblinFrontCategoryListVo getStoreGoodes(String storeId,String categoryId,String name){
String configVal="";
List<GoblinStoreConfigVo> listVo=goblinRedisUtils.getStoreConfigVos(storeId);
//ONOFF_SOLD_OUT_SHOW ON 开启
for(GoblinStoreConfigVo goblinStoreConfigVo:listVo){
//获取是 售罄是否开启
if(goblinStoreConfigVo.getConfigKey().equals(GoblinStoreConf.ONOFF_SOLD_OUT_SHOW)){
configVal=goblinStoreConfigVo.getConfigVal();
}
}
//
Query query = new Query();
query.addCriteria(Criteria.where("storeId").is(storeId).and("spuAppear").is("0").and("delFlg").is("0").and("shelvesStatus").is("3"));
if(StringUtil.isNotBlank(categoryId)){
query.addCriteria(new Criteria().orOperator(
Criteria.where("storeCateFid").is(categoryId),
Criteria.where("storeCateSid").is(categoryId),
Criteria.where("storeCateTid").is(categoryId)
));
}
if(StringUtil.isNotBlank(name)){
Pattern pattern = Pattern.compile("^.*"+name+".*$", Pattern.CASE_INSENSITIVE);
query.addCriteria(Criteria.where("name").regex(pattern));
}
query.with(Sort.by(Sort.Direction.DESC, "count"));
// 查询总数
List<GoblinGoodsInfoVo> list = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
// 计算库存
Iterator<GoblinGoodsInfoVo> iterator = list.iterator();
//删掉库存没有的商品
while(iterator.hasNext()){
GoblinGoodsInfoVo goblinGoodsInfoVo=iterator.next();
List<String> skuIdList =goblinGoodsInfoVo.getSkuIdList();
int count=0;
for(String skuId:skuIdList){
count=count+goblinRedisUtils.getSkuStock(null,skuId);
}
if(StringUtil.isNotBlank(configVal)&&!configVal.equals("ON")){
if(count==0){
iterator.remove();
}
}
}
ArrayList<GoblinGoodsInfoListVo> listVos=ObjectUtil.getGoblinGoodsInfoListVo();
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
GoblinGoodsInfoListVo goblinGoodsInfoListVo= GoblinGoodsInfoListVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoListVo);
listVos.add(goblinGoodsInfoListVo);
}
GoblinFrontCategoryListVo goblinFrontCategoryListVo=GoblinFrontCategoryListVo.getNew();
goblinFrontCategoryListVo.setSpuList(listVos);
return goblinFrontCategoryListVo;
}
/**
*音乐人列表
*/
public GoblinFrontCategoryListVo getMusic(String tagId,String type,int page,int pageSize){
//
Query query = new Query();
query.addCriteria(new Criteria().orOperator(
Criteria.where("extagVoList.tagId").is(tagId).and("spuAppear").is("0").and("delFlg").is("0").and("shelvesStatus").is("3")
));
Pageable pageable=null;
//
boolean isRe=false;
if(type.equals("1")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "count"));
}else if(type.equals("2")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "shelvesAt"));
}else if(type.equals("3")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "priceGe"));
}else if(type.equals("4")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.ASC, "priceGe"));
}
// 排序 分页
// Query query = Query.query(Criteria.where("status").ne(1).and("status").ne(0));
// 查询总数
long count = mongoTemplate.count(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
query.with(pageable);
List<GoblinGoodsInfoVo> list = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
/*if(list.size()>0&&isRe){
//找到 销量
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
Integer counts=goblinRedisUtils.getSpuSaleCount(goblinGoodsInfoVo.getSpuId());
if(counts==null){
goblinGoodsInfoVo.setCount(0);
}else{
goblinGoodsInfoVo.setCount(counts);
}
}
Collections.sort(list, new Comparator<GoblinGoodsInfoVo>() {
public int compare(GoblinGoodsInfoVo arg0, GoblinGoodsInfoVo arg1) {
return -(arg0.getCount().compareTo(arg1.getCount()));
}});
}*/
ArrayList<GoblinGoodsInfoListVo> listVos=ObjectUtil.getGoblinGoodsInfoListVo();
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
GoblinGoodsInfoListVo goblinGoodsInfoListVo= GoblinGoodsInfoListVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoListVo);
listVos.add(goblinGoodsInfoListVo);
}
GoblinFrontCategoryListVo goblinFrontCategoryListVo=GoblinFrontCategoryListVo.getNew();
goblinFrontCategoryListVo.setCount(count);
goblinFrontCategoryListVo.setSpuList(listVos);
return goblinFrontCategoryListVo;
}
/**
* 获取分类列表
* 1、销量优先、2、新品优先、3、价格降序、4、价格升序
*/
public GoblinFrontCategoryListVo getCategoryList(String type,String categoryId,int page,int pageSize){
//
Query query = new Query();
query.addCriteria(new Criteria().orOperator(
Criteria.where("cateSid").is(categoryId),
Criteria.where("cateTid").is(categoryId)
));
query.addCriteria(Criteria.where("spuAppear").is("0").and("delFlg").is("0").and("shelvesStatus").is("3"));
Pageable pageable=null;
//
if(type.equals("1")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "count"));
}else if(type.equals("2")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "shelvesAt"));
}else if(type.equals("3")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "priceGe"));
}else if(type.equals("4")){
pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.ASC, "priceGe"));
}
// 排序 分页
// Query query = Query.query(Criteria.where("status").ne(1).and("status").ne(0));
// 查询总数
long count = mongoTemplate.count(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
query.with(pageable);
List<GoblinGoodsInfoVo> list = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
GoblinFrontCategoryListVo goblinFrontCategoryListVo=GoblinFrontCategoryListVo.getNew();
goblinFrontCategoryListVo.setCount(count);
ArrayList<GoblinGoodsInfoListVo> listVos=ObjectUtil.getGoblinGoodsInfoListVo();
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
GoblinGoodsInfoListVo goblinGoodsInfoListVo= GoblinGoodsInfoListVo.getNew();
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoListVo);
listVos.add(goblinGoodsInfoListVo);
}
goblinFrontCategoryListVo.setSpuList(listVos);
return goblinFrontCategoryListVo;
}
/**
* 获取 mongodb里面的spuId
* @return
*/
public String getspuId(String spuids,int page,int pageSize){
Query query = new Query();
if(StringUtil.isNotBlank(spuids)){
query.addCriteria(Criteria.where("spuId").nin(spuids.split(",")));
}
query.addCriteria(Criteria.where("delFlg").is("0").and("shelvesStatus").is("3").and("spuAppear").is("0"));
//redis里面获取排序规则 1、上架时间2、销量3、价格高到低4、价格低到高
int sortType=0;
if(redisUtil.hasKey(GoblinRedisConst.SELECT_GOODS_SORT)){
sortType = (int) redisUtil.get(GoblinRedisConst.SELECT_GOODS_SORT);
}
Sort sortName=null;
if(sortType==1){
sortName = Sort.by(Sort.Direction.DESC, "shelvesAt");
}else if(sortType==2){
sortName = Sort.by(Sort.Direction.DESC, "count");
}else if(sortType==3){
Document source = new Document();
source.put("locale", "zh");
source.put("numericOrdering", true);
Collation collation = Collation.from(source);
query.collation(collation);
sortName = Sort.by(Sort.Direction.DESC, "priceGe");
}else{
Document source = new Document();
source.put("locale", "zh");
source.put("numericOrdering", true);
Collation collation = Collation.from(source);
query.collation(collation);
sortName = Sort.by(Sort.Direction.ASC, "priceGe");
}
/* Pageable pageable = PageRequest.of(page, pageSize, sortName);
query.with(pageable);*/
query.with(sortName);
List<GoblinGoodsInfoVo> list = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
StringBuffer sb = new StringBuffer();
int index=0;
for(GoblinGoodsInfoVo goblinGoodsInfoVo:list){
if(index==0){
sb.append(goblinGoodsInfoVo.getSpuId());
}else{
sb.append(","+goblinGoodsInfoVo.getSpuId());
}
index++;
}
return sb.toString();
}
public void setPage1(List<GoblinFrontSelectGoods> list,int pageSize){
StringBuffer sb = new StringBuffer();
//足够了 拼接字符串
int i=0;
for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){
if(i==0){
sb.append(goblinFrontSelectGoods.getSpuId());
}else{
sb.append(","+goblinFrontSelectGoods.getSpuId());
}
i++;
if(i==pageSize) break;
}
redisUtil.set(GoblinRedisConst.SELECT_GOODS_PAGE1,sb.toString());
}
public void setPage1AndSpu(List<GoblinFrontSelectGoods> list,int pageSize){
validate(list);
//sb 为配置的 精选商品 spuid
StringBuffer sb = new StringBuffer();
if(null!=list&&list.size()>0){
int i=0;
for(GoblinFrontSelectGoods goblinFrontSelectGoods:list){
if(i==0){
sb.append(goblinFrontSelectGoods.getSpuId());
}else{
sb.append(","+goblinFrontSelectGoods.getSpuId());
}
i++;
}
}
//获得没有配置的spuid s 是没有配置的精选商品spuid
String s=this.getspuId(sb.toString(),0,0);
String supids="";
if(StringUtil.isNotBlank(sb.toString())&&StringUtil.isNotBlank(s)){
supids=sb.toString()+","+s;
}else if(StringUtil.isNotBlank(sb.toString())){
supids=sb.toString();
}else if(StringUtil.isNotBlank(s)){
supids=s;
}
log.debug("spuid所有的为:{}",supids);
int index=0;
//sb1 为 第一页的 spuid
StringBuffer sb1 = new StringBuffer();
for(String ss:supids.split(",")){
if(index==0){
sb1.append(ss);
}else{
sb1.append(","+ss);
}
index++;
if(index==pageSize){
break;
}
}
redisUtil.set(GoblinRedisConst.SELECT_GOODS_PAGE1,sb1.toString());
redisUtil.set(GoblinRedisConst.SELECT_GOODS_SPUIDS,supids);
}
public void validate( List<GoblinFrontSelectGoods> list){
if(null!=list&&list.size()>0){
Iterator<GoblinFrontSelectGoods> it = list.iterator();
while (it.hasNext()) {
GoblinFrontSelectGoods goblinFrontSelectGoods= it.next();
if(StringUtils.isBlank(goblinFrontSelectGoods.getSpuId())){
it.remove();
}else{
GoblinGoodsInfoVo goblinGoodsInfoVo= goblinRedisUtils.getGoodsInfoVo(goblinFrontSelectGoods.getSpuId());
if (null==goblinGoodsInfoVo) {
it.remove();
}
}
}
}
}
public String getRedisKey(String key){
Object value=redisUtil.get(key);
if(null!=value){
return value.toString();
}else{
return "";
}
}
/**
* @author zhangfuxin
* @Description:精选商品列表
* @date 2022/1/5 下午3:00
*/
@Override
public GoblinFrontSelectGoodVo getSelectGoods(int page, int pageSize) {
GoblinFrontSelectGoodVo goblinFrontSelectGoodVo=GoblinFrontSelectGoodVo.getNew();
//先从redis里 查 是否有第一页的值
String spuIds="";
if(page==0){
String selectGoodsPage1= getRedisKey(GoblinRedisConst.SELECT_GOODS_PAGE1);
if(StringUtil.isNotBlank(selectGoodsPage1)){
String[] spuids=selectGoodsPage1.split(",");
log.debug("spuids{}",spuids);
ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList= ObjectUtil.getGoblinGoodsInfoVos();
for(String id:spuids){
GoblinGoodsInfoVo goblinGoodsInfoVo= goblinRedisUtils.getGoodsInfoVo(id);
if(null!=goblinGoodsInfoVo){
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo);
}
}
goblinFrontSelectGoodVo.setGoblinGoodsInfoVoList(goblinGoodsInfoVoArrayList);
return goblinFrontSelectGoodVo;
}else{
//从redis里面查出配置的 spu
if(redisUtil.hasKey(GoblinRedisConst.SELECT_GOODS)){
List<GoblinFrontSelectGoods> list= (List<GoblinFrontSelectGoods>) redisUtil.get(GoblinRedisConst.SELECT_GOODS);
validate(list);
if(list.size()>=pageSize){
this.setPage1(list,pageSize);
return this.getSelectGoods(page,pageSize);
}else{
setPage1AndSpu(list,pageSize);
return this.getSelectGoods(page,pageSize);
}
}else{
setPage1AndSpu(null,pageSize);
return this.getSelectGoods(page,pageSize);
}
}
}else{
//查看是否有 配置的 spuid的顺序
String selectGoodsSpuids= getRedisKey(GoblinRedisConst.SELECT_GOODS_PAGE1);
if(StringUtil.isBlank(selectGoodsSpuids)){
List<GoblinFrontSelectGoods> list= (List<GoblinFrontSelectGoods>) redisUtil.get(GoblinRedisConst.SELECT_GOODS);
setPage1AndSpu(list,pageSize);
this.getSelectGoods(page,pageSize);
}
String[] spuidss=selectGoodsSpuids.split(",");
//找到对应的spuid
int start =page*pageSize;
int end=(page+1)*pageSize;
if(end>spuidss.length){
end=spuidss.length;
}
ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList= ObjectUtil.getGoblinGoodsInfoVos();
for(int i=0;i<end;i++){
if(i>=start){
GoblinGoodsInfoVo goblinGoodsInfoVo= goblinRedisUtils.getGoodsInfoVo(spuidss[i]);
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo);
}
}
goblinFrontSelectGoodVo.setGoblinGoodsInfoVoList(goblinGoodsInfoVoArrayList);
goblinFrontSelectGoodVo.setCount(spuidss.length);
return goblinFrontSelectGoodVo;
}
/* String spuIds="";
if(!redisUtil.hasKey(GoblinRedisConst.SELECT_GOODS)){
//查看redis里面第一页的商品
if(redisUtil.hasKey(GoblinRedisConst.SELECT_GOODS_PAGE1)){
spuIds= (String) redisUtil.get(GoblinRedisConst.SELECT_GOODS_PAGE1);
}else{
Query query = new Query();
query.addCriteria(Criteria.where("delFlg").is("0").and("shelvesStatus").is("3"));
//直接从库里查
PageRequest pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "count"));
query.with(pageable);
List<GoblinGoodsInfoVo> voList=mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
return null;
}else{
}*/
/*//redis 取出精选商品列表
List<GoblinFrontSelectGoods> list= (List<GoblinFrontSelectGoods>) redisUtil.get(GoblinRedisConst.SELECT_GOODS);
if(null!=list&&list.size()==1){
//获取商品列表
String spuId=list.get(0).getSpuId();
int start=page*pageSize;
int end =start+pageSize;
String[] ids=spuId.split(",");
if(end>ids.length){
end=ids.length;
}
//创建
GoblinFrontSelectGoodVo goblinFrontSelectGoodVo=GoblinFrontSelectGoodVo.getNew();
goblinFrontSelectGoodVo.setCount(ids.length);
//
ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList= ObjectUtil.getGoblinGoodsInfoVos();
for(int i=0;i<end;i++){
if (i>=start){
GoblinGoodsInfoVo goblinGoodsInfoVo= goblinRedisUtils.getGoodsInfoVo(ids[i]);
goblinGoodsInfoVoArrayList.add(goblinGoodsInfoVo);
}
}
goblinFrontSelectGoodVo.setGoblinGoodsInfoVoList(goblinGoodsInfoVoArrayList);
return goblinFrontSelectGoodVo;
}*/
// return null;
}
@Override
public List<GoblinGoodsInfoVo> getGoodByMusicTagP(String musicTag, String performanceId) {
return goblinRedisUtils.getMusicTagList(musicTag,performanceId);
}
public boolean belongCalendar( String startString, String endString) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.DATE_FULL_STR);//注意月份是MM
Date from = simpleDateFormat.parse(startString);
Date end= simpleDateFormat.parse(endString);
Calendar date = Calendar.getInstance();
date.setTime(new Date());
Calendar after = Calendar.getInstance();
after.setTime(from);
Calendar before = Calendar.getInstance();
before.setTime(end);
if (date.after(after) && date.before(before)) {
return true;
} else {
return false;
}
}
//判断是否是该时间之后
public boolean afterCalendar(String time) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.DATE_FULL_STR);//注意月份是MM
Calendar date = Calendar.getInstance();
date.setTime(new Date());
Date timefrom = simpleDateFormat.parse(time);
if (date.after(timefrom)) {
return true;
} else {
return false;
}
}
//判断是否是该时间之后
public boolean beforeCalendar(String time) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.DATE_FULL_STR);//注意月份是MM
Calendar date = Calendar.getInstance();
date.setTime(new Date());
Date timefrom = simpleDateFormat.parse(time);
if (date.before(timefrom)) {
return true;
} else {
return false;
}
}
public boolean validateShoopCartNumber(String skuId,String type,Integer buyCount,String userId){
if(!type.equals("1")){
return true;
}
//获取sku
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo=goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if(null==goblinGoodsSkuInfoVo){
return false;
}
if(null==goblinGoodsSkuInfoVo.getBuyLimit()||goblinGoodsSkuInfoVo.getBuyLimit()==0){
return true;
}
//已经购买的数量
Integer buyCounts=goblinRedisUtils.getSkuCountByUid(userId, skuId);
if(goblinGoodsSkuInfoVo.getBuyLimit()<(buyCounts+buyCount)){
//
return false;
}
return true;
}
/**
* @author zhangfuxin
* @Description:添加购物车
* @date 2022/1/11 下午4:16
*/
public ResponseDto addShoopCart(String spuId, String storeId,String skuId,Integer number,String userId,String type){
if(null==number||number<=0){
return ResponseDto.success(false);
}
boolean isGoods=false;
String cardId="";
//判断该用户 redis里是否有购物车
GoblinShoppingCartVoo goblinShoppingCartVoo= (GoblinShoppingCartVoo) redisUtil.get(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type.toString()));
if(null==goblinShoppingCartVoo){
//创建 voo
GoblinShoppingCartVoo goblinShoppingCartVoo1=GoblinShoppingCartVoo.getNew();
// 根据shop分类
ArrayList<GoblinShoppingCartVo> list=ObjectUtil.goblinShoppingCartVoArrayList();
GoblinShoppingCartVo goblinShoppingCartVo=GoblinShoppingCartVo.getNew();
goblinShoppingCartVo.setStoreId(storeId);
//该商铺下的所有商品
ArrayList<GoblinShoppingCartVoDetail> list1=ObjectUtil.goblinShoppingCartVoDetailArrayList();
if(!validateShoopCartNumber(skuId,type,number,userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
//创建 购物车vo
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number);
list1.add(goblinShoppingCartVoDetail);
goblinShoppingCartVo.setSkuList(list1);
list.add(goblinShoppingCartVo);
goblinShoppingCartVoo1.setShopList(list);
goblinShoppingCartVoo1.setGoblinShoppingCartId(IDGenerator.nextSnowId());
saveRedisMongodbMysqlShop(goblinShoppingCartVoo1,userId,type);
insertShopCartMysql(goblinShoppingCartVoDetail.getCarId(),spuId,storeId,skuId,number,userId,type);
}else{
//查看是否有该商铺
List<GoblinShoppingCartVo> list=goblinShoppingCartVoo.getShopList();
boolean isShop=false;
for(GoblinShoppingCartVo goblinShoppingCartVo:list){
if(storeId.equals(goblinShoppingCartVo.getStoreId())){
//有这个商铺的 东西
List<GoblinShoppingCartVoDetail> list1=goblinShoppingCartVo.getSkuList();
//查看是否有这个商品
for(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail:list1){
if(skuId.equals(goblinShoppingCartVoDetail.getSkuId())){
isGoods=true;
if(!validateShoopCartNumber(skuId,type,(goblinShoppingCartVoDetail.getNumber()+number),userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
goblinShoppingCartVoDetail.setNumber((goblinShoppingCartVoDetail.getNumber()+number));
cardId=goblinShoppingCartVoDetail.getCarId();
}
}
if(isGoods){
//添加商品 数量
//不需要做
}else{
//创建商品放入到list
if(!validateShoopCartNumber(skuId,type,number,userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number);
cardId=goblinShoppingCartVoDetail.getCarId();
list1.add(goblinShoppingCartVoDetail);
}
isShop=true;
}
}
if(!isShop){
GoblinShoppingCartVo goblinShoppingCartVo=GoblinShoppingCartVo.getNew();
goblinShoppingCartVo.setStoreId(storeId);
//该商铺下的所有商品
ArrayList<GoblinShoppingCartVoDetail> list1=ObjectUtil.goblinShoppingCartVoDetailArrayList();
if(!validateShoopCartNumber(skuId,type,number,userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
//创建 购物车vo
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number);
list1.add(goblinShoppingCartVoDetail);
goblinShoppingCartVo.setSkuList(list1);
list.add(goblinShoppingCartVo);
}
saveRedisMongodbMysqlShop(goblinShoppingCartVoo,userId,type);
if(isGoods){
updateShopCartMysql(cardId,number,userId);
}else{
insertShopCartMysql(cardId,spuId,storeId,skuId,number,userId,type);
}
}
return ResponseDto.success(true);
}
/***
* @author zhangfuxin
* @Description: 修改 购物车里 数量
* @date 2022/1/11 下午6:24
*/
public boolean updateShopCart(String spuId, String storeId,String skuId,Integer number,String userId,String type){
if(null==number||number<=0){
return false;
}
GoblinShoppingCartVoo goblinShoppingCartVoo= (GoblinShoppingCartVoo) redisUtil.get(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type));
String cardId="";
if(null!=goblinShoppingCartVoo){
List<GoblinShoppingCartVo> list=goblinShoppingCartVoo.getShopList();
//遍历商铺
for(GoblinShoppingCartVo goblinShoppingCartVo:list){
if(storeId.equals(goblinShoppingCartVo.getStoreId())){
//找到 商品id
List<GoblinShoppingCartVoDetail> list1=goblinShoppingCartVo.getSkuList();
for(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail:list1){
if(skuId.equals(goblinShoppingCartVoDetail.getSkuId())){
cardId=goblinShoppingCartVoDetail.getCarId();
goblinShoppingCartVoDetail.setNumber(number);
}
}
}
}
//调用储存方法
saveRedisMongodbMysqlShop(goblinShoppingCartVoo,userId,type);
updateShopCartMysql(cardId,number,userId);
}
return true;
}
public int getShopCartCount(String userId,String type){
log.debug("获取商品数量{}",userId);
int count=0;
GoblinShoppingCartVoo goblinShoppingCartVoo= (GoblinShoppingCartVoo) redisUtil.get(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type.toString()));
if(null!=goblinShoppingCartVoo){
List<GoblinShoppingCartVo> shopList=goblinShoppingCartVoo.getShopList();
for(GoblinShoppingCartVo goblinShoppingCartVo:shopList){
List<GoblinShoppingCartVoDetail> skuList=goblinShoppingCartVo.getSkuList();
for(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail:skuList){
count=goblinShoppingCartVoDetail.getNumber()+count;
}
}
}
return count;
}
/***
* @author zhangfuxin
* @Description:存储信息
* @date 2022/1/17 下午4:55
*/
public boolean saveDate(String data,String userId,String type) {
redisUtil.set(GoblinRedisConst.FRONT_SHOPCART_TWO.concat(userId).concat(type.toString()),data,60*60*24);
return true;
}
public ResponseDto getDate(String userId,String type) {
if(redisUtil.get(GoblinRedisConst.FRONT_SHOPCART_TWO.concat(userId).concat(type.toString()))==null){
return ResponseDto.failure(ErrorMapping.get("20003"));
}
return ResponseDto.success( redisUtil.get(GoblinRedisConst.FRONT_SHOPCART_TWO.concat(userId).concat(type.toString())));
//return (String) redisUtil.get(GoblinRedisConst.FRONT_SHOPCART_TWO.concat(userId).concat(type.toString()));
}
/**
* 删除购物车里面的商品
*/
public boolean delteShoppingCart(String[] skuIds,String userId,String type) {
boolean isDeleteAll = false;
GoblinShoppingCartVoo goblinShoppingCartVoo = (GoblinShoppingCartVoo) redisUtil.get(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type));
if (null != goblinShoppingCartVoo) {
List<GoblinShoppingCartVo> shopList = goblinShoppingCartVoo.getShopList();
Iterator<GoblinShoppingCartVo> shopIter = shopList.iterator();
while (shopIter.hasNext()){
GoblinShoppingCartVo goblinShoppingCartVo=shopIter.next();
List<GoblinShoppingCartVoDetail> skuList = goblinShoppingCartVo.getSkuList();
Iterator<GoblinShoppingCartVoDetail> iterator = skuList.iterator();
while(iterator.hasNext()){
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=iterator.next();
for (String skuId : skuIds) {
if (goblinShoppingCartVoDetail.getSkuId().equals(skuId)) {
//skuList.remove(goblinShoppingCartVoDetail);
iterator.remove();
}
}
}
if(skuList.size()==0){
shopIter.remove();
}
}
if(shopList.size()==0){
deleteRedisMongodbMysqlShop(goblinShoppingCartVoo,userId,skuIds,type);
deleteMysql(userId,skuIds);
}else{
saveRedisMongodbMysqlShop(goblinShoppingCartVoo,userId,type);
deleteMysql(userId,skuIds);
}
}
/* if(this.getShopCartCount(userId)==0){
//删除redis、删除mongodb
deleteRedisMongodbMysqlShop(goblinShoppingCartVoo,userId);
}else{
saveRedisMongodbMysqlShop(goblinShoppingCartVoo,userId);
}
*/
return true;
}
//获得spu
public GoblinGoodsInfoVo getGoodsInfoVo(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail){
GoblinGoodsInfoVo goblinGoodsInfoVo=goblinRedisUtils.getGoodsInfoVo(goblinShoppingCartVoDetail.getSpuId());
if(null==goblinGoodsInfoVo){
goblinGoodsInfoVo=goblinRedisUtils.getGoodsInfoVoByUnShelves(goblinShoppingCartVoDetail.getSpuId());
}
return goblinGoodsInfoVo;
}
//获得sku
public GoblinGoodsSkuInfoVo getGoblinGoodsSkuInfoVo(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail){
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo=goblinRedisUtils.getGoodsSkuInfoVo(goblinShoppingCartVoDetail.getSkuId());
if(null==goblinGoodsSkuInfoVo){
goblinGoodsSkuInfoVo=goblinRedisUtils.getGoodsSkuInfoVoByUnShelves(goblinShoppingCartVoDetail.getSkuId());
}
return goblinGoodsSkuInfoVo;
}
//copy spu
public GoblinGoodsInfoShopCartVo copySpuVo(GoblinGoodsInfoVo goblinGoodsInfoVo){
GoblinGoodsInfoShopCartVo goblinGoodsInfoShopCartVo=GoblinGoodsInfoShopCartVo.getNew();
if(null!=goblinGoodsInfoVo){
BeanUtils.copyProperties(goblinGoodsInfoVo,goblinGoodsInfoShopCartVo);
}
return goblinGoodsInfoShopCartVo;
}
//copy sku
public GoblinGoodsSkuShopCartInfoVo copySkuVo(GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo,String userId){
GoblinGoodsSkuShopCartInfoVo goblinGoodsSkuShopCartInfoVo= GoblinGoodsSkuShopCartInfoVo.getNew();
if(null!=goblinGoodsSkuInfoVo){
BeanUtils.copyProperties(goblinGoodsSkuInfoVo,goblinGoodsSkuShopCartInfoVo);
//查看是否有库存
String pre = GoblinStatusConst.MarketPreStatus.getPre(goblinGoodsSkuInfoVo.getSpuId());
int stock=goblinRedisUtils.getSkuStock(pre,goblinGoodsSkuInfoVo.getSkuId());
if(stock<=0){
goblinGoodsSkuShopCartInfoVo.setStockLess(true);
}else {goblinGoodsSkuShopCartInfoVo.setStockLess(false);}
//查看已经购买数量
Integer buyCount=goblinRedisUtils.getSkuCountByUid(userId, goblinGoodsSkuShopCartInfoVo.getSkuId());
//查看限购数量
if(null==buyCount){buyCount=0;}
if(null!=goblinGoodsSkuShopCartInfoVo.getBuyLimit()&&goblinGoodsSkuShopCartInfoVo.getBuyLimit()>0){
goblinGoodsSkuShopCartInfoVo.setCanBuy(goblinGoodsSkuShopCartInfoVo.getBuyLimit()-buyCount);
}else{
goblinGoodsSkuShopCartInfoVo.setCanBuy(-9999);
}
}
return goblinGoodsSkuShopCartInfoVo;
}
/**
* @author zhangfuxin
* @Description: 获得购物车列表
* @date 2022/1/12 下午2:36
*/
public GoblinShoppingCartVoo getShoppCart(String userId,String type){
//判断该用户 redis里是否有购物车
GoblinShoppingCartVoo goblinShoppingCartVoo= (GoblinShoppingCartVoo) redisUtil.get(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type.toString()));
if(null==goblinShoppingCartVoo){
return null;
}
//遍历里面信息
for(GoblinShoppingCartVo goblinShoppingCartVo:goblinShoppingCartVoo.getShopList()){
if(null!=goblinRedisUtils.getStoreInfoVo(goblinShoppingCartVo.getStoreId())){
goblinShoppingCartVo.setStoreName(goblinRedisUtils.getStoreInfoVo(goblinShoppingCartVo.getStoreId()).getStoreName());
}
for(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail:goblinShoppingCartVo.getSkuList()){
//找到对应的 spu
GoblinGoodsInfoVo goblinGoodsInfoVo=getGoodsInfoVo(goblinShoppingCartVoDetail);
// 找到对应 sku
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo=getGoblinGoodsSkuInfoVo(goblinShoppingCartVoDetail);
//spu copy
GoblinGoodsInfoShopCartVo goblinGoodsInfoShopCartVo=copySpuVo(goblinGoodsInfoVo);
//sku copy
GoblinGoodsSkuShopCartInfoVo goblinGoodsSkuShopCartInfoVo= copySkuVo(goblinGoodsSkuInfoVo,userId);
goblinShoppingCartVoDetail.setGoblinGoodsInfoVo(goblinGoodsInfoShopCartVo);
goblinShoppingCartVoDetail.setGoblinGoodsSkuInfoVo(goblinGoodsSkuShopCartInfoVo);
}
}
goblinShoppingCartVoo.setShoopingCount(this.getShopCartCount(userId,type));
return goblinShoppingCartVoo;
}
public GoblinShoppingCartVoDetail setValue(String userId,String storeId,String spuId,String skuId,Integer number){
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=GoblinShoppingCartVoDetail.getNew();
goblinShoppingCartVoDetail.setCarId(IDGenerator.nextSnowId());
goblinShoppingCartVoDetail.setUserId(userId);
goblinShoppingCartVoDetail.setStoreId(storeId);
goblinShoppingCartVoDetail.setSpuId(spuId);
goblinShoppingCartVoDetail.setSkuId(skuId);
goblinShoppingCartVoDetail.setNumber(number);
goblinShoppingCartVoDetail.setDelTag(0);
goblinShoppingCartVoDetail.setCreatedAt(LocalDateTime.now());
goblinShoppingCartVoDetail.setUpdatedAt(LocalDateTime.now());
return goblinShoppingCartVoDetail;
}
public void saveRedisMongodbMysqlShop(GoblinShoppingCartVoo goblinShoppingCartVoo,String userId,String type){
goblinShoppingCartVoo.setUserId(userId);
//redis存储
redisUtil.set(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type.toString()),goblinShoppingCartVoo);
//mongodb存储
boolean exists2 =mongoTemplate.exists(Query.query(Criteria.where("goblinShoppingCartId").is(goblinShoppingCartVoo.getGoblinShoppingCartId())),GoblinShoppingCartVoo.class, GoblinShoppingCartVoo.class.getSimpleName());
goblinShoppingCartVoo.setType(type);
if(exists2){
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(goblinShoppingCartVoo)));
mongoTemplate.getCollection(GoblinShoppingCartVoo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("goblinShoppingCartId").is(goblinShoppingCartVoo.getGoblinShoppingCartId())).getQueryObject(),
orderObject
);
}else{
mongoTemplate.save(goblinShoppingCartVoo,GoblinShoppingCartVoo.class.getSimpleName());
}
//mysql 消息队列
}
//删除redis 删除mongodb
public void deleteRedisMongodbMysqlShop(GoblinShoppingCartVoo goblinShoppingCartVoo,String userId,String[] skuIds,String type){
//redis存储
redisUtil.del(GoblinRedisConst.FRONT_SHOPCART.concat(userId).concat(type.toString()));
//mongodb 删除
mongoTemplate.remove(Query.query(Criteria.where("goblinShoppingCartId").is(goblinShoppingCartVoo.getGoblinShoppingCartId())), GoblinShoppingCartVoo.class, GoblinShoppingCartVoo.class.getSimpleName());
//mysql 删除 按照 userid 、skuid
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_shop.cart.delete"));
LinkedList<Object[]> sqlData = CollectionUtil.linkedListObjectArr();
for(String sku:skuIds){
sqlData.add(new Object[]{
userId,sku,0
});
}
String sqlDatas = SqlMapping.gets(sqls, sqlData);
log.debug("sql信息{}",sqlDatas);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SHOP_CART.getKey(), sqlDatas);
}
public void insertShopCartMysql(String carId ,String spuId, String storeId,String skuId,Integer number,String userId,String type){
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_shop.cart.insert"));
LinkedList<Object[]> sqlData = CollectionUtil.linkedListObjectArr();
sqlData.add(new Object[]{
//car_id, user_id, store_id,spu_id, sku_id, `number`,marketing_id, del_tag, `comment`
carId,userId,storeId,spuId,skuId,number,"",0,"",type
});
String sqlDatas = SqlMapping.gets(sqls, sqlData);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SHOP_CART.getKey(), sqlDatas);
}
public void updateShopCartMysql(String carId ,Integer number,String userId){
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_shop.cart.update"));
LinkedList<Object[]> sqlData = CollectionUtil.linkedListObjectArr();
sqlData.add(new Object[]{
//update goblin_shopping_cart set `number` = ? where car_id=? and user_id=?
number,carId,userId
});
String sqlDatas = SqlMapping.gets(sqls, sqlData);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SHOP_CART.getKey(), sqlDatas);
}
//删除
public void deleteMysql(String userId,String[] skuIds){
//mysql 删除 按照 userid 、skuid
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_shop.cart.delete"));
LinkedList<Object[]> sqlData = CollectionUtil.linkedListObjectArr();
for(String sku:skuIds){
sqlData.add(new Object[]{
1,userId,sku
});
}
String sqlDatas = SqlMapping.gets(sqls, sqlData);
log.debug(sqlDatas);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SHOP_CART.getKey(), sqlDatas);
}
}
package com.liquidnet.service.goblin.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Joiner;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinBackOrder;
import com.liquidnet.service.goblin.entity.GoblinBackOrderLog;
import com.liquidnet.service.goblin.entity.GoblinStoreOrder;
import com.liquidnet.service.goblin.param.GoblinAppOrderRefundParam;
import com.liquidnet.service.goblin.service.IGoblinOrderAppService;
import com.liquidnet.service.goblin.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import static com.liquidnet.commons.lang.util.DateUtil.DTF_YMD_HMS;
import static com.liquidnet.commons.lang.util.DateUtil.DTFYMDHMS;
@Service
@Slf4j
public class GoblinOrderAppServiceImpl implements IGoblinOrderAppService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinOrderUtils orderUtils;
@Override
public ResponseDto<PageInfo<GoblinAppOrderListVo>> orderList(int page, String pre) {
String uid = CurrentUtil.getCurrentUid();
List<GoblinAppOrderListVo> orderVoList = ObjectUtil.goblinAppOrderListVoArrayList();
List<String> orderIds;
if (pre == null) {
orderIds = redisUtils.getOrderList(uid);
} else if (pre.equals(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())) {
orderIds = redisUtils.getZhengzaiOrderList(uid);
} else {
return ResponseDto.failure("参数错误");
}
int size = 40;
int finalCount = orderIds.size() - page * size;
int initCount = orderIds.size() - (page - 1) * size - 1;
if (finalCount <= 0) {
finalCount = 0;
}
for (int i = initCount; i >= finalCount; i--) {
String orderId = orderIds.get(i);
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
GoblinAppOrderListVo vo = GoblinAppOrderListVo.getNew();
BeanUtils.copyProperties(orderVo, vo);
vo.setRestTime(getRestTime(orderVo));
List<GoblinOrderSkuVo> skuVos = ObjectUtil.getGoblinOrderSkuVoArrayList();
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
skuVos.add(orderSkuVo);
}
vo.setOrderSkuVos(skuVos);
orderVoList.add(vo);
}
PageInfo<GoblinAppOrderListVo> pageInfo = new PageInfo(orderVoList);
pageInfo.setTotal(orderIds.size());
return ResponseDto.success(pageInfo);
}
@Override
public ResponseDto<List<GoblinAppOrderListVo>> orderListByMaster(String orderMasterCode) {
String[] orderIdArray = redisUtils.getMasterCode(orderMasterCode);
List<GoblinAppOrderListVo> orderVoList = ObjectUtil.goblinAppOrderListVoArrayList();
for (String orderId : orderIdArray) {
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
GoblinAppOrderListVo vo = GoblinAppOrderListVo.getNew();
BeanUtils.copyProperties(orderVo, vo);
vo.setRestTime(getRestTime(orderVo));
List<GoblinOrderSkuVo> skuVos = ObjectUtil.getGoblinOrderSkuVoArrayList();
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
skuVos.add(orderSkuVo);
}
vo.setOrderSkuVos(skuVos);
orderVoList.add(vo);
}
return ResponseDto.success(orderVoList);
}
@Override
public ResponseDto<GoblinAppOrderDetailsVo> orderDetails(String orderId, String uid) {
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || (!orderVo.getUserId().equals(uid) && uid != null)) {
return ResponseDto.failure(ErrorMapping.get("20003"));
}
GoblinAppOrderDetailsVo vo = GoblinAppOrderDetailsVo.getNew();
List<GoblinOrderSkuVo> skuVos = ObjectUtil.getGoblinOrderSkuVoArrayList();
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
skuVos.add(orderSkuVo);
}
LocalDateTime canRefundTime = getCanRefundTime(orderVo);
if (canRefundTime == null) {
vo.setCanRefund(0);
} else {
if (LocalDateTime.now().isAfter(canRefundTime)) {
vo.setCanRefund(0);
} else {
vo.setCanRefund(1);
}
}
List<String> orderRefundIds = redisUtils.getBackOrderByOrderId(orderId);
if (orderRefundIds.size() > 0) {
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(orderRefundIds.get(orderRefundIds.size() - 1));
vo.setRefundStatus(backOrderVo.getStatus());
if (vo.getCanRefund() == 1 &&
(backOrderVo.getStatus() == 2 || backOrderVo.getStatus() == 3 || backOrderVo.getStatus() == 5) &&
(vo.getStoreOrderVo().getStatus() == GoblinStatusConst.Status.ORDER_STATUS_2.getValue() || vo.getStoreOrderVo().getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue())) {
} else {
vo.setCanRefund(0);
}
} else {
vo.setRefundStatus(-1);
}
List<GoblinMailVo> mailVos = redisUtils.getGoblinMail(orderId);
for (GoblinMailVo mailVo : mailVos) {
mailVo.setOrderSkuVos(null);
mailVo.setOrderSkuVoIds(null);
}
vo.setMailVos(mailVos);
vo.setRefuseSize(orderRefundIds.size());
vo.setRestTime(getRestTime(orderVo));
vo.setStoreOrderVo(orderVo);
vo.setOrderSkuVos(skuVos);
return ResponseDto.success(vo);
}
@Override
public ResponseDto<Boolean> getProduce(String orderId, String uid) {
LocalDateTime now = LocalDateTime.now();
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_order.store.orderStatus"));
sqls.add(SqlMapping.get("goblin_order.store.orderSkuStatus"));
LinkedList<Object[]> orderStatus = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> orderSkuStatus = CollectionUtil.linkedListObjectArr();
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (!orderVo.getUserId().equals(uid)) {
return ResponseDto.failure("无权操作");
}
if (orderVo.getStatus() != GoblinStatusConst.Status.ORDER_STATUS_3.getValue()) {
return ResponseDto.failure("不可操作");
}
//订单状态修改
orderVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_4.getValue());
orderStatus.add(new Object[]{
orderVo.getStatus(), now,
orderVo.getOrderId(), now, now
});
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
//订单款式状态修改
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_4.getValue());
//redis
redisUtils.setGoblinOrderSku(orderSkuVo.getOrderSkuId(), orderSkuVo);
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuVo.getOrderSkuId(), orderSkuVo);
orderSkuStatus.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
}
//redis
redisUtils.setGoblinOrder(orderId, orderVo);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
//redis
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_USER_ORDER_OPERA.getKey(), SqlMapping.gets(sqls, orderStatus, orderSkuStatus));
return ResponseDto.success(true);
}
@Override
public ResponseDto<Boolean> applyRefund(GoblinAppOrderRefundParam param) {
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_order.user.applyRefund"));
sqls.add(SqlMapping.get("goblin_order.store.orderStatus"));
sqls.add(SqlMapping.get("goblin_order.store.orderSkuStatus"));
sqls.add(SqlMapping.get("goblin_order.store.refundLog"));
LinkedList<Object[]> applyRefund = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> orderStatus = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> orderSkuStatus = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> refundLog = CollectionUtil.linkedListObjectArr();
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(param.getOrderId());
if (!orderVo.getUserId().equals(uid)) {
return ResponseDto.failure("无权操作");
}
List<String> backOrderIds = redisUtils.getBackOrderByOrderId(param.getOrderId());
for (String backOrderId : backOrderIds) {
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
if (!(backOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_3.getValue()) || backOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_5.getValue()) || backOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_9.getValue()))) {
return ResponseDto.failure("申请失败");
}
}
if (!(orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_2.getValue() ||
// orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_3.getValue() ||
orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue())) {
return ResponseDto.failure("不可操作");
}
//判断7天
LocalDateTime canRefundTime = getCanRefundTime(orderVo);
if (canRefundTime == null) {
return ResponseDto.failure("申请失败");
} else {
if (LocalDateTime.now().isAfter(canRefundTime)) {
return ResponseDto.failure("申请失败");
}
}
//判断券
if ((!(orderVo.getUcouponId() == null || orderVo.getUcouponId().equals("")) || !(orderVo.getStoreCouponId() == null || orderVo.getStoreCouponId().equals("")))
&& param.getOrderSkuId() != null) {
return ResponseDto.failure("用券仅支持整单退款");
}
//退款订单生成
GoblinBackOrder backOrder = GoblinBackOrder.getNew();
backOrder.setBackOrderId(IDGenerator.nextTimeId2());
backOrder.setBackCode(IDGenerator.storeRefundCode(orderVo.getMasterOrderCode()));
backOrder.setOrderId(param.getOrderId());
backOrder.setOrderCode(orderVo.getOrderCode());
backOrder.setStoreId(orderVo.getStoreId());
backOrder.setLogisCompanyName(param.getCompany());
backOrder.setMailNo(param.getMailNo());
backOrder.setUserId(orderVo.getUserId());
backOrder.setType(GoblinStatusConst.Type.BACK_TYPE_1.getValue());
backOrder.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_1.getValue());
backOrder.setCreatedAt(now);
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_2.getValue()) {//未发货
backOrder.setRealBackPrice(orderVo.getPriceActual());
backOrder.setBackPriceExpress(orderVo.getPriceExpress());
backOrder.setReason(param.getReason());
backOrder.setPics(param.getPics());
backOrder.setDescribes(param.getDescribes());
backOrder.setSkuIdNums(Joiner.on(",").join(orderVo.getOrderSkuVoIds()));
} else if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue()) {//已完成
if (param.getOrderSkuId() != null) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(param.getOrderSkuId());
if (orderVo.getPriceRefund().add(orderSkuVo.getSkuPriceActual()).add(orderVo.getPriceExpress()).compareTo(orderVo.getPriceActual()) >= 0) {
backOrder.setRealBackPrice(orderSkuVo.getSkuPriceActual().add(orderVo.getPriceExpress()));
backOrder.setBackPriceExpress(orderVo.getPriceExpress());
} else {
backOrder.setRealBackPrice(orderSkuVo.getSkuPriceActual());
backOrder.setBackPriceExpress(BigDecimal.ZERO);
}
} else {
backOrder.setRealBackPrice(orderVo.getPriceActual());
backOrder.setBackPriceExpress(orderVo.getPriceExpress());
}
backOrder.setReason(param.getReason());
backOrder.setPics(param.getPics());
backOrder.setDescribes(param.getDescribes());
backOrder.setType(param.getRefundType());
backOrder.setSkuIdNums(param.getOrderSkuId());
} else {
return ResponseDto.failure("不可申请");
}
GoblinBackOrderVo vo = GoblinBackOrderVo.getNew();
BeanUtils.copyProperties(backOrder, vo);
vo.setCreatedAt(nowStr);
List<GoblinBackOrderSkuVo> orderSkuVoList = ObjectUtil.goblinBackOrderSkuVoArrayList();
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_2.getValue()) {
//订单状态修改
// orderVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_61.getValue());
orderStatus.add(new Object[]{
orderVo.getStatus(), now,
orderVo.getOrderId(), now, now
});
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
//订单款式状态修改
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_61.getValue());
GoblinBackOrderSkuVo backOrderSkuVo = GoblinBackOrderSkuVo.getNew();
backOrderSkuVo.setOrderSkuId(orderSkuId);
backOrderSkuVo.setSpuId(orderSkuVo.getSpuId());
backOrderSkuVo.setSpuName(orderSkuVo.getSpuName());
backOrderSkuVo.setSkuId(orderSkuVo.getSkuId());
backOrderSkuVo.setSkuPic(orderSkuVo.getSkuImage());
backOrderSkuVo.setSkuName(orderSkuVo.getSkuName());
backOrderSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
backOrderSkuVo.setRefundPrice(orderSkuVo.getSkuPriceActual());
backOrderSkuVo.setCreatedAt(nowStr);
orderSkuVoList.add(backOrderSkuVo);
backOrderLog(orderVo, orderSkuVo, now);
//redis
redisUtils.setGoblinOrderSku(orderSkuVo.getOrderSkuId(), orderSkuVo);
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuVo.getOrderSkuId(), orderSkuVo);
orderSkuStatus.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
}
} else if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue()) {
if (param.getOrderSkuId() != null) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(param.getOrderSkuId());
//订单款式状态修改
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_61.getValue());
GoblinBackOrderSkuVo backOrderSkuVo = GoblinBackOrderSkuVo.getNew();
backOrderSkuVo.setOrderSkuId(param.getOrderSkuId());
backOrderSkuVo.setSpuId(orderSkuVo.getSpuId());
backOrderSkuVo.setSpuName(orderSkuVo.getSpuName());
backOrderSkuVo.setSkuId(orderSkuVo.getSkuId());
backOrderSkuVo.setSkuPic(orderSkuVo.getSkuImage());
backOrderSkuVo.setSkuName(orderSkuVo.getSkuName());
backOrderSkuVo.setRefundPrice(orderSkuVo.getSkuPriceActual());
backOrderSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
backOrderSkuVo.setCreatedAt(nowStr);
orderSkuVoList.add(backOrderSkuVo);
backOrderLog(orderVo, orderSkuVo, now);
//redis
redisUtils.setGoblinOrderSku(orderSkuVo.getOrderSkuId(), orderSkuVo);
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuVo.getOrderSkuId(), orderSkuVo);
orderSkuStatus.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
} else {
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
//订单款式状态修改
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_61.getValue());
GoblinBackOrderSkuVo backOrderSkuVo = GoblinBackOrderSkuVo.getNew();
backOrderSkuVo.setOrderSkuId(orderSkuId);
backOrderSkuVo.setSpuId(orderSkuVo.getSpuId());
backOrderSkuVo.setSpuName(orderSkuVo.getSpuName());
backOrderSkuVo.setSkuId(orderSkuVo.getSkuId());
backOrderSkuVo.setSkuName(orderSkuVo.getSkuName());
backOrderSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
backOrderSkuVo.setSkuPic(orderSkuVo.getSkuImage());
backOrderSkuVo.setRefundPrice(orderSkuVo.getSkuPriceActual());
backOrderSkuVo.setCreatedAt(nowStr);
orderSkuVoList.add(backOrderSkuVo);
backOrderLog(orderVo, orderSkuVo, now);
//redis
redisUtils.setGoblinOrderSku(orderSkuVo.getOrderSkuId(), orderSkuVo);
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuVo.getOrderSkuId(), orderSkuVo);
orderSkuStatus.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
}
}
} else {
return ResponseDto.failure("不可申请");
}
vo.setBackOrderSkuVos(orderSkuVoList);
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(param.getOrderId(), uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_21.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_1.getValue());
backOrderLog.setMessage("用户发起发起:" + JsonUtils.toJson(param));
//redis
redisUtils.setBackOrderVo(backOrder.getBackOrderId(), vo);
redisUtils.setGoblinOrder(orderVo.getOrderId(), orderVo);
redisUtils.addBackOrderByOrderId(orderVo.getOrderId(), backOrder.getBackOrderId());
//mongo
mongoUtils.insertGoblinBackOrderVo(vo);
mongoUtils.updateGoblinStoreOrderVo(orderVo.getOrderId(), orderVo);
//mysql
applyRefund.add(new Object[]{
backOrder.getBackOrderId(), backOrder.getBackCode(), backOrder.getOrderId(),
backOrder.getOrderCode(), backOrder.getStoreId(), backOrder.getUserId(),
backOrder.getSkuIdNums(), backOrder.getType(), backOrder.getReason(),
backOrder.getDescribes(), backOrder.getRealBackPrice(), backOrder.getBackPriceExpress(), backOrder.getStatus(),
backOrder.getLogisCompanyName(), backOrder.getMailNo(), backOrder.getPics(), backOrder.getCreatedAt()
});
//添加日志
refundLog.add(new Object[]{
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_USER_ORDER_OPERA.getKey(), SqlMapping.gets(sqls, applyRefund, orderStatus, orderSkuStatus, refundLog));
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> againRefund(GoblinAppOrderRefundParam param) {
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_order.user.againRefund"));
sqls.add(SqlMapping.get("goblin_order.store.refundLog"));
LinkedList<Object[]> applyRefund = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> refundLog = CollectionUtil.linkedListObjectArr();
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
GoblinBackOrderVo backOrder = redisUtils.getBackOrderVo(param.getOrderBackId());
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(backOrder.getOrderId());
if (!orderVo.getUserId().equals(uid) || !backOrder.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_3.getValue())) {
return ResponseDto.failure("无权操作");
}
if (!(orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_2.getValue() ||
orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue())) {
return ResponseDto.failure("不可操作");
}
//判断7天
LocalDateTime canRefundTime = getCanRefundTime(orderVo);
if (canRefundTime == null) {
return ResponseDto.failure("申请失败");
} else {
if (LocalDateTime.now().isAfter(canRefundTime)) {
return ResponseDto.failure("申请失败");
}
}
backOrder.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_1.getValue());
backOrder.setDescribes(param.getDescribes());
backOrder.setPics(param.getPics());
backOrder.setReason(param.getReason());
backOrder.setType(param.getRefundType());
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(backOrder.getOrderId(), uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_21.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_1.getValue());
backOrderLog.setMessage("用户再次发起退款:" + backOrder);
//redis
redisUtils.setBackOrderVo(backOrder.getBackOrderId(), backOrder);
//mongo
mongoUtils.updateGoblinBackOrderVo(backOrder.getBackOrderId(), backOrder);
//mysql
applyRefund.add(new Object[]{
backOrder.getStatus(),
backOrder.getDescribes(), backOrder.getPics(), backOrder.getReason(), backOrder.getType(),
now, backOrder.getBackOrderId()
});
//添加日志
refundLog.add(new Object[]{
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_USER_ORDER_OPERA.getKey(), SqlMapping.gets(sqls, applyRefund, refundLog));
return ResponseDto.success();
}
@Override
public ResponseDto<List<GoblinBackOrderVo>> refundDetails(String orderId) {
List<GoblinBackOrderVo> vos = ObjectUtil.goblinBackOrderVoArrayList();
List<String> backOrderList = redisUtils.getBackOrderByOrderId(orderId);
for (String backOrderId : backOrderList) {
GoblinBackOrderVo vo = redisUtils.getBackOrderVo(backOrderId);
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(vo.getOrderId());
vo.setPayType(orderVo.getPayType());
vos.add(vo);
}
return ResponseDto.success(vos);
}
@Override
public String huiFuSync(HttpServletRequest request) {
try {
// 验签请参data
String responseData = request.getParameter("resp_data");
// 验签请参sign
String sign = request.getParameter("sign");
// 使用汇付公钥验签
// if (!RsaUtils.verify(responseData, PUBLIC_KEY, sign)) {
// // 验签失败处理
// return "";
// }
JSONObject dataObj = JSON.parseObject(responseData);
String subRespCode = dataObj.getString("sub_resp_code");
String reqSeqId = dataObj.getString("req_seq_id");
String orderMasterCode = dataObj.getString("mer_ord_id");
String payCode = dataObj.getString("mer_ord_id");
String paymentType = dataObj.getString("trans_type");
String paymentId = dataObj.getString("hf_seq_id");
String paymentAt = dataObj.getString("end_time");
if ("00000000".equals(subRespCode)) {
log.debug("SYNC PARAM = " + responseData);
//支付时间
LocalDateTime now = LocalDateTime.now();
String[] array = redisUtils.getMasterCode(orderMasterCode);
String uid = "zhengzai";
BigDecimal priceActual = BigDecimal.ZERO;
for (String orderId : array) {
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
uid = orderVo.getUserId();
priceActual = priceActual.add(orderVo.getPriceActual());
if (orderVo == null) {
log.error("订单号:" + orderMasterCode + " 订单不存在");
return "fail";//订单不存在
}
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlDataOrder = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> sqlDataSku = CollectionUtil.linkedListObjectArr();
GoblinStoreOrder storeOrder = GoblinStoreOrder.getNew();
storeOrder.setPaymentType(paymentType);
storeOrder.setPaymentId(paymentId);
storeOrder.setPayCode(payCode);
LocalDateTime payTime = LocalDateTime.parse(paymentAt, DTFYMDHMS);
storeOrder.setPayTime(payTime);
if (orderVo.getWriteOffCode().equals("EMPTY")) {
storeOrder.setWriteOffCode(IDGenerator.getWriteOffCode());
} else {
storeOrder.setWriteOffCode("");
}
storeOrder.setStatus(GoblinStatusConst.Status.ORDER_STATUS_4.getValue());
storeOrder.setUpdatedAt(now);
sqls.add(SqlMapping.get("goblin_order.pay.order"));
sqlDataOrder.add(new Object[]{
storeOrder.getPaymentType(), storeOrder.getPaymentId(), storeOrder.getPayCode(), storeOrder.getPayTime(), storeOrder.getWriteOffCode(), storeOrder.getStatus(), storeOrder.getUpdatedAt(),
orderId, now, now
});
sqls.add(SqlMapping.get("goblin_order.pay.sku"));
List<String> skuList = orderVo.getOrderSkuVoIds();
for (String orderSkuVoIds : skuList) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuVoIds);
//增加销量
redisUtils.incrSkuSaleCount(orderSkuVo.getSpuId(), orderSkuVo.getSkuId(), orderSkuVo.getNum());
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_4.getValue());
//redis
redisUtils.setGoblinOrderSku(orderSkuVo.getOrderSkuId(), orderSkuVo);
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuVo.getOrderSkuId(), orderSkuVo);
//mongo 添加操作日志
GoblinOrderLogVo logVo = GoblinOrderLogVo.getNew();
logVo.setOrderId(orderVo.getOrderId());
logVo.setOrderCode(orderVo.getOrderCode());
logVo.setPayCode(orderVo.getPayCode());
logVo.setStoreId(orderVo.getStoreId());
if (orderSkuVo.getSkuId().indexOf(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()) > 0) {
logVo.setOrderType("zhengzai");
} else {
logVo.setOrderType("order");
}
logVo.setSpuId(orderSkuVo.getSpuId());
logVo.setSkuId(orderSkuVo.getSkuId());
logVo.setSkuPriceActual(orderSkuVo.getSkuPriceActual().multiply(new BigDecimal(100)).longValue());
logVo.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_11.getValue());
logVo.setRemark(GoblinStatusConst.Status.ORDER_LOG_STATUS_11.getDesc());
logVo.setOperationId(uid);
logVo.setOperationName(orderVo.getUserName());
logVo.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_1.getValue());
logVo.setCreatedAt(LocalDateTime.now());
mongoUtils.insertGoblinOrderLogVo(logVo);
//mysql
sqlDataSku.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
}
//redis
orderVo.setPayCode(storeOrder.getPayCode());
orderVo.setPayTime(paymentAt);
orderVo.setWriteOffCode(storeOrder.getWriteOffCode());
orderVo.setStatus(storeOrder.getStatus());
orderVo.setPaymentId(paymentId);
orderVo.setPaymentType(paymentType);
orderVo.setOrderSkuVoIds(skuList);
redisUtils.setGoblinOrder(orderId, orderVo);
redisUtils.setOffCode(orderVo.getWriteOffCode(), orderVo.getMasterOrderCode());
//删除未支付订单
redisUtils.removeGoblinOrder(orderVo.getRandomKey() + "", orderId);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_ORDER_CREATE_PAY.getKey(),
SqlMapping.gets(sqls, sqlDataOrder, sqlDataSku));
}
//加分
if (noZhengzaiOrder(uid)) {
orderUtils.doTask(uid, priceActual);
}
} else {
// 业务处理失败
log.info("处理失败");
}
return "RECV_ORD_ID_" + reqSeqId;
} catch (Exception e) {
log.info("异步回调开始,参数,request={},异常={}", request, e);
e.printStackTrace();
}
return "";
}
private GoblinBackOrderLog initBackLog(String orderId, String uid, LocalDateTime now) {
GoblinBackOrderLog log = GoblinBackOrderLog.getNew();
log.setBackOrderId(orderId);
log.setOperationName(uid);
log.setBackOrderLogId(IDGenerator.nextTimeId2());
log.setCreatedAt(now);
return log;
}
private void backOrderLog(GoblinStoreOrderVo orderVo, GoblinOrderSkuVo orderSkuVo, LocalDateTime now) {
//操作日志vo
GoblinOrderLogVo logVo = GoblinOrderLogVo.getNew();
logVo.setOrderId(orderVo.getOrderId());
logVo.setOrderCode(orderVo.getOrderCode());
logVo.setPayCode(orderVo.getPayCode());
if (orderSkuVo.getSkuId().indexOf(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()) > 0) {
logVo.setOrderType("zhengzai");
} else {
logVo.setOrderType("order");
}
logVo.setStoreId(orderVo.getStoreId());
logVo.setSpuId(orderSkuVo.getSpuId());
logVo.setSpuName(orderSkuVo.getSpuName());
logVo.setSkuId(orderSkuVo.getSkuId());
logVo.setSkuPriceActual(orderSkuVo.getSkuPriceActual().multiply(BigDecimal.valueOf(100)).negate().longValue());
logVo.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_21.getValue());
logVo.setRemark("申请退款,orderSkuVoId=" + orderSkuVo.getOrderSkuId());
logVo.setOperationId(orderVo.getUserId());
logVo.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
logVo.setCreatedAt(now);
mongoUtils.insertGoblinOrderLogVo(logVo);
}
@Override
public ResponseDto<List<GoblinMailVo>> getMail(String orderId, String mailId) {
List<GoblinMailVo> voList = redisUtils.getGoblinMail(orderId);
for (GoblinMailVo vo : voList) {
if (mailId.equals(vo.getMailId())) {
List<GoblinOrderSkuVo> orderSkuVos = ObjectUtil.getGoblinOrderSkuVoArrayList();
for (String orderSkuId : vo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
orderSkuVos.add(orderSkuVo);
}
vo.setOrderSkuVos(orderSkuVos);
}
}
return ResponseDto.success(voList);
}
//获取 订单剩余可支付时间[S]
private long getRestTime(GoblinStoreOrderVo orderVo) {
long restTime = 0L;
int time = orderVo.getPayCountdownMinute();
if (orderVo.getMarketType() != null && orderVo.getMarketType().equals(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())) {
time = 0;
}
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_0.getValue()) {
try {
Date OverdueAt = DateUtil.addMin(DateUtil.parse(orderVo.getCreatedAt(), "yyyy-MM-dd HH:mm:ss"), time);
restTime = DateUtil.intervalSeconds(
OverdueAt,
DateUtil.parse(DateUtil.getNowTime(), "yyyy-MM-dd HH:mm:ss")
);
if (restTime <= 0L) {
restTime = 0L;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return restTime;
}
//获取 可申请退款时间
private LocalDateTime getCanRefundTime(GoblinStoreOrderVo orderVo) {
LocalDateTime canRefundTimeDateTime = null;
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_2.getValue() || orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue()) {
try {
canRefundTimeDateTime = LocalDateTime.parse(orderVo.getPayTime(), DTF_YMD_HMS).plusDays(7);
} catch (Exception e) {
e.printStackTrace();
}
}
return canRefundTimeDateTime;
}
private boolean noZhengzaiOrder(String uid) {
return !uid.equals("zhengzai");
}
}
package com.liquidnet.service.goblin.service.impl;
import com.liquidnet.service.goblin.service.GoblinStoreService;
import org.springframework.stereotype.Service;
@Service
public class GoblinStoreServiceImpl implements GoblinStoreService {
}
package com.liquidnet.service.goblin.service.impl;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.IGoblinStoreZhengzaiService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import static com.liquidnet.commons.lang.util.DateUtil.DTF_YMD_HMS;
@Service
public class GoblinStoreZhengzaiServiceImpl implements IGoblinStoreZhengzaiService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
QueueUtils queueUtils;
@Override
public ResponseDto<List<GoblinSelfMarketingVo>> getZhengzaiMarketList() {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("店铺不存在");
}
String storeId = storeInfoVo.getStoreId();
List<String> marketIds = redisUtils.getStoreZhengzaiRelation(storeId);//可参加的正在活动id
List<GoblinSelfMarketingVo> list = redisUtils.getGoblinSelfMarketingVoList();//所有正在下单活动列表
List<GoblinSelfMarketingVo> voList = ObjectUtil.getGoblinSelfMarketingVoList();
LocalDateTime now = LocalDateTime.now();
for (GoblinSelfMarketingVo item : list) {
GoblinMarketingZhengzaiRelationVo zhengzaiRelationVo = redisUtils.getZhengzaiRelation(item.getSelfMarketId(), storeId);
if (LocalDateTime.parse(item.getEndTime(), DTF_YMD_HMS).isAfter(now) && zhengzaiRelationVo != null) {
if (marketIds.contains(item.getSelfMarketId())) {
List<GoblinMarketRelationVo> relationVo = redisUtils.getMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), item.getSelfMarketId());
List<String> storeIdList = relationVo.stream().map(GoblinMarketRelationVo::getStoreId).distinct().collect(Collectors.toList());//配置了商铺的店铺
if (storeIdList.contains(storeId)) {
voList.add(item);
}
}
}
}
return ResponseDto.success(voList);
}
@Override
public ResponseDto<List<GoblinZhengzaiGoodVo>> getSpuList(String marketId) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("店铺不存在");
}
String storeId = storeInfoVo.getStoreId();
List<GoblinMarketRelationVo> relationVo = redisUtils.getMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketId);
List<String> spuIdList = relationVo.stream().map(GoblinMarketRelationVo::getSpuId).collect(Collectors.toList());
List<GoblinZhengzaiGoodVo> voList = ObjectUtil.getGoblinZhengzaiGoodVoArrayList();
for (String spuId : spuIdList) {
GoblinGoodsInfoVo vo = redisUtils.getGoodsInfoVo(spuId);
if (vo.getShelvesStatus().equals("3") && vo.getStoreId().equals(storeId)) {
GoblinZhengzaiGoodVo returnVo = GoblinZhengzaiGoodVo.getNew();
BeanUtils.copyProperties(vo, returnVo);
voList.add(returnVo);
}
}
return ResponseDto.success(voList);
}
@Override
public ResponseDto<List<GoblinAppOrderListVo>> orderList(int page) {
String uid = CurrentUtil.getCurrentUid();
List<GoblinAppOrderListVo> orderVoList = ObjectUtil.goblinAppOrderListVoArrayList();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
List<GoblinStoreOrderVo> mongoVoList = mongoUtils.storeZhengzaiOrderList(page, storeInfoVo.getStoreId());
for (GoblinStoreOrderVo orderVo : mongoVoList) {
GoblinAppOrderListVo vo = GoblinAppOrderListVo.getNew();
BeanUtils.copyProperties(orderVo, vo);
vo.setRestTime(getRestTime(orderVo));
List<GoblinOrderSkuVo> skuVos = ObjectUtil.getGoblinOrderSkuVoArrayList();
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
skuVos.add(orderSkuVo);
}
vo.setOrderSkuVos(skuVos);
orderVoList.add(vo);
}
return ResponseDto.success(orderVoList);
}
@Override
public ResponseDto<Boolean> orderPush(String orderMasterCode) {
String[] orderIds = redisUtils.getMasterCode(orderMasterCode);
LocalDateTime now = LocalDateTime.now();
LinkedList<Object[]> sqlDataOrder = CollectionUtil.linkedListObjectArr();
if (orderIds == null) {
return ResponseDto.failure("订单不存在");
} else {
for (String orderId : orderIds) {
GoblinStoreOrderVo storeOrderVo = redisUtils.getGoblinOrder(orderId);
storeOrderVo.setZhengzaiStatus(1);
//mongo
mongoUtils.updateGoblinStoreOrderVo(storeOrderVo.getOrderId(), storeOrderVo);
//redis
redisUtils.setGoblinOrder(storeOrderVo.getOrderId(), storeOrderVo);
sqlDataOrder.add(new Object[]{
1, now, storeOrderVo.getOrderId(), now, now
});
}
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.zhengzai.bind", sqlDataOrder));
}
return ResponseDto.success();
}
//获取 订单剩余可支付时间[S]
private long getRestTime(GoblinStoreOrderVo orderVo) {
long restTime = 0L;
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_0.getValue()) {
try {
Date OverdueAt = DateUtil.addMin(DateUtil.parse(orderVo.getCreatedAt(), "yyyy-MM-dd HH:mm:ss"), orderVo.getPayCountdownMinute());
restTime = DateUtil.intervalSeconds(
OverdueAt,
DateUtil.parse(DateUtil.getNowTime(), "yyyy-MM-dd HH:mm:ss")
);
if (restTime <= 0L) {
restTime = 0L;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return restTime;
}
}
package com.liquidnet.service.goblin.service.impl.inner;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.TempCouponDto;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.service.GoblinFrontService;
import com.liquidnet.service.goblin.service.manage.IGoblinInnerService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Slf4j
@Service
public class GoblinInnerServiceImpl implements IGoblinInnerService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinFrontService goblinFrontService;
@Override
public ResponseDto<String> insertCoupon(MultipartFile file, String performanceId) {
try {
EasyExcel.read(file.getInputStream(), TempCouponDto.class, new PageReadListener<TempCouponDto>(dataList -> {
redisUtils.delMarketTempCoupon(performanceId);
for (TempCouponDto data : dataList) {
if (data.getSpuId() == null) {
continue;
}
List<String> spuList = Arrays.asList(data.getSpuId().split(","));
TempCouponVo vo = TempCouponVo.getNew();
vo.setName(data.getName());
vo.setType(data.getType());
vo.setValue(data.getValue());
vo.setIsDefault(data.getIsDefault());
vo.setSpuIdList(spuList);
vo.setStoreCouponId(data.getStoreCouponId());
redisUtils.addMarketTempCoupon(performanceId, vo.getStoreCouponId());
redisUtils.setTempCoupon(vo.getStoreCouponId(), vo);
}
})).sheet().doRead();
} catch (Exception e) {
e.printStackTrace();
}
return ResponseDto.success("完成");
}
@Override
public ResponseDto<ArDataVo> getArData(String tag, String performanceId) {
ArDataVo vo = ArDataVo.getNew();
//券
ArrayList<TempCouponVo> tempCouponVos = ObjectUtil.getTempCouponVo();
List<String> ucouponIds = redisUtils.getMarketTempCoupon(performanceId);
for (String ucouponId : ucouponIds) {
TempCouponVo tempCouponVo = redisUtils.getTempCoupon(ucouponId);
tempCouponVos.add(tempCouponVo);
}
vo.setTempCouponVos(tempCouponVos);
//商品
List<GoblinGoodsInfoVo> goodsInfoVos = goblinFrontService.getGoodByMusicTagP(tag, performanceId);
for (GoblinGoodsInfoVo spuVo : goodsInfoVos) {
List<GoblinGoodsSkuInfoVo> skuVoList = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList();
for (String skuId : spuVo.getSkuIdList()) {
GoblinGoodsSkuInfoVo skuVo = redisUtils.getGoodsSkuInfoVo(skuId);
skuVoList.add(skuVo);
}
spuVo.setGoblinOrderSkuVos(skuVoList);
}
vo.setGoodsInfoVos(goodsInfoVos);
return ResponseDto.success(vo);
}
@Override
public ResponseDto<TempCouponVo> getTempCouponData(String ucouponId) {
TempCouponVo tempCouponVo = redisUtils.getTempCoupon(ucouponId);
return ResponseDto.success(tempCouponVo);
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinBackOrderLog;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreBackOrderService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
@Service
@Slf4j
public class GoblinStoreBackOrderServiceImpl implements IGoblinStoreBackOrderService {
// todo hujiachen 日志没加
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
QueueUtils queueUtils;
@Value("${liquidnet.service.order.url-pay.goblinRefundUrl}")
private String synUrl;
@Value("${liquidnet.service.dragon.urls.refundApply}")
private String refundApply;
@Override
public ResponseDto<PageInfo<GoblinStoreBackOrderListVo>> orderBackList(Integer page, String orderBackCode, Integer type, String cst, String cet, String orderCode, String spuName, Integer status) {
List<GoblinStoreBackOrderListVo> listVos = ObjectUtil.goblinStoreBackOrderListVoArrayList();
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
HashMap<String, Object> map = mongoUtils.storeBackOrderList(storeInfoVo.getStoreId(), page, orderBackCode, type, cst, cet, orderCode, spuName, status);
long total = (long) map.get("total");
List<GoblinBackOrderVo> voList = (List<GoblinBackOrderVo>) map.get("data");
for (GoblinBackOrderVo item : voList) {
GoblinStoreBackOrderListVo vo = GoblinStoreBackOrderListVo.getNew();
vo.setCreatedAt(item.getCreatedAt());
vo.setBackOrderId(item.getBackOrderId());
vo.setBackCode(item.getBackCode());
vo.setBackOrderSkuVos(item.getBackOrderSkuVos());
vo.setOrderCode(item.getOrderCode());
vo.setRealBackPrice(item.getRealBackPrice());
vo.setStatus(item.getStatus());
vo.setType(item.getType());
listVos.add(vo);
}
PageInfo<GoblinStoreBackOrderListVo> pageInfo = new PageInfo(listVos);
pageInfo.setTotal(total);
return ResponseDto.success(pageInfo);
}
@Override
public ResponseDto<GoblinBackOrderDetailsVo> orderDetails(String backOrderId) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(backOrderVo.getOrderId());
GoblinBackOrderDetailsVo vo = GoblinBackOrderDetailsVo.getNew();
BeanUtils.copyProperties(backOrderVo, vo);
vo.setPayTime(orderVo.getPayTime());
vo.setPriceVoucher(orderVo.getPriceVoucher());
vo.setPriceExpress(orderVo.getPriceExpress());
vo.setPriceActual(orderVo.getPriceActual());
vo.setIsMember(orderVo.getIsMember());
vo.setUserName(orderVo.getUserName());
vo.setUserMobile(orderVo.getUserMobile());
if (orderVo.getMarketId() == null || orderVo.getMarketId().equals("")) {
vo.setMarketName("");
} else {
GoblinSelfMarketingVo marketingVo = redisUtils.getSelfMarket(orderVo.getMarketId().split("ZZ")[1]);
vo.setMarketName(marketingVo.getName());
}
List<GoblinOrderSkuVo> orderSkuVoList = ObjectUtil.getGoblinOrderSkuVoArrayList();
for (String orderSkuVoId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuVoId);
orderSkuVo.setStatus(vo.getStatus());
orderSkuVoList.add(orderSkuVo);
}
vo.setOrderSkuVoList(orderSkuVoList);
return ResponseDto.success(vo);
}
@Override
public ResponseDto<Boolean> changeExpressRefund(String backOrderId, BigDecimal refundPrice) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
BigDecimal sub = backOrderVo.getBackPriceExpress().subtract(refundPrice);
backOrderVo.setBackPriceExpress(refundPrice);
backOrderVo.setRealBackPrice(backOrderVo.getRealBackPrice().subtract(sub));
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(backOrderId, uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
backOrderLog.setMessage("商户退款-修改快递费:backOrderId=[" + backOrderId + "],refundPrice=[" + refundPrice + "]");
//redis
redisUtils.setBackOrderVo(backOrderId, backOrderVo);
//mongo
mongoUtils.updateGoblinBackOrderVo(backOrderId, backOrderVo);
//mysql
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.changeExpress",
backOrderVo.getRealBackPrice(), backOrderVo.getBackPriceExpress(), now,
backOrderId, now, now
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.refundLog",
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> agreeRefund(String backOrderId) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
backOrderVo.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_0.getValue());
backOrderVo.setAuditAt(nowStr);
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(backOrderId, uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
backOrderLog.setMessage("商户退款-同意退款:backOrderId=[" + backOrderId + "]");
//调用退款
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(backOrderVo.getOrderId());
String returnString = initRefund(orderVo, backOrderVo.getRealBackPrice(), backOrderVo.getBackCode());
HashMap hashMapResult = JsonUtils.fromJson(returnString, HashMap.class);
Boolean success = (Boolean) hashMapResult.get("success");
String message = (String) hashMapResult.get("message");
if (!success) {
backOrderVo.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_10.getValue());
backOrderVo.setErrorReason("失败原因:" + message);
log.error("REFUND DATA = " + returnString);
}
//redis
redisUtils.setBackOrderVo(backOrderId, backOrderVo);
//mongo
mongoUtils.updateGoblinBackOrderVo(backOrderId, backOrderVo);
//mysql
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.applyRefund",
backOrderVo.getStatus(), backOrderVo.getReason(), backOrderVo.getAuditAt(), now,
backOrderId, now, now
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.refundLog",
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> refusedRefund(String backOrderId) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
backOrderVo.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_3.getValue());
backOrderVo.setRefuseAt(nowStr);
backOrderVo.setRefuseSize(backOrderVo.getRefuseSize() == null ? 1 : backOrderVo.getRefuseSize() + 1);
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(backOrderId, uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
backOrderLog.setMessage("商户退款-拒绝退款:backOrderId=[" + backOrderId + "]");
//redis
redisUtils.setBackOrderVo(backOrderId, backOrderVo);
//mongo
mongoUtils.updateGoblinBackOrderVo(backOrderId, backOrderVo);
//mysql
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.backOrderStatus",
backOrderVo.getStatus(), backOrderVo.getAuditAt(), backOrderVo.getRefuseSize(), now,
backOrderId, now, now
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.refundLog",
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> changeSkuRefund(String backOrderId, BigDecimal refundPrice, String orderSkuId) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
BigDecimal sub = BigDecimal.ZERO;
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
for (GoblinBackOrderSkuVo backOrderSkuVo : backOrderVo.getBackOrderSkuVos()) {
if (backOrderSkuVo.getOrderSkuId().equals(orderSkuId)) {
sub = backOrderSkuVo.getRefundPrice().subtract(refundPrice);
backOrderSkuVo.setRefundPrice(refundPrice);
break;
}
}
backOrderVo.setRealBackPrice(backOrderVo.getRealBackPrice().subtract(sub));
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(backOrderId, uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
backOrderLog.setMessage("商户退款-修改sku价格:backOrderId=[" + backOrderId + "],refundPrice=[" + refundPrice + "],orderSkuId=[" + orderSkuId + "]");
//redis
redisUtils.setBackOrderVo(backOrderId, backOrderVo);
//mongo
mongoUtils.updateGoblinBackOrderVo(backOrderId, backOrderVo);
//mysql
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.changeSku",
backOrderVo.getRealBackPrice(), now,
backOrderId, now, now
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.refundLog",
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
)
);
return ResponseDto.success();
}
private GoblinBackOrderLog initBackLog(String orderId, String uid, LocalDateTime now) {
GoblinBackOrderLog log = GoblinBackOrderLog.getNew();
log.setBackOrderId(orderId);
log.setOperationName(uid);
log.setBackOrderLogId(IDGenerator.nextTimeId2());
log.setCreatedAt(now);
return log;
}
private String initRefund(GoblinStoreOrderVo orderVo, BigDecimal price, String refundCode) {
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("code", orderVo.getPayCode());
params.add("notifyUrl", synUrl);
params.add("orderCode", orderVo.getMasterOrderCode());
params.add("orderRefundCode", refundCode);
params.add("paymentId", orderVo.getPaymentId());
params.add("paymentType", orderVo.getPaymentType());
params.add("price", String.valueOf(price));
params.add("priceTotal", String.valueOf(orderVo.getPriceActual()));
params.add("reason", "按需退款");
MultiValueMap<String, String> headers = CollectionUtil.linkedMultiValueMapStringString();
headers.add("Accept", "application/json;charset=UTF-8");
String returnString = HttpUtil.post(refundApply, params, headers);
log.debug("REFUND DATA = " + returnString);
return returnString;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreGoodsCategoryVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtCategoryService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
@Slf4j
@Service
public class GoblinStoreMgtCategoryServiceImpl implements IGoblinStoreMgtCategoryService {
@Autowired
private QueueUtils queueUtils;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinMongoUtils goblinMongoUtils;
@Override
public List<GoblinStoreGoodsCategoryVo> list(String storeId) {
return goblinRedisUtils.getStoreGoodsCategoryVos(storeId);
}
@Override
public void add(String storeId, List<GoblinStoreGoodsCategoryVo> addStoreGoodsCategoryVos, List<GoblinStoreGoodsCategoryVo> storeGoodsCategoryVosCache) {
goblinMongoUtils.setStoreGoodsCategoryVos(addStoreGoodsCategoryVos);
if (CollectionUtils.isEmpty(storeGoodsCategoryVosCache)) {
storeGoodsCategoryVosCache = addStoreGoodsCategoryVos;
} else {
storeGoodsCategoryVosCache.addAll(addStoreGoodsCategoryVos);
}
goblinRedisUtils.setStoreGoodsCategoryVos(storeId, storeGoodsCategoryVosCache);
LinkedList<Object[]> initStoreGoodsCategoryObjs = CollectionUtil.linkedListObjectArr();
addStoreGoodsCategoryVos.forEach(r -> initStoreGoodsCategoryObjs.add(new Object[]{
r.getStoreId(), r.getCateId(), r.getName(), r.getSort(), r.getGrade(), r.getCatePid(), r.getNeIsbn(), r.getCreatedBy(), r.getCreatedAt()
}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_goods_category.insert", initStoreGoodsCategoryObjs));
}
@Override
public boolean edit(GoblinStoreGoodsCategoryVo updateStoreGoodsCategoryVo, List<GoblinStoreGoodsCategoryVo> storeGoodsCategoryVosCache) {
if (goblinMongoUtils.updateStoreGoodsCategoryVo(updateStoreGoodsCategoryVo)) {
goblinRedisUtils.setStoreGoodsCategoryVos(updateStoreGoodsCategoryVo.getStoreId(), storeGoodsCategoryVosCache);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(), SqlMapping.get("goblin_store_goods_category.update",
updateStoreGoodsCategoryVo.getName(), updateStoreGoodsCategoryVo.getSort(), updateStoreGoodsCategoryVo.getUpdatedBy(),
updateStoreGoodsCategoryVo.getUpdatedAt(), updateStoreGoodsCategoryVo.getStoreId(), updateStoreGoodsCategoryVo.getCateId())
);
return true;
}
return false;
}
@Override
public boolean del(String uid, String storeId, String cateId) {
List<GoblinStoreGoodsCategoryVo> storeGoodsCategoryVosCache = goblinRedisUtils.getStoreGoodsCategoryVos(storeId);
int beforeSize = storeGoodsCategoryVosCache.size();
storeGoodsCategoryVosCache.removeIf(r -> r.getCateId().equals(cateId));
int afterSize = storeGoodsCategoryVosCache.size();
if (beforeSize > afterSize) {
LocalDateTime now = LocalDateTime.now();
GoblinStoreGoodsCategoryVo delStoreGoodsCategoryVo = GoblinStoreGoodsCategoryVo.getNew();
delStoreGoodsCategoryVo.setStoreId(storeId);
delStoreGoodsCategoryVo.setCateId(cateId);
delStoreGoodsCategoryVo.setDelFlg("1");
delStoreGoodsCategoryVo.setUpdatedBy(uid);
delStoreGoodsCategoryVo.setUpdatedAt(now);
delStoreGoodsCategoryVo.setDeletedBy(uid);
delStoreGoodsCategoryVo.setDeletedAt(now);
if (goblinMongoUtils.updateStoreGoodsCategoryVo(delStoreGoodsCategoryVo)) {
goblinRedisUtils.setStoreGoodsCategoryVos(storeId, storeGoodsCategoryVosCache);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_goods_category.remove",
uid, now, uid, now, storeId, cateId)
);
return true;
}
} else {
log.warn("###店铺商品分类管理:删除:分类不存在[uid={},storeId={},cateId={}]", uid, storeId, cateId);
}
return false;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCertificationParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCompleteParam;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCertificationVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtCertificationService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
@Slf4j
@Service
public class GoblinStoreMgtCertificationServiceImpl implements IGoblinStoreMgtCertificationService {
@Autowired
QueueUtils queueUtils;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinMongoUtils goblinMongoUtils;
@Override
public GoblinStoreInfoVo certificationInformationProcessing(GoblinStoreMgtCertificationParam param, GoblinStoreInfoVo storeInfoVo) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
if (null == storeInfoVo) {
storeInfoVo = GoblinStoreInfoVo.getNew();
storeInfoVo.setStoreId(IDGenerator.get32UUID());
storeInfoVo.setUid(uid);
storeInfoVo.setStatus("0");
storeInfoVo.setStoreType("0");
storeInfoVo.setCertType(param.getCertType());
storeInfoVo.setDelFlg("0");
storeInfoVo.setCreatedAt(now);
storeInfoVo.setCreatedBy(uid);
storeInfoVo.setUpdatedBy(uid);
storeInfoVo.setUpdatedAt(now);
GoblinStoreCertificationVo storeCertificationVo = param.initStoreCertificationVo();
storeInfoVo.setCertificationVo(storeCertificationVo);
goblinMongoUtils.setStoreInfoVo(storeInfoVo);
goblinRedisUtils.addStoreId(uid, storeInfoVo.getStoreId());
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
LinkedList<Object[]> initStoreInfoObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_store_info.insert_by_cert"));
initStoreInfoObjs.add(new Object[]{
storeInfoVo.getStoreId(), storeInfoVo.getUid(), storeInfoVo.getStatus(), storeInfoVo.getStoreType(),
storeInfoVo.getCertType(), storeInfoVo.getCreatedBy(), storeInfoVo.getCreatedAt()
});
toMqSqls.add(SqlMapping.get("goblin_store_certification.insert_by_cert"));
LinkedList<Object[]> initStoreCertificationObjs = CollectionUtil.linkedListObjectArr();
initStoreCertificationObjs.add(new Object[]{
storeInfoVo.getStoreId(), storeCertificationVo.getPersonCertType(), storeCertificationVo.getPersonName(),
storeCertificationVo.getPersonCertCode(), storeCertificationVo.getPersonCertValidity(), storeCertificationVo.getPersonCertLasting(),
storeCertificationVo.getPersonCertFpic(), storeCertificationVo.getPersonCertBpic(), storeCertificationVo.getPersonCertSpic(),
storeCertificationVo.getProvinceId(), storeCertificationVo.getProvinceName(), storeCertificationVo.getCityId(),
storeCertificationVo.getCityName(), storeCertificationVo.getCountyId(), storeCertificationVo.getCountyName(),
storeCertificationVo.getBusAddress(), storeCertificationVo.getBusName(), storeCertificationVo.getBusCertCode(),
storeCertificationVo.getBusCertValidity(), storeCertificationVo.getBusCertLasting(), storeCertificationVo.getBusCertPic(),
storeCertificationVo.getBusQualityPic(), storeInfoVo.getCreatedBy(), storeInfoVo.getCreatedAt()
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.gets(toMqSqls, initStoreInfoObjs, initStoreCertificationObjs));
} else {
storeInfoVo.setStatus("0");
storeInfoVo.setStoreType("0");
storeInfoVo.setUpdatedBy(uid);
storeInfoVo.setUpdatedAt(now);
GoblinStoreCertificationVo storeCertificationVo = param.initStoreCertificationVo();
storeInfoVo.setCertificationVo(storeCertificationVo);
if (goblinMongoUtils.updateStoreInfoVo(storeInfoVo)) {
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
LinkedList<Object[]> updateStoreInfoObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_store_info.update_by_cert1"));
updateStoreInfoObjs.add(new Object[]{
storeInfoVo.getStoreType(), storeInfoVo.getCertType(),
storeInfoVo.getUpdatedBy(), storeInfoVo.getUpdatedAt(), storeInfoVo.getStoreId(),
});
toMqSqls.add(SqlMapping.get("goblin_store_certification.update_by_cert"));
LinkedList<Object[]> updateStoreCertificationObjs = CollectionUtil.linkedListObjectArr();
updateStoreCertificationObjs.add(new Object[]{
storeCertificationVo.getPersonCertType(), storeCertificationVo.getPersonName(),
storeCertificationVo.getPersonCertCode(), storeCertificationVo.getPersonCertValidity(), storeCertificationVo.getPersonCertLasting(),
storeCertificationVo.getPersonCertFpic(), storeCertificationVo.getPersonCertBpic(), storeCertificationVo.getPersonCertSpic(),
storeCertificationVo.getProvinceId(), storeCertificationVo.getProvinceName(), storeCertificationVo.getCityId(),
storeCertificationVo.getCityName(), storeCertificationVo.getCountyId(), storeCertificationVo.getCountyName(),
storeCertificationVo.getBusAddress(), storeCertificationVo.getBusName(), storeCertificationVo.getBusCertCode(),
storeCertificationVo.getBusCertValidity(), storeCertificationVo.getBusCertLasting(), storeCertificationVo.getBusCertPic(),
storeCertificationVo.getBusQualityPic(), storeInfoVo.getUpdatedBy(), storeInfoVo.getUpdatedAt(), storeInfoVo.getStoreId()
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.gets(toMqSqls, updateStoreInfoObjs, updateStoreCertificationObjs));
}
}
return storeInfoVo;
}
@Override
public boolean certificationCompleteProcessing(GoblinStoreMgtCompleteParam param, GoblinStoreInfoVo storeInfoVo) {
storeInfoVo.setUpdatedAt(LocalDateTime.now());
storeInfoVo.setUpdatedBy(CurrentUtil.getCurrentUid());
if (goblinMongoUtils.updateStoreInfoVo(param.completeStoreInfoVo(storeInfoVo))) {
goblinRedisUtils.setStoreInfoVo(storeInfoVo);
// LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
// LinkedList<Object[]> updateStoreInfoObjs = CollectionUtil.linkedListObjectArr();
// toMqSqls.add(SqlMapping.get("goblin_store_info.update_by_cert2"));
// updateStoreInfoObjs.add(new Object[]{
// storeInfoVo.getStoreName(), storeInfoVo.getLogoPic(), storeInfoVo.getBackgroundPic(), storeInfoVo.getIntroduce(),
// storeInfoVo.getStoreType(), storeInfoVo.getUpdatedBy(), storeInfoVo.getUpdatedAt(), storeInfoVo.getStoreId()
// });
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_info.update_by_cert2",
storeInfoVo.getStoreName(), storeInfoVo.getLogoPic(), storeInfoVo.getBackgroundPic(), storeInfoVo.getIntroduce(),
storeInfoVo.getStatus(), storeInfoVo.getStoreType(), storeInfoVo.getUpdatedBy(), storeInfoVo.getUpdatedAt(), storeInfoVo.getStoreId())
);
return true;
}
return false;
}
@Override
public boolean certificationCancelProcessing(String storeId, String uid) {
LocalDateTime now = LocalDateTime.now();
if (goblinMongoUtils.delStoreInfoVo(storeId, uid, now)) {
goblinRedisUtils.delStoreId(CurrentUtil.getCurrentUid(), storeId);
goblinRedisUtils.delStoreInfoVo(storeId);
goblinRedisUtils.delStoreConfigVos(storeId);
List<String> delSpuIdList = goblinMongoUtils.delGoodsInfoVoByStoreId(storeId, uid, now);
delSpuIdList.forEach(spuId -> goblinRedisUtils.delGoodsInfoVo(spuId));
List<String> delSkuIdList = goblinMongoUtils.delGoodsSkuInfoVoByStoreId(storeId, uid, now);
delSkuIdList.forEach(skuId -> goblinRedisUtils.delGoodsSkuInfoVo(skuId));
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_store_info.update_by_del"));
LinkedList<Object[]> updateStoreObjs = CollectionUtil.linkedListObjectArr();
updateStoreObjs.add(new Object[]{uid, now, storeId});
toMqSqls.add(SqlMapping.get("goblin_store_certification.update_by_del"));
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_del_store"));
LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
updateGoodsObjs.add(new Object[]{uid, now, uid, now, storeId});
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_del_store"));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(), SqlMapping.gets(toMqSqls, updateStoreObjs, updateStoreObjs, updateGoodsObjs, updateGoodsObjs));
}
return false;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.dto.GoblinStoreMarketDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponActionParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponFilterParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponSpuListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfGoodsCategoryVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponBasicVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService;
import com.liquidnet.service.goblin.service.manage.IGoblinstoreMgtCouponService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class GoblinStoreMgtCouponServiceImpl implements IGoblinstoreMgtCouponService {
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
IGoblinStoreMgtExtraService goblinStoreMgtExtraService;
@Override
public PagedResult<GoblinStoreMgtCouponListVo> couponList(GoblinStoreMgtCouponFilterParam filterParam) {
PagedResult<GoblinStoreMgtCouponListVo> mgtCouponListVoPagedResult = goblinMongoUtils.getMgtStoreCouponListVos(filterParam);
if (mgtCouponListVoPagedResult.getTotal() > 0) {
List<GoblinStoreMgtCouponListVo> volist = mgtCouponListVoPagedResult.getList();
List<String> storeCouponIdList = volist.stream().map(GoblinStoreMgtCouponListVo::getStoreCouponId).collect(Collectors.toList());
List<Document> aggregateUserCouponResults = goblinMongoUtils.aggregateMgtUserCoupon(storeCouponIdList);
if (!CollectionUtils.isEmpty(aggregateUserCouponResults)) {
volist.forEach(vo -> {
List<Document> aggregateUserCouponResult = aggregateUserCouponResults.stream()
.filter(r -> r.getString("storeCouponId").equals(vo.getStoreCouponId())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(aggregateUserCouponResult)) {
int receiveNum = 0, usedNum = 0;
for (Document aggregateDoc : aggregateUserCouponResult) {
Integer totalCount = aggregateDoc.getInteger("totalCount");
switch (aggregateDoc.getInteger("state")) {// 用户券状态[1-可用|2-无效|3-已过期|5-已使用]
case 5:
usedNum += totalCount;
default:
receiveNum += totalCount;
}
}
vo.setReceiveNum(receiveNum);
vo.setUsedNum(usedNum);
}
});
} else {
}
}
return mgtCouponListVoPagedResult;
}
@Override
public void couponActivityProcessing(GoblinStoreMgtCouponActionParam mgtCouponActionParam, String uid) {
LocalDateTime now = LocalDateTime.now();
String storeId = mgtCouponActionParam.getStoreId();
String state = mgtCouponActionParam.getAction().equals("DISABLED") ? "3" : "0";
List<String> storeCouponIdList = mgtCouponActionParam.getStoreCouponIdList();
if (goblinMongoUtils.activityMgtStoreCouponBasicVo(uid, now, state, storeCouponIdList)) {
storeCouponIdList.forEach(storeCouponId -> goblinRedisUtils.del(GoblinRedisConst.STORE_COUPON.concat(storeCouponId)));// 删除REDIS缓存
List<GoblinStoreMarketDto> storeMarketDtos = goblinRedisUtils.getStoreMarketDtos(storeId);
if (!CollectionUtils.isEmpty(storeMarketDtos)) {
int beforeSize = storeMarketDtos.size();
storeMarketDtos.removeIf(dto -> (dto.getType() == 1 && storeCouponIdList.contains(dto.getId())));
if (beforeSize > storeMarketDtos.size()) {
goblinRedisUtils.setStoreMarketDtos(storeId, storeMarketDtos);
}
}
LinkedList<Object[]> activityStoreCouponObjs = CollectionUtil.linkedListObjectArr();
storeCouponIdList.forEach(storeCouponId -> activityStoreCouponObjs.add(new Object[]{state, uid, now, storeCouponId}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_store_coupon.activity", activityStoreCouponObjs));
}
}
@Override
public void couponRemove(GoblinStoreMgtCouponActionParam mgtCouponActionParam, String uid) {
LocalDateTime now = LocalDateTime.now();
String storeId = mgtCouponActionParam.getStoreId();
List<String> storeCouponIdList = mgtCouponActionParam.getStoreCouponIdList();
if (goblinMongoUtils.delMgtStoreCouponBasicVos(storeCouponIdList, uid, now)) {
storeCouponIdList.forEach(storeCouponId -> goblinRedisUtils.del(GoblinRedisConst.STORE_COUPON.concat(storeCouponId)));// 删除REDIS缓存
List<GoblinStoreMarketDto> storeMarketDtos = goblinRedisUtils.getStoreMarketDtos(storeId);
if (!CollectionUtils.isEmpty(storeMarketDtos)) {
int beforeSize = storeMarketDtos.size();
storeMarketDtos.removeIf(dto -> (dto.getType() == 1 && storeCouponIdList.contains(dto.getId())));
if (beforeSize > storeMarketDtos.size()) {
goblinRedisUtils.setStoreMarketDtos(storeId, storeMarketDtos);
}
}
LinkedList<Object[]> deleteStoreCouponObjs = CollectionUtil.linkedListObjectArr();
storeCouponIdList.forEach(storeCouponId -> deleteStoreCouponObjs.add(new Object[]{uid, now, storeCouponId}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_store_coupon.delete", deleteStoreCouponObjs));
}
}
@Override
public void couponAdd(String uid, GoblinStoreCouponBasicVo storeCouponBasicVo) {
String storeCouponId = IDGenerator.nextMilliId();
LocalDateTime now = LocalDateTime.now();
boolean activityStartFlg = storeCouponBasicVo.getStartTime().isBefore(now);
storeCouponBasicVo.setState(activityStartFlg ? "1" : "0");
storeCouponBasicVo.setStoreCouponId(storeCouponId);
storeCouponBasicVo.setStoreCouponNo(storeCouponId);
storeCouponBasicVo.setDelFlg("0");
storeCouponBasicVo.setCreatedAt(now);
storeCouponBasicVo.setCreatedBy(uid);
goblinMongoUtils.setMgtStoreCouponBasicVo(storeCouponBasicVo);
Integer stock = storeCouponBasicVo.getStock();
if (!stock.equals(0)) {
goblinRedisUtils.setStoreCouponStock(storeCouponId, stock);
}
if (activityStartFlg) {// 活动已开始,处理店铺活动数据
GoblinStoreMarketDto storeMarketDto = GoblinStoreMarketDto.getNew();
storeMarketDto.setId(storeCouponId);
storeMarketDto.setType(1);
goblinRedisUtils.addStoreMarketDto(storeCouponBasicVo.getStoreId(), storeMarketDto);
}
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_store_coupon.insert"));
LinkedList<Object[]> initStoreCouponObjs = CollectionUtil.linkedListObjectArr();
initStoreCouponObjs.add(new Object[]{
storeCouponId, storeCouponBasicVo.getStoreCouponNo(), storeCouponBasicVo.getStoreId(),
storeCouponBasicVo.getTitle(), storeCouponBasicVo.getLabel(), storeCouponBasicVo.getNotice(),
storeCouponBasicVo.getType(), stock, storeCouponBasicVo.getTriggers(),
storeCouponBasicVo.getValFace(), storeCouponBasicVo.getDiscount(), storeCouponBasicVo.getValOver(),
storeCouponBasicVo.getValMinus(), storeCouponBasicVo.getDeduction(), storeCouponBasicVo.getReceiveLimit(),
storeCouponBasicVo.getReceiveCurb(), storeCouponBasicVo.getUseScope(), storeCouponBasicVo.getState(),
storeCouponBasicVo.getStartTime(), storeCouponBasicVo.getEndTime(), storeCouponBasicVo.getCreatedBy(),
storeCouponBasicVo.getCreatedAt()
});
toMqSqls.add(SqlMapping.get("goblin_store_coupon_rule.insert"));
LinkedList<Object[]> initStoreCouponRuleObjs = CollectionUtil.linkedListObjectArr();
if ("1".equals(storeCouponBasicVo.getUseScope()) && !CollectionUtils.isEmpty(storeCouponBasicVo.getSpuIdList())) {// 部分商品
storeCouponBasicVo.getSpuIdList().forEach(spuId -> initStoreCouponRuleObjs.add(new Object[]{storeCouponId, spuId, uid, now}));
}
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.gets(toMqSqls, initStoreCouponObjs, initStoreCouponRuleObjs));
}
@Override
public GoblinStoreMgtCouponInfoVo couponInfo(String storeId, String storeCouponId) {
GoblinStoreMgtCouponInfoVo mgtCouponInfoVo = GoblinStoreMgtCouponInfoVo.getNew();
GoblinStoreCouponVo couponVo = goblinRedisUtils.getStoreCouponVo(storeCouponId);
if (null != couponVo && couponVo.getStoreId().equals(storeId)) {
mgtCouponInfoVo.setCouponVo(couponVo);
if ("1".equals(couponVo.getUseScope())) {
List<String> spuIds = goblinRedisUtils.getStoreCouponSpuIds(storeCouponId);
if (!CollectionUtils.isEmpty(spuIds)) {
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinStoreMgtExtraService.listCategoryVo();
ArrayList<GoblinStoreMgtCouponSpuListVo> couponSpuListVos = ObjectUtil.getGoblinStoreMgtCouponSpuListVoArrayList();
spuIds.forEach(spuId -> {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null != goodsInfoVo && goodsInfoVo.getDelFlg().equals("0")) {
String cateFid = goodsInfoVo.getCateFid(), cateSid = goodsInfoVo.getCateSid(), cateTid = goodsInfoVo.getCateTid();
List<GoblinSelfGoodsCategoryVo> categoryVoList = selfGoodsCategoryVos.stream()
.filter(cr -> Arrays.asList(cateFid, cateSid, cateTid).contains(cr.getCateId())).collect(Collectors.toList());
categoryVoList.forEach(cr -> {
if (cr.getCateId().equals(cateFid)) goodsInfoVo.setCateFid(cr.getName());
if (cr.getCateId().equals(cateSid)) goodsInfoVo.setCateSid(cr.getName());
if (cr.getCateId().equals(cateTid)) goodsInfoVo.setCateTid(cr.getName());
});
couponSpuListVos.add(GoblinStoreMgtCouponSpuListVo.getNew().copy(goodsInfoVo));
}
});
mgtCouponInfoVo.setSpuVoList(couponSpuListVos);
}
}
}
return mgtCouponInfoVo;
}
@Override
public boolean couponEdit(String uid, GoblinStoreCouponBasicVo storeCouponBasicVo) {
String storeCouponId = storeCouponBasicVo.getStoreCouponId();
LocalDateTime now = LocalDateTime.now();
boolean activityStopFlg = storeCouponBasicVo.getEndTime().isBefore(now);
storeCouponBasicVo.setState(activityStopFlg ? "2" : storeCouponBasicVo.getState());
storeCouponBasicVo.setUpdatedAt(now);
storeCouponBasicVo.setUpdatedBy(uid);
if (goblinMongoUtils.updateMgtStoreCouponBasicVo(storeCouponBasicVo)) {
if (activityStopFlg) {// 活动已结束,处理店铺活动数据
GoblinStoreMarketDto storeMarketDto = GoblinStoreMarketDto.getNew();
storeMarketDto.setId(storeCouponId);
storeMarketDto.setType(1);
goblinRedisUtils.delStoreMarketDto(storeCouponBasicVo.getStoreId(), storeMarketDto);
}
goblinRedisUtils.del(GoblinRedisConst.STORE_COUPON.concat(storeCouponId));// 删除REDIS缓存
goblinRedisUtils.del(GoblinRedisConst.STORE_COUPON_RULE.concat(storeCouponId));// 删除REDIS缓存
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_store_coupon.update"));
LinkedList<Object[]> updateStoreCouponObjs = CollectionUtil.linkedListObjectArr();
updateStoreCouponObjs.add(new Object[]{
storeCouponBasicVo.getTitle(), storeCouponBasicVo.getLabel(), storeCouponBasicVo.getNotice(),
storeCouponBasicVo.getType(), storeCouponBasicVo.getTriggers(), storeCouponBasicVo.getValFace(),
storeCouponBasicVo.getDiscount(), storeCouponBasicVo.getValOver(), storeCouponBasicVo.getValMinus(),
storeCouponBasicVo.getDeduction(), storeCouponBasicVo.getReceiveLimit(), storeCouponBasicVo.getReceiveCurb(),
storeCouponBasicVo.getUseScope(), storeCouponBasicVo.getStartTime(), storeCouponBasicVo.getEndTime(),
storeCouponBasicVo.getUpdatedBy(), storeCouponBasicVo.getUpdatedAt(), storeCouponId
});
toMqSqls.add(SqlMapping.get("goblin_store_coupon_rule.update_del"));
LinkedList<Object[]> delStoreCouponRuleObjs = CollectionUtil.linkedListObjectArr();
delStoreCouponRuleObjs.add(new Object[]{uid, now, storeCouponId});
toMqSqls.add(SqlMapping.get("goblin_store_coupon_rule.insert"));
LinkedList<Object[]> initStoreCouponRuleObjs = CollectionUtil.linkedListObjectArr();
if ("1".equals(storeCouponBasicVo.getUseScope()) && !CollectionUtils.isEmpty(storeCouponBasicVo.getSpuIdList())) {// 部分商品
storeCouponBasicVo.getSpuIdList().forEach(spuId -> initStoreCouponRuleObjs.add(new Object[]{storeCouponId, spuId, uid, now}));
}
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.gets(toMqSqls, updateStoreCouponObjs, delStoreCouponRuleObjs, initStoreCouponRuleObjs));
return true;
}
return false;
}
@Override
public boolean couponEditStock(GoblinStoreCouponVo storeCouponVo, String uid, int operStock) {
String storeCouponId = storeCouponVo.getStoreCouponId();
Integer stock = storeCouponVo.getStock();
int surplusStock, operStockVal = Math.abs(operStock);
if (operStock < 0) {
surplusStock = goblinRedisUtils.decrStoreCouponStock(storeCouponId, operStockVal);
if (surplusStock < 0) {
goblinRedisUtils.incrStoreCouponStock(storeCouponId, operStock);
log.warn("商铺活动:优惠券库存编辑:[storeCouponId={},operStock={},surplusStock={},uid={}]", storeCouponId, operStock, surplusStock, uid);
return false;
}
stock -= operStockVal;
} else {
surplusStock = goblinRedisUtils.incrStoreCouponStock(storeCouponId, operStockVal);
stock += operStockVal;
}
log.info("商铺活动:优惠券库存编辑:[storeCouponId={},operStock={},surplusStock={},uid={}]", storeCouponId, operStock, surplusStock, uid);
LocalDateTime now = LocalDateTime.now();
goblinMongoUtils.updateMgtStoreCouponStock(storeCouponId, stock, uid, now);
if (stock.equals(0)) {
goblinRedisUtils.delStoreCouponStock(storeCouponId);
}
goblinRedisUtils.del(GoblinRedisConst.STORE_COUPON.concat(storeCouponId));// 删除REDIS缓存
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_store_coupon.update_stock", stock, uid, now, storeCouponId));
return true;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfGoodsCategoryVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfTagVo;
import com.liquidnet.service.goblin.dto.vo.GoblinServiceSupportVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.QueueUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.LinkedList;
import java.util.List;
@Service
public class GoblinStoreMgtExtraServiceImpl implements IGoblinStoreMgtExtraService {
@Autowired
private QueueUtils queueUtils;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinMongoUtils goblinMongoUtils;
@Override
public List<GoblinSelfGoodsCategoryVo> listCategoryVo() {
return goblinRedisUtils.getSelfGoodsCategoryVos();
}
@Override
public List<GoblinSelfTagVo> listTagVo(String keyword, String belong, String... typeRange) {
return goblinMongoUtils.getSelfTagVos(keyword, belong, typeRange);
}
@Override
public List<GoblinServiceSupportVo> listServiceSupportVo() {
List<GoblinServiceSupportVo> serviceSupportVos = goblinRedisUtils.getServiceSupportVos();
if (CollectionUtils.isEmpty(serviceSupportVos)) {
serviceSupportVos.add(GoblinServiceSupportVo.getNew().setName("正品保证").setDesc("商品为正版行货").setSsid("101"));
serviceSupportVos.add(GoblinServiceSupportVo.getNew().setName("极速发货").setDesc("24小时内发送货物").setSsid("102"));
serviceSupportVos.add(GoblinServiceSupportVo.getNew().setName("无忧退货").setDesc("支持7天无理由退款").setSsid("103"));
goblinMongoUtils.insertMgtServiceSupportVos(serviceSupportVos);
LinkedList<Object[]> upsertServiceSupportObjs = CollectionUtil.linkedListObjectArr();
serviceSupportVos.forEach(vo -> upsertServiceSupportObjs.add(new Object[]{vo.getSsid(), vo.getName(), vo.getDesc(), vo.getUrl()}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_service_support.insert_byreplace", upsertServiceSupportObjs));
}
return serviceSupportVos;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsActionParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsAddParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsEditSkuParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsFilterParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.enums.GoblinStoreConf;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService;
import com.liquidnet.service.goblin.service.manage.IGoblinstoreMgtGoodsService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class GoblinStoreMgtGoodsServiceImpl implements IGoblinstoreMgtGoodsService {
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
IGoblinStoreMgtExtraService goblinStoreMgtExtraService;
@Override
public PagedResult<GoblinStoreMgtGoodsListVo> goodsList(GoblinStoreMgtGoodsFilterParam mgtGoodsFilterParam) {
PagedResult<GoblinStoreMgtGoodsListVo> goodsListVoPagedResult = goblinMongoUtils.getMgtGoodsInfoVos(mgtGoodsFilterParam);
if (goodsListVoPagedResult.getTotal() > 0) {
List<GoblinStoreMgtGoodsListVo> voList = goodsListVoPagedResult.getList();
// 存在关联活动的SPUNO获取
List<String> relateMarketSpuNoList = goblinMongoUtils.getMgtSpuNosForMarketBySpuNos(
voList.stream().map(GoblinStoreMgtGoodsListVo::getSpuNo).collect(Collectors.toList()), "3");
// 库存预警配置获取
List<GoblinStoreConfigVo> storeConfigVos = goblinRedisUtils.getStoreConfigVos(mgtGoodsFilterParam.getStoreId());
Optional<GoblinStoreConfigVo> optional = storeConfigVos.stream().filter(r -> r.getConfigKey().equals(GoblinStoreConf.LIMIT_WARNING_STOCK.name())).findAny();
Integer warningStock = optional.map(goblinStoreConfigVo -> Integer.parseInt(goblinStoreConfigVo.getConfigVal())).orElse(5);
// 商品分类获取
List<GoblinSelfGoodsCategoryVo> selfGoodsCategoryVos = goblinStoreMgtExtraService.listCategoryVo();
voList.forEach(vo -> {
GoblinGoodsInfoVo mgtGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(vo.getSpuId());
int totalStock = 0, surplusStock = 0;
for (String skuId : mgtGoodsInfoVo.getSkuIdList()) {
GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null != mgtGoodsSkuInfoVo && mgtGoodsSkuInfoVo.getDelFlg().equals("0")) {
totalStock += mgtGoodsSkuInfoVo.getStock();
surplusStock += goblinRedisUtils.getSkuStock(null, skuId);
List<String> skuReList = goblinRedisUtils.getSkuRe(skuId);
if (!CollectionUtils.isEmpty(skuReList))
for (String skuRe : skuReList)
surplusStock += goblinRedisUtils.getSkuStock(GoblinStatusConst.MarketPreStatus.getPre(skuRe), skuRe);
}
}
vo.setTotalStock(totalStock);
vo.setSurplusStock(surplusStock);
vo.setWarningStock(warningStock);
vo.setRelateMarket(relateMarketSpuNoList.contains(vo.getSpuNo()) ? 1 : 0);
String cateFid = vo.getCateFid(), cateSid = vo.getCateSid(), cateTid = vo.getCateTid();
List<GoblinSelfGoodsCategoryVo> categoryVoList = selfGoodsCategoryVos.stream()
.filter(cr -> Arrays.asList(cateFid, cateSid, cateTid).contains(cr.getCateId())).collect(Collectors.toList());
categoryVoList.forEach(cr -> {
if (cr.getCateId().equals(cateFid)) vo.setCateFid(cr.getName());
if (cr.getCateId().equals(cateSid)) vo.setCateSid(cr.getName());
if (cr.getCateId().equals(cateTid)) vo.setCateTid(cr.getName());
});
});
goodsListVoPagedResult.setList(voList);
}
return goodsListVoPagedResult;
}
@Override
public void goodsAdd(GoblinGoodsInfoVo goodsInfoVo, List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList) {
goblinMongoUtils.setGoodsInfoVo(goodsInfoVo);
goblinMongoUtils.setGoodsSkuInfoVos(goodsSkuInfoVoList);
if (goodsInfoVo.getShelvesHandle().equals("2")) {
goblinRedisUtils.deleteKeyForSelectGoods();// 精选商品:商品上架、下架、删除 调用的方法
}
String createdBy = goodsInfoVo.getCreatedBy();
LocalDateTime createdAt = goodsInfoVo.getCreatedAt();
String spuId = goodsInfoVo.getSpuId();
LinkedList<Object[]> initGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> initGoodsSkuSpecValueObjs = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> initGoodsCategorySpecObjs = CollectionUtil.linkedListObjectArr();
{// 分类规格记录
String cateFid = goodsInfoVo.getCateFid(), cateSid = goodsInfoVo.getCateSid(), cateTid = goodsInfoVo.getCateTid();
String filterCateId = StringUtils.isBlank(cateTid) ? (StringUtils.isBlank(cateSid) ? cateFid : cateSid) : cateTid;
GoblinMgtCategorySpecVo mgtCategorySpecVoCache = goblinRedisUtils.getCategorySpec(filterCateId);// 分类绑定的规格信息
List<String> addSpecNameList = goodsSkuInfoVoList.get(0).getSkuSpecList().stream().map(GoblinGoodsSpecDto::getSpecName).collect(Collectors.toList());
if (null == mgtCategorySpecVoCache) {// 根据分类ID未查取到规格信息,则Cache、数据库新增
GoblinMgtCategorySpecVo initMgtCategorySpecVo = GoblinMgtCategorySpecVo.getNew().setCateId(filterCateId).setSpecNameList(addSpecNameList);
goblinMongoUtils.setCategorySpecVo(initMgtCategorySpecVo);
goblinRedisUtils.setCategorySpec(filterCateId, initMgtCategorySpecVo);
addSpecNameList.forEach(r -> initGoodsCategorySpecObjs.add(new Object[]{filterCateId, r}));
} else {// 根据分类ID查取到规格信息,则进一步比对判断是否新增
List<String> confirmAddSpecNameList = addSpecNameList.stream().filter(r -> !mgtCategorySpecVoCache.getSpecNameList().contains(r)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(confirmAddSpecNameList)) {// 不存在于`mgtCategorySpecVoCache`的,则更新Cache,数据库新增
mgtCategorySpecVoCache.getSpecNameList().addAll(confirmAddSpecNameList);
goblinMongoUtils.updateCategorySpecVo(mgtCategorySpecVoCache);
goblinRedisUtils.setCategorySpec(filterCateId, mgtCategorySpecVoCache);
confirmAddSpecNameList.forEach(r -> initGoodsCategorySpecObjs.add(new Object[]{filterCateId, r}));
}
}
}
int skuSize = goodsSkuInfoVoList.size();
for (int i = 0; i < skuSize; i++) {
GoblinGoodsSkuInfoVo skuInfoVo = goodsSkuInfoVoList.get(i);
String skuId = skuInfoVo.getSkuId();
String buyRoster = skuInfoVo.getBuyRoster();
goblinRedisUtils.setSkuStock(null, skuId, skuInfoVo.getSkuStock());
initGoodsSkuObjs.add(new Object[]{
skuId, skuInfoVo.getSpuId(), skuInfoVo.getSkuNo(), skuInfoVo.getName(), skuInfoVo.getSubtitle(),
skuInfoVo.getSellPrice(), skuInfoVo.getSkuPic(), skuInfoVo.getSkuIsbn(), skuInfoVo.getStock(), skuInfoVo.getSkuStock(),
skuInfoVo.getWarningStock(), skuInfoVo.getPrice(), skuInfoVo.getPriceMember(), skuInfoVo.getWeight(), skuInfoVo.getBuyFactor(),
buyRoster, skuInfoVo.getBuyLimit(), skuInfoVo.getStoreId(), skuInfoVo.getSkuValidity(), skuInfoVo.getVirtualFlg(),
skuInfoVo.getStatus(), skuInfoVo.getShelvesStatus(), skuInfoVo.getSkuAppear(), skuInfoVo.getShelvesAt(), createdBy,
createdAt, skuInfoVo.getLogisticsTemplate()
});
skuInfoVo.getSkuSpecList().forEach(skuSpecDto -> initGoodsSkuSpecValueObjs.add(new Object[]{
spuId, skuId, skuSpecDto.getSpecName(), skuSpecDto.getSpecVname()
}));
if (skuInfoVo.getBuyFactor().equals("2") && StringUtils.isNotBlank(buyRoster) && buyRoster.startsWith("http")) {
queueUtils.sendMsgByRedisXls(buyRoster, "1", skuId);
}
}
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods.insert"));
LinkedList<Object[]> initGoodsObjs = CollectionUtil.linkedListObjectArr();
initGoodsObjs.add(new Object[]{
spuId, goodsInfoVo.getSpuNo(), goodsInfoVo.getName(), goodsInfoVo.getSubtitle(), goodsInfoVo.getSellPrice(),
goodsInfoVo.getPriceGe(), goodsInfoVo.getPriceLe(), goodsInfoVo.getIntro(), goodsInfoVo.getDetails(), goodsInfoVo.getCoverPic(),
goodsInfoVo.getVideo(), goodsInfoVo.getSpecMode(), goodsInfoVo.getStoreId(), goodsInfoVo.getCateFid(), goodsInfoVo.getCateSid(),
goodsInfoVo.getCateTid(), goodsInfoVo.getStoreCateFid(), goodsInfoVo.getStoreCateSid(), goodsInfoVo.getStoreCateTid(), goodsInfoVo.getBrandId(),
goodsInfoVo.getShelvesHandle(), goodsInfoVo.getShelvesTime(), goodsInfoVo.getSpuValidity(), goodsInfoVo.getVirtualFlg(), goodsInfoVo.getStatus(),
goodsInfoVo.getShelvesStatus(), goodsInfoVo.getSpuAppear(), goodsInfoVo.getShelvesAt(), createdBy, createdAt,
goodsInfoVo.getLogisticsTemplate()
});
toMqSqls.add(SqlMapping.get("goblin_goods_sku.insert"));
toMqSqls.add(SqlMapping.get("goblin_goods_image.insert_byreplace"));
LinkedList<Object[]> initGoodsImageObjs = CollectionUtil.linkedListObjectArr();
if (CollectionUtils.isEmpty(goodsInfoVo.getImageList())) {
goodsInfoVo.getImageList().forEach(imageUrl -> initGoodsImageObjs.add(new Object[]{spuId, imageUrl}));
}
toMqSqls.add(SqlMapping.get("goblin_goods_tag.insert_byreplace"));
LinkedList<Object[]> initGoodsTagObjs = CollectionUtil.linkedListObjectArr();
if (!CollectionUtils.isEmpty(goodsInfoVo.getTagVoList())) {
goodsInfoVo.getTagVoList().forEach(tagVo -> initGoodsTagObjs.add(new Object[]{spuId, tagVo.getTagId(), tagVo.getSort(), "0"}));
}
if (!CollectionUtils.isEmpty(goodsInfoVo.getExtagVoList())) {
goodsInfoVo.getExtagVoList().forEach(exTagVo -> initGoodsTagObjs.add(new Object[]{spuId, exTagVo.getTagId(), exTagVo.getSort(), "1"}));
}
toMqSqls.add(SqlMapping.get("goblin_goods_artag.insert_byreplace"));
LinkedList<Object[]> initGoodsArTagObjs = CollectionUtil.linkedListObjectArr();
if (!CollectionUtils.isEmpty(goodsInfoVo.getArtagVoList())) {
goodsInfoVo.getArtagVoList().forEach(arTagVo -> initGoodsArTagObjs.add(new Object[]{spuId, arTagVo.getTagId(), arTagVo.getSort(), "1"}));
}
toMqSqls.add(SqlMapping.get("goblin_goods_service_support.insert_byreplace"));
LinkedList<Object[]> initGoodsServiceSupportObjs = CollectionUtil.linkedListObjectArr();
if (!CollectionUtils.isEmpty(goodsInfoVo.getServiceSupportVoList())) {
goodsInfoVo.getServiceSupportVoList().forEach(ssvo -> initGoodsServiceSupportObjs.add(new Object[]{spuId, ssvo.getSsid()}));
}
toMqSqls.add(SqlMapping.get("goblin_goods_spec.insert_byreplace"));
LinkedList<Object[]> initGoodsSpecObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_spec_value.insert_byreplace"));
LinkedList<Object[]> initGoodsSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_spu_spec_value.insert_byreplace"));// SPU规格信息
LinkedList<Object[]> initGoodsSpuSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_sku_spec_value.insert_byreplace"));// SKU规格信息
{// 规格记录
List<GoblinGoodsSpecVo> specVoList = goodsInfoVo.getSpecVoList();
specVoList.forEach(s -> {
initGoodsSpecObjs.add(new Object[]{s.getSpecName(), createdAt});
s.getSpecValues().forEach(sv -> {
initGoodsSpecValueObjs.add(new Object[]{s.getSpecName(), sv.getSpecVname(), createdAt});
initGoodsSpuSpecValueObjs.add(new Object[]{spuId, s.getSpecName(), sv.getSpecVname(), sv.getSpecVsort()});
});
});
}
toMqSqls.add(SqlMapping.get("goblin_goods_category_spec.insert_byreplace"));// 分类关联规格信息
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, initGoodsObjs, initGoodsSkuObjs, initGoodsImageObjs,
initGoodsTagObjs, initGoodsArTagObjs, initGoodsServiceSupportObjs, initGoodsSpecObjs, initGoodsSpecValueObjs,
initGoodsSpuSpecValueObjs, initGoodsSkuSpecValueObjs, initGoodsCategorySpecObjs)
);
}
@Override
public GoblinStoreMgtGoodsInfoVo goodsInfo(String storeId, String spuId) {
GoblinStoreMgtGoodsInfoVo vo = GoblinStoreMgtGoodsInfoVo.getNew();
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null != goodsInfoVo && goodsInfoVo.getStoreId().equals(storeId) && goodsInfoVo.getDelFlg().equals("0")) {
vo.setGoodsInfoVo(goodsInfoVo);
List<String> skuIdList = goodsInfoVo.getSkuIdList();
if (!CollectionUtils.isEmpty(skuIdList)) {
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList();
skuIdList.forEach(skuId -> {
GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null != mgtGoodsSkuInfoVo && mgtGoodsSkuInfoVo.getDelFlg().equals("0")) {
mgtGoodsSkuInfoVo.setSurplusStock(goblinRedisUtils.getSkuStock(null, skuId));
goodsSkuInfoVoList.add(mgtGoodsSkuInfoVo);
}
});
vo.setGoodsSkuInfoVoList(goodsSkuInfoVoList);
}
}
return vo;
}
@Override
public boolean goodsEditSpu(String uid, GoblinStoreMgtGoodsAddParam storeMgtGoodsAddParam, GoblinGoodsInfoVo mgtGoodsInfoVo) {
String spuId = storeMgtGoodsAddParam.getSpuId();
GoblinGoodsInfoVo updateSpuInfoVo = storeMgtGoodsAddParam.initEditGoodsInfoVo();
boolean updateTagFlg = false, updateExtagFlg = false, updateArtagFlg = false;
List<GoblinGoodsTagVo> befTagVoList = mgtGoodsInfoVo.getTagVoList();
boolean befTagIsEmptyFlg = CollectionUtils.isEmpty(befTagVoList);
List<GoblinGoodsExtagVo> befExtagVoList = mgtGoodsInfoVo.getExtagVoList();
boolean befExtagIsEmptyFlg = CollectionUtils.isEmpty(befExtagVoList);
List<GoblinGoodsExtagVo> befArtagVoList = mgtGoodsInfoVo.getArtagVoList();
boolean befArtagIsEmptyFlg = CollectionUtils.isEmpty(befArtagVoList);
boolean paramTagIsEmptyFlg, paramExtagIsEmptyFlg, paramArtagIsEmptyFlg;
List<GoblinGoodsTagVo> paramTagVoList = ObjectUtil.getGoblinGoodsTagVoArrayList();
List<GoblinGoodsExtagVo> paramExtagVoList = ObjectUtil.getGoblinGoodsExtagVoArrayList();
List<GoblinGoodsExtagVo> paramArtagVoList = ObjectUtil.getGoblinGoodsExtagVoArrayList();
{// 标签处理
List<String> goodsTagIdList = storeMgtGoodsAddParam.getTagList(),
goodsExtagIdList = storeMgtGoodsAddParam.getExtagList(),
goodsArtagIdList = storeMgtGoodsAddParam.getArtagList();
if (!CollectionUtils.isEmpty(goodsTagIdList)) {
List<GoblinSelfTagVo> selfGoodsTagVos = goblinRedisUtils.getSelfTagVos();
for (int i = 0; i < goodsTagIdList.size(); i++)
for (GoblinSelfTagVo r : selfGoodsTagVos)
if (r.getTagId().equals(goodsTagIdList.get(i)) && r.getTagBelong().equals("0")) {
paramTagVoList.add(GoblinGoodsTagVo.getNew().copy(r).setSort(i));
break;
}
}
List<GoblinSelfTagVo> selfExtagVos = null;
if (!CollectionUtils.isEmpty(goodsExtagIdList)) {
selfExtagVos = goblinRedisUtils.getSelfExtagVos();
for (int i = 0; i < goodsExtagIdList.size(); i++)
for (GoblinSelfTagVo r : selfExtagVos)
if (r.getTagId().equals(goodsExtagIdList.get(i)) && r.getTagBelong().equals("1") && !r.getTagType().equals("5")) {
paramExtagVoList.add(GoblinGoodsExtagVo.getNew().copy(r).setSort(i));
break;
}
}
if (!CollectionUtils.isEmpty(goodsArtagIdList)) {
selfExtagVos = CollectionUtils.isEmpty(selfExtagVos) ? goblinRedisUtils.getSelfExtagVos() : selfExtagVos;
for (int i = 0; i < goodsArtagIdList.size(); i++)
for (GoblinSelfTagVo r : selfExtagVos)
if (r.getTagId().equals(goodsArtagIdList.get(i)) && r.getTagBelong().equals("1")) {
paramArtagVoList.add(GoblinGoodsExtagVo.getNew().copy(r).setSort(i));
break;
}
}
paramTagIsEmptyFlg = CollectionUtils.isEmpty(paramTagVoList);
paramExtagIsEmptyFlg = CollectionUtils.isEmpty(paramExtagVoList);
paramArtagIsEmptyFlg = CollectionUtils.isEmpty(paramArtagVoList);
if (!befTagIsEmptyFlg || !paramTagIsEmptyFlg) {
if (!befTagIsEmptyFlg && !paramTagIsEmptyFlg) {
if (paramTagVoList.size() != befTagVoList.size()) {
updateTagFlg = true;
} else {
List<String> befTagIdList = befTagVoList.stream().map(GoblinGoodsTagVo::getTagId).collect(Collectors.toList());
for (GoblinGoodsTagVo vo : paramTagVoList) {
if (!befTagIdList.contains(vo.getTagId())) {
updateTagFlg = true;
break;
}
}
}
} else {
updateTagFlg = true;
}
}
if (updateTagFlg) {
updateSpuInfoVo.setTagVoList(paramTagIsEmptyFlg ? ObjectUtil.getGoblinGoodsTagVoArrayList() : paramTagVoList);
}
if (!befExtagIsEmptyFlg || !paramExtagIsEmptyFlg) {
if (!befExtagIsEmptyFlg && !paramExtagIsEmptyFlg) {
if (paramExtagVoList.size() != befExtagVoList.size()) {
updateExtagFlg = true;
} else {
List<String> befExtagIdList = befExtagVoList.stream().map(GoblinGoodsExtagVo::getTagId).collect(Collectors.toList());
for (GoblinGoodsExtagVo vo : paramExtagVoList) {
if (!befExtagIdList.contains(vo.getTagId())) {
updateExtagFlg = true;
break;
}
}
}
} else {
updateExtagFlg = true;
}
}
if (updateExtagFlg) {
updateSpuInfoVo.setExtagVoList(paramExtagIsEmptyFlg ? ObjectUtil.getGoblinGoodsExtagVoArrayList() : paramExtagVoList);
}
if (!befArtagIsEmptyFlg || !paramArtagIsEmptyFlg) {
if (!befArtagIsEmptyFlg && !paramArtagIsEmptyFlg) {
if (paramArtagVoList.size() != befArtagVoList.size()) {
updateArtagFlg = true;
} else {
List<String> befArtagIdList = befArtagVoList.stream().map(GoblinGoodsExtagVo::getTagId).collect(Collectors.toList());
for (GoblinGoodsExtagVo vo : paramArtagVoList) {
if (!befArtagIdList.contains(vo.getTagId())) {
updateArtagFlg = true;
break;
}
}
}
} else {
updateArtagFlg = true;
}
}
if (updateArtagFlg) {
updateSpuInfoVo.setArtagVoList(paramArtagIsEmptyFlg ? ObjectUtil.getGoblinGoodsExtagVoArrayList() : paramArtagVoList);
}
}
boolean updateSsidFlg = false;
List<String> ssidList = storeMgtGoodsAddParam.getSsidList();
boolean paramSsidListIsEmptyFlg = CollectionUtils.isEmpty(ssidList);
List<GoblinServiceSupportVo> serviceSupportVoList = mgtGoodsInfoVo.getServiceSupportVoList();
boolean befServiceSupportVoListIsEmptyFlg = CollectionUtils.isEmpty(serviceSupportVoList);
{// 服务支持处理
if (!befServiceSupportVoListIsEmptyFlg || !paramSsidListIsEmptyFlg) {
if (!befServiceSupportVoListIsEmptyFlg && !paramSsidListIsEmptyFlg) {
if (serviceSupportVoList.size() != ssidList.size()) {
updateSsidFlg = true;
} else {
List<String> befSsidList = serviceSupportVoList.stream().map(GoblinServiceSupportVo::getSsid).collect(Collectors.toList());
for (String ssid : ssidList) {
if (!befSsidList.contains(ssid)) {
updateSsidFlg = true;
break;
}
}
}
} else {
updateSsidFlg = true;
}
}
if (updateSsidFlg) {
updateSpuInfoVo.setServiceSupportVoList(paramSsidListIsEmptyFlg ? ObjectUtil.getGoblinServiceSupportVoArrayList() : goblinMongoUtils.getServiceSupportVos(ssidList));
}
}
boolean updateImageFlg = false;
List<String> paramImageList = storeMgtGoodsAddParam.getImageList();
List<String> befImageList = mgtGoodsInfoVo.getImageList();
{// 图片处理
if (befImageList.size() != paramImageList.size()) {
updateImageFlg = true;
} else {
for (String imageUrl : paramImageList) {
if (!befImageList.contains(imageUrl)) {
updateImageFlg = true;
break;
}
}
}
if (updateImageFlg) {
updateSpuInfoVo.setImageList(paramImageList);
}
}
updateSpuInfoVo.setUpdatedBy(uid);
updateSpuInfoVo.setUpdatedAt(LocalDateTime.now());
if (goblinMongoUtils.updateGoodsInfoVo(updateSpuInfoVo)) {
GoblinGoodsSkuInfoVo updateSkuInfoVo = GoblinGoodsSkuInfoVo.getNew();
updateSkuInfoVo.setSpuId(updateSpuInfoVo.getSpuId());
updateSkuInfoVo.setSkuNo(updateSpuInfoVo.getSpuNo());
// updateSkuInfoVo.setName(updateSpuInfoVo.getName());
// updateSkuInfoVo.setSubtitle(updateSpuInfoVo.getSubtitle());
updateSkuInfoVo.setVirtualFlg(updateSpuInfoVo.getVirtualFlg());
updateSkuInfoVo.setLogisticsTemplate(updateSpuInfoVo.getLogisticsTemplate());
updateSkuInfoVo.setUpdatedBy(updateSpuInfoVo.getUpdatedBy());
updateSkuInfoVo.setUpdatedAt(updateSpuInfoVo.getUpdatedAt());
LinkedList<Object[]> updateGoodsInfoObjs = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
// 参与活动的同一商品更新处理
List<String> marketSpuIdList = goblinMongoUtils.updateGoodsInfoVoForMarket(spuId, mgtGoodsInfoVo.getSpuNo(), updateSpuInfoVo);
if (!CollectionUtils.isEmpty(marketSpuIdList)) {
marketSpuIdList.forEach(marketSpuId -> {
goblinRedisUtils.delGoodsInfoVo(marketSpuId);
updateGoodsInfoObjs.add(new Object[]{
updateSpuInfoVo.getSpuNo(), updateSpuInfoVo.getName(), updateSpuInfoVo.getSubtitle(), updateSpuInfoVo.getSellPrice(),
updateSpuInfoVo.getIntro(), updateSpuInfoVo.getDetails(), updateSpuInfoVo.getCoverPic(), updateSpuInfoVo.getVideo(),
"2", updateSpuInfoVo.getCateFid(), updateSpuInfoVo.getCateSid(), updateSpuInfoVo.getCateTid(),
updateSpuInfoVo.getShelvesHandle(), updateSpuInfoVo.getShelvesTime(), updateSpuInfoVo.getSpuValidity(), updateSpuInfoVo.getVirtualFlg(),
updateSpuInfoVo.getLogisticsTemplate(), updateSpuInfoVo.getUpdatedBy(), updateSpuInfoVo.getUpdatedAt(), marketSpuId
});
updateGoodsSkuObjs.add(new Object[]{
updateSkuInfoVo.getSkuNo(), updateSkuInfoVo.getVirtualFlg(), updateSkuInfoVo.getLogisticsTemplate(),
updateSkuInfoVo.getUpdatedBy(), updateSkuInfoVo.getUpdatedAt(), marketSpuId
});
});
}
goblinMongoUtils.updateGoodsSkuInfoVoBySpuId(updateSkuInfoVo);
goblinRedisUtils.delGoodsInfoVo(updateSpuInfoVo.getSpuId());
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_edit"));
// LinkedList<Object[]> updateGoodsInfoObjs = CollectionUtil.linkedListObjectArr();
updateGoodsInfoObjs.add(new Object[]{
updateSpuInfoVo.getSpuNo(), updateSpuInfoVo.getName(), updateSpuInfoVo.getSubtitle(), updateSpuInfoVo.getSellPrice(),
updateSpuInfoVo.getIntro(), updateSpuInfoVo.getDetails(), updateSpuInfoVo.getCoverPic(), updateSpuInfoVo.getVideo(),
updateSpuInfoVo.getSpecMode(), updateSpuInfoVo.getCateFid(), updateSpuInfoVo.getCateSid(), updateSpuInfoVo.getCateTid(),
updateSpuInfoVo.getShelvesHandle(), updateSpuInfoVo.getShelvesTime(), updateSpuInfoVo.getSpuValidity(), updateSpuInfoVo.getVirtualFlg(),
updateSpuInfoVo.getLogisticsTemplate(), updateSpuInfoVo.getUpdatedBy(), updateSpuInfoVo.getUpdatedAt(), updateSpuInfoVo.getSpuId()
});
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_edit_spu"));
// LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
updateGoodsSkuObjs.add(new Object[]{
updateSkuInfoVo.getSkuNo(), updateSkuInfoVo.getVirtualFlg(), updateSkuInfoVo.getLogisticsTemplate(),
updateSkuInfoVo.getUpdatedBy(), updateSkuInfoVo.getUpdatedAt(), updateSkuInfoVo.getSpuId()
});
toMqSqls.add(SqlMapping.get("goblin_goods_tag.delete"));
LinkedList<Object[]> deleteGoodsTagObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_tag.insert_byreplace"));
LinkedList<Object[]> initGoodsTagObjs = CollectionUtil.linkedListObjectArr();
if (updateTagFlg) {
if (!befTagIsEmptyFlg) {
deleteGoodsTagObjs.add(new Object[]{spuId, '0'});
}
if (!paramTagIsEmptyFlg) {
updateSpuInfoVo.getTagVoList().forEach(vo -> initGoodsTagObjs.add(new Object[]{spuId, vo.getTagId(), vo.getSort(), "0"}));
}
}
if (updateExtagFlg) {
if (!befExtagIsEmptyFlg) {
deleteGoodsTagObjs.add(new Object[]{spuId, '1'});
// List<GoblinGoodsExtagVo> artagVoList = updateArtagFlg ? updateSpuInfoVo.getArtagVoList() : mgtGoodsInfoVo.getArtagVoList();
// artagVoList.forEach(vo -> initGoodsTagObjs.add(new Object[]{spuId, vo.getTagId(), vo.getSort(), "1"}));
}
if (!paramExtagIsEmptyFlg) {
updateSpuInfoVo.getExtagVoList().forEach(vo -> initGoodsTagObjs.add(new Object[]{spuId, vo.getTagId(), vo.getSort(), "1"}));
}
}
toMqSqls.add(SqlMapping.get("goblin_goods_artag.delete"));
LinkedList<Object[]> deleteGoodsArTagObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_artag.insert_byreplace"));
LinkedList<Object[]> initGoodsArTagObjs = CollectionUtil.linkedListObjectArr();
if (updateArtagFlg) {
if (!befArtagIsEmptyFlg) {
deleteGoodsArTagObjs.add(new Object[]{spuId, '1'});
// List<GoblinGoodsExtagVo> extagVoList = updateExtagFlg ? updateSpuInfoVo.getExtagVoList() : mgtGoodsInfoVo.getExtagVoList();
// extagVoList.forEach(vo -> initGoodsArTagObjs.add(new Object[]{spuId, vo.getTagId(), vo.getSort(), "1"}));
}
if (!paramArtagIsEmptyFlg) {
updateSpuInfoVo.getArtagVoList().forEach(vo -> initGoodsArTagObjs.add(new Object[]{spuId, vo.getTagId(), vo.getSort(), "1"}));
}
}
toMqSqls.add(SqlMapping.get("goblin_goods_service_support.delete"));
LinkedList<Object[]> deleteServiceSupportObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_service_support.insert_byreplace"));
LinkedList<Object[]> initServiceSupportObjs = CollectionUtil.linkedListObjectArr();
if (updateSsidFlg) {
if (!befServiceSupportVoListIsEmptyFlg) {
deleteServiceSupportObjs.add(new Object[]{spuId});
}
if (!paramSsidListIsEmptyFlg) {
updateSpuInfoVo.getServiceSupportVoList().forEach(vo -> initServiceSupportObjs.add(new Object[]{spuId, vo.getSsid()}));
}
}
toMqSqls.add(SqlMapping.get("goblin_goods_image.delete"));
LinkedList<Object[]> deleteGoodsImageObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_image.insert_byreplace"));
LinkedList<Object[]> initGoodsImageObjs = CollectionUtil.linkedListObjectArr();
if (updateImageFlg) {
deleteGoodsImageObjs.add(new Object[]{spuId});
updateSpuInfoVo.getImageList().forEach(imageUrl -> initGoodsImageObjs.add(new Object[]{spuId, imageUrl}));
}
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, updateGoodsInfoObjs, updateGoodsSkuObjs,
deleteGoodsTagObjs, initGoodsTagObjs, deleteGoodsArTagObjs, initGoodsArTagObjs,
deleteServiceSupportObjs, initServiceSupportObjs, deleteGoodsImageObjs, initGoodsImageObjs));
return true;
}
return false;
}
@Override
public boolean goodsEditSku(String uid, GoblinStoreMgtGoodsEditSkuParam mgtGoodsEditSkuParam, GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo,
GoblinGoodsInfoVo goodsInfoVo, Map<String, String> delSpuSpecMap, Map<String, String> addSpuSpecMap) {
LocalDateTime now = LocalDateTime.now();
GoblinGoodsSkuInfoVo updateSkuInfoVo = mgtGoodsEditSkuParam.initEditGoodsSkuInfoVo(mgtGoodsSkuInfoVo);
updateSkuInfoVo.setUpdatedBy(uid);
updateSkuInfoVo.setUpdatedAt(now);
String skuId = updateSkuInfoVo.getSkuId();
if (goblinMongoUtils.updateGoodsSkuInfoVo(updateSkuInfoVo)) {
LinkedList<Object[]> updateGoodsSkuForMarketObjs = CollectionUtil.linkedListObjectArr();
// 参与活动的同一商品更新处理
List<String> marketSkuIdList = goblinRedisUtils.getSkuRe(updateSkuInfoVo.getSkuId());
if (!CollectionUtils.isEmpty(marketSkuIdList)) {
goblinMongoUtils.updateGoodsSkuInfoVoForMarket(marketSkuIdList, updateSkuInfoVo);
marketSkuIdList.forEach(marketSkuId -> {
goblinRedisUtils.delGoodsSkuInfoVo(marketSkuId);
updateGoodsSkuForMarketObjs.add(new Object[]{
updateSkuInfoVo.getName(), updateSkuInfoVo.getSkuPic(), updateSkuInfoVo.getSellPrice(),
updateSkuInfoVo.getWeight(), updateSkuInfoVo.getStock(), updateSkuInfoVo.getWarningStock(),
updateSkuInfoVo.getSkuAppear(), updateSkuInfoVo.getSkuIsbn(), updateSkuInfoVo.getSkuValidity(),
updateSkuInfoVo.getUpdatedBy(), updateSkuInfoVo.getUpdatedAt(), marketSkuId
});
});
}
String spuId = goodsInfoVo.getSpuId();
goblinRedisUtils.delGoodsSkuInfoVo(skuId);
LinkedList<Object[]> updateSkuSpecValueObjs = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> initSpuSpecValueObjs = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> delSpuSpecValueObjs = CollectionUtil.linkedListObjectArr();
boolean updateGoodsInfoVoFlg = false;
List<GoblinGoodsSpecDto> skuSpecList = updateSkuInfoVo.getSkuSpecList();
List<GoblinGoodsSpecVo> specVoList = goodsInfoVo.getSpecVoList();
skuSpecList.forEach(spec -> {
String specName = spec.getSpecName(), specVname = spec.getSpecVname();
GoblinGoodsSpecVo specVo = specVoList.stream().filter(r -> r.getSpecName().equals(specName)).findAny().get();
specVo.getSpecValues().forEach(r -> initSpuSpecValueObjs.add(new Object[]{spuId, specName, r.getSpecVname(), r.getSpecVsort()}));
updateSkuSpecValueObjs.add(new Object[]{specVname, skuId, specName});
if (!CollectionUtils.isEmpty(marketSkuIdList)) {
marketSkuIdList.forEach(marketSkuId -> updateSkuSpecValueObjs.add(new Object[]{specVname, marketSkuId, specName}));
}
});
if (!delSpuSpecMap.isEmpty()) {// 删除了规格值,需要同步SPU里的规格信息
updateGoodsInfoVoFlg = true;
goodsInfoVo.setUpdatedBy(uid);
goodsInfoVo.setUpdatedAt(now);
delSpuSpecMap.forEach((k, v) -> delSpuSpecValueObjs.add(new Object[]{spuId, k, v}));
}
if (!addSpuSpecMap.isEmpty()) {// 新增了规格值,需要同步SPU里的规格信息
updateGoodsInfoVoFlg = true;
goodsInfoVo.setUpdatedBy(uid);
goodsInfoVo.setUpdatedAt(now);
}
BigDecimal priceGe = BigDecimal.ZERO, priceLe = BigDecimal.ZERO;
for (String skuIdStr : goodsInfoVo.getSkuIdList()) {
GoblinGoodsSkuInfoVo skuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuIdStr);
if (null != skuInfoVo && skuInfoVo.getDelFlg().equals("0")) {
priceGe = priceGe.compareTo(BigDecimal.ZERO) == 0 ? skuInfoVo.getPrice() : (priceGe.compareTo(skuInfoVo.getPrice()) > 0 ? skuInfoVo.getPrice() : priceGe);
priceLe = priceLe.compareTo(skuInfoVo.getPrice()) < 0 ? skuInfoVo.getPrice() : priceLe;
}
}
LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
if (priceGe.compareTo(goodsInfoVo.getPriceGe()) != 0 || priceLe.compareTo(goodsInfoVo.getPriceLe()) != 0) {
updateGoodsInfoVoFlg = true;
goodsInfoVo.setPriceGe(priceGe);
goodsInfoVo.setPriceLe(priceLe);
goodsInfoVo.setUpdatedBy(uid);
goodsInfoVo.setUpdatedAt(now);
updateGoodsObjs.add(new Object[]{priceGe, priceLe, uid, now, spuId});
}
if (updateGoodsInfoVoFlg) {
goblinMongoUtils.updateGoodsInfoVo(goodsInfoVo);
goblinRedisUtils.delGoodsInfoVo(spuId);
}
String buyRoster = mgtGoodsEditSkuParam.getBuyRoster();
if (StringUtils.isNotEmpty(buyRoster)) {
queueUtils.sendMsgByRedisXls(buyRoster, mgtGoodsEditSkuParam.getBuyRosterType(), skuId);
}
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_edit_for_market"));
// LinkedList<Object[]> updateGoodsSkuForMarketObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_edit"));
LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
updateGoodsSkuObjs.add(new Object[]{
updateSkuInfoVo.getName(), updateSkuInfoVo.getSkuPic(), updateSkuInfoVo.getSellPrice(), updateSkuInfoVo.getPrice(),
updateSkuInfoVo.getPriceMember(), updateSkuInfoVo.getWeight(), updateSkuInfoVo.getStock(), updateSkuInfoVo.getSkuStock(),
updateSkuInfoVo.getWarningStock(), updateSkuInfoVo.getSkuAppear(), updateSkuInfoVo.getSkuIsbn(), updateSkuInfoVo.getBuyFactor(),
updateSkuInfoVo.getBuyRoster(), updateSkuInfoVo.getBuyLimit(), updateSkuInfoVo.getSkuValidity(), updateSkuInfoVo.getUpdatedBy(),
updateSkuInfoVo.getUpdatedAt(), skuId
});
toMqSqls.add(SqlMapping.get("goblin_goods_sku_spec_value.update_by_edit"));
// LinkedList<Object[]> updateSkuSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_spu_spec_value.insert_byreplace"));
// LinkedList<Object[]> initSpuSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_spu_spec_value.update_by_editdel"));
// LinkedList<Object[]> delSpuSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_edit_sku"));
// LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, updateGoodsSkuForMarketObjs, updateGoodsSkuObjs,
updateSkuSpecValueObjs, initSpuSpecValueObjs, delSpuSpecValueObjs, updateGoodsObjs));
return true;
}
Integer operStock = mgtGoodsEditSkuParam.getOperStock();
if (null != operStock && operStock != 0) {
if (operStock > 0) {
goblinRedisUtils.decrSkuStock(null, skuId, Math.abs(operStock));
} else {
goblinRedisUtils.incrSkuStock(null, skuId, Math.abs(operStock));
}
}
return false;
}
@Override
public void goodsEditSkuAdd(String uid, GoblinStoreMgtGoodsEditSkuParam mgtGoodsEditSkuParam, GoblinGoodsInfoVo goodsInfoVo) {
LocalDateTime now = LocalDateTime.now();
String spuId = mgtGoodsEditSkuParam.getSpuId();
String skuId = spuId.concat(StringUtils.right(String.valueOf(System.nanoTime()), 5));
GoblinGoodsSkuInfoVo addSkuInfoVo = mgtGoodsEditSkuParam.initEditAddGoodsSkuInfoVo();
addSkuInfoVo.setSkuId(skuId);
addSkuInfoVo.setSpuId(spuId);
addSkuInfoVo.setSkuNo(goodsInfoVo.getSpuNo());
// addSkuInfoVo.setName(goodsInfoVo.getName());
addSkuInfoVo.setSubtitle(goodsInfoVo.getSubtitle());
addSkuInfoVo.setVirtualFlg(goodsInfoVo.getVirtualFlg());
addSkuInfoVo.setStatus("3");
addSkuInfoVo.setShelvesStatus(goodsInfoVo.getShelvesStatus());
addSkuInfoVo.setDelFlg("0");
addSkuInfoVo.setCreatedAt(now);
addSkuInfoVo.setCreatedBy(uid);
addSkuInfoVo.setLogisticsTemplate(goodsInfoVo.getLogisticsTemplate());
goblinMongoUtils.setGoodsSkuInfoVo(addSkuInfoVo);
List<String> skuIdList = goodsInfoVo.getSkuIdList();
skuIdList.add(addSkuInfoVo.getSkuId());
goodsInfoVo.setSkuIdList(skuIdList);
BigDecimal priceGe = BigDecimal.ZERO, priceLe = BigDecimal.ZERO;
for (String skuIdStr : goodsInfoVo.getSkuIdList()) {
GoblinGoodsSkuInfoVo skuInfoVo = skuIdStr.equals(skuId) ? addSkuInfoVo : goblinRedisUtils.getGoodsSkuInfoVo(skuIdStr);
if (null != skuInfoVo && skuInfoVo.getDelFlg().equals("0")) {
priceGe = priceGe.compareTo(BigDecimal.ZERO) == 0 ? skuInfoVo.getPrice() : (priceGe.compareTo(skuInfoVo.getPrice()) > 0 ? skuInfoVo.getPrice() : priceGe);
priceLe = priceLe.compareTo(skuInfoVo.getPrice()) < 0 ? skuInfoVo.getPrice() : priceLe;
}
}
LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
if (priceGe.compareTo(goodsInfoVo.getPriceGe()) != 0 || priceLe.compareTo(goodsInfoVo.getPriceLe()) != 0) {
goodsInfoVo.setPriceGe(priceGe);
goodsInfoVo.setPriceLe(priceLe);
goodsInfoVo.setUpdatedBy(uid);
goodsInfoVo.setUpdatedAt(now);
updateGoodsObjs.add(new Object[]{priceGe, priceLe, uid, now, spuId});
}
goblinMongoUtils.updateGoodsInfoVo(goodsInfoVo);
goblinRedisUtils.delGoodsSkuInfoVo(spuId);
goblinRedisUtils.delGoodsInfoVo(spuId);
goblinRedisUtils.setSkuStock(null, addSkuInfoVo.getSkuId(), addSkuInfoVo.getSkuStock());
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods_sku.insert"));
LinkedList<Object[]> initGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
initGoodsSkuObjs.add(new Object[]{
addSkuInfoVo.getSkuId(), addSkuInfoVo.getSpuId(), addSkuInfoVo.getSkuNo(), addSkuInfoVo.getName(), addSkuInfoVo.getSubtitle(),
addSkuInfoVo.getSellPrice(), addSkuInfoVo.getSkuPic(), addSkuInfoVo.getSkuIsbn(), addSkuInfoVo.getStock(), addSkuInfoVo.getSkuStock(),
addSkuInfoVo.getWarningStock(), addSkuInfoVo.getPrice(), addSkuInfoVo.getPriceMember(), addSkuInfoVo.getWeight(), addSkuInfoVo.getBuyFactor(),
addSkuInfoVo.getBuyRoster(), addSkuInfoVo.getBuyLimit(), addSkuInfoVo.getStoreId(), addSkuInfoVo.getSkuValidity(), addSkuInfoVo.getVirtualFlg(),
addSkuInfoVo.getStatus(), addSkuInfoVo.getShelvesStatus(), addSkuInfoVo.getSkuAppear(), addSkuInfoVo.getShelvesAt(), uid,
now, addSkuInfoVo.getLogisticsTemplate()
});
toMqSqls.add(SqlMapping.get("goblin_goods_spec.insert_byreplace"));
LinkedList<Object[]> initGoodsSpecObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_spec_value.insert_byreplace"));
LinkedList<Object[]> initGoodsSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_spu_spec_value.insert_byreplace"));// SPU规格信息
LinkedList<Object[]> initGoodsSpuSpecValueObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_sku_spec_value.insert_byreplace"));// SKU规格信息
LinkedList<Object[]> initGoodsSkuSpecValueObjs = CollectionUtil.linkedListObjectArr();
addSkuInfoVo.getSkuSpecList().forEach(skuSpecDto -> initGoodsSkuSpecValueObjs.add(new Object[]{
spuId, skuId, skuSpecDto.getSpecName(), skuSpecDto.getSpecVname()
}));
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_edit_sku"));// SPU价格区间
// LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
{// 规格记录
List<GoblinGoodsSpecVo> specVoList = goodsInfoVo.getSpecVoList();
specVoList.forEach(s -> {
initGoodsSpecObjs.add(new Object[]{s.getSpecName(), now});
s.getSpecValues().forEach(sv -> {
initGoodsSpecValueObjs.add(new Object[]{s.getSpecName(), sv.getSpecVname(), now});
initGoodsSpuSpecValueObjs.add(new Object[]{spuId, s.getSpecName(), sv.getSpecVname(), sv.getSpecVsort()});
});
});
}
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, initGoodsSkuObjs, initGoodsSpecObjs,
initGoodsSpecValueObjs, initGoodsSpuSpecValueObjs, initGoodsSkuSpecValueObjs, updateGoodsObjs)
);
}
@Override
public boolean goodsEditSkuDel(String uid, GoblinGoodsSkuInfoVo delGoodsSkuInfoVo, GoblinGoodsInfoVo mgtGoodsInfoVo) {
String spuId = delGoodsSkuInfoVo.getSpuId();
String delSkuId = delGoodsSkuInfoVo.getSkuId();
List<String> skuIdList = mgtGoodsInfoVo.getSkuIdList();
skuIdList.removeIf(r -> r.equals(delSkuId));
List<GoblinGoodsSkuInfoVo> remainGoodsSkuInfoVos = goblinMongoUtils.getGoodsSkuInfoVos(skuIdList);
Map<String, Set<String>> remainSkuSpecNameVnameMap = new HashMap<>();
int remainGoodsSkuInfoVoSize = remainGoodsSkuInfoVos.size();
for (int i = 0; i < remainGoodsSkuInfoVoSize; i++) {
GoblinGoodsSkuInfoVo remainGoodsSkuInfoVo = remainGoodsSkuInfoVos.get(i);
if (remainGoodsSkuInfoVo.getDelFlg().equals("0")) {// 有效SKU
List<GoblinGoodsSpecDto> remainGoodsSkuSpecDtoList = remainGoodsSkuInfoVo.getSkuSpecList();
for (GoblinGoodsSpecDto remainGoodsSkuSpecDto : remainGoodsSkuSpecDtoList) {
String remainGoodsSkuSpecDtoSpecName = remainGoodsSkuSpecDto.getSpecName();
String remainGoodsSkuSpecDtoSpecVname = remainGoodsSkuSpecDto.getSpecVname();
Set<String> remainSkuSpecVnameTmpSet = remainSkuSpecNameVnameMap.get(remainGoodsSkuSpecDtoSpecName);
if (CollectionUtils.isEmpty(remainSkuSpecVnameTmpSet)) {
remainSkuSpecVnameTmpSet = CollectionUtil.getStringArraySet();
}
remainSkuSpecVnameTmpSet.add(remainGoodsSkuSpecDtoSpecVname);
remainSkuSpecNameVnameMap.put(remainGoodsSkuSpecDtoSpecName, remainSkuSpecVnameTmpSet);
}
}
}
List<GoblinGoodsSpecVo> goodsInfoVoSpecVoList = mgtGoodsInfoVo.getSpecVoList();
List<GoblinGoodsSpecDto> delGoodsSkuInfoVoSkuSpecList = delGoodsSkuInfoVo.getSkuSpecList();
LinkedList<Object[]> updateGoodsSpuSpecObjs = CollectionUtil.linkedListObjectArr();
for (int i = 0; i < delGoodsSkuInfoVoSkuSpecList.size(); i++) {
GoblinGoodsSpecDto delGoodsSpecDto = delGoodsSkuInfoVoSkuSpecList.get(i);
String delGoodsSpecDtoSpecName = delGoodsSpecDto.getSpecName();
String delGoodsSpecDtoSpecVname = delGoodsSpecDto.getSpecVname();
Set<String> remainSkuSpecVnameSet = remainSkuSpecNameVnameMap.get(delGoodsSpecDtoSpecName);
if (CollectionUtils.isEmpty(remainSkuSpecVnameSet) || !remainSkuSpecVnameSet.contains(delGoodsSpecDtoSpecVname)) {// 其他SKU规格值中不存在当前删除SKU规格值,则删除该规格值
for (GoblinGoodsSpecVo goodsSpecVo : goodsInfoVoSpecVoList) {
if (goodsSpecVo.getSpecName().equals(delGoodsSpecDtoSpecName)) {
List<GoblinGoodsSpecValueVo> goodsSpecVoSpecValues = goodsSpecVo.getSpecValues();
goodsSpecVoSpecValues.removeIf(r -> r.getSpecVname().equals(delGoodsSpecDtoSpecVname));
goodsSpecVoSpecValues.sort(Comparator.comparing(GoblinGoodsSpecValueVo::getSpecVsort));
updateGoodsSpuSpecObjs.add(new Object[]{0, "1", spuId, delGoodsSpecDtoSpecName, delGoodsSpecDtoSpecVname});
for (int j = 0; j < goodsSpecVoSpecValues.size(); j++) {
GoblinGoodsSpecValueVo goodsSpecVoSpecValue = goodsSpecVoSpecValues.get(j);
goodsSpecVoSpecValue.setSpecVsort(j);
updateGoodsSpuSpecObjs.add(new Object[]{j, "0", spuId, delGoodsSpecDtoSpecName, goodsSpecVoSpecValue.getSpecVname()});
}
break;
}
}
}
}
LocalDateTime now = LocalDateTime.now();
delGoodsSkuInfoVo.setUpdatedBy(uid);
delGoodsSkuInfoVo.setUpdatedAt(now);
delGoodsSkuInfoVo.setDeletedBy(uid);
delGoodsSkuInfoVo.setDeletedAt(now);
List<String> delSkuIdList = goblinRedisUtils.getSkuRe(delSkuId);
delSkuIdList = null == delSkuIdList ? CollectionUtil.arrayListString() : delSkuIdList;
delSkuIdList.add(delSkuId);
if (log.isDebugEnabled()) {
log.debug("商品管理:商品编辑:SKU删除[delSkuId={},skuReId={}]", delSkuId, JsonUtils.toJson(delSkuIdList));
}
if (goblinMongoUtils.delGoodsSkuInfoVo(delGoodsSkuInfoVo, delSkuIdList)) {
delSkuIdList.forEach(skuId -> {
goblinRedisUtils.delGoodsSkuInfoVo(skuId);
goblinRedisUtils.delGoodsSkuInfoVoByUnShelves(skuId);
});
BigDecimal priceGe = BigDecimal.ZERO, priceLe = BigDecimal.ZERO;
for (String skuId : skuIdList) {
GoblinGoodsSkuInfoVo skuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null != skuInfoVo && skuInfoVo.getDelFlg().equals("0")) {
priceGe = priceGe.compareTo(BigDecimal.ZERO) == 0 ? skuInfoVo.getPrice() : (priceGe.compareTo(skuInfoVo.getPrice()) > 0 ? skuInfoVo.getPrice() : priceGe);
priceLe = priceLe.compareTo(skuInfoVo.getPrice()) < 0 ? skuInfoVo.getPrice() : priceLe;
}
}
mgtGoodsInfoVo.setUpdatedBy(uid);
mgtGoodsInfoVo.setUpdatedAt(now);
LinkedList<Object[]> updateGoodsInfoObjs = CollectionUtil.linkedListObjectArr();
if (priceGe.compareTo(mgtGoodsInfoVo.getPriceGe()) != 0 || priceLe.compareTo(mgtGoodsInfoVo.getPriceLe()) != 0) {
mgtGoodsInfoVo.setPriceGe(priceGe);
mgtGoodsInfoVo.setPriceLe(priceLe);
updateGoodsInfoObjs.add(new Object[]{priceGe, priceLe, uid, now, spuId});
}
goblinMongoUtils.updateGoodsInfoVo(mgtGoodsInfoVo);
goblinRedisUtils.delGoodsInfoVo(spuId);
goblinRedisUtils.delGoodsInfoVoByUnShelves(spuId);
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_del"));
LinkedList<Object[]> delGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
delSkuIdList.forEach(skuId -> delGoodsSkuObjs.add(new Object[]{uid, now, uid, now, skuId}));
toMqSqls.add(SqlMapping.get("goblin_goods_spu_spec_value.update_by_del_sku"));
// LinkedList<Object[]> updateGoodsSpuSpecObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods_sku_spec_value.update_by_del_sku"));
LinkedList<Object[]> deleteGoodsSkuSpecObjs = CollectionUtil.linkedListObjectArr();
deleteGoodsSkuSpecObjs.add(new Object[]{delSkuId});
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_del_sku"));
// LinkedList<Object[]> updateGoodsInfoObjs = CollectionUtil.linkedListObjectArr();
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, delGoodsSkuObjs, updateGoodsSpuSpecObjs, deleteGoodsSkuSpecObjs, updateGoodsInfoObjs));
return true;
}
return false;
}
// @Override
// public boolean goodsEditSkuBat(String spuId, String batField, String batFieldVal) {
// return false;
// }
@Override
public boolean goodsShelvesProcessing(GoblinStoreMgtGoodsActionParam mgtGoodsActionParam, String uid, boolean shelvesFlg, List<String> spuNoList) {
LocalDateTime now = LocalDateTime.now();
String storeId = mgtGoodsActionParam.getStoreId();
List<String> spuIdList = mgtGoodsActionParam.getSpuIdList();
// if (!shelvesFlg) {// 下架操作,需处理关联活动的商品数据
// spuIdList.addAll(goblinMongoUtils.getMgtSpuIdsForMarketBySpuNos(spuNoList, "3"));
// }
if (shelvesFlg) {
spuIdList.addAll(goblinMongoUtils.getMgtSpuIdsForMarketBySpuNos(spuNoList, "0", "1"));
} else {
spuIdList.addAll(goblinMongoUtils.getMgtSpuIdsForMarketBySpuNos(spuNoList, "3"));
}
if (goblinMongoUtils.updateGoodsInfoVoByShelves(storeId, spuIdList, shelvesFlg, uid, now)) {
if (goblinMongoUtils.updateGoodsSkuInfoVoByShelves(storeId, spuIdList, shelvesFlg, uid, now)) {
goblinRedisUtils.deleteKeyForSelectGoods();// 精选商品:商品上架、下架、删除 调用的方法
spuIdList.forEach(spuId -> {
goblinRedisUtils.delGoodsInfoVo(spuId);
goblinRedisUtils.delGoodsInfoVoByUnShelves(spuId);
});
List<String> skuIds = goblinMongoUtils.getMgtGoodsSkuIds(storeId, spuIdList);
skuIds.forEach(skuId -> {
goblinRedisUtils.delGoodsSkuInfoVo(skuId);
goblinRedisUtils.delGoodsSkuInfoVoByUnShelves(skuId);
});
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_shelves"));
LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
String shelvesStatus = shelvesFlg ? "3" : "1";
spuIdList.forEach(spuId -> updateGoodsObjs.add(new Object[]{shelvesStatus, now, uid, now, spuId, storeId}));
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_shelves"));
LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
spuIdList.forEach(spuId -> updateGoodsSkuObjs.add(new Object[]{shelvesStatus, now, uid, now, spuId, storeId}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, updateGoodsObjs, updateGoodsSkuObjs));
return true;
} else {
goblinMongoUtils.updateGoodsInfoVoByShelves(storeId, spuIdList, !shelvesFlg, uid, now);
}
}
return false;
}
@Override
public boolean goodsRemove(GoblinStoreMgtGoodsActionParam mgtGoodsActionParam, String uid, List<String> spuNoList) {
LocalDateTime now = LocalDateTime.now();
String storeId = mgtGoodsActionParam.getStoreId();
List<String> spuIdList = mgtGoodsActionParam.getSpuIdList();
// 删除操作,需处理关联活动的商品数据
spuIdList.addAll(goblinMongoUtils.getMgtSpuIdsForMarketBySpuNos(spuNoList, "0", "1", "2"));
if (goblinMongoUtils.delGoodsInfoVoBySpuIds(storeId, spuIdList, uid, now)) {
goblinRedisUtils.deleteKeyForSelectGoods();// 精选商品:商品上架、下架、删除 调用的方法
spuIdList.forEach(spuId -> {
goblinRedisUtils.delGoodsInfoVo(spuId);
goblinRedisUtils.delGoodsInfoVoByUnShelves(spuId);
});
List<String> skuIdList = goblinMongoUtils.getMgtGoodsSkuIds(storeId, spuIdList);
skuIdList.forEach(skuId -> {
goblinRedisUtils.delGoodsSkuInfoVo(skuId);
goblinRedisUtils.delGoodsSkuInfoVoByUnShelves(skuId);
});
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_del"));
LinkedList<Object[]> updateGoodsObjs = CollectionUtil.linkedListObjectArr();
spuIdList.forEach(spuId -> updateGoodsObjs.add(new Object[]{uid, now, uid, now, spuId}));
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_del_spu"));
LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
spuIdList.forEach(spuId -> updateGoodsSkuObjs.add(new Object[]{uid, now, uid, now, spuId}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, updateGoodsObjs, updateGoodsSkuObjs));
return true;
}
return false;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtNoticeFilterParam;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreNoticeVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtNoticeService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* <p>
* 店铺公告 服务实现类
* </p>
*
* @author zhanggb
* Created by IntelliJ IDEA at 2022/1/17
*/
@Slf4j
@Service
public class GoblinStoreMgtNoticeServiceImpl implements IGoblinStoreMgtNoticeService {
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Override
public PagedResult<GoblinStoreNoticeVo> pageList(GoblinStoreMgtNoticeFilterParam filterParam) {
log.info("====={}", JsonUtils.toJson(goblinRedisUtils.getStoreNoticeVo(filterParam.getStoreId(), LocalDateTime.now())));
PagedResult<GoblinStoreNoticeVo> storeNoticeVoPagedResult = goblinMongoUtils.getStoreNoticeVos(filterParam);
if (!CollectionUtils.isEmpty(storeNoticeVoPagedResult.getList())) {
List<GoblinStoreNoticeVo> storeNoticeVoList = ObjectUtil.getGoblinStoreNoticeVoArrayList();
LocalDateTime now = LocalDateTime.now();
storeNoticeVoPagedResult.getList().forEach(r -> {
if (r.getStatus().equals("0") && r.getReleaseTime().isBefore(now)) {
r.setStatus("1");
r.setUpdatedAt(r.getReleaseTime());
storeNoticeVoList.add(r);
}
});
if (!CollectionUtils.isEmpty(storeNoticeVoList) && goblinMongoUtils.updateStoreNoticeVoByBulk(storeNoticeVoList)) {
List<String> noticeIdList = storeNoticeVoList.stream().map(GoblinStoreNoticeVo::getNoticeId).collect(Collectors.toList());
List<GoblinStoreNoticeVo> storeNoticeVos = goblinRedisUtils.getStoreNoticeVos(filterParam.getStoreId(), now);
boolean toUpdateFlg = false;
for (GoblinStoreNoticeVo r : storeNoticeVos) {
if (noticeIdList.contains(r.getNoticeId())) {
r.setStatus("1");
r.setUpdatedAt(r.getReleaseTime());
toUpdateFlg = true;
}
}
if (toUpdateFlg) {
goblinRedisUtils.setStoreNoticeVos(filterParam.getStoreId(), storeNoticeVos);
}
}
}
return storeNoticeVoPagedResult;
}
@Override
public void addSave(GoblinStoreNoticeVo storeNoticeVo) {
goblinMongoUtils.setStoreNoticeVo(storeNoticeVo);
List<GoblinStoreNoticeVo> storeNoticeVos = goblinRedisUtils.getStoreNoticeVos(storeNoticeVo.getStoreId(), storeNoticeVo.getCreatedAt());
storeNoticeVos.add(storeNoticeVo);
goblinRedisUtils.setStoreNoticeVos(storeNoticeVo.getStoreId(),
storeNoticeVos.stream().sorted(Comparator.comparing(GoblinStoreNoticeVo::getReleaseTime).thenComparing(GoblinStoreNoticeVo::getCreatedAt)).collect(Collectors.toList()));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_notice.insert",
storeNoticeVo.getNoticeId(), storeNoticeVo.getStoreId(), storeNoticeVo.getContent(),
storeNoticeVo.getReleaseTime(), storeNoticeVo.getLongLasting(), storeNoticeVo.getCancellTime(),
storeNoticeVo.getStatus(), storeNoticeVo.getCreatedBy(), storeNoticeVo.getCreatedAt())
);
}
@Override
public boolean editSave(GoblinStoreNoticeVo updateStoreNoticeVo) {
if (goblinMongoUtils.updateStoreNoticeVo(updateStoreNoticeVo)) {
String storeId = updateStoreNoticeVo.getStoreId();
List<GoblinStoreNoticeVo> storeNoticeVos = goblinRedisUtils.getStoreNoticeVos(storeId, updateStoreNoticeVo.getUpdatedAt());
storeNoticeVos.forEach(r -> {
if (r.getNoticeId().equals(updateStoreNoticeVo.getNoticeId())) {
r.setContent(updateStoreNoticeVo.getContent());
r.setReleaseTime(updateStoreNoticeVo.getReleaseTime());
r.setLongLasting(updateStoreNoticeVo.getLongLasting());
r.setCancellTime(updateStoreNoticeVo.getCancellTime());
r.setStatus(updateStoreNoticeVo.getStatus());
r.setUpdatedBy(updateStoreNoticeVo.getUpdatedBy());
r.setUpdatedAt(updateStoreNoticeVo.getUpdatedAt());
}
});
goblinRedisUtils.setStoreNoticeVos(storeId,
storeNoticeVos.stream().sorted(Comparator.comparing(GoblinStoreNoticeVo::getReleaseTime).thenComparing(GoblinStoreNoticeVo::getCreatedAt)).collect(Collectors.toList()));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_notice.update",
updateStoreNoticeVo.getContent(), updateStoreNoticeVo.getReleaseTime(), updateStoreNoticeVo.getLongLasting(),
updateStoreNoticeVo.getCancellTime(), updateStoreNoticeVo.getStatus(), updateStoreNoticeVo.getUpdatedBy(),
updateStoreNoticeVo.getUpdatedAt(), updateStoreNoticeVo.getNoticeId())
);
}
return false;
}
@Override
public boolean releaseProcessing(String uid, String storeId, List<String> noticeIdList) {
LocalDateTime now = LocalDateTime.now();
if (goblinMongoUtils.updateStoreNoticeVoByRelease(uid, now, storeId, noticeIdList)) {
List<GoblinStoreNoticeVo> storeNoticeVos = goblinRedisUtils.getStoreNoticeVos(storeId, now);
storeNoticeVos.forEach(r -> {
if (noticeIdList.contains(r.getNoticeId())) {
r.setReleaseTime(now);
r.setStatus("1");
r.setUpdatedBy(uid);
r.setUpdatedAt(now);
}
});
goblinRedisUtils.setStoreNoticeVos(storeId, storeNoticeVos);
LinkedList<Object[]> updateStoreNoticeObjs = CollectionUtil.linkedListObjectArr();
noticeIdList.forEach(noticeId -> updateStoreNoticeObjs.add(new Object[]{now, uid, now, storeId, noticeId}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_notice.release", updateStoreNoticeObjs));
return true;
}
return false;
}
@Override
public boolean removeProcessing(String uid, String storeId, List<String> noticeIdList) {
LocalDateTime now = LocalDateTime.now();
if (goblinMongoUtils.updateStoreNoticeVoByRemove(uid, now, storeId, noticeIdList)) {
List<GoblinStoreNoticeVo> storeNoticeVos = goblinRedisUtils.getStoreNoticeVos(storeId, now);
storeNoticeVos.removeIf(r -> noticeIdList.contains(r.getNoticeId()));
goblinRedisUtils.setStoreNoticeVos(storeId, storeNoticeVos);
LinkedList<Object[]> revStoreNoticeObjs = CollectionUtil.linkedListObjectArr();
noticeIdList.forEach(noticeId -> revStoreNoticeObjs.add(new Object[]{uid, now, storeId, noticeId}));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_notice.remove", revStoreNoticeObjs));
return true;
}
return false;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreConfigVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo;
import com.liquidnet.service.goblin.enums.GoblinStoreConf;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class GoblinStoreMgtServiceImpl implements IGoblinStoreMgtService {
@Autowired
private QueueUtils queueUtils;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinMongoUtils goblinMongoUtils;
@Override
public boolean updateStoreMgtInfo(GoblinStoreInfoVo storeInfoVo) {
if (goblinMongoUtils.updateStoreInfoVo(storeInfoVo)) {
goblinRedisUtils.delStoreInfoVo(storeInfoVo.getStoreId());
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_store_info.update_by_edit",
storeInfoVo.getStoreName(), storeInfoVo.getLogoPic(), storeInfoVo.getBackgroundPic(), storeInfoVo.getIntroduce(),
storeInfoVo.getUpdatedBy(), storeInfoVo.getUpdatedAt(), storeInfoVo.getStoreId()
));
return true;
}
return false;
}
@Override
public boolean updateStoreMgtConfig(String uid, String storeId, Map<String, String> confMap) {
LocalDateTime now = LocalDateTime.now();
List<GoblinStoreConfigVo> storeConfigVos = goblinRedisUtils.getStoreConfigVos(storeId);
List<GoblinStoreConfigVo> updateStoreConfigVoList = ObjectUtil.getGoblinStoreConfigVoArrayList();
boolean toUpdateStoreStatusFlg = false;
for (GoblinStoreConfigVo configVo : storeConfigVos) {
String updateConfVal = confMap.get(configVo.getConfigKey());
if (configVo.getConfigKey().equals(GoblinStoreConf.BUSINESS_STATUS.name())) {
toUpdateStoreStatusFlg = !configVo.getConfigVal().equals(updateConfVal);
}
if (StringUtils.isNotEmpty(updateConfVal)) {
configVo.setConfigVal(updateConfVal);
configVo.setUpdatedBy(uid);
configVo.setUpdatedAt(now);
updateStoreConfigVoList.add(configVo);
}
}
if (!CollectionUtils.isEmpty(updateStoreConfigVoList) && goblinMongoUtils.updateStoreConfigVos(updateStoreConfigVoList)) {
goblinRedisUtils.delStoreConfigVos(storeId);
LinkedList<Object[]> updateStoreInfoObjs = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> updateGoodsInfoObjs = CollectionUtil.linkedListObjectArr();
if (toUpdateStoreStatusFlg) {
String status = confMap.get(GoblinStoreConf.BUSINESS_STATUS.name());
GoblinStoreInfoVo updateStoreInfoVo = goblinRedisUtils.getStoreInfoVo(storeId);
updateStoreInfoVo.setStatus(status);
updateStoreInfoVo.setUpdatedBy(uid);
updateStoreInfoVo.setUpdatedAt(now);
goblinMongoUtils.updateStoreInfoVo(updateStoreInfoVo);
goblinRedisUtils.delStoreInfoVo(storeId);
goblinMongoUtils.updateGoodsInfoVoAppear(storeId, status.equals("4") ? "1" : "0", now, uid);
goblinRedisUtils.deleteKeyForSelectGoods();// 精选商品:商品上架、下架、删除 调用的方法
List<String> spuIdList = goblinMongoUtils.getMgtGoodsSpuIds(storeId);
spuIdList.forEach(spuId -> goblinRedisUtils.delGoodsInfoVo(spuId));
updateStoreInfoObjs.add(new Object[]{updateStoreInfoVo.getStatus(), uid, now, storeId});
updateGoodsInfoObjs.add(new Object[]{status.equals("4") ? "1" : "0", uid, now, storeId});
}
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_store_config.update"));
LinkedList<Object[]> updateStoreConfigVoObjs = CollectionUtil.linkedListObjectArr();
updateStoreConfigVoList.forEach(uc -> updateStoreConfigVoObjs.add(new Object[]{
uc.getConfigVal(), uc.getUpdatedBy(), uc.getUpdatedAt(), uc.getStoreId(), uc.getConfigKey()}));
toMqSqls.add(SqlMapping.get("goblin_store_info.update_by_setting"));
// LinkedList<Object[]> updateStoreInfoObjs = CollectionUtil.linkedListObjectArr();
toMqSqls.add(SqlMapping.get("goblin_goods.update_by_status"));
// LinkedList<Object[]> updateGoodsInfoObjs = CollectionUtil.linkedListObjectArr();
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.gets(toMqSqls, updateStoreConfigVoObjs, updateStoreInfoObjs, updateGoodsInfoObjs));
return true;
}
return false;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinOrderLogVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMoneyService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
@Service
public class GoblinStoreMoneyServiceImpl implements IGoblinStoreMoneyService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Override
public ResponseDto<HashMap<String,String>> money(String spuId) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo vo = redisUtils.getStoreInfoVoByUid(uid);
if (vo == null) {
return ResponseDto.failure("店铺不存在");
}
String data = mongoUtils.storeMoney(vo.getStoreId(), spuId);
String[] array = data.split(",");
HashMap<String,String> map = CollectionUtil.mapStringString();
map.put("name",array[0]);
map.put("price",array[1]);
return ResponseDto.success(map);
}
@Override
public ResponseDto<PageInfo<GoblinOrderLogVo>> getSpuList(String spuName, String st, String et, int page) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo vo = redisUtils.getStoreInfoVoByUid(uid);
if (vo == null) {
return ResponseDto.failure("店铺不存在");
}
HashMap<String, Object> map = mongoUtils.moneyGetSpuList(spuName, st, et, vo.getStoreId(), page);
PageInfo<GoblinOrderLogVo> info = new PageInfo((List<GoblinOrderLogVo>) map.get("data"));
info.setTotal((Long) map.get("total"));
return ResponseDto.success(info);
}
@Override
public ResponseDto<PageInfo<GoblinOrderLogVo>> getOrderOperaList(String spuId, String orderCode, Integer type, String st, String et, int page) {
HashMap<String, Object> map = mongoUtils.moneyGetSpuDetails(spuId, orderCode, type, st, et, page);
PageInfo<GoblinOrderLogVo> info = new PageInfo((List<GoblinOrderLogVo>) map.get("data"));
info.setTotal((Long) map.get("total"));
return ResponseDto.success(info);
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.candy.vo.CandyCouponVo;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinBackOrder;
import com.liquidnet.service.goblin.entity.GoblinBackOrderLog;
import com.liquidnet.service.goblin.entity.GoblinOrderOperationLog;
import com.liquidnet.service.goblin.param.BackCouponParam;
import com.liquidnet.service.goblin.param.RefundCallbackParam;
import com.liquidnet.service.goblin.service.GoblinCouponService;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMoneyService;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreOrderService;
import com.liquidnet.service.goblin.util.*;
import com.mongodb.BasicDBObject;
import com.mongodb.client.result.UpdateResult;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Service
@Slf4j
public class GoblinStoreOrderServiceImpl implements IGoblinStoreOrderService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
GoblinOrderUtils orderUtils;
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinCouponService goblinCouponService;
@Value("${liquidnet.service.order.url-pay.goblinRefundUrl}")
private String synUrl;
@Value("${liquidnet.service.dragon.urls.refundApply}")
private String refundApply;
@Override
public ResponseDto<PageInfo<GoblinStoreOrderListVo>> orderList(Integer page, String orderCode, Integer type, String cst, String cet, String expressContacts, String phone, Integer status) {
List<GoblinStoreOrderListVo> listVos = ObjectUtil.getGoblinStoreOrderListVoArrayList();
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
HashMap<String, Object> map = mongoUtils.storeOrderList(storeInfoVo.getStoreId(), page, orderCode, cst, cet, expressContacts, phone, status);
long total = (long) map.get("total");
List<GoblinStoreOrderVo> voList = (List<GoblinStoreOrderVo>) map.get("data");
for (GoblinStoreOrderVo item : voList) {
GoblinStoreOrderListVo vo = GoblinStoreOrderListVo.getNew();
vo.setCreatedAt(item.getCreatedAt());
vo.setExpressAddressDetail(item.getOrderAttrVo().getExpressAddressDetail());
vo.setExpressContacts(item.getOrderAttrVo().getExpressContacts());
vo.setExpressPhone(item.getOrderAttrVo().getExpressPhone());
vo.setOrderCode(item.getOrderCode());
vo.setExpressAddress(item.getOrderAttrVo().getExpressAddress());
vo.setOrderId(item.getOrderId());
vo.setPayType(item.getPayType());
vo.setPriceActual(item.getPriceActual());
vo.setStatus(item.getStatus());
vo.setMarketType(item.getMarketType());
vo.setPriceExpress(item.getPriceExpress());
List<GoblinStoreOrderListSkuVo> orderListSkuVos = ObjectUtil.getGoblinStoreOrderListSkuVoArrayList();
for (String skuId : item.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(skuId);
GoblinStoreOrderListSkuVo itemSkuVo = GoblinStoreOrderListSkuVo.getNew();
itemSkuVo.setNum(orderSkuVo.getNum());
itemSkuVo.setOrderSkuId(orderSkuVo.getOrderSkuId());
itemSkuVo.setSkuId(orderSkuVo.getSkuId());
itemSkuVo.setSkuName(orderSkuVo.getSkuName());
itemSkuVo.setSpuName(orderSkuVo.getSpuName());
itemSkuVo.setSkuPriceActual(orderSkuVo.getSkuPriceActual());
itemSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
itemSkuVo.setSkuImage(orderSkuVo.getSkuImage());
itemSkuVo.setStatus(orderSkuVo.getStatus());
orderListSkuVos.add(itemSkuVo);
}
vo.setStoreOrderListSkuVoList(orderListSkuVos);
listVos.add(vo);
}
PageInfo<GoblinStoreOrderListVo> pageInfo = new PageInfo(listVos);
pageInfo.setTotal(total);
return ResponseDto.success(pageInfo);
}
@Override
public ResponseDto<GoblinStoreOrderListVo> orderDetails(String orderId) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderListVo vo = GoblinStoreOrderListVo.getNew();
vo.setCreatedAt(orderVo.getCreatedAt());
vo.setExpressAddressDetail(orderVo.getOrderAttrVo().getExpressAddressDetail());
vo.setExpressContacts(orderVo.getOrderAttrVo().getExpressContacts());
vo.setExpressPhone(orderVo.getOrderAttrVo().getExpressPhone());
vo.setOrderCode(orderVo.getOrderCode());
vo.setExpressAddress(orderVo.getOrderAttrVo().getExpressAddress());
vo.setOrderId(orderVo.getOrderId());
vo.setPayType(orderVo.getPayType());
vo.setPriceActual(orderVo.getPriceActual());
vo.setStatus(orderVo.getStatus());
vo.setPayTime(orderVo.getPayTime());
vo.setPriceExpress(orderVo.getPriceExpress());
if (!(orderVo.getUcouponId() == null || orderVo.getUcouponId().equals(""))) {
CandyCouponVo candyCouponVo = orderUtils.getCouponDetails(orderVo.getUcouponId());
vo.setPlatformUcouponId(candyCouponVo.getUcouponId());
vo.setPlatformUcouponName(candyCouponVo.getTitle());
vo.setPlatformUcouponPrice(orderVo.getPriceCoupon());
} else {
vo.setPlatformUcouponId("");
vo.setPlatformUcouponName("");
vo.setPlatformUcouponPrice(BigDecimal.ZERO);
}
if (!(orderVo.getStoreCouponId() == null || orderVo.getStoreCouponId().equals(""))) {
List<GoblinUserCouponVo> voList = redisUtils.getUserCouponVos(orderVo.getUserId());
for (GoblinUserCouponVo goblinUserCouponVo : voList) {
if (goblinUserCouponVo.getUcouponId().equals(orderVo.getStoreCouponId())) {
vo.setStoreUcouponId(goblinUserCouponVo.getStoreCouponId());
vo.setStoreUcouponName(goblinUserCouponVo.getTitle());
vo.setStoreUcouponPrice(orderVo.getStorePriceCoupon());
break;
}
}
} else {
vo.setStoreUcouponId("");
vo.setStoreUcouponName("");
vo.setStoreUcouponPrice(BigDecimal.ZERO);
}
if (orderVo.getMarketId() == null || orderVo.getMarketId().equals("")) {
vo.setMarketName("");
} else {
GoblinSelfMarketingVo marketingVo = redisUtils.getSelfMarket(orderVo.getMarketId().split("ZZ")[1]);
vo.setMarketName(marketingVo.getName());
}
vo.setGoblinMailVoList(redisUtils.getGoblinMail(orderId));
List<GoblinStoreOrderListSkuVo> orderListSkuVos = ObjectUtil.getGoblinStoreOrderListSkuVoArrayList();
for (String skuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(skuId);
GoblinStoreOrderListSkuVo itemSkuVo = GoblinStoreOrderListSkuVo.getNew();
itemSkuVo.setNum(orderSkuVo.getNum());
itemSkuVo.setOrderSkuId(orderSkuVo.getOrderSkuId());
itemSkuVo.setSkuId(orderSkuVo.getSkuId());
itemSkuVo.setSkuName(orderSkuVo.getSkuName());
itemSkuVo.setSpuName(orderSkuVo.getSpuName());
itemSkuVo.setSkuPriceActual(orderSkuVo.getSkuPriceActual());
itemSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
itemSkuVo.setSkuImage(orderSkuVo.getSkuImage());
itemSkuVo.setStatus(orderSkuVo.getStatus());
orderListSkuVos.add(itemSkuVo);
}
vo.setStoreOrderListSkuVoList(orderListSkuVos);
return ResponseDto.success(vo);
}
@Override
public ResponseDto<Boolean> orderCancel(String orderId) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlsOrder = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> sqlsOrderSku = CollectionUtil.linkedListObjectArr();
sqls.add(SqlMapping.get("goblin_order.store.cancel"));
sqls.add(SqlMapping.get("goblin_order.store.orderSkuStatus"));
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
if (!orderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_STATUS_0.getValue())) {
return ResponseDto.failure("无法取消");
}
orderVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_5.getValue());
orderVo.setCancelReason("商铺取消");
orderVo.setCancelTime(nowStr);
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_5.getValue());
//redis
String pre = GoblinStatusConst.MarketPreStatus.getPre(orderSkuVo.getSkuId());
redisUtils.setGoblinOrderSku(orderSkuId, orderSkuVo);
redisUtils.incrSkuStock(pre,orderSkuVo.getSkuId(),orderSkuVo.getNum());
redisUtils.decrSkuCountByUid(orderVo.getUserId(), orderSkuVo.getSkuId(), orderSkuVo.getNum());
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuId, orderSkuVo);
//mysql
sqlsOrderSku.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
}
GoblinOrderOperationLog log = initLog(orderId, uid, now);
log.setType(GoblinStatusConst.Status.ORDER_LOG_STATUS_14.getValue());
log.setRemark("商铺取消订单");
//回退平台券
if (!(orderVo.getUcouponId() == null || orderVo.getUcouponId().equals(""))) {
orderUtils.backCoupon(orderVo.getUcouponId(), orderVo.getUserId());
}
//回退店铺券
if (!(orderVo.getStoreCouponId() == null || orderVo.getStoreCouponId().equals(""))) {
List<BackCouponParam> params = ObjectUtil.getBackCouponParam();
BackCouponParam backCouponParam = BackCouponParam.getNew();
backCouponParam.setuCouponIds(orderVo.getStoreCouponId());
backCouponParam.setUid(orderVo.getUserId());
params.add(backCouponParam);
goblinCouponService.backCoupon(params);
}
//redis
redisUtils.setGoblinOrder(orderId, orderVo);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
//mysql
sqlsOrder.add(new Object[]{
orderVo.getStatus(), now, orderVo.getCancelReason(), now,
orderId, now, now
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.gets(sqls, sqlsOrder, sqlsOrderSku));
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> changeExpressPrice(String orderId, BigDecimal price) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_3.getValue()) {
return ResponseDto.failure("已发货");
}
BigDecimal voucherExpress = orderVo.getPriceExpress().subtract(price);
orderVo.setPriceTotal(orderVo.getPriceTotal().subtract(voucherExpress));
orderVo.setPriceModify(orderVo.getPriceModify().add(voucherExpress));
// orderVo.setPriceVoucher(orderVo.getPriceVoucher().add(voucherExpress));
orderVo.setPriceActual(orderVo.getPriceActual().subtract(voucherExpress));
orderVo.setPriceExpress(price);
GoblinOrderOperationLog log = initLog(orderId, uid, now);
log.setType(GoblinStatusConst.Status.ORDER_LOG_STATUS_17.getValue());
log.setRemark("修改快递价格,expressPress=[" + price + "]");
//redis
redisUtils.setGoblinOrder(orderId, orderVo);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
//mysql
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.orderExpressPrice",
orderVo.getPriceTotal(), orderVo.getPriceModify(), orderVo.getPriceVoucher(), orderVo.getPriceActual(), orderVo.getPriceExpress(), now,
orderId, now, now
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.log",
log.getOrderLogId(), log.getOrderId(), log.getType(), log.getRemark(), log.getOperationName(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> changeAddress(String orderId, String expressContacts, String expressPhone, String expressAddressDetail) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_3.getValue()) {
return ResponseDto.failure("已发货");
}
orderVo.getOrderAttrVo().setExpressAddressDetail(expressAddressDetail);
orderVo.getOrderAttrVo().setExpressContacts(expressContacts);
orderVo.getOrderAttrVo().setExpressPhone(expressPhone);
GoblinOrderOperationLog log = initLog(orderId, uid, now);
log.setType(GoblinStatusConst.Status.ORDER_LOG_STATUS_17.getValue());
log.setRemark("修改收货地址,expressContacts=[" + expressContacts + "],expressPhone=[" + expressPhone + "],expressAddressDetail=[" + expressAddressDetail + "]");
//redis
redisUtils.setGoblinOrder(orderId, orderVo);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
//mysql
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.address",
expressContacts, expressPhone, expressAddressDetail, now, orderId, now, now
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.log",
log.getOrderLogId(), log.getOrderId(), log.getType(), log.getRemark(), log.getOperationName(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> changeSkuPrice(String orderId, String orderSkuId, BigDecimal price) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_3.getValue()) {
return ResponseDto.failure("已发货");
}
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
if (orderSkuVo == null) {
return ResponseDto.failure("不存在");
}
BigDecimal voucherPrice = orderSkuVo.getSkuPriceActual().subtract(price);
orderSkuVo.setPriceModify(orderSkuVo.getPriceModify() == null ? price : orderSkuVo.getPriceModify().add(price));
// orderSkuVo.setPriceVoucher(orderSkuVo.getPriceVoucher().add(voucherPrice));
orderSkuVo.setSkuPriceActual(orderSkuVo.getSkuPriceActual().subtract(voucherPrice));
orderVo.setPriceTotal(orderVo.getPriceTotal().subtract(voucherPrice));
orderVo.setPriceModify(orderVo.getPriceModify().add(voucherPrice));
// orderVo.setPriceVoucher(orderVo.getPriceVoucher().add(voucherPrice));
orderVo.setPriceActual(orderVo.getPriceActual().subtract(voucherPrice));
GoblinOrderOperationLog log = initLog(orderId, uid, now);
log.setType(GoblinStatusConst.Status.ORDER_LOG_STATUS_12.getValue());
log.setRemark("修改金额,orderSkuId=[" + orderSkuId + "],price=[" + price + "]");
//redis
redisUtils.setGoblinOrder(orderId, orderVo);
redisUtils.setGoblinOrderSku(orderSkuId, orderSkuVo);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
mongoUtils.updateGoblinOrderSkuVo(orderSkuId, orderSkuVo);
//mysql
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlsOrder = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> sqlsOrderSku = CollectionUtil.linkedListObjectArr();
sqls.add(SqlMapping.get("goblin_order.store.orderPrice"));
sqls.add(SqlMapping.get("goblin_order.store.orderSkuPrice"));
sqlsOrder.add(new Object[]{
orderVo.getPriceModify(), orderVo.getPriceVoucher(), orderVo.getPriceActual(), now,
orderId, now, now
});
sqlsOrderSku.add(new Object[]{
orderSkuVo.getPriceModify(), orderSkuVo.getPriceVoucher(), orderSkuVo.getSkuPriceActual(), now,
orderSkuId, now, now
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.gets(sqls, sqlsOrder, sqlsOrderSku));
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.log",
log.getOrderLogId(), log.getOrderId(), log.getType(), log.getRemark(), log.getOperationName(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> refundOrderSku(String orderId, String orderSkuId, BigDecimal price) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
List<GoblinBackOrderSkuVo> orderSkuVoList = ObjectUtil.goblinBackOrderSkuVoArrayList();
BigDecimal refundPrice = price;
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
if (orderSkuId != null) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
if (orderSkuVo == null) {
return ResponseDto.failure("不存在");
}
GoblinBackOrderSkuVo backOrderSkuVo = GoblinBackOrderSkuVo.getNew();
backOrderSkuVo.setOrderSkuId(orderSkuId);
backOrderSkuVo.setSpuId(orderSkuVo.getSpuId());
backOrderSkuVo.setSpuName(orderSkuVo.getSpuName());
backOrderSkuVo.setSkuId(orderSkuVo.getSkuId());
backOrderSkuVo.setSkuName(orderSkuVo.getSkuName());
backOrderSkuVo.setRefundPrice(price);
backOrderSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
backOrderSkuVo.setCreatedAt(nowStr);
backOrderSkuVo.setSkuPic(orderSkuVo.getSkuImage());
orderSkuVoList.add(backOrderSkuVo);
BigDecimal backOrderSkuVoPrice = mongoUtils.getRefundOrderSkuVoPrice(orderSkuId);
if (price.compareTo(orderSkuVo.getSkuPriceActual().subtract(backOrderSkuVoPrice)) > 0) {
return ResponseDto.failure("退款价格超过商品可退价格");
}
} else {
refundPrice = BigDecimal.ZERO;
for (String orderSkuIdItem : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuIdItem);
GoblinBackOrderSkuVo backOrderSkuVo = GoblinBackOrderSkuVo.getNew();
backOrderSkuVo.setOrderSkuId(orderSkuIdItem);
backOrderSkuVo.setSpuId(orderSkuVo.getSpuId());
backOrderSkuVo.setSpuName(orderSkuVo.getSpuName());
backOrderSkuVo.setSkuId(orderSkuVo.getSkuId());
backOrderSkuVo.setSkuName(orderSkuVo.getSkuName());
backOrderSkuVo.setRefundPrice(orderSkuVo.getSkuPriceActual());
backOrderSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
backOrderSkuVo.setCreatedAt(nowStr);
backOrderSkuVo.setSkuPic(orderSkuVo.getSkuImage());
orderSkuVoList.add(backOrderSkuVo);
refundPrice = refundPrice.add(orderSkuVo.getSkuPriceActual().subtract(orderSkuVo.getPriceRefund()));
}
}
//记录退款单
String refundCode = IDGenerator.storeRefundCode(orderVo.getMasterOrderCode());
GoblinBackOrder goblinBackOrder = GoblinBackOrder.getNew();
goblinBackOrder.setBackOrderId(IDGenerator.nextTimeId2());
goblinBackOrder.setBackCode(refundCode);
goblinBackOrder.setOrderId(orderVo.getOrderId());
goblinBackOrder.setOrderCode(orderVo.getOrderCode());
goblinBackOrder.setStoreId(orderVo.getStoreId());
goblinBackOrder.setUserId(orderVo.getUserId());
goblinBackOrder.setSkuIdNums(orderSkuId);
goblinBackOrder.setType(GoblinStatusConst.Type.BACK_TYPE_1.getValue());
goblinBackOrder.setReason(GoblinStatusConst.Type.BACK_REASON_TYPE_8.getDesc());
goblinBackOrder.setDescribes("店铺退款");
goblinBackOrder.setRealBackPrice(refundPrice);
goblinBackOrder.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_0.getValue());
goblinBackOrder.setAuditAt(now);
goblinBackOrder.setCreatedAt(now);
GoblinBackOrderVo backOrderVo = GoblinBackOrderVo.getNew();
BeanUtils.copyProperties(goblinBackOrder, backOrderVo);
backOrderVo.setCreatedAt(nowStr);
backOrderVo.setBackOrderSkuVos(orderSkuVoList);
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(goblinBackOrder.getBackOrderId(), uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
backOrderLog.setMessage("商户发起:orderSkuId=[" + orderSkuId + "],refundPrice=[" + refundPrice + "],[refundCode=" + refundCode + "]");
//调用退款
String returnString = initRefund(orderVo, refundPrice, refundCode);
HashMap hashMapResult = JsonUtils.fromJson(returnString, HashMap.class);
Boolean success = (Boolean) hashMapResult.get("success");
String message = (String) hashMapResult.get("message");
if (!success) {
if (!(backOrderVo.getStatus() == GoblinStatusConst.Status.ORDER_BACK_STATUS_8.getValue() || backOrderVo.getStatus() == GoblinStatusConst.Status.ORDER_BACK_STATUS_2.getValue())) {
backOrderVo.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_10.getValue());
backOrderVo.setErrorReason(backOrderVo.getErrorReason() + ",失败原因:" + message);
log.error("REFUND DATA = " + returnString);
}
}
//redis
redisUtils.setBackOrderVo(backOrderVo.getBackOrderId(), backOrderVo);
redisUtils.addBackOrderByOrderId(orderVo.getOrderId(), backOrderVo.getBackOrderId());
//mongo
mongoUtils.insertGoblinBackOrderVo(backOrderVo);
//添加退款
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.backOrder",
goblinBackOrder.getBackOrderId(), goblinBackOrder.getBackCode(), goblinBackOrder.getOrderId(),
goblinBackOrder.getOrderCode(), goblinBackOrder.getStoreId(), goblinBackOrder.getUserId(),
goblinBackOrder.getSkuIdNums(), goblinBackOrder.getType(), goblinBackOrder.getReason(),
goblinBackOrder.getDescribes(), goblinBackOrder.getRealBackPrice(), goblinBackOrder.getStatus(),
goblinBackOrder.getCreatedAt(), goblinBackOrder.getAuditAt(), goblinBackOrder.getErrorReason()
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.refundLog",
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
)
);
if (success) {
return ResponseDto.success();
}
return ResponseDto.failure("退款失败:" + message);
}
@Override
public ResponseDto<Boolean> express(String orderId, String orderSkuIds, String mailNo) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlsOrder = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> sqlsOrderSku = CollectionUtil.linkedListObjectArr();
LinkedList<Object[]> sqlsMail = CollectionUtil.linkedListObjectArr();
sqls.add(SqlMapping.get("goblin_order.store.express"));
sqls.add(SqlMapping.get("goblin_order.store.orderSkuStatus"));
sqls.add(SqlMapping.get("goblin_order.mail"));
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
if (orderVo.getStatus() != GoblinStatusConst.Status.ORDER_STATUS_2.getValue()) {
return ResponseDto.failure("无法发货");
}
List<String> backOrderIds = redisUtils.getBackOrderByOrderId(orderId);
for (String backOrderId : backOrderIds) {
GoblinBackOrderVo backOrderVo = redisUtils.getBackOrderVo(backOrderId);
if (!(backOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_3.getValue()) || backOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_5.getValue()) || backOrderVo.getStatus().equals(GoblinStatusConst.Status.ORDER_BACK_STATUS_9.getValue()))) {
return ResponseDto.failure("申请失败");
}
}
List<String> skuIds;
if (orderSkuIds == null) {
skuIds = orderVo.getOrderSkuVoIds();
} else {
skuIds = Arrays.asList(orderSkuIds.split(","));
}
GoblinMailVo mailVo = GoblinMailVo.getNew();
mailVo.setMailId(IDGenerator.nextTimeId2());
mailVo.setOrderId(orderVo.getOrderId());
mailVo.setMailNo(mailNo);
mailVo.setDeliveryTime(nowStr);
mailVo.setLogisticsCompany("松鼠德邦");
mailVo.setOrderSkuVoIds(skuIds);
//redis
redisUtils.addGoblinMail(orderId, mailVo);
//mongo
mongoUtils.insertGoblinMailVo(mailVo);
//mysql
sqlsMail.add(new Object[]{
mailVo.getMailId(), mailVo.getOrderId(), mailVo.getMailNo(), mailVo.getDeliveryTime(),
mailVo.getLogisticsCompany(), StringUtils.join(mailVo.getOrderSkuVoIds(), ","), now
});
for (String orderSkuId : skuIds) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
orderSkuVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_3.getValue());
//redis
redisUtils.setGoblinOrderSku(orderSkuId, orderSkuVo);
//mongo
mongoUtils.updateGoblinOrderSkuVo(orderSkuId, orderSkuVo);
//mysql
sqlsOrderSku.add(new Object[]{
orderSkuVo.getStatus(), now,
orderSkuVo.getOrderSkuId(), now, now
});
}
int sendSize = 0;
for (String orderSkuId : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuId);
if (orderSkuVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_3.getValue() || orderSkuVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_4.getValue()) {
sendSize++;
}
}
if (sendSize == orderVo.getOrderSkuVoIds().size()) {
orderVo.setStatus(GoblinStatusConst.Status.ORDER_STATUS_3.getValue());
}
GoblinOrderOperationLog log = initLog(orderId, uid, now);
log.setType(GoblinStatusConst.Status.ORDER_LOG_STATUS_13.getValue());
log.setRemark("发货:orderId=[" + orderId + "],orderSkuId=[" + StringUtils.join(skuIds, ",") + "],mailNo=[" + mailNo + "]");
//redis
redisUtils.setGoblinOrder(orderId, orderVo);
//mongo
mongoUtils.updateGoblinStoreOrderVo(orderId, orderVo);
//mysql
sqlsOrder.add(new Object[]{
orderVo.getStatus(), now, orderId, now, now
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.gets(sqls, sqlsOrder, sqlsOrderSku, sqlsMail));
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.log",
log.getOrderLogId(), log.getOrderId(), log.getType(), log.getRemark(), log.getOperationName(), now
)
);
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> changeExpressMailNo(String orderId, String mailId, String mailNo) {
String uid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = redisUtils.getStoreInfoVoByUid(uid);
if (storeInfoVo == null) {
return ResponseDto.failure("无法查看");
}
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
if (orderVo == null || !orderVo.getStoreId().equals(storeInfoVo.getStoreId())) {
return ResponseDto.failure("无法查看");
}
GoblinMailVo vo = GoblinMailVo.getNew();
vo.setMailNo(mailNo);
vo.setMailId(mailId);
vo.setOrderId(orderId);
redisUtils.changeGoblinMail(orderId, vo);
mongoUtils.updateGoblinMailVo(mailId, vo);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.mail.update",
vo.getMailNo(), LocalDateTime.now(), vo.getMailId()
)
);
return ResponseDto.success();
}
private GoblinOrderOperationLog initLog(String orderId, String uid, LocalDateTime now) {
GoblinOrderOperationLog log = GoblinOrderOperationLog.getNew();
log.setOrderId(orderId);
log.setOperationName(uid);
log.setOrderLogId(IDGenerator.nextTimeId2());
log.setCreatedAt(now);
return log;
}
private GoblinBackOrderLog initBackLog(String orderId, String uid, LocalDateTime now) {
GoblinBackOrderLog log = GoblinBackOrderLog.getNew();
log.setBackOrderId(orderId);
log.setOperationName(uid);
log.setBackOrderLogId(IDGenerator.nextTimeId2());
log.setCreatedAt(now);
return log;
}
private String initRefund(GoblinStoreOrderVo orderVo, BigDecimal price, String refundCode) {
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("code", orderVo.getPayCode());
params.add("notifyUrl", synUrl);
params.add("orderCode", orderVo.getMasterOrderCode());
params.add("orderRefundCode", refundCode);
params.add("paymentId", orderVo.getPaymentId());
params.add("paymentType", orderVo.getPaymentType());
params.add("price", String.valueOf(price));
params.add("priceTotal", String.valueOf(orderVo.getPriceActual()));
params.add("reason", "按需退款");
MultiValueMap<String, String> headers = CollectionUtil.linkedMultiValueMapStringString();
headers.add("Accept", "application/json;charset=UTF-8");
String returnString = HttpUtil.post(refundApply, params, headers);
log.debug("REFUND DATA = " + returnString);
return returnString;
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.manage.GoblinStorePurchaseCommonParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStorePurchaseItemParam;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinStoreMarketPurchasing;
import com.liquidnet.service.goblin.entity.GoblinStoreMarketing;
import com.liquidnet.service.goblin.service.manage.IGoblinStorePurchasingService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import static com.liquidnet.commons.lang.util.DateUtil.DTF_YMD_HMS;
@Service
public class GoblinStorePurchasingServiceImpl implements IGoblinStorePurchasingService {
@Autowired
GoblinRedisUtils goblinRedisUtils;
@Autowired
GoblinMongoUtils goblinMongoUtils;
@Autowired
QueueUtils queueUtils;
@Override
public ResponseDto<PageInfo<GoblinStoreMarketVo>> purchasingList(int page, String purchaseName, int status, String st, String et, String ct) {
PageInfo pageInfo = new PageInfo();
LocalDateTime now = LocalDateTime.now();
HashMap<String, Object> map = goblinMongoUtils.getStoreMarketList(page, purchaseName, status, st, et, ct);
List<GoblinStoreMarketVo> list = (List<GoblinStoreMarketVo>) map.get("data");
for (GoblinStoreMarketVo item : list) {
if (item.getStatus().equals(7)) {
item.setStatus(7);
} else if (LocalDateTime.parse(item.getStartTime(), DTF_YMD_HMS).isAfter(now)) {
item.setStatus(0);
} else if (LocalDateTime.parse(item.getEndTime(), DTF_YMD_HMS).isBefore(now)) {
item.setStatus(2);
} else {
item.setStatus(1);
}
}
pageInfo.setList(list);
pageInfo.setTotal((Long) map.get("total"));
return ResponseDto.success(pageInfo);
}
@Override
public ResponseDto<Boolean> purchasingStatus(String marketId, String storeId, int status) {
GoblinStoreMarketing bean = GoblinStoreMarketing.getNew();
LocalDateTime now = LocalDateTime.now();
bean.setUpdatedAt(now);
switch (status) {
case 0:
case 7:
bean.setStatus(status);
bean.setDelFlag(0);
GoblinStoreMarketVo vo = GoblinStoreMarketVo.getNew();
vo.setStatus(status);
goblinMongoUtils.updateStoreMarket(marketId, storeId, vo);
vo = goblinRedisUtils.getGoblinStoreMarketVo(marketId);
vo.setStatus(status);
goblinRedisUtils.setGoblinStoreMarketVo(marketId, vo);
break;
case -1:
bean.setStatus(7);
bean.setDelFlag(1);
goblinMongoUtils.delStoreMarket(marketId, storeId);
goblinRedisUtils.delGoblinStoreMarketVo(marketId);
break;
}
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_MARKET.getKey(),
SqlMapping.get("goblin.store.market.status", bean.getStatus(), bean.getDelFlag(), marketId, storeId));
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> purchasingInsert(String purchaseName, String storeId, String st, String et, Integer isPre, String preTime) {
String storeMarketId = IDGenerator.nextTimeId2();
GoblinStoreMarketing bean = GoblinStoreMarketing.getNew();
bean.setStoreMarketId(storeMarketId);
bean.setName(purchaseName);
bean.setType(2);
bean.setStatus(0);
bean.setStoreId(storeId);
bean.setDescribes("");
bean.setStartTime(LocalDateTime.parse(st, DTF_YMD_HMS));
bean.setEndTime(LocalDateTime.parse(et, DTF_YMD_HMS));
bean.setDelFlag(0);
bean.setIsPre(isPre);
if (isPre == 1) {
bean.setPreTime(LocalDateTime.parse(preTime, DTF_YMD_HMS));
} else {
bean.setPreTime(null);
}
bean.setCreatedAt(LocalDateTime.now());
GoblinStoreMarketVo vo = GoblinStoreMarketVo.getNew();
BeanUtils.copyProperties(bean, vo);
vo.setStartTime(st);
vo.setEndTime(et);
vo.setCreatedAt(DateUtil.getNowTime());
vo.setPreTime(preTime);
//mongo
goblinMongoUtils.insertStoreMarket(vo);
//redis
goblinRedisUtils.setGoblinStoreMarketVo(storeMarketId, vo);
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_MARKET.getKey(),
SqlMapping.get("goblin.store.market.insert", bean.getStoreMarketId(), bean.getName(), bean.getType(), bean.getStatus(), bean.getStoreId(), bean.getStartTime(), bean.getEndTime(), bean.getDelFlag(), bean.getIsPre(), bean.getPreTime(), bean.getCreatedAt()));
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> purchasingUpdate(String marketId, String purchaseName, String storeId, String st, String et, Integer isPre, String preTime) {
GoblinStoreMarketing bean = GoblinStoreMarketing.getNew();
bean.setName(purchaseName);
bean.setType(2);
bean.setStatus(0);
bean.setStoreId(storeId);
bean.setDescribes("");
bean.setStartTime(LocalDateTime.parse(st, DTF_YMD_HMS));
bean.setEndTime(LocalDateTime.parse(et, DTF_YMD_HMS));
bean.setDelFlag(0);
bean.setIsPre(isPre);
if (isPre == 1) {
bean.setPreTime(LocalDateTime.parse(preTime, DTF_YMD_HMS));
} else {
bean.setPreTime(null);
}
bean.setUpdatedAt(LocalDateTime.now());
GoblinStoreMarketVo vo = GoblinStoreMarketVo.getNew();
BeanUtils.copyProperties(bean, vo);
//mongo
goblinMongoUtils.updateStoreMarket(marketId, storeId, vo);
//redis
goblinRedisUtils.setGoblinStoreMarketVo(marketId, vo);
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_MARKET.getKey(),
SqlMapping.get("goblin.store.market.update", bean.getName(), bean.getType(), bean.getStatus(), bean.getStoreId(), bean.getDescribes(), bean.getStartTime(), bean.getEndTime(), bean.getDelFlag(), bean.getIsPre(), bean.getPreTime(), bean.getUpdatedAt(), marketId, bean.getStoreId()));
return ResponseDto.success();
}
@Override
public ResponseDto<GoblinStoreMarketVo> purchasingDetails(String marketId) {
return ResponseDto.success(goblinRedisUtils.getGoblinStoreMarketVo(marketId));
}
@Override
public ResponseDto<List<GoblinMarketSpuListVo>> purchasingSpuList(String marketId, String storeId, int page) {
int size = 20;
List<GoblinStoreMarketIsConfigVo> spuIds = goblinRedisUtils.getStoreMarketIsConfig(marketId, storeId);
List<String> marketSpuList = spuIds.stream().map(GoblinStoreMarketIsConfigVo::getMarketSpuId).collect(Collectors.toList());
List<GoblinMarketSpuListVo> voList = ObjectUtil.getGoblinMarketSpuListVoArrayList();
int count = page * size;
int startCount = (page - 1) * size;
if (count >= marketSpuList.size()) {
count = marketSpuList.size();
}
for (int i = startCount; i < count; i++) {
GoblinMarketSpuListVo vo = GoblinMarketSpuListVo.getNew();
String marketSpuId = marketSpuList.get(i);
GoblinGoodsInfoVo spuVo = goblinRedisUtils.getGoodsInfoVo(marketSpuId);
vo.setMarketSpuId(marketSpuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue())[0]);
vo.setCoverPic(spuVo.getCoverPic());
vo.setName(spuVo.getName());
vo.setPriceGe(spuVo.getPriceGe());
vo.setPriceLe(spuVo.getPriceLe());
voList.add(vo);
}
return ResponseDto.success(voList);
}
@Override
public ResponseDto<List<GoblinStorePurchaseSkuVo>> purchasingSkuList(String marketId, String storeId, String marketSpuId) {
GoblinGoodsInfoVo marketSpuVo = goblinRedisUtils.getGoodsInfoVo(marketSpuId);
List<String> marketSkuIdList = marketSpuVo.getSkuIdList();
List<GoblinStorePurchaseSkuVo> voList = ObjectUtil.getGoblinStorePurchaseSkuVoArrayList();
for (String marketSkuId : marketSkuIdList) {
GoblinGoodsSkuInfoVo marketSkuVo = goblinRedisUtils.getGoodsSkuInfoVo(marketSkuId);
GoblinGoodsSkuInfoVo skuVo = goblinRedisUtils.getGoodsSkuInfoVo(marketSkuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue())[0]);
GoblinStorePurchaseSkuVo vo = GoblinStorePurchaseSkuVo.getNew();
vo.setMarketSkuId(marketSkuId);
vo.setSkuSpecList(marketSkuVo.getSkuSpecList());
vo.setPrice(skuVo.getPrice());
vo.setStock(skuVo.getStock());
vo.setSkuStock(skuVo.getSkuStock());
vo.setPriceMarketing(marketSkuVo.getPrice());
vo.setStockMarketing(marketSkuVo.getSkuStock());
vo.setBuyFactor(marketSkuVo.getBuyFactor());
vo.setBuyLimit(marketSkuVo.getBuyLimit());
vo.setBuyRoster(marketSkuVo.getBuyRoster());
voList.add(vo);
}
return ResponseDto.success(voList);
}
@Override
public ResponseDto<Boolean> purchasingSkuInsert(GoblinStorePurchaseCommonParam params) {
LocalDateTime now = LocalDateTime.now();
String marketSpuId = params.getSpuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()).concat(IDGenerator.marketGoodId(params.getStoreMarketId()));
GoblinMarketRelationVo relationVo = GoblinMarketRelationVo.getNew();
relationVo.setSpuId(params.getSpuId());
relationVo.setStoreId(params.getStoreId());
List<String> skuList = CollectionUtil.arrayListString();//skuId数组
List<String> marketSkuList = CollectionUtil.arrayListString();//活动skuId数组
List<String> errorNameList = CollectionUtil.arrayListString();//修改失败的款式名称数组
List<BigDecimal> priceList = CollectionUtil.arrayListBigDecimal();//价格集合
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin.store.market.insertRelation"));
LinkedList<Object[]> sqlsData = CollectionUtil.linkedListObjectArr();
for (GoblinStorePurchaseItemParam item : params.getGoblinStorePurchaseItemParam()) {
String purchaseId = IDGenerator.nextMilliId2();
GoblinStoreMarketPurchasing bean = GoblinStoreMarketPurchasing.getNew();
bean.setStoreId(params.getStoreId());
bean.setStoreMarketId(params.getStoreMarketId());
bean.setSpuId(params.getSpuId());
bean.setPurchaseId(purchaseId);
bean.setSkuId(item.getSkuId());
bean.setPriceMarketing(item.getPriceMarketing());
bean.setStockMarketing(item.getStockMarketing());
bean.setBuyLimit(item.getBuyLimit());
bean.setBuyFactor(item.getBuyFactor());
bean.setBuyRoster(item.getBuyRoster());
bean.setDelFlag(0);
bean.setCreatedAt(now);
//mongo
GoblinGoodsSkuInfoVo skuVo = goblinRedisUtils.getGoodsSkuInfoVo(item.getSkuId());
//判断库存相关
String marketSkuId = item.getSkuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()).concat(IDGenerator.marketGoodId(params.getStoreMarketId()));
int restStock = goblinRedisUtils.decrSkuStock(null, item.getSkuId(), item.getStockMarketing());
if (restStock < 0) {
errorNameList.add(skuVo.getName());
goblinRedisUtils.incrSkuStock(null, item.getSkuId(), item.getStockMarketing());
continue;
}
goblinRedisUtils.setSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), marketSkuId, item.getStockMarketing());
skuVo.setSpuId(marketSpuId);
skuVo.setSkuId(marketSkuId);
skuVo.setPrice(bean.getPriceMarketing());
skuVo.setPriceMember(bean.getPriceMarketing());
skuVo.setSkuStock(bean.getStockMarketing());
skuVo.setBuyLimit(bean.getBuyLimit());
skuVo.setBuyRoster(bean.getBuyRoster());
skuVo.setBuyFactor(bean.getBuyFactor().toString());
skuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue().concat(params.getStoreMarketId()));
goblinMongoUtils.setGoodsSkuInfoVo(skuVo);
//redis
goblinRedisUtils.setGoodsSkuInfoVo(skuVo);
//mysql
sqlsData.add(new Object[]{purchaseId, bean.getStoreMarketId(), bean.getSpuId(), bean.getSpuId(), bean.getStoreId(), bean.getPriceMarketing(),
bean.getStockMarketing(), bean.getBuyFactor(), bean.getBuyRoster(), bean.getBuyLimit(), bean.getDelFlag(), bean.getCreatedAt()});
marketSkuList.add(skuVo.getSkuId());
skuList.add(item.getSkuId());
priceList.add(item.getPriceMarketing());
}
if (errorNameList.size() == params.getGoblinStorePurchaseItemParam().size()) {
return ResponseDto.failure(JsonUtils.toJson(errorNameList));
}
//mongo
GoblinGoodsInfoVo spuVo = goblinRedisUtils.getGoodsInfoVo(params.getSpuId());
spuVo.setSpuId(marketSpuId);
spuVo.setSkuIdList(marketSkuList);
//排序
priceList = priceList.stream().sorted().collect(Collectors.toList());
spuVo.setPriceGe(priceList.get(0));
spuVo.setPriceLe(priceList.get(priceList.size() - 1));
spuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue().concat(params.getStoreMarketId()));
GoblinSelfMarketingVo marketVo = goblinRedisUtils.getSelfMarket(params.getStoreMarketId());
spuVo.setPerformanceId(marketVo.getPerformanceId());
goblinMongoUtils.setGoodsInfoVo(spuVo);
//redis
goblinRedisUtils.setGoodsInfoVo(spuVo);
relationVo.setSkuList(skuList);
goblinRedisUtils.addMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), params.getStoreMarketId(), relationVo);
goblinRedisUtils.addStoreMarketIsConfig(params.getStoreMarketId(), params.getStoreId(), params.getSpuId(), marketSpuId);
// 执行sql
String sqlData = SqlMapping.gets(sqls, sqlsData);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_MARKET.getKey(),
sqlData);
if (errorNameList.size() > 0) {
return ResponseDto.failure(JsonUtils.toJson(errorNameList));
}
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> purchasingSkuUpdate(GoblinStorePurchaseCommonParam params) {
LocalDateTime now = LocalDateTime.now();
String marketSpuId = params.getSpuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()).concat(IDGenerator.marketGoodId(params.getStoreMarketId()));
List<String> marketSkuList = CollectionUtil.arrayListString();
List<BigDecimal> priceList = CollectionUtil.arrayListBigDecimal();//价格集合
List<String> errorNameList = CollectionUtil.arrayListString();//修改失败的款式名称数组
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin.store.market.updateRelation"));
LinkedList<Object[]> sqlsData = CollectionUtil.linkedListObjectArr();
for (GoblinStorePurchaseItemParam item : params.getGoblinStorePurchaseItemParam()) {
GoblinStoreMarketPurchasing bean = GoblinStoreMarketPurchasing.getNew();
bean.setPriceMarketing(item.getPriceMarketing());
bean.setStockMarketing(item.getStockMarketing());
bean.setBuyLimit(item.getBuyLimit());
bean.setBuyFactor(item.getBuyFactor());
bean.setBuyRoster(item.getBuyRoster());
bean.setDelFlag(0);
bean.setUpdatedAt(now);
//mongo
GoblinGoodsSkuInfoVo skuVo = goblinRedisUtils.getGoodsSkuInfoVo(item.getSkuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()).concat(IDGenerator.marketGoodId(params.getStoreMarketId())));
int changeStock = item.getStockMarketing() - skuVo.getSkuStock();
//判断库存相关
int restStock;
if (changeStock > 0) {
restStock = goblinRedisUtils.incrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), skuVo.getSkuId(), changeStock);
goblinRedisUtils.decrSkuStock(null, item.getSkuId(), changeStock);
} else {
restStock = goblinRedisUtils.decrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), skuVo.getSkuId(), -changeStock);
goblinRedisUtils.incrSkuStock(null, item.getSkuId(), -changeStock);
}
if (restStock < 0) {
errorNameList.add(skuVo.getName());
goblinRedisUtils.incrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), skuVo.getSkuId(), -changeStock);
goblinRedisUtils.decrSkuStock(null, item.getSkuId(), -changeStock);
continue;
}
skuVo.setPrice(bean.getPriceMarketing());
skuVo.setPriceMember(bean.getPriceMarketing());
skuVo.setSkuStock(bean.getStockMarketing());
skuVo.setBuyLimit(bean.getBuyLimit());
skuVo.setBuyRoster(bean.getBuyRoster());
skuVo.setBuyFactor(bean.getBuyFactor().toString());
skuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue().concat(params.getStoreMarketId()));
goblinMongoUtils.updateGoodsSkuInfoVo(skuVo);
//redis
goblinRedisUtils.setGoodsSkuInfoVo(skuVo);
//mysql
sqlsData.add(new Object[]{bean.getPriceMarketing(),
bean.getStockMarketing(), bean.getBuyFactor(), bean.getBuyRoster(), bean.getBuyLimit(), bean.getUpdatedAt(), params.getStoreMarketId(), params.getStoreId()});
marketSkuList.add(skuVo.getSkuId());
priceList.add(bean.getPriceMarketing());
}
if (errorNameList.size() == params.getGoblinStorePurchaseItemParam().size()) {
return ResponseDto.failure(JsonUtils.toJson(errorNameList));
}
//mongo
GoblinGoodsInfoVo spuVo = goblinRedisUtils.getGoodsInfoVo(params.getSpuId());
spuVo.setSpuId(marketSpuId);
//排序
priceList = priceList.stream().sorted().collect(Collectors.toList());
spuVo.setPriceGe(priceList.get(0));
spuVo.setPriceLe(priceList.get(priceList.size() - 1));
spuVo.setSkuIdList(marketSkuList);
spuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue().concat(params.getStoreMarketId()));
GoblinSelfMarketingVo marketVo = goblinRedisUtils.getSelfMarket(params.getStoreMarketId());
spuVo.setPerformanceId(marketVo.getPerformanceId());
goblinMongoUtils.updateGoodsInfoVo(spuVo);
//redis
goblinRedisUtils.setGoodsInfoVo(spuVo);
// 执行sql
String sqlData = SqlMapping.gets(sqls, sqlsData);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_MARKET.getKey(),
sqlData);
if (errorNameList.size() > 0) {
return ResponseDto.failure(JsonUtils.toJson(errorNameList));
}
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> purchasingSpuDel(String marketId, String storeId, String spuId) {
//todo hujiachen 判断 如果有订单待支付 则不能关闭
LocalDateTime now = LocalDateTime.now();
String marketSpuId = spuId.concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue()).concat(IDGenerator.marketGoodId(marketId));
GoblinStoreMarketPurchasing bean = GoblinStoreMarketPurchasing.getNew();
bean.setUpdatedAt(now);
bean.setDelFlag(1);
//mongo
goblinMongoUtils.delGoodsInfoVo(marketSpuId);
//redis
goblinRedisUtils.delGoodsInfoVo(marketSpuId);
goblinRedisUtils.removeMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), marketId, spuId);
goblinRedisUtils.delStoreMarketIsConfig(marketId, storeId, spuId, marketSpuId);
//库存处理
GoblinGoodsInfoVo marketVo = goblinRedisUtils.getGoodsInfoVo(marketSpuId);
for (String marketSkuId : marketVo.getSkuIdList()) {
String skuId = marketSkuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue())[0];
//库存回滚
int restStock = goblinRedisUtils.getSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), marketSkuId);
int restStockDe = goblinRedisUtils.decrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_PURCHASE.getValue(), marketSkuId, restStock);
goblinRedisUtils.incrSkuStock(null, skuId, restStock + restStockDe);
}
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_STORE_MARKET.getKey(),
SqlMapping.get("goblin.store.market.delSpuRelation", bean.getDelFlag(), bean.getUpdatedAt(), marketId, storeId, spuId));
return ResponseDto.success();
}
}
package com.liquidnet.service.goblin.service.impl.manage;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreZhengzaiCommonParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreZhengzaiItemParam;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinMarketingZhengzai;
import com.liquidnet.service.goblin.entity.GoblinSelfMarketing;
import com.liquidnet.service.goblin.service.manage.IGoblinZhengzaiService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class GoblinZhengzaiServiceImpl implements IGoblinZhengzaiService {
@Autowired
GoblinRedisUtils redisUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
QueueUtils queueUtils;
@Override
public List<GoblinSelfMarketingVo> zhengzaiCanJoin(String storeId) {
String nowStr = DateUtil.getNowTime();
List<String> marketIds = redisUtils.getStoreZhengzaiRelation(storeId);
marketIds = marketIds.stream().distinct().collect(Collectors.toList());
List<GoblinSelfMarketingVo> voList = ObjectUtil.getGoblinSelfMarketingVoList();
for (String selfMarketId : marketIds) {
GoblinMarketingZhengzaiRelationVo zhengzaiRelationVo = redisUtils.getZhengzaiRelation(selfMarketId, storeId);
if (DateUtil.compareStrDay(DateUtil.getNowTime(), zhengzaiRelationVo.getShowTime()) == 1) {
GoblinSelfMarketingVo vo = redisUtils.getSelfMarket(selfMarketId);
if (vo == null) {
continue;
}
if (vo.getStatus() == null || vo.getStatus() != 7) {
if (DateUtil.compareStrDay(nowStr, vo.getStartTime()) < 0) {
vo.setStatus(0);
} else if (DateUtil.compareStrDay(nowStr, vo.getEndTime()) > 0) {
vo.setStatus(2);
} else {
vo.setStatus(1);
}
}
voList.add(vo);
}
}
return voList;
}
@Override
public GoblinSelfMarketingVo zhengzaiCanJoinDetails(String marketId, String storeId) {
GoblinMarketingZhengzaiRelationVo zhengzaiRelationVo = redisUtils.getZhengzaiRelation(marketId, storeId);
if (DateUtil.compareStrDay(DateUtil.getNowTime(), zhengzaiRelationVo.getShowTime()) == 1) {
return redisUtils.getSelfMarket(marketId);
}
return null;
}
@Override
public ResponseDto<PageInfo<GoblinMarketSpuListVo>> zhengzaiSpuList(String marketId, String storeId, int page) {
int size = 20;
List<GoblinStoreMarketIsConfigVo> spuIds = redisUtils.getStoreMarketIsConfig(marketId, storeId);
List<GoblinMarketSpuListVo> voList = ObjectUtil.getGoblinMarketSpuListVoArrayList();
int startCount = (page - 1) * size;
List<GoblinGoodsInfoVo> list = mongoUtils.marketSpuList(marketId, storeId, startCount, size);
for (GoblinGoodsInfoVo spuVo : list) {
GoblinMarketSpuListVo vo = GoblinMarketSpuListVo.getNew();
if (null != spuVo && spuVo.getDelFlg().equals("0") && spuVo.getShelvesStatus().equals("3")) {
vo.setMarketSpuId(spuVo.getSpuId().split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())[0]);
vo.setCoverPic(spuVo.getCoverPic());
vo.setName(spuVo.getName());
vo.setPriceGe(spuVo.getPriceGe());
vo.setPriceLe(spuVo.getPriceLe());
voList.add(vo);
}
}
PageInfo pageInfo = new PageInfo(voList);
pageInfo.setTotal(spuIds.size());
return ResponseDto.success(pageInfo);
}
@Override
public ResponseDto<List<GoblinSelfZhengzaiSkuVo>> zhengzaiSkuList(String selfMarketId, String storeId, String spuId) {
GoblinGoodsInfoVo marketSpuVo = redisUtils.getGoodsInfoVo(spuId.concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue()).concat(IDGenerator.marketGoodId(selfMarketId)));
List<String> marketSkuIdList = marketSpuVo.getSkuIdList();
List<GoblinSelfZhengzaiSkuVo> voList = ObjectUtil.getGoblinSelfZhengzaiSkuVoArrayList();
for (String marketSkuId : marketSkuIdList) {
GoblinGoodsSkuInfoVo marketSkuVo = redisUtils.getGoodsSkuInfoVo(marketSkuId);
GoblinGoodsSkuInfoVo skuVo = redisUtils.getGoodsSkuInfoVo(marketSkuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())[0]);
if (skuVo.getDelFlg().equals("1")) {
continue;
}
if (marketSkuVo == null) {
continue;
}
GoblinSelfZhengzaiSkuVo vo = GoblinSelfZhengzaiSkuVo.getNew();
vo.setMarketSkuId(marketSkuId);
vo.setSkuId(marketSkuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())[0]);
vo.setSkuSpecList(skuVo.getSkuSpecList());
vo.setPrice(skuVo.getPrice());
vo.setStock(skuVo.getStock());
vo.setSkuStock(skuVo.getSkuStock());
vo.setPriceMarketing(marketSkuVo.getPrice());
vo.setStockMarketing(marketSkuVo.getSkuStock());
vo.setBuyFactor(marketSkuVo.getBuyFactor());
vo.setBuyLimit(marketSkuVo.getBuyLimit());
vo.setBuyRoster(marketSkuVo.getBuyRoster());
voList.add(vo);
}
return ResponseDto.success(voList);
}
@Override
public ResponseDto<Boolean> zhengzaiSkuInsert(GoblinStoreZhengzaiCommonParam params) {
LocalDateTime now = LocalDateTime.now();
String marketSpuId = params.getSpuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue()).concat(IDGenerator.marketGoodId(params.getSelfMarketId()));
GoblinMarketRelationVo relationVo = GoblinMarketRelationVo.getNew();
List<String> skuList = CollectionUtil.arrayListString();//skuId数组
List<String> marketSkuList = CollectionUtil.arrayListString();//活动skuId数组
List<String> errorNameList = CollectionUtil.arrayListString();//修改失败的款式名称数组
List<BigDecimal> priceList = CollectionUtil.arrayListBigDecimal();//价格集合
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin.self.market.insertRelation"));
LinkedList<Object[]> sqlsData = CollectionUtil.linkedListObjectArr();
List<GoblinStoreMarketIsConfigVo> isConfigVos = redisUtils.getStoreMarketIsConfig(params.getSelfMarketId(), params.getStoreId());
for (GoblinStoreMarketIsConfigVo item : isConfigVos) {
if (item.getSpuId().equals(params.getSpuId())) {
return ResponseDto.failure("该商品已经配置");
}
}
GoblinGoodsInfoVo spuVo = redisUtils.getGoodsInfoVo(params.getSpuId());
List<String> skuSize = params.getGoblinStoreZhengzaiItemParams().stream().distinct().map(GoblinStoreZhengzaiItemParam::getSkuId).collect(Collectors.toList());
if (spuVo.getSkuIdList().size() != skuSize.size()) {
return ResponseDto.failure("参数异常");
}
for (GoblinStoreZhengzaiItemParam item : params.getGoblinStoreZhengzaiItemParams()) {
if (!spuVo.getSkuIdList().contains(item.getSkuId())) {
return ResponseDto.failure("参数异常");
}
//mongo
GoblinGoodsSkuInfoVo skuVo = redisUtils.getGoodsSkuInfoVo(item.getSkuId());
//判断库存相关
if (item.getStockMarketing() > 0) {
int restStock = redisUtils.decrSkuStock(null, item.getSkuId(), item.getStockMarketing());
if (restStock < 0) {
errorNameList.add(skuVo.getName()+"库存不足");
redisUtils.incrSkuStock(null, item.getSkuId(), item.getStockMarketing());
item.setStockMarketing(0);
// continue;
}
}
String zhengzaiId = IDGenerator.nextMilliId2();
GoblinMarketingZhengzai bean = GoblinMarketingZhengzai.getNew();
bean.setStoreId(params.getStoreId());
bean.setSelfMarketId(params.getSelfMarketId());
bean.setSpuId(params.getSpuId());
bean.setZhengzaiId(zhengzaiId);
bean.setSkuId(item.getSkuId());
bean.setPriceMarketing(item.getPriceMarketing());
bean.setStockMarketing(item.getStockMarketing());
bean.setBuyLimit(item.getBuyLimit());
bean.setBuyFactor(item.getBuyFactor());
bean.setBuyRoster(item.getBuyRoster());
bean.setDelFlag(0);
bean.setCreatedAt(now);
String marketSkuId = item.getSkuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue()).concat(IDGenerator.marketGoodId(params.getSelfMarketId()));
skuVo.setSpuId(marketSpuId);
skuVo.setSkuId(marketSkuId);
skuVo.setPrice(bean.getPriceMarketing());
skuVo.setPriceMember(bean.getPriceMarketing());
skuVo.setSkuStock(bean.getStockMarketing());
skuVo.setBuyLimit(bean.getBuyLimit());
skuVo.setBuyRoster(bean.getBuyRoster());
skuVo.setBuyFactor(bean.getBuyFactor().toString());
skuVo.setDelFlg("0");
skuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue().concat(params.getSelfMarketId()));
skuVo.setCreatedAt(LocalDateTime.now());
mongoUtils.upsertGoodsSkuInfoVo(skuVo);
//redis
redisUtils.setGoodsSkuInfoVo(skuVo);
redisUtils.setSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketSkuId, item.getStockMarketing());
redisUtils.addSkuRe(item.getSkuId(), marketSkuId);
//mysql
sqlsData.add(new Object[]{zhengzaiId, bean.getSelfMarketId(), bean.getSpuId(), bean.getSkuId(), bean.getStoreId(), bean.getPriceMarketing(),
bean.getStockMarketing(), bean.getBuyFactor(), bean.getBuyRoster(), bean.getBuyLimit(), bean.getDelFlag(), bean.getCreatedAt()});
marketSkuList.add(skuVo.getSkuId());
skuList.add(skuVo.getSkuId());
priceList.add(item.getPriceMarketing());
if (bean.getBuyFactor() == 2) {
queueUtils.sendMsgByRedisXls(bean.getBuyRoster(), item.getType(), item.getSkuId());
}
}
if (errorNameList.size() == params.getGoblinStoreZhengzaiItemParams().size()) {
return ResponseDto.failure("148001", JsonUtils.toJson(errorNameList));
}
//mongo
spuVo.setSpuId(marketSpuId);
spuVo.setSkuIdList(marketSkuList);
//排序
priceList = priceList.stream().sorted().collect(Collectors.toList());
spuVo.setPriceGe(priceList.get(0));
// spuVo.setSpecMode("2");
spuVo.setPriceLe(priceList.get(priceList.size() - 1));
spuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue().concat(params.getSelfMarketId()));
spuVo.setDelFlg("0");
mongoUtils.upsertGoodsInfoVo(spuVo);
//redis
redisUtils.setGoodsInfoVo(spuVo);
relationVo.setSkuList(skuList);
relationVo.setSpuId(spuVo.getSpuId());
relationVo.setStoreId(params.getStoreId());
redisUtils.addMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), params.getSelfMarketId(), relationVo);
redisUtils.addStoreMarketIsConfig(params.getSelfMarketId(), params.getStoreId(), params.getSpuId(), marketSpuId);
// 执行sql
String sqlData = SqlMapping.gets(sqls, sqlsData);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SELF_MARKET.getKey(),
sqlData);
if (errorNameList.size() > 0) {
return ResponseDto.failure("148001", JsonUtils.toJson(errorNameList));
}
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> zhengzaiSkuUpdate(GoblinStoreZhengzaiCommonParam params) {
LocalDateTime now = LocalDateTime.now();
String marketSpuId = params.getSpuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue()).concat(IDGenerator.marketGoodId(params.getSelfMarketId()));
List<String> marketSkuList = CollectionUtil.arrayListString();
List<BigDecimal> priceList = CollectionUtil.arrayListBigDecimal();//价格集合
List<String> errorNameList = CollectionUtil.arrayListString();//修改失败的款式名称数组
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin.self.market.updateRelation"));
LinkedList<Object[]> sqlsData = CollectionUtil.linkedListObjectArr();
GoblinGoodsInfoVo spuVo = redisUtils.getGoodsInfoVo(params.getSpuId());
for (GoblinStoreZhengzaiItemParam item : params.getGoblinStoreZhengzaiItemParams()) {
if (!spuVo.getSkuIdList().contains(item.getSkuId())) {
return ResponseDto.failure("参数异常");
}
GoblinMarketingZhengzai bean = GoblinMarketingZhengzai.getNew();
bean.setPriceMarketing(item.getPriceMarketing());
bean.setStockMarketing(item.getStockMarketing());
bean.setBuyLimit(item.getBuyLimit());
bean.setBuyFactor(item.getBuyFactor());
bean.setBuyRoster(item.getBuyRoster());
bean.setDelFlag(0);
bean.setUpdatedAt(now);
//mongo
GoblinGoodsSkuInfoVo skuVo = redisUtils.getGoodsSkuInfoVo(item.getSkuId().concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue()).concat(IDGenerator.marketGoodId(params.getSelfMarketId())));
int changeStock = item.getStockMarketing() - skuVo.getSkuStock();
//判断库存相关
int mStock;
int sStock;
if (changeStock > 0) {
mStock = redisUtils.incrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), skuVo.getSkuId(), changeStock);
sStock = redisUtils.decrSkuStock(null, item.getSkuId(), changeStock);
} else {
mStock = redisUtils.decrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), skuVo.getSkuId(), -changeStock);
sStock = redisUtils.incrSkuStock(null, item.getSkuId(), -changeStock);
}
if (mStock < 0) {
errorNameList.add(skuVo.getName()+"库存不足");
redisUtils.incrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), skuVo.getSkuId(), -changeStock);
redisUtils.decrSkuStock(null, item.getSkuId(), -changeStock);
continue;
}
if (sStock < 0) {
errorNameList.add(skuVo.getName()+"库存不足");
redisUtils.incrSkuStock(null, item.getSkuId(), changeStock);
redisUtils.decrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), skuVo.getSkuId(), changeStock);
continue;
}
skuVo.setPrice(bean.getPriceMarketing());
skuVo.setPriceMember(bean.getPriceMarketing());
skuVo.setSkuStock(bean.getStockMarketing());
skuVo.setBuyLimit(bean.getBuyLimit());
skuVo.setBuyRoster(bean.getBuyRoster());
skuVo.setBuyFactor(bean.getBuyFactor().toString());
skuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue().concat(params.getSelfMarketId()));
mongoUtils.updateGoodsSkuInfoVo(skuVo);
//redis
redisUtils.setGoodsSkuInfoVo(skuVo);
//mysql
sqlsData.add(new Object[]{bean.getPriceMarketing(),
bean.getStockMarketing(), bean.getBuyFactor(), bean.getBuyRoster(), bean.getBuyLimit(), bean.getUpdatedAt(), params.getSelfMarketId(), params.getStoreId()});
marketSkuList.add(skuVo.getSkuId());
priceList.add(bean.getPriceMarketing());
if (bean.getBuyFactor() == 2) {
queueUtils.sendMsgByRedisXls(bean.getBuyRoster(), item.getType(), item.getSkuId());
}
}
if (errorNameList.size() == params.getGoblinStoreZhengzaiItemParams().size()) {
return ResponseDto.failure("148001", JsonUtils.toJson(errorNameList));
}
//mongo
spuVo.setSpuId(marketSpuId);
//排序
priceList = priceList.stream().sorted().collect(Collectors.toList());
spuVo.setPriceGe(priceList.get(0));
spuVo.setPriceLe(priceList.get(priceList.size() - 1));
spuVo.setSkuIdList(marketSkuList);
spuVo.setMarketId(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue().concat(params.getSelfMarketId()));
mongoUtils.updateGoodsInfoVo(spuVo);
//redis
redisUtils.setGoodsInfoVo(spuVo);
// 执行sql
String sqlData = SqlMapping.gets(sqls, sqlsData);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SELF_MARKET.getKey(),
sqlData);
if (errorNameList.size() > 0) {
return ResponseDto.failure("148001", JsonUtils.toJson(errorNameList));
}
return ResponseDto.success();
}
@Override
public ResponseDto<Boolean> zhengzaiSpuDel(String marketId, String storeId, String spuId) {
//todo hujiachen 判断 如果有订单待支付 则不能关闭
LocalDateTime now = LocalDateTime.now();
String marketSpuId = spuId.concat(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue()).concat(IDGenerator.marketGoodId(marketId));
GoblinMarketingZhengzai bean = GoblinMarketingZhengzai.getNew();
bean.setUpdatedAt(now);
bean.setDelFlag(1);
//库存处理
GoblinGoodsInfoVo marketVo = redisUtils.getGoodsInfoVo(marketSpuId);
if (marketVo == null) {
return ResponseDto.failure("商品不存在");
}
for (String marketSkuId : marketVo.getSkuIdList()) {
String skuId = marketSkuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())[0];
//库存回滚
int restStock = redisUtils.getSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketSkuId);
int restStockDe = redisUtils.decrSkuStock(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketSkuId, restStock);
redisUtils.incrSkuStock(null, skuId, restStock + restStockDe);
mongoUtils.delGoodsSkuInfoVo(marketSkuId);
redisUtils.delGoodsSkuInfoVo(marketSkuId);
redisUtils.removeGoblinOrder(null, marketSkuId);
redisUtils.removeSkuRe(skuId, marketSkuId);
}
//mongo
mongoUtils.delGoodsInfoVo(marketSpuId);
//redis
redisUtils.delGoodsInfoVo(marketSpuId);
redisUtils.removeMarketRelation(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue(), marketId, marketSpuId);
redisUtils.delStoreMarketIsConfig(marketId, storeId, spuId, marketSpuId);
//mysql
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_SELF_MARKET.getKey(),
SqlMapping.get("goblin.self.market.delSpuRelation", bean.getDelFlag(), bean.getUpdatedAt(), marketId, storeId, spuId));
return ResponseDto.success();
}
}
package com.liquidnet.service.goblin.util;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponFilterParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsFilterParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtNoticeFilterParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.entity.GoblinFrontHotWord;
import com.liquidnet.service.goblin.entity.GoblinFrontNavigation;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.UpdateOneModel;
import com.mongodb.client.model.WriteModel;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Component
public class GoblinMongoUtils {
@Autowired
MongoTemplate mongoTemplate;
@Autowired
MongoConverter mongoConverter;
@Autowired
GoblinRedisUtils redisUtils;
/* ---------------------------------------- 平台分类数据源 ---------------------------------------- */
public List<GoblinSelfGoodsCategoryVo> getSelfGoodsCategoryVos() {
return mongoTemplate.findAll(GoblinSelfGoodsCategoryVo.class, GoblinSelfGoodsCategoryVo.class.getSimpleName());
}
/* ---------------------------------------- 店铺分类数据源 ---------------------------------------- */
public void setStoreGoodsCategoryVos(List<GoblinStoreGoodsCategoryVo> vos) {
mongoTemplate.insert(vos, GoblinStoreGoodsCategoryVo.class.getSimpleName());
}
public boolean updateStoreGoodsCategoryVo(GoblinStoreGoodsCategoryVo vo) {
return mongoTemplate.getCollection(GoblinStoreGoodsCategoryVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("storeId").is(vo.getStoreId()).and("cateId").is(vo.getCateId())).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
public List<GoblinStoreGoodsCategoryVo> getStoreGoodsCategoryVos(String storeId) {
return mongoTemplate.find(Query.query(Criteria.where("storeId").is(storeId)),
GoblinStoreGoodsCategoryVo.class, GoblinStoreGoodsCategoryVo.class.getSimpleName());
}
/* ---------------------------------------- 平台分类规格数据源 ---------------------------------------- */
public void setCategorySpecVo(GoblinMgtCategorySpecVo vo) {
mongoTemplate.insert(vo, GoblinMgtCategorySpecVo.class.getSimpleName());
}
public boolean updateCategorySpecVo(GoblinMgtCategorySpecVo vo) {
return mongoTemplate.getCollection(GoblinMgtCategorySpecVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("cateId").is(vo.getCateId())).getQueryObject(),
Update.update("specNameList", vo.getSpecNameList()).getUpdateObject()
).getModifiedCount() > 0;
}
public GoblinMgtCategorySpecVo getCategorySpecVo(String cateId) {
return mongoTemplate.findOne(Query.query(Criteria.where("cateId").is(cateId)),
GoblinMgtCategorySpecVo.class, GoblinMgtCategorySpecVo.class.getSimpleName());
}
/* ---------------------------------------- 标签数据源 ---------------------------------------- */
public List<GoblinSelfTagVo> getSelfTagVos(String keyword, String belong, Object[] typeRange) {
Criteria criteria = Criteria.where("delFlg").is("0").and("tagBelong").is(belong);
if (StringUtils.isNotBlank(keyword)) {
criteria.and("tagName").regex("^.*" + keyword + ".*$");
}
if (belong.equals("1")) {
criteria.and("tagType").in(typeRange);
}
return mongoTemplate.find(Query.query(criteria).skip(0).limit(20), GoblinSelfTagVo.class, GoblinSelfTagVo.class.getSimpleName());
}
/**
* 标签全量数据
*
* @param belong 标签所属[0-普通标签|1-专属标签]
* @return List<GoblinSelfTagVo>
*/
public List<GoblinSelfTagVo> getSelfTagVos(String belong) {
return mongoTemplate.find(Query.query(Criteria.where("delFlg").is("0").and("tagBelong").is(belong)),
GoblinSelfTagVo.class, GoblinSelfTagVo.class.getSimpleName());
}
public List<GoblinSelfTagVo> getMgtSelfTagVos(List<String> tagIds) {
if (CollectionUtils.isEmpty(tagIds)) return ObjectUtil.getGoblinSelfTagVoArrayList();
return mongoTemplate.find(Query.query(Criteria.where("delFlg").is("0")),
GoblinSelfTagVo.class, GoblinSelfTagVo.class.getSimpleName());
}
// public List<GoblinGoodsTagVo> getGoodsTagVos(List<String> tagIds) {
// if (CollectionUtils.isEmpty(tagIds)) return ObjectUtil.getGoblinGoodsTagVoArrayList();
//
// return null;
// }
//
// public List<GoblinGoodsExtagVo> getGoodsExtagVos(List<String> tagIds) {
// if (CollectionUtils.isEmpty(tagIds)) return ObjectUtil.getGoblinGoodsExtagVoArrayList();
//
// return null;
// }
/* ---------------------------------------- 服务保障数据源 ---------------------------------------- */
public List<GoblinServiceSupportVo> getServiceSupportVos(List<String> ssids) {
if (CollectionUtils.isEmpty(ssids)) return ObjectUtil.getGoblinServiceSupportVoArrayList();
return mongoTemplate.find(Query.query(Criteria.where("ssid").in(ssids)),
GoblinServiceSupportVo.class, GoblinServiceSupportVo.class.getSimpleName());
}
public List<GoblinServiceSupportVo> getMgtServiceSupportVos() {
return mongoTemplate.findAll(GoblinServiceSupportVo.class, GoblinServiceSupportVo.class.getSimpleName());
}
public List<GoblinServiceSupportVo> insertMgtServiceSupportVos(List<GoblinServiceSupportVo> vos) {
return (List<GoblinServiceSupportVo>) mongoTemplate.insert(vos, GoblinServiceSupportVo.class.getSimpleName());
}
/* ---------------------------------------- 店铺公告数据源 ---------------------------------------- */
public PagedResult<GoblinStoreNoticeVo> getStoreNoticeVos(GoblinStoreMgtNoticeFilterParam filterParam) {
Criteria criteria = Criteria.where("storeId").is(filterParam.getStoreId()).and("delFlg").is("0");
if (StringUtils.isNotBlank(filterParam.getKeyword())) {
Pattern pattern = Pattern.compile("^.*" + filterParam.getKeyword() + ".*$", Pattern.CASE_INSENSITIVE);
criteria.and("content").regex(pattern);
}
Query query = Query.query(criteria);
long count = mongoTemplate.count(query, GoblinStoreNoticeVo.class.getSimpleName());
PagedResult<GoblinStoreNoticeVo> pagedResult = ObjectUtil.getGoblinStoreNoticeVoPagedResult();
if (count <= 0) return pagedResult;
query.with(PageRequest.of(filterParam.getPageNum() - 1, filterParam.getPageSize()));
query.with(Sort.by(Sort.Order.desc("createdAt")));
List<GoblinStoreNoticeVo> storeNoticeVos = mongoTemplate.find(query, GoblinStoreNoticeVo.class, GoblinStoreNoticeVo.class.getSimpleName());
return pagedResult.setList(storeNoticeVos).setTotal(count, filterParam.getPageSize());
}
/**
* 查取指定店铺有效的公告通知
*
* @param storeId 店铺ID
* @return List<GoblinStoreNoticeVo>
*/
public List<GoblinStoreNoticeVo> getStoreNoticeVos(String storeId, LocalDateTime nowTime) {
return mongoTemplate.find(Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0")
.orOperator(
Criteria.where("releaseTime").gte(nowTime),
Criteria.where("longLasting").is("0").and("cancellTime").gte(nowTime),
Criteria.where("longLasting").is("1")
)
).with(Sort.by(Sort.Order.asc("releaseTime"), Sort.Order.asc("createdAt"))),
GoblinStoreNoticeVo.class, GoblinStoreNoticeVo.class.getSimpleName());
}
public void setStoreNoticeVo(GoblinStoreNoticeVo vo) {
mongoTemplate.insert(vo, GoblinStoreNoticeVo.class.getSimpleName());
}
public boolean updateStoreNoticeVo(GoblinStoreNoticeVo vo) {
return mongoTemplate.getCollection(GoblinStoreNoticeVo.class.getSimpleName())
.updateOne(
Query.query(Criteria.where("storeId").is(vo.getStoreId()).and("delFlg").is("0").and("noticeId").is(vo.getNoticeId())).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
public boolean updateStoreNoticeVoByBulk(List<GoblinStoreNoticeVo> vos) {
List<WriteModel<Document>> list = ObjectUtil.getWriteModelDocumentArrayList();
vos.forEach(r -> {
if (StringUtils.isNotEmpty(r.getStoreId())) {
list.add(new UpdateOneModel<>(
Query.query(Criteria.where("storeId").is(r.getStoreId()).and("noticeId").is(r.getNoticeId())).getQueryObject(),
Update.update("releaseTime", r.getReleaseTime()).set("status", r.getStatus()).set("updatedBy", r.getUpdatedBy()).set("updatedAt", r.getUpdatedAt()).getUpdateObject()
));
}
});
return mongoTemplate.getCollection(GoblinStoreNoticeVo.class.getSimpleName()).bulkWrite(list).getModifiedCount() > 0;
}
public boolean updateStoreNoticeVoByRelease(String uid, LocalDateTime nowTime, String storeId, List<String> noticeIdList) {
return mongoTemplate.getCollection(GoblinStoreNoticeVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0").and("noticeId").in(noticeIdList.toArray()).and("status").is("0")).getQueryObject(),
Update.update("status", "1").set("releaseTime", nowTime).set("updatedBy", uid).set("updatedAt", nowTime).getUpdateObject()
).getModifiedCount() > 0;
}
public boolean updateStoreNoticeVoByRemove(String uid, LocalDateTime nowTime, String storeId, List<String> noticeIdList) {
return mongoTemplate.getCollection(GoblinStoreNoticeVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0").and("noticeId").in(noticeIdList.toArray())).getQueryObject(),
Update.update("delFlg", "1").set("updatedBy", uid).set("updatedAt", nowTime).getUpdateObject()
).getModifiedCount() > 0;
}
/* ---------------------------------------- 店铺配置数据源 ---------------------------------------- */
public List<GoblinStoreConfigVo> getStoreConfigVos(String storeId) {
Query query = Query.query(Criteria.where("storeId").is(storeId));
query.fields().include("storeId").include("configKey").include("configVal");
return mongoTemplate.find(query,
GoblinStoreConfigVo.class, GoblinStoreConfigVo.class.getSimpleName());
}
public boolean updateStoreConfigVos(List<GoblinStoreConfigVo> vos) {
List<WriteModel<Document>> list = ObjectUtil.getWriteModelDocumentArrayList();
vos.forEach(r -> {
if (StringUtils.isNotEmpty(r.getStoreId())) {
list.add(new UpdateOneModel<>(
Query.query(Criteria.where("storeId").is(r.getStoreId()).and("configKey").is(r.getConfigKey())).getQueryObject(),
Update.update("configVal", r.getConfigVal()).set("updatedBy", r.getUpdatedBy()).set("updatedAt", r.getUpdatedAt()).getUpdateObject()
));
}
});
return mongoTemplate.getCollection(GoblinStoreConfigVo.class.getSimpleName()).bulkWrite(list).getModifiedCount() > 0;
}
public List<GoblinStoreConfigVo> delStoreConfigVo(String storeId) {
Query query = Query.query(Criteria.where("storeId").is(storeId));
query.fields().include("configKey").include("configVal");
return mongoTemplate.find(query,
GoblinStoreConfigVo.class, GoblinStoreConfigVo.class.getSimpleName());
}
/* ---------------------------------------- 店铺数据源 ---------------------------------------- */
public GoblinStoreInfoVo setStoreInfoVo(GoblinStoreInfoVo vo) {
return mongoTemplate.insert(vo, GoblinStoreInfoVo.class.getSimpleName());
}
public boolean delStoreInfoVo(String storeId, String uid, LocalDateTime time) {
return mongoTemplate.updateFirst(Query.query(Criteria.where("storeId").is(storeId)),
Update.update("delFlg", "1").set("updatedBy", uid).set("updatedAt", time).set("deletedBy", uid).set("deletedAt", time),
GoblinStoreInfoVo.class.getSimpleName()).getModifiedCount() > 0;
}
public boolean updateStoreInfoVo(GoblinStoreInfoVo vo) {
return mongoTemplate.getCollection(GoblinStoreInfoVo.class.getSimpleName())
.updateOne(Query.query(Criteria.where("storeId").is(vo.getStoreId())).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
public GoblinStoreInfoVo getStoreInfoVo(String storeId) {
return mongoTemplate.findOne(Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0")),
GoblinStoreInfoVo.class, GoblinStoreInfoVo.class.getSimpleName());
}
public ArrayList<String> getStoreInfoVoRegexName(String storeName) {
Query query = Query.query(Criteria.where("storeName").regex("^.*" + storeName + ".*$").and("delFlg").is("0").and("status").in("3", "5"));
query.fields().include("storeId");
List<GoblinStoreInfoVo> voList = mongoTemplate.find(query, GoblinStoreInfoVo.class, GoblinStoreInfoVo.class.getSimpleName());
ArrayList<String> list = CollectionUtil.arrayListString();
for (GoblinStoreInfoVo goblinStoreInfoVo : voList) {
list.add(goblinStoreInfoVo.getStoreId());
}
return list;
}
public List<GoblinStoreInfoVo> getStoreInfoVoByUid(String uid) {
// return mongoTemplate.findOne(Query.query(Criteria.where("uid").is(uid).and("delFlg").is("0")),
// GoblinStoreInfoVo.class, GoblinStoreInfoVo.class.getSimpleName());
return mongoTemplate.find(Query.query(Criteria.where("uid").is(uid).and("delFlg").is("0")),
GoblinStoreInfoVo.class, GoblinStoreInfoVo.class.getSimpleName());
}
/* ---------------------------------------- 商品数据源 ---------------------------------------- */
// SPU信息
public GoblinGoodsInfoVo setGoodsInfoVo(GoblinGoodsInfoVo vo) {
return mongoTemplate.insert(vo, GoblinGoodsInfoVo.class.getSimpleName());
}
public void upsertGoodsInfoVo(GoblinGoodsInfoVo vo) {
Document document = (Document) mongoConverter.convertToMongoType(vo);
Update update = Update.fromDocument(document);
mongoTemplate.upsert(Query.query(Criteria.where("storeId").is(vo.getStoreId()).and("spuId").is(vo.getSpuId())), update, GoblinGoodsInfoVo.class.getSimpleName());
}
public boolean delGoodsInfoVo(String spuId) {
return mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("spuId").is(spuId).and("delFlg").is("0")).getQueryObject(),
Update.update("delFlg", "1").getUpdateObject()
).getModifiedCount() > 0;
}
public boolean delGoodsSkuInfoVo(String skuId) {
return mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("skuId").is(skuId).and("delFlg").is("0")).getQueryObject(),
Update.update("delFlg", "1").getUpdateObject()
).getModifiedCount() > 0;
}
public boolean delGoodsInfoVoBySpuIds(String storeId, List<String> spuIdList, String uid, LocalDateTime time) {
return mongoTemplate.updateMulti(
Query.query(Criteria.where("storeId").is(storeId).and("spuId").in(spuIdList).and("delFlg").is("0")),
Update.update("delFlg", "1").set("updatedBy", uid).set("updatedAt", time).set("deletedBy", uid).set("deletedAt", time),
GoblinGoodsInfoVo.class.getSimpleName()
).getModifiedCount() > 0;
}
public List<String> delGoodsInfoVoByStoreId(String storeId, String uid, LocalDateTime time) {
Query query = Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0").and("shelvesStatus").is("3"));
query.fields().include("spuId");
List<GoblinGoodsInfoVo> storeSpus = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
List<String> storeSpuIdList = CollectionUtil.arrayListString();
if (!CollectionUtils.isEmpty(storeSpus)) {
storeSpuIdList = storeSpus.stream().map(GoblinGoodsInfoVo::getSpuId).collect(Collectors.toList());
UpdateResult updateResult = mongoTemplate.updateMulti(Query.query(Criteria.where("spuId").in(storeSpuIdList)),
Update.update("delFlg", "1").set("updatedBy", uid).set("updatedAt", time).set("deletedBy", uid).set("deletedAt", time),
GoblinGoodsInfoVo.class.getSimpleName());
if (updateResult.getModifiedCount() > 0) {
return storeSpuIdList;
}
}
return storeSpuIdList;
}
// SPU分页
public PagedResult<GoblinStoreMgtGoodsListVo> getMgtGoodsInfoVos(GoblinStoreMgtGoodsFilterParam filterParam) {
Criteria criteria = Criteria.where("delFlg").is("0").and("storeId").is(filterParam.getStoreId()).and("marketId").exists(false);
if (StringUtils.isNotBlank(filterParam.getKeyword())) {
Pattern pattern = Pattern.compile("^.*" + filterParam.getKeyword() + ".*$", Pattern.CASE_INSENSITIVE);
criteria.and("name").regex(pattern);
}
if (StringUtils.isNotBlank(filterParam.getShelvesStatus())) {
criteria.and("shelvesStatus").is(filterParam.getShelvesStatus());
}
if (StringUtils.isNotBlank(filterParam.getCateFid())) {
criteria.and("cateFid").is(filterParam.getCateFid());
}
if (StringUtils.isNotBlank(filterParam.getCateSid())) {
criteria.and("cateSid").is(filterParam.getCateSid());
}
if (StringUtils.isNotBlank(filterParam.getCateTid())) {
criteria.and("cateTid").is(filterParam.getCateTid());
}
if (StringUtils.isNotBlank(filterParam.getCreatedDt())) {
LocalDateTime createDt = DateUtil.Formatter.yyyy_MM_dd.parse(filterParam.getCreatedDt());
LocalDateTime createdAtBegin = createDt.withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime createdAtEnd = createDt.withHour(23).withMinute(59).withSecond(59).withNano(999);
criteria.and("createdAt").gte(createdAtBegin).lte(createdAtEnd);
}
if (null != filterParam.getPriceGe()) {
criteria.and("priceGe").gte(filterParam.getPriceGe());
}
if (null != filterParam.getPriceLe()) {
criteria.and("priceLe").lte(filterParam.getPriceLe());
}
Query query = Query.query(criteria);
long count = mongoTemplate.count(query, GoblinGoodsInfoVo.class.getSimpleName());
PagedResult<GoblinStoreMgtGoodsListVo> pagedResult = ObjectUtil.getGoblinStoreMgtGoodsVoPagedResult();
if (count <= 0) return pagedResult;
query.with(PageRequest.of(filterParam.getPageNum() - 1, filterParam.getPageSize()));
query.with(Sort.by(Sort.Order.desc("createdAt")));
List<GoblinStoreMgtGoodsListVo> goodsListVos = mongoTemplate.find(query, GoblinStoreMgtGoodsListVo.class, GoblinGoodsInfoVo.class.getSimpleName());
return pagedResult.setList(goodsListVos).setTotal(count, filterParam.getPageSize());
}
public List<String> getMgtSpuNosForMarketBySpuNos(List<String> spuNos, Object... shelvesStatus) {
Query query = Query.query(Criteria.where("spuNo").in(spuNos.toArray())
.and("marketId").exists(true).and("delFlg").is("0").and("shelvesStatus").in(shelvesStatus));
query.fields().include("spuNo");
List<GoblinGoodsInfoVo> goblinGoodsInfoVos = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
return CollectionUtils.isEmpty(goblinGoodsInfoVos) ? CollectionUtil.arrayListString() : goblinGoodsInfoVos.stream().map(GoblinGoodsInfoVo::getSpuNo).distinct().collect(Collectors.toList());
}
public List<String> getMgtSpuIdsForMarketBySpuNos(List<String> spuNos, Object... shelvesStatus) {
Query query = Query.query(Criteria.where("spuNo").in(spuNos.toArray())
.and("marketId").exists(true).and("delFlg").is("0").and("shelvesStatus").in(shelvesStatus));
query.fields().include("spuId");
List<GoblinGoodsInfoVo> goblinGoodsInfoVos = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
return CollectionUtils.isEmpty(goblinGoodsInfoVos) ? CollectionUtil.arrayListString() : goblinGoodsInfoVos.stream().map(GoblinGoodsInfoVo::getSpuId).distinct().collect(Collectors.toList());
}
// SPU信息
public List<String> getMgtGoodsSpuIds(String storeId) {
Query query = Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0"));
query.fields().include("spuId");
List<GoblinGoodsInfoVo> vos = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
return CollectionUtils.isEmpty(vos) ? CollectionUtil.arrayListString()
: vos.stream().map(GoblinGoodsInfoVo::getSpuId).collect(Collectors.toList());
}
// SPU信息
public GoblinGoodsInfoVo getGoodsInfoVo(String spuId) {
// return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId).and("delFlg").is("0").and("shelvesStatus").is("3")),
// return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId).and("delFlg").is("0")),
return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId)),
GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
}
// SPU信息
// public GoblinGoodsInfoVo getMgtGoodsInfoVo(String spuId) {
// return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId).and("delFlg").is("0")),
// GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
// }
// SPU信息
public GoblinGoodsInfoVo getMgtGoodsInfoVo(String storeId, String name) {
return mongoTemplate.findOne(Query.query(Criteria.where("storeId").is(storeId).and("name").is(name).and("delFlg").is("0")),
GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
}
public long countMgtGoodsInfoVo(String name) {
return mongoTemplate.count(Query.query(Criteria.where("name").is(name).and("delFlg").is("0")),
GoblinGoodsInfoVo.class.getSimpleName());
}
// SPU信息
public boolean updateGoodsInfoVo(GoblinGoodsInfoVo vo) {
return mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("spuId").is(vo.getSpuId()).and("delFlg").is("0")).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
// SPU活动商品信息更新
public List<String> updateGoodsInfoVoForMarket(String spuId, String spuNo, GoblinGoodsInfoVo vo) {
Query query = Query.query(Criteria.where("spuNo").is(spuNo).and("delFlg").is("0").and("spuId").ne(spuId));
query.fields().include("spuId");
List<GoblinGoodsInfoVo> marketGoodsInfoVos = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
if (!CollectionUtils.isEmpty(marketGoodsInfoVos)) {
List<String> marketSpuIds = marketGoodsInfoVos.stream().map(GoblinGoodsInfoVo::getSpuId).collect(Collectors.toList());
mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("spuId").in(marketSpuIds).and("delFlg").is("0")).getQueryObject(),
Update.update("spuNo", vo.getSpuNo())
.set("name", vo.getName())
.set("subtitle", vo.getSubtitle())
.set("sellPrice", vo.getSellPrice())
.set("intro", vo.getIntro())
.set("details", vo.getDetails())
.set("coverPic", vo.getCoverPic())
.set("video", vo.getVideo())
.set("specMode", "2")
.set("cateFid", vo.getCateFid())
.set("cateSid", vo.getCateSid())
.set("cateTid", vo.getCateTid())
.set("shelvesHandle", vo.getShelvesHandle())
.set("shelvesTime", vo.getShelvesTime())
.set("spuValidity", vo.getSpuValidity())
.set("virtualFlg", vo.getVirtualFlg())
.set("imageList", mongoConverter.convertToMongoType(vo.getImageList()))
.set("logisticsTemplate", vo.getLogisticsTemplate())
.set("tagVoList", mongoConverter.convertToMongoType(vo.getTagVoList()))
.set("extagVoList", mongoConverter.convertToMongoType(vo.getExtagVoList()))
.set("artagVoList", mongoConverter.convertToMongoType(vo.getArtagVoList()))
.set("serviceSupportVoList", mongoConverter.convertToMongoType(vo.getServiceSupportVoList()))
.set("updatedBy", vo.getUpdatedBy())
.set("updatedAt", vo.getUpdatedAt())
.getUpdateObject()
);
return marketSpuIds;
}
return null;
}
// SPU信息
public boolean updateGoodsInfoVoAppear(String storeId, String spuAppear, LocalDateTime time, String uid) {
return mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0")).getQueryObject(),
Update.update("spuAppear", spuAppear).set("updatedBy", uid).set("updatedAt", time).getUpdateObject()
).getModifiedCount() > 0;
}
public boolean updateGoodsInfoVoByShelves(String storeId, List<String> spuIdList, boolean shelvesFlg, String uid, LocalDateTime time) {
return mongoTemplate.updateMulti(Query.query(Criteria.where("storeId").is(storeId).and("spuId").in(spuIdList.toArray())),
Update.update("shelvesStatus", shelvesFlg ? "3" : "1").set("shelvesAt", time).set("updatedBy", uid).set("updatedAt", time),
GoblinGoodsInfoVo.class.getSimpleName()).getModifiedCount() > 0;
}
// SKU信息
public GoblinGoodsSkuInfoVo setGoodsSkuInfoVo(GoblinGoodsSkuInfoVo vo) {
return mongoTemplate.insert(vo, GoblinGoodsSkuInfoVo.class.getSimpleName());
}
public UpdateResult upsertGoodsSkuInfoVo(GoblinGoodsSkuInfoVo vo) {
Document document = (Document) mongoConverter.convertToMongoType(vo);
Update update = Update.fromDocument(document);
Query query = Query.query(Criteria.where("storeId").is(vo.getStoreId()).and("skuId").is(vo.getSkuId()));
UpdateResult result = mongoTemplate.upsert(query, update, GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
return result;
}
// SKU信息
public List<GoblinGoodsSkuInfoVo> setGoodsSkuInfoVos(List<GoblinGoodsSkuInfoVo> vos) {
return (List<GoblinGoodsSkuInfoVo>) mongoTemplate.insert(vos, GoblinGoodsSkuInfoVo.class.getSimpleName());
}
public boolean delGoodsSkuInfoVo(GoblinGoodsSkuInfoVo vo, List<String> skuIdList) {
return mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("skuId").in(skuIdList).and("delFlg").is("0")).getQueryObject(),
Update.update("delFlg", "1").set("updatedBy", vo.getUpdatedBy()).set("updatedAt", vo.getUpdatedAt())
.set("deletedBy", vo.getDeletedBy()).set("deletedAt", vo.getDeletedAt()).getUpdateObject()
).getModifiedCount() > 0;
}
public List<String> delGoodsSkuInfoVoByStoreId(String storeId, String uid, LocalDateTime time) {
Query query = Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0").and("shelvesStatus").is("3"));
query.fields().include("skuId");
List<GoblinGoodsSkuInfoVo> storeSkus = mongoTemplate.find(query, GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
List<String> storeSkuIdList = CollectionUtil.arrayListString();
if (!CollectionUtils.isEmpty(storeSkus)) {
storeSkuIdList = storeSkus.stream().map(GoblinGoodsSkuInfoVo::getSkuId).collect(Collectors.toList());
UpdateResult updateResult = mongoTemplate.updateMulti(Query.query(Criteria.where("skuId").in(storeSkuIdList)),
Update.update("delFlg", "1").set("updatedBy", uid).set("updatedAt", time).set("deletedBy", uid).set("deletedAt", time),
GoblinGoodsSkuInfoVo.class.getSimpleName());
if (updateResult.getModifiedCount() > 0) {
return storeSkuIdList;
}
}
return storeSkuIdList;
}
// SKU信息
public GoblinGoodsSkuInfoVo getGoodsSkuInfoVo(String skuId) {
// return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId).and("delFlg").is("0").and("shelvesStatus").is("3")),
// return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId).and("delFlg").is("0")),
return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId)),
GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
}
public List<GoblinGoodsSkuInfoVo> getGoodsSkuInfoVos(List<String> skuIds) {
return mongoTemplate.find(Query.query(Criteria.where("skuId").in(skuIds)),
GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
}
// SKU信息
public List<String> getMgtGoodsSkuIds(String storeId, List<String> spuIdList) {
Query query = Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0").and("spuId").in(spuIdList.toArray()));
query.fields().include("skuId");
List<GoblinGoodsSkuInfoVo> vos = mongoTemplate.find(query, GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
return CollectionUtils.isEmpty(vos) ? CollectionUtil.arrayListString()
: vos.stream().map(GoblinGoodsSkuInfoVo::getSkuId).collect(Collectors.toList());
}
// SKU信息
// public GoblinGoodsSkuInfoVo getMgtGoodsSkuInfoVo(String skuId) {
// return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId).and("delFlg").is("0")),
// GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
// }
// SKU信息
public boolean updateGoodsSkuInfoVo(GoblinGoodsSkuInfoVo vo) {
return mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName())
.updateOne(
Query.query(Criteria.where("skuId").is(vo.getSkuId()).and("delFlg").is("0")).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
// SKU活动商品信息更新
public boolean updateGoodsSkuInfoVoForMarket(List<String> skuIds, GoblinGoodsSkuInfoVo vo) {
return mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("skuId").in(skuIds).and("delFlg").is("0")).getQueryObject(),
Update.update("name", vo.getName())
.set("skuPic", vo.getSkuPic())
.set("skuSpecList", mongoConverter.convertToMongoType(vo.getSkuSpecList()))
.set("sellPrice", vo.getSellPrice())
// .set("price", vo.getPrice())
// .set("priceMember", vo.getPriceMember())
.set("weight", vo.getWeight())
.set("stock", vo.getStock())
// .set("skuStock", vo.getSkuStock())
.set("warningStock", vo.getWarningStock())
.set("skuAppear", vo.getSkuAppear())
.set("skuIsbn", vo.getSkuIsbn())
// .set("buyFactor", vo.getBuyFactor())
// .set("buyRoster", vo.getBuyRoster())
// .set("buyLimit", vo.getBuyLimit())
.set("skuValidity", vo.getSkuValidity())
.set("updatedBy", vo.getUpdatedBy())
.set("updatedAt", vo.getUpdatedAt())
.getUpdateObject()
).getModifiedCount() > 0;
}
public boolean updateGoodsSkuInfoVoBySpuId(GoblinGoodsSkuInfoVo vo) {
return mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("spuId").is(vo.getSpuId()).and("delFlg").is("0")).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
public boolean updateGoodsSkuInfoVoByShelves(String storeId, List<String> spuIdList, boolean shelvesFlg, String uid, LocalDateTime time) {
return mongoTemplate.updateMulti(Query.query(Criteria.where("storeId").is(storeId).and("delFlg").is("0").and("spuId").in(spuIdList.toArray())),
Update.update("shelvesStatus", shelvesFlg ? "3" : "1").set("shelvesAt", time).set("updatedBy", uid).set("updatedAt", time),
GoblinGoodsSkuInfoVo.class.getSimpleName()).getModifiedCount() > 0;
}
/* ---------------------------------------- ---------------------------------------- */
/**
* 添加 商铺活动 mongo
*
* @param data
* @return
*/
public GoblinStoreMarketVo insertStoreMarket(GoblinStoreMarketVo data) {
return mongoTemplate.insert(data, GoblinStoreMarketVo.class.getSimpleName());
}
/**
* 修改 商铺活动 mongo
*
* @param marketId
* @param data
* @return
*/
public UpdateResult updateStoreMarket(String marketId, String storeId, GoblinStoreMarketVo data) {
BasicDBObject object = ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(data));
return mongoTemplate.getCollection(GoblinStoreMarketVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("storeMarketId").is(marketId).and("storeId").is(storeId)).getQueryObject(),
object);
}
/**
* 获取 商铺活动 mongo
*
* @param marketId
* @return
*/
public GoblinStoreMarketVo getStoreMarket(String marketId) {
return mongoTemplate.findOne(Query.query(Criteria.where("storeMarketId").is(marketId)), GoblinStoreMarketVo.class, GoblinStoreMarketVo.class.getSimpleName());
}
/**
* 删除 商铺活动 mongo
*
* @param marketId
* @param storeId
* @return
*/
public DeleteResult delStoreMarket(String marketId, String storeId) {
return mongoTemplate.remove(Query.query(Criteria.where("storeMarketId").is(marketId).and("storeId").is(storeId)), GoblinStoreMarketVo.class.getSimpleName());
}
/**
* 获取 商铺活动列表
*
* @param page
* @param purchaseName
* @param status
* @param st
* @param et
* @param ct
* @return
*/
public HashMap<String, Object> getStoreMarketList(int page, String purchaseName, int status, String st, String et, String ct) {
String nowStr = DateUtil.getNowTime();
int size = 40;
HashMap<String, Object> info = CollectionUtil.mapStringObject();
// 排序 分页
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt"));
//条件
Criteria criteria = new Criteria();
if (purchaseName != null) {
criteria = criteria.and("name").regex(".*?\\" + purchaseName);
}
if (st != null && et != null) {
criteria = criteria.and("endTime").lte(et).and("startTime").gte(st);
}
if (ct != null) {
criteria = criteria.and("createdAt").regex(".*?\\" + ct);
}
switch (status) {
case 0:
criteria = criteria.and("startTime").gte(nowStr);
break;
case 1:
criteria = criteria.and("endTime").gte(nowStr).and("startTime").lte(nowStr);
break;
case 2:
criteria = criteria.and("endTime").lte(nowStr);
break;
case 7:
criteria = criteria.and("status").lte(7);
break;
}
Query query = Query.query(criteria);
// 查询总数
long count = mongoTemplate.count(query, GoblinStoreMarketVo.class, GoblinStoreMarketVo.class.getSimpleName());
query.with(pageable);
List<GoblinStoreMarketVo> voList = mongoTemplate.find(query, GoblinStoreMarketVo.class, GoblinStoreMarketVo.class.getSimpleName());
info.put("total", count);
info.put("data", voList);
return info;
}
//获取全部正在下单的活动
public List<GoblinSelfMarketingVo> getGoblinSelfMarketingVoList() {
String nowStr = DateUtil.getNowTime();
List<GoblinSelfMarketingVo> voList = mongoTemplate.find(Query.query(Criteria.where("type").is(2).and("status").ne(7).and("endTime").gte(nowStr).and("startTime").lte(nowStr)), GoblinSelfMarketingVo.class, GoblinSelfMarketingVo.class.getSimpleName());
return voList;
}
//添加 订单vo全量
public GoblinStoreOrderVo insertGoblinStoreOrderVo(GoblinStoreOrderVo vo) {
return mongoTemplate.insert(vo, GoblinStoreOrderVo.class.getSimpleName());
}
public UpdateResult updateGoblinStoreOrderVo(String orderId, GoblinStoreOrderVo data) {
BasicDBObject object = ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(data));
return mongoTemplate.getCollection(GoblinStoreOrderVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderId").is(orderId)).getQueryObject(),
object);
}
//添加 订单SkuVo全量
public GoblinOrderSkuVo insertGoblinOrderSkuVo(GoblinOrderSkuVo vo) {
return mongoTemplate.insert(vo, GoblinOrderSkuVo.class.getSimpleName());
}
public UpdateResult updateGoblinOrderSkuVo(String orderSkuId, GoblinOrderSkuVo data) {
BasicDBObject object = ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(data));
return mongoTemplate.getCollection(GoblinOrderSkuVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderSkuId").is(orderSkuId)).getQueryObject(),
object);
}
//添加 订单SkuVo全量
public GoblinMailVo insertGoblinMailVo(GoblinMailVo vo) {
return mongoTemplate.insert(vo, GoblinMailVo.class.getSimpleName());
}
public UpdateResult updateGoblinMailVo(String mailId, GoblinMailVo data) {
BasicDBObject object = ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(data));
return mongoTemplate.getCollection(GoblinMailVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("mailId").is(mailId)).getQueryObject(),
object);
}
//添加 操作日志
public GoblinOrderLogVo insertGoblinOrderLogVo(GoblinOrderLogVo vo) {
return mongoTemplate.insert(vo, GoblinOrderLogVo.class.getSimpleName());
}
//添加 订单退款数据
public GoblinBackOrderVo insertGoblinBackOrderVo(GoblinBackOrderVo vo) {
return mongoTemplate.insert(vo, GoblinBackOrderVo.class.getSimpleName());
}
//修改 订单退款数据
public UpdateResult updateGoblinBackOrderVo(String backOrderId, GoblinBackOrderVo data) {
BasicDBObject object = ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(data));
return mongoTemplate.getCollection(GoblinBackOrderVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("backOrderId").is(backOrderId)).getQueryObject(),
object);
}
//获取 订单退款数据根据orderCode
public GoblinBackOrderVo getGoblinBackOrderVoByBackCode(String backCode) {
return mongoTemplate.findOne(Query.query(Criteria.where("backCode").is(backCode)), GoblinBackOrderVo.class, GoblinBackOrderVo.class.getSimpleName());
}
//获取 正在下单活动内容列表
public List<GoblinGoodsInfoVo> marketSpuList(String marketId, String storeId, int start, int skip) {
List<GoblinGoodsInfoVo> list = mongoTemplate.find(Query.query(Criteria.where("storeId").is(storeId).and("marketId").is("ZZ" + marketId).and("delFlg").is("0").and("shelvesStatus").is("3")).with(Sort.by(Sort.Order.desc("createdAt"))).skip(start).limit(skip), GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
return list;
}
//店铺总收入
public String storeMoney(String storeId, String spuId) {
String spuName = "店铺总收入";
Criteria criteria = Criteria.where("status").in(GoblinStatusConst.Status.ORDER_LOG_STATUS_11.getValue(), GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue(), GoblinStatusConst.Status.ORDER_LOG_STATUS_28.getValue()).and("storeId").is(storeId);
Aggregation aggregation;
if (spuId != null) {
criteria = criteria.and("spuId").is(spuId);
Query query = Query.query(Criteria.where("spuId").is(spuId));
query.fields().include("name");
GoblinGoodsInfoVo spuIdAndName = mongoTemplate.findOne(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
if (spuIdAndName == null) {
return "," + BigDecimal.ZERO;
} else {
spuName = spuIdAndName.getName();
}
aggregation = Aggregation.newAggregation(
Aggregation.match(criteria),
Aggregation.group("spuId")
.first("spuId").as("spuId")
.sum("skuPriceActual").as("skuPriceActual"));
// aggregation = Aggregation.newAggregation(
// Aggregation.match(criteria),
// Aggregation.project("spuId", "skuPriceActual"),
// Aggregation.group("spuId")
// .first("spuId").as("spuId")
// .sum("skuPriceActual").as("skuPriceActual")
// );
} else {
aggregation = Aggregation.newAggregation(
Aggregation.match(criteria),
Aggregation.group("storeId")
.first("storeId").as("storeId")
.sum("skuPriceActual").as("skuPriceActual"));
}
AggregationResults<GoblinOrderLogVo> outputType = mongoTemplate.aggregate(aggregation, GoblinOrderLogVo.class.getSimpleName(), GoblinOrderLogVo.class);
List<GoblinOrderLogVo> dataList = new ArrayList(outputType.getMappedResults());
if (dataList.size() > 0) {
return spuName + "," + dataList.get(0).getSkuPriceActualBig();
} else {
return "," + BigDecimal.ZERO;
}
}
//资金列表
public HashMap<String, Object> moneyGetSpuList(String spuName, String st, String et, String storeId, int page) {
//查询销量
int size = 20;
int skipCount = ((page - 1) * size);
int finalCount = skipCount + size;
List<GoblinGoodsInfoVo> spuIdAndName = null;
Criteria criteria = Criteria.where("status").in(GoblinStatusConst.Status.ORDER_LOG_STATUS_11.getValue(), GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue(), GoblinStatusConst.Status.ORDER_LOG_STATUS_28.getValue()).and("storeId").is(storeId);
if (st != null && et != null) {
criteria = criteria.and("createdAt").gte(st).lt(et);
}
//查询总数量
Query countQuery = Query.query(criteria);
countQuery.fields().include("spuId");
List<GoblinOrderLogVo> countList = mongoTemplate.find(countQuery, GoblinOrderLogVo.class, GoblinOrderLogVo.class.getSimpleName());
List<String> spuIdList = countList.stream().map(GoblinOrderLogVo::getSpuId).distinct().collect(Collectors.toList());
long total = spuIdList.size();
if (finalCount > total) {
finalCount = (int) total - 1;
}
if (spuName != null) {
//根据spu名称查询spuId
Query query = Query.query(Criteria.where("name").regex(".*?" + spuName + ".*").and("storeId").is(storeId));
query.fields().include("spuId").include("name");
spuIdAndName = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
spuIdList = spuIdAndName.stream().map(GoblinGoodsInfoVo::getSpuId).collect(Collectors.toList());
if (finalCount > spuIdList.size()) {
finalCount = spuIdList.size();
}
}
if(finalCount>0){
spuIdList = spuIdList.subList(skipCount, finalCount);
}
criteria = criteria.and("spuId").in(spuIdList);
//查询聚合数据
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(criteria),
Aggregation.project("spuId", "skuPriceActual"),
Aggregation.group("spuId")
.first("spuId").as("spuId")
.sum("skuPriceActual").as("skuPriceActual")
);
AggregationResults<GoblinOrderLogVo> outputType = mongoTemplate.aggregate(aggregation, GoblinOrderLogVo.class.getSimpleName(), GoblinOrderLogVo.class);
List<GoblinOrderLogVo> dataList = new ArrayList(outputType.getMappedResults());
if (spuIdAndName == null) {
Query query = Query.query(Criteria.where("spuId").in(dataList.stream().map(GoblinOrderLogVo::getSpuId).collect(Collectors.toList())));
query.fields().include("spuId").include("name");
spuIdAndName = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
}
//处理数据
for (GoblinOrderLogVo item : dataList) {
for (GoblinGoodsInfoVo item2 : spuIdAndName) {
if (item.getSpuId().equals(item2.getSpuId())) {
item.setSpuName(item2.getName());
break;
}
}
}
HashMap<String, Object> map = CollectionUtil.mapStringObject();
map.put("data", dataList);
map.put("total", total);
return map;
}
//商品订单操作日志列表
public HashMap<String, Object> moneyGetSpuDetails(String spuId, String orderCode, Integer type, String st, String et, int page) {
//查询销量
int size = 20;
int skipCount = ((page - 1) * size);
Criteria criteria = Criteria.where("spuId").is(spuId);
if (st != null && et != null) {
criteria = criteria.and("createdAt").gte(st).lt(et);
}
if (orderCode != null) {
criteria = criteria.and("orderCode").is(orderCode);
}
if (type != null) {
switch (type) {
case 1:
criteria = criteria.and("orderType").is("order").and("status").is(11);
break;
case 2:
criteria = criteria.and("orderType").is("order").and("status").in(22, 28);
break;
case 3:
criteria = criteria.and("orderType").is("zhengzai").and("status").is(11);
break;
case 4:
criteria = criteria.and("orderType").is("zhengzai").and("status").in(22, 28);
break;
}
}else{
criteria = criteria.and("status").in(
GoblinStatusConst.Status.ORDER_LOG_STATUS_11.getValue(),
GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue(),
GoblinStatusConst.Status.ORDER_LOG_STATUS_28.getValue()
);
}
Query query = Query.query(criteria);
query.skip(skipCount).limit(size);
List<GoblinOrderLogVo> dataList = mongoTemplate.find(query, GoblinOrderLogVo.class, GoblinOrderLogVo.class.getSimpleName());
//查询总数量
Query countQuery = Query.query(criteria);
countQuery.fields().include("spuId");
List<GoblinOrderLogVo> countList = mongoTemplate.find(countQuery, GoblinOrderLogVo.class, GoblinOrderLogVo.class.getSimpleName());
long total = countList.size();
HashMap<String, Object> map = CollectionUtil.mapStringObject();
map.put("data", dataList);
map.put("total", total);
return map;
}
//商品订单列表
public HashMap<String, Object> storeOrderList(String storeId, Integer page, String orderCode, String cst, String cet, String expressContacts, String phone, Integer status) {
//查询销量
int size = 20;
int skipCount = ((page - 1) * size);
Criteria criteria = Criteria.where("storeId").is(storeId);
if (cst != null && cet != null) {
criteria = criteria.and("createdAt").gte(cst).lt(cet);
}
if (orderCode != null) {
criteria = criteria.and("orderCode").is(orderCode);
}
if (phone != null) {
criteria = criteria.and("userMobile").is(phone);
}
if (status != null) {
criteria = criteria.and("status").is(status);
}
if (expressContacts != null) {
criteria = criteria.and("orderAttrVo.expressContacts").is(expressContacts);
}
Query query = Query.query(criteria);
query.with(Sort.by(Sort.Order.desc("createdAt")));
query.skip(skipCount).limit(size);
query.fields().include("orderCode").include("createdAt").include("payType").include("status").include("orderSkuVoIds").include("orderId").include("priceActual").include("priceExpress")
.include("orderAttrVo.expressContacts").include("orderAttrVo.expressAddressDetail").include("orderAttrVo.expressAddress").include("orderAttrVo.expressPhone");
List<GoblinStoreOrderVo> dataList = mongoTemplate.find(query, GoblinStoreOrderVo.class, GoblinStoreOrderVo.class.getSimpleName());
//查询总数量
Query countQuery = Query.query(criteria);
countQuery.fields().include("orderCode");
List<GoblinStoreOrderVo> countList = mongoTemplate.find(countQuery, GoblinStoreOrderVo.class, GoblinStoreOrderVo.class.getSimpleName());
long total = countList.size();
HashMap<String, Object> map = CollectionUtil.mapStringObject();
map.put("data", dataList);
map.put("total", total);
return map;
}
//商品退款订单列表
public HashMap<String, Object> storeBackOrderList(String storeId, Integer page, String orderBackCode, Integer type, String cst, String cet, String orderCode, String spuName, Integer status) {
//查询销量
int size = 20;
int skipCount = ((page - 1) * size);
Criteria criteria = Criteria.where("storeId").is(storeId);
if (cst != null && cet != null) {
criteria = criteria.and("createdAt").gte(cst).lt(cet);
}
if (orderCode != null) {
criteria = criteria.and("orderCode").is(orderCode);
}
if (orderBackCode != null) {
criteria = criteria.and("backCode").is(orderBackCode);
}
if (status != null) {
criteria = criteria.and("status").is(status);
}
if (type != null) {
criteria = criteria.and("type").is(type);
}
if (spuName != null) {
criteria = criteria.and("backOrderSkuVos.spuName").regex(".*?\\" + spuName);
}
Query query = Query.query(criteria);
query.skip(skipCount).limit(size).with(Sort.by(Sort.Order.desc("createdAt")));
;
query.fields().include("backCode").include("orderCode").include("backOrderId").include("type").include("status").include("realBackPrice").include("createdAt")
.include("backOrderSkuVos.spuName").include("backOrderSkuVos.skuName").include("backOrderSkuVos.spuPic").include("backOrderSkuVos.skuPic")
.include("backOrderSkuVos.skuSpecs").include("backOrderSkuVos.skuId").include("backOrderSkuVos.spuId").include("backOrderSkuVos.orderSkuId")
.include("backOrderSkuVos.refundPrice");
List<GoblinBackOrderVo> dataList = mongoTemplate.find(query, GoblinBackOrderVo.class, GoblinBackOrderVo.class.getSimpleName());
//查询总数量
Query countQuery = Query.query(criteria);
countQuery.fields().include("orderCode");
List<GoblinBackOrderVo> countList = mongoTemplate.find(countQuery, GoblinBackOrderVo.class, GoblinBackOrderVo.class.getSimpleName());
long total = countList.size();
HashMap<String, Object> map = CollectionUtil.mapStringObject();
map.put("data", dataList);
map.put("total", total);
return map;
}
//商户 正在下单列表
public List<GoblinStoreOrderVo> storeZhengzaiOrderList(int page, String storeId) {
//查询销量
int size = 40;
int skipCount = ((page - 1) * size);
Criteria criteria = Criteria.where("storeId").is(storeId).and("marketType").is(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue());
Query query = Query.query(criteria);
query.skip(skipCount).limit(size).with(Sort.by(Sort.Order.desc("createdAt")));
return mongoTemplate.find(query, GoblinStoreOrderVo.class, GoblinStoreOrderVo.class.getSimpleName());
}
public List<GoblinFrontBanner> getListBanner() {
Query query = Query.query(Criteria.where("delTag").is(0).and("bannerType").is(1));
return mongoTemplate.find(query,
GoblinFrontBanner.class, GoblinFrontBanner.class.getSimpleName());
}
public List<GoblinFrontBanner> getMiddleBanner() {
Query query = Query.query(Criteria.where("delTag").is(0).and("bannerType").is(2));
return mongoTemplate.find(query,
GoblinFrontBanner.class, GoblinFrontBanner.class.getSimpleName());
}
public List<GoblinFrontHotWord> getHotWord() {
Query query = Query.query(Criteria.where("delTag").is(0));
return mongoTemplate.find(query,
GoblinFrontHotWord.class, GoblinFrontHotWord.class.getSimpleName());
}
public List<GoblinFrontNavigation> getNavigation() {
Query query = Query.query(Criteria.where("delTag").is(0));
query.with(Sort.by(Sort.Order.asc("indexs")));
return mongoTemplate.find(query,
GoblinFrontNavigation.class, GoblinFrontNavigation.class.getSimpleName());
}
/* ---------------------------------------- 商铺活动:优惠券 ---------------------------------------- */
public GoblinStoreCouponBasicVo setMgtStoreCouponBasicVo(GoblinStoreCouponBasicVo vo) {
return mongoTemplate.insert(vo, GoblinStoreCouponBasicVo.class.getSimpleName());
}
public boolean updateMgtStoreCouponBasicVo(GoblinStoreCouponBasicVo vo) {
return mongoTemplate.getCollection(GoblinStoreCouponBasicVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("storeCouponId").is(vo.getStoreCouponId()).and("delFlg").is("0")).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
public boolean activityMgtStoreCouponBasicVo(String uid, LocalDateTime time, String state, List<String> storeCouponIds) {
return mongoTemplate.getCollection(GoblinStoreCouponBasicVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("storeCouponId").in(storeCouponIds).and("delFlg").is("0")).getQueryObject(),
Update.update("state", state).set("updatedBy", uid).set("updatedAt", time).getUpdateObject()
).getModifiedCount() > 0;
}
public boolean updateMgtStoreCouponStock(String storeCouponId, int stock, String uid, LocalDateTime time) {
return mongoTemplate.getCollection(GoblinStoreCouponBasicVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("storeCouponId").is(storeCouponId).and("delFlg").is("0")).getQueryObject(),
Update.update("stock", stock).set("updatedBy", uid).set("updatedAt", time).getUpdateObject()
).getModifiedCount() > 0;
}
public boolean delMgtStoreCouponBasicVo(String storeCouponId, String uid, LocalDateTime time) {
return mongoTemplate.updateFirst(
Query.query(Criteria.where("storeCouponId").is(storeCouponId).and("delFlg").is("0")),
Update.update("delFlg", "1").set("deletedBy", uid).set("deletedAt", time),
GoblinStoreCouponBasicVo.class.getSimpleName()
).getModifiedCount() > 0;
}
public boolean delMgtStoreCouponBasicVos(List<String> storeCouponIds, String uid, LocalDateTime time) {
return mongoTemplate.updateFirst(
Query.query(Criteria.where("storeCouponId").in(storeCouponIds).and("delFlg").is("0")),
Update.update("delFlg", "1").set("deletedBy", uid).set("deletedAt", time),
GoblinStoreCouponBasicVo.class.getSimpleName()
).getModifiedCount() > 0;
}
public GoblinStoreCouponBasicVo getMgtStoreCouponBasicVo(String storeCouponId) {
return mongoTemplate.findOne(
Query.query(Criteria.where("storeCouponId").is(storeCouponId).and("delFlg").is("0")),
GoblinStoreCouponBasicVo.class, GoblinStoreCouponBasicVo.class.getSimpleName()
);
}
public GoblinStoreCouponVo getStoreCouponVo(String storeCouponId) {
return mongoTemplate.findOne(
Query.query(Criteria.where("storeCouponId").is(storeCouponId).and("delFlg").is("0")),
GoblinStoreCouponVo.class, GoblinStoreCouponBasicVo.class.getSimpleName()
);
}
public PagedResult<GoblinStoreMgtCouponListVo> getMgtStoreCouponListVos(GoblinStoreMgtCouponFilterParam filterParam) {
Criteria criteria = Criteria.where("delFlg").is("0").and("storeId").is(filterParam.getStoreId());
if (StringUtils.isNotBlank(filterParam.getKeyword())) {
Pattern pattern = Pattern.compile("^.*" + filterParam.getKeyword() + ".*$", Pattern.CASE_INSENSITIVE);
criteria.and("title").regex(pattern);
}
if (StringUtils.isNotBlank(filterParam.getStoreCouponNo())) {
criteria.and("storeCouponNo").is(filterParam.getStoreCouponNo());
}
if (StringUtils.isNotBlank(filterParam.getState())) {
criteria.and("state").is(filterParam.getState());
}
if (StringUtils.isNotBlank(filterParam.getStartTime())) {
LocalDateTime startTime = DateUtil.Formatter.yyyyMMddHHmmss.parse(filterParam.getStartTime());
LocalDateTime startTimeBegin = startTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
criteria.and("startTime").gte(startTimeBegin);
}
if (StringUtils.isNotBlank(filterParam.getEndTime())) {
LocalDateTime endTime = DateUtil.Formatter.yyyyMMddHHmmss.parse(filterParam.getEndTime());
LocalDateTime endTimeEnd = endTime.withHour(23).withMinute(59).withSecond(59).withNano(999);
criteria.and("endTime").gte(endTimeEnd);
}
if (StringUtils.isNotBlank(filterParam.getCreatedDt())) {
LocalDateTime createdAtBegin = DateUtil.Formatter.yyyyMMddHHmmss.parse(filterParam.getCreatedDt() + " 00:00:00");
LocalDateTime createdAtEnd = createdAtBegin.withHour(23).withMinute(59).withSecond(59).withNano(999);
criteria.and("createdAt").gte(createdAtBegin).lte(createdAtEnd);
}
Query query = Query.query(criteria);
long count = mongoTemplate.count(query, GoblinStoreCouponBasicVo.class.getSimpleName());
PagedResult<GoblinStoreMgtCouponListVo> pagedResult = ObjectUtil.getGoblinStoreMgtCouponListVoPagedResult();
if (count <= 0) return pagedResult;
query.with(PageRequest.of(filterParam.getPageNum() - 1, filterParam.getPageSize()));
query.with(Sort.by(Sort.Order.desc("createdAt")));
List<GoblinStoreMgtCouponListVo> mgtCouponListVos = mongoTemplate.find(query, GoblinStoreMgtCouponListVo.class, GoblinStoreCouponBasicVo.class.getSimpleName());
return pagedResult.setList(mgtCouponListVos).setTotal(count, filterParam.getPageSize());
}
public List<Document> aggregateMgtUserCoupon(List<String> storeCouponIds) {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.project("storeCouponId", "state", "receiveStock"),
Aggregation.match(Criteria.where("storeCouponId").in(storeCouponIds).and("state").ne(2)),
Aggregation.group("storeCouponId", "state").count().as("totalCount")
);
AggregationResults<Document> aggregationResults = mongoTemplate.aggregate(aggregation, GoblinUserCouponBasicVo.class.getSimpleName(), Document.class);
return aggregationResults.getMappedResults();
}
//根据艺人标签和演出查询商品
public List<GoblinGoodsInfoVo> getMusicTagPGoods(String musicTag, String performanceId) {
Query query = Query.query(Criteria.where("extagVoList.tagName").is(musicTag)
.and("delFlg").is("0").and("shelvesStatus").is("3"));
return mongoTemplate.find(query,
GoblinGoodsInfoVo.class,
GoblinGoodsInfoVo.class.getSimpleName()
);
}
//获取退款sku订单价格
public BigDecimal getRefundOrderSkuVoPrice(String orderSkuId) {
BigDecimal refundPrice = BigDecimal.ZERO;
List<GoblinBackOrderVo> backOrderVos = mongoTemplate.find(Query.query(Criteria.where("backOrderSkuVos.orderSkuId").is(orderSkuId).and("status").nin(3, 5, 9)),
GoblinBackOrderVo.class, GoblinBackOrderVo.class.getSimpleName());
for (GoblinBackOrderVo vo : backOrderVos) {
for (GoblinBackOrderSkuVo orderSkuVo : vo.getBackOrderSkuVos()) {
refundPrice = refundPrice.add(orderSkuVo.getRefundPrice());
}
}
return refundPrice;
}
;
/* ---------------------------------------- 商城:用户优惠券 ---------------------------------------- */
public List<GoblinUserCouponVo> getUserCouponVos(String uid) {
return mongoTemplate.find(Query.query(Criteria.where("uid").is(uid)),
GoblinUserCouponVo.class, GoblinUserCouponBasicVo.class.getSimpleName());
}
public GoblinUserCouponBasicVo insertUserCouponVo(GoblinUserCouponBasicVo vo) {
return mongoTemplate.insert(vo, GoblinUserCouponBasicVo.class.getSimpleName());
}
public Boolean changeCouponVos(String ucouponId, GoblinUserCouponVo vo) {
return mongoTemplate.getCollection(GoblinUserCouponVo.class.getSimpleName())
.updateOne(Query.query(Criteria.where("ucouponId").is(ucouponId)).getQueryObject(),
ObjectUtil.cloneBasicDBObject().append("$set", mongoConverter.convertToMongoType(vo))
).getModifiedCount() > 0;
}
/* ---------------------------------------- ---------------------------------------- */
/* ---------------------------------------- ---------------------------------------- */
}
package com.liquidnet.service.goblin.util;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.adam.dto.vo.AdamRscPolymer01Vo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.candy.param.BackCouponParam;
import com.liquidnet.service.candy.vo.CandyCouponVo;
import com.liquidnet.service.candy.vo.CandyUseResultVo;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
@Component
@Slf4j
public class GoblinOrderUtils {
@Value("${liquidnet.service.adam.url}")
private String adamUrl;
@Value("${liquidnet.service.candy.url}")
private String candyUrl;
@Value("${liquidnet.service.stone.url}")
private String stoneUrl;
@Autowired
GoblinRedisUtils redisUtils;
public AdamRscPolymer01Vo adamAddressEnterMember(String uid, String enterIds, String addressId) {
try {
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Accept", "application/json;charset=UTF-8");
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("addressId", addressId);
params.add("entersIds", enterIds);
params.add("uid", uid);
String resultData = HttpUtil.post(adamUrl + "/adam/rsc/inquire/of_buy_ticket", params, header);
ResponseDto<AdamRscPolymer01Vo> vo = JsonUtils.fromJson(resultData, new TypeReference<ResponseDto<AdamRscPolymer01Vo>>() {
});
if (null != vo.getData()) {
return vo.getData();
} else {
return null;
}
} catch (Exception e) {
log.error("获取用户信息,e:{}", e);
e.printStackTrace();
return null;
}
}
//判断 数量限购
public String judgeOrderLimit(String uid, String skuId, int number, int limitCount) {
int buyCount = redisUtils.getSkuCountByUid(uid, skuId);
if (buyCount + number > limitCount) {
return "已超出限购数量";
} else {
int a = redisUtils.incrSkuCountByUid(uid, skuId, number);
return "";
}
}
//判断指定人群购买
public Boolean judgeOrderRose(Boolean isMember, String skuId, String mobile, int buyFactor) {
Boolean result = false;
switch (buyFactor) {
case 0:
result = true;
break;
case 1:
result = isMember;
break;
case 2:
result = redisUtils.getSkuCanBuyByUid(mobile, skuId);
break;
}
return result;
}
/**
* 使用优惠券
*
* @param uCouponId 券id
* @param content 消费内容
* @param totalPrice 订单总价
* @return
*/
public HashMap<String, Object> useCoupon(String uCouponId, String content, BigDecimal totalPrice, String spuId, String uid) {
HashMap<String, Object> hashMap = CollectionUtil.mapStringObject();
try {
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("uCouponId", uCouponId);
params.add("content", content);
params.add("totalPrice", totalPrice.toString());
params.add("goodId", spuId);
params.add("performanceId", "null");
params.add("timeId", "null");
params.add("ticketId", "null");
params.add("uid", uid);
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Authorization", "Bearer " + CurrentUtil.getToken());
header.add("Accept", "application/json;charset=UTF-8");
log.debug("url=" + candyUrl + "/candy-coupon/use");
String returnData = HttpUtil.post(candyUrl + "/candy-coupon/use", params, header);
ResponseDto<CandyUseResultVo> innerReturnVo = JsonUtils.fromJson(returnData, new TypeReference<ResponseDto<CandyUseResultVo>>() {
});
CandyUseResultVo candyUseResultVo = innerReturnVo.getData();
Integer type = candyUseResultVo.getCouType();
BigDecimal value = candyUseResultVo.getValue();
BigDecimal voucher = BigDecimal.ZERO;
switch (type) {
case -1:
voucher = BigDecimal.valueOf(-1);
break;
case 1:
voucher = voucher.add(value);
break;
case 2:
voucher = voucher.add(value);
break;
case 3:
voucher = voucher.add(totalPrice);
break;
case 4:
voucher = totalPrice.subtract(totalPrice.multiply(value));
break;
default:
voucher = BigDecimal.ZERO;
break;
}
hashMap.put("type", type);
hashMap.put("voucher", voucher.setScale(2, BigDecimal.ROUND_HALF_UP));
return hashMap;
} catch (Exception e) {
log.error("用券ERROR:{}", e);
hashMap.put("type", -1);
hashMap.put("voucher", 0);
return hashMap;
}
}
public void backCoupon(String uCouponId, String uid) {
try {
BackCouponParam param = BackCouponParam.getNew();
param.setuCouponIds(uCouponId);
param.setUid(uid);
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Authorization", "Bearer " + CurrentUtil.getToken());
header.add("Accept", "application/json;charset=UTF-8");
ArrayList<BackCouponParam> params = new ArrayList();
params.add(param);
String jsonString = JSON.toJSONString(params);
String returnData = HttpUtil.postRaw(candyUrl + "/candy-coupon/useBack", jsonString, header);
} catch (Exception e) {
log.error("回退券ERROR:{}", e);
}
}
public CandyCouponVo getCouponDetails(String uCouponId) {
try {
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Authorization", "Bearer " + CurrentUtil.getToken());
header.add("Accept", "application/json;charset=UTF-8");
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("uCouponIds", uCouponId);
String returnData = HttpUtil.post(candyUrl + " /candy-coupon/receive/ListById", params, header);
ResponseDto<CandyCouponVo> innerReturnVo = JsonUtils.fromJson(returnData, new TypeReference<ResponseDto<CandyCouponVo>>() {
});
return innerReturnVo.getData();
} catch (Exception e) {
log.error("回退券ERROR:{}", e);
CandyCouponVo vo = CandyCouponVo.getNew();
vo.setUcouponId(uCouponId);
vo.setTitle("");
return vo;
}
}
public void doTask(String uid, BigDecimal price) {
try {
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Accept", "application/json;charset=UTF-8");
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("score", price.intValue() + "");
params.add("content", "购买商品:");
params.add("uid", uid);
String resultData = HttpUtil.post(stoneUrl + "/user/logs/in2111", params, header);
} catch (Exception e) {
log.error("添加积分失败,e:{}", e);
e.printStackTrace();
}
}
public void desTask(String uid, BigDecimal price) {
try {
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Accept", "application/json;charset=UTF-8");
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("score", price.intValue() + "");
params.add("content", "购买商品:");
params.add("uid", uid);
String resultData = HttpUtil.post(stoneUrl + "/user/logs/de2111", params, header);
} catch (Exception e) {
log.error("添加积分失败,e:{}", e);
e.printStackTrace();
}
}
}
package com.liquidnet.service.goblin.util;
import com.fasterxml.jackson.core.type.TypeReference;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.RandomUtil;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.GoblinStoreMarketDto;
import com.liquidnet.service.goblin.dto.vo.TempCouponVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.entity.GoblinFrontHotWord;
import com.liquidnet.service.goblin.entity.GoblinFrontNavigation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static com.liquidnet.service.goblin.constant.GoblinRedisConst.REDIS_GOBLIN_TEMP_COUPON_MARKET;
@Slf4j
@Component
public class GoblinRedisUtils {
@Autowired
RedisUtil redisUtil;
@Autowired
GoblinMongoUtils goblinMongoUtils;
private int randomMax = 10;
public void del(String... keys) {
redisUtil.del(keys);
}
/* ---------------------------------------- sku库存相关 ---------------------------------------- */
public void setSkuStock(String marketPre, String skuId, Integer stock) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
redisUtil.set(rk, stock);
}
public int getSkuStock(String marketPre, String skuId) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null && !marketPre.equals("null")) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
Object obj = redisUtil.get(rk);
if (obj == null) {
return 0;
} else {
return (int) obj;
}
}
public int incrSkuStock(String marketPre, String skuId, Integer stock) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null && !marketPre.equals("null")) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
return (int) redisUtil.incr(rk, stock);
}
public int decrSkuStock(String marketPre, String skuId, Integer stock) {
String rk = GoblinRedisConst.REAL_STOCK_SKU;
if (marketPre != null && !marketPre.equals("null")) {
rk = rk.concat(marketPre + ":");
}
rk = rk.concat(skuId);
return (int) redisUtil.decr(rk, stock);
}
//添加 skuId 相关的活动 skuId
public void addSkuRe(String skuId, String marketSkuId) {
String rk = GoblinRedisConst.SKU_RELATION.concat(skuId);
List<String> list = getSkuRe(skuId);
list.add(marketSkuId);
redisUtil.set(rk, list);
}
//删除 skuId 相关的活动 skuId
public void removeSkuRe(String skuId, String marketSkuId) {
String rk = GoblinRedisConst.SKU_RELATION.concat(skuId);
List<String> list = getSkuRe(skuId);
list.remove(marketSkuId);
redisUtil.set(rk, list);
}
//获取 skuId 相关的活动 skuId
public List<String> getSkuRe(String skuId) {
String rk = GoblinRedisConst.SKU_RELATION.concat(skuId);
Object obj = redisUtil.get(rk);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
/* ---------------------------------------- 平台标签数据源 ---------------------------------------- */
/**
* 普通商品标签
* {
* tagType:0-普通商品标签
* tagBelong:0-普通标签
* }
*
* @return List<GoblinSelfTagVo>
*/
public List<GoblinSelfTagVo> getSelfTagVos() {
String valStr = (String) redisUtil.get(GoblinRedisConst.BASIC_SELF_TAG);
boolean valStrIsEmptyFlg = StringUtils.isEmpty(valStr);
List<GoblinSelfTagVo> vos;
if (valStrIsEmptyFlg) {
if (!CollectionUtils.isEmpty(vos = goblinMongoUtils.getSelfTagVos("0"))) {
redisUtil.set(GoblinRedisConst.BASIC_SELF_TAG, JsonUtils.toJson(vos), 60 * 60);
}
} else {
vos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinSelfTagVo>>() {
});
}
return vos;
}
/**
* 专属标签
* {
* tagType:1-音乐人|2-艺术家|3-品牌方|4-厂牌|5-AR
* tagBelong:1-专属标签
* }
*
* @return List<GoblinSelfTagVo>
*/
public List<GoblinSelfTagVo> getSelfExtagVos() {
String valStr = (String) redisUtil.get(GoblinRedisConst.BASIC_SELF_EXTAG);
List<GoblinSelfTagVo> vos;
if (StringUtils.isEmpty(valStr)) {
if (!CollectionUtils.isEmpty(vos = goblinMongoUtils.getSelfTagVos("1"))) {
redisUtil.set(GoblinRedisConst.BASIC_SELF_EXTAG, JsonUtils.toJson(vos), 60 * 60);
}
} else {
vos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinSelfTagVo>>() {
});
}
return vos;
}
/* ---------------------------------------- 平台分类数据源 ---------------------------------------- */
public List<GoblinSelfGoodsCategoryVo> getSelfGoodsCategoryVos() {
String valStr = (String) redisUtil.get(GoblinRedisConst.BASIC_SELF_GOODS_CATEGORY);
boolean valStrIsEmptyFlg = StringUtils.isEmpty(valStr);
List<GoblinSelfGoodsCategoryVo> vos;
if (valStrIsEmptyFlg) {
if (!CollectionUtils.isEmpty(vos = goblinMongoUtils.getSelfGoodsCategoryVos())) {
redisUtil.set(GoblinRedisConst.BASIC_SELF_GOODS_CATEGORY, JsonUtils.toJson(vos));
}
} else {
vos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinSelfGoodsCategoryVo>>() {
});
}
return vos;
}
/* ---------------------------------------- 店铺分类数据源 ---------------------------------------- */
public boolean setStoreGoodsCategoryVos(String storeId, List<GoblinStoreGoodsCategoryVo> vos) {
return redisUtil.set(GoblinRedisConst.BASIC_STORE_GOODS_CATEGORY.concat(storeId), JsonUtils.toJson(vos));
}
public List<GoblinStoreGoodsCategoryVo> getStoreGoodsCategoryVos(String storeId) {
String rk = GoblinRedisConst.BASIC_STORE_GOODS_CATEGORY.concat(storeId);
String valStr = (String) redisUtil.get(rk);
boolean valStrIsEmptyFlg = StringUtils.isEmpty(valStr);
List<GoblinStoreGoodsCategoryVo> vos = null;
if (valStrIsEmptyFlg && !CollectionUtils.isEmpty(vos = goblinMongoUtils.getStoreGoodsCategoryVos(storeId))) {
valStr = JsonUtils.toJson(vos);
redisUtil.set(rk, valStr);
} else if (!valStrIsEmptyFlg) {
vos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinStoreGoodsCategoryVo>>() {
});
}
return vos;
}
/* ---------------------------------------- 平台分类规格数据源 ---------------------------------------- */
public boolean setCategorySpec(String cateId, GoblinMgtCategorySpecVo vo) {
return redisUtil.set(GoblinRedisConst.BASIC_SELF_GOODS_CATEGORY_SPEC.concat(cateId), vo);
}
public GoblinMgtCategorySpecVo getCategorySpec(String cateId) {
String rk = GoblinRedisConst.BASIC_SELF_GOODS_CATEGORY_SPEC.concat(cateId);
GoblinMgtCategorySpecVo vo = (GoblinMgtCategorySpecVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getCategorySpecVo(cateId))) {
redisUtil.set(rk, vo);
}
return vo;
}
/* ---------------------------------------- 服务支持数据源 ---------------------------------------- */
public List<GoblinServiceSupportVo> getServiceSupportVos() {
String valStr = (String) redisUtil.get(GoblinRedisConst.BASIC_SERVICE_SUPPORT);
boolean valStrIsEmptyFlg = StringUtils.isEmpty(valStr);
List<GoblinServiceSupportVo> vos;
if (valStrIsEmptyFlg) {
if (!CollectionUtils.isEmpty(vos = goblinMongoUtils.getMgtServiceSupportVos())) {
redisUtil.set(GoblinRedisConst.BASIC_SERVICE_SUPPORT, JsonUtils.toJson(vos));
}
} else {
vos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinServiceSupportVo>>() {
});
}
return vos;
}
/* ---------------------------------------- 店铺公告数据源 ---------------------------------------- */
public GoblinStoreNoticeVo getStoreNoticeVo(String storeId, LocalDateTime nowTime) {
List<GoblinStoreNoticeVo> noticeVos = this.getStoreNoticeVos(storeId, nowTime);
int size = noticeVos.size();
for (int i = size - 1; i >= 0; i--) {
GoblinStoreNoticeVo noticeVo = noticeVos.get(i);
if (noticeVo.getReleaseTime().isBefore(nowTime)) {
noticeVos.removeIf(r -> (
(r.getLongLasting().equals("0") && r.getCancellTime().isBefore(nowTime))
|| r.getReleaseTime().isBefore(noticeVo.getReleaseTime())
));
this.setStoreNoticeVos(storeId, noticeVos);
return noticeVo;
}
}
return null;
}
public List<GoblinStoreNoticeVo> getStoreNoticeVos(String storeId, LocalDateTime nowTime) {
String rk = GoblinRedisConst.STORE_NOTICE.concat(storeId);
List<GoblinStoreNoticeVo> vos = (List<GoblinStoreNoticeVo>) redisUtil.get(rk);
if (CollectionUtils.isEmpty(vos) && !CollectionUtils.isEmpty(vos = goblinMongoUtils.getStoreNoticeVos(storeId, nowTime))) {
// redisUtil.set(rk, vos);
}
return vos;
}
public boolean setStoreNoticeVos(String storeId, List<GoblinStoreNoticeVo> vos) {
return redisUtil.set(GoblinRedisConst.STORE_NOTICE.concat(storeId), vos);
}
/* ---------------------------------------- 店铺配置数据源 ---------------------------------------- */
public List<GoblinStoreConfigVo> getStoreConfigVos(String storeId) {
String rk = GoblinRedisConst.BASIC_STORE_CONF.concat(storeId);
List<GoblinStoreConfigVo> vos = (List<GoblinStoreConfigVo>) redisUtil.get(rk);
if (CollectionUtils.isEmpty(vos) && !CollectionUtils.isEmpty(vos = goblinMongoUtils.getStoreConfigVos(storeId))) {
redisUtil.set(rk, vos);
}
return vos;
}
public boolean setStoreConfigVos(String storeId, List<GoblinStoreConfigVo> vos) {
return redisUtil.set(GoblinRedisConst.BASIC_STORE_CONF.concat(storeId), vos);
}
public void delStoreConfigVos(String storeId) {
redisUtil.del(GoblinRedisConst.BASIC_STORE_CONF.concat(storeId));
}
/* ---------------------------------------- 店铺数据源 ---------------------------------------- */
private boolean setStoreIds(String uid, List<String> storeIds) {
return redisUtil.set(GoblinRedisConst.BASIC_USTORE.concat(uid), storeIds);
}
public boolean addStoreId(String uid, String storeId) {
List<String> storeIds = this.getStoreIds(uid);
if (CollectionUtils.isEmpty(storeIds)) {
storeIds = CollectionUtil.arrayListString();
}
storeIds.add(storeId);
return this.setStoreIds(uid, storeIds);
}
public void delStoreIds(String uid) {
redisUtil.del(GoblinRedisConst.BASIC_USTORE.concat(uid));
}
public void delStoreId(String uid, String storeId) {
List<String> storeIds = this.getStoreIds(uid);
if (!CollectionUtils.isEmpty(storeIds)) {
storeIds.removeIf(r -> r.equals(storeId));
this.setStoreIds(uid, storeIds);
}
}
public List<String> getStoreIds(String uid) {
// List<String> list = (List<String>) redisUtil.get(GoblinRedisConst.BASIC_USTORE.concat(uid));
// return CollectionUtils.isEmpty(list) ? Arrays.asList("1") : list;
return (List<String>) redisUtil.get(GoblinRedisConst.BASIC_USTORE.concat(uid));
}
public boolean hasStoreId(String uid, String storeId) {
List<String> list = this.getStoreIds(uid);
return !CollectionUtils.isEmpty(list) && list.contains(storeId);
}
public boolean setStoreInfoVo(GoblinStoreInfoVo vo) {
List<String> storeIds = this.getStoreIds(vo.getUid());
if (CollectionUtils.isEmpty(storeIds)) {
storeIds = CollectionUtil.arrayListString();
}
storeIds.add(vo.getStoreId());
this.setStoreIds(vo.getUid(), storeIds);
return redisUtil.set(GoblinRedisConst.BASIC_STORE.concat(vo.getStoreId()), vo);
}
public void delStoreInfoVo(String storeId) {
redisUtil.del(GoblinRedisConst.BASIC_STORE.concat(storeId));
}
public GoblinStoreInfoVo getStoreInfoVo(String storeId) {
String rk = GoblinRedisConst.BASIC_STORE.concat(storeId);
GoblinStoreInfoVo vo = (GoblinStoreInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getStoreInfoVo(storeId))) {
redisUtil.set(rk, vo);
}
return vo;
}
public GoblinStoreInfoVo getStoreInfoVoByUid(String uid) {
List<String> storeIds = this.getStoreIds(uid);
GoblinStoreInfoVo storeInfoVo = null;
if (CollectionUtils.isEmpty(storeIds)) {
List<GoblinStoreInfoVo> vos = goblinMongoUtils.getStoreInfoVoByUid(uid);
if (!CollectionUtils.isEmpty(vos)) {
storeIds = CollectionUtil.arrayListString();
for (GoblinStoreInfoVo vo : vos) {
storeIds.add(vo.getStoreId());
}
this.setStoreIds(uid, storeIds);
storeInfoVo = vos.get(0);
}
} else {
storeInfoVo = this.getStoreInfoVo(storeIds.get(0));
}
return storeInfoVo;
}
/* ---------------------------------------- 商品数据源 ---------------------------------------- */
public boolean setGoodsInfoVo(GoblinGoodsInfoVo vo) {
return redisUtil.set(GoblinRedisConst.BASIC_GOODS.concat(vo.getSpuId()), vo);
}
public void delGoodsInfoVo(String spuId) {
redisUtil.del(GoblinRedisConst.BASIC_GOODS.concat(spuId));
}
public void delGoodsInfoVoByUnShelves(String spuId) {
redisUtil.del(GoblinRedisConst.BASIC_GOODS_UNSHELVES.concat(spuId));
}
/**
* 商品基础信息
*
* @param spuId 商品ID
* @return GoblinGoodsInfoVo
*/
public GoblinGoodsInfoVo getGoodsInfoVo(String spuId) {
String pre = GoblinStatusConst.MarketPreStatus.getPre(spuId);
if (pre != null && pre.equals(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())) {
String[] spuSplitArr = spuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue());
String rk = GoblinRedisConst.BASIC_GOODS.concat(spuSplitArr[0]);
GoblinGoodsInfoVo vo = (GoblinGoodsInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsInfoVo(spuId))) {
redisUtil.set(rk, vo);
}
if (vo == null) {
return vo;
}
String marketrk = GoblinRedisConst.BASIC_GOODS.concat(spuId);
GoblinGoodsInfoVo marketVo = (GoblinGoodsInfoVo) redisUtil.get(marketrk);
if (null == marketVo && null != (marketVo = goblinMongoUtils.getGoodsInfoVo(spuId))) {
redisUtil.set(marketrk, marketVo);
}
if (marketVo == null) {
return marketVo;
}
vo.setSpuId(marketVo.getSpuId());
List<String> skuIdList = CollectionUtil.linkedListString();
for (String skuIds : vo.getSkuIdList()) {
skuIdList.add(skuIds.concat(pre).concat(spuSplitArr[1]));
}
vo.setSkuIdList(skuIdList);
vo.setPriceGe(marketVo.getPriceGe());
vo.setPriceLe(marketVo.getPriceLe());
vo.setMarketId(marketVo.getMarketId());
return vo;
} else {
String rk = GoblinRedisConst.BASIC_GOODS.concat(spuId);
GoblinGoodsInfoVo vo = (GoblinGoodsInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsInfoVo(spuId))) {
redisUtil.set(rk, vo);
}
return vo;
}
}
public GoblinGoodsInfoVo getGoodsInfoVoByUnShelves(String spuId) {
String pre = GoblinStatusConst.MarketPreStatus.getPre(spuId);
if (pre != null && pre.equals(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())) {
String[] spuSplitArr = spuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue());
String rk = GoblinRedisConst.BASIC_GOODS_UNSHELVES.concat(spuSplitArr[0]);
GoblinGoodsInfoVo vo = (GoblinGoodsInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsInfoVo(spuId))) {
redisUtil.set(rk, vo);
}
if (vo == null) {
return vo;
}
String marketrk = GoblinRedisConst.BASIC_GOODS_UNSHELVES.concat(spuId);
GoblinGoodsInfoVo marketVo = (GoblinGoodsInfoVo) redisUtil.get(marketrk);
if (null == marketVo && null != (marketVo = goblinMongoUtils.getGoodsInfoVo(spuId))) {
redisUtil.set(marketrk, marketVo);
}
if (marketVo == null) {
return marketVo;
}
vo.setSpuId(marketVo.getSpuId());
List<String> skuIdList = CollectionUtil.linkedListString();
for (String skuIds : vo.getSkuIdList()) {
skuIdList.add(skuIds.concat(pre).concat(spuSplitArr[1]));
}
vo.setSkuIdList(skuIdList);
vo.setPriceGe(marketVo.getPriceGe());
vo.setPriceLe(marketVo.getPriceLe());
vo.setMarketId(marketVo.getMarketId());
return vo;
} else {
String rk = GoblinRedisConst.BASIC_GOODS_UNSHELVES.concat(spuId);
GoblinGoodsInfoVo vo = (GoblinGoodsInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsInfoVo(spuId))) {
redisUtil.set(rk, vo);
}
return vo;
}
}
public boolean setGoodsSkuInfoVo(GoblinGoodsSkuInfoVo vo) {
return redisUtil.set(GoblinRedisConst.BASIC_GOODS_SKU.concat(vo.getSkuId()), vo);
}
public void delGoodsSkuInfoVo(String skuId) {
redisUtil.del(GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId));
}
public void delGoodsSkuInfoVoByUnShelves(String skuId) {
redisUtil.del(GoblinRedisConst.BASIC_GOODS_SKU_UNSHELVES.concat(skuId));
}
/**
* 单品信息
*
* @param skuId 单品ID
* @return GoblinGoodsSkuInfoVo
*/
public GoblinGoodsSkuInfoVo getGoodsSkuInfoVo(String skuId) {
String pre = GoblinStatusConst.MarketPreStatus.getPre(skuId);
if (pre != null && pre.equals(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())) {
String rk = GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())[0]);
GoblinGoodsSkuInfoVo vo = (GoblinGoodsSkuInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsSkuInfoVo(skuId))) {
redisUtil.set(rk, vo);
}
if (vo == null) {
return vo;
}
String marketrk = GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId);
GoblinGoodsSkuInfoVo marketVo = (GoblinGoodsSkuInfoVo) redisUtil.get(marketrk);
if (null == marketVo && null != (marketVo = goblinMongoUtils.getGoodsSkuInfoVo(skuId))) {
redisUtil.set(marketrk, marketVo);
}
if (marketVo == null) {
return marketVo;
}
vo.setSpuId(marketVo.getSpuId());
vo.setSkuId(marketVo.getSkuId());
vo.setPrice(marketVo.getPrice());
vo.setPriceMember(marketVo.getPriceMember());
vo.setSkuStock(marketVo.getSkuStock());
vo.setBuyLimit(marketVo.getBuyLimit());
vo.setBuyRoster(marketVo.getBuyRoster());
vo.setBuyFactor(marketVo.getBuyFactor());
vo.setDelFlg("0");
vo.setMarketId(marketVo.getMarketId());
vo.setCreatedAt(LocalDateTime.now());
return vo;
} else {
String rk = GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId);
GoblinGoodsSkuInfoVo vo = (GoblinGoodsSkuInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsSkuInfoVo(skuId))) {
redisUtil.set(rk, vo);
}
return vo;
}
}
public GoblinGoodsSkuInfoVo getGoodsSkuInfoVoByUnShelves(String skuId) {
String pre = GoblinStatusConst.MarketPreStatus.getPre(skuId);
if (pre != null && pre.equals(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())) {
String rk = GoblinRedisConst.BASIC_GOODS_SKU_UNSHELVES.concat(skuId.split(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue())[0]);
GoblinGoodsSkuInfoVo vo = (GoblinGoodsSkuInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsSkuInfoVo(skuId))) {
redisUtil.set(rk, vo);
}
if (vo == null) {
return vo;
}
String marketrk = GoblinRedisConst.BASIC_GOODS_SKU_UNSHELVES.concat(skuId);
GoblinGoodsSkuInfoVo marketVo = (GoblinGoodsSkuInfoVo) redisUtil.get(marketrk);
if (null == marketVo && null != (marketVo = goblinMongoUtils.getGoodsSkuInfoVo(skuId))) {
redisUtil.set(marketrk, marketVo);
}
if (marketVo == null) {
return marketVo;
}
vo.setSpuId(marketVo.getSpuId());
vo.setSkuId(marketVo.getSkuId());
vo.setPrice(marketVo.getPrice());
vo.setPriceMember(marketVo.getPriceMember());
vo.setSkuStock(marketVo.getSkuStock());
vo.setBuyLimit(marketVo.getBuyLimit());
vo.setBuyRoster(marketVo.getBuyRoster());
vo.setBuyFactor(marketVo.getBuyFactor());
vo.setMarketId(marketVo.getMarketId());
vo.setCreatedAt(LocalDateTime.now());
return vo;
} else {
String rk = GoblinRedisConst.BASIC_GOODS_SKU_UNSHELVES.concat(skuId);
GoblinGoodsSkuInfoVo vo = (GoblinGoodsSkuInfoVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getGoodsSkuInfoVo(skuId))) {
redisUtil.set(rk, vo);
}
return vo;
}
}
// public GoblinGoodsSkuInfoVo getMgtGoodsSkuInfoVo(String skuId) {
// String rk = GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId);
// GoblinGoodsSkuInfoVo vo = (GoblinGoodsSkuInfoVo) redisUtil.get(rk);
// if (null == vo && null != (vo = goblinMongoUtils.getMgtGoodsSkuInfoVo(skuId))) {
// redisUtil.set(rk, vo);
// }
// return vo;
// }
/* ---------------------------------------- ---------------------------------------- */
/**
* 覆盖 商铺活动vo
*
* @param storeMarketId
* @param vo
* @return
*/
public boolean setGoblinStoreMarketVo(String storeMarketId, GoblinStoreMarketVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET.concat(storeMarketId);
return redisUtil.set(redisKey, vo);
}
/**
* 获取 商铺活动vo
*
* @param storeMarketId
* @return
*/
public GoblinStoreMarketVo getGoblinStoreMarketVo(String storeMarketId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET.concat(storeMarketId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
GoblinStoreMarketVo vo = goblinMongoUtils.getStoreMarket(storeMarketId);
setGoblinStoreMarketVo(storeMarketId, vo);
return vo;
} else {
return (GoblinStoreMarketVo) obj;
}
}
/**
* 删除 商铺活动vo
*
* @param storeMarketId
* @return
*/
public void delGoblinStoreMarketVo(String storeMarketId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET.concat(storeMarketId);
redisUtil.del(redisKey);
}
/**
* 获取 配置的商铺id
*
* @param marketId
* @param storeId
*/
public List<GoblinStoreMarketIsConfigVo> getStoreMarketIsConfig(String marketId, String storeId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return new ArrayList();
} else {
return (List<GoblinStoreMarketIsConfigVo>) obj;
}
}
public void addStoreMarketIsConfig(String marketId, String storeId, String spuId, String marketSpuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId);
List<GoblinStoreMarketIsConfigVo> voList = getStoreMarketIsConfig(marketId, storeId);
GoblinStoreMarketIsConfigVo vo = GoblinStoreMarketIsConfigVo.getNew();
vo.setMarketSpuId(marketSpuId);
vo.setSpuId(spuId);
voList.add(vo);
redisUtil.set(redisKey, voList);
}
public void delStoreMarketIsConfig(String marketId, String storeId, String spuId, String marketSpuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_MARKET_ISCONFIG.concat(marketId).concat(":store_id:" + storeId);
List<GoblinStoreMarketIsConfigVo> voList = getStoreMarketIsConfig(marketId, storeId);
for (int i = 0; i < voList.size(); i++) {
String itemSpuId = voList.get(i).getSpuId();
if (spuId.equals(itemSpuId)) {
voList.remove(i);
}
}
redisUtil.set(redisKey, voList);
}
/**
* 添加 活动内商品款式关联关系
*
* @param marketPre
* @param marketId
* @param vo
*/
public void addMarketRelation(String marketPre, String marketId, GoblinMarketRelationVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_MARKET_RELATION.concat(marketPre).concat(marketId);
List<GoblinMarketRelationVo> voList = getMarketRelation(marketPre, marketId);
voList.add(vo);
redisUtil.set(redisKey, voList);
}
/**
* 移除 活动内商品款式关联关系
*
* @param marketPre
* @param marketId
*/
public void removeMarketRelation(String marketPre, String marketId, String spuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_MARKET_RELATION.concat(marketPre).concat(marketId);
List<GoblinMarketRelationVo> voList = getMarketRelation(marketPre, marketId);
for (GoblinMarketRelationVo item : voList) {
if (item.getSpuId().equals(spuId)) {
voList.remove(item);
break;
}
}
redisUtil.set(redisKey, voList);
}
/**
* 获取 活动内商品款式关联关系
*
* @param marketPre
* @param marketId
*/
public List<GoblinMarketRelationVo> getMarketRelation(String marketPre, String marketId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_MARKET_RELATION.concat(marketPre).concat(marketId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return new ArrayList();
} else {
return (List<GoblinMarketRelationVo>) obj;
}
}
/**
* 获取 当前商铺能参与的官方活动id列表
*
* @param storeId
* @return
*/
public List<String> getStoreZhengzaiRelation(String storeId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_STORE_SELF_RELATION.concat(storeId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
/**
* 正在下单 可参加商户关系 详情
*
* @param selfMarketId
* @param storeId
*/
public GoblinMarketingZhengzaiRelationVo getZhengzaiRelation(String selfMarketId, String storeId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ZHENGZAI_RELATION.concat(selfMarketId).concat(":store_id:" + storeId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinMarketingZhengzaiRelationVo) obj;
}
}
/**
* 正在下单 可参加商户 详情
*
* @param selfMarketId
*/
public GoblinSelfMarketingVo getSelfMarket(String selfMarketId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SELF_MARKET.concat(selfMarketId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinSelfMarketingVo) obj;
}
}
//获取全部正在下单的活动
public List<GoblinSelfMarketingVo> getGoblinSelfMarketingVoList() {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ZHENGZAI_LIST;
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return goblinMongoUtils.getGoblinSelfMarketingVoList();
} else {
return (List<GoblinSelfMarketingVo>) obj;
}
}
//获取 用户sku购买个数
public Integer getSkuCountByUid(String uid, String skuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BUY_COUNT.concat(uid + ":skuId:" + skuId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return 0;
} else {
return (Integer) obj;
}
}
//获取 用户是否可购买
public boolean getSkuCanBuyByUid(String mobile, String skuId) {
String redisKey = GoblinRedisConst.REDIS_CAN_BUY.concat(skuId + ":").concat(mobile);
return redisUtil.hasKey(redisKey);
}
// 增加 用户sku购买个数
public int incrSkuCountByUid(String uid, String skuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BUY_COUNT.concat(uid + ":skuId:" + skuId);
return (int) redisUtil.incr(redisKey, number);
}
// 减少 用户sku购买个数
public int decrSkuCountByUid(String uid, String skuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BUY_COUNT.concat(uid + ":skuId:" + skuId);
return (int) redisUtil.decr(redisKey, number);
}
//获取 sku销量
public Integer getSkuSaleCount(String skuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SALE_COUNT.concat(skuId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (Integer) obj;
}
}
// 增加 sku销量
public int incrSkuSaleCount(String spuId, String skuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SALE_COUNT.concat(skuId);
incrSpuSaleCount(spuId, number);
return (int) redisUtil.incr(redisKey, number);
}
// 减少 sku销量
public int decrSkuSaleCount(String spuId, String skuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SALE_COUNT.concat(skuId);
decrSpuSaleCount(spuId, number);
return (int) redisUtil.decr(redisKey, number);
}
//获取 spu销量
public Integer getSpuSaleCount(String spuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SALE_SPU_COUNT.concat(spuId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (Integer) obj;
}
}
// 增加 spu销量
private int incrSpuSaleCount(String spuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SALE_SPU_COUNT.concat(spuId);
return (int) redisUtil.incr(redisKey, number);
}
// 减少 spu销量
private int decrSpuSaleCount(String spuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_SALE_SPU_COUNT.concat(spuId);
return (int) redisUtil.decr(redisKey, number);
}
// 赋值 订单相关vo
public void setGoblinOrder(String orderId, GoblinStoreOrderVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER.concat(orderId);
redisUtil.set(redisKey, vo);
}
// 赋值 订单相关Skuvo
public void setGoblinOrderSku(String orderSkuId, GoblinOrderSkuVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_SKU.concat(orderSkuId);
redisUtil.set(redisKey, vo);
}
// 赋值 快递vo
public void addGoblinMail(String orderId, GoblinMailVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_MAIL.concat(orderId);
List<GoblinMailVo> list = getGoblinMail(orderId);
list.add(vo);
redisUtil.set(redisKey, list);
}
// 修改 快递vo
public void changeGoblinMail(String orderId, GoblinMailVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_MAIL.concat(orderId);
List<GoblinMailVo> list = getGoblinMail(orderId);
for (GoblinMailVo item : list) {
if (item.getMailId().equals(vo.getMailId())) {
item.setMailNo(vo.getMailNo());
break;
}
}
redisUtil.set(redisKey, list);
}
// 获取 快递vo
public List<GoblinMailVo> getGoblinMail(String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_MAIL.concat(orderId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return ObjectUtil.goblinMailVo();
} else {
return (List<GoblinMailVo>) obj;
}
}
// 获取 订单相关vo
public GoblinStoreOrderVo getGoblinOrder(String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER.concat(orderId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinStoreOrderVo) obj;
}
}
// 获取 订单相关Skuvo
public GoblinOrderSkuVo getGoblinOrderSkuVo(String orderSkuId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_SKU.concat(orderSkuId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinOrderSkuVo) obj;
}
}
// 获取 未支付订单id列表
public List<String> getUnPayOrder(String randomKey) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_UN_PAY.concat(randomKey);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
// 添加 未支付订单id列表 返回 radomKey
public int addUnPayOrder(String orderId) {
int randomKey = RandomUtil.getRandomInt(0, randomMax);
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_UN_PAY.concat(randomKey + "");
List<String> list = getUnPayOrder(randomKey + "");
list.add(orderId);
redisUtil.set(redisKey, list);
return randomKey;
}
// 删除 未支付订单id列表
public void removeGoblinOrder(String randomKey, String orderId) {
if (randomKey == null) {
for (int i = 0; i < randomMax; i++) {
randomKey = i + "";
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_UN_PAY.concat(randomKey);
List<String> list = getUnPayOrder(randomKey);
if (list.contains(orderId)) {
list.remove(orderId);
redisUtil.set(redisKey, list);
break;
}
}
} else {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_UN_PAY.concat(randomKey + "");
List<String> list = getUnPayOrder(randomKey);
list.remove(orderId);
redisUtil.set(redisKey, list);
}
}
// 获取 订单id列表
public List<String> getOrderList(String uid) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_LIST.concat(uid);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
// 添加 订单id列表
public void addOrderList(String uid, String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_LIST.concat(uid);
List<String> list = getOrderList(uid);
list.add(orderId);
redisUtil.set(redisKey, list);
}
// 删除 订单id列表
public void removeOrderList(String uid, String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_LIST.concat(uid);
List<String> list = getOrderList(uid);
list.remove(orderId);
redisUtil.set(redisKey, list);
}
// 获取 订单id列表
public List<String> getZhengzaiOrderList(String uid) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_ZHENGZAI_LIST.concat(uid);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
// 添加 订单id列表
public void addZhengzaiOrderList(String uid, String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_ZHENGZAI_LIST.concat(uid);
List<String> list = getZhengzaiOrderList(uid);
list.add(orderId);
redisUtil.set(redisKey, list);
}
// 删除 订单id列表
public void removeZhengzaiOrderList(String uid, String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_ZHENGZAI_LIST.concat(uid);
List<String> list = getZhengzaiOrderList(uid);
list.remove(orderId);
redisUtil.set(redisKey, list);
}
//主订单下包含的子订单
public void setMasterCode(String masterCode, String orderIds) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_MASTER.concat(masterCode);
redisUtil.set(redisKey, orderIds);
}
public String[] getMasterCode(String masterCode) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_MASTER.concat(masterCode);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return ((String) obj).split(",");
}
}
//主订单对应的出货吗
public void setOffCode(String writeOffCode, String masterCode) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_OFFCODE.concat(writeOffCode);
redisUtil.set(redisKey, masterCode);
}
public String[] getOffCode(String writeOffCode) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_OFFCODE.concat(writeOffCode);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return getMasterCode((String) obj);
}
}
//覆盖 退款订单vo
public void setBackOrderVo(String backOrderId, GoblinBackOrderVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_BACK.concat(backOrderId);
redisUtil.set(redisKey, vo);
}
//覆盖 获取订单vo
public GoblinBackOrderVo getBackOrderVo(String backOrderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_ORDER_BACK.concat(backOrderId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinBackOrderVo) obj;
}
}
// 获取 订单id下的退款订单id
public List<String> getBackOrderByOrderId(String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BACK_ORDER_ID.concat(orderId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
// 添加 订单id下的退款订单id
public void addBackOrderByOrderId(String orderId, String backOrderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BACK_ORDER_ID.concat(orderId);
List<String> list = getBackOrderByOrderId(orderId);
list.add(backOrderId);
redisUtil.set(redisKey, list);
}
//商品上架、下架、删除 调用的方法
public void deleteKeyForSelectGoods() {
redisUtil.del(GoblinRedisConst.SELECT_GOODS_SPUIDS);
redisUtil.del(GoblinRedisConst.SELECT_GOODS_PAGE1);
}
// banner 降级
public List<GoblinFrontBanner> getListBanner() {
List<GoblinFrontBanner> vo = (List<GoblinFrontBanner>) redisUtil.get(GoblinRedisConst.FRONT_TOP_BANNER);
if (null == vo) {
//降级
return goblinMongoUtils.getListBanner();
}
return vo;
}
public List<GoblinFrontBanner> getMiddleBanner() {
List<GoblinFrontBanner> vo = (List<GoblinFrontBanner>) redisUtil.get(GoblinRedisConst.FRONT_MIDDLE_BANNER);
if (null == vo) {
//降级
return goblinMongoUtils.getMiddleBanner();
}
return vo;
}
// 热词降级
public List<GoblinFrontHotWord> getHotWord() {
List<GoblinFrontHotWord> vo = (List<GoblinFrontHotWord>) redisUtil.get(GoblinRedisConst.FRONT_HOTWORD);
if (null == vo) {
//降级
return goblinMongoUtils.getHotWord();
}
return vo;
}
// 导航栏 降级
// List<GoblinFrontNavigation> list = (List<GoblinFrontNavigation>) redisUtil.get(GoblinRedisConst.FRONT_NAVIGATION);
public List<GoblinFrontNavigation> getNavigation() {
List<GoblinFrontNavigation> vo = (List<GoblinFrontNavigation>) redisUtil.get(GoblinRedisConst.FRONT_NAVIGATION);
if (null == vo) {
//降级
return goblinMongoUtils.getNavigation();
}
return vo;
}
/* ---------------------------------------- 商铺活动:优惠券数据源 ---------------------------------------- */
public GoblinStoreCouponVo getStoreCouponVo(String storeCouponId) {
String rk = GoblinRedisConst.STORE_COUPON.concat(storeCouponId);
GoblinStoreCouponVo vo = (GoblinStoreCouponVo) redisUtil.get(rk);
if (null == vo && null != (vo = goblinMongoUtils.getStoreCouponVo(storeCouponId))) {
redisUtil.set(rk, vo);
}
return vo;
}
public List<String> getStoreCouponSpuIds(String storeCouponId) {
String rk = GoblinRedisConst.STORE_COUPON_RULE.concat(storeCouponId);
String valStr = (String) redisUtil.get(rk);
List<String> strs;
if (StringUtils.isEmpty(valStr)) {
GoblinStoreCouponBasicVo storeCouponBasicVo = goblinMongoUtils.getMgtStoreCouponBasicVo(storeCouponId);
strs = null == storeCouponBasicVo ? null : storeCouponBasicVo.getSpuIdList();
if (!CollectionUtils.isEmpty(strs)) {
redisUtil.set(rk, JsonUtils.toJson(strs));
}
} else {
strs = JsonUtils.fromJson(valStr, new TypeReference<List<String>>() {
});
}
return strs;
}
/* ---------------------------------------- 商铺活动:优惠券剩余库存 ---------------------------------------- */
public boolean setStoreCouponStock(String storeCouponId, Integer stock) {
return redisUtil.set(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId), stock);
}
public void delStoreCouponStock(String storeCouponId) {
redisUtil.del(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId));
}
public int getStoreCouponStock(String storeCouponId) {
Object valObj = redisUtil.get(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId));
return null == valObj ? 0 : (int) valObj;
}
public int incrStoreCouponStock(String storeCouponId, Integer operStock) {
return (int) redisUtil.incr(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId), operStock);
}
public int decrStoreCouponStock(String storeCouponId, Integer operStock) {
return (int) redisUtil.decr(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId), operStock);
}
/* ---------------------------------------- 商铺活动 ---------------------------------------- */
public boolean setStoreMarketDtos(String storeId, List<GoblinStoreMarketDto> dtos) {
return redisUtil.set(GoblinRedisConst.STORE_MARKETS.concat(storeId), JsonUtils.toJson(dtos));
}
public List<GoblinStoreMarketDto> getStoreMarketDtos(String storeId) {
String rk = GoblinRedisConst.STORE_MARKETS.concat(storeId);
String valStr = (String) redisUtil.get(rk);
List<GoblinStoreMarketDto> dtos;
if (StringUtils.isEmpty(valStr)) {
// TODO: 2022/2/17 zhanggb mongodb 查取该商品所有参与的活动并整理集合
dtos = ObjectUtil.getGoblinStoreMarketDtoArrayList();
} else {
dtos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinStoreMarketDto>>() {
});
}
return dtos;
}
public boolean addStoreMarketDto(String storeId, GoblinStoreMarketDto dto) {
List<GoblinStoreMarketDto> dtos = this.getStoreMarketDtos(storeId);
dtos.add(dto);
return redisUtil.set(GoblinRedisConst.STORE_MARKETS.concat(storeId), JsonUtils.toJson(dtos));
}
public void delStoreMarketDto(String storeId) {
redisUtil.del(GoblinRedisConst.STORE_MARKETS.concat(storeId));
}
public void delStoreMarketDto(String storeId, GoblinStoreMarketDto dto) {
String rk = GoblinRedisConst.STORE_MARKETS.concat(storeId);
List<GoblinStoreMarketDto> dtos = this.getStoreMarketDtos(storeId);
if (!CollectionUtils.isEmpty(dtos)) {
int beforeSize = dtos.size();
dtos.removeIf(r -> r.getId().equals(dto.getId()) && r.getType().equals(dto.getType()));
if (beforeSize > dtos.size()) {
redisUtil.set(GoblinRedisConst.STORE_MARKETS.concat(storeId), JsonUtils.toJson(dtos));
}
}
}
//获取艺人标签redis
public List<GoblinGoodsInfoVo> getMusicTagList(String musicTag, String performanceId) {
List<GoblinGoodsInfoVo> listVo = ObjectUtil.getGoblinGoodsInfoVos();
// String rk = GoblinRedisConst.REDIS_ZZ_MUSIC_TAG.concat(musicTag + ":").concat(performanceId);
// Object obj = redisUtil.get(rk);
// if (obj == null) {
listVo = goblinMongoUtils.getMusicTagPGoods(musicTag, performanceId);
// redisUtil.set(rk, listVo);
return listVo;
// } else {
// return (List<GoblinGoodsInfoVo>) obj;
// }
}
//删除艺人标签redis
public void delMusicTagList(String musicTag, String performanceId) {
String rk = GoblinRedisConst.REDIS_ZZ_MUSIC_TAG.concat(musicTag + ":").concat(performanceId);
redisUtil.del(rk);
}
/* ---------------------------------------- 商品活动 ---------------------------------------- */
public List<GoblinStoreCouponVo> getGoodsMarketsForCoupon(String spuId, String storeId) {
List<GoblinStoreMarketDto> storeMarketDtos = this.getStoreMarketDtos(storeId);
if (CollectionUtils.isEmpty(storeMarketDtos)) {
return ObjectUtil.getGoblinStoreCouponVoArrayList();
}
ArrayList<GoblinStoreCouponVo> storeCouponVos = ObjectUtil.getGoblinStoreCouponVoArrayList();
storeMarketDtos.forEach(dto -> {// 逐个活动筛选优惠券活动处理
if (dto.getType() == 1) {// 优惠券活动
GoblinStoreCouponVo storeCouponVo = this.getStoreCouponVo(dto.getId());
if (null != storeCouponVo) {
if ("0".equals(storeCouponVo.getUseScope())) {
storeCouponVos.add(storeCouponVo);
} else {
List<String> storeCouponSpuIds = this.getStoreCouponSpuIds(dto.getId());
if (!CollectionUtils.isEmpty(storeCouponSpuIds) && storeCouponSpuIds.contains(spuId)) {
storeCouponVos.add(storeCouponVo);
}
}
}
}
});
return storeCouponVos;
}
/* ---------------------------------------- 商城:用户优惠券 ---------------------------------------- */
public boolean setUserCouponVos(String uid, List<GoblinUserCouponVo> vos) {
return redisUtil.set(GoblinRedisConst.USER_COUPON.concat(uid), JsonUtils.toJson(vos));
}
public List<GoblinUserCouponVo> getUserCouponVos(String uid) {
String rk = GoblinRedisConst.USER_COUPON.concat(uid);
// long s = System.nanoTime();
String valStr = (String) redisUtil.get(rk);
// log.info("RDS.G耗时:{}ms", (System.nanoTime() - s) / 1000000);
List<GoblinUserCouponVo> vos;
if (StringUtils.isEmpty(valStr)) {
// if (!CollectionUtils.isEmpty(vos = goblinMongoUtils.getUserCouponVos(uid))) {
// redisUtil.set(rk, JsonUtils.toJson(vos));
// }
return ObjectUtil.getGoblinUserCouponVo();
} else {
vos = JsonUtils.fromJson(valStr, new TypeReference<List<GoblinUserCouponVo>>() {
});
}
return vos;
}
public boolean addUserCouponVos(String uid, GoblinUserCouponVo vo) {
if (null == vo) return false;
List<GoblinUserCouponVo> vos = this.getUserCouponVos(uid);
vos.add(vo);
return redisUtil.set(GoblinRedisConst.USER_COUPON.concat(uid), JsonUtils.toJson(vos));
}
/* ---------------------------------------- ---------------------------------------- */
public boolean addMarketTempCoupon(String marketId, String ucouponId) {
String redisKey = REDIS_GOBLIN_TEMP_COUPON_MARKET.concat(marketId);
List<String> list = getMarketTempCoupon(marketId);
list.add(ucouponId);
return redisUtil.set(redisKey, list, 60 * 60 * 24 * 60);
}
/* ---------------------------------------- 临时券 ---------------------------------------- */
public void delMarketTempCoupon(String performanceId) {
String redisKey = REDIS_GOBLIN_TEMP_COUPON_MARKET.concat(performanceId);
redisUtil.del(redisKey);
}
public List<String> getMarketTempCoupon(String performanceId) {
String redisKey = REDIS_GOBLIN_TEMP_COUPON_MARKET.concat(performanceId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
public void setTempCoupon(String ucouponId, TempCouponVo vo) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_TEMP_COUPON.concat(ucouponId);
redisUtil.set(redisKey, vo, 60 * 60 * 24 * 60);
}
public TempCouponVo getTempCoupon(String ucouponId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_TEMP_COUPON.concat(ucouponId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (TempCouponVo) obj;
}
}
/* ---------------------------------------- ---------------------------------------- */
}
package com.liquidnet.service.goblin.util;
import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.goblin.dto.GoblinStoreMarketDto;
import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtCouponListVoExcel;
import com.liquidnet.service.goblin.dto.GoblinStoreMgtGoodsListVoExcel;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponSpuListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtThumbVo;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.entity.GoblinOrderAttr;
import com.liquidnet.service.goblin.entity.GoblinOrderSku;
import com.liquidnet.service.goblin.entity.GoblinStoreOrder;
import com.liquidnet.service.goblin.param.BackCouponParam;
import com.liquidnet.service.goblin.param.GoblinOrderSqlParam;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.WriteModel;
import org.bson.Document;
import java.util.ArrayList;
import java.util.List;
public class ObjectUtil {
private static final PagedResult<GoblinStoreMgtGoodsListVo> goblinStoreMgtGoodsVoPagedResult = new PagedResult<>();
private static final PagedResult<GoblinStoreNoticeVo> goblinStoreNoticeVoPagedResult = new PagedResult<>();
private static final PagedResult<GoblinStoreMgtCouponListVo> goblinStoreMgtCouponListVoPagedResult = new PagedResult<>();
private static final ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinFrontBanner> goblinFrontBannerArrayList = new ArrayList<>();
private static final ArrayList<GoblinFrontBannerVo> goblinFrontBannerVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinSelfMarketingVo> goblinSelfMarketingVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreMgtThumbVo> goblinStoreMgtThumbVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreConfigVo> goblinStoreConfigVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreNoticeVo> goblinStoreNoticeVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsSkuInfoVo> goblinGoodsSkuInfoVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsSpecVo> goblinGoodsSpecVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsSpecValueVo> goblinGoodsSpecValueVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinServiceSupportVo> goblinServiceSupportVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinSelfTagVo> goblinSelfTagVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsTagVo> goblinGoodsTagVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinSelfGoodsCategoryVo> goblinSelfGoodsCategoryVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreGoodsCategoryVo> goblinStoreGoodsCategoryVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsExtagVo> goblinGoodsExtagVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsSpecDto> goblinGoodsSpecDtoArrayList = new ArrayList<>();
private static final ArrayList<GoblinMarketSpuListVo> goblinMarketSpuListVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStorePurchaseSkuVo> goblinStorePurchaseSkuVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinSelfZhengzaiSkuVo> goblinSelfZhengzaiSkuVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinShowStoreInfoVo> goblinShowStoreInfoVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVos = new ArrayList<>();
private static final ArrayList<GoblinZhengzaiGoodVo> goblinZhengzaiGoodVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinOrderSkuVo> goblinOrderSkuVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinOrderSku> goblinOrderSkuArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreOrder> goblinStoreOrderArrayList = new ArrayList<>();
private static final ArrayList<GoblinOrderAttr> goblinOrderAttrArrayList = new ArrayList<>();
private static final ArrayList<GoblinOrderSqlParam> goblinOrderSqlParamArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreOrderVo> goblinStoreOrderVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinZhengzaiPushVo> goblinZhengzaiPushVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreOrderListVo> goblinStoreOrderListVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreOrderListSkuVo> goblinStoreOrderListSkuVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinShoppingCartVo> goblinShoppingCartVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinShoppingCartVoDetail> goblinShoppingCartVoDetailArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreBackOrderListVo> goblinStoreBackOrderListVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinAppOrderListVo> goblinAppOrderListVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinBackOrderSkuVo> goblinBackOrderSkuVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinBackOrderVo> goblinBackOrderVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinFrontNavigationVo> goblinFrontNavigationVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinGoodsSkuInfoDetailVo> goblinGoodsSkuInfoDetailVos = new ArrayList<>();
private static final ArrayList<GoblinGoodsInfoListVo> goblinGoodsInfoListVo = new ArrayList<>();
private static final ArrayList<GoblinStoreMgtGoodsListVoExcel> goblinStoreMgtGoodsListVoExcelArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreMgtCouponSpuListVo> goblinStoreMgtCouponSpuListVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreMarketDto> goblinStoreMarketDtoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreCouponVo> goblinStoreCouponVoArrayList = new ArrayList<>();
private static final ArrayList<GoblinStoreMgtCouponListVoExcel> goblinStoreMgtCouponListVoExcelArrayList = new ArrayList<>();
private static final ArrayList<GoblinUserCouponVo> goblinUserCouponVo = new ArrayList<>();
private static final ArrayList<BackCouponParam> backCouponParam = new ArrayList<>();
private static final ArrayList<GoblinMailVo> goblinMailVo = new ArrayList<>();
private static final ArrayList<GoblinPosGoodsVo> goblinPosGoodsVoArrayList = new ArrayList<>();
private static final ArrayList<TempCouponVo> tempCouponVo = new ArrayList<>();
private static final BasicDBObject basicDBObject = new BasicDBObject();
private static final ArrayList<WriteModel<Document>> writeModelDocumentArrayList = new ArrayList<>();
public static PagedResult<GoblinStoreMgtGoodsListVo> getGoblinStoreMgtGoodsVoPagedResult() {
return goblinStoreMgtGoodsVoPagedResult.clone();
}
public static PagedResult<GoblinStoreNoticeVo> getGoblinStoreNoticeVoPagedResult() {
return goblinStoreNoticeVoPagedResult.clone();
}
public static PagedResult<GoblinStoreMgtCouponListVo> getGoblinStoreMgtCouponListVoPagedResult() {
return goblinStoreMgtCouponListVoPagedResult.clone();
}
public static ArrayList<GoblinMailVo> goblinMailVo() {
return (ArrayList<GoblinMailVo>) goblinMailVo.clone();
}
public static ArrayList<BackCouponParam> getBackCouponParam() {
return (ArrayList<BackCouponParam>) backCouponParam.clone();
}
public static ArrayList<TempCouponVo> getTempCouponVo() {
return (ArrayList<TempCouponVo>) tempCouponVo.clone();
}
public static ArrayList<GoblinGoodsInfoListVo> getGoblinGoodsInfoListVo() {
return (ArrayList<GoblinGoodsInfoListVo>) goblinGoodsInfoListVo.clone();
}
public static ArrayList<GoblinUserCouponVo> getGoblinUserCouponVo() {
return (ArrayList<GoblinUserCouponVo>) goblinUserCouponVo.clone();
}
public static ArrayList<GoblinStoreMgtGoodsListVoExcel> getGoblinStoreMgtGoodsListVoExcelArrayList() {
return (ArrayList<GoblinStoreMgtGoodsListVoExcel>) goblinStoreMgtGoodsListVoExcelArrayList.clone();
}
public static ArrayList<GoblinGoodsSkuInfoDetailVo> goblinGoodsSkuInfoDetailVos() {
return (ArrayList<GoblinGoodsSkuInfoDetailVo>) goblinGoodsSkuInfoDetailVos.clone();
}
public static ArrayList<GoblinBackOrderVo> goblinBackOrderVoArrayList() {
return (ArrayList<GoblinBackOrderVo>) goblinBackOrderVoArrayList.clone();
}
public static ArrayList<GoblinBackOrderSkuVo> goblinBackOrderSkuVoArrayList() {
return (ArrayList<GoblinBackOrderSkuVo>) goblinBackOrderSkuVoArrayList.clone();
}
public static ArrayList<GoblinShoppingCartVo> goblinShoppingCartVoArrayList() {
return (ArrayList<GoblinShoppingCartVo>) goblinShoppingCartVoArrayList.clone();
}
public static ArrayList<GoblinAppOrderListVo> goblinAppOrderListVoArrayList() {
return (ArrayList<GoblinAppOrderListVo>) goblinAppOrderListVoArrayList.clone();
}
public static ArrayList<GoblinStoreBackOrderListVo> goblinStoreBackOrderListVoArrayList() {
return (ArrayList<GoblinStoreBackOrderListVo>) goblinStoreBackOrderListVoArrayList.clone();
}
public static ArrayList<GoblinShoppingCartVoDetail> goblinShoppingCartVoDetailArrayList() {
return (ArrayList<GoblinShoppingCartVoDetail>) goblinShoppingCartVoDetailArrayList.clone();
}
public static ArrayList<GoblinStoreOrderListSkuVo> getGoblinStoreOrderListSkuVoArrayList() {
return (ArrayList<GoblinStoreOrderListSkuVo>) goblinStoreOrderListSkuVoArrayList.clone();
}
public static ArrayList<GoblinStoreOrderListVo> getGoblinStoreOrderListVoArrayList() {
return (ArrayList<GoblinStoreOrderListVo>) goblinStoreOrderListVoArrayList.clone();
}
public static ArrayList<GoblinZhengzaiPushVo> getGoblinZhengzaiPushVoArrayList() {
return (ArrayList<GoblinZhengzaiPushVo>) goblinZhengzaiPushVoArrayList.clone();
}
public static ArrayList<GoblinStoreOrderVo> getGoblinStoreOrderVoArrayList() {
return (ArrayList<GoblinStoreOrderVo>) goblinStoreOrderVoArrayList.clone();
}
public static ArrayList<GoblinGoodsInfoVo> getGoblinGoodsInfoVos() {
return (ArrayList<GoblinGoodsInfoVo>) goblinGoodsInfoVos.clone();
}
public static ArrayList<GoblinOrderSkuVo> getGoblinOrderSkuVoArrayList() {
return (ArrayList<GoblinOrderSkuVo>) goblinOrderSkuVoArrayList.clone();
}
public static ArrayList<GoblinOrderSqlParam> getGoblinOrderSqlParamArrayListList() {
return (ArrayList<GoblinOrderSqlParam>) goblinOrderSqlParamArrayList.clone();
}
public static ArrayList<GoblinOrderSku> getGoblinOrderSkuArrayList() {
return (ArrayList<GoblinOrderSku>) goblinOrderSkuArrayList.clone();
}
public static ArrayList<GoblinOrderAttr> getGoblinOrderAttrArrayList() {
return (ArrayList<GoblinOrderAttr>) goblinOrderAttrArrayList.clone();
}
public static ArrayList<GoblinStoreOrder> getGoblinStoreOrderArrayList() {
return (ArrayList<GoblinStoreOrder>) goblinStoreOrderArrayList.clone();
}
public static ArrayList<GoblinShowStoreInfoVo> getGoblinShowStoreInfoVoArrayList() {
return (ArrayList<GoblinShowStoreInfoVo>) goblinShowStoreInfoVoArrayList.clone();
}
public static ArrayList<GoblinZhengzaiGoodVo> getGoblinZhengzaiGoodVoArrayList() {
return (ArrayList<GoblinZhengzaiGoodVo>) goblinZhengzaiGoodVoArrayList.clone();
}
public static ArrayList<GoblinGoodsInfoVo> goblinGoodsInfoVoArrayList() {
return (ArrayList<GoblinGoodsInfoVo>) goblinGoodsInfoVoArrayList.clone();
}
public static ArrayList<GoblinFrontBannerVo> goblinFrontBannerVoArrayList() {
return (ArrayList<GoblinFrontBannerVo>) goblinFrontBannerVoArrayList.clone();
}
public static ArrayList<GoblinFrontBanner> getGoblinFrontBannerArrayList() {
return (ArrayList<GoblinFrontBanner>) goblinFrontBannerArrayList.clone();
}
public static ArrayList<GoblinSelfMarketingVo> getGoblinSelfMarketingVoList() {
return (ArrayList<GoblinSelfMarketingVo>) goblinSelfMarketingVoArrayList.clone();
}
public static ArrayList<GoblinStoreMgtThumbVo> getGoblinStoreMgtThumbVoArrayList() {
return (ArrayList<GoblinStoreMgtThumbVo>) goblinStoreMgtThumbVoArrayList.clone();
}
public static ArrayList<GoblinStoreConfigVo> getGoblinStoreConfigVoArrayList() {
return (ArrayList<GoblinStoreConfigVo>) goblinStoreConfigVoArrayList.clone();
}
public static ArrayList<GoblinStoreNoticeVo> getGoblinStoreNoticeVoArrayList() {
return (ArrayList<GoblinStoreNoticeVo>) goblinStoreNoticeVoArrayList.clone();
}
public static ArrayList<GoblinGoodsSkuInfoVo> getGoblinGoodsSkuInfoVoArrayList() {
return (ArrayList<GoblinGoodsSkuInfoVo>) goblinGoodsSkuInfoVoArrayList.clone();
}
public static ArrayList<GoblinGoodsSpecVo> getGoblinGoodsSpecVoArrayList() {
return (ArrayList<GoblinGoodsSpecVo>) goblinGoodsSpecVoArrayList.clone();
}
public static ArrayList<GoblinGoodsSpecValueVo> getGoblinGoodsSpecValueVoArrayList() {
return (ArrayList<GoblinGoodsSpecValueVo>) goblinGoodsSpecValueVoArrayList.clone();
}
public static ArrayList<GoblinServiceSupportVo> getGoblinServiceSupportVoArrayList() {
return (ArrayList<GoblinServiceSupportVo>) goblinServiceSupportVoArrayList.clone();
}
public static ArrayList<GoblinSelfTagVo> getGoblinSelfTagVoArrayList() {
return (ArrayList<GoblinSelfTagVo>) goblinSelfTagVoArrayList.clone();
}
public static ArrayList<GoblinGoodsTagVo> getGoblinGoodsTagVoArrayList() {
return (ArrayList<GoblinGoodsTagVo>) goblinGoodsTagVoArrayList.clone();
}
public static ArrayList<GoblinSelfGoodsCategoryVo> getGoblinSelfGoodsCategoryVoArrayList() {
return (ArrayList<GoblinSelfGoodsCategoryVo>) goblinSelfGoodsCategoryVoArrayList.clone();
}
public static ArrayList<GoblinStoreGoodsCategoryVo> getGoblinStoreGoodsCategoryVoArrayList() {
return (ArrayList<GoblinStoreGoodsCategoryVo>) goblinStoreGoodsCategoryVoArrayList.clone();
}
public static ArrayList<GoblinGoodsExtagVo> getGoblinGoodsExtagVoArrayList() {
return (ArrayList<GoblinGoodsExtagVo>) goblinGoodsExtagVoArrayList.clone();
}
public static ArrayList<GoblinGoodsSpecDto> getGoblinGoodsSpecDtoArrayList() {
return (ArrayList<GoblinGoodsSpecDto>) goblinGoodsSpecDtoArrayList.clone();
}
public static ArrayList<GoblinMarketSpuListVo> getGoblinMarketSpuListVoArrayList() {
return (ArrayList<GoblinMarketSpuListVo>) goblinMarketSpuListVoArrayList.clone();
}
public static ArrayList<GoblinStorePurchaseSkuVo> getGoblinStorePurchaseSkuVoArrayList() {
return (ArrayList<GoblinStorePurchaseSkuVo>) goblinStorePurchaseSkuVoArrayList.clone();
}
public static ArrayList<GoblinSelfZhengzaiSkuVo> getGoblinSelfZhengzaiSkuVoArrayList() {
return (ArrayList<GoblinSelfZhengzaiSkuVo>) goblinSelfZhengzaiSkuVoArrayList.clone();
}
public static ArrayList<GoblinFrontNavigationVo> getgoblinFrontNavigationVoArrayList() {
return (ArrayList<GoblinFrontNavigationVo>) goblinFrontNavigationVoArrayList.clone();
}
public static ArrayList<GoblinStoreMgtCouponSpuListVo> getGoblinStoreMgtCouponSpuListVoArrayList() {
return (ArrayList<GoblinStoreMgtCouponSpuListVo>) goblinStoreMgtCouponSpuListVoArrayList.clone();
}
public static ArrayList<GoblinStoreMarketDto> getGoblinStoreMarketDtoArrayList() {
return (ArrayList<GoblinStoreMarketDto>) goblinStoreMarketDtoArrayList.clone();
}
public static ArrayList<GoblinStoreCouponVo> getGoblinStoreCouponVoArrayList() {
return (ArrayList<GoblinStoreCouponVo>) goblinStoreCouponVoArrayList.clone();
}
public static ArrayList<GoblinStoreMgtCouponListVoExcel> getGoblinStoreMgtCouponListVoExcelArrayList() {
return (ArrayList<GoblinStoreMgtCouponListVoExcel>) goblinStoreMgtCouponListVoExcelArrayList.clone();
}
public static ArrayList<GoblinPosGoodsVo> getGoblinPosGoodsVoArrayList() {
return (ArrayList<GoblinPosGoodsVo>) goblinPosGoodsVoArrayList.clone();
}
public static BasicDBObject cloneBasicDBObject() {
return (BasicDBObject) basicDBObject.clone();
}
public static ArrayList<WriteModel<Document>> getWriteModelDocumentArrayList() {
return (ArrayList<WriteModel<Document>>) writeModelDocumentArrayList.clone();
}
}
package com.liquidnet.service.goblin.util;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.constant.MQConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Component
public class QueueUtils {
// @Autowired
// private RabbitTemplate rabbitTemplate;
@Autowired
StringRedisTemplate stringRedisTemplate;
/**
* 发送消息 - RABBIT
*
* @param exchange 交换机
* @param routeKey 路径
* @param jsonMsg Json字符串
*/
// public void sendMsgByRabbit(String exchange, String routeKey, String jsonMsg) {
// rabbitTemplate.convertAndSend(exchange, routeKey, jsonMsg);
// }
/**
* 发送消息 - REDIS
*
* @param streamKey Redis消费Key
* @param jsonMsg Json字符串
*/
public void sendMsgByRedis(String streamKey, String jsonMsg) {
HashMap<String, String> map = CollectionUtil.mapStringString();
map.put("message", jsonMsg);
stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(streamKey));
}
/**
* 发送消息 - REDIS [XLS]
*
* @param xlsPath xls 对应的OSS 全量路径
* @param type [1-添加|2-删除]
* @param skuId skuId
*/
public void sendMsgByRedisXls(String xlsPath, String type, String skuId) {
if (xlsPath == null || xlsPath.equals("") || type == null || type.equals("") || skuId == null || skuId.equals("")) {
} else {
HashMap<String, String> map = CollectionUtil.mapStringString();
map.put("message", xlsPath);
map.put("type", type);
map.put("skuId", skuId);
stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(MQConst.GoblinQueue.GOBLIN_XLS_OPERA.getKey()));
}
}
}
# begin-dev-这里是配置信息基本值
liquidnet:
cloudConfig:
profile: dev
security:
username: user
password: user123
eureka:
host: 127.0.0.1:7001
# end-dev-这里是配置信息基本值
spring:
profiles:
include: service-smile
# begin-prod-这里是配置信息基本值
liquidnet:
cloudConfig:
profile: prod
security:
username: user
password: user123
eureka:
host: 172.17.207.189:7001
# end-prod-这里是配置信息基本值
spring:
profiles:
include: service-smile
#eurekaServer配置
eureka:
client:
register-with-eureka: false
fetch-registry: true
serviceUrl:
defaultZone: http://${liquidnet.security.username}:${liquidnet.security.password}@${liquidnet.eureka.host}/eureka-server/eureka
#configServer配置
spring:
cloud:
config:
# uri: http://127.0.0.1:7002/support-config
# uri: http://39.107.71.112:7002/support-config
profile: ${liquidnet.cloudConfig.profile}
name: ${spring.application.name} #默认为spring.application.name
discovery:
enabled: true
service-id: liquidnet-support-config
\ No newline at end of file
# begin-test-这里是配置信息基本值
liquidnet:
cloudConfig:
profile: test
security:
username: user
password: user123
eureka:
host: 172.17.192.6:7001
#instance:
# prefer-ip-address: true
#host: eureka-test-0.eureka-test-svc.zhengzai-test:7001/eureka-server/eureka,eureka-test-1.eureka-test-svc.zhengzai-test:7001/eureka-server/eureka,eureka-test-2.eureka-test-svc.zhengzai-test:7001/eureka-server/eureka
#host: 192.168.193.41:7001
# end-test-这里是配置信息基本值
spring:
profiles:
include: service-smile
spring:
application:
name: liquidnet-service-smile
profiles:
active: dev
\ No newline at end of file
#---- 服务支持信息
goblin_service_support.insert_byreplace=REPLACE INTO goblin_service_support (ssid,name,`desc`,url,del_flg,created_by,created_at)VALUES(?,?,?,?,'0','-',sysdate())
import org.junit.Test;
public class TestGoblin {
public static void main(String[] args) {
}
@Test
public void testTmp() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liquidnet-bus-service</artifactId>
<groupId>com.liquidnet</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liquidnet-service-smile</artifactId>
<packaging>pom</packaging>
<modules>
<module>liquidnet-service-smile-impl</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
<module>liquidnet-service-slime</module> <module>liquidnet-service-slime</module>
<module>liquidnet-service-stone</module> <module>liquidnet-service-stone</module>
<module>liquidnet-service-goblin</module> <module>liquidnet-service-goblin</module>
<module>liquidnet-service-smile</module>
<!-- <module>liquidnet-service-example</module>--> <!-- <module>liquidnet-service-example</module>-->
<!-- <module>liquidnet-service-sequence</module>--> <!-- <module>liquidnet-service-sequence</module>-->
<!-- <module>liquidnet-service-account</module>--> <!-- <module>liquidnet-service-account</module>-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment