diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java index fb7a13de..94d9f79f 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java @@ -61,7 +61,8 @@ public class HighCouponAgentController { @RequestMapping(value = "/getAgentCount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "代理商统计") - public ResponseData getAgentCount(HttpServletRequest request) { + public ResponseData getAgentCount(HttpServletRequest request, + @RequestParam(name = "type", required = true) Integer type) { try { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); @@ -71,7 +72,7 @@ public class HighCouponAgentController { throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); } - return ResponseMsgUtil.success(highCouponAgentService.getSalesCountByAgent(userInfoModel.getHighAgent().getId())); + return ResponseMsgUtil.success(highCouponAgentService.getSalesCountByAgent(userInfoModel.getHighAgent().getId(), type)); } catch (Exception e) { log.error("HighCouponAgentController --> getCodeById() error!", e); @@ -187,6 +188,7 @@ public class HighCouponAgentController { if(highCouponAgentRel.getCouponId() == null || highCouponAgentRel.getAgentId() == null + || highCouponAgentRel.getType() == null || highCouponAgentRel.getStockCount() == null) { log.error("HighCouponAgentController -> assignCouponAgent() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); @@ -207,7 +209,7 @@ public class HighCouponAgentController { } // 校验是否分配过 - HighCouponAgentRel couponAgent = highCouponAgentService.getRelByCouponAgent(highCouponAgentRel.getCouponId(), highCouponAgentRel.getAgentId()); + HighCouponAgentRel couponAgent = highCouponAgentService.getRelByCouponAgent(highCouponAgentRel.getCouponId(), highCouponAgentRel.getAgentId(), highCouponAgentRel.getType()); if (couponAgent != null) { couponAgent.setStockCount(couponAgent.getStockCount() + highCouponAgentRel.getStockCount()); couponAgent.setOperatorId(userInfoModel.getSecUser().getId()); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java index e8bd2408..0b55d2ff 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java @@ -12,7 +12,7 @@ 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.generateCode; +import com.hai.common.GenerateCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.DateUtil; @@ -620,7 +620,7 @@ public class HighCouponController { highCouponCode = new HighCouponCode(); highCouponCode.setCouponId(couponId); highCouponCode.setMerchantId(coupon.getMerchantId()); - highCouponCode.setSalesCode(generateCode.couponSalesCode(coupon.getMerchantId(), couponId)); + highCouponCode.setSalesCode(GenerateCode.couponSalesCode(coupon.getMerchantId(), couponId)); highCouponCode.setSalesEndTime(salesEndTimeC.getTime()); highCouponCode.setUseEndTime(useEndTimeC.getTime()); highCouponCode.setStatus(1); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index f86a14d9..bd90ed5c 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -93,6 +93,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/order/*") .excludePathPatterns("/coupon/getCouponList") .excludePathPatterns("/wechatpay/*") + .excludePathPatterns("/couponAgent/useConvertCode") .excludePathPatterns("/coupon/getCouponById") .excludePathPatterns("/discount/getDiscountByQrCode") .excludePathPatterns("/discount/getDiscountById") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java new file mode 100644 index 00000000..099a751a --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java @@ -0,0 +1,77 @@ +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.DateUtil; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.*; +import com.hai.model.ResponseData; +import com.hai.model.UserInfoModel; +import com.hai.service.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +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.math.BigDecimal; +import java.util.*; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/4/20 23:47 + */ +@Controller +@RequestMapping(value = "/couponAgent") +@Api(value = "代理商接口") +public class HighCouponAgentController { + + private static Logger log = LoggerFactory.getLogger(HighCouponAgentController.class); + + @Resource + private HighCouponAgentService highCouponAgentService; + + @RequestMapping(value = "/useConvertCode", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "兑换码使用") + public ResponseData useConvertCode(@RequestBody JSONObject body) { + try { + + if (body == null || StringUtils.isBlank(body.getString("code"))) { + log.error("HighCouponAgentController -> queryConvertCode() error!",""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + // 查询兑换码 + HighCouponAgentCode convertCode = highCouponAgentService.getConvertCode(body.getString("code")); + if (convertCode == null) { + log.error("HighCouponAgentController -> queryConvertCode() error!","无效的兑换码"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的兑换码"); + } + if (convertCode.getStatus() != 1) { + log.error("HighCouponAgentController -> queryConvertCode() error!","兑换码已被使用"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用"); + } + + return ResponseMsgUtil.success(highCouponAgentService.useConvertCode(body.getString("code"))); + + } catch (Exception e) { + log.error("HighCouponAgentController --> useConvertCode() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + +} diff --git a/hai-service/src/main/java/com/hai/common/generateCode.java b/hai-service/src/main/java/com/hai/common/GenerateCode.java similarity index 56% rename from hai-service/src/main/java/com/hai/common/generateCode.java rename to hai-service/src/main/java/com/hai/common/GenerateCode.java index aa6d1c27..ac87b81d 100644 --- a/hai-service/src/main/java/com/hai/common/generateCode.java +++ b/hai-service/src/main/java/com/hai/common/GenerateCode.java @@ -1,5 +1,6 @@ package com.hai.common; +import java.security.SecureRandom; import java.util.Calendar; import java.util.Random; @@ -8,8 +9,11 @@ import java.util.Random; * @Description: * @Date: 2021/3/18 21:07 */ -public class generateCode { +public class GenerateCode { + private static final Random RANDOM = new SecureRandom(); + + private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; /** * @Author 胡锐 @@ -33,4 +37,23 @@ public class generateCode { } return val; } + + /** + * 生成兑换码 + * @param couponAgentRelId + * @return + */ + public static String convertCode(Long couponAgentRelId) { + // 兑换码总长度 + int countLength = 20; + // 需要生成的长度 + int generateLength = countLength - couponAgentRelId.toString().length(); + + char[] nonceChars = new char[generateLength]; + for (int index = 0; index < nonceChars.length; ++index) { + nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length())); + } + return new String(nonceChars) + couponAgentRelId; + } + } diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeMapper.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeMapper.java index f876a552..92cb7f29 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeMapper.java @@ -39,16 +39,18 @@ public interface HighCouponAgentCodeMapper extends HighCouponAgentCodeMapperExt int deleteByPrimaryKey(Long id); @Insert({ - "insert into high_coupon_agent_code (coupon_agent_id, coupon_id, ", - "agent_id, coupon_code_id, ", - "coupon_agent_record_id, coupon_code, ", + "insert into high_coupon_agent_code (`type`, coupon_agent_id, ", + "coupon_id, agent_id, ", + "coupon_agent_record_id, convert_code, ", + "coupon_code_id, coupon_code, ", "qr_code, `status`, ", "remark, create_time, ", "operator_id, operator_name, ", "ext_1, ext_2, ext_3)", - "values (#{couponAgentId,jdbcType=BIGINT}, #{couponId,jdbcType=BIGINT}, ", - "#{agentId,jdbcType=BIGINT}, #{couponCodeId,jdbcType=BIGINT}, ", - "#{couponAgentRecordId,jdbcType=BIGINT}, #{couponCode,jdbcType=VARCHAR}, ", + "values (#{type,jdbcType=INTEGER}, #{couponAgentId,jdbcType=BIGINT}, ", + "#{couponId,jdbcType=BIGINT}, #{agentId,jdbcType=BIGINT}, ", + "#{couponAgentRecordId,jdbcType=BIGINT}, #{convertCode,jdbcType=VARCHAR}, ", + "#{couponCodeId,jdbcType=BIGINT}, #{couponCode,jdbcType=VARCHAR}, ", "#{qrCode,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ", "#{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ", "#{operatorId,jdbcType=BIGINT}, #{operatorName,jdbcType=VARCHAR}, ", @@ -64,11 +66,13 @@ public interface HighCouponAgentCodeMapper extends HighCouponAgentCodeMapperExt @SelectProvider(type=HighCouponAgentCodeSqlProvider.class, method="selectByExample") @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="type", property="type", jdbcType=JdbcType.INTEGER), @Result(column="coupon_agent_id", property="couponAgentId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), - @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_agent_record_id", property="couponAgentRecordId", jdbcType=JdbcType.BIGINT), + @Result(column="convert_code", property="convertCode", jdbcType=JdbcType.VARCHAR), + @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_code", property="couponCode", jdbcType=JdbcType.VARCHAR), @Result(column="qr_code", property="qrCode", jdbcType=JdbcType.VARCHAR), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @@ -84,19 +88,21 @@ public interface HighCouponAgentCodeMapper extends HighCouponAgentCodeMapperExt @Select({ "select", - "id, coupon_agent_id, coupon_id, agent_id, coupon_code_id, coupon_agent_record_id, ", - "coupon_code, qr_code, `status`, remark, create_time, operator_id, operator_name, ", - "ext_1, ext_2, ext_3", + "id, `type`, coupon_agent_id, coupon_id, agent_id, coupon_agent_record_id, convert_code, ", + "coupon_code_id, coupon_code, qr_code, `status`, remark, create_time, operator_id, ", + "operator_name, ext_1, ext_2, ext_3", "from high_coupon_agent_code", "where id = #{id,jdbcType=BIGINT}" }) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="type", property="type", jdbcType=JdbcType.INTEGER), @Result(column="coupon_agent_id", property="couponAgentId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), - @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_agent_record_id", property="couponAgentRecordId", jdbcType=JdbcType.BIGINT), + @Result(column="convert_code", property="convertCode", jdbcType=JdbcType.VARCHAR), + @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.BIGINT), @Result(column="coupon_code", property="couponCode", jdbcType=JdbcType.VARCHAR), @Result(column="qr_code", property="qrCode", jdbcType=JdbcType.VARCHAR), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @@ -121,11 +127,13 @@ public interface HighCouponAgentCodeMapper extends HighCouponAgentCodeMapperExt @Update({ "update high_coupon_agent_code", - "set coupon_agent_id = #{couponAgentId,jdbcType=BIGINT},", + "set `type` = #{type,jdbcType=INTEGER},", + "coupon_agent_id = #{couponAgentId,jdbcType=BIGINT},", "coupon_id = #{couponId,jdbcType=BIGINT},", "agent_id = #{agentId,jdbcType=BIGINT},", - "coupon_code_id = #{couponCodeId,jdbcType=BIGINT},", "coupon_agent_record_id = #{couponAgentRecordId,jdbcType=BIGINT},", + "convert_code = #{convertCode,jdbcType=VARCHAR},", + "coupon_code_id = #{couponCodeId,jdbcType=BIGINT},", "coupon_code = #{couponCode,jdbcType=VARCHAR},", "qr_code = #{qrCode,jdbcType=VARCHAR},", "`status` = #{status,jdbcType=INTEGER},", diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeSqlProvider.java index 3ff4fd78..50f71478 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentCodeSqlProvider.java @@ -28,6 +28,10 @@ public class HighCouponAgentCodeSqlProvider { SQL sql = new SQL(); sql.INSERT_INTO("high_coupon_agent_code"); + if (record.getType() != null) { + sql.VALUES("`type`", "#{type,jdbcType=INTEGER}"); + } + if (record.getCouponAgentId() != null) { sql.VALUES("coupon_agent_id", "#{couponAgentId,jdbcType=BIGINT}"); } @@ -40,14 +44,18 @@ public class HighCouponAgentCodeSqlProvider { sql.VALUES("agent_id", "#{agentId,jdbcType=BIGINT}"); } - if (record.getCouponCodeId() != null) { - sql.VALUES("coupon_code_id", "#{couponCodeId,jdbcType=BIGINT}"); - } - if (record.getCouponAgentRecordId() != null) { sql.VALUES("coupon_agent_record_id", "#{couponAgentRecordId,jdbcType=BIGINT}"); } + if (record.getConvertCode() != null) { + sql.VALUES("convert_code", "#{convertCode,jdbcType=VARCHAR}"); + } + + if (record.getCouponCodeId() != null) { + sql.VALUES("coupon_code_id", "#{couponCodeId,jdbcType=BIGINT}"); + } + if (record.getCouponCode() != null) { sql.VALUES("coupon_code", "#{couponCode,jdbcType=VARCHAR}"); } @@ -98,11 +106,13 @@ public class HighCouponAgentCodeSqlProvider { } else { sql.SELECT("id"); } + sql.SELECT("`type`"); sql.SELECT("coupon_agent_id"); sql.SELECT("coupon_id"); sql.SELECT("agent_id"); - sql.SELECT("coupon_code_id"); sql.SELECT("coupon_agent_record_id"); + sql.SELECT("convert_code"); + sql.SELECT("coupon_code_id"); sql.SELECT("coupon_code"); sql.SELECT("qr_code"); sql.SELECT("`status`"); @@ -134,6 +144,10 @@ public class HighCouponAgentCodeSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); } + if (record.getType() != null) { + sql.SET("`type` = #{record.type,jdbcType=INTEGER}"); + } + if (record.getCouponAgentId() != null) { sql.SET("coupon_agent_id = #{record.couponAgentId,jdbcType=BIGINT}"); } @@ -146,14 +160,18 @@ public class HighCouponAgentCodeSqlProvider { sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}"); } - if (record.getCouponCodeId() != null) { - sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); - } - if (record.getCouponAgentRecordId() != null) { sql.SET("coupon_agent_record_id = #{record.couponAgentRecordId,jdbcType=BIGINT}"); } + if (record.getConvertCode() != null) { + sql.SET("convert_code = #{record.convertCode,jdbcType=VARCHAR}"); + } + + if (record.getCouponCodeId() != null) { + sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); + } + if (record.getCouponCode() != null) { sql.SET("coupon_code = #{record.couponCode,jdbcType=VARCHAR}"); } @@ -203,11 +221,13 @@ public class HighCouponAgentCodeSqlProvider { sql.UPDATE("high_coupon_agent_code"); sql.SET("id = #{record.id,jdbcType=BIGINT}"); + sql.SET("`type` = #{record.type,jdbcType=INTEGER}"); sql.SET("coupon_agent_id = #{record.couponAgentId,jdbcType=BIGINT}"); sql.SET("coupon_id = #{record.couponId,jdbcType=BIGINT}"); sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}"); - sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); sql.SET("coupon_agent_record_id = #{record.couponAgentRecordId,jdbcType=BIGINT}"); + sql.SET("convert_code = #{record.convertCode,jdbcType=VARCHAR}"); + sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); sql.SET("coupon_code = #{record.couponCode,jdbcType=VARCHAR}"); sql.SET("qr_code = #{record.qrCode,jdbcType=VARCHAR}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); @@ -228,6 +248,10 @@ public class HighCouponAgentCodeSqlProvider { SQL sql = new SQL(); sql.UPDATE("high_coupon_agent_code"); + if (record.getType() != null) { + sql.SET("`type` = #{type,jdbcType=INTEGER}"); + } + if (record.getCouponAgentId() != null) { sql.SET("coupon_agent_id = #{couponAgentId,jdbcType=BIGINT}"); } @@ -240,14 +264,18 @@ public class HighCouponAgentCodeSqlProvider { sql.SET("agent_id = #{agentId,jdbcType=BIGINT}"); } - if (record.getCouponCodeId() != null) { - sql.SET("coupon_code_id = #{couponCodeId,jdbcType=BIGINT}"); - } - if (record.getCouponAgentRecordId() != null) { sql.SET("coupon_agent_record_id = #{couponAgentRecordId,jdbcType=BIGINT}"); } + if (record.getConvertCode() != null) { + sql.SET("convert_code = #{convertCode,jdbcType=VARCHAR}"); + } + + if (record.getCouponCodeId() != null) { + sql.SET("coupon_code_id = #{couponCodeId,jdbcType=BIGINT}"); + } + if (record.getCouponCode() != null) { sql.SET("coupon_code = #{couponCode,jdbcType=VARCHAR}"); } diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java index a166f0ee..3cf1e4e3 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapper.java @@ -39,18 +39,20 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { int deleteByPrimaryKey(Long id); @Insert({ - "insert into high_coupon_agent_rel (coupon_name, sales_price, ", - "coupon_id, agent_id, ", - "stock_count, sales_count, ", - "create_time, `status`, ", - "operator_id, operator_name, ", - "ext_1, ext_2, ext_3)", - "values (#{couponName,jdbcType=VARCHAR}, #{salesPrice,jdbcType=DECIMAL}, ", - "#{couponId,jdbcType=BIGINT}, #{agentId,jdbcType=BIGINT}, ", - "#{stockCount,jdbcType=INTEGER}, #{salesCount,jdbcType=INTEGER}, ", - "#{createTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, ", - "#{operatorId,jdbcType=BIGINT}, #{operatorName,jdbcType=VARCHAR}, ", - "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "insert into high_coupon_agent_rel (`type`, coupon_name, ", + "sales_price, coupon_id, ", + "agent_id, stock_count, ", + "sales_count, create_time, ", + "`status`, operator_id, ", + "operator_name, ext_1, ", + "ext_2, ext_3)", + "values (#{type,jdbcType=INTEGER}, #{couponName,jdbcType=VARCHAR}, ", + "#{salesPrice,jdbcType=DECIMAL}, #{couponId,jdbcType=BIGINT}, ", + "#{agentId,jdbcType=BIGINT}, #{stockCount,jdbcType=INTEGER}, ", + "#{salesCount,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", + "#{status,jdbcType=INTEGER}, #{operatorId,jdbcType=BIGINT}, ", + "#{operatorName,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, ", + "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighCouponAgentRel record); @@ -62,6 +64,7 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @SelectProvider(type=HighCouponAgentRelSqlProvider.class, method="selectByExample") @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="type", property="type", jdbcType=JdbcType.INTEGER), @Result(column="coupon_name", property="couponName", jdbcType=JdbcType.VARCHAR), @Result(column="sales_price", property="salesPrice", jdbcType=JdbcType.DECIMAL), @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @@ -80,13 +83,14 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @Select({ "select", - "id, coupon_name, sales_price, coupon_id, agent_id, stock_count, sales_count, ", + "id, `type`, coupon_name, sales_price, coupon_id, agent_id, stock_count, sales_count, ", "create_time, `status`, operator_id, operator_name, ext_1, ext_2, ext_3", "from high_coupon_agent_rel", "where id = #{id,jdbcType=BIGINT}" }) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="type", property="type", jdbcType=JdbcType.INTEGER), @Result(column="coupon_name", property="couponName", jdbcType=JdbcType.VARCHAR), @Result(column="sales_price", property="salesPrice", jdbcType=JdbcType.DECIMAL), @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @@ -114,7 +118,8 @@ public interface HighCouponAgentRelMapper extends HighCouponAgentRelMapperExt { @Update({ "update high_coupon_agent_rel", - "set coupon_name = #{couponName,jdbcType=VARCHAR},", + "set `type` = #{type,jdbcType=INTEGER},", + "coupon_name = #{couponName,jdbcType=VARCHAR},", "sales_price = #{salesPrice,jdbcType=DECIMAL},", "coupon_id = #{couponId,jdbcType=BIGINT},", "agent_id = #{agentId,jdbcType=BIGINT},", diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java index 818a82f5..fa7e3062 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java @@ -47,6 +47,6 @@ public interface HighCouponAgentRelMapperExt { }) List getAgentSalesCodeList(@Param("agentId") Long agentId, @Param("consumeTimeS")String consumeTimeS, @Param("consumeTimeE")String consumeTimeE); - @Select(" select count(1) from high_coupon_agent_code a where a.agent_id = #{agentId} and a.`status` in (#{status}) ") - Integer getAgentCodeCount(@Param("agentId") Long agentId,@Param("status") String status); + @Select(" select count(1) from high_coupon_agent_code a where a.agent_id = #{agentId} and a.`status` in (#{status}) and a.type = #{type} ") + Integer getAgentCodeCount(@Param("agentId") Long agentId,@Param("status") String status,@Param("type") Integer type); } diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java index 7783432a..13d0d982 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelSqlProvider.java @@ -28,6 +28,10 @@ public class HighCouponAgentRelSqlProvider { SQL sql = new SQL(); sql.INSERT_INTO("high_coupon_agent_rel"); + if (record.getType() != null) { + sql.VALUES("`type`", "#{type,jdbcType=INTEGER}"); + } + if (record.getCouponName() != null) { sql.VALUES("coupon_name", "#{couponName,jdbcType=VARCHAR}"); } @@ -90,6 +94,7 @@ public class HighCouponAgentRelSqlProvider { } else { sql.SELECT("id"); } + sql.SELECT("`type`"); sql.SELECT("coupon_name"); sql.SELECT("sales_price"); sql.SELECT("coupon_id"); @@ -124,6 +129,10 @@ public class HighCouponAgentRelSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); } + if (record.getType() != null) { + sql.SET("`type` = #{record.type,jdbcType=INTEGER}"); + } + if (record.getCouponName() != null) { sql.SET("coupon_name = #{record.couponName,jdbcType=VARCHAR}"); } @@ -185,6 +194,7 @@ public class HighCouponAgentRelSqlProvider { sql.UPDATE("high_coupon_agent_rel"); sql.SET("id = #{record.id,jdbcType=BIGINT}"); + sql.SET("`type` = #{record.type,jdbcType=INTEGER}"); sql.SET("coupon_name = #{record.couponName,jdbcType=VARCHAR}"); sql.SET("sales_price = #{record.salesPrice,jdbcType=DECIMAL}"); sql.SET("coupon_id = #{record.couponId,jdbcType=BIGINT}"); @@ -208,6 +218,10 @@ public class HighCouponAgentRelSqlProvider { SQL sql = new SQL(); sql.UPDATE("high_coupon_agent_rel"); + if (record.getType() != null) { + sql.SET("`type` = #{type,jdbcType=INTEGER}"); + } + if (record.getCouponName() != null) { sql.SET("coupon_name = #{couponName,jdbcType=VARCHAR}"); } diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentCode.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentCode.java index 1fae72af..6b21861f 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentCode.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentCode.java @@ -20,6 +20,11 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser */ private Long id; + /** + * 类型 1:销售码 2:兑换码 + */ + private Integer type; + /** * 卡券和代理商的id */ @@ -36,14 +41,19 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser private Long agentId; /** - * 销售码id + * 卡券分配给代理商库存记录id */ - private Long couponCodeId; + private Long couponAgentRecordId; /** - * 卡券分配给代理商库存记录id + * 兑换码 */ - private Long couponAgentRecordId; + private String convertCode; + + /** + * 销售码id + */ + private Long couponCodeId; /** * 销售码 @@ -96,6 +106,14 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser this.id = id; } + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + public Long getCouponAgentId() { return couponAgentId; } @@ -120,14 +138,6 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser this.agentId = agentId; } - public Long getCouponCodeId() { - return couponCodeId; - } - - public void setCouponCodeId(Long couponCodeId) { - this.couponCodeId = couponCodeId; - } - public Long getCouponAgentRecordId() { return couponAgentRecordId; } @@ -136,6 +146,22 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser this.couponAgentRecordId = couponAgentRecordId; } + public String getConvertCode() { + return convertCode; + } + + public void setConvertCode(String convertCode) { + this.convertCode = convertCode; + } + + public Long getCouponCodeId() { + return couponCodeId; + } + + public void setCouponCodeId(Long couponCodeId) { + this.couponCodeId = couponCodeId; + } + public String getCouponCode() { return couponCode; } @@ -229,11 +255,13 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser } HighCouponAgentCode other = (HighCouponAgentCode) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) && (this.getCouponAgentId() == null ? other.getCouponAgentId() == null : this.getCouponAgentId().equals(other.getCouponAgentId())) && (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId())) && (this.getAgentId() == null ? other.getAgentId() == null : this.getAgentId().equals(other.getAgentId())) - && (this.getCouponCodeId() == null ? other.getCouponCodeId() == null : this.getCouponCodeId().equals(other.getCouponCodeId())) && (this.getCouponAgentRecordId() == null ? other.getCouponAgentRecordId() == null : this.getCouponAgentRecordId().equals(other.getCouponAgentRecordId())) + && (this.getConvertCode() == null ? other.getConvertCode() == null : this.getConvertCode().equals(other.getConvertCode())) + && (this.getCouponCodeId() == null ? other.getCouponCodeId() == null : this.getCouponCodeId().equals(other.getCouponCodeId())) && (this.getCouponCode() == null ? other.getCouponCode() == null : this.getCouponCode().equals(other.getCouponCode())) && (this.getQrCode() == null ? other.getQrCode() == null : this.getQrCode().equals(other.getQrCode())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) @@ -251,11 +279,13 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); result = prime * result + ((getCouponAgentId() == null) ? 0 : getCouponAgentId().hashCode()); result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode()); result = prime * result + ((getAgentId() == null) ? 0 : getAgentId().hashCode()); - result = prime * result + ((getCouponCodeId() == null) ? 0 : getCouponCodeId().hashCode()); result = prime * result + ((getCouponAgentRecordId() == null) ? 0 : getCouponAgentRecordId().hashCode()); + result = prime * result + ((getConvertCode() == null) ? 0 : getConvertCode().hashCode()); + result = prime * result + ((getCouponCodeId() == null) ? 0 : getCouponCodeId().hashCode()); result = prime * result + ((getCouponCode() == null) ? 0 : getCouponCode().hashCode()); result = prime * result + ((getQrCode() == null) ? 0 : getQrCode().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); @@ -276,11 +306,13 @@ public class HighCouponAgentCode extends HighCouponAgentCodeModel implements Ser sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); + sb.append(", type=").append(type); sb.append(", couponAgentId=").append(couponAgentId); sb.append(", couponId=").append(couponId); sb.append(", agentId=").append(agentId); - sb.append(", couponCodeId=").append(couponCodeId); sb.append(", couponAgentRecordId=").append(couponAgentRecordId); + sb.append(", convertCode=").append(convertCode); + sb.append(", couponCodeId=").append(couponCodeId); sb.append(", couponCode=").append(couponCode); sb.append(", qrCode=").append(qrCode); sb.append(", status=").append(status); diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentCodeExample.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentCodeExample.java index fbd038f7..cccf62bb 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentCodeExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentCodeExample.java @@ -185,6 +185,66 @@ public class HighCouponAgentCodeExample { return (Criteria) this; } + public Criteria andTypeIsNull() { + addCriterion("`type` is null"); + return (Criteria) this; + } + + public Criteria andTypeIsNotNull() { + addCriterion("`type` is not null"); + return (Criteria) this; + } + + public Criteria andTypeEqualTo(Integer value) { + addCriterion("`type` =", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotEqualTo(Integer value) { + addCriterion("`type` <>", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThan(Integer value) { + addCriterion("`type` >", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThanOrEqualTo(Integer value) { + addCriterion("`type` >=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThan(Integer value) { + addCriterion("`type` <", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThanOrEqualTo(Integer value) { + addCriterion("`type` <=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeIn(List values) { + addCriterion("`type` in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotIn(List values) { + addCriterion("`type` not in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeBetween(Integer value1, Integer value2) { + addCriterion("`type` between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotBetween(Integer value1, Integer value2) { + addCriterion("`type` not between", value1, value2, "type"); + return (Criteria) this; + } + public Criteria andCouponAgentIdIsNull() { addCriterion("coupon_agent_id is null"); return (Criteria) this; @@ -365,123 +425,193 @@ public class HighCouponAgentCodeExample { return (Criteria) this; } - public Criteria andCouponCodeIdIsNull() { - addCriterion("coupon_code_id is null"); + public Criteria andCouponAgentRecordIdIsNull() { + addCriterion("coupon_agent_record_id is null"); return (Criteria) this; } - public Criteria andCouponCodeIdIsNotNull() { - addCriterion("coupon_code_id is not null"); + public Criteria andCouponAgentRecordIdIsNotNull() { + addCriterion("coupon_agent_record_id is not null"); return (Criteria) this; } - public Criteria andCouponCodeIdEqualTo(Long value) { - addCriterion("coupon_code_id =", value, "couponCodeId"); + public Criteria andCouponAgentRecordIdEqualTo(Long value) { + addCriterion("coupon_agent_record_id =", value, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdNotEqualTo(Long value) { - addCriterion("coupon_code_id <>", value, "couponCodeId"); + public Criteria andCouponAgentRecordIdNotEqualTo(Long value) { + addCriterion("coupon_agent_record_id <>", value, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdGreaterThan(Long value) { - addCriterion("coupon_code_id >", value, "couponCodeId"); + public Criteria andCouponAgentRecordIdGreaterThan(Long value) { + addCriterion("coupon_agent_record_id >", value, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdGreaterThanOrEqualTo(Long value) { - addCriterion("coupon_code_id >=", value, "couponCodeId"); + public Criteria andCouponAgentRecordIdGreaterThanOrEqualTo(Long value) { + addCriterion("coupon_agent_record_id >=", value, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdLessThan(Long value) { - addCriterion("coupon_code_id <", value, "couponCodeId"); + public Criteria andCouponAgentRecordIdLessThan(Long value) { + addCriterion("coupon_agent_record_id <", value, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdLessThanOrEqualTo(Long value) { - addCriterion("coupon_code_id <=", value, "couponCodeId"); + public Criteria andCouponAgentRecordIdLessThanOrEqualTo(Long value) { + addCriterion("coupon_agent_record_id <=", value, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdIn(List values) { - addCriterion("coupon_code_id in", values, "couponCodeId"); + public Criteria andCouponAgentRecordIdIn(List values) { + addCriterion("coupon_agent_record_id in", values, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdNotIn(List values) { - addCriterion("coupon_code_id not in", values, "couponCodeId"); + public Criteria andCouponAgentRecordIdNotIn(List values) { + addCriterion("coupon_agent_record_id not in", values, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdBetween(Long value1, Long value2) { - addCriterion("coupon_code_id between", value1, value2, "couponCodeId"); + public Criteria andCouponAgentRecordIdBetween(Long value1, Long value2) { + addCriterion("coupon_agent_record_id between", value1, value2, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponCodeIdNotBetween(Long value1, Long value2) { - addCriterion("coupon_code_id not between", value1, value2, "couponCodeId"); + public Criteria andCouponAgentRecordIdNotBetween(Long value1, Long value2) { + addCriterion("coupon_agent_record_id not between", value1, value2, "couponAgentRecordId"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdIsNull() { - addCriterion("coupon_agent_record_id is null"); + public Criteria andConvertCodeIsNull() { + addCriterion("convert_code is null"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdIsNotNull() { - addCriterion("coupon_agent_record_id is not null"); + public Criteria andConvertCodeIsNotNull() { + addCriterion("convert_code is not null"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdEqualTo(Long value) { - addCriterion("coupon_agent_record_id =", value, "couponAgentRecordId"); + public Criteria andConvertCodeEqualTo(String value) { + addCriterion("convert_code =", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdNotEqualTo(Long value) { - addCriterion("coupon_agent_record_id <>", value, "couponAgentRecordId"); + public Criteria andConvertCodeNotEqualTo(String value) { + addCriterion("convert_code <>", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdGreaterThan(Long value) { - addCriterion("coupon_agent_record_id >", value, "couponAgentRecordId"); + public Criteria andConvertCodeGreaterThan(String value) { + addCriterion("convert_code >", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdGreaterThanOrEqualTo(Long value) { - addCriterion("coupon_agent_record_id >=", value, "couponAgentRecordId"); + public Criteria andConvertCodeGreaterThanOrEqualTo(String value) { + addCriterion("convert_code >=", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdLessThan(Long value) { - addCriterion("coupon_agent_record_id <", value, "couponAgentRecordId"); + public Criteria andConvertCodeLessThan(String value) { + addCriterion("convert_code <", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdLessThanOrEqualTo(Long value) { - addCriterion("coupon_agent_record_id <=", value, "couponAgentRecordId"); + public Criteria andConvertCodeLessThanOrEqualTo(String value) { + addCriterion("convert_code <=", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdIn(List values) { - addCriterion("coupon_agent_record_id in", values, "couponAgentRecordId"); + public Criteria andConvertCodeLike(String value) { + addCriterion("convert_code like", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdNotIn(List values) { - addCriterion("coupon_agent_record_id not in", values, "couponAgentRecordId"); + public Criteria andConvertCodeNotLike(String value) { + addCriterion("convert_code not like", value, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdBetween(Long value1, Long value2) { - addCriterion("coupon_agent_record_id between", value1, value2, "couponAgentRecordId"); + public Criteria andConvertCodeIn(List values) { + addCriterion("convert_code in", values, "convertCode"); return (Criteria) this; } - public Criteria andCouponAgentRecordIdNotBetween(Long value1, Long value2) { - addCriterion("coupon_agent_record_id not between", value1, value2, "couponAgentRecordId"); + public Criteria andConvertCodeNotIn(List values) { + addCriterion("convert_code not in", values, "convertCode"); + return (Criteria) this; + } + + public Criteria andConvertCodeBetween(String value1, String value2) { + addCriterion("convert_code between", value1, value2, "convertCode"); + return (Criteria) this; + } + + public Criteria andConvertCodeNotBetween(String value1, String value2) { + addCriterion("convert_code not between", value1, value2, "convertCode"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdIsNull() { + addCriterion("coupon_code_id is null"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdIsNotNull() { + addCriterion("coupon_code_id is not null"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdEqualTo(Long value) { + addCriterion("coupon_code_id =", value, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdNotEqualTo(Long value) { + addCriterion("coupon_code_id <>", value, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdGreaterThan(Long value) { + addCriterion("coupon_code_id >", value, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdGreaterThanOrEqualTo(Long value) { + addCriterion("coupon_code_id >=", value, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdLessThan(Long value) { + addCriterion("coupon_code_id <", value, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdLessThanOrEqualTo(Long value) { + addCriterion("coupon_code_id <=", value, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdIn(List values) { + addCriterion("coupon_code_id in", values, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdNotIn(List values) { + addCriterion("coupon_code_id not in", values, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdBetween(Long value1, Long value2) { + addCriterion("coupon_code_id between", value1, value2, "couponCodeId"); + return (Criteria) this; + } + + public Criteria andCouponCodeIdNotBetween(Long value1, Long value2) { + addCriterion("coupon_code_id not between", value1, value2, "couponCodeId"); return (Criteria) this; } diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java index 78f33d29..57d98c69 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRel.java @@ -21,6 +21,11 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria */ private Long id; + /** + * 类型 1:销售码 2:兑换码 + */ + private Integer type; + /** * 卡券名称 */ @@ -87,6 +92,14 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria this.id = id; } + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + public String getCouponName() { return couponName; } @@ -204,6 +217,7 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria } HighCouponAgentRel other = (HighCouponAgentRel) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) && (this.getCouponName() == null ? other.getCouponName() == null : this.getCouponName().equals(other.getCouponName())) && (this.getSalesPrice() == null ? other.getSalesPrice() == null : this.getSalesPrice().equals(other.getSalesPrice())) && (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId())) @@ -224,6 +238,7 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); result = prime * result + ((getCouponName() == null) ? 0 : getCouponName().hashCode()); result = prime * result + ((getSalesPrice() == null) ? 0 : getSalesPrice().hashCode()); result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode()); @@ -247,6 +262,7 @@ public class HighCouponAgentRel extends HighCouponAgentRelModel implements Seria sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); + sb.append(", type=").append(type); sb.append(", couponName=").append(couponName); sb.append(", salesPrice=").append(salesPrice); sb.append(", couponId=").append(couponId); diff --git a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java index 3d82ecff..59ebd92c 100644 --- a/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighCouponAgentRelExample.java @@ -186,6 +186,66 @@ public class HighCouponAgentRelExample { return (Criteria) this; } + public Criteria andTypeIsNull() { + addCriterion("`type` is null"); + return (Criteria) this; + } + + public Criteria andTypeIsNotNull() { + addCriterion("`type` is not null"); + return (Criteria) this; + } + + public Criteria andTypeEqualTo(Integer value) { + addCriterion("`type` =", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotEqualTo(Integer value) { + addCriterion("`type` <>", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThan(Integer value) { + addCriterion("`type` >", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThanOrEqualTo(Integer value) { + addCriterion("`type` >=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThan(Integer value) { + addCriterion("`type` <", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThanOrEqualTo(Integer value) { + addCriterion("`type` <=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeIn(List values) { + addCriterion("`type` in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotIn(List values) { + addCriterion("`type` not in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeBetween(Integer value1, Integer value2) { + addCriterion("`type` between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotBetween(Integer value1, Integer value2) { + addCriterion("`type` not between", value1, value2, "type"); + return (Criteria) this; + } + public Criteria andCouponNameIsNull() { addCriterion("coupon_name is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java index 60f1f27b..bf526f8f 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -35,7 +35,7 @@ public interface HighCouponAgentService { * @Description 根据卡券id和代理商id 查询 * @Date 2021/4/20 23:52 **/ - HighCouponAgentRel getRelByCouponAgent(Long couponId,Long agentId); + HighCouponAgentRel getRelByCouponAgent(Long couponId,Long agentId, Integer type); /** * @Author 胡锐 @@ -78,7 +78,7 @@ public interface HighCouponAgentService { * @Description 根据代理商 查询销售统计 * @Date 2021/4/22 22:26 **/ - Map getSalesCountByAgent(Long agentId) throws Exception; + Map getSalesCountByAgent(Long agentId, Integer type) throws Exception; /** * @@ -104,4 +104,25 @@ public interface HighCouponAgentService { */ List getAgentSalesCodeList(Long agentId,String consumeTimeS,String consumeTimeE); + /** + * 生成兑换码 + * @param couponAgentRelId + * @return + */ + String generateConvertCode(Long couponAgentRelId); + + /** + * 查询兑换码 + * @param convertCode + * @return + */ + HighCouponAgentCode getConvertCode(String convertCode); + + /** + * 使用兑换码 + * @param code + * @return + */ + String useConvertCode(String code); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java index 885d53b0..d9c312de 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java @@ -1,6 +1,7 @@ package com.hai.service.impl; import com.github.pagehelper.PageInfo; +import com.hai.common.GenerateCode; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; @@ -15,6 +16,7 @@ import com.hai.service.*; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -54,13 +56,9 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { private HighAgentService highAgentService; @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel,Integer stockCount) { - // 查询未销售的卡券 - List codeList = highCouponCodeService.getNoSaleCode(highCouponAgentRel.getCouponId()); - if (stockCount > codeList.size()) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法分配,分配数量超过库存数量"); - } if (highCouponAgentRel.getId() != null) { highCouponAgentRelMapper.updateByPrimaryKey(highCouponAgentRel); } else { @@ -87,26 +85,50 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { record.setCreateTime(new Date()); highCouponAgentRecordMapper.insert(record); - List assignCouponCodeList = codeList.stream().limit(stockCount).collect(Collectors.toList()); - HighCouponAgentCode highCouponAgentCode; - for (HighCouponCode code : assignCouponCodeList) { - code.setAgentId(highCouponAgentRel.getAgentId()); - code.setIsAssignAgent(true); - highCouponCodeService.updateCouponCode(code); - - highCouponAgentCode = new HighCouponAgentCode(); - highCouponAgentCode.setCouponAgentId(highCouponAgentRel.getId()); - highCouponAgentCode.setCouponAgentRecordId(record.getId()); - highCouponAgentCode.setCouponId(code.getCouponId()); - highCouponAgentCode.setAgentId(highCouponAgentRel.getAgentId()); - highCouponAgentCode.setCouponCodeId(code.getId()); - highCouponAgentCode.setCouponCode(code.getSalesCode()); - highCouponAgentCode.setQrCode(code.getExt1()); - highCouponAgentCode.setStatus(1); - highCouponAgentCode.setCreateTime(new Date()); - highCouponAgentCode.setOperatorId(highCouponAgentRel.getOperatorId()); - highCouponAgentCode.setOperatorName(highCouponAgentRel.getOperatorName()); - highCouponAgentCodeMapper.insert(highCouponAgentCode); + if (highCouponAgentRel.getType() == 1) { + // 查询未销售的卡券 + List codeList = highCouponCodeService.getNoSaleCode(highCouponAgentRel.getCouponId()); + if (stockCount > codeList.size()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法分配,分配数量超过库存数量"); + } + List assignCouponCodeList = codeList.stream().limit(stockCount).collect(Collectors.toList()); + HighCouponAgentCode highCouponAgentCode; + for (HighCouponCode code : assignCouponCodeList) { + code.setAgentId(highCouponAgentRel.getAgentId()); + code.setIsAssignAgent(true); + highCouponCodeService.updateCouponCode(code); + + highCouponAgentCode = new HighCouponAgentCode(); + highCouponAgentCode.setCouponAgentId(highCouponAgentRel.getId()); + highCouponAgentCode.setCouponAgentRecordId(record.getId()); + highCouponAgentCode.setCouponId(code.getCouponId()); + highCouponAgentCode.setAgentId(highCouponAgentRel.getAgentId()); + highCouponAgentCode.setCouponCodeId(code.getId()); + highCouponAgentCode.setCouponCode(code.getSalesCode()); + highCouponAgentCode.setQrCode(code.getExt1()); + highCouponAgentCode.setStatus(1); + highCouponAgentCode.setCreateTime(new Date()); + highCouponAgentCode.setOperatorId(highCouponAgentRel.getOperatorId()); + highCouponAgentCode.setOperatorName(highCouponAgentRel.getOperatorName()); + highCouponAgentCodeMapper.insert(highCouponAgentCode); + } + } + + if (highCouponAgentRel.getType() == 2) { + HighCouponAgentCode highCouponAgentCode; + for (int i = 0; i < stockCount; i++) { + highCouponAgentCode = new HighCouponAgentCode(); + highCouponAgentCode.setCouponAgentId(highCouponAgentRel.getId()); + highCouponAgentCode.setCouponAgentRecordId(record.getId()); + highCouponAgentCode.setCouponId(highCoupon.getId()); + highCouponAgentCode.setAgentId(highCouponAgentRel.getAgentId()); + highCouponAgentCode.setConvertCode(generateConvertCode(highCouponAgentRel.getId())); + highCouponAgentCode.setStatus(1); + highCouponAgentCode.setCreateTime(new Date()); + highCouponAgentCode.setOperatorId(highCouponAgentRel.getOperatorId()); + highCouponAgentCode.setOperatorName(highCouponAgentRel.getOperatorName()); + highCouponAgentCodeMapper.insert(highCouponAgentCode); + } } } @@ -116,9 +138,9 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { } @Override - public HighCouponAgentRel getRelByCouponAgent(Long couponId, Long agentId) { + public HighCouponAgentRel getRelByCouponAgent(Long couponId, Long agentId,Integer type) { HighCouponAgentRelExample example = new HighCouponAgentRelExample(); - example.createCriteria().andCouponIdEqualTo(couponId).andAgentIdEqualTo(agentId); + example.createCriteria().andCouponIdEqualTo(couponId).andAgentIdEqualTo(agentId).andTypeEqualTo(type); List list = highCouponAgentRelMapper.selectByExample(example); if (list != null && list.size() > 0) { return list.get(0); @@ -131,6 +153,10 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { HighCouponAgentRelExample example = new HighCouponAgentRelExample(); HighCouponAgentRelExample.Criteria criteria = example.createCriteria(); + if (MapUtils.getInteger(map, "type") != null) { + criteria.andTypeEqualTo(MapUtils.getInteger(map, "type")); + } + if (MapUtils.getLong(map, "couponId") != null) { criteria.andCouponIdEqualTo(MapUtils.getLong(map, "couponId")); } @@ -213,15 +239,19 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { couponAgentCode.setRemark(remark); highCouponAgentCodeMapper.updateByPrimaryKey(couponAgentCode); - HighCouponAgentRel couponAgent = getRelByCouponAgent(couponAgentCode.getCouponId(), couponAgentCode.getAgentId()); + HighCouponAgentRel couponAgent = getRelByCouponAgent(couponAgentCode.getCouponId(), couponAgentCode.getAgentId(), couponAgentCode.getType()); couponAgent.setStockCount(couponAgent.getStockCount() - 1); couponAgent.setSalesCount(couponAgent.getSalesCount() + 1); highCouponAgentRelMapper.updateByPrimaryKey(couponAgent); - HighCouponCode couponCode = highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId()); - couponCode.setStatus(2); - couponCode.setReceiveTime(new Date()); - highCouponCodeService.updateCouponCode(couponCode); + + HighCouponCode couponCode = null; + if (couponAgentCode.getType() == 1) { + couponCode = highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId()); + couponCode.setStatus(2); + couponCode.setReceiveTime(new Date()); + highCouponCodeService.updateCouponCode(couponCode); + } Map map = new HashMap<>(); map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); @@ -231,12 +261,13 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { } @Override - public Map getSalesCountByAgent(Long agentId) throws Exception { + public Map getSalesCountByAgent(Long agentId, Integer type) throws Exception { BigDecimal surplusCountPrice = new BigDecimal("0"); BigDecimal salesCountPrice = new BigDecimal("0"); Map listMap = new HashMap<>(); listMap.put("agentId", agentId); + listMap.put("type", type); List list = getCouponAgentList(listMap).stream().sorted(Comparator.comparing(HighCouponAgentRel::getSalesPrice)).collect(Collectors.toList()); for (HighCouponAgentRel highCouponAgentRel : list) { BigDecimal surplusPrice = new BigDecimal(highCouponAgentRel.getStockCount()).multiply((highCouponAgentRel.getSalesPrice())); @@ -246,7 +277,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { salesCountPrice = salesCountPrice.add(salesPrice); } - // 计算使用有效期 + // 当前日时间 Calendar consumeTimeS = Calendar.getInstance(); consumeTimeS.setTime(new Date()); consumeTimeS.set(Calendar.HOUR_OF_DAY, 00); @@ -265,8 +296,8 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { returnMap.put("orderCount", agentSales.getCount()); returnMap.put("turnoverPrice", agentSales.getSalesCountPrice()); - returnMap.put("laveStockCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "1")); // 库存数量 - returnMap.put("soldCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "2,3")); // 销售数量 + returnMap.put("laveStockCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "1", type)); // 库存数量 + returnMap.put("soldCount", highCouponAgentRelMapper.getAgentCodeCount(agentId, "2,3", type)); // 销售数量 returnMap.put("surplusCountPrice", surplusCountPrice); // 剩余总额 returnMap.put("salesCountPrice", salesCountPrice); // 销售总额 @@ -312,4 +343,52 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { } return new ArrayList<>(); } + + @Override + public String generateConvertCode(Long couponAgentRelId) { + // 生成兑换码 + String code = GenerateCode.convertCode(couponAgentRelId); + if (getConvertCode(code) != null){ + return generateConvertCode(couponAgentRelId); + } + return code; + } + + @Override + public HighCouponAgentCode getConvertCode(String convertCode) { + HighCouponAgentCodeExample example = new HighCouponAgentCodeExample(); + example.createCriteria().andConvertCodeEqualTo(convertCode); + List list = highCouponAgentCodeMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) + public String useConvertCode(String code) { + // 查询兑换码 + HighCouponAgentCode convertCode = getConvertCode(code); + if (convertCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的兑换码"); + } + if (convertCode.getStatus() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用"); + } + // 查询未销售的卡券 + List codeList = highCouponCodeService.getNoSaleCode(convertCode.getCouponId()); + if (codeList.size() == 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法使用兑换码"); + } + HighCouponCode couponCode = codeList.get(0); + + convertCode.setCouponCodeId(couponCode.getId()); + convertCode.setCouponCode(couponCode.getSalesCode()); + convertCode.setQrCode(couponCode.getExt1()); + convertCode.setStatus(2); + highCouponAgentCodeMapper.updateByPrimaryKey(convertCode); + + return "/couponCode/"+couponCode.getExt1(); + } }