'提交代码'

dev-discount
199901012 4 years ago
parent 5cf0af8aaa
commit 0e913ece8d
  1. 38
      hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java
  2. 1
      hai-service/src/main/java/com/hai/common/exception/ErrorCode.java
  3. 36
      hai-service/src/main/java/com/hai/common/generateCode.java
  4. 63
      hai-service/src/main/java/com/hai/dao/HighCouponCodeMapper.java
  5. 38
      hai-service/src/main/java/com/hai/dao/HighCouponCodeMapperExt.java
  6. 69
      hai-service/src/main/java/com/hai/dao/HighCouponCodeSqlProvider.java
  7. 6
      hai-service/src/main/java/com/hai/service/HighCouponCodeService.java
  8. 4
      hai-service/src/main/java/com/hai/service/HighCouponService.java
  9. 16
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java

@ -6,6 +6,7 @@ import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.generateCode;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil; import com.hai.common.utils.DateUtil;
@ -31,9 +32,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -322,6 +321,9 @@ public class HighCouponController {
public ResponseData writeStock(@RequestBody String reqBody, HttpServletRequest request){ public ResponseData writeStock(@RequestBody String reqBody, HttpServletRequest request){
try { try {
SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
JSONObject jsonObject = JSONObject.parseObject(reqBody); JSONObject jsonObject = JSONObject.parseObject(reqBody);
Long couponId = jsonObject.getLong("couponId"); Long couponId = jsonObject.getLong("couponId");
Long salesEndTime = jsonObject.getLong("salesEndTime"); Long salesEndTime = jsonObject.getLong("salesEndTime");
@ -335,20 +337,42 @@ public class HighCouponController {
// 查找商户 // 查找商户
HighCouponModel coupon = highCouponService.getCouponById(couponId); HighCouponModel coupon = highCouponService.getCouponById(couponId);
if (coupon == null) { if (coupon == null) {
log.error("HighCouponController -> insertCoupon() error!","未找到商户"); log.error("HighCouponController -> writeStock() error!","未找到商户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
} }
if (coupon.getCouponType() != 1) { if (coupon.getCouponType() != 1) {
log.error("HighCouponController -> insertCoupon() error!","卡卷类型错误"); log.error("HighCouponController -> writeStock() error!","卡卷类型错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_TYPE_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<HighCouponCode> 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("操作成功"); return ResponseMsgUtil.success("操作成功");
} catch (Exception e) { } catch (Exception e) {
log.error("HighCouponController -> getCouponList() error!",e); log.error("HighCouponController -> writeStock() error!",e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }

@ -87,6 +87,7 @@ public enum ErrorCode {
APPROVE_PROCESSED("2115","审批已处理"), APPROVE_PROCESSED("2115","审批已处理"),
COUPON_STOCK_ERROR("2116","卡卷库存数量错误"), COUPON_STOCK_ERROR("2116","卡卷库存数量错误"),
COUPON_TYPE_ERROR("2117","卡卷类型错误"), COUPON_TYPE_ERROR("2117","卡卷类型错误"),
COUPON_STATUS_ERROR("2118","卡卷状态错误"),
STATUS_ERROR("3000","状态错误"), STATUS_ERROR("3000","状态错误"),
ADD_DATA_ERROR("3001","增加数据失败"), ADD_DATA_ERROR("3001","增加数据失败"),

@ -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;
}
}

@ -3,6 +3,7 @@ package com.hai.dao;
import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCode;
import com.hai.entity.HighCouponCodeExample; import com.hai.entity.HighCouponCodeExample;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider; import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider; 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.Param;
import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider; import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider; import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -29,6 +32,12 @@ public interface HighCouponCodeMapper extends HighCouponCodeMapperExt {
@DeleteProvider(type=HighCouponCodeSqlProvider.class, method="deleteByExample") @DeleteProvider(type=HighCouponCodeSqlProvider.class, method="deleteByExample")
int deleteByExample(HighCouponCodeExample example); int deleteByExample(HighCouponCodeExample example);
@Delete({
"delete from high_coupon_code",
"where id = #{id,jdbcType=BIGINT}"
})
int deleteByPrimaryKey(Long id);
@Insert({ @Insert({
"insert into high_coupon_code (coupon_id, merchant_id, ", "insert into high_coupon_code (coupon_id, merchant_id, ",
"order_id, sales_code, ", "order_id, sales_code, ",
@ -54,7 +63,7 @@ public interface HighCouponCodeMapper extends HighCouponCodeMapperExt {
@SelectProvider(type=HighCouponCodeSqlProvider.class, method="selectByExample") @SelectProvider(type=HighCouponCodeSqlProvider.class, method="selectByExample")
@Results({ @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="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT),
@Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT), @Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT),
@Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT),
@ -73,9 +82,61 @@ public interface HighCouponCodeMapper extends HighCouponCodeMapperExt {
}) })
List<HighCouponCode> selectByExample(HighCouponCodeExample example); List<HighCouponCode> 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") @UpdateProvider(type=HighCouponCodeSqlProvider.class, method="updateByExampleSelective")
int updateByExampleSelective(@Param("record") HighCouponCode record, @Param("example") HighCouponCodeExample example); int updateByExampleSelective(@Param("record") HighCouponCode record, @Param("example") HighCouponCodeExample example);
@UpdateProvider(type=HighCouponCodeSqlProvider.class, method="updateByExample") @UpdateProvider(type=HighCouponCodeSqlProvider.class, method="updateByExample")
int updateByExample(@Param("record") HighCouponCode record, @Param("example") HighCouponCodeExample example); 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);
} }

@ -1,7 +1,45 @@
package com.hai.dao; 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扩展类 * mapper扩展类
*/ */
public interface HighCouponCodeMapperExt { public interface HighCouponCodeMapperExt {
@Insert({
"<script>",
"insert into high_coupon_code (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)",
"values ",
"<foreach collection='list' item='item' index='index' separator=','>",
"(#{item.couponId,jdbcType=BIGINT}, " +
"#{item.merchantId,jdbcType=BIGINT}," +
"#{item.orderId,jdbcType=BIGINT}, " +
"#{item.salesCode,jdbcType=VARCHAR}, ",
"#{item.salesEndTime,jdbcType=TIMESTAMP}," +
"#{item.useEndTime,jdbcType=TIMESTAMP}, ",
"#{item.createTime,jdbcType=TIMESTAMP}, " +
"#{item.receiveTime,jdbcType=TIMESTAMP}, ",
"#{item.consumeTime,jdbcType=TIMESTAMP}," +
"#{item.status,jdbcType=INTEGER}, ",
"#{item.operatorId,jdbcType=BIGINT}, " +
"#{item.operatorName,jdbcType=VARCHAR}, ",
"#{item.ext1,jdbcType=VARCHAR}," +
"#{item.ext2,jdbcType=VARCHAR}, " +
"#{item.ext3,jdbcType=VARCHAR})",
"</foreach>",
"</script>"
})
void insertList(@Param(value = "list") List<HighCouponCode> list);
} }

@ -224,6 +224,75 @@ public class HighCouponCodeSqlProvider {
return sql.toString(); 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) { protected void applyWhere(SQL sql, HighCouponCodeExample example, boolean includeExamplePhrase) {
if (example == null) { if (example == null) {
return; return;

@ -22,10 +22,10 @@ public interface HighCouponCodeService {
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 生成销售码 数量 * @Description 批量增加
* @Date 2021/3/17 20:47 * @Date 2021/3/18 21:30
**/ **/
void generateCode(Long couponId, Date salesEndTime, Date useEndTime, Integer generateNum); void insertList(List<HighCouponCode> list);
/** /**
* *

@ -2,6 +2,7 @@ package com.hai.service;
import com.hai.entity.HighApprove; import com.hai.entity.HighApprove;
import com.hai.entity.HighCoupon; import com.hai.entity.HighCoupon;
import com.hai.entity.HighCouponCode;
import com.hai.model.HighCouponModel; import com.hai.model.HighCouponModel;
import java.util.List; import java.util.List;
@ -21,6 +22,8 @@ public interface HighCouponService {
**/ **/
void insertCoupon(HighCouponModel highCouponModel); void insertCoupon(HighCouponModel highCouponModel);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 修改卡卷业务 * @Description 修改卡卷业务
@ -61,6 +64,7 @@ public interface HighCouponService {
void ofShelfCoupon(Long id); void ofShelfCoupon(Long id);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 根据id查询卡卷基本信息赠送信息 * @Description 根据id查询卡卷基本信息赠送信息

@ -1,6 +1,7 @@
package com.hai.service.impl; package com.hai.service.impl;
import com.hai.dao.HighCouponCodeMapper; import com.hai.dao.HighCouponCodeMapper;
import com.hai.dao.HighCouponCodeMapperExt;
import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCode;
import com.hai.entity.HighCouponCodeExample; import com.hai.entity.HighCouponCodeExample;
import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponCodeService;
@ -8,6 +9,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -20,21 +22,17 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
@Resource @Resource
private HighCouponCodeMapper highCouponCodeMapper; private HighCouponCodeMapper highCouponCodeMapper;
@Resource
private HighCouponCodeMapperExt highCouponCodeMapperExt;
@Override @Override
public void insertCouponCode(HighCouponCode highCouponCode) { public void insertCouponCode(HighCouponCode highCouponCode) {
highCouponCodeMapper.insert(highCouponCode); highCouponCodeMapper.insert(highCouponCode);
} }
@Override @Override
public void generateCode(Long couponId, Date salesEndTime, Date useEndTime, Integer generateNum) { public void insertList(List<HighCouponCode> list) {
HighCouponCode highCouponCode; highCouponCodeMapperExt.insertList(list);
for (int i = 0; i < generateNum;i++) {
highCouponCode = new HighCouponCode();
highCouponCode.setCouponId(couponId);
highCouponCode.setSalesEndTime(salesEndTime);
highCouponCode.setUseEndTime(useEndTime);
highCouponCode.setCreateTime(new Date());
}
} }
@Override @Override

Loading…
Cancel
Save