Bladeren bron

feat:课程计费逻辑调整

Joburgess 4 jaren geleden
bovenliggende
commit
cac4f28e41

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -3,6 +3,7 @@ package com.ym.mec.biz.dal.dao;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
+import com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
@@ -392,4 +393,12 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      */
     List<StudentVipDouble11Dto> countStudentDouble11CourseTime(@Param("userIds") List<Integer> userIds,
                                                                @Param("specialActivityIds") List<Integer> specialActivityIds);
+
+    /**
+     * @describe 获取需要更新课营收的课程
+     * @author qnc99
+     * @date 2020/12/2 0002
+     * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto>
+     */
+    List<CourseScheduleStudentPaymentDto> findNeedUpdateActualPriceStudentCourses();
 }

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRegistrationDao.java

@@ -18,6 +18,9 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
 
     StudentRegistration lock(@Param("id") Long id);
 
+    StudentRegistration lockWithUserAndMusic(@Param("userId") Integer userId,
+                                             @Param("musicGroupId") String musicGroupId);
+
     /**
      * 获取乐团学员报名详情
      *

+ 20 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseScheduleStudentPaymentDto.java

@@ -0,0 +1,20 @@
+package com.ym.mec.biz.dal.entity;
+
+import com.ym.mec.biz.dal.enums.CourseStatusEnum;
+
+/**
+ * @Author qnc99
+ * @Date 2020/12/2 0002
+ */
+public class CourseScheduleStudentPaymentDto extends CourseScheduleStudentPayment{
+
+    private CourseStatusEnum courseStatus;
+
+    public CourseStatusEnum getCourseStatus() {
+        return courseStatus;
+    }
+
+    public void setCourseStatus(CourseStatusEnum courseStatus) {
+        this.courseStatus = courseStatus;
+    }
+}

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

@@ -11,9 +11,6 @@ public class StudentCourseFeeDetail {
 	/**  */
 	private Long studentRegistrationId;
 	
-	/** 交易类型 (RECHARGE 充值,PAY_FEE 缴费) */
-	private PlatformCashAccountDetailTypeEnum type;
-	
 	/** 交易金额 */
 	private java.math.BigDecimal amount;
 	
@@ -40,14 +37,6 @@ public class StudentCourseFeeDetail {
 		return this.studentRegistrationId;
 	}
 
-	public PlatformCashAccountDetailTypeEnum getType() {
-		return type;
-	}
-
-	public void setType(PlatformCashAccountDetailTypeEnum type) {
-		this.type = type;
-	}
-
 	public void setAmount(java.math.BigDecimal amount){
 		this.amount = amount;
 	}

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

@@ -109,4 +109,12 @@ public interface CourseScheduleStudentPaymentService extends BaseService<Long, C
 	 */
 	List<SimpleUserDto> getCourseStudents(List<Long> courseIds);
 
+	/**
+	 * @describe 更新课程营收
+	 * @author qnc99
+	 * @date 2020/12/2 0002
+	 * @return void
+	 */
+	void updateCourseActualPrice();
+
 }

+ 0 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -89,8 +89,6 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      */
     void sellOrderBatchNoAllot();
 
-    void getGoodsTest(List<Integer> goodsIds);
-
     /**
      * @describe 扣减商品库存
      * @author Joburgess

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

@@ -303,11 +303,11 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
      * @describe 更新学生乐团可用课程余额
      * @author qnc99
      * @date 2020/12/2 0002
-     * @param studentRegistrationId:
+     * @param userId:
      * @param amount:
      * @param memo:
      * @param operatorId:
      * @return boolean
      */
-    boolean updateUserSurplusCourseFee(Long studentRegistrationId, BigDecimal amount, String memo, Integer operatorId);
+    boolean updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId);
 }

+ 40 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -9,6 +9,7 @@ import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.page.CourseScheduleStudentPaymentQueryInfo;
 import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
+import com.ym.mec.biz.service.StudentRegistrationService;
 import com.ym.mec.biz.service.SysUserCashAccountService;
 import com.ym.mec.common.constant.CommonConstants;
 import com.ym.mec.common.dal.BaseDAO;
@@ -61,6 +62,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	private StudentDao studentDao;
 	@Autowired
 	private SubjectDao subjectDao;
+	@Autowired
+	private StudentRegistrationService studentRegistrationService;
 
 	@Override
 	public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
@@ -405,9 +408,9 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 			}
 		}
 		courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
-		for (String batchNo : allBatchNos) {
-			updateForMusicGroupWithPaymentCalender(batchNo);
-		}
+//		for (String batchNo : allBatchNos) {
+//			updateForMusicGroupWithPaymentCalender(batchNo);
+//		}
 	}
 
 	@Override
@@ -571,4 +574,38 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 		}
 		return usersSimpleInfo;
 	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void updateCourseActualPrice() {
+		List<CourseScheduleStudentPaymentDto> courseScheduleStudentPayments = courseScheduleStudentPaymentDao.findNeedUpdateActualPriceStudentCourses();
+		if(CollectionUtils.isEmpty(courseScheduleStudentPayments)){
+			return;
+		}
+		List<CourseScheduleStudentPayment> needUpdates = new ArrayList<>();
+		Map<CourseStatusEnum, List<CourseScheduleStudentPaymentDto>> statusCoursesMap = courseScheduleStudentPayments.stream().collect(Collectors.groupingBy(CourseScheduleStudentPaymentDto::getCourseStatus));
+		if(statusCoursesMap.containsKey(CourseStatusEnum.NOT_START)){
+			List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.NOT_START);
+			for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
+				studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), notStartCourse.getActualPrice(), StringUtils.join("课程状态变更到未开始,退还缴费:", notStartCourse.getCourseScheduleId()), null);
+				notStartCourse.setActualPrice(BigDecimal.ZERO);
+				needUpdates.add(notStartCourse);
+			}
+		}
+
+		if(statusCoursesMap.containsKey(CourseStatusEnum.OVER)){
+			List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.OVER);
+			for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
+				boolean isUpdate = studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), notStartCourse.getExpectPrice().negate(), StringUtils.join("课程结束,扣除课程费用:", notStartCourse.getCourseScheduleId()), null);
+				if(!isUpdate){
+					continue;
+				}
+				notStartCourse.setActualPrice(notStartCourse.getExpectPrice());
+				needUpdates.add(notStartCourse);
+			}
+		}
+		if(!CollectionUtils.isEmpty(needUpdates)){
+			courseScheduleStudentPaymentDao.batchUpdate(needUpdates);
+		}
+	}
 }

+ 0 - 36
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -466,42 +466,6 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-	public void getGoodsTest(List<Integer> goodsIds) {
-		goodsDao.lockGoods(new ArrayList<>(goodsIds));
-		for (Integer goodsId : goodsIds) {
-			Goods tempGoods = goodsDao.get(goodsId);
-			List<Goods> childGoods = new ArrayList<>();
-			if(StringUtils.isBlank(tempGoods.getComplementGoodsIdList())){
-				childGoods.add(tempGoods);
-			}else{
-				List<Integer> complementGoodsIds = Arrays.stream(tempGoods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
-				childGoods = goodsDao.getGoodies(complementGoodsIds);
-			}
-			for (Goods goods : childGoods) {
-				GoodsProcurement goodsProcurement;
-				if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(AccountType.INTERNAL))){
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
-					goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
-					if(Objects.nonNull(goodsProcurement)){
-						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
-					}
-				}else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(AccountType.EXTERNAL))){
-					goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(goods.getId());
-					goods.setTaxStockCount(new AtomicInteger(goods.getTaxStockCount()).decrementAndGet());
-					if(Objects.nonNull(goodsProcurement)){
-						goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
-					}
-				}
-
-				goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
-
-				goodsDao.update(goods);
-			}
-		}
-	}
-
-	@Override
-	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public List<SellOrder> subtractStock(List<Integer> goodsIds, AccountType accountType) {
 		if(CollectionUtils.isEmpty(goodsIds)){
 			return Collections.emptyList();

+ 0 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -1139,7 +1139,6 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		calender.setActualNum(actualNum + 1);
 		calender.setUpdateTime(date);
 		musicGroupPaymentCalenderDao.update(calender);
-		courseScheduleStudentPaymentService.updateForMusicGroupWithPaymentCalender(calender.getBatchNo());
 		return musicGroupStudentFee;
 	}
 

+ 6 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -1281,8 +1281,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Override
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-    public boolean updateUserSurplusCourseFee(Long studentRegistrationId, BigDecimal amount, String memo, Integer operatorId) {
-        StudentRegistration studentRegistration = studentRegistrationDao.lock(studentRegistrationId);
+    public boolean updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId) {
+        StudentRegistration studentRegistration = studentRegistrationDao.lockWithUserAndMusic(userId, musicGroupId);
         if(Objects.isNull(studentRegistration)){
             throw new BizException("学员注册信息不存在");
         }
@@ -1291,13 +1291,14 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             return true;
         }
 
-        if(studentRegistration.getSurplusCourseFee().compareTo(amount)<0){
+        studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(amount));
+
+        if(BigDecimal.ZERO.compareTo(studentRegistration.getSurplusCourseFee())>0){
             return false;
         }
-        studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(amount));
 
         StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
-        studentCourseFeeDetail.setStudentRegistrationId(studentRegistrationId);
+        studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
         studentCourseFeeDetail.setAmount(amount);
         studentCourseFeeDetail.setSurplusCourseFee(studentRegistration.getSurplusCourseFee());
         studentCourseFeeDetail.setMemo(memo);

+ 17 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -30,6 +30,10 @@
 		<result column="freePracticeTimes" property="freePracticeCourseTimes" />
 	</resultMap>
 
+	<resultMap id="CourseScheduleStudentPaymentDto" type="com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto" extends="CourseScheduleStudentPayment">
+		<result column="course_status_" property="courseStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+	</resultMap>
+
 	<!-- 根据主键查询一条记录 -->
 	<select id="get" resultMap="CourseScheduleStudentPayment" >
 		SELECT * FROM course_schedule_student_payment WHERE id_ = #{id}
@@ -619,4 +623,17 @@
 		GROUP BY
 			cssp.user_id_
     </select>
+
+	<select id="findNeedUpdateActualPriceStudentCourses" resultMap="CourseScheduleStudentPaymentDto">
+		SELECT
+			cssp.*,
+			cs.status_ course_status_
+		FROM
+			course_schedule_student_payment cssp
+		LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
+		WHERE
+			cssp.batch_no_ IS NOT NULL
+			AND ((cs.status_ = 'OVER' AND (cssp.actual_price_ IS NULL OR cssp.actual_price_ &lt;= 0))
+			OR ( cs.status_ = 'NOT_START' AND (cssp.actual_price_ IS NOT NULL AND cssp.actual_price_ &gt; 0)))
+	</select>
 </mapper>

+ 2 - 6
mec-biz/src/main/resources/config/mybatis/StudentCourseFeeDetailMapper.xml

@@ -8,7 +8,6 @@
 	
 	<resultMap type="com.ym.mec.biz.dal.entity.StudentCourseFeeDetail" id="StudentCourseFeeDetail">
 		<result column="student_registration_id_" property="studentRegistrationId" />
-		<result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
 		<result column="amount_" property="amount" />
 		<result column="surplus_course_fee_" property="surplusCourseFee" />
 		<result column="memo_" property="memo" />
@@ -24,16 +23,13 @@
 	
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentCourseFeeDetail" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-		INSERT INTO student_course_fee_detail (student_registration_id_,type_,amount_,surplus_course_fee_,memo_,operator_,create_time_,update_time_)
-		VALUES(#{studentRegistrationId},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{amount},#{surplusCourseFee},#{memo},#{operator},NOW(),NOW())
+		INSERT INTO student_course_fee_detail (student_registration_id_,amount_,surplus_course_fee_,memo_,operator_,create_time_,update_time_)
+		VALUES(#{studentRegistrationId},#{amount},#{surplusCourseFee},#{memo},#{operator},NOW(),NOW())
 	</insert>
 
 	<update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentCourseFeeDetail">
 		UPDATE student_course_fee_detail
 		<set>
-			<if test="type!=null">
-				type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-			</if>
 			<if test="amount!=null">
 				amount_ = #{amount},
 			</if>

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

@@ -87,6 +87,10 @@
         SELECT * FROM student_registration WHERE id_ = #{id} FOR UPDATE
     </select>
 
+    <select id="lockWithUserAndMusic" resultMap="StudentRegistration">
+        SELECT * FROM student_registration WHERE user_id_ = #{userId} AND music_group_id_=#{musicGroupId} FOR UPDATE
+    </select>
+
     <!-- 全查询 -->
     <select id="findAll" resultMap="StudentRegistration">
         SELECT *

+ 0 - 8
mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -122,12 +122,4 @@ public class GoodsController extends BaseController {
     public Object findGoodsBySubId(Integer subjectId,String type){
         return succeed(goodsService.findGoodsBySubId(subjectId,type));
     }
-
-    @GetMapping("getGoodsTest")
-    @Transactional(rollbackFor = Exception.class)
-    public HttpResponseResult getGoodsTest(Integer goodsId){
-        goodsService.getGoodsTest(Arrays.asList(goodsId));
-//        goodsService.subtractStock(Arrays.asList(goodsId), AccountType.INTERNAL);
-        return succeed();
-    }
 }

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -78,6 +78,9 @@ public class TaskController extends BaseController {
 	@Autowired
 	private StudentGoodsSellService studentGoodsSellService;
 
+	@Autowired
+	private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
+
 	@GetMapping(value = "/autoAffirmReceiveTask")
 	// 自动确认收货
 	public void affirmReceive(){
@@ -288,4 +291,9 @@ public class TaskController extends BaseController {
 	public void operatingReport(){
 		operatingReportService.statistics();
 	}
+
+	@GetMapping("/updateCourseActualPrice")
+	public void updateCourseActualPrice(){
+		courseScheduleStudentPaymentService.updateCourseActualPrice();
+	}
 }