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 edc508d7..38cb01aa 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java @@ -6,6 +6,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.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.DateUtil; @@ -31,9 +32,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * @Auther: 胡锐 @@ -322,6 +321,9 @@ public class HighCouponController { public ResponseData writeStock(@RequestBody String reqBody, HttpServletRequest request){ try { + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + JSONObject jsonObject = JSONObject.parseObject(reqBody); Long couponId = jsonObject.getLong("couponId"); Long salesEndTime = jsonObject.getLong("salesEndTime"); @@ -335,20 +337,42 @@ public class HighCouponController { // 查找商户 HighCouponModel coupon = highCouponService.getCouponById(couponId); if (coupon == null) { - log.error("HighCouponController -> insertCoupon() error!","未找到商户"); + log.error("HighCouponController -> writeStock() error!","未找到商户"); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); } if (coupon.getCouponType() != 1) { - log.error("HighCouponController -> insertCoupon() error!","卡卷类型错误"); + log.error("HighCouponController -> writeStock() error!","卡卷类型错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_TYPE_ERROR, ""); } + if (coupon.getStatus() != 1) { + log.error("HighCouponController -> writeStock() error!","卡卷状态错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STATUS_ERROR, ""); + } + + Date salesEndTimeD = new Date(salesEndTime); + Date useEndTimeD =new Date(useEndTime); + HighCouponCode highCouponCode; + List list = new ArrayList<>(); + for (int i = 0; i < generateNum;i++) { + highCouponCode = new HighCouponCode(); + highCouponCode.setCouponId(couponId); + highCouponCode.setMerchantId(coupon.getMerchantId()); + highCouponCode.setSalesCode(generateCode.couponSalesCode(coupon.getMerchantId(), couponId)); + highCouponCode.setSalesEndTime(salesEndTimeD); + highCouponCode.setUseEndTime(useEndTimeD); + highCouponCode.setStatus(1); // 状态:1.待销售 2.未使用 3.已使用 + highCouponCode.setCreateTime(new Date()); + highCouponCode.setOperatorId(userInfoModel.getSecUser().getId()); + highCouponCode.setOperatorName(userInfoModel.getSecUser().getUserName()); + list.add(highCouponCode); + } - highCouponCodeService.generateCode(couponId, new Date(salesEndTime), new Date(useEndTime),generateNum); + highCouponCodeService.insertList(list); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { - log.error("HighCouponController -> getCouponList() error!",e); + log.error("HighCouponController -> writeStock() 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 80feb271..bf99c7ad 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 @@ -87,6 +87,7 @@ public enum ErrorCode { APPROVE_PROCESSED("2115","审批已处理"), COUPON_STOCK_ERROR("2116","卡卷库存数量错误"), COUPON_TYPE_ERROR("2117","卡卷类型错误"), + COUPON_STATUS_ERROR("2118","卡卷状态错误"), STATUS_ERROR("3000","状态错误"), ADD_DATA_ERROR("3001","增加数据失败"), diff --git a/hai-service/src/main/java/com/hai/common/generateCode.java b/hai-service/src/main/java/com/hai/common/generateCode.java new file mode 100644 index 00000000..aa6d1c27 --- /dev/null +++ b/hai-service/src/main/java/com/hai/common/generateCode.java @@ -0,0 +1,36 @@ +package com.hai.common; + +import java.util.Calendar; +import java.util.Random; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/3/18 21:07 + */ +public class generateCode { + + + /** + * @Author 胡锐 + * @Description 生成卡卷销售码 21位 毫秒+随机字符串 + * @Date 2021/3/18 21:08 + **/ + public static String couponSalesCode(Long merchantId,Long couponId) { + // 默认3位时间毫秒 + String val = merchantId + "" + couponId; + Random random = new Random(); + for (int i = 0; i < 21; i++) { + // 输出字母还是数字 + String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; + if ("char".equalsIgnoreCase(charOrNum)) { + // 取得大写字母还是小写字母 + int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; + val += (char) (choice + random.nextInt(26)); + } else if ("num".equalsIgnoreCase(charOrNum)) { // 数字 + val += String.valueOf(random.nextInt(10)); + } + } + return val; + } +} diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapper.java b/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapper.java index e48742d5..e47e0c76 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapper.java @@ -3,6 +3,7 @@ package com.hai.dao; import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCodeExample; import java.util.List; +import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.DeleteProvider; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.InsertProvider; @@ -10,7 +11,9 @@ import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.UpdateProvider; import org.apache.ibatis.type.JdbcType; import org.springframework.stereotype.Repository; @@ -29,6 +32,12 @@ public interface HighCouponCodeMapper extends HighCouponCodeMapperExt { @DeleteProvider(type=HighCouponCodeSqlProvider.class, method="deleteByExample") int deleteByExample(HighCouponCodeExample example); + @Delete({ + "delete from high_coupon_code", + "where id = #{id,jdbcType=BIGINT}" + }) + int deleteByPrimaryKey(Long id); + @Insert({ "insert into high_coupon_code (coupon_id, merchant_id, ", "order_id, sales_code, ", @@ -54,7 +63,7 @@ public interface HighCouponCodeMapper extends HighCouponCodeMapperExt { @SelectProvider(type=HighCouponCodeSqlProvider.class, method="selectByExample") @Results({ - @Result(column="id", property="id", jdbcType=JdbcType.BIGINT), + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), @Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT), @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), @@ -73,9 +82,61 @@ public interface HighCouponCodeMapper extends HighCouponCodeMapperExt { }) List selectByExample(HighCouponCodeExample example); + @Select({ + "select", + "id, coupon_id, merchant_id, order_id, sales_code, sales_end_time, use_end_time, ", + "create_time, receive_time, consume_time, `status`, operator_id, operator_name, ", + "ext_1, ext_2, ext_3", + "from high_coupon_code", + "where id = #{id,jdbcType=BIGINT}" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), + @Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT), + @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), + @Result(column="sales_code", property="salesCode", jdbcType=JdbcType.VARCHAR), + @Result(column="sales_end_time", property="salesEndTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="use_end_time", property="useEndTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="receive_time", property="receiveTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="consume_time", property="consumeTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), + @Result(column="operator_id", property="operatorId", jdbcType=JdbcType.BIGINT), + @Result(column="operator_name", property="operatorName", jdbcType=JdbcType.VARCHAR), + @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), + @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), + @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) + }) + HighCouponCode selectByPrimaryKey(Long id); + @UpdateProvider(type=HighCouponCodeSqlProvider.class, method="updateByExampleSelective") int updateByExampleSelective(@Param("record") HighCouponCode record, @Param("example") HighCouponCodeExample example); @UpdateProvider(type=HighCouponCodeSqlProvider.class, method="updateByExample") int updateByExample(@Param("record") HighCouponCode record, @Param("example") HighCouponCodeExample example); + + @UpdateProvider(type=HighCouponCodeSqlProvider.class, method="updateByPrimaryKeySelective") + int updateByPrimaryKeySelective(HighCouponCode record); + + @Update({ + "update high_coupon_code", + "set coupon_id = #{couponId,jdbcType=BIGINT},", + "merchant_id = #{merchantId,jdbcType=BIGINT},", + "order_id = #{orderId,jdbcType=BIGINT},", + "sales_code = #{salesCode,jdbcType=VARCHAR},", + "sales_end_time = #{salesEndTime,jdbcType=TIMESTAMP},", + "use_end_time = #{useEndTime,jdbcType=TIMESTAMP},", + "create_time = #{createTime,jdbcType=TIMESTAMP},", + "receive_time = #{receiveTime,jdbcType=TIMESTAMP},", + "consume_time = #{consumeTime,jdbcType=TIMESTAMP},", + "`status` = #{status,jdbcType=INTEGER},", + "operator_id = #{operatorId,jdbcType=BIGINT},", + "operator_name = #{operatorName,jdbcType=VARCHAR},", + "ext_1 = #{ext1,jdbcType=VARCHAR},", + "ext_2 = #{ext2,jdbcType=VARCHAR},", + "ext_3 = #{ext3,jdbcType=VARCHAR}", + "where id = #{id,jdbcType=BIGINT}" + }) + int updateByPrimaryKey(HighCouponCode record); } \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapperExt.java index 18052a3e..26528ae3 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponCodeMapperExt.java @@ -1,7 +1,45 @@ package com.hai.dao; +import com.hai.entity.HighCouponCode; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + /** * mapper扩展类 */ public interface HighCouponCodeMapperExt { -} \ No newline at end of file + + @Insert({ + "" + }) + void insertList(@Param(value = "list") List list); + +} diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponCodeSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighCouponCodeSqlProvider.java index 5f59da47..db4cca1b 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponCodeSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponCodeSqlProvider.java @@ -224,6 +224,75 @@ public class HighCouponCodeSqlProvider { return sql.toString(); } + public String updateByPrimaryKeySelective(HighCouponCode record) { + SQL sql = new SQL(); + sql.UPDATE("high_coupon_code"); + + if (record.getCouponId() != null) { + sql.SET("coupon_id = #{couponId,jdbcType=BIGINT}"); + } + + if (record.getMerchantId() != null) { + sql.SET("merchant_id = #{merchantId,jdbcType=BIGINT}"); + } + + if (record.getOrderId() != null) { + sql.SET("order_id = #{orderId,jdbcType=BIGINT}"); + } + + if (record.getSalesCode() != null) { + sql.SET("sales_code = #{salesCode,jdbcType=VARCHAR}"); + } + + if (record.getSalesEndTime() != null) { + sql.SET("sales_end_time = #{salesEndTime,jdbcType=TIMESTAMP}"); + } + + if (record.getUseEndTime() != null) { + sql.SET("use_end_time = #{useEndTime,jdbcType=TIMESTAMP}"); + } + + if (record.getCreateTime() != null) { + sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); + } + + if (record.getReceiveTime() != null) { + sql.SET("receive_time = #{receiveTime,jdbcType=TIMESTAMP}"); + } + + if (record.getConsumeTime() != null) { + sql.SET("consume_time = #{consumeTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.SET("`status` = #{status,jdbcType=INTEGER}"); + } + + if (record.getOperatorId() != null) { + sql.SET("operator_id = #{operatorId,jdbcType=BIGINT}"); + } + + if (record.getOperatorName() != null) { + sql.SET("operator_name = #{operatorName,jdbcType=VARCHAR}"); + } + + if (record.getExt1() != null) { + sql.SET("ext_1 = #{ext1,jdbcType=VARCHAR}"); + } + + if (record.getExt2() != null) { + sql.SET("ext_2 = #{ext2,jdbcType=VARCHAR}"); + } + + if (record.getExt3() != null) { + sql.SET("ext_3 = #{ext3,jdbcType=VARCHAR}"); + } + + sql.WHERE("id = #{id,jdbcType=BIGINT}"); + + return sql.toString(); + } + protected void applyWhere(SQL sql, HighCouponCodeExample example, boolean includeExamplePhrase) { if (example == null) { return; diff --git a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java index 440e29ff..c27cffe2 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java @@ -22,10 +22,10 @@ public interface HighCouponCodeService { /** * @Author 胡锐 - * @Description 生成销售码 数量 - * @Date 2021/3/17 20:47 + * @Description 批量增加 + * @Date 2021/3/18 21:30 **/ - void generateCode(Long couponId, Date salesEndTime, Date useEndTime, Integer generateNum); + void insertList(List list); /** * diff --git a/hai-service/src/main/java/com/hai/service/HighCouponService.java b/hai-service/src/main/java/com/hai/service/HighCouponService.java index f54ec0d3..c7f3da0e 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponService.java @@ -2,6 +2,7 @@ package com.hai.service; import com.hai.entity.HighApprove; import com.hai.entity.HighCoupon; +import com.hai.entity.HighCouponCode; import com.hai.model.HighCouponModel; import java.util.List; @@ -21,6 +22,8 @@ public interface HighCouponService { **/ void insertCoupon(HighCouponModel highCouponModel); + + /** * @Author 胡锐 * @Description 修改卡卷业务 @@ -61,6 +64,7 @@ public interface HighCouponService { void ofShelfCoupon(Long id); + /** * @Author 胡锐 * @Description 根据id查询卡卷基本信息、赠送信息 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java index 859ccbaa..88d7892d 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java @@ -1,6 +1,7 @@ package com.hai.service.impl; import com.hai.dao.HighCouponCodeMapper; +import com.hai.dao.HighCouponCodeMapperExt; import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCodeExample; import com.hai.service.HighCouponCodeService; @@ -8,6 +9,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; +import java.util.List; /** * @Auther: 胡锐 @@ -20,21 +22,17 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { @Resource private HighCouponCodeMapper highCouponCodeMapper; + @Resource + private HighCouponCodeMapperExt highCouponCodeMapperExt; + @Override public void insertCouponCode(HighCouponCode highCouponCode) { highCouponCodeMapper.insert(highCouponCode); } @Override - public void generateCode(Long couponId, Date salesEndTime, Date useEndTime, Integer generateNum) { - HighCouponCode highCouponCode; - for (int i = 0; i < generateNum;i++) { - highCouponCode = new HighCouponCode(); - highCouponCode.setCouponId(couponId); - highCouponCode.setSalesEndTime(salesEndTime); - highCouponCode.setUseEndTime(useEndTime); - highCouponCode.setCreateTime(new Date()); - } + public void insertList(List list) { + highCouponCodeMapperExt.insertList(list); } @Override