From 385b2227cfc504963e5876ae772cd70269784752 Mon Sep 17 00:00:00 2001 From: 199901012 Date: Sun, 4 Apr 2021 15:50:03 +0800 Subject: [PATCH] =?UTF-8?q?'=E5=AE=8C=E6=88=90=E7=94=A8=E6=88=B7=E9=A2=86?= =?UTF-8?q?=E5=8F=96=E4=BC=98=E6=83=A0=E5=88=B8=E6=8E=A5=E5=8F=A3'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighDiscountController.java | 4 +- .../HighDiscountCouponRelController.java | 3 +- .../controller/HighDiscountController.java | 76 +++++++++++ .../HighUserDiscountController.java | 97 ++++++++++++++ .../com/hai/common/exception/ErrorCode.java | 1 + .../hai/dao/HighDiscountUserRelMapper.java | 12 +- .../dao/HighDiscountUserRelSqlProvider.java | 16 +-- .../com/hai/entity/HighDiscountUserRel.java | 22 ++-- .../entity/HighDiscountUserRelExample.java | 48 +++---- .../hai/model/HighDiscountUserRelModel.java | 34 +++++ .../service/HighDiscountUserRelService.java | 37 ++++++ .../impl/HighDiscountUserRelServiceImpl.java | 120 ++++++++++++++++++ 12 files changed, 418 insertions(+), 52 deletions(-) create mode 100644 hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java create mode 100644 hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java create mode 100644 hai-service/src/main/java/com/hai/model/HighDiscountUserRelModel.java create mode 100644 hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java create mode 100644 hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java index b6869fb0..bb6cb574 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java @@ -130,7 +130,7 @@ public class HighDiscountController { } - @RequestMapping(value="/getDiscountById",method = RequestMethod.POST) + @RequestMapping(value="/getDiscountById",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据id查询") public ResponseData getDiscountById(@RequestParam(name = "id", required = true) Long id) { @@ -144,7 +144,7 @@ public class HighDiscountController { } } - @RequestMapping(value="/getDiscountList",method = RequestMethod.POST) + @RequestMapping(value="/getDiscountList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询优惠券列表") public ResponseData getDiscountList(@RequestParam(name = "discountKey", required = false) String discountKey, diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java index 123b7df1..f25b5493 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java @@ -54,7 +54,6 @@ public class HighDiscountCouponRelController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "重复增加"); } - HighDiscountCouponRel rel = new HighDiscountCouponRel(); rel.setDiscountId(discountId); rel.setCouponId(couponId); @@ -92,7 +91,7 @@ public class HighDiscountCouponRelController { } } - @RequestMapping(value="/insertDiscount",method = RequestMethod.POST) + @RequestMapping(value="/insertDiscount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据卡卷 查询关联卡券") public ResponseData getRelByDiscount(@RequestParam(name = "discountId", required = true) Long discountId) { diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java new file mode 100644 index 00000000..06658914 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java @@ -0,0 +1,76 @@ +package com.cweb.controller; + +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.AESEncodeUtil; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.model.ResponseData; +import com.hai.service.HighDiscountAgentRelService; +import com.hai.service.HighDiscountCouponRelService; +import com.hai.service.HighDiscountUserRelService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/4 14:46 + */ +@Controller +@RequestMapping(value = "/discount") +@Api(value = "优惠券接口") +public class HighDiscountController { + + private static Logger log = LoggerFactory.getLogger(HighDiscountController.class); + + @Resource + private HighDiscountAgentRelService highDiscountAgentRelService; + + @Resource + private HighDiscountCouponRelService highDiscountCouponRelService; + + @Resource + private HighDiscountUserRelService highDiscountUserRelService; + + @RequestMapping(value="/getDiscountByQrCode",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据二维码Code查询") + public ResponseData getDiscountByQrCode(@RequestParam(name = "code", required = true) String code) { + try { + String relId; + try { + relId = AESEncodeUtil.aesDecrypt(code); + } catch (Exception e) { + log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误"); + } + return ResponseMsgUtil.success(highDiscountAgentRelService.getRelById(Long.parseLong(relId))); + + } catch (Exception e) { + log.error("HighDiscountController -> getDiscountByQrCode() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getCouponByDiscount",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "根据优惠券查询卡券") + public ResponseData getCouponByDiscount(@RequestParam(name = "discountId", required = true) Long discountId) { + try { + + return ResponseMsgUtil.success(highDiscountCouponRelService.getRelByDiscount(discountId)); + + } catch (Exception e) { + log.error("HighDiscountController -> getCouponByDiscount() error!",e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java new file mode 100644 index 00000000..a5f87994 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -0,0 +1,97 @@ +package com.cweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.SessionObject; +import com.hai.common.security.UserCenter; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.model.HighUserModel; +import com.hai.model.ResponseData; +import com.hai.service.HighDiscountUserRelService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/4 15:41 + */ +@Controller +@RequestMapping(value = "/userDiscount") +@Api(value = "用户优惠券接口") +public class HighUserDiscountController { + + private static Logger log = LoggerFactory.getLogger(HighUserDiscountController.class); + + @Autowired + private UserCenter userCenter; + + @Resource + private HighDiscountUserRelService highDiscountUserRelService; + + @RequestMapping(value="/receiveDiscount",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "用户领取优惠券") + public ResponseData receiveDiscount(@RequestBody String reqBody, HttpServletRequest request) { + try { + + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + JSONObject jsonObject = JSONObject.parseObject(reqBody); + Long discountAgentId = jsonObject.getLong("discountAgentId"); + if (discountAgentId == null) { + log.error("HighDiscountController -> receiveDiscount() error!", "参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + // 领取成功 + highDiscountUserRelService.receiveDiscount(userInfoModel.getHighUser().getId(), discountAgentId); + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("HighDiscountController -> receiveDiscount() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getUserDiscountList",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "获取用户的优惠券列表") + public ResponseData getUserDiscountList(@RequestParam(name = "status", required = false) Integer status, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize, + HttpServletRequest request) { + try { + + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + map.put("userId", userInfoModel.getHighUser().getId()); + map.put("status", status); + + PageHelper.startPage(pageNum,pageSize); + return ResponseMsgUtil.success(new PageInfo<>(highDiscountUserRelService.getDiscountList(map))); + + } catch (Exception e) { + log.error("HighDiscountController -> receiveDiscount() error!",e); + return ResponseMsgUtil.exception(e); + } + } +} diff --git a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java index 7f78caa0..5a6aabf3 100644 --- a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java +++ b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java @@ -107,6 +107,7 @@ public enum ErrorCode { AGENT_NAME("2124","代理商名称已存在"), NOT_FOUND_DISCOUNT("2125","未找到优惠券信息"), NOT_FOUND_AGENT("2126","未找到代理商信息"), + DISCOUNT_STOCK_COUNT_ERROR("2127","优惠券库存数量不足"), STATUS_ERROR("3000","状态错误"), ADD_DATA_ERROR("3001","增加数据失败"), diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java index f147d09a..9a3e0d47 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java @@ -39,11 +39,11 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt int deleteByPrimaryKey(Long id); @Insert({ - "insert into high_discount_user_rel (discount_id, ageent_id, ", + "insert into high_discount_user_rel (discount_id, agent_id, ", "user_id, `status`, create_time, ", "use_end_time, ext_1, ", "ext_2, ext_3)", - "values (#{discountId,jdbcType=BIGINT}, #{ageentId,jdbcType=BIGINT}, ", + "values (#{discountId,jdbcType=BIGINT}, #{agentId,jdbcType=BIGINT}, ", "#{userId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", "#{useEndTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" @@ -59,7 +59,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="discount_id", property="discountId", jdbcType=JdbcType.BIGINT), - @Result(column="ageent_id", property="ageentId", jdbcType=JdbcType.BIGINT), + @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @@ -72,7 +72,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Select({ "select", - "id, discount_id, ageent_id, user_id, `status`, create_time, use_end_time, ext_1, ", + "id, discount_id, agent_id, user_id, `status`, create_time, use_end_time, ext_1, ", "ext_2, ext_3", "from high_discount_user_rel", "where id = #{id,jdbcType=BIGINT}" @@ -80,7 +80,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="discount_id", property="discountId", jdbcType=JdbcType.BIGINT), - @Result(column="ageent_id", property="ageentId", jdbcType=JdbcType.BIGINT), + @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @@ -103,7 +103,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Update({ "update high_discount_user_rel", "set discount_id = #{discountId,jdbcType=BIGINT},", - "ageent_id = #{ageentId,jdbcType=BIGINT},", + "agent_id = #{agentId,jdbcType=BIGINT},", "user_id = #{userId,jdbcType=BIGINT},", "`status` = #{status,jdbcType=INTEGER},", "create_time = #{createTime,jdbcType=TIMESTAMP},", diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java index 1a2c2fda..4eda9831 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java @@ -32,8 +32,8 @@ public class HighDiscountUserRelSqlProvider { sql.VALUES("discount_id", "#{discountId,jdbcType=BIGINT}"); } - if (record.getAgeentId() != null) { - sql.VALUES("ageent_id", "#{ageentId,jdbcType=BIGINT}"); + if (record.getAgentId() != null) { + sql.VALUES("agent_id", "#{agentId,jdbcType=BIGINT}"); } if (record.getUserId() != null) { @@ -75,7 +75,7 @@ public class HighDiscountUserRelSqlProvider { sql.SELECT("id"); } sql.SELECT("discount_id"); - sql.SELECT("ageent_id"); + sql.SELECT("agent_id"); sql.SELECT("user_id"); sql.SELECT("`status`"); sql.SELECT("create_time"); @@ -108,8 +108,8 @@ public class HighDiscountUserRelSqlProvider { sql.SET("discount_id = #{record.discountId,jdbcType=BIGINT}"); } - if (record.getAgeentId() != null) { - sql.SET("ageent_id = #{record.ageentId,jdbcType=BIGINT}"); + if (record.getAgentId() != null) { + sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}"); } if (record.getUserId() != null) { @@ -150,7 +150,7 @@ public class HighDiscountUserRelSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("discount_id = #{record.discountId,jdbcType=BIGINT}"); - sql.SET("ageent_id = #{record.ageentId,jdbcType=BIGINT}"); + sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}"); sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); @@ -172,8 +172,8 @@ public class HighDiscountUserRelSqlProvider { sql.SET("discount_id = #{discountId,jdbcType=BIGINT}"); } - if (record.getAgeentId() != null) { - sql.SET("ageent_id = #{ageentId,jdbcType=BIGINT}"); + if (record.getAgentId() != null) { + sql.SET("agent_id = #{agentId,jdbcType=BIGINT}"); } if (record.getUserId() != null) { diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java index af231a88..90197178 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java @@ -1,5 +1,7 @@ package com.hai.entity; +import com.hai.model.HighDiscountUserRelModel; + import java.io.Serializable; import java.util.Date; @@ -12,7 +14,7 @@ import java.util.Date; * 代码由工具生成 * **/ -public class HighDiscountUserRel implements Serializable { +public class HighDiscountUserRel extends HighDiscountUserRelModel implements Serializable { /** * 主键 */ @@ -26,7 +28,7 @@ public class HighDiscountUserRel implements Serializable { /** * 代理商id */ - private Long ageentId; + private Long agentId; /** * 用户id @@ -72,12 +74,12 @@ public class HighDiscountUserRel implements Serializable { this.discountId = discountId; } - public Long getAgeentId() { - return ageentId; + public Long getAgentId() { + return agentId; } - public void setAgeentId(Long ageentId) { - this.ageentId = ageentId; + public void setAgentId(Long agentId) { + this.agentId = agentId; } public Long getUserId() { @@ -150,7 +152,7 @@ public class HighDiscountUserRel implements Serializable { HighDiscountUserRel other = (HighDiscountUserRel) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getDiscountId() == null ? other.getDiscountId() == null : this.getDiscountId().equals(other.getDiscountId())) - && (this.getAgeentId() == null ? other.getAgeentId() == null : this.getAgeentId().equals(other.getAgeentId())) + && (this.getAgentId() == null ? other.getAgentId() == null : this.getAgentId().equals(other.getAgentId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) @@ -166,7 +168,7 @@ public class HighDiscountUserRel implements Serializable { int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getDiscountId() == null) ? 0 : getDiscountId().hashCode()); - result = prime * result + ((getAgeentId() == null) ? 0 : getAgeentId().hashCode()); + result = prime * result + ((getAgentId() == null) ? 0 : getAgentId().hashCode()); result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); @@ -185,7 +187,7 @@ public class HighDiscountUserRel implements Serializable { sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", discountId=").append(discountId); - sb.append(", ageentId=").append(ageentId); + sb.append(", agentId=").append(agentId); sb.append(", userId=").append(userId); sb.append(", status=").append(status); sb.append(", createTime=").append(createTime); @@ -197,4 +199,4 @@ public class HighDiscountUserRel implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java index 58d588fb..2d0f92c9 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java @@ -245,63 +245,63 @@ public class HighDiscountUserRelExample { return (Criteria) this; } - public Criteria andAgeentIdIsNull() { - addCriterion("ageent_id is null"); + public Criteria andAgentIdIsNull() { + addCriterion("agent_id is null"); return (Criteria) this; } - public Criteria andAgeentIdIsNotNull() { - addCriterion("ageent_id is not null"); + public Criteria andAgentIdIsNotNull() { + addCriterion("agent_id is not null"); return (Criteria) this; } - public Criteria andAgeentIdEqualTo(Long value) { - addCriterion("ageent_id =", value, "ageentId"); + public Criteria andAgentIdEqualTo(Long value) { + addCriterion("agent_id =", value, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdNotEqualTo(Long value) { - addCriterion("ageent_id <>", value, "ageentId"); + public Criteria andAgentIdNotEqualTo(Long value) { + addCriterion("agent_id <>", value, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdGreaterThan(Long value) { - addCriterion("ageent_id >", value, "ageentId"); + public Criteria andAgentIdGreaterThan(Long value) { + addCriterion("agent_id >", value, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdGreaterThanOrEqualTo(Long value) { - addCriterion("ageent_id >=", value, "ageentId"); + public Criteria andAgentIdGreaterThanOrEqualTo(Long value) { + addCriterion("agent_id >=", value, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdLessThan(Long value) { - addCriterion("ageent_id <", value, "ageentId"); + public Criteria andAgentIdLessThan(Long value) { + addCriterion("agent_id <", value, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdLessThanOrEqualTo(Long value) { - addCriterion("ageent_id <=", value, "ageentId"); + public Criteria andAgentIdLessThanOrEqualTo(Long value) { + addCriterion("agent_id <=", value, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdIn(List values) { - addCriterion("ageent_id in", values, "ageentId"); + public Criteria andAgentIdIn(List values) { + addCriterion("agent_id in", values, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdNotIn(List values) { - addCriterion("ageent_id not in", values, "ageentId"); + public Criteria andAgentIdNotIn(List values) { + addCriterion("agent_id not in", values, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdBetween(Long value1, Long value2) { - addCriterion("ageent_id between", value1, value2, "ageentId"); + public Criteria andAgentIdBetween(Long value1, Long value2) { + addCriterion("agent_id between", value1, value2, "agentId"); return (Criteria) this; } - public Criteria andAgeentIdNotBetween(Long value1, Long value2) { - addCriterion("ageent_id not between", value1, value2, "ageentId"); + public Criteria andAgentIdNotBetween(Long value1, Long value2) { + addCriterion("agent_id not between", value1, value2, "agentId"); return (Criteria) this; } diff --git a/hai-service/src/main/java/com/hai/model/HighDiscountUserRelModel.java b/hai-service/src/main/java/com/hai/model/HighDiscountUserRelModel.java new file mode 100644 index 00000000..440613f0 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/HighDiscountUserRelModel.java @@ -0,0 +1,34 @@ +package com.hai.model; + +import com.hai.entity.HighAgent; +import com.hai.entity.HighDiscount; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/4 15:37 + */ +public class HighDiscountUserRelModel { + + // 优惠券信息 + private HighDiscount highDiscount; + + // 代理商信息 + private HighAgent highAgent; + + public HighDiscount getHighDiscount() { + return highDiscount; + } + + public void setHighDiscount(HighDiscount highDiscount) { + this.highDiscount = highDiscount; + } + + public HighAgent getHighAgent() { + return highAgent; + } + + public void setHighAgent(HighAgent highAgent) { + this.highAgent = highAgent; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java new file mode 100644 index 00000000..7778a594 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java @@ -0,0 +1,37 @@ +package com.hai.service; + +import com.hai.entity.HighDiscountAgentRel; +import com.hai.entity.HighDiscountUserRel; + +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/4 15:10 + */ +public interface HighDiscountUserRelService { + + /** + * @Author 胡锐 + * @Description 领取卡券 + * @Date 2021/4/4 15:12 + **/ + void receiveDiscount(Long userId,Long discountAgentId); + + /** + * @Author 胡锐 + * @Description + * @Date 2021/4/4 15:45 + **/ + HighDiscountUserRel getRelByUserDiscount(Long userId,Long discountId); + + /** + * @Author 胡锐 + * @Description 查询优惠券列表 + * @Date 2021/4/4 15:35 + **/ + List getDiscountList(Map map); + +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java new file mode 100644 index 00000000..c96d28a8 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -0,0 +1,120 @@ +package com.hai.service.impl; + +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.dao.HighDiscountUserRelMapper; +import com.hai.entity.HighDiscount; +import com.hai.entity.HighDiscountAgentRel; +import com.hai.entity.HighDiscountUserRel; +import com.hai.entity.HighDiscountUserRelExample; +import com.hai.service.HighAgentService; +import com.hai.service.HighDiscountAgentRelService; +import com.hai.service.HighDiscountService; +import com.hai.service.HighDiscountUserRelService; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/4 15:12 + */ +@Service("highDiscountUserRelService") +public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelService { + + @Resource + private HighDiscountUserRelMapper highDiscountUserRelMapper; + + @Resource + private HighDiscountAgentRelService highDiscountAgentRelService; + + @Resource + private HighAgentService highAgentService; + + @Resource + private HighDiscountService highDiscountService; + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void receiveDiscount(Long userId, Long discountAgentId) { + + // 查询优惠券信息 + HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(discountAgentId); + if (rel == null || rel.getHighDiscount() == null || rel.getAgentId() == null){ + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); + } + // 校验卡卷状态 + if (rel.getHighDiscount().getStatus() != 2) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已下架"); + } + if (rel.getStockCount() <= 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.DISCOUNT_STOCK_COUNT_ERROR, ""); + } + + // 校验是否重复领取 + HighDiscountUserRelExample example = new HighDiscountUserRelExample(); + example.createCriteria().andUserIdEqualTo(userId).andDiscountIdEqualTo(rel.getDiscountId()).andStatusEqualTo(1); + if (highDiscountUserRelMapper.selectByExample(example).size() > 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "重复领取卡券,请使用后再进行领取"); + } + + HighDiscountUserRel userRel = new HighDiscountUserRel(); + userRel.setDiscountId(rel.getDiscountId()); + userRel.setAgentId(rel.getAgentId()); + userRel.setUserId(userId); + userRel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + userRel.setCreateTime(new Date()); + // 计算使用有效期 + Calendar userEndTime = Calendar.getInstance(); + userEndTime.add(Calendar.DATE, rel.getHighDiscount().getEffectiveDay()); + if (userEndTime.getTime().compareTo(rel.getHighDiscount().getSalesEndTime()) == 1) { + userRel.setUseEndTime(rel.getHighDiscount().getSalesEndTime()); + } else { + userRel.setUseEndTime(userEndTime.getTime()); + } + highDiscountUserRelMapper.insert(userRel); + + } + + @Override + public HighDiscountUserRel getRelByUserDiscount(Long userId, Long discountId) { + HighDiscountUserRelExample example = new HighDiscountUserRelExample(); + example.createCriteria().andUserIdEqualTo(userId).andDiscountIdEqualTo(discountId); + List list = highDiscountUserRelMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Override + public List getDiscountList(Map map) { + HighDiscountUserRelExample example = new HighDiscountUserRelExample(); + HighDiscountUserRelExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); + } + + if (MapUtils.getInteger(map, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); + } + + example.setOrderByClause("create_time desc"); + List list = highDiscountUserRelMapper.selectByExample(example); + for (HighDiscountUserRel rel : list) { + rel.setHighDiscount(highDiscountService.getDiscountById(rel.getDiscountId())); + rel.setHighAgent(highAgentService.findByAgentMsgId(rel.getAgentId())); + } + return list; + } +}