Commit 6abd00e5 by caiyt

修复优化优惠券联调过程中遇到的问题及逻辑优化

parent 35745bc1
...@@ -11,10 +11,12 @@ import com.soss.framework.web.service.TokenService; ...@@ -11,10 +11,12 @@ import com.soss.framework.web.service.TokenService;
import com.soss.system.domain.Order; import com.soss.system.domain.Order;
import com.soss.system.domain.OrderDetail; import com.soss.system.domain.OrderDetail;
import com.soss.system.domain.vo.CouponVo; import com.soss.system.domain.vo.CouponVo;
import com.soss.system.service.ICouponRuleService;
import com.soss.system.service.ICouponUserService; import com.soss.system.service.ICouponUserService;
import com.soss.system.service.impl.AppServiceImpl; import com.soss.system.service.impl.AppServiceImpl;
import com.soss.system.service.impl.OrderServiceImpl; import com.soss.system.service.impl.OrderServiceImpl;
import com.soss.system.service.impl.WechatMessageServiceImpl; import com.soss.system.service.impl.WechatMessageServiceImpl;
import com.soss.system.utils.CollectionUtil;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -40,6 +42,8 @@ public class AppController extends BaseController { ...@@ -40,6 +42,8 @@ public class AppController extends BaseController {
private WechatMessageServiceImpl wechatMessageService; private WechatMessageServiceImpl wechatMessageService;
@Autowired @Autowired
private ICouponUserService couponUserService; private ICouponUserService couponUserService;
@Autowired
private ICouponRuleService couponRuleService;
@RequestMapping("/getMyOrder") @RequestMapping("/getMyOrder")
public TableDataInfo getMyOrder(HttpServletRequest request) { public TableDataInfo getMyOrder(HttpServletRequest request) {
...@@ -112,7 +116,7 @@ public class AppController extends BaseController { ...@@ -112,7 +116,7 @@ public class AppController extends BaseController {
if (loginUser == null) { if (loginUser == null) {
throw new ServiceException("请先登录"); throw new ServiceException("请先登录");
} }
int userAvailableCouponCnt = couponUserService.getUserAvailableCouponCnt(loginUser.getUserId()); int userAvailableCouponCnt = couponUserService.getCustAvailableCouponCnt(loginUser.getOpenId());
return AjaxResult.success(userAvailableCouponCnt); return AjaxResult.success(userAvailableCouponCnt);
} }
...@@ -123,7 +127,16 @@ public class AppController extends BaseController { ...@@ -123,7 +127,16 @@ public class AppController extends BaseController {
if (loginUser == null) { if (loginUser == null) {
throw new ServiceException("请先登录"); throw new ServiceException("请先登录");
} }
List<CouponVo> userAvailableCouponCnt = couponUserService.listUserAvailableCoupon(loginUser.getUserId()); List<CouponVo> couponVoList = couponUserService.listCustAvailableCoupon(loginUser.getOpenId());
return getDataTable(userAvailableCouponCnt); couponVoList.forEach(couponVo -> {
couponVo.setCategoryIds(CollectionUtil.transStrToCodeList(couponVo.getCategoryIdStr()));
couponVo.setGoodsIds(CollectionUtil.transStrToLongList(couponVo.getGoodsIdStr()));
couponVo.setProvince(CollectionUtil.transStrToCodeList(couponVo.getProvinceStr()));
couponVo.setCity(CollectionUtil.transStrToCodeList(couponVo.getCityStr()));
couponVo.setArea(CollectionUtil.transStrToCodeList(couponVo.getAreaStr()));
couponVo.setShopIds(CollectionUtil.transStrToLongList(couponVo.getShopIdStr()));
});
couponRuleService.translateUseLimit(couponVoList);
return getDataTable(couponVoList);
} }
} }
...@@ -8,7 +8,6 @@ import com.soss.common.core.page.TableDataInfo; ...@@ -8,7 +8,6 @@ import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType; import com.soss.common.enums.BusinessType;
import com.soss.common.enums.CouponCategoryType; import com.soss.common.enums.CouponCategoryType;
import com.soss.common.enums.CouponState; import com.soss.common.enums.CouponState;
import com.soss.common.utils.StringUtils;
import com.soss.common.utils.bean.BeanUtils; import com.soss.common.utils.bean.BeanUtils;
import com.soss.system.domain.Coupon; import com.soss.system.domain.Coupon;
import com.soss.system.domain.CouponRule; import com.soss.system.domain.CouponRule;
...@@ -17,6 +16,7 @@ import com.soss.system.domain.po.CouponPo; ...@@ -17,6 +16,7 @@ import com.soss.system.domain.po.CouponPo;
import com.soss.system.domain.vo.CouponVo; import com.soss.system.domain.vo.CouponVo;
import com.soss.system.service.ICouponRuleService; import com.soss.system.service.ICouponRuleService;
import com.soss.system.service.ICouponService; import com.soss.system.service.ICouponService;
import com.soss.system.utils.CollectionUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,7 +24,6 @@ import org.springframework.security.access.prepost.PreAuthorize; ...@@ -24,7 +24,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -73,16 +72,27 @@ public class CouponController extends BaseController { ...@@ -73,16 +72,27 @@ public class CouponController extends BaseController {
couponVo.setTypeDesc(CouponCategoryType.getDesc(coupon.getType())); couponVo.setTypeDesc(CouponCategoryType.getDesc(coupon.getType()));
CouponRule couponRule = ruleMap.get(coupon.getRuleId()); CouponRule couponRule = ruleMap.get(coupon.getRuleId());
if (couponRule != null) { if (couponRule != null) {
BeanUtils.copyProperties(couponRule, couponVo, "name", "state", "categoryIds", "goodsIds", "province", "city", "area", "shopIds"); transLimitToArrStyle(couponVo, couponRule);
couponVo.setRuleId(coupon.getRuleId()); couponVo.setRuleId(coupon.getRuleId());
couponVo.setRuleName(couponRule.getName()); couponVo.setRuleName(couponRule.getName());
couponVo.setRuleDesc(couponRule.getDesc()); couponVo.setRuleDesc(couponRule.getDesc());
} }
return couponVo; return couponVo;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
couponRuleService.translateUseLimit(voList);
return getDataTable(voList); return getDataTable(voList);
} }
private void transLimitToArrStyle(CouponVo couponVo, CouponRule couponRule) {
BeanUtils.copyProperties(couponRule, couponVo, "name", "state", "categoryIds", "goodsIds", "province", "city", "area", "shopIds");
couponVo.setCategoryIds(CollectionUtil.transStrToCodeList(couponRule.getCategoryIds()));
couponVo.setGoodsIds(CollectionUtil.transStrToLongList(couponRule.getGoodsIds()));
couponVo.setProvince(CollectionUtil.transStrToCodeList(couponRule.getProvince()));
couponVo.setCity(CollectionUtil.transStrToCodeList(couponRule.getCity()));
couponVo.setArea(CollectionUtil.transStrToCodeList(couponRule.getArea()));
couponVo.setShopIds(CollectionUtil.transStrToLongList(couponRule.getShopIds()));
}
/** /**
* 获取优惠券详情 * 获取优惠券详情
*/ */
...@@ -95,27 +105,10 @@ public class CouponController extends BaseController { ...@@ -95,27 +105,10 @@ public class CouponController extends BaseController {
CouponVo couponVo = new CouponVo(); CouponVo couponVo = new CouponVo();
BeanUtils.copyProperties(coupon, couponVo); BeanUtils.copyProperties(coupon, couponVo);
CouponRule couponRule = couponRuleService.detail(coupon.getRuleId()); CouponRule couponRule = couponRuleService.detail(coupon.getRuleId());
BeanUtils.copyProperties(couponRule, couponVo, "name", "state", "categoryIds", "goodsIds", "province", "city", "area", "shopIds"); transLimitToArrStyle(couponVo, couponRule);
couponVo.setCategoryIds(transStrToIntList(couponRule.getCategoryIds()));
couponVo.setGoodsIds(transStrToIntList(couponRule.getGoodsIds()));
couponVo.setProvince(transStrToCodeList(couponRule.getProvince()));
couponVo.setCity(transStrToCodeList(couponRule.getCity()));
couponVo.setArea(transStrToCodeList(couponRule.getArea()));
couponVo.setShopIds(transStrToIntList(couponRule.getShopIds()));
return AjaxResult.success(couponVo); return AjaxResult.success(couponVo);
} }
private String[] transStrToCodeList(String codeStr) {
return StringUtils.isEmpty(codeStr) ? null : codeStr.split(",");
}
private Integer[] transStrToIntList(String idsStr) {
if (StringUtils.isEmpty(idsStr)) {
return null;
}
return Arrays.stream(idsStr.split(",")).map(Integer::parseInt).toArray(Integer[]::new);
}
/** /**
* 新增优惠券 * 新增优惠券
*/ */
...@@ -141,6 +134,18 @@ public class CouponController extends BaseController { ...@@ -141,6 +134,18 @@ public class CouponController extends BaseController {
} }
/** /**
* 更新优惠券预校验
*/
@PreAuthorize("@ss.hasPermi('coupon:update:check')")
@Log(title = "更新优惠券预校验", businessType = BusinessType.INSERT)
@PostMapping("/update/check/{id}")
@ApiOperation("更新优惠券预校验")
public AjaxResult checkPreUpdate(@PathVariable Integer id) {
couponService.updateCheckPre(id);
return AjaxResult.success();
}
/**
* 上架优惠券 * 上架优惠券
*/ */
@PreAuthorize("@ss.hasPermi('coupon:online')") @PreAuthorize("@ss.hasPermi('coupon:online')")
......
...@@ -2,18 +2,27 @@ package com.soss.web.controller.coupon; ...@@ -2,18 +2,27 @@ package com.soss.web.controller.coupon;
import com.soss.common.annotation.Log; import com.soss.common.annotation.Log;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult; import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType; import com.soss.common.enums.BusinessType;
import com.soss.common.enums.CouponUserState;
import com.soss.common.enums.CouponUserType;
import com.soss.system.domain.CouponUser;
import com.soss.system.domain.vo.CouponUserVo;
import com.soss.system.service.ICouponUserService; import com.soss.system.service.ICouponUserService;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* <p> * <p>
* 用户领取优惠券记录表 前端控制器 * 用户领取优惠券记录表 前端控制器
...@@ -25,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -25,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/coupon-user") @RequestMapping("/coupon-user")
@Api(tags = "用户领取优惠券记录服务类") @Api(tags = "用户领取优惠券记录服务类")
public class CouponUserController { public class CouponUserController extends BaseController {
@Autowired @Autowired
private ICouponUserService couponUserService; private ICouponUserService couponUserService;
...@@ -34,10 +43,29 @@ public class CouponUserController { ...@@ -34,10 +43,29 @@ public class CouponUserController {
*/ */
@PreAuthorize("@ss.hasPermi('coupon:user:give')") @PreAuthorize("@ss.hasPermi('coupon:user:give')")
@Log(title = "赠送优惠券", businessType = BusinessType.INSERT) @Log(title = "赠送优惠券", businessType = BusinessType.INSERT)
@GetMapping("/{userId}/{userPhone}/{couponId}") @PostMapping("give")
@ApiOperation("赠送优惠券") @ApiOperation("赠送优惠券")
public AjaxResult giveUserCoupon(@PathVariable Long userId, @PathVariable String userPhone, @PathVariable Integer couponId) { public AjaxResult giveUserCoupon(@RequestBody CouponUser couponUser) {
couponUserService.giveUserCoupon(userId, userPhone, couponId); Assert.notNull(couponUser.getCustId(), "用户ID未传递");
Assert.notNull(couponUser.getCouponId(), "优惠券ID未传递");
couponUserService.giveUserCoupon(couponUser.getCustId(), couponUser.getCouponId());
return AjaxResult.success(); return AjaxResult.success();
} }
/**
* 查询用户领取优惠券列表
*/
@PreAuthorize("@ss.hasPermi('coupon:user:list')")
@Log(title = "查询用户领取优惠券列表", businessType = BusinessType.INSERT)
@PostMapping("list")
@ApiOperation("查询用户领取优惠券列表")
public TableDataInfo selectCouponUserList(@RequestBody CouponUser couponUser) {
startPage();
List<CouponUserVo> couponUserVos = couponUserService.selectCouponUserList(couponUser);
couponUserVos.forEach(couponUserVo -> {
couponUserVo.setTypeDesc(CouponUserType.getDesc(couponUserVo.getType()));
couponUserVo.setStateDesc(CouponUserState.getDesc(couponUserVo.getState()));
});
return getDataTable(couponUserVos);
}
} }
package com.soss.common.enums;
public enum CouponUserType {
RECEIVE(1, "领取"),
GRANT(2, "发放"),
GIVE(3, "赠送");
private Integer type;
private String desc;
CouponUserType(Integer type, String desc) {
this.type = type;
this.desc = desc;
}
public Integer getType() {
return type;
}
public static String getDesc(Integer type) {
for (CouponUserType couponUserStat : CouponUserType.values()) {
if (couponUserStat.type.equals(type)) {
return couponUserStat.desc;
}
}
return null;
}
}
...@@ -25,17 +25,17 @@ public class CouponUser extends BaseEntity { ...@@ -25,17 +25,17 @@ public class CouponUser extends BaseEntity {
/** /**
* 用户ID * 用户ID
*/ */
private Long userId; private String custId;
/** /**
* 用户名 * 用户名
*/ */
private String userName; private String custName;
/** /**
* 用户手机号 * 用户手机号
*/ */
private String userPhone; private String custPhone;
/** /**
* 关联订单 * 关联订单
...@@ -76,7 +76,7 @@ public class CouponUser extends BaseEntity { ...@@ -76,7 +76,7 @@ public class CouponUser extends BaseEntity {
private String source; private String source;
/** /**
* 1领取 2 发放 * 1领取 2 发放 3赠送
*/ */
private Integer type; private Integer type;
......
...@@ -23,10 +23,10 @@ public class CouponPo { ...@@ -23,10 +23,10 @@ public class CouponPo {
private Integer categoryId; private Integer categoryId;
@ApiModelProperty("可用商品类别列表,全品类传 [0]") @ApiModelProperty("可用商品类别列表,全品类传 [0]")
private Integer[] categoryIds; private String[] categoryIds;
@ApiModelProperty("可用商品id列表") @ApiModelProperty("可用商品id列表")
private Integer[] goodsIds; private Long[] goodsIds;
@ApiModelProperty("可用省份列表,全国通用传 [0]") @ApiModelProperty("可用省份列表,全国通用传 [0]")
private String[] province; private String[] province;
...@@ -38,7 +38,7 @@ public class CouponPo { ...@@ -38,7 +38,7 @@ public class CouponPo {
private String[] area; private String[] area;
@ApiModelProperty("可用店铺ID列表") @ApiModelProperty("可用店铺ID列表")
private Integer[] shopIds; private Long[] shopIds;
@ApiModelProperty("可领取时间时间") @ApiModelProperty("可领取时间时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
...@@ -97,4 +97,12 @@ public class CouponPo { ...@@ -97,4 +97,12 @@ public class CouponPo {
throw new ServiceException("适用范围之地区/门店不能跨级"); throw new ServiceException("适用范围之地区/门店不能跨级");
} }
} }
public boolean isAllCategory() {
return categoryIds != null && categoryIds.length == 1 && categoryIds[0].equals("0");
}
public boolean isAllProvs() {
return province != null && province.length == 1 && province[0].equals("0");
}
} }
package com.soss.system.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
@ApiModel
@Data
public class CouponUserVo {
@ApiModelProperty("id")
private Integer id;
@ApiModelProperty("用户ID")
private String custId;
@ApiModelProperty("用户名称")
private String custName;
@ApiModelProperty("用户号码")
private String custPhone;
@ApiModelProperty("关联订单id")
private Long orderId;
@ApiModelProperty("关联订单号")
private String orderNo;
@ApiModelProperty("优惠券名称")
private String couponName;
@ApiModelProperty("优惠券来源")
private String source;
@ApiModelProperty("类型:1领取 2 发放 3赠送")
private Integer type;
@ApiModelProperty("类型描述")
private String typeDesc;
@ApiModelProperty("优惠券领取时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime receiveTime;
@ApiModelProperty("优惠券生效时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
@ApiModelProperty("优惠券失效时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime expiredTime;
@ApiModelProperty("优惠券状态")
private Integer state;
@ApiModelProperty("优惠券状态描述")
private String stateDesc;
}
...@@ -53,4 +53,22 @@ public class CouponVo extends CouponPo { ...@@ -53,4 +53,22 @@ public class CouponVo extends CouponPo {
@ApiModelProperty("可用店铺描述") @ApiModelProperty("可用店铺描述")
private String shopDesc; private String shopDesc;
@ApiModelProperty(value = "可用商品类别列表字符串,全品类传 [0]", hidden = true)
private String categoryIdStr;
@ApiModelProperty(value = "可用商品id列表字符串", hidden = true)
private String goodsIdStr;
@ApiModelProperty(value = "可用省份列表字符串,全国通用传 [0]", hidden = true)
private String provinceStr;
@ApiModelProperty(value = "可用城市列表字符串", hidden = true)
private String cityStr;
@ApiModelProperty(value = "可用区域列表字符串", hidden = true)
private String areaStr;
@ApiModelProperty(value = "可用店铺ID列表字符串", hidden = true)
private String shopIdStr;
} }
package com.soss.system.mapper; package com.soss.system.mapper;
import com.soss.system.domain.CouponUser; import com.soss.system.domain.CouponUser;
import com.soss.system.domain.vo.CouponUserVo;
import com.soss.system.domain.vo.CouponVo; import com.soss.system.domain.vo.CouponVo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -50,18 +51,26 @@ public interface CouponUserMapper { ...@@ -50,18 +51,26 @@ public interface CouponUserMapper {
/** /**
* 查询用户可用优惠券数量 * 查询用户可用优惠券数量
* *
* @param userId * @param custId
* @param nowTime * @param nowTime
* @return * @return
*/ */
int getUserAvailableCouponCnt(@Param("userId") Long userId, @Param("nowTime") LocalDateTime nowTime); int getCustAvailableCouponCnt(@Param("custId") String custId, @Param("nowTime") LocalDateTime nowTime);
/** /**
* 查询用户可用优惠券列表 * 查询用户可用优惠券列表
* *
* @param userId * @param custId
* @param nowTime * @param nowTime
* @return * @return
*/ */
List<CouponVo> listUserAvailableCoupon(@Param("userId") Long userId, @Param("nowTime") LocalDateTime nowTime); List<CouponVo> listCustAvailableCoupon(@Param("custId") String custId, @Param("nowTime") LocalDateTime nowTime);
/**
* 查询用户领取优惠券列表
*
* @param couponUser
* @return
*/
List<CouponUserVo> selectCouponUserList(CouponUser couponUser);
} }
package com.soss.system.mapper; package com.soss.system.mapper;
import java.util.List;
import com.soss.system.domain.GoodsCategory; import com.soss.system.domain.GoodsCategory;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 商品分类Mapper接口 * 商品分类Mapper接口
* *
* @author zxq * @author zxq
* @date 2022-04-28 * @date 2022-04-28
*/ */
public interface GoodsCategoryMapper public interface GoodsCategoryMapper {
{
/** /**
* 查询商品分类 * 查询商品分类
* *
* @param id 商品分类主键 * @param id 商品分类主键
* @return 商品分类 * @return 商品分类
*/ */
public GoodsCategory selectGoodsCategoryById(String id); public GoodsCategory selectGoodsCategoryById(String id);
/** /**
* 查询商品分类集合,供翻译使用
*
* @param ids 商品分类主键集合
* @return 商品分类
*/
List<GoodsCategory> selectGoodsCategoryByIds(@Param("ids") List<String> ids);
/**
* 查询商品分类列表 * 查询商品分类列表
* *
* @param goodsCategory 商品分类 * @param goodsCategory 商品分类
* @return 商品分类集合 * @return 商品分类集合
*/ */
......
package com.soss.system.mapper; package com.soss.system.mapper;
import java.util.List;
import com.soss.system.domain.Goods; import com.soss.system.domain.Goods;
import com.soss.system.domain.GoodsSku;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 商品Mapper接口 * 商品Mapper接口
* *
...@@ -23,15 +23,23 @@ public interface GoodsMapper ...@@ -23,15 +23,23 @@ public interface GoodsMapper
/** /**
* 查询商品列表 * 查询商品列表
* *
* @param goods 商品 * @param goods 商品
* @return 商品集合 * @return 商品集合
*/ */
public List<Goods> selectGoodsList(Goods goods); public List<Goods> selectGoodsList(Goods goods);
/** /**
* 查询商品列表,为翻译使用
*
* @param ids
* @return
*/
List<Goods> selectGoodsByIds(@Param("ids") List<Long> ids);
/**
* 新增商品 * 新增商品
* *
* @param goods 商品 * @param goods 商品
* @return 结果 * @return 结果
*/ */
......
package com.soss.system.mapper; package com.soss.system.mapper;
import com.soss.system.domain.Shop; import com.soss.system.domain.Shop;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
...@@ -10,8 +11,7 @@ import java.util.List; ...@@ -10,8 +11,7 @@ import java.util.List;
* @author zxq * @author zxq
* @date 2022-04-28 * @date 2022-04-28
*/ */
public interface ShopMapper public interface ShopMapper {
{
/** /**
* 查询店铺 * 查询店铺
* *
...@@ -21,6 +21,14 @@ public interface ShopMapper ...@@ -21,6 +21,14 @@ public interface ShopMapper
public Shop selectShopById(String id); public Shop selectShopById(String id);
/** /**
* 查询店铺列表,为翻译用
*
* @param ids 店铺主键
* @return 店铺
*/
List<Shop> selectShopByIds(@Param("ids") List<Long> ids);
/**
* 查询所有的店铺 * 查询所有的店铺
* *
* @return 店铺集合 * @return 店铺集合
......
package com.soss.system.service; package com.soss.system.service;
import com.soss.system.domain.CouponRule; import com.soss.system.domain.CouponRule;
import com.soss.system.domain.vo.CouponVo;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -18,4 +19,6 @@ public interface ICouponRuleService { ...@@ -18,4 +19,6 @@ public interface ICouponRuleService {
Map<Integer, CouponRule> getCouponRuleMap(List<Integer> ids); Map<Integer, CouponRule> getCouponRuleMap(List<Integer> ids);
CouponRule detail(Integer id); CouponRule detail(Integer id);
void translateUseLimit(List<CouponVo> couponVos);
} }
...@@ -23,6 +23,8 @@ public interface ICouponService { ...@@ -23,6 +23,8 @@ public interface ICouponService {
void update(CouponPo couponPo); void update(CouponPo couponPo);
void updateCheckPre(Integer id);
int onlineCoupon(Integer id); int onlineCoupon(Integer id);
int offlineCoupon(Integer id); int offlineCoupon(Integer id);
......
package com.soss.system.service; package com.soss.system.service;
import com.soss.system.domain.CouponUser;
import com.soss.system.domain.vo.CouponUserVo;
import com.soss.system.domain.vo.CouponVo; import com.soss.system.domain.vo.CouponVo;
import java.util.List; import java.util.List;
...@@ -14,11 +16,13 @@ import java.util.List; ...@@ -14,11 +16,13 @@ import java.util.List;
*/ */
public interface ICouponUserService { public interface ICouponUserService {
void giveUserCoupon(Long userId, String phone, Integer couponId); void giveUserCoupon(String custId, Integer couponId);
void receiveCoupon(Long userId, Integer id); void receiveCoupon(Long userId, Integer id);
int getUserAvailableCouponCnt(Long userId); int getCustAvailableCouponCnt(String custId);
List<CouponVo> listUserAvailableCoupon(Long userId); List<CouponVo> listCustAvailableCoupon(String custId);
List<CouponUserVo> selectCouponUserList(CouponUser couponUser);
} }
package com.soss.system.service.impl; package com.soss.system.service.impl;
import com.soss.system.domain.CouponRule; import com.soss.system.domain.CouponRule;
import com.soss.system.domain.Goods;
import com.soss.system.domain.GoodsCategory;
import com.soss.system.domain.Shop;
import com.soss.system.domain.vo.CouponVo;
import com.soss.system.mapper.CouponRuleMapper; import com.soss.system.mapper.CouponRuleMapper;
import com.soss.system.mapper.GoodsCategoryMapper;
import com.soss.system.mapper.GoodsMapper;
import com.soss.system.mapper.ShopMapper;
import com.soss.system.service.ICouponRuleService; import com.soss.system.service.ICouponRuleService;
import com.soss.system.utils.AreaUtil;
import com.soss.system.utils.CollectionUtil;
import io.jsonwebtoken.lang.Assert; import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -24,6 +33,14 @@ import java.util.stream.Collectors; ...@@ -24,6 +33,14 @@ import java.util.stream.Collectors;
public class CouponRuleServiceImpl implements ICouponRuleService { public class CouponRuleServiceImpl implements ICouponRuleService {
@Autowired @Autowired
private CouponRuleMapper couponRuleMapper; private CouponRuleMapper couponRuleMapper;
@Autowired
private GoodsCategoryMapper goodsCategoryMapper;
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private ShopMapper shopMapper;
@Autowired
private AreaUtil areaUtil;
@Override @Override
public Map<Integer, CouponRule> getCouponRuleMap(List<Integer> ids) { public Map<Integer, CouponRule> getCouponRuleMap(List<Integer> ids) {
...@@ -43,4 +60,115 @@ public class CouponRuleServiceImpl implements ICouponRuleService { ...@@ -43,4 +60,115 @@ public class CouponRuleServiceImpl implements ICouponRuleService {
Assert.notNull(couponRule, "未查询到匹配的优惠券规则记录[id=" + id + "]"); Assert.notNull(couponRule, "未查询到匹配的优惠券规则记录[id=" + id + "]");
return couponRule; return couponRule;
} }
@Override
public void translateUseLimit(List<CouponVo> couponVos) {
if (CollectionUtils.isEmpty(couponVos)) {
return;
}
transCategoryIds(couponVos);
translateArea(couponVos);
}
private void transCategoryIds(List<CouponVo> couponVos) {
List<String> categoryIds = new ArrayList<>(16);
List<Long> goodsIds = new ArrayList<>(16);
for (CouponVo couponVo : couponVos) {
if (!couponVo.isAllCategory()) {
CollectionUtil.listAddArray(categoryIds, couponVo.getCategoryIds());
}
CollectionUtil.listAddArray(goodsIds, couponVo.getGoodsIds());
}
Map<String, String> categoryMap;
if (!CollectionUtils.isEmpty(categoryIds)) {
List<GoodsCategory> goodsCategories = goodsCategoryMapper.selectGoodsCategoryByIds(categoryIds);
categoryMap = goodsCategories.stream().collect(Collectors.toMap(GoodsCategory::getId, GoodsCategory::getName));
} else {
categoryMap = new HashMap<>(0);
}
Map<Long, String> goodsMap;
if (!CollectionUtils.isEmpty(goodsIds)) {
List<Goods> goods = goodsMapper.selectGoodsByIds(goodsIds);
goodsMap = goods.stream().collect(Collectors.toMap(Goods::getId, Goods::getName));
} else {
goodsMap = new HashMap<>(0);
}
for (CouponVo couponVo : couponVos) {
if (couponVo.isAllCategory()) {
couponVo.setCategoryDesc("全品类");
continue;
} else if (CollectionUtil.hasContents(couponVo.getCategoryIds())) {
String categoryDec = Arrays.stream(couponVo.getCategoryIds()).map(categoryMap::get).collect(Collectors.joining(","));
couponVo.setCategoryDesc(categoryDec);
continue;
}
if (CollectionUtil.hasContents(couponVo.getGoodsIds())) {
String goodsDesc = Arrays.stream(couponVo.getGoodsIds()).map(goodsMap::get).collect(Collectors.joining(","));
couponVo.setGoodsDesc(goodsDesc);
}
}
}
private void translateArea(List<CouponVo> couponVos) {
List<String> province = new ArrayList<>(16);
List<String> city = new ArrayList<>(16);
List<String> area = new ArrayList<>(16);
List<Long> shopIds = new ArrayList<>(16);
for (CouponVo couponVo : couponVos) {
if (!couponVo.isAllProvs()) {
CollectionUtil.listAddArray(province, couponVo.getProvince());
}
CollectionUtil.listAddArray(city, couponVo.getCity());
CollectionUtil.listAddArray(area, couponVo.getArea());
CollectionUtil.listAddArray(shopIds, couponVo.getShopIds());
}
Map<Long, Shop> shopMapInit;
if (!CollectionUtils.isEmpty(shopIds)) {
List<Shop> shops = shopMapper.selectShopByIds(shopIds);
shopMapInit = shops.stream().collect(Collectors.toMap(Shop::getId, Function.identity()));
} else {
shopMapInit = new HashMap<>(0);
}
Map<Long, Shop> shopMap = shopMapInit;
for (CouponVo couponVo : couponVos) {
if (couponVo.isAllProvs()) {
couponVo.setProvinceDesc("全国通用");
continue;
} else if (CollectionUtil.hasContents(couponVo.getProvince())) {
String provDesc = Arrays.stream(couponVo.getProvince()).map(areaUtil::getAreaNameByCode).collect(Collectors.joining(","));
couponVo.setProvinceDesc(provDesc);
}
if (CollectionUtil.hasContents(couponVo.getCity())) {
String cityDesc = Arrays.stream(couponVo.getCity()).map(areaUtil::getAreaNameByCode).collect(Collectors.joining(","));
couponVo.setCityDesc(cityDesc);
continue;
}
if (CollectionUtil.hasContents(couponVo.getArea())) {
String areaDesc = Arrays.stream(couponVo.getArea()).map(areaUtil::getAreaNameByCode).collect(Collectors.joining(","));
couponVo.setAreaDesc(areaDesc);
continue;
}
if (!CollectionUtil.hasContents(couponVo.getShopIds())) {
continue;
}
String shopDesc = Arrays.stream(couponVo.getShopIds()).map(shopId -> {
Shop shop = shopMap.get(shopId);
if (shop == null) {
return null;
}
return areaUtil.getAreaNameByCode(shop.getZone()) + shop.getName();
}).filter(Objects::nonNull).collect(Collectors.joining(","));
couponVo.setShopDesc(shopDesc);
}
}
} }
...@@ -93,6 +93,14 @@ public class CouponServiceImpl implements ICouponService { ...@@ -93,6 +93,14 @@ public class CouponServiceImpl implements ICouponService {
couponMapper.updateCoupon(coupon); couponMapper.updateCoupon(coupon);
} }
@Override
public void updateCheckPre(Integer id) {
int couponReceiveCount = couponUserMapper.getCouponReceiveCount(id);
if (couponReceiveCount > 0) {
throw new ServiceException("优惠券已被领取,无法编辑,只可下线");
}
}
private void checkAndWrapperCoupon(CouponPo couponPo, Coupon coupon, CouponRule couponRule, boolean saveFlag) { private void checkAndWrapperCoupon(CouponPo couponPo, Coupon coupon, CouponRule couponRule, boolean saveFlag) {
Assert.notNull(couponPo.getName(), "优惠券名称还未填写"); Assert.notNull(couponPo.getName(), "优惠券名称还未填写");
Assert.notNull(couponPo.getCategoryId(), "优惠券类别还未选择"); Assert.notNull(couponPo.getCategoryId(), "优惠券类别还未选择");
......
package com.soss.system.service.impl; package com.soss.system.service.impl;
import com.soss.common.core.domain.entity.SysUser;
import com.soss.common.enums.CouponState; import com.soss.common.enums.CouponState;
import com.soss.common.enums.CouponUserType;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.common.utils.DateUtils; import com.soss.common.utils.DateUtils;
import com.soss.system.domain.Coupon; import com.soss.system.domain.Coupon;
import com.soss.system.domain.CouponRule; import com.soss.system.domain.CouponRule;
import com.soss.system.domain.CouponUser; import com.soss.system.domain.CouponUser;
import com.soss.system.domain.Customer;
import com.soss.system.domain.vo.CouponUserVo;
import com.soss.system.domain.vo.CouponVo; import com.soss.system.domain.vo.CouponVo;
import com.soss.system.mapper.CouponMapper; import com.soss.system.mapper.CouponMapper;
import com.soss.system.mapper.CouponRuleMapper; import com.soss.system.mapper.CouponRuleMapper;
import com.soss.system.mapper.CouponUserMapper; import com.soss.system.mapper.CouponUserMapper;
import com.soss.system.mapper.SysUserMapper; import com.soss.system.mapper.CustomerMapper;
import com.soss.system.service.ICouponUserService; import com.soss.system.service.ICouponUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -39,13 +41,12 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -39,13 +41,12 @@ public class CouponUserServiceImpl implements ICouponUserService {
@Autowired @Autowired
private CouponRuleMapper couponRuleMapper; private CouponRuleMapper couponRuleMapper;
@Autowired @Autowired
private SysUserMapper userMapper; private CustomerMapper customerMapper;
@Override @Override
public void giveUserCoupon(Long userId, String phone, Integer couponId) { public void giveUserCoupon(String custId, Integer couponId) {
SysUser user = userMapper.selectUserById(userId); Customer cust = customerMapper.selectCustomerById(custId);
Assert.isTrue(user != null && Objects.equals(user.getPhonenumber(), phone), Assert.notNull(cust, "用户不存在[id=" + custId + "]");
"用户信息不匹配[id=" + userId + "][phone=" + phone + "]");
Coupon coupon = couponMapper.selectCouponById(couponId); Coupon coupon = couponMapper.selectCouponById(couponId);
Assert.isTrue(coupon != null && Objects.equals(coupon.getState(), CouponState.ONLINE.getState()), "优惠券状态不合法"); Assert.isTrue(coupon != null && Objects.equals(coupon.getState(), CouponState.ONLINE.getState()), "优惠券状态不合法");
CouponRule couponRule = couponRuleMapper.selectCouponRuleById(coupon.getRuleId()); CouponRule couponRule = couponRuleMapper.selectCouponRuleById(coupon.getRuleId());
...@@ -55,14 +56,14 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -55,14 +56,14 @@ public class CouponUserServiceImpl implements ICouponUserService {
throw new ServiceException("优惠券不在有效期内"); throw new ServiceException("优惠券不在有效期内");
} }
CouponUser couponUser = new CouponUser(); CouponUser couponUser = new CouponUser();
couponUser.setUserId(userId); couponUser.setCustId(custId);
couponUser.setUserName(user.getUserName()); couponUser.setCustName(cust.getUserName());
couponUser.setUserPhone(user.getPhonenumber()); couponUser.setCustPhone(cust.getPhone());
couponUser.setCouponId(couponId); couponUser.setCouponId(couponId);
couponUser.setExpiredTime(this.getCouponExpiredTime(couponRule, now)); couponUser.setExpiredTime(this.getCouponExpiredTime(couponRule, now));
couponUser.setReceiveTime(now); couponUser.setReceiveTime(now);
couponUser.setSource("give"); couponUser.setSource("赠送");
couponUser.setType(2); couponUser.setType(CouponUserType.GIVE.getType());
couponUser.setCreatedAt(now); couponUser.setCreatedAt(now);
couponUser.setUpdatedAt(now); couponUser.setUpdatedAt(now);
couponUserMapper.insertCouponUser(couponUser); couponUserMapper.insertCouponUser(couponUser);
...@@ -73,7 +74,7 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -73,7 +74,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
public void receiveCoupon(Long userId, Integer id) { public void receiveCoupon(Long userId, Integer id) {
CouponUser couponUser = couponUserMapper.getUserCouponById(id); CouponUser couponUser = couponUserMapper.getUserCouponById(id);
Assert.notNull(couponUser, "未查询到匹配记录[id=" + id + "]"); Assert.notNull(couponUser, "未查询到匹配记录[id=" + id + "]");
Assert.isTrue(couponUser.getUserId().equals(userId), "该券与当前用户信息不符"); Assert.isTrue(couponUser.getCustId().equals(userId), "该券与当前用户信息不符");
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
Coupon coupon = couponMapper.selectCouponById(couponUser.getCouponId()); Coupon coupon = couponMapper.selectCouponById(couponUser.getCouponId());
Assert.notNull(coupon, "未查询到匹配的优惠券信息[id=" + couponUser.getCouponId() + "]"); Assert.notNull(coupon, "未查询到匹配的优惠券信息[id=" + couponUser.getCouponId() + "]");
...@@ -106,22 +107,33 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -106,22 +107,33 @@ public class CouponUserServiceImpl implements ICouponUserService {
/** /**
* 查询用户可用优惠券数量 * 查询用户可用优惠券数量
* *
* @param userId * @param custId
* @return * @return
*/ */
@Override @Override
public int getUserAvailableCouponCnt(Long userId) { public int getCustAvailableCouponCnt(String custId) {
return couponUserMapper.getUserAvailableCouponCnt(userId, LocalDateTime.now()); return couponUserMapper.getCustAvailableCouponCnt(custId, LocalDateTime.now());
} }
/** /**
* 查询用户可用优惠券列表 * 查询用户可用优惠券列表
* *
* @param userId * @param custId
* @return * @return
*/ */
@Override @Override
public List<CouponVo> listUserAvailableCoupon(Long userId) { public List<CouponVo> listCustAvailableCoupon(String custId) {
return couponUserMapper.listUserAvailableCoupon(userId, LocalDateTime.now()); return couponUserMapper.listCustAvailableCoupon(custId, LocalDateTime.now());
}
/**
* 查询用户领取优惠券列表
*
* @param couponUser
* @return
*/
@Override
public List<CouponUserVo> selectCouponUserList(CouponUser couponUser) {
return couponUserMapper.selectCouponUserList(couponUser);
} }
} }
package com.soss.system.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Component
@Slf4j
public class AreaUtil {
// private Map<String, Area> areaMap;
private Map<String, String> areaDeepMap = new HashMap<>();
@PostConstruct
public void init() {
try {
ClassPathResource resource = new ClassPathResource("province.json");
BufferedReader bufferedReader = new BufferedReader(new FileReader(resource.getFile()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
JSONArray areaArray = JSONArray.parseArray(builder.toString());
// areaMap = buildAreaTree(areaArray);
deepAreaTree(areaArray, "");
} catch (IOException e) {
log.error("解析区域文件出错", e);
}
}
private void deepAreaTree(JSONArray areaArray, String parentName) {
if (CollectionUtils.isEmpty(areaArray)) {
return;
}
for (int i = 0; i < areaArray.size(); i++) {
JSONObject area = areaArray.getJSONObject(i);
String code = area.getString("value");
String label = area.getString("label");
String curLabel = parentName + label;
areaDeepMap.put(code, curLabel);
JSONArray children = area.getJSONArray("children");
deepAreaTree(children, curLabel);
}
}
public String getAreaNameByCode(String code) {
return areaDeepMap.get(code);
}
/*private Map<String, Area> buildAreaTree(JSONArray areaArray) {
if (CollectionUtils.isEmpty(areaArray)) {
return null;
}
Map<String, Area> areaMap = new HashMap<>();
for (int i = 0; i < areaArray.size(); i++) {
JSONObject area = areaArray.getJSONObject(i);
String code = area.getString("value");
String label = area.getString("label");
JSONArray children = area.getJSONArray("children");
areaMap.put(code, new Area(label, buildAreaTree(children)));
}
return areaMap;
}
public <T> void translateArea(List<T> ts) throws Exception {
if (CollectionUtils.isEmpty(ts)) {
return;
}
Map<String, Field> tfdMap = ReflectUtil.getFields(ts.get(0));
for (T t : ts) {
Map<String, Area> cityMap = translate(t, "province", "provinceDesc", tfdMap, areaMap);
if (cityMap == null) continue;
Map<String, Area> areaMap = translate(t, "city", "cityDesc", tfdMap, cityMap);
if (areaMap == null) continue;
translate(t, "area", "areaDesc", tfdMap, areaMap);
}
}
private <T> Map<String, Area> translate(T t, String codeFieldName, String descFieldName,
Map<String, Field> tfdMap, Map<String, Area> areaMap) throws Exception {
if (CollectionUtils.isEmpty(areaMap)) {
return null;
}
Field provField = tfdMap.get(codeFieldName);
Field provDescField = tfdMap.get(descFieldName);
if (provField == null || provDescField == null) {
return null;
}
ReflectUtil.accessField(provField, provDescField);
String province = (String) provField.get(t);
if (!StringUtils.hasText(province)) {
return null;
}
Area area = areaMap.get(province);
if (area == null) return null;
provDescField.set(t, area.getLabel());
return area.getChildren();
}
@Data
@AllArgsConstructor
class Area {
private String label;
private Map<String, Area> children;
}*/
}
package com.soss.system.utils;
import com.soss.common.utils.StringUtils;
import java.util.Arrays;
import java.util.List;
public class CollectionUtil {
public static <T> void listAddArray(List<T> lst, T[] ts) {
if (hasContents(ts)) {
lst.addAll(Arrays.asList(ts));
}
}
public static <T> boolean hasContents(T[] ts) {
return ts != null && ts.length > 0;
}
public static String[] transStrToCodeList(String codeStr) {
return StringUtils.isEmpty(codeStr) ? null : codeStr.split(",");
}
public static Long[] transStrToLongList(String idsStr) {
if (StringUtils.isEmpty(idsStr)) {
return null;
}
return Arrays.stream(idsStr.split(",")).map(Long::parseLong).toArray(Long[]::new);
}
}
package com.soss.system.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 反射工具类
*/
public class ReflectUtil {
/**
* 获取类的全部方法,以字典形式返回
*
* @param t
* @param <T>
* @return
*/
public static <T> Map<String, Method> getMethod(T t) {
Class tempClass = t.getClass();
Map<String, Method> methodMap = new ConcurrentHashMap<>();
while (tempClass != null) {
Method[] declaredMethods = tempClass.getDeclaredMethods();
for (Method method : declaredMethods) {
if (!methodMap.containsKey(method.getName())) {
methodMap.put(method.getName(), method);
}
}
tempClass = tempClass.getSuperclass();
}
return methodMap;
}
/**
* 获取类的全部属性
*
* @param t
* @param <T>
* @return
*/
public static <T> Map<String, Field> getFields(T t) {
Class tempClass = t.getClass();
Map<String, Field> fieldMap = new ConcurrentHashMap<>();
while (tempClass != null) {
Field[] declaredFields = tempClass.getDeclaredFields();
for (Field field : declaredFields) {
if (!fieldMap.containsKey(field.getName())) {
fieldMap.put(field.getName(), field);
}
}
tempClass = tempClass.getSuperclass();
}
return fieldMap;
}
public static void accessField(Field... fields) {
Arrays.stream(fields).forEach(field -> {
if (field != null && !field.isAccessible()) {
field.setAccessible(true);
}
});
}
}
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.soss.system.domain.CouponUser"> <resultMap id="BaseResultMap" type="com.soss.system.domain.CouponUser">
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="user_id" property="userId"/> <result column="cust_id" property="custId"/>
<result column="user_name" property="userName"/> <result column="cust_name" property="custName"/>
<result column="user_phone" property="userPhone"/> <result column="cust_phone" property="custPhone"/>
<result column="order_id" property="orderId"/> <result column="order_id" property="orderId"/>
<result column="coupon_id" property="couponId"/> <result column="coupon_id" property="couponId"/>
<result column="receive_time" property="receiveTime"/> <result column="receive_time" property="receiveTime"/>
...@@ -26,29 +26,46 @@ ...@@ -26,29 +26,46 @@
where coupon_id = #{couponId} where coupon_id = #{couponId}
</select> </select>
<select id="getUserAvailableCouponCnt" resultType="java.lang.Integer"> <select id="getCustAvailableCouponCnt" resultType="java.lang.Integer">
select count(*) select count(*)
<include refid="selectUserAvailableCoupon"/> <include refid="selectCustAvailableCoupon"/>
</select> </select>
<select id="listUserAvailableCoupon" resultType="com.soss.system.domain.vo.CouponVo"> <select id="listCustAvailableCoupon" resultType="com.soss.system.domain.vo.CouponVo">
select cu.id, cc.`type`, cc.name categoryName, cr.name ruleName, cr.`desc` ruleDesc, c.name, cr.use_start_time select cu.id, cc.`type`, cc.name categoryName, cr.name ruleName, cr.`desc` ruleDesc, c.name, cr.use_start_time
useStartTime, cu.expired_time useEndTime, cc.`desc` categoryDesc, cr.category_ids categoryIds, cr.goods_ids useStartTime, cu.expired_time useEndTime, cc.`desc` categoryDesc, cr.category_ids categoryIdStr, cr.goods_ids
goodsIds, cr.province, cr.city, cr.area, cr.shop_ids shopIds goodsIdStr, cr.province provinceStr, cr.city cityStr, cr.area areaStr, cr.shop_ids shopIdStr
<include refid="selectUserAvailableCoupon"/> <include refid="selectCustAvailableCoupon"/>
</select> </select>
<sql id="selectUserAvailableCoupon"> <sql id="selectCustAvailableCoupon">
from coupon_user cu from coupon_user cu
left join coupon c on cu.coupon_id = c.id left join coupon c on cu.coupon_id = c.id
left join coupon_category cc on c.category_id = cc.id left join coupon_category cc on c.category_id = cc.id
left join coupon_rule cr on c.rule_id = cr.id left join coupon_rule cr on c.rule_id = cr.id
where cu.user_id = #{userId} and cr.use_start_time &lt; #{nowTime} and cu.expired_time > #{nowTime} where cu.cust_id = #{custId} and cr.use_start_time &lt; #{nowTime} and cu.expired_time > #{nowTime}
and cu.state = ${@com.soss.common.enums.CouponUserState @DEFAULT.getState} and cu.state = ${@com.soss.common.enums.CouponUserState @DEFAULT.getState}
</sql> </sql>
<select id="getUserAvailableCouponList" resultMap="BaseResultMap"> <select id="selectCouponUserList" resultType="com.soss.system.domain.vo.CouponUserVo">
select cu.id, cu.cust_id custId, cu.cust_name custName, cu.cust_phone custPhone, cu.order_id orderId,
cu.order_no orderNo, c.name couponName, cu.source, cu.`type`, cu.receive_time receiveTime,
cr.use_start_time startTime, cu.expired_time expiredTime, cu.state
from coupon_user cu
left join coupon c on cu.coupon_id = c.id
left join coupon_rule cr on c.rule_id = cr.id
<where>
<if test="source != null">
and cu.source like concat("%", #{source}, "%")
</if>
<if test="couponId != null">
and cu.coupon_id = #{couponId}
</if>
<if test="state != null">
and cu.state = #{state}
</if>
</where>
order by cu.id desc
</select> </select>
<select id="getUserCouponInfo" resultMap="BaseResultMap"> <select id="getUserCouponInfo" resultMap="BaseResultMap">
...@@ -59,9 +76,9 @@ ...@@ -59,9 +76,9 @@
keyProperty="id"> keyProperty="id">
insert into coupon_user insert into coupon_user
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if> <if test="custId != null">cust_id,</if>
<if test="userName != null and userName != ''">user_name,</if> <if test="custName != null and custName != ''">cust_name,</if>
<if test="userPhone != null and userPhone != ''">user_phone,</if> <if test="custPhone != null and custPhone != ''">cust_phone,</if>
<if test="orderId != null">order_id,</if> <if test="orderId != null">order_id,</if>
<if test="couponId != null">coupon_id,</if> <if test="couponId != null">coupon_id,</if>
<if test="receiveTime != null">receive_time,</if> <if test="receiveTime != null">receive_time,</if>
...@@ -75,9 +92,9 @@ ...@@ -75,9 +92,9 @@
<if test="updatedAt != null">updated_at,</if> <if test="updatedAt != null">updated_at,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if> <if test="custId != null">#{custId},</if>
<if test="userName != null and userName != ''">#{userName},</if> <if test="custName != null and custName != ''">#{custName},</if>
<if test="userPhone != null and userPhone != ''">#{userPhone},</if> <if test="custPhone != null and custPhone != ''">#{custPhone},</if>
<if test="orderId != null">#{orderId},</if> <if test="orderId != null">#{orderId},</if>
<if test="couponId != null">#{couponId},</if> <if test="couponId != null">#{couponId},</if>
<if test="receiveTime != null">#{receiveTime},</if> <if test="receiveTime != null">#{receiveTime},</if>
...@@ -95,9 +112,9 @@ ...@@ -95,9 +112,9 @@
<update id="updateCouponUser" parameterType="com.soss.system.domain.CouponUser"> <update id="updateCouponUser" parameterType="com.soss.system.domain.CouponUser">
update coupon_user update coupon_user
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if> <if test="custId != null">cust_id = #{custId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if> <if test="custName != null and custName != ''">cust_name = #{custName},</if>
<if test="userPhone != null and userPhone != ''">user_phone = #{userPhone},</if> <if test="custPhone != null and custPhone != ''">cust_phone = #{custPhone},</if>
<if test="orderId != null">order_id = #{orderId},</if> <if test="orderId != null">order_id = #{orderId},</if>
<if test="couponId != null">coupon_id = #{couponId},</if> <if test="couponId != null">coupon_id = #{couponId},</if>
<if test="receiveTime != null">receive_time = #{receiveTime},</if> <if test="receiveTime != null">receive_time = #{receiveTime},</if>
......
...@@ -24,23 +24,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -24,23 +24,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectGoodsCategoryVo"/> <include refid="selectGoodsCategoryVo"/>
<where> <where>
and is_deleted = 0 and is_deleted = 0
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="remarks != null and remarks != ''"> and remarks = #{remarks}</if> <if test="remarks != null and remarks != ''">and remarks = #{remarks}</if>
<if test="turn != null and turn != ''"> and turn = #{turn}</if> <if test="turn != null and turn != ''">and turn = #{turn}</if>
<if test="state != null and state != ''"> and state = #{state}</if> <if test="state != null and state != ''">and state = #{state}</if>
<if test="createdAt != null "> and created_at = #{createdAt}</if> <if test="createdAt != null ">and created_at = #{createdAt}</if>
<if test="updatedAt != null "> and updated_at = #{updatedAt}</if> <if test="updatedAt != null ">and updated_at = #{updatedAt}</if>
<if test="code != null and code != ''"> and code = #{code}</if> <if test="code != null and code != ''">and code = #{code}</if>
</where> </where>
order by turn order by turn
</select> </select>
<select id="selectGoodsCategoryByIds" resultMap="GoodsCategoryResult">
select id, name from goods_category where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select>
<select id="selectGoodsCategoryById" parameterType="String" resultMap="GoodsCategoryResult"> <select id="selectGoodsCategoryById" parameterType="String" resultMap="GoodsCategoryResult">
<include refid="selectGoodsCategoryVo"/> <include refid="selectGoodsCategoryVo"/>
where id = #{id} where id = #{id}
and is_deleted = 0 and is_deleted = 0
</select> </select>
<insert id="insertGoodsCategory" parameterType="GoodsCategory" useGeneratedKeys="true" keyProperty="id"> <insert id="insertGoodsCategory" parameterType="GoodsCategory" useGeneratedKeys="true" keyProperty="id">
insert into goods_category insert into goods_category
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
......
...@@ -17,9 +17,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -17,9 +17,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remarks" column="remarks" /> <result property="remarks" column="remarks" />
<result property="state" column="state" /> <result property="state" column="state" />
<result property="isDeleted" column="is_deleted" /> <result property="isDeleted" column="is_deleted" />
<result property="createdAt" column="created_at" /> <result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at" /> <result property="updatedAt" column="updated_at"/>
<result property="code" column="code" /> <result property="code" column="code"/>
<result property="shelfAt" column="shelf_at"/> <result property="shelfAt" column="shelf_at"/>
<result property="categoryName" column="categoryName"/> <result property="categoryName" column="categoryName"/>
</resultMap> </resultMap>
...@@ -28,15 +28,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -28,15 +28,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, name, category, price, discount, take_time, spec, pics, `desc`, remarks, state, is_deleted, created_at, updated_at, code,shelf_at from goods select id, name, category, price, discount, take_time, spec, pics, `desc`, remarks, state, is_deleted, created_at, updated_at, code,shelf_at from goods
</sql> </sql>
<select id="selectGoodsByIds" resultMap="GoodsResult">
select id, name from goods where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select>
<select id="selectGoodsList" parameterType="Goods" resultMap="GoodsResult"> <select id="selectGoodsList" parameterType="Goods" resultMap="GoodsResult">
<include refid="selectGoodsVo"/> <include refid="selectGoodsVo"/>
<where> <where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="category != null and category != ''"> and category = #{category}</if> <if test="category != null and category != ''">and category = #{category}</if>
<if test="price != null "> and price = #{price}</if> <if test="price != null ">and price = #{price}</if>
<if test="discount != null "> and discount = #{discount}</if> <if test="discount != null ">and discount = #{discount}</if>
<if test="takeTime != null "> and take_time = #{takeTime}</if> <if test="takeTime != null ">and take_time = #{takeTime}</if>
<if test="spec != null and spec != ''"> and spec = #{spec}</if> <if test="spec != null and spec != ''">and spec = #{spec}</if>
<if test="pics != null and pics != ''"> and pics = #{pics}</if> <if test="pics != null and pics != ''"> and pics = #{pics}</if>
<if test="desc != null and desc != ''"> and `desc` = #{desc}</if> <if test="desc != null and desc != ''"> and `desc` = #{desc}</if>
<if test="remarks != null and remarks != ''"> and remarks = #{remarks}</if> <if test="remarks != null and remarks != ''"> and remarks = #{remarks}</if>
......
...@@ -40,24 +40,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -40,24 +40,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="lat != null and lat != ''">and s.lat = #{lat}</if> <if test="lat != null and lat != ''">and s.lat = #{lat}</if>
<if test="remarks != null and remarks != ''">and s.remarks = #{remarks}</if> <if test="remarks != null and remarks != ''">and s.remarks = #{remarks}</if>
<if test="startTime != null and startTime != ''">and s.start_time = #{startTime}</if> <if test="startTime != null and startTime != ''">and s.start_time = #{startTime}</if>
<if test="endTime != null and endTime != ''"> and s.end_time = #{endTime}</if> <if test="endTime != null and endTime != ''">and s.end_time = #{endTime}</if>
<if test="address != null and address != ''"> and s.address = #{address}</if> <if test="address != null and address != ''">and s.address = #{address}</if>
<if test="province != null and province != ''"> and s.province = #{province}</if> <if test="province != null and province != ''">and s.province = #{province}</if>
<if test="city != null and city != ''"> and s.city = #{city}</if> <if test="city != null and city != ''">and s.city = #{city}</if>
<if test="zone != null and zone != ''"> and s.zone = #{zone}</if> <if test="zone != null and zone != ''">and s.zone = #{zone}</if>
<if test="state != null and state != ''"> and s.state = #{state}</if> <if test="state != null and state != ''">and s.state = #{state}</if>
<if test="createdAt != null "> and s.created_at = #{createdAt}</if> <if test="createdAt != null ">and s.created_at = #{createdAt}</if>
<if test="updatedAt != null "> and s.updated_at = #{updatedAt}</if> <if test="updatedAt != null ">and s.updated_at = #{updatedAt}</if>
<if test="isDefault != null "> and s.is_default = #{isDefault}</if> <if test="isDefault != null ">and s.is_default = #{isDefault}</if>
<if test="machineCode!=null and machineCode != ''"> and m.code =#{machineCode}</if> <if test="machineCode!=null and machineCode != ''">and m.code =#{machineCode}</if>
</where> </where>
</select> </select>
<select id="selectShopById" parameterType="String" resultMap="ShopResult"> <select id="selectShopById" parameterType="String" resultMap="ShopResult">
<include refid="selectShopVo"/> <include refid="selectShopVo"/>
where id = #{id} where id = #{id}
</select> </select>
<select id="selectShopByIds" resultMap="ShopResult">
select id, name, zone from shop where id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
</select>
<insert id="insertShop" parameterType="Shop" useGeneratedKeys="true" keyProperty="id"> <insert id="insertShop" parameterType="Shop" useGeneratedKeys="true" keyProperty="id">
insert into shop insert into shop
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
......
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