From a84ffaed41b97eedf9ef10d2ad8317b4e1180ddc Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 7 Nov 2023 16:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighUserCardController.java | 27 +++++- .../com/web/controller/OrderController.java | 6 ++ .../java/com/hai/dao/HighOilCardMapper.java | 25 ++--- .../com/hai/dao/HighOilCardSqlProvider.java | 14 +++ .../main/java/com/hai/entity/HighOilCard.java | 16 ++++ .../com/hai/entity/HighOilCardExample.java | 60 ++++++++++++ .../com/hai/enum_type/OilCardGetTypeEnum.java | 36 ++++++++ .../OilCardRecordSourceTypeEnum.java | 1 + .../impl/OrderPaySuccessServiceImpl.java | 9 +- .../hai/order/type/OrderChildGoodsType.java | 1 + .../com/hai/order/type/OrderProductType.java | 1 + .../com/hai/service/HighOilCardService.java | 14 +++ .../service/impl/HighOilCardServiceImpl.java | 92 +++++++++++++++++++ 13 files changed, 286 insertions(+), 16 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/enum_type/OilCardGetTypeEnum.java diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java index 31106d19..b5ca0b0a 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java @@ -11,15 +11,13 @@ import com.hai.common.utils.RedisUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.entity.HighFleetOilCard; +import com.hai.entity.HighOilCard; import com.hai.entity.HighUser; import com.hai.entity.HighUserCard; import com.hai.enum_type.UserCardType; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; -import com.hai.service.HighFleetOilCardService; -import com.hai.service.HighUserCardService; -import com.hai.service.HighUserPayPasswordService; -import com.hai.service.HighUserService; +import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.catalina.User; @@ -59,6 +57,9 @@ public class HighUserCardController { @Resource private HighFleetOilCardService fleetOilCardService; + @Resource + private HighOilCardService oilCardService; + @RequestMapping(value = "/bindCard", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "绑卡") @@ -370,4 +371,22 @@ public class HighUserCardController { } } + + @RequestMapping(value = "/applyOilCard", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "申请个人加油卡") + public ResponseData applyOilCard(HttpServletRequest request) { + try { + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + return ResponseMsgUtil.success(oilCardService.applyOilCard(userInfoModel.getHighUser().getPhone())); + + } catch (Exception e) { + log.error("HighUserCardController --> applyOilCard() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-order/src/main/java/com/web/controller/OrderController.java b/hai-order/src/main/java/com/web/controller/OrderController.java index 057ccde4..9dc089a3 100644 --- a/hai-order/src/main/java/com/web/controller/OrderController.java +++ b/hai-order/src/main/java/com/web/controller/OrderController.java @@ -149,6 +149,12 @@ public class OrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请选择收货地址!"); } + } else if (childModel.getGoodsType().equals(OrderChildGoodsType.TYPE14.getNumber())) { + if (childModel.getGoodsSpecName() == null) { + log.error("OrderController -> create() error!",""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入卡号"); + } + } } diff --git a/hai-service/src/main/java/com/hai/dao/HighOilCardMapper.java b/hai-service/src/main/java/com/hai/dao/HighOilCardMapper.java index e2a563ca..6510f10f 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOilCardMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighOilCardMapper.java @@ -43,20 +43,20 @@ public interface HighOilCardMapper extends HighOilCardMapperExt { "org_id, org_name, card_no, ", "amount, amount_consume, ", "contact_name, contact_phone, ", - "`status`, bind_status, ", - "bind_time, create_time, ", - "update_time, op_user_id, ", - "op_user_name, ext_1, ", - "ext_2, ext_3)", + "`status`, get_type, ", + "bind_status, bind_time, ", + "create_time, update_time, ", + "op_user_id, op_user_name, ", + "ext_1, ext_2, ext_3)", "values (#{companyId,jdbcType=BIGINT}, #{companyName,jdbcType=VARCHAR}, ", "#{orgId,jdbcType=BIGINT}, #{orgName,jdbcType=VARCHAR}, #{cardNo,jdbcType=VARCHAR}, ", "#{amount,jdbcType=DECIMAL}, #{amountConsume,jdbcType=DECIMAL}, ", "#{contactName,jdbcType=VARCHAR}, #{contactPhone,jdbcType=VARCHAR}, ", - "#{status,jdbcType=INTEGER}, #{bindStatus,jdbcType=INTEGER}, ", - "#{bindTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, ", - "#{updateTime,jdbcType=TIMESTAMP}, #{opUserId,jdbcType=BIGINT}, ", - "#{opUserName,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, ", - "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{status,jdbcType=INTEGER}, #{getType,jdbcType=INTEGER}, ", + "#{bindStatus,jdbcType=INTEGER}, #{bindTime,jdbcType=TIMESTAMP}, ", + "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", + "#{opUserId,jdbcType=BIGINT}, #{opUserName,jdbcType=VARCHAR}, ", + "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighOilCard record); @@ -78,6 +78,7 @@ public interface HighOilCardMapper extends HighOilCardMapperExt { @Result(column="contact_name", property="contactName", jdbcType=JdbcType.VARCHAR), @Result(column="contact_phone", property="contactPhone", jdbcType=JdbcType.VARCHAR), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), + @Result(column="get_type", property="getType", jdbcType=JdbcType.INTEGER), @Result(column="bind_status", property="bindStatus", jdbcType=JdbcType.INTEGER), @Result(column="bind_time", property="bindTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @@ -93,7 +94,7 @@ public interface HighOilCardMapper extends HighOilCardMapperExt { @Select({ "select", "id, company_id, company_name, org_id, org_name, card_no, amount, amount_consume, ", - "contact_name, contact_phone, `status`, bind_status, bind_time, create_time, ", + "contact_name, contact_phone, `status`, get_type, bind_status, bind_time, create_time, ", "update_time, op_user_id, op_user_name, ext_1, ext_2, ext_3", "from high_oil_card", "where id = #{id,jdbcType=BIGINT}" @@ -110,6 +111,7 @@ public interface HighOilCardMapper extends HighOilCardMapperExt { @Result(column="contact_name", property="contactName", jdbcType=JdbcType.VARCHAR), @Result(column="contact_phone", property="contactPhone", jdbcType=JdbcType.VARCHAR), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), + @Result(column="get_type", property="getType", jdbcType=JdbcType.INTEGER), @Result(column="bind_status", property="bindStatus", jdbcType=JdbcType.INTEGER), @Result(column="bind_time", property="bindTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @@ -143,6 +145,7 @@ public interface HighOilCardMapper extends HighOilCardMapperExt { "contact_name = #{contactName,jdbcType=VARCHAR},", "contact_phone = #{contactPhone,jdbcType=VARCHAR},", "`status` = #{status,jdbcType=INTEGER},", + "get_type = #{getType,jdbcType=INTEGER},", "bind_status = #{bindStatus,jdbcType=INTEGER},", "bind_time = #{bindTime,jdbcType=TIMESTAMP},", "create_time = #{createTime,jdbcType=TIMESTAMP},", diff --git a/hai-service/src/main/java/com/hai/dao/HighOilCardSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighOilCardSqlProvider.java index 18184a00..91c5fae0 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOilCardSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighOilCardSqlProvider.java @@ -68,6 +68,10 @@ public class HighOilCardSqlProvider { sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); } + if (record.getGetType() != null) { + sql.VALUES("get_type", "#{getType,jdbcType=INTEGER}"); + } + if (record.getBindStatus() != null) { sql.VALUES("bind_status", "#{bindStatus,jdbcType=INTEGER}"); } @@ -124,6 +128,7 @@ public class HighOilCardSqlProvider { sql.SELECT("contact_name"); sql.SELECT("contact_phone"); sql.SELECT("`status`"); + sql.SELECT("get_type"); sql.SELECT("bind_status"); sql.SELECT("bind_time"); sql.SELECT("create_time"); @@ -194,6 +199,10 @@ public class HighOilCardSqlProvider { sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); } + if (record.getGetType() != null) { + sql.SET("get_type = #{record.getType,jdbcType=INTEGER}"); + } + if (record.getBindStatus() != null) { sql.SET("bind_status = #{record.bindStatus,jdbcType=INTEGER}"); } @@ -249,6 +258,7 @@ public class HighOilCardSqlProvider { sql.SET("contact_name = #{record.contactName,jdbcType=VARCHAR}"); sql.SET("contact_phone = #{record.contactPhone,jdbcType=VARCHAR}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); + sql.SET("get_type = #{record.getType,jdbcType=INTEGER}"); sql.SET("bind_status = #{record.bindStatus,jdbcType=INTEGER}"); sql.SET("bind_time = #{record.bindTime,jdbcType=TIMESTAMP}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); @@ -308,6 +318,10 @@ public class HighOilCardSqlProvider { sql.SET("`status` = #{status,jdbcType=INTEGER}"); } + if (record.getGetType() != null) { + sql.SET("get_type = #{getType,jdbcType=INTEGER}"); + } + if (record.getBindStatus() != null) { sql.SET("bind_status = #{bindStatus,jdbcType=INTEGER}"); } diff --git a/hai-service/src/main/java/com/hai/entity/HighOilCard.java b/hai-service/src/main/java/com/hai/entity/HighOilCard.java index 4d667f71..eac3f0ba 100644 --- a/hai-service/src/main/java/com/hai/entity/HighOilCard.java +++ b/hai-service/src/main/java/com/hai/entity/HighOilCard.java @@ -66,6 +66,11 @@ public class HighOilCard implements Serializable { */ private Integer status; + /** + * 获取类型 1:机构分配 2:客户申领 + */ + private Integer getType; + /** * 绑定状态 0:未绑定 1:已绑定 */ @@ -192,6 +197,14 @@ public class HighOilCard implements Serializable { this.status = status; } + public Integer getGetType() { + return getType; + } + + public void setGetType(Integer getType) { + this.getType = getType; + } + public Integer getBindStatus() { return bindStatus; } @@ -287,6 +300,7 @@ public class HighOilCard implements Serializable { && (this.getContactName() == null ? other.getContactName() == null : this.getContactName().equals(other.getContactName())) && (this.getContactPhone() == null ? other.getContactPhone() == null : this.getContactPhone().equals(other.getContactPhone())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) + && (this.getGetType() == null ? other.getGetType() == null : this.getGetType().equals(other.getGetType())) && (this.getBindStatus() == null ? other.getBindStatus() == null : this.getBindStatus().equals(other.getBindStatus())) && (this.getBindTime() == null ? other.getBindTime() == null : this.getBindTime().equals(other.getBindTime())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) @@ -313,6 +327,7 @@ public class HighOilCard implements Serializable { result = prime * result + ((getContactName() == null) ? 0 : getContactName().hashCode()); result = prime * result + ((getContactPhone() == null) ? 0 : getContactPhone().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); + result = prime * result + ((getGetType() == null) ? 0 : getGetType().hashCode()); result = prime * result + ((getBindStatus() == null) ? 0 : getBindStatus().hashCode()); result = prime * result + ((getBindTime() == null) ? 0 : getBindTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); @@ -342,6 +357,7 @@ public class HighOilCard implements Serializable { sb.append(", contactName=").append(contactName); sb.append(", contactPhone=").append(contactPhone); sb.append(", status=").append(status); + sb.append(", getType=").append(getType); sb.append(", bindStatus=").append(bindStatus); sb.append(", bindTime=").append(bindTime); sb.append(", createTime=").append(createTime); diff --git a/hai-service/src/main/java/com/hai/entity/HighOilCardExample.java b/hai-service/src/main/java/com/hai/entity/HighOilCardExample.java index 82478253..02b473b9 100644 --- a/hai-service/src/main/java/com/hai/entity/HighOilCardExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighOilCardExample.java @@ -836,6 +836,66 @@ public class HighOilCardExample { return (Criteria) this; } + public Criteria andGetTypeIsNull() { + addCriterion("get_type is null"); + return (Criteria) this; + } + + public Criteria andGetTypeIsNotNull() { + addCriterion("get_type is not null"); + return (Criteria) this; + } + + public Criteria andGetTypeEqualTo(Integer value) { + addCriterion("get_type =", value, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeNotEqualTo(Integer value) { + addCriterion("get_type <>", value, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeGreaterThan(Integer value) { + addCriterion("get_type >", value, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeGreaterThanOrEqualTo(Integer value) { + addCriterion("get_type >=", value, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeLessThan(Integer value) { + addCriterion("get_type <", value, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeLessThanOrEqualTo(Integer value) { + addCriterion("get_type <=", value, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeIn(List values) { + addCriterion("get_type in", values, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeNotIn(List values) { + addCriterion("get_type not in", values, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeBetween(Integer value1, Integer value2) { + addCriterion("get_type between", value1, value2, "getType"); + return (Criteria) this; + } + + public Criteria andGetTypeNotBetween(Integer value1, Integer value2) { + addCriterion("get_type not between", value1, value2, "getType"); + return (Criteria) this; + } + public Criteria andBindStatusIsNull() { addCriterion("bind_status is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/enum_type/OilCardGetTypeEnum.java b/hai-service/src/main/java/com/hai/enum_type/OilCardGetTypeEnum.java new file mode 100644 index 00000000..428be8c6 --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/OilCardGetTypeEnum.java @@ -0,0 +1,36 @@ + +package com.hai.enum_type; + +/** + * 油卡获取类型 + * @author hurui + */ +public enum OilCardGetTypeEnum { + type1(1 , "机构分配"), + type2(2 , "个人申领"), + ; + + private Integer code; + private String name; + + OilCardGetTypeEnum(int status , String name) { + this.code = status; + this.name = name; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hai-service/src/main/java/com/hai/enum_type/OilCardRecordSourceTypeEnum.java b/hai-service/src/main/java/com/hai/enum_type/OilCardRecordSourceTypeEnum.java index 16cc66f2..4bf8eea4 100644 --- a/hai-service/src/main/java/com/hai/enum_type/OilCardRecordSourceTypeEnum.java +++ b/hai-service/src/main/java/com/hai/enum_type/OilCardRecordSourceTypeEnum.java @@ -9,6 +9,7 @@ public enum OilCardRecordSourceTypeEnum { type2(2 , "订单消费"), type3(3 , "订单退款"), type4(4 , "回收余额"), + type5(5 , "现金充值"), ; private Integer type; diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java index f9ab0be4..bc69eacd 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java @@ -119,7 +119,8 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { @Resource private HighOrderService highOrderService; - + @Resource + private HighOilCardService oilCardService; @Override public HighOrder orderPaySuccessHandle(String orderNo, OrderPayType payType, String paySerialNo, BigDecimal payRealPrice, HighUserCard userCard) { @@ -241,6 +242,8 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { blxCouponHandle(order , childOrder); } else if (childOrder.getGoodsType().equals(OrderChildGoodsType.TYPE13.getNumber())) { blxOrderHandle(order); + } else if (childOrder.getGoodsType().equals(OrderChildGoodsType.TYPE14.getNumber())) { + oilCardHandle(childOrder.getGoodsSpecName(), order); } } } @@ -600,4 +603,8 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { } + + private void oilCardHandle(String cardNo, HighOrder order) { + oilCardService.recharge(cardNo, order.getOrderNo()); + } } diff --git a/hai-service/src/main/java/com/hai/order/type/OrderChildGoodsType.java b/hai-service/src/main/java/com/hai/order/type/OrderChildGoodsType.java index c51519da..a4fb3c12 100644 --- a/hai-service/src/main/java/com/hai/order/type/OrderChildGoodsType.java +++ b/hai-service/src/main/java/com/hai/order/type/OrderChildGoodsType.java @@ -22,6 +22,7 @@ public enum OrderChildGoodsType { TYPE11(11, "实物商品购买"), TYPE12(12, "比邻星停车券"), TYPE13(13, "比邻星停车"), + TYPE14(14, "个人油卡充值"), ; private Integer number; diff --git a/hai-service/src/main/java/com/hai/order/type/OrderProductType.java b/hai-service/src/main/java/com/hai/order/type/OrderProductType.java index 3b3d8cd0..f0835d36 100644 --- a/hai-service/src/main/java/com/hai/order/type/OrderProductType.java +++ b/hai-service/src/main/java/com/hai/order/type/OrderProductType.java @@ -24,6 +24,7 @@ public enum OrderProductType { PRODUCT_TYPE12(12, "实物商品" , "orderLogo/goods.png", "GOODS"), PRODUCT_TYPE13(13, "比邻星停车券" , "orderLogo/coupon.png", "BLX_COUPON"), PRODUCT_TYPE14(14, "比邻星停车业务" , "orderLogo/coupon.png", "BLX_PARK"), + PRODUCT_TYPE15(15, "个人油卡充值" , "orderLogo/coupon.png", ""), PRODUCT_TYPE101(101, "惠支付" , "orderLogo/pay.png", "PAY"), PRODUCT_TYPE102(102, "门店活动" , "orderLogo/store_activity.png", "STORE_ACTIVITY"), ; diff --git a/hai-service/src/main/java/com/hai/service/HighOilCardService.java b/hai-service/src/main/java/com/hai/service/HighOilCardService.java index d9f334cb..37e31101 100644 --- a/hai-service/src/main/java/com/hai/service/HighOilCardService.java +++ b/hai-service/src/main/java/com/hai/service/HighOilCardService.java @@ -19,6 +19,20 @@ public interface HighOilCardService { */ void editData(HighOilCard oilCard); + /** + * 申请个人油卡 + * @param phone + * @return + */ + HighOilCard applyOilCard(String phone); + + /** + * 个人油卡现金充值 + * @param cardNo + * @param orderNo + */ + void recharge(String cardNo, String orderNo); + /** * 油卡充值 * @param cardNo 油卡卡号 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOilCardServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOilCardServiceImpl.java index 6f7fc4d8..ac4ebe84 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOilCardServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOilCardServiceImpl.java @@ -72,6 +72,97 @@ public class HighOilCardServiceImpl implements HighOilCardService { } } + @Override + @Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW) + public HighOilCard applyOilCard(String phone) { + if (getOilCardByPhone(phone) != null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法申领,手机号【"+phone+"】的油卡已存在"); + } + // 查询用户 + HighUser user = userService.findByPhone(phone); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户不存在"); + } + // 查询部门信息,个人油卡部门 + BsOrganization organization = organizationService.findById(5L); + if (organization == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到部门"); + } + BsCompany company = companyService.getCompanyById(organization.getCompanyId()); + + // 生成油卡 + HighOilCard oilCard = new HighOilCard(); + oilCard.setCompanyId(organization.getCompanyId()); + oilCard.setCompanyName(company.getName()); + oilCard.setOrgId(organization.getId()); + oilCard.setOrgName(organization.getName()); + oilCard.setAmount(new BigDecimal("0")); + oilCard.setAmountConsume(new BigDecimal("0")); + oilCard.setCardNo(BankNumberUtil.getBrankNumber("8")); + oilCard.setOpUserId(user.getId()); + oilCard.setOpUserName(user.getName()); + oilCard.setCreateTime(new Date()); + oilCard.setUpdateTime(new Date()); + oilCard.setStatus(OilCardStatusEnum.status1.getStatus()); + oilCard.setBindStatus(OilCardBindStatusEnum.status1.getStatus()); + oilCard.setBindTime(new Date()); + oilCard.setGetType(OilCardGetTypeEnum.type2.getCode()); + editData(oilCard); + + // 绑定用户 + userCardService.bindCard(UserCardType.type2.getType(), oilCard.getCardNo(), user.getId()); + + return oilCard; + } + + @Override + @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) + public void recharge(String cardNo, String orderNo) { + // 查询订单 + HighOrder order = orderService.getOrderByOrderNo(orderNo); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单"); + } + if (!order.getOrderStatus().equals(OrderStatusEnum.type2.getType())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态错误"); + } + + HighOilCard oilCard = getOilCardByCardNo(cardNo); + if (oilCard == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡卡号错误"); + } + if (!oilCard.getStatus().equals(OilCardStatusEnum.status1.getStatus())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油卡不处于正常状态"); + } + // 变更前金额 + BigDecimal beforeAmount = oilCard.getAmount(); + // 计算金额 + oilCard.setAmount(oilCard.getAmount().add(order.getTotalPrice())); + editData(oilCard); + // 变更后金额 + BigDecimal afterAmount = oilCard.getAmount(); + + HighOilCardRecord record = new HighOilCardRecord(); + record.setOilCardId(oilCard.getId()); + record.setCardNo(oilCard.getCardNo()); + record.setType(OilCardRecordTypeEnum.type1.getType()); + record.setAmount(order.getTotalPrice()); + record.setBeforeAmount(beforeAmount); + record.setAfterAmount(afterAmount); + record.setSourceType(OilCardRecordSourceTypeEnum.type5.getType()); + try { + record.setSourceOrderNo(DateUtil.date2String(new Date(), "yyyyMMddHHmmss")); + } catch (Exception e) { + e.printStackTrace(); + } + record.setSourceContent("充值油卡金额:" + record.getAmount()); + oilCardRecordService.insertRecord(record); + + order.setOrderStatus(OrderStatusEnum.type3.getType()); + order.setFinishTime(new Date()); + orderService.updateOrder(order); + } + @Override @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) public synchronized void recharge(String cardNo, BigDecimal price, Long orgId) { @@ -284,6 +375,7 @@ public class HighOilCardServiceImpl implements HighOilCardService { oilCard.setUpdateTime(new Date()); oilCard.setStatus(OilCardStatusEnum.status1.getStatus()); oilCard.setBindStatus(OilCardBindStatusEnum.status0.getStatus()); + oilCard.setGetType(OilCardGetTypeEnum.type1.getCode()); oilCardList.add(oilCard); } oilCardMapper.insertList(oilCardList);