Преглед на файлове

Merge remote-tracking branch 'origin/master'

Joburgess преди 5 години
родител
ревизия
c4f72d0a02
променени са 14 файла, в които са добавени 330 реда и са изтрити 76 реда
  1. 18 14
      mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/web/controller/SmsCodeController.java
  2. 34 14
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDao.java
  3. 21 0
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java
  4. 1 1
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentRegistrationService.java
  5. 27 15
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java
  6. 4 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
  7. 3 3
      mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml
  8. 9 0
      mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml
  9. 4 0
      mec-common/common-core/src/main/java/com/ym/mec/common/redis/service/RedisCache.java
  10. 17 0
      mec-common/common-core/src/main/java/com/ym/mec/common/service/IdGeneratorService.java
  11. 89 0
      mec-common/common-core/src/main/java/com/ym/mec/common/service/impl/RedisIdGeneratorService.java
  12. 6 10
      mec-education/src/main/java/com/ym/mec/education/service/impl/ClassGroupStudentMapperServiceImpl.java
  13. 3 14
      mec-education/src/main/java/com/ym/mec/education/service/impl/TeacherServiceImpl.java
  14. 94 3
      mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

+ 18 - 14
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/web/controller/SmsCodeController.java

@@ -1,28 +1,32 @@
 package com.ym.mec.auth.web.controller;
 
-import com.google.code.kaptcha.Constants;
-import com.google.code.kaptcha.Producer;
-import com.google.code.kaptcha.servlet.KaptchaServlet;
-import com.ym.mec.auth.config.constant.SecurityConstants;
-import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.validcode.SmsCodeService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+
+import java.awt.image.BufferedImage;
+import java.util.concurrent.TimeUnit;
+
+import javax.imageio.ImageIO;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.http.MediaType;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
-import javax.imageio.ImageIO;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
-import java.util.HashMap;
-import java.util.concurrent.TimeUnit;
+import com.google.code.kaptcha.Constants;
+import com.google.code.kaptcha.Producer;
+import com.google.code.kaptcha.servlet.KaptchaServlet;
+import com.ym.mec.auth.config.constant.SecurityConstants;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.validcode.SmsCodeService;
 
 @RestController
 @RequestMapping("code")

+ 34 - 14
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDao.java

@@ -1,8 +1,11 @@
 package com.ym.mec.biz.dal.dao;
 
 import com.ym.mec.biz.dal.entity.Goods;
+import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
 
@@ -10,19 +13,36 @@ import java.util.List;
 
 public interface StudentPaymentOrderDao extends BaseDAO<Long, StudentPaymentOrder> {
 
-	/**
-	 * 查询商品列表
-	 * @param musicGroupId
-	 * @param type
-	 * @return
-	 */
-	List<Goods> queryApplyGoodsList(@Param("musicGroupId") Integer musicGroupId, @Param("type") OrderDetailTypeEnum type);
+    /**
+     * 查询商品列表
+     *
+     * @param musicGroupId
+     * @param type
+     * @return
+     */
+    List<Goods> queryApplyGoodsList(@Param("musicGroupId") Integer musicGroupId, @Param("type") OrderDetailTypeEnum type);
 
-	/**
-	 * @Author: Joburgess
-	 * @Date: 2019/10/3
-	 * 根据学生vip课获取缴费订单
-	 */
-	StudentPaymentOrder findByStudentVipGroup(@Param("vipGroupId") Long vipGroupId,
-											  @Param("userId") Long userId);
+    /**
+     * @Author: Joburgess
+     * @Date: 2019/10/3
+     * 根据学生vip课获取缴费订单
+     */
+    StudentPaymentOrder findByStudentVipGroup(@Param("vipGroupId") Long vipGroupId, @Param("userId") Long userId);
+
+    /**
+     * 查询乐团报名的订单
+     *
+     * @param userId
+     * @param musicGroupId
+     * @param status
+     * @return
+     */
+    StudentPaymentOrder findMusicGroupApplyOrderByStatus(@Param("userId") Integer userId, @Param("musicGroupId") String musicGroupId, @Param("status") DealStatusEnum status);
+
+    /**
+     * 根据订单号查询订单
+     * @param orderNo
+     * @return
+     */
+    StudentPaymentOrder findOrderByOrderNo(@Param("orderNo") String orderNo);
 }

+ 21 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java

@@ -4,8 +4,11 @@ import java.util.List;
 
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.common.service.BaseService;
+import org.apache.ibatis.annotations.Param;
 
 public interface StudentPaymentOrderService extends BaseService<Long, StudentPaymentOrder> {
 
@@ -16,4 +19,22 @@ public interface StudentPaymentOrderService extends BaseService<Long, StudentPay
 	 * @return
 	 */
 	List<Goods> queryApplyGoodsList(Integer musicGroupId, OrderDetailTypeEnum type);
+
+	/**
+	 * 查询报名缴费订单
+	 * @param musicGroupId
+	 * @param status
+	 * @return
+	 */
+	StudentPaymentOrder findMusicGroupApplyOrderByStatus(Integer userId,String musicGroupId, DealStatusEnum status);
+
+
+	/**
+	 * 根据orderNo查询订单
+	 * @param orderNo
+	 * @return
+	 */
+	StudentPaymentOrder findOrderByOrderNo(String orderNo);
+
+
 }

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

@@ -93,6 +93,6 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
      * @param goodsList
      * @return
      */
-    StudentPaymentOrder addOrder(Integer userId,BigDecimal amount,String orderNo,String paymentChannel,BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList);
+    StudentPaymentOrder addOrder(Integer userId,BigDecimal amount,String orderNo,String paymentChannel,BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList,String musicGroupId);
 
 }

+ 27 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -2,6 +2,8 @@ package com.ym.mec.biz.service.impl;
 
 import java.util.List;
 
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -14,19 +16,29 @@ import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 
 @Service
-public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder>  implements StudentPaymentOrderService {
-	
-	@Autowired
-	private StudentPaymentOrderDao studentPaymentOrderDao;
-
-	@Override
-	public BaseDAO<Long, StudentPaymentOrder> getDAO() {
-		return studentPaymentOrderDao;
-	}
-
-	@Override
-	public List<Goods> queryApplyGoodsList(Integer musicGroupId, OrderDetailTypeEnum type) {
-		return studentPaymentOrderDao.queryApplyGoodsList(musicGroupId, type);
-	}
-	
+public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
+
+    @Autowired
+    private StudentPaymentOrderDao studentPaymentOrderDao;
+
+    @Override
+    public BaseDAO<Long, StudentPaymentOrder> getDAO() {
+        return studentPaymentOrderDao;
+    }
+
+    @Override
+    public List<Goods> queryApplyGoodsList(Integer musicGroupId, OrderDetailTypeEnum type) {
+        return studentPaymentOrderDao.queryApplyGoodsList(musicGroupId, type);
+    }
+
+    @Override
+    public StudentPaymentOrder findMusicGroupApplyOrderByStatus(Integer userId,String musicGroupId, DealStatusEnum status) {
+        return studentPaymentOrderDao.findMusicGroupApplyOrderByStatus(userId,musicGroupId, status);
+    }
+
+    @Override
+    public StudentPaymentOrder findOrderByOrderNo(String orderNo) {
+        return studentPaymentOrderDao.findOrderByOrderNo(orderNo);
+    }
+
 }

+ 4 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -44,7 +44,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     private SysUserFeignService sysUserFeignService;
     @Autowired
     private StudentPaymentOrderService studentPaymentOrderService;
-
+    @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
 
     @Override
@@ -140,16 +140,18 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public StudentPaymentOrder addOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList) {
+    public StudentPaymentOrder addOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId) {
 
         Date date = new Date();
         StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
         studentPaymentOrder.setUserId(userId);
+        studentPaymentOrder.setOrderNo(orderNo);
         studentPaymentOrder.setType(OrderTypeEnum.APPLY);
         studentPaymentOrder.setExpectAmount(amount);
         studentPaymentOrder.setActualAmount(amount);
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
         studentPaymentOrder.setPaymentChannel(paymentChannel);
+        studentPaymentOrder.setMusicGroupId(musicGroupId);
         studentPaymentOrderService.insert(studentPaymentOrder);
 
         ArrayList<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();

+ 3 - 3
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml

@@ -80,10 +80,10 @@
 
     <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id_">
         INSERT INTO student_payment_order_detail
-        (type_,goods_id_list_,price_,create_time_,update_time_,payment_order_id_)
-        VALUE
+        (id_,type_,goods_id_list_,price_,create_time_,update_time_,payment_order_id_)
+        VALUES
         <foreach collection="studentPaymentOrderDetailList" item="orderDetail" separator=",">
-            (#{orderDetail.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{orderDetail.goodsIdList},#{orderDetail.price},#{orderDetail.createTime},#{orderDetail.updateTime},#{orderDetail.paymentOrderId})
+            (#{orderDetail.id},#{orderDetail.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{orderDetail.goodsIdList},#{orderDetail.price},#{orderDetail.createTime},#{orderDetail.updateTime},#{orderDetail.paymentOrderId})
         </foreach>
     </insert>
 </mapper>

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

@@ -150,4 +150,13 @@
             LEFT JOIN student_payment_order spo ON svgp.student_payment_order_id_=spo.id_
             WHERE svgp.user_id_=#{userId} AND svgp.vip_group_id_=#{vipGroupId}
     </select>
+    <!-- 查询报名订单 -->
+    <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
+        SELECT * FROM student_payment_order WHERE music_group_id_= #{musicGroupId} AND user_id_=#{userId} AND type_ = 'APPLY' AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+    </select>
+
+    <!-- 根据订单号查询订单 -->
+    <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
+        SELECT * FROM student_payment_order WHERE order_no_ = #{orderNo}
+    </select>
 </mapper>

+ 4 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/redis/service/RedisCache.java

@@ -68,4 +68,8 @@ public class RedisCache<K, V> implements Cache<K, V> {
 	public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
 		this.redisTemplate = redisTemplate;
 	}
+
+	public RedisTemplate<K, V> getRedisTemplate() {
+		return redisTemplate;
+	}
 }

+ 17 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/service/IdGeneratorService.java

@@ -0,0 +1,17 @@
+package com.ym.mec.common.service;
+
+public interface IdGeneratorService {
+
+	/**
+	 * 根据业务名称生产id
+	 * @param biz
+	 * @return
+	 */
+	long generatorId(String biz);
+
+	/**
+	 * 自动生成id
+	 * @return
+	 */
+	long generatorId();
+}

+ 89 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/service/impl/RedisIdGeneratorService.java

@@ -0,0 +1,89 @@
+package com.ym.mec.common.service.impl;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.stereotype.Service;
+
+import com.google.common.base.Strings;
+import com.ym.mec.common.redis.service.RedisCache;
+import com.ym.mec.common.service.IdGeneratorService;
+
+@Service
+public class RedisIdGeneratorService implements IdGeneratorService {
+
+	private final static Logger log = LoggerFactory.getLogger(RedisIdGeneratorService.class);
+
+	private static final String keyPrefix = "smart";
+
+	@Autowired
+	private RedisCache<String,Object> redisCache;
+
+	/**
+	 * @Description
+	 * @author butterfly
+	 */
+	private String getIDPrefix() {
+		Date date = new Date();
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		int year = c.get(Calendar.YEAR);
+		int month = c.get(Calendar.MONTH) + 1;
+		int day = c.get(Calendar.DAY_OF_MONTH); // 今天是第多少天
+		int hour = c.get(Calendar.HOUR_OF_DAY);
+		int minute = c.get(Calendar.MINUTE);
+		int second = c.get(Calendar.SECOND);
+		String monthFmt = String.format("%1$02d", month);
+		String dayFmt = String.format("%1$02d", day); // 0补位操作 必须满足三位
+		String hourFmt = String.format("%1$02d", hour); // 0补位操作 必须满足2位
+		String minuteFmt = String.format("%1$02d", minute); // 0补位操作 必须满足2位
+		String secondFmt = String.format("%1$02d", second); // 0补位操作 必须满足2位
+		StringBuffer prefix = new StringBuffer();
+		prefix.append((year - 2000)).append(monthFmt).append(dayFmt).append(hourFmt).append(minuteFmt).append(secondFmt);
+		return prefix.toString();
+	}
+
+	/**
+	 * @author butterfly
+	 */
+	private long incrDistrId(String biz) {
+		String prefix = getIDPrefix();
+		String orderId = null;
+		String key = "#{biz}:id:".replace("#{biz}", biz).concat(prefix); // 001
+		RedisTemplate<String, Object> redisTemplate = redisCache.getRedisTemplate();
+		try {
+			ValueOperations<String, Object> valueOper = redisTemplate.opsForValue();
+			Long index = valueOper.increment(key, 1);
+			orderId = prefix.concat(String.format("%1$03d", index)); // 补位操作 保证满足3位
+		} catch (Exception ex) {
+			log.error("分布式订单号生成失败异常。。。。。", ex);
+		} finally {
+			redisTemplate.expire(key, 600, TimeUnit.SECONDS);// 保留10分钟内的key
+		}
+		if (Strings.isNullOrEmpty(orderId))
+			return 0;
+		return Long.parseLong(orderId);
+	}
+
+	/**
+	 * @Description 生成分布式ID
+	 * @author butterfly
+	 */
+	@Override
+	public long generatorId(String biz) {
+		// 转成数字类型,可排序
+		return incrDistrId(biz);
+	}
+
+	@Override
+	public long generatorId() {
+		return incrDistrId(keyPrefix);
+	}
+	
+}

+ 6 - 10
mec-education/src/main/java/com/ym/mec/education/service/impl/ClassGroupStudentMapperServiceImpl.java

@@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
 import com.ym.mec.biz.dal.enums.JobTypeEnum;
 import com.ym.mec.common.enums.UserGenderEnum;
-import com.ym.mec.common.security.AuthUser;
-import com.ym.mec.common.security.SecurityUtils;
 import com.ym.mec.education.base.BaseResponse;
 import com.ym.mec.education.base.PageResponse;
 import com.ym.mec.education.entity.*;
@@ -24,7 +22,9 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -113,14 +113,10 @@ public class ClassGroupStudentMapperServiceImpl extends ServiceImpl<ClassGroupSt
 
     @Override
     public PageResponse getPageByTeacher(StudentReq studentReq) {
-        Teacher teacher;
-        //判断当前登录人角色
-        AuthUser user = SecurityUtils.getUser();
-        if(Objects.nonNull(user)) {
-            teacher = teacherService.getById(user.getUserId());
-        }else {
-            teacher = teacherService.getById(studentReq.getTeacherId());
+        if (Objects.isNull(studentReq.getTeacherId())) {
+            return PageResponse.errorParam();
         }
+        Teacher teacher = teacherService.getById(studentReq.getTeacherId());
         if (Objects.nonNull(teacher)) {
             //教学主管
             QueryWrapper<MusicGroup> musicGroupQueryWrapper = new QueryWrapper<>();

+ 3 - 14
mec-education/src/main/java/com/ym/mec/education/service/impl/TeacherServiceImpl.java

@@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
-import com.ym.mec.common.security.AuthUser;
-import com.ym.mec.common.security.SecurityUtils;
 import com.ym.mec.education.base.BaseResponse;
 import com.ym.mec.education.base.PageResponse;
 import com.ym.mec.education.entity.*;
@@ -24,7 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
-
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
@@ -320,22 +317,14 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> impl
 
     @Override
     public PageResponse dailySchedule(TeacherReq req) {
-        AuthUser user = SecurityUtils.getUser();
-        Optional<AuthUser> optional = Optional.ofNullable(user);
         Page<TeacherDailyScheduleResp> pageResult = new Page<>();
-        Integer userId;
-        if (optional.isPresent()) {
-            userId = optional.get().getUserId();
-        } else {
-            if (Objects.isNull(req.getUserId())) {
-                return PageResponse.errorParam();
-            }
-            userId = req.getUserId();
+        if (Objects.isNull(req.getUserId())) {
+            return PageResponse.errorParam();
         }
         List<TeacherDailyScheduleResp> list = Lists.newArrayList();
         Page<CourseSchedule> courseSchedulePage = new Page<>(req.getPageNo(), req.getPageSize());
         QueryWrapper<CourseSchedule> courseScheduleQueryWrapper = new QueryWrapper<>();
-        courseScheduleQueryWrapper.lambda().eq(CourseSchedule::getTeacherId, userId)
+        courseScheduleQueryWrapper.lambda().eq(CourseSchedule::getTeacherId, req.getUserId())
             .eq(Objects.isNull(req.getDate()), CourseSchedule::getClassDate, req.getDate());
         IPage<CourseSchedule> page = courseScheduleService.page(courseSchedulePage, courseScheduleQueryWrapper);
         BeanUtils.copyProperties(page, pageResult);

+ 94 - 3
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

@@ -5,8 +5,10 @@ import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.MusicGroupSubjectGoodsAndInfoDto;
 import com.ym.mec.biz.dal.dto.RegisterPayDto;
 import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GoodsType;
 import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
@@ -16,6 +18,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -97,6 +100,93 @@ public class MusicGroupController extends BaseController {
             return failed("报名信息有误,请核查");
         }
 
+        StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.SUCCESS);
+        if (ApplyOrder != null) {
+            return failed("您已支付成功,请勿重复支付");
+        }
+
+        //判断用户是否已存在订单
+        ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.ING);
+        if (ApplyOrder != null) {
+            return failed(HttpStatus.CONTINUE, "您有待支付的订单");
+        }
+
+        BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
+        BigDecimal orderAmount = new BigDecimal("0");
+
+        //获取课程价格
+        MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId());
+        BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
+        orderAmount = orderAmount.add(courseFee);
+
+
+        //乐器及打包辅件
+        List<MusicGroupSubjectGoodsGroup> goodsGroups = null;
+        if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
+            goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
+            for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
+                orderAmount = orderAmount.add(goodsGroup.getPrice());
+                //团购乐器减免课程费用
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
+                    orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
+                }
+            }
+        }
+
+        //单独辅件
+        List<Goods> goodsList = null;
+        if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
+            goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
+            for (Goods goods : goodsList) {
+                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+            }
+        }
+
+        //单独教谱
+        List<Goods> otherGoodsList = null;
+        if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
+            otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
+            for (Goods goods : otherGoodsList) {
+                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+            }
+        }
+        if (amount.compareTo(orderAmount) != 0) {
+            return failed("商品价格不符");
+        }
+
+
+        IdWorker idWorker = new IdWorker(0, 0);
+        String orderNo = idWorker.nextId();
+
+        Map payMap = payService.getPayMap(orderAmount, orderNo, "https://pay.dayaedu.com/api/yqpay/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
+
+        studentRegistrationService.addOrder(userId, amount, orderNo, "双乾", courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId().toString());
+
+        return succeed(payMap);
+    }
+
+    @ApiOperation(value = "乐团报名重新支付")
+    @PostMapping("/rePay")
+    @ApiImplicitParams({@ApiImplicitParam(name = "registerPayDto", value = "支付信息", required = true, dataType = "Integer")})
+    public HttpResponseResult rePay(@RequestBody RegisterPayDto registerPayDto) throws Exception {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        Integer userId = sysUser.getId();
+        StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
+        if (!studentRegistration.getUserId().equals(userId)) {
+            return failed("报名信息有误,请核查");
+        }
+
+        StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.SUCCESS);
+        if (ApplyOrder != null) {
+            return failed("您已支付成功,请勿重复支付");
+        }
+
+        //判断用户是否已存在订单
+        ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.ING);
+        if (ApplyOrder == null) {
+            return failed(HttpStatus.CONTINUE, "没有支付中的订单,请勿非法请求");
+        }
+
         BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
         BigDecimal orderAmount = new BigDecimal("0");
 
@@ -144,9 +234,9 @@ public class MusicGroupController extends BaseController {
         IdWorker idWorker = new IdWorker(0, 0);
         String orderNo = idWorker.nextId();
 
-        Map payMap = payService.getPayMap(orderAmount, orderNo, "https://pay.dayaedu.com/yqpay/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
+        Map payMap = payService.getPayMap(orderAmount, orderNo, "https://pay.dayaedu.com/api/yqpay/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
 
-        studentRegistrationService.addOrder(userId, amount, orderNo, "双乾", courseFee, goodsGroups, goodsList, otherGoodsList);
+        studentRegistrationService.addOrder(userId, amount, orderNo, "双乾", courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId().toString());
 
         return succeed(payMap);
     }
@@ -165,6 +255,7 @@ public class MusicGroupController extends BaseController {
     @GetMapping("/getOrderStatus")
     @ApiImplicitParams({@ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String")})
     public HttpResponseResult getOrderStatus(String orderNo) {
-        return succeed(orderNo);
+        StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(orderNo);
+        return succeed(order);
     }
 }