Forráskód Böngészése

涉及乐团id类型修改

周箭河 5 éve
szülő
commit
de5d038c4f

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrder.java

@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * 对应数据库表(student_payment_order):
@@ -76,6 +77,8 @@ public class StudentPaymentOrder {
 	private Integer classGroupId;
 
 	private Integer version;
+
+	private Date payTime;
 	
 	public void setId(Long id){
 		this.id = id;
@@ -213,6 +216,14 @@ public class StudentPaymentOrder {
 		this.version = version;
 	}
 
+	public Date getPayTime() {
+		return payTime;
+	}
+
+	public void setPayTime(Date payTime) {
+		this.payTime = payTime;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentRegistrationService.java

@@ -140,4 +140,12 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 	 */
 	List<StudentRegistration> findClassGroupStu(String musicGroupId, Integer classGroupId);
 
+
+	/**
+	 * 更新报名订单
+	 * @param studentPaymentOrder
+	 * @return
+	 */
+	StudentPaymentOrder updateApplyOrder(StudentPaymentOrder studentPaymentOrder);
+
 }

+ 52 - 31
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -9,6 +9,7 @@ import javax.annotation.Resource;
 import com.ym.mec.auth.api.entity.SysMenu;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
 import com.ym.mec.common.entity.ImResult;
 import com.ym.mec.common.entity.ImUserModel;
@@ -25,11 +26,6 @@ import com.ym.mec.auth.api.enums.UserLockFlag;
 import com.ym.mec.biz.dal.dto.StudentApplyDetailDto;
 import com.ym.mec.biz.dal.dto.StudentFeeDto;
 import com.ym.mec.biz.dal.dto.StudentInfo;
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
-import com.ym.mec.biz.dal.enums.GoodsType;
-import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
-import com.ym.mec.biz.dal.enums.OrderTypeEnum;
-import com.ym.mec.biz.dal.enums.YesOrNoEnum;
 import com.ym.mec.biz.dal.page.StudentRegistrationQueryInfo;
 import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
 import com.ym.mec.biz.service.StudentPaymentOrderService;
@@ -115,21 +111,21 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    public List<Map<String,Object>> getNoClassStuBySubjectId(String musicGroupId, String actualSubjectId) {
+    public List<Map<String, Object>> getNoClassStuBySubjectId(String musicGroupId, String actualSubjectId) {
         List<StudentRegistration> students = studentRegistrationDao.getNoClassStuBySubjectId(musicGroupId, actualSubjectId);
-        List<Map<String,Object>> mapArrayList = new ArrayList<>();
-        if(students != null && students.size() > 0){
+        List<Map<String, Object>> mapArrayList = new ArrayList<>();
+        if (students != null && students.size() > 0) {
             String[] subjectIds = actualSubjectId.split(",");
-            if(subjectIds != null && subjectIds.length > 0){
+            if (subjectIds != null && subjectIds.length > 0) {
                 List<Map<Integer, String>> subjectNames = subjectDao.queryNameByIds(actualSubjectId);
                 Map<Integer, String> subjectNameMap = MapUtil.convertMybatisMap(subjectNames);
-                for (int i = 0;i<subjectIds.length;i++){
-                    Map<String,Object> resultMap = new HashMap<>(3);
+                for (int i = 0; i < subjectIds.length; i++) {
+                    Map<String, Object> resultMap = new HashMap<>(3);
                     int subjectId = Integer.parseInt(subjectIds[i]);
                     List<StudentRegistration> collect = students.stream().filter(e -> e.getSubjectId().equals(subjectId)).collect(Collectors.toList());
-                    resultMap.put("subjectId",subjectId);
-                    resultMap.put("subjectName",subjectNameMap.get(subjectId));
-                    resultMap.put("rows",collect);
+                    resultMap.put("subjectId", subjectId);
+                    resultMap.put("subjectName", subjectNameMap.get(subjectId));
+                    resultMap.put("rows", collect);
                     mapArrayList.add(resultMap);
                 }
             }
@@ -138,7 +134,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    public List<Map<Integer,Long>> getNoClassStuCountBySubjectId(String musicGroupId) {
+    public List<Map<Integer, Long>> getNoClassStuCountBySubjectId(String musicGroupId) {
         return studentRegistrationDao.getNoClassStuCountBySubjectId(musicGroupId);
     }
 
@@ -172,7 +168,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         studentRegistrationDao.insert(studentRegistration);
         //增加报名学生数
         MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId());
-        musicOneSubjectClassPlan.setApplyStudentNum(musicOneSubjectClassPlan.getApplyStudentNum()+1);
+        musicOneSubjectClassPlan.setApplyStudentNum(musicOneSubjectClassPlan.getApplyStudentNum() + 1);
         return studentRegistration;
     }
 
@@ -358,12 +354,12 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Override
     public Integer insertStudent(StudentRegistration studentRegistration) throws Exception {
         StudentRegistration phoneAndMusicGroupId = studentRegistrationDao.getByPhoneAndMusicGroupId(studentRegistration.getMusicGroupId(), studentRegistration.getParentsPhone());
-        if(phoneAndMusicGroupId != null){
+        if (phoneAndMusicGroupId != null) {
             throw new Exception("该学员已存在");
-        }else {
+        } else {
             SysUser sysUser = studentRegistrationDao.getSysUserByPhone(studentRegistration.getParentsPhone());
             Integer userId;
-            if(sysUser == null){
+            if (sysUser == null) {
                 //新增user
                 sysUser = new SysUser();
                 sysUser.setRealName(studentRegistration.getName());
@@ -376,28 +372,28 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 ImResult register = imFeignService.register(new ImUserModel(userId.toString(), sysUser.getUsername(), sysUser.getAvatar()));
                 sysUser.setImToken(register.getToken());
                 teacherDao.updateUser(sysUser);
-            }else {
+            } else {
                 userId = sysUser.getId();
             }
             studentRegistration.setUserId(userId);
             //学生报名表
             studentRegistrationDao.insert(studentRegistration);
-            if(studentRegistration.getClassGroupId() != null){
+            if (studentRegistration.getClassGroupId() != null) {
                 ClassGroup classGroup = classGroupDao.get(studentRegistration.getClassGroupId());
-                if(classGroup != null){
-                    if(classGroup.getMusicGroupId().equals(studentRegistration.getMusicGroupId())){
+                if (classGroup != null) {
+                    if (classGroup.getMusicGroupId().equals(studentRegistration.getMusicGroupId())) {
                         throw new Exception("班级录入错误");
-                    }else {
+                    } else {
                         //修改实际学生人数
                         classGroup.setStudentNum(classGroup.getStudentNum() + 1);
                         classGroup.setUpdateTime(new Date());
                         classGroupDao.update(classGroup);
                     }
-                }else {
+                } else {
                     throw new Exception("班级不存在");
                 }
                 //新增班级学生关系
-                classGroupStudentMapperDao.insert(new ClassGroupStudentMapper(studentRegistration.getClassGroupId(),userId));
+                classGroupStudentMapperDao.insert(new ClassGroupStudentMapper(studentRegistration.getClassGroupId(), userId));
                 //乐团学生费用表
                 MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
                 //获取当前月
@@ -405,9 +401,9 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 //获取下次缴费月份
                 List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByMusicGroupId(studentRegistration.getMusicGroupId());
                 List<Integer> months = musicGroupPaymentCalenders.stream().map(e -> e.getPaymentMonth()).collect(Collectors.toList());
-                for (int i = 0;i<months.size();i++){
-                    if(months.get(i).equals(month)){
-                        month = i == months.size()-1?months.get(0):months.get(i+1);
+                for (int i = 0; i < months.size(); i++) {
+                    if (months.get(i).equals(month)) {
+                        month = i == months.size() - 1 ? months.get(0) : months.get(i + 1);
                     }
                 }
                 Calendar calendar = Calendar.getInstance();
@@ -415,8 +411,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 DateUtil.getFirstDayOfMonth(calendar.getTime());
                 //保存乐团学生费用表
                 musicGroupStudentFeeDao.insert(new MusicGroupStudentFee(studentRegistration.getMusicGroupId(),
-                        userId,studentRegistration.getSubjectId(),musicOneSubjectClassPlan.getFee(),
-                        DateUtil.getFirstDayOfMonth(calendar.getTime()),0,studentRegistration.getTemporaryCourseFee()));
+                        userId, studentRegistration.getSubjectId(), musicOneSubjectClassPlan.getFee(),
+                        DateUtil.getFirstDayOfMonth(calendar.getTime()), 0, studentRegistration.getTemporaryCourseFee()));
             }
             return userId;
         }
@@ -426,4 +422,29 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     public List<StudentRegistration> findClassGroupStu(String musicGroupId, Integer classGroupId) {
         return studentRegistrationDao.findClassGroupStu(musicGroupId, classGroupId);
     }
+
+    @Override
+    public StudentPaymentOrder updateApplyOrder(StudentPaymentOrder studentPaymentOrder) {
+        //更新订单状态
+        studentPaymentOrderService.update(studentPaymentOrder);
+
+        //成功报名状态变更
+        StudentRegistration studentRegistration = studentRegistrationDao.queryByUserIdAndMusicGroupId(studentPaymentOrder.getUserId(), studentPaymentOrder.getMusicGroupId());
+        if (studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS)) {
+            studentRegistration.setPaymentStatus(YesOrNoEnum.YES);
+            studentRegistration.setMusicGroupStatus(ClassGroupStudentStatusEnum.NORMAL);
+            studentRegistrationDao.update(studentRegistration);
+        }
+
+        //失败减去已收款金额
+
+        //减去缴费人数
+        if (studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS)) {
+            MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId());
+            musicOneSubjectClassPlan.setPaidStudentNum(musicOneSubjectClassPlan.getPaidStudentNum() - 1);
+            musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
+        }
+
+        return studentPaymentOrder;
+    }
 }

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -23,6 +23,7 @@
         <result column="order_no_" property="orderNo"/>
         <result column="music_group_id_" property="musicGroupId"/>
         <result column="class_group_id_" property="classGroupId"/>
+        <result column="pay_time_" property="payTime"/>
         <result column="version_" property="version"/>
     </resultMap>
 
@@ -122,6 +123,9 @@
             <if test="musicGroupId != null">
                 music_group_id_ = #{musicGroupId},
             </if>
+            <if test="payTime != null">
+                pay_time_ = #{payTime},
+            </if>
             <if test="version != null">
                 version_ = version_+1,
             </if>

+ 40 - 16
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -1,20 +1,23 @@
 package com.ym.mec.student.controller;
 
 import com.ym.mec.biz.dal.dao.SysAccountDao;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.SysAccount;
-import com.ym.mec.biz.service.SysAccountService;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
+import com.ym.mec.biz.service.StudentPaymentOrderService;
+import com.ym.mec.biz.service.StudentRegistrationService;
+import com.ym.mec.thirdparty.union.NotifyMsg;
 import io.swagger.annotations.Api;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Map;
 
 @RequestMapping("studentOrder")
@@ -24,24 +27,45 @@ public class StudentOrderController {
     private static final Logger log = LoggerFactory.getLogger(StudentOrderController.class);
     @Autowired
     private SysAccountDao sysAccountDao;
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
+    @Autowired
+    private StudentRegistrationService studentRegistrationService;
 
 
     @PostMapping("/notify")
-    public String notify(HttpServletRequest request) {
-       Map<String,String[]> msg = request.getParameterMap();
-        ArrayList<SysAccount> sysAccounts = new ArrayList<>();
-        for (Map.Entry<String, String[]> stringObjectEntry : msg.entrySet()) {
-            SysAccount sysAccount = new SysAccount();
-            String KeyVal = "Key:" + stringObjectEntry.getKey() + " val:" + stringObjectEntry.getValue().toString();
-            log.warn(KeyVal);
-            sysAccount.setMerNo(stringObjectEntry.getKey());
-            sysAccount.setChannel(request.getParameter(stringObjectEntry.getKey()));
-            sysAccounts.add(sysAccount);
-        }
-        sysAccountDao.batchInsert(sysAccounts);
+    public String notify(NotifyMsg notifyMsg) {
+        //       ArrayList<SysAccount> sysAccounts = new ArrayList<>();
+//       Map<String,String[]> msg = request.getParameterMap();
+//        for (Map.Entry<String, String[]> stringObjectEntry : msg.entrySet()) {
+//            SysAccount sysAccount = new SysAccount();
+//            String KeyVal = "Key:" + stringObjectEntry.getKey() + " val:" + stringObjectEntry.getValue().toString();
+//            log.warn(KeyVal);
+//            sysAccount.setMerNo(stringObjectEntry.getKey());
+//            sysAccount.setChannel(request.getParameter(stringObjectEntry.getKey()));
+//            sysAccounts.add(sysAccount);
+//        }
+        //sysAccountDao.batchInsert(sysAccounts);
 
         // "SUCCESS";
-        // "FAILED";
+        //
+        //不是成功和失败的通知
+        if (!notifyMsg.getStatus().equals("TRADE_SUCCESS") && !notifyMsg.getStatus().equals("TRADE_CLOSED")) {
+            return "SUCCESS";
+        }
+
+        StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(notifyMsg.getMerOrderId());
+        if (order != null && !order.getStatus().equals(DealStatusEnum.ING)) { //订单状态不是在支付中
+            return "SUCCESS";
+        }
+        DealStatusEnum status = notifyMsg.getStatus().equals("TRADE_SUCCESS") ? DealStatusEnum.SUCCESS : DealStatusEnum.FAilED;
+        order.setStatus(status);
+        order.setTransNo(notifyMsg.getSeqId());
+        order.setPaymentBusinessChannel(notifyMsg.getTargetSys());
+        order.setPayTime(notifyMsg.getPayTime());
+        if (order.getType().equals(OrderTypeEnum.APPLY)) { //报名订单
+            studentRegistrationService.updateApplyOrder(order);
+        }
 
         return "SUCCESS";
     }

+ 63 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/union/GenerateNum.java

@@ -0,0 +1,63 @@
+package com.ym.mec.thirdparty.union;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 生成订单号类
+ */
+public class GenerateNum {
+    // 使用单例模式,不允许直接创建实例
+    private GenerateNum() {}
+
+    // 创建一个空实例对象,类需要用的时候才赋值
+    private static GenerateNum g = null;
+
+    // 单例模式--懒汉模式
+    public static synchronized GenerateNum getInstance() {
+        if (g == null) {
+            g = new GenerateNum();
+        }
+        return g;
+    }
+
+    // 全局自增数
+    private static int count = 0;
+
+    // 每毫秒秒最多生成多少订单(最好是像9999这种准备进位的值)
+    private static final int total = 9999;
+
+    // 格式化的时间字符串
+    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+
+    // 获取当前时间年月日时分秒毫秒字符串
+    private static String getNowDateStr() {
+        return sdf.format(new Date());
+    }
+
+    // 记录上一次的时间,用来判断是否需要递增全局数
+    private static String now = null;
+
+    /*
+     * 生成一个订单号
+     */
+    public synchronized String GenerateOrderNo() {
+        String datastr = getNowDateStr();
+        if (datastr.equals(now)) {
+            count++;// 自增
+        } else {
+            count = 1;
+            now = datastr;
+        }
+        int countInteger = String.valueOf(total).length() - String.valueOf(count).length();// 算补位
+        String bu = "";// 补字符串
+        for (int i = 0; i < countInteger; i++) {
+            bu += "0";
+        }
+        bu += String.valueOf(count);
+        if (count >= total) {
+            count = 0;
+        }
+        return datastr + bu;
+    }
+}

+ 13 - 58
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/union/NotifyMsg.java

@@ -1,70 +1,28 @@
 package com.ym.mec.thirdparty.union;
 
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * 异步通知具体信息
  */
 public class NotifyMsg {
-    private String mid;//商户号
-    private String tid;//终端号
-    private String instMid;//业务类型
-    private String billFunds;//资金渠道
-    private String billFundsDesc;//资金渠道说明
-    private Integer totalAmount;//订单总金额(分)
+    private BigDecimal totalAmount;//订单总金额(分)
     private String merOrderId;//商户订单号
-    private String payTime;//支付时间
+    private Date payTime;//支付时间
     private String seqId; //支付系统交易流水号
     private String status; //交易状态,NEW_ORDER-新订单 UNKNOWN-不明交易状态 TRADE_CLOSED-关闭的交易 WAIT_BUYER_PAY-交易创建等待付款 TRADE_SUCCESS-交易成功
     private String targetOrderId; //渠道订单号
-    private String targetSys;//支付渠道,WXPay,等
-    private String sign;//签名
-
-    public String getMid() {
-        return mid;
-    }
-
-    public void setMid(String mid) {
-        this.mid = mid;
-    }
-
-    public String getTid() {
-        return tid;
-    }
-
-    public void setTid(String tid) {
-        this.tid = tid;
-    }
-
-    public String getInstMid() {
-        return instMid;
-    }
+    private String targetSys;//支付渠道,WXPay,Alipay 2.0等
 
-    public void setInstMid(String instMid) {
-        this.instMid = instMid;
-    }
-
-    public String getBillFunds() {
-        return billFunds;
-    }
 
-    public void setBillFunds(String billFunds) {
-        this.billFunds = billFunds;
-    }
-
-    public String getBillFundsDesc() {
-        return billFundsDesc;
-    }
-
-    public void setBillFundsDesc(String billFundsDesc) {
-        this.billFundsDesc = billFundsDesc;
-    }
-
-    public Integer getTotalAmount() {
+    public BigDecimal getTotalAmount() {
         return totalAmount;
     }
 
-    public void setTotalAmount(Integer totalAmount) {
+    public void setTotalAmount(BigDecimal totalAmount) {
         this.totalAmount = totalAmount;
     }
 
@@ -76,11 +34,11 @@ public class NotifyMsg {
         this.merOrderId = merOrderId;
     }
 
-    public String getPayTime() {
+    public Date getPayTime() {
         return payTime;
     }
 
-    public void setPayTime(String payTime) {
+    public void setPayTime(Date payTime) {
         this.payTime = payTime;
     }
 
@@ -116,11 +74,8 @@ public class NotifyMsg {
         this.targetSys = targetSys;
     }
 
-    public String getSign() {
-        return sign;
-    }
-
-    public void setSign(String sign) {
-        this.sign = sign;
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
     }
 }

+ 2 - 1
mec-web/src/main/java/com/ym/mec/web/controller/ClassGroupController.java

@@ -43,7 +43,8 @@ public class ClassGroupController extends BaseController {
 
     @ApiOperation(value = "新增提高班")
     @PostMapping("/addHighClass")
-    public Object addHighClass(@ApiParam(value = "乐团提高班json", required = true) @RequestParam List<HighClassGroupDto> highClassGroupDtoList) throws Exception {
+    @ApiParam(value = "乐团提高班json", required = true)
+    public Object addHighClass(@RequestBody List<HighClassGroupDto> highClassGroupDtoList) throws Exception {
         if (highClassGroupDtoList.size() <= 0) {
             return failed("参数不合法");
         }