Pārlūkot izejas kodu

add web乐器维护列表

周箭河 4 gadi atpakaļ
vecāks
revīzija
2098dd1d7e

+ 40 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/MaintenancePayDto.java

@@ -0,0 +1,40 @@
+package com.ym.mec.biz.dal.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+public class MaintenancePayDto {
+    @ApiModelProperty(value = "乐器列表id", required = true)
+    private Long id;
+
+    @ApiModelProperty(value = "支付金额", required = true)
+    private BigDecimal amount;
+
+    @ApiModelProperty(value = "是否使用余额", required = true)
+    private Boolean isUseBalance = false;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+
+    public Boolean getUseBalance() {
+        return isUseBalance;
+    }
+
+    public void setUseBalance(Boolean useBalance) {
+        isUseBalance = useBalance;
+    }
+}

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/StudentInstrumentService.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service;
 
+import com.ym.mec.biz.dal.dto.MaintenancePayDto;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
@@ -12,15 +13,14 @@ public interface StudentInstrumentService extends BaseService<Long, StudentInstr
 
     /**
      * 乐保支付
-     *
-     * @param id
-     * @return
      */
-    Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception;
+    Map pay(MaintenancePayDto maintenancePayDto) throws Exception;
 
     /**
      * 回调页面
+     *
      * @param studentPaymentOrder
      * @return
      */
     Boolean orderCallback(StudentPaymentOrder studentPaymentOrder);
+}

+ 67 - 60
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -1,10 +1,12 @@
 package com.ym.mec.biz.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
-import com.ym.mec.biz.dal.dao.StudentDao;
 import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
-import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.dto.MaintenancePayDto;
+import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.SysUserCashAccount;
+import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
@@ -12,20 +14,18 @@ import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.ym.mec.util.date.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 @Service
 public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentInstrument> implements StudentInstrumentService {
@@ -48,6 +48,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     private ContractService contractService;
     @Autowired
     private SysUserCashAccountDetailService sysUserCashAccountDetailService;
+    @Autowired
+    private SysMessageService sysMessageService;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -58,25 +60,23 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception {
-        StudentInstrument studentInstrument = studentInstrumentDao.get(id);
+    public Map pay(MaintenancePayDto maintenancePayDto) throws Exception {
+        StudentInstrument studentInstrument = studentInstrumentDao.get(maintenancePayDto.getId());
         if (studentInstrument == null) {
             throw new BizException("所选乐器不存在,请核查");
         }
         Integer userId = studentInstrument.getStudentId();
         BigDecimal orderAmount = new BigDecimal(400);
-
+        BigDecimal amount = maintenancePayDto.getAmount(); //扣除余额之前的金额
         if (amount.compareTo(orderAmount) != 0) {
             throw new BizException("商品价格不符");
         }
 
-        String orderNo = idGeneratorService.generatorId("payment") + "";
-
         String channelType = "";
         Date date = new Date();
 
         BigDecimal balance = BigDecimal.ZERO;
-        if (isUseBalance && amount.compareTo(BigDecimal.ZERO) > 0) {
+        if (maintenancePayDto.getUseBalance() && amount.compareTo(BigDecimal.ZERO) > 0) {
             SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
             if (userCashAccount == null) {
                 throw new BizException("用户账户找不到");
@@ -87,6 +87,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
                 sysUserCashAccountService.updateBalance(userId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐保购买");
             }
         }
+
+        String orderNo = idGeneratorService.generatorId("payment") + "";
         StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 
         studentPaymentOrder.setPaymentChannel("BALANCE");
@@ -94,7 +96,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         studentPaymentOrder.setGroupType(GroupType.MAINTENANCE);
         studentPaymentOrder.setOrderNo(orderNo);
         studentPaymentOrder.setType(OrderTypeEnum.MAINTENANCE);
-        studentPaymentOrder.setExpectAmount(amount);
+        studentPaymentOrder.setExpectAmount(orderAmount);
         studentPaymentOrder.setActualAmount(amount);
         studentPaymentOrder.setBalancePaymentAmount(balance);
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
@@ -166,68 +168,73 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         Map<Integer, String> map = new HashMap<>();
         map.put(userId, userId.toString());
 
+        //支付成功
         if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
             try {
                 contractService.transferProduceContract(userId, null);
             } catch (Exception e) {
                 logger.error("产品协议生成失败", e);
             }
-
-            repairInfo.setPayStatus(2);
-            repairInfo.setUpdateTime(nowDate);
-            if (this.update(repairInfo) <= 0) {
-                throw new BizException("维修单更新失败");
+            Date startTime = nowDate;
+            Date endTime = DateUtil.addYears(nowDate, 1);
+            if (studentInstrument.getEndTime() != null &&
+                    DateUtil.getLastTimeWithDay(studentInstrument.getEndTime()).compareTo(nowDate) >= 0) {
+                startTime = studentInstrument.getStartTime();
+                endTime = DateUtil.addYears(studentInstrument.getStartTime(), 1);
+            }
+            studentInstrument.setStartTime(startTime);
+            studentInstrument.setEndTime(endTime);
+            studentInstrument.setStatus(1);
+            if (this.update(studentInstrument) <= 0) {
+                throw new BizException("乐保信息更新失败");
             }
 
             //插入交易明细
             BigDecimal amount = studentPaymentOrder.getActualAmount();
-            SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
-            //充值
-            SysUserCashAccountDetail rechargeDetail = new SysUserCashAccountDetail();
-            rechargeDetail.setAmount(amount);
-            rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
-            rechargeDetail.setComment("缴费前充值");
-            rechargeDetail.setCreateTime(nowDate);
-            rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
-            rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
-            rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
-            rechargeDetail.setUpdateTime(nowDate);
-            rechargeDetail.setUserId(userId);
-            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
-            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
-            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
-            sysUserCashAccountDetailService.insert(rechargeDetail);
-
-            //缴费
-            SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
-            paymentDetail.setAmount(amount.negate());
-            paymentDetail.setBalance(cashAccount.getBalance());
-            paymentDetail.setComment("乐保购买");
-            paymentDetail.setCreateTime(nowDate);
-            paymentDetail.setStatus(DealStatusEnum.SUCCESS);
-            paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
-            paymentDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
-            paymentDetail.setUpdateTime(nowDate);
-            paymentDetail.setUserId(userId);
-            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
-            sysUserCashAccountDetailService.insert(paymentDetail);
-
-            sysMessageService.sendNoAuthPrivateMessage(repairInfo.getEmployeeId().toString(), userId.toString(), imContent);
+            if (amount.compareTo(BigDecimal.ZERO) > 0) {
+                SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
+                //充值
+                SysUserCashAccountDetail rechargeDetail = new SysUserCashAccountDetail();
+                rechargeDetail.setAmount(amount);
+                rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
+                rechargeDetail.setComment("缴费前充值");
+                rechargeDetail.setCreateTime(nowDate);
+                rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
+                rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
+                rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
+                rechargeDetail.setUpdateTime(nowDate);
+                rechargeDetail.setUserId(userId);
+                rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+                rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
+                rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
+                sysUserCashAccountDetailService.insert(rechargeDetail);
+
+                //缴费
+                SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
+                paymentDetail.setAmount(amount.negate());
+                paymentDetail.setBalance(cashAccount.getBalance());
+                paymentDetail.setComment("乐保购买");
+                paymentDetail.setCreateTime(nowDate);
+                paymentDetail.setStatus(DealStatusEnum.SUCCESS);
+                paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
+                paymentDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
+                paymentDetail.setUpdateTime(nowDate);
+                paymentDetail.setUserId(userId);
+                rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+                sysUserCashAccountDetailService.insert(paymentDetail);
+            }
+
             return true;
         }
 
         if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
-            repairInfo.setPayStatus(0);
-            repairInfo.setUpdateTime(nowDate);
-            if (this.update(repairInfo) <= 0) {
-                throw new BizException("维修单更新失败");
-            }
+
             if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
-                sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
+                sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐保购买支付失败");
             }
 
             sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_SPORADIC_PAYMENT_FAILED, map, null, 0, "", "STUDENT",
-                    studentPaymentOrder.getActualAmount(), "乐器维修");
+                    studentPaymentOrder.getActualAmount(), "乐保购买");
             return false;
         }
         return false;

+ 4 - 6
mec-student/src/main/java/com/ym/mec/student/controller/StudentInstrumentController.java

@@ -3,6 +3,7 @@ package com.ym.mec.student.controller;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dto.MaintenancePayDto;
 import com.ym.mec.biz.dal.dto.RegisterPayDto;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 import com.ym.mec.biz.dal.page.DegreeQueryInfo;
@@ -45,11 +46,8 @@ public class StudentInstrumentController extends BaseController {
 
     @ApiOperation(value = "乐保支付")
     @PostMapping("/pay")
-    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "开通月保的乐器记录id", required = true, dataType = "int"),
-            @ApiImplicitParam(name = "amount", value = "金额", required = true, dataType = "BigDecimal"),
-            @ApiImplicitParam(name = "isUseBalance", value = "是否使用余额", required = true, dataType = "boolean")
-    })
-    public HttpResponseResult pay(Long id, BigDecimal amount, Boolean isUseBalance) throws Exception {
-        return succeed(studentInstrumentService.pay(id, amount, isUseBalance));
+    @ApiImplicitParams({@ApiImplicitParam(name = "maintenancePayDto", value = "支付参数", required = true, dataType = "MaintenancePayDto")})
+    public HttpResponseResult pay(MaintenancePayDto maintenancePayDto) throws Exception {
+        return succeed(studentInstrumentService.pay(maintenancePayDto));
     }
 }