Просмотр исходного кода

Merge branch 'maintenance_feature' into 20200324

# Conflicts:
#	mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java
#	mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java
#	mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java
周箭河 4 лет назад
Родитель
Сommit
24f27270b4
17 измененных файлов с 447 добавлено и 43 удалено
  1. 23 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentInstrumentDao.java
  2. 53 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentInstrument.java
  3. 2 1
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentGoodsSellService.java
  4. 30 0
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentInstrumentService.java
  5. 21 6
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java
  6. 5 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java
  7. 85 4
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java
  8. 12 9
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
  9. 5 5
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java
  10. 8 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java
  11. 70 12
      mec-biz/src/main/resources/config/mybatis/StudentInstrumentMapper.xml
  12. 1 1
      mec-biz/src/main/resources/config/mybatis/StudentRepairMapper.xml
  13. 4 0
      mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java
  14. 5 0
      mec-client-api/src/main/java/com/ym/mec/task/fallback/TaskRemoteServiceFallback.java
  15. 19 0
      mec-task/src/main/java/com/ym/mec/task/jobs/MaintenanceOldDataAddTask.java
  16. 98 2
      mec-web/src/main/java/com/ym/mec/web/controller/StudentInstrumentController.java
  17. 6 0
      mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

+ 23 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentInstrumentDao.java

@@ -26,9 +26,32 @@ public interface StudentInstrumentDao extends BaseDAO<Long, StudentInstrument> {
 
 
     /**
     /**
      * 根据服务结束时间获取列表
      * 根据服务结束时间获取列表
+     *
      * @param startTime
      * @param startTime
      * @param endTime
      * @param endTime
      * @return
      * @return
      */
      */
     List<StudentInstrument> getListByEndTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
     List<StudentInstrument> getListByEndTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
+
+    /**
+     * 获取学生乐器信息
+     *
+     * @param orderId
+     * @return
+     */
+    StudentInstrument getByOrderId(Long orderId);
+
+    /**
+     * 获取学生的乐器信息
+     *
+     * @return
+     */
+    StudentInstrument getStudentInstrument(@Param("studentId") Integer studentId, @Param("goodsId") Integer goodsId);
+
+    /**
+     * 获取用户已购买乐保的商品的记录
+     * @param startTime
+     * @return
+     */
+    List<StudentInstrument> getOldStudentInstrument(@Param("startTime") Date startTime);
 }
 }

+ 53 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentInstrument.java

@@ -59,6 +59,24 @@ public class StudentInstrument {
     private Date endTime;
     private Date endTime;
 
 
     /**
     /**
+     * 对应订单id
+     */
+    @ApiModelProperty(value = "原订单id")
+    private Long orderId;
+
+    /**
+     * 对应订单id
+     */
+    @ApiModelProperty(value = "更改后订单id")
+    private Long changeOrderId;
+
+    /**
+     * 操作人
+     */
+    @ApiModelProperty(value = "操作人")
+    private Integer operation;
+
+    /**
      * 添加时间
      * 添加时间
      */
      */
     @ApiModelProperty(value = "添加时间")
     @ApiModelProperty(value = "添加时间")
@@ -70,6 +88,9 @@ public class StudentInstrument {
     @ApiModelProperty(value = "更新时间")
     @ApiModelProperty(value = "更新时间")
     private Date updateTime;
     private Date updateTime;
 
 
+    @ApiModelProperty(value = "删除标识 1 已删除 0 正常")
+    private Integer delFlag;
+
     @ApiModelProperty(value = "乐器名称")
     @ApiModelProperty(value = "乐器名称")
     private String goodsName;
     private String goodsName;
 
 
@@ -235,4 +256,36 @@ public class StudentInstrument {
     public void setGoodsCategoryName(String goodsCategoryName) {
     public void setGoodsCategoryName(String goodsCategoryName) {
         this.goodsCategoryName = goodsCategoryName;
         this.goodsCategoryName = goodsCategoryName;
     }
     }
+
+    public Integer getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(Integer delFlag) {
+        this.delFlag = delFlag;
+    }
+
+    public Long getOrderId() {
+        return orderId;
+    }
+
+    public void setOrderId(Long orderId) {
+        this.orderId = orderId;
+    }
+
+    public Integer getOperation() {
+        return operation;
+    }
+
+    public void setOperation(Integer operation) {
+        this.operation = operation;
+    }
+
+    public Long getChangeOrderId() {
+        return changeOrderId;
+    }
+
+    public void setChangeOrderId(Long changeOrderId) {
+        this.changeOrderId = changeOrderId;
+    }
 }
 }

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

@@ -5,6 +5,7 @@ import com.ym.mec.biz.dal.dto.StudentGoodsSellDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.entity.StudentGoodsSell;
 import com.ym.mec.biz.dal.entity.StudentGoodsSell;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
 import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.common.service.BaseService;
@@ -51,6 +52,6 @@ public interface StudentGoodsSellService extends BaseService<Integer, StudentGoo
      * 将购买的乐器加入学生乐器列表
      * 将购买的乐器加入学生乐器列表
      * @return
      * @return
      */
      */
-    List<StudentInstrument> saveStudentInstrument(String orderNo);
+    List<StudentInstrument> saveStudentInstrument(StudentPaymentOrder order);
 
 
 }
 }

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

@@ -4,6 +4,7 @@ import com.ym.mec.biz.dal.dto.MaintenancePayDto;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 
 
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.SubjectChange;
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.common.service.BaseService;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
@@ -45,4 +46,33 @@ public interface StudentInstrumentService extends BaseService<Long, StudentInstr
      * @return
      * @return
      */
      */
     Boolean pushNotice();
     Boolean pushNotice();
+
+
+    /**
+     * 修改学生乐器
+     * @param studentInstrument
+     * @return
+     */
+    StudentInstrument updateStudentInstrument(StudentInstrument studentInstrument);
+
+
+    /**
+     * 乐器更换更新乐器信息
+     * @param subjectChange
+     * @return
+     */
+    Boolean subjectChangeUpdateInstrument(SubjectChange subjectChange);
+
+
+    /**
+     * 获取学生的乐器信息
+     * @param studentId
+     * @param goodsId
+     * @return
+     */
+    StudentInstrument getStudentInstrument(Integer studentId,Integer goodsId);
+
+
+    Boolean addOldStudentInstrument();
+
 }
 }

+ 21 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -57,6 +57,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             balance = BigDecimal.ZERO;
             balance = BigDecimal.ZERO;
         }
         }
         StudentPaymentOrder order = studentPaymentOrderDao.get(orderId);
         StudentPaymentOrder order = studentPaymentOrderDao.get(orderId);
+        BigDecimal totalActualAmount = order.getActualAmount() == null ? BigDecimal.ZERO : order.getActualAmount();
         MusicGroup musicGroup = new MusicGroup();
         MusicGroup musicGroup = new MusicGroup();
         if (StringUtils.isNotBlank(musicGroupId)) {
         if (StringUtils.isNotBlank(musicGroupId)) {
             musicGroup = musicGroupDao.get(musicGroupId);
             musicGroup = musicGroupDao.get(musicGroupId);
@@ -74,8 +75,14 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             }
             }
         }
         }
 
 
+        //已分配的商品余额
         BigDecimal hasRouteBalance = BigDecimal.ZERO;
         BigDecimal hasRouteBalance = BigDecimal.ZERO;
-        BigDecimal goodsTotalBalance = goodsTotalPrice.multiply(balance).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
+        //已分配的商品现金
+        BigDecimal hasRouteActualAmount= BigDecimal.ZERO;
+        //商品占用的的余额
+        BigDecimal goodsTotalBalance = totalAmount.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : goodsTotalPrice.multiply(balance).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
+        //商品占用的总现金
+        BigDecimal goodsTotalActualAmount = totalAmount.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : goodsTotalPrice.multiply(totalActualAmount).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
         AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos());
         AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos());
 
 
         List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
         List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
@@ -91,11 +98,19 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             }
             }
             goodsPrice = nowGoods.getDiscountPrice();
             goodsPrice = nowGoods.getDiscountPrice();
 
 
-            BigDecimal goodsBalance = goodsTotalBalance.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
+            //当前商品占用的总余额
+            BigDecimal goodsBalance = goodsTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                    goodsTotalBalance.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
+            //当前商品占用的总现金
+            BigDecimal goodsActualAmount = goodsTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                    goodsTotalActualAmount.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
+
             if (i == goodsNum) {
             if (i == goodsNum) {
                 goodsBalance = goodsTotalBalance.subtract(hasRouteBalance);
                 goodsBalance = goodsTotalBalance.subtract(hasRouteBalance);
+                goodsActualAmount = goodsTotalActualAmount.subtract(hasRouteActualAmount);
             }
             }
             hasRouteBalance = hasRouteBalance.add(goodsBalance);
             hasRouteBalance = hasRouteBalance.add(goodsBalance);
+            hasRouteActualAmount = hasRouteActualAmount.add(goodsActualAmount);
             i++;
             i++;
 
 
             int complementGoodsNum = nowGoods.getComplementGoodsIdList() == null ? 1 : nowGoods.getComplementGoodsIdList().split(",").length;
             int complementGoodsNum = nowGoods.getComplementGoodsIdList() == null ? 1 : nowGoods.getComplementGoodsIdList().split(",").length;
@@ -120,21 +135,21 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
                 BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
                 BigDecimal sellOrderBalance = BigDecimal.ZERO;
                 BigDecimal sellOrderBalance = BigDecimal.ZERO;
                 if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
                 if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
-                    sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsPrice).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
+                    sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsActualAmount).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
                     sellOrderBalance = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsBalance).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
                     sellOrderBalance = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsBalance).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
                 }
                 }
 
 
                 complementGoodsNum = complementGoodsNum - sellOrder.getNum();
                 complementGoodsNum = complementGoodsNum - sellOrder.getNum();
                 if (complementGoodsNum <= 0) {
                 if (complementGoodsNum <= 0) {
-                    sellOrderActualAmount = goodsPrice.subtract(hasRouteSellOrderActualAmount);
+                    sellOrderActualAmount = goodsActualAmount.subtract(hasRouteSellOrderActualAmount);
                     sellOrderBalance = goodsBalance.subtract(hasRouteSellOrderBalance);
                     sellOrderBalance = goodsBalance.subtract(hasRouteSellOrderBalance);
                 }
                 }
                 hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
                 hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
                 hasRouteSellOrderBalance = hasRouteSellOrderBalance.add(sellOrderBalance);
                 hasRouteSellOrderBalance = hasRouteSellOrderBalance.add(sellOrderBalance);
 
 
-                sellOrder.setExpectAmount(sellOrderActualAmount);
+                sellOrder.setExpectAmount(sellOrderActualAmount.add(sellOrderBalance));
                 sellOrder.setBalanceAmount(sellOrderBalance);
                 sellOrder.setBalanceAmount(sellOrderBalance);
-                sellOrder.setActualAmount(sellOrderActualAmount.subtract(sellOrderBalance));
+                sellOrder.setActualAmount(sellOrderActualAmount);
                 sellOrder.setOrganId(order.getOrganId());
                 sellOrder.setOrganId(order.getOrganId());
                 sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
                 sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
                 sellOrder.setTransNo(order.getTransNo());
                 sellOrder.setTransNo(order.getTransNo());

+ 5 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java

@@ -12,6 +12,7 @@ import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.StudentGoodsSell;
 import com.ym.mec.biz.dal.entity.StudentGoodsSell;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
 import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
 import com.ym.mec.biz.service.StudentGoodsSellService;
 import com.ym.mec.biz.service.StudentGoodsSellService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.dal.BaseDAO;
@@ -110,8 +111,8 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
     }
     }
 
 
     @Override
     @Override
-    public List<StudentInstrument> saveStudentInstrument(String orderNo) {
-        StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
+    public List<StudentInstrument> saveStudentInstrument(StudentPaymentOrder order) {
+        StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(order.getOrderNo());
         List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(), GoodsSellDto.class);
         List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(), GoodsSellDto.class);
         List<Integer> goodsIds = new ArrayList<>();
         List<Integer> goodsIds = new ArrayList<>();
         for (GoodsSellDto goodsSellDto : goodsSellDtos) {
         for (GoodsSellDto goodsSellDto : goodsSellDtos) {
@@ -134,6 +135,8 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
             studentInstrument.setGoodsBrand(goods.getBrand());
             studentInstrument.setGoodsBrand(goods.getBrand());
             studentInstrument.setSpecification(goods.getSpecification());
             studentInstrument.setSpecification(goods.getSpecification());
             studentInstrument.setGoodsImg(goods.getImage());
             studentInstrument.setGoodsImg(goods.getImage());
+            studentInstrument.setOrderId(order.getId());
+            studentInstrument.setChangeOrderId(order.getId());
             studentInstrument.setStatus(0);
             studentInstrument.setStatus(0);
             studentInstruments.add(studentInstrument);
             studentInstruments.add(studentInstrument);
         }
         }

+ 85 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -14,6 +14,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.date.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
@@ -247,7 +248,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
                 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",
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_SPORADIC_PAYMENT_FAILED, map, null, 0, null, "STUDENT",
                     studentPaymentOrder.getActualAmount(), "乐保购买");
                     studentPaymentOrder.getActualAmount(), "乐保购买");
             return false;
             return false;
         }
         }
@@ -276,7 +277,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetailByType(order.getId(), orderDetailTypes);
         List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetailByType(order.getId(), orderDetailTypes);
         List<StudentPaymentOrderDetail> orderDetails4Instruments = orderDetails.stream()
         List<StudentPaymentOrderDetail> orderDetails4Instruments = orderDetails.stream()
                 .filter(e -> e.getType().equals(OrderDetailTypeEnum.MUSICAL))
                 .filter(e -> e.getType().equals(OrderDetailTypeEnum.MUSICAL))
-                .filter(e -> KitGroupPurchaseTypeEnum.GROUP.equals(e.getKitGroupPurchaseType())).collect(Collectors.toList());
+                .collect(Collectors.toList());
         if (orderDetails4Instruments.size() <= 0) {
         if (orderDetails4Instruments.size() <= 0) {
             return false;
             return false;
         }
         }
@@ -300,6 +301,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         studentInstrument.setOrganId(order.getOrganId());
         studentInstrument.setOrganId(order.getOrganId());
         studentInstrument.setGoodsId(goodsId);
         studentInstrument.setGoodsId(goodsId);
         studentInstrument.setStatus(maintenanceStatus);
         studentInstrument.setStatus(maintenanceStatus);
+        studentInstrument.setOrderId(order.getId());
+        studentInstrument.setChangeOrderId(order.getId());
         studentInstrument.setStartTime(startTime);
         studentInstrument.setStartTime(startTime);
         studentInstrument.setEndTime(endTime);
         studentInstrument.setEndTime(endTime);
         addStudentInstrument(studentInstrument);
         addStudentInstrument(studentInstrument);
@@ -312,8 +315,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
 
 
     @Override
     @Override
     public Boolean pushNotice() {
     public Boolean pushNotice() {
-        Date startTime = DateUtil.trunc(new Date());
-        Date endTime = DateUtil.addDays(DateUtil.getLastTimeWithDay(startTime), +6);
+        Date endTime = DateUtil.addDays(DateUtil.getLastTimeWithDay(new Date()), +7);
+        Date startTime = DateUtil.trunc(endTime);
         List<StudentInstrument> studentInstruments = studentInstrumentDao.getListByEndTime(startTime, endTime);
         List<StudentInstrument> studentInstruments = studentInstrumentDao.getListByEndTime(startTime, endTime);
         if (studentInstruments.size() <= 0) {
         if (studentInstruments.size() <= 0) {
             return false;
             return false;
@@ -328,4 +331,82 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         }
         }
         return true;
         return true;
     }
     }
+
+    @Override
+    public StudentInstrument updateStudentInstrument(StudentInstrument studentInstrument) {
+        Goods goods = goodsService.get(studentInstrument.getGoodsId());
+        GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
+        studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
+        studentInstrument.setGoodsCategoryName(goodsCategory.getName());
+        studentInstrument.setGoodsName(goods.getName());
+        studentInstrument.setGoodsBrand(goods.getBrand());
+        studentInstrument.setSpecification(goods.getSpecification());
+        studentInstrument.setGoodsImg(goods.getImage());
+        studentInstrumentDao.update(studentInstrument);
+        return studentInstrument;
+    }
+
+    @Override
+    public Boolean subjectChangeUpdateInstrument(SubjectChange subjectChange) {
+        if (subjectChange == null || subjectChange.getChangeMusical() == null ||
+                KitGroupPurchaseTypeEnum.OWNED.equals(subjectChange.getKitGroupPurchaseType())) {
+            return false;
+        }
+        StudentInstrument studentInstrument = studentInstrumentDao.getByOrderId(subjectChange.getOriginalOrderId().longValue());
+
+        if (studentInstrument == null) {
+            studentInstrument = new StudentInstrument();
+            studentInstrument.setStudentId(subjectChange.getStudentId());
+            studentInstrument.setOrganId(subjectChange.getOrganId());
+            studentInstrument.setOrderId(subjectChange.getOrderId().longValue());
+            studentInstrument.setStatus(0);
+        }
+        studentInstrument.setChangeOrderId(subjectChange.getOrderId().longValue());
+        studentInstrument.setGoodsId(subjectChange.getChangeMusical());
+        if (studentInstrument.getId() == null) {
+            addStudentInstrument(studentInstrument);
+            return true;
+        }
+        updateStudentInstrument(studentInstrument);
+        return true;
+    }
+
+    @Override
+    public StudentInstrument getStudentInstrument(Integer studentId, Integer goodsId) {
+        return studentInstrumentDao.getStudentInstrument(studentId, goodsId);
+    }
+
+    @Override
+    public Boolean addOldStudentInstrument() {
+        Date startTime = null;
+        Date nowDate = new Date();
+        StudentInstrument studentInstrument = studentInstrumentDao.getStudentInstrument(2094765, 60);
+        if (studentInstrument != null) {
+            startTime = DateUtil.addMinutes(nowDate, -15);
+        }
+        List<StudentInstrument> oldStudentInstruments = studentInstrumentDao.getOldStudentInstrument(startTime);
+        for (StudentInstrument oldStudentInstrument : oldStudentInstruments) {
+            oldStudentInstrument.setChangeOrderId(oldStudentInstrument.getOrderId());
+            if (oldStudentInstrument.getEndTime().compareTo(nowDate) > 0) {
+                oldStudentInstrument.setStatus(1);
+            } else {
+                oldStudentInstrument.setStatus(0);
+            }
+            StudentInstrument has = studentInstrumentDao.getStudentInstrument(oldStudentInstrument.getStudentId(), oldStudentInstrument.getGoodsId());
+            if (has == null) {
+                studentInstrumentDao.insert(oldStudentInstrument);
+                continue;
+            }
+            oldStudentInstrument.setId(has.getId());
+            if (has.getEndTime() == null) {
+                studentInstrumentDao.update(oldStudentInstrument);
+                continue;
+            }
+            if (has.getEndTime().compareTo(oldStudentInstrument.getEndTime()) >= 0) {
+                continue;
+            }
+            studentInstrumentDao.update(oldStudentInstrument);
+        }
+        return true;
+    }
 }
 }

+ 12 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -358,7 +358,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         student.setCurrentClass(studentRegistration.getCurrentClass());
         student.setCurrentClass(studentRegistration.getCurrentClass());
         studentDao.update(student);
         studentDao.update(student);
 
 
-        webFeignService.updateNickName(sysUser.getId(),studentRegistration.getName(),"STUDENT");
+        //webFeignService.updateNickName(sysUser.getId(),studentRegistration.getName(),"STUDENT");
         // 增加报名学生数
         // 增加报名学生数
         musicGroupSubjectPlanService.addApplyStudentNum(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId(), 1);
         musicGroupSubjectPlanService.addApplyStudentNum(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId(), 1);
         // 报名成功后,发送短信
         // 报名成功后,发送短信
@@ -430,7 +430,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 studentPaymentOrderDetail4goodsGroup.setPaymentOrderId(studentPaymentOrder.getId());
                 studentPaymentOrderDetail4goodsGroup.setPaymentOrderId(studentPaymentOrder.getId());
                 studentPaymentOrderDetail4goodsGroup.setKitGroupPurchaseType(goodsGroup.getKitGroupPurchaseType());
                 studentPaymentOrderDetail4goodsGroup.setKitGroupPurchaseType(goodsGroup.getKitGroupPurchaseType());
                 studentPaymentOrderDetailList.add(studentPaymentOrderDetail4goodsGroup);
                 studentPaymentOrderDetailList.add(studentPaymentOrderDetail4goodsGroup);
-                if (OrderDetailTypeEnum.MUSICAL.equals(type) && KitGroupPurchaseTypeEnum.GROUP.equals(goodsGroup.getKitGroupPurchaseType())) {
+                if (OrderDetailTypeEnum.MUSICAL.equals(type)) {
                     maintenanceGoodsId = goodsGroup.getGoodsIdList();
                     maintenanceGoodsId = goodsGroup.getGoodsIdList();
                 }
                 }
             }
             }
@@ -456,7 +456,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         }
         }
         if (buyMaintenance) {
         if (buyMaintenance) {
             if ("".equals(maintenanceGoodsId)) {
             if ("".equals(maintenanceGoodsId)) {
-                throw new BizException("团购乐器才能购买乐保,请核查");
+                throw new BizException("乐器才能购买乐保,请核查");
             }
             }
             BigDecimal maintenancePrice = new BigDecimal(sysConfigDao.findConfigValue("maintenance_price"));
             BigDecimal maintenancePrice = new BigDecimal(sysConfigDao.findConfigValue("maintenance_price"));
             StudentPaymentOrderDetail maintenanceOrderDetail = new StudentPaymentOrderDetail();
             StudentPaymentOrderDetail maintenanceOrderDetail = new StudentPaymentOrderDetail();
@@ -555,7 +555,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 studentPaymentOrderDetail4goodsGroup.setPaymentOrderId(studentPaymentOrder.getId());
                 studentPaymentOrderDetail4goodsGroup.setPaymentOrderId(studentPaymentOrder.getId());
                 studentPaymentOrderDetail4goodsGroup.setKitGroupPurchaseType(goodsGroup.getKitGroupPurchaseType());
                 studentPaymentOrderDetail4goodsGroup.setKitGroupPurchaseType(goodsGroup.getKitGroupPurchaseType());
                 studentPaymentOrderDetailList.add(studentPaymentOrderDetail4goodsGroup);
                 studentPaymentOrderDetailList.add(studentPaymentOrderDetail4goodsGroup);
-                if (OrderDetailTypeEnum.MUSICAL.equals(type) && KitGroupPurchaseTypeEnum.GROUP.equals(goodsGroup.getKitGroupPurchaseType())) {
+                if (OrderDetailTypeEnum.MUSICAL.equals(type)) {
                     maintenanceGoodsId = goodsGroup.getGoodsIdList();
                     maintenanceGoodsId = goodsGroup.getGoodsIdList();
                 }
                 }
             }
             }
@@ -581,7 +581,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         }
         }
         if (buyMaintenance) {
         if (buyMaintenance) {
             if ("".equals(maintenanceGoodsId)) {
             if ("".equals(maintenanceGoodsId)) {
-                throw new BizException("团购乐器才能购买乐保,请核查");
+                throw new BizException("乐器才能购买乐保,请核查");
             }
             }
             BigDecimal maintenancePrice = new BigDecimal(sysConfigDao.findConfigValue("maintenance_price"));
             BigDecimal maintenancePrice = new BigDecimal(sysConfigDao.findConfigValue("maintenance_price"));
             StudentPaymentOrderDetail maintenanceOrderDetail = new StudentPaymentOrderDetail();
             StudentPaymentOrderDetail maintenanceOrderDetail = new StudentPaymentOrderDetail();
@@ -1032,7 +1032,10 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
             List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
 
 
             List<StudentPaymentOrderDetail> allDetails = studentPaymentOrderDetailDao.getOrderDetailByOrderId(studentPaymentOrder.getId());
             List<StudentPaymentOrderDetail> allDetails = studentPaymentOrderDetailDao.getOrderDetailByOrderId(studentPaymentOrder.getId());
-            BigDecimal courseFee = allDetails.stream().filter(o -> !o.getType().getCode().equals("MUSICAL")).filter(o -> !o.getType().getCode().equals("ACCESSORIES")).map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
+            BigDecimal courseFee = allDetails.stream().filter(o -> !o.getType().getCode().equals("MUSICAL"))
+                    .filter(o -> !o.getType().getCode().equals("ACCESSORIES"))
+                    .filter(o -> !o.getType().getCode().equals("MAINTENANCE"))
+                    .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
 
 
             //累加充值金额
             //累加充值金额
@@ -1119,13 +1122,13 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 Map<Integer, String> map = new HashMap<>(1);
                 Map<Integer, String> map = new HashMap<>(1);
                 map.put(studentPaymentOrder.getUserId(), studentRegistration.getParentsPhone());
                 map.put(studentPaymentOrder.getUserId(), studentRegistration.getParentsPhone());
                 sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS,
                 sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS,
-                        MessageTypeEnum.STUDENT_SMS_PAYMENT_SUCCESS, map, null, 0, "1", "",
+                        MessageTypeEnum.STUDENT_SMS_PAYMENT_SUCCESS, map, null, 0, null, "",
                         studentRegistration.getName(), studentPaymentOrder.getActualAmount());
                         studentRegistration.getName(), studentPaymentOrder.getActualAmount());
                 //push
                 //push
                 Map<Integer, String> map1 = new HashMap<>(1);
                 Map<Integer, String> map1 = new HashMap<>(1);
                 map1.put(studentPaymentOrder.getUserId(), studentPaymentOrder.getUserId().toString());
                 map1.put(studentPaymentOrder.getUserId(), studentPaymentOrder.getUserId().toString());
                 sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,
                 sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,
-                        MessageTypeEnum.STUDENT_SMS_PAYMENT_SUCCESS, map1, null, 0, "1", "STUDENT",
+                        MessageTypeEnum.STUDENT_SMS_PAYMENT_SUCCESS, map1, null, 0, null, "STUDENT",
                         studentRegistration.getName(), studentPaymentOrder.getActualAmount());
                         studentRegistration.getName(), studentPaymentOrder.getActualAmount());
             }
             }
             try {
             try {
@@ -1160,7 +1163,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 Map<Integer, String> map = new HashMap<>(1);
                 Map<Integer, String> map = new HashMap<>(1);
                 map.put(studentPaymentOrder.getUserId(), studentRegistration.getParentsPhone());
                 map.put(studentPaymentOrder.getUserId(), studentRegistration.getParentsPhone());
                 sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS,
                 sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS,
-                        MessageTypeEnum.STUDENT_SMS_PAYMENT_FAILED, map, null, 0, "1", "",
+                        MessageTypeEnum.STUDENT_SMS_PAYMENT_FAILED, map, null, 0, null, "",
                         HttpUtil.getSortUrl(studentApplyUrl));
                         HttpUtil.getSortUrl(studentApplyUrl));
             }
             }
 //            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,
 //            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,

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

@@ -736,7 +736,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             paymentDetail.setUserId(userId);
             paymentDetail.setUserId(userId);
             sysUserCashAccountDetailService.insert(paymentDetail);
             sysUserCashAccountDetailService.insert(paymentDetail);
             //将购买的乐器加入学生乐器列表
             //将购买的乐器加入学生乐器列表
-            studentGoodsSellService.saveStudentInstrument(studentPaymentOrder.getOrderNo());
+            studentGoodsSellService.saveStudentInstrument(studentPaymentOrder);
             //购买的商品加入销售列表
             //购买的商品加入销售列表
             saveSellOrder(studentPaymentOrder.getOrderNo());
             saveSellOrder(studentPaymentOrder.getOrderNo());
         } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
         } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
@@ -1051,7 +1051,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
                 List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
                 List<Integer> goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
                 List<Integer> goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
                 if (goodsIds.size() > 0) {
                 if (goodsIds.size() > 0) {
-                    sellOrderService.addSellOrder(studentPaymentOrder.getId(), null, goodsIds, studentPaymentOrder.getExpectAmount(), studentPaymentOrder.getBalancePaymentAmount());
+                    sellOrderService.addSellOrder(studentPaymentOrder.getId(), null, goodsIds, studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()), studentPaymentOrder.getBalancePaymentAmount());
                 }
                 }
             }
             }
 
 
@@ -1062,10 +1062,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                         "联系人:" + repairInfo.getEmployeeName() + "(" + repairInfo.getEmployeePhone() + ")\n" +
                         "联系人:" + repairInfo.getEmployeeName() + "(" + repairInfo.getEmployeePhone() + ")\n" +
                         "地址:" + repairInfo.getEmployeeAddress() + "";
                         "地址:" + repairInfo.getEmployeeAddress() + "";
 
 
-                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_ONLINE_PAYMENT_SUCCESS, map, null, 0, "1", "STUDENT",
+                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_ONLINE_PAYMENT_SUCCESS, map, null, 0, null, "STUDENT",
                         repairInfo.getStudentName(), repairInfo.getEmployeeName(), repairInfo.getEmployeePhone(), repairInfo.getEmployeeAddress());
                         repairInfo.getStudentName(), repairInfo.getEmployeeName(), repairInfo.getEmployeePhone(), repairInfo.getEmployeeAddress());
             } else {
             } else {
-                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_OFFLINE_PAYMENT_SUCCESS, map, null, 0, "1", "STUDENT",
+                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_OFFLINE_PAYMENT_SUCCESS, map, null, 0, null, "STUDENT",
                         repairInfo.getStudentName());
                         repairInfo.getStudentName());
             }
             }
             sysMessageService.sendNoAuthPrivateMessage(repairInfo.getEmployeeId().toString(), userId.toString(), imContent);
             sysMessageService.sendNoAuthPrivateMessage(repairInfo.getEmployeeId().toString(), userId.toString(), imContent);
@@ -1082,7 +1082,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 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",
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_SPORADIC_PAYMENT_FAILED, map, null, 0, null, "STUDENT",
                     studentPaymentOrder.getActualAmount(), "乐器维修");
                     studentPaymentOrder.getActualAmount(), "乐器维修");
             return false;
             return false;
         }
         }

+ 8 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -68,6 +68,8 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
     private SellOrderService sellOrderService;
     private SellOrderService sellOrderService;
     @Autowired
     @Autowired
     private GoodsService goodsService;
     private GoodsService goodsService;
+    @Autowired
+    private StudentInstrumentService studentInstrumentService;
 
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
 
@@ -300,6 +302,8 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 //添加新订单
                 //添加新订单
                 this.addSellOrder(studentPaymentOrder.getId(), subjectChange.getMusicGroupId(), goodsIdList, BigDecimal.ZERO, BigDecimal.ZERO, subjectChange.getKitGroupPurchaseType());
                 this.addSellOrder(studentPaymentOrder.getId(), subjectChange.getMusicGroupId(), goodsIdList, BigDecimal.ZERO, BigDecimal.ZERO, subjectChange.getKitGroupPurchaseType());
             }
             }
+            //乐保处理
+            studentInstrumentService.subjectChangeUpdateInstrument(subjectChange);
         }
         }
         return subjectChange;
         return subjectChange;
     }
     }
@@ -491,6 +495,9 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 this.addSellOrder(studentPaymentOrder.getId(), subjectChange.getMusicGroupId(), goodsIdList, studentPaymentOrder.getExpectAmount(), studentPaymentOrder.getBalancePaymentAmount(), subjectChange.getKitGroupPurchaseType());
                 this.addSellOrder(studentPaymentOrder.getId(), subjectChange.getMusicGroupId(), goodsIdList, studentPaymentOrder.getExpectAmount(), studentPaymentOrder.getBalancePaymentAmount(), subjectChange.getKitGroupPurchaseType());
             }
             }
 
 
+            //乐保处理
+            studentInstrumentService.subjectChangeUpdateInstrument(subjectChange);
+
             //插入交易明细
             //插入交易明细
             BigDecimal amount = studentPaymentOrder.getActualAmount();
             BigDecimal amount = studentPaymentOrder.getActualAmount();
             SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
             SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
@@ -538,7 +545,7 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 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",
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_SPORADIC_PAYMENT_FAILED, map, null, 0, null, "STUDENT",
                     studentPaymentOrder.getActualAmount(), "声部更换");
                     studentPaymentOrder.getActualAmount(), "声部更换");
             return false;
             return false;
         }
         }

+ 70 - 12
mec-biz/src/main/resources/config/mybatis/StudentInstrumentMapper.xml

@@ -13,8 +13,12 @@
         <result column="status_" property="status"/>
         <result column="status_" property="status"/>
         <result column="start_time_" property="startTime"/>
         <result column="start_time_" property="startTime"/>
         <result column="end_time_" property="endTime"/>
         <result column="end_time_" property="endTime"/>
+        <result column="order_id_" property="orderId"/>
+        <result column="change_order_id_" property="changeOrderId"/>
+        <result column="operation_" property="operation"/>
         <result column="create_time_" property="createTime"/>
         <result column="create_time_" property="createTime"/>
         <result column="update_time" property="updateTime"/>
         <result column="update_time" property="updateTime"/>
+        <result column="del_flag_" property="delFlag"/>
         <result column="goods_name_" property="goodsName"/>
         <result column="goods_name_" property="goodsName"/>
         <result column="specification_" property="specification"/>
         <result column="specification_" property="specification"/>
         <result column="goods_brand_" property="goodsBrand"/>
         <result column="goods_brand_" property="goodsBrand"/>
@@ -37,11 +41,11 @@
         <!--@mbg.generated-->
         <!--@mbg.generated-->
         insert into student_instrument
         insert into student_instrument
         (student_id_,organ_id_,goods_id_,goods_category_id_,goods_category_name_,goods_name_,goods_brand_,specification_,goods_img_,
         (student_id_,organ_id_,goods_id_,goods_category_id_,goods_category_name_,goods_name_,goods_brand_,specification_,goods_img_,
-        status_, start_time_, end_time_, create_time_, update_time
+        status_,order_id_,change_order_id_,operation_, start_time_, end_time_, create_time_, update_time
         )
         )
         values
         values
         (#{studentId},#{organId},#{goodsId},#{goodsCategoryId},#{goodsCategoryName},#{goodsName},#{goodsBrand},#{specification},#{goodsImg},
         (#{studentId},#{organId},#{goodsId},#{goodsCategoryId},#{goodsCategoryName},#{goodsName},#{goodsBrand},#{specification},#{goodsImg},
-        #{status}, #{startTime}, #{endTime}, NOW(), NOW()
+        #{status},#{orderId},#{changeOrderId},#{operation}, #{startTime}, #{endTime}, NOW(), NOW()
         )
         )
     </insert>
     </insert>
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentInstrument">
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentInstrument">
@@ -72,18 +76,21 @@
             <if test="status != null">
             <if test="status != null">
                 status_ = #{status},
                 status_ = #{status},
             </if>
             </if>
-            <if test="startTime != null">
-                start_time_ = #{startTime},
+            <if test="operation != null">
+                operation_ = #{operation},
             </if>
             </if>
-            <if test="endTime != null">
-                end_time_ = #{endTime},
+            start_time_ = #{startTime},
+            end_time_ = #{endTime},
+            <if test="changeOrderId != null">
+                change_order_id_ = #{changeOrderId},
             </if>
             </if>
             <if test="createTime != null">
             <if test="createTime != null">
                 create_time_ = #{createTime},
                 create_time_ = #{createTime},
             </if>
             </if>
-            <if test="updateTime != null">
-                update_time = #{updateTime},
+            <if test="delFlag != null">
+                del_flag_ = #{delFlag},
             </if>
             </if>
+            update_time = NOW(),
         </set>
         </set>
         where id_ = #{id}
         where id_ = #{id}
     </update>
     </update>
@@ -131,20 +138,24 @@
             <if test="specification != null">
             <if test="specification != null">
                 AND si.specification_ LIKE CONCAT('%',#{specification},'%')
                 AND si.specification_ LIKE CONCAT('%',#{specification},'%')
             </if>
             </if>
+            <if test="status != null">
+                AND si.status_ = #{status}
+            </if>
             <if test="search != null">
             <if test="search != null">
                 AND (si.student_id_ = #{search} OR su.phone_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%'))
                 AND (si.student_id_ = #{search} OR su.phone_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%'))
             </if>
             </if>
+            AND si.del_flag_ = 0
         </where>
         </where>
     </sql>
     </sql>
 
 
     <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
     <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
         insert into student_instrument
         insert into student_instrument
         (student_id_,organ_id_,goods_id_,goods_category_id_,goods_category_name_,goods_name_,goods_brand_,specification_,goods_img_,
         (student_id_,organ_id_,goods_id_,goods_category_id_,goods_category_name_,goods_name_,goods_brand_,specification_,goods_img_,
-        status_, start_time_, end_time_, create_time_, update_time)
+        order_id_,change_order_id_,status_, start_time_, end_time_, create_time_, update_time)
         VALUE
         VALUE
         <foreach collection="studentInstruments" item="item" separator=",">
         <foreach collection="studentInstruments" item="item" separator=",">
             (#{item.studentId},#{item.organId},#{item.goodsId},#{item.goodsCategoryId},#{item.goodsCategoryName},#{item.goodsName},#{item.goodsBrand},#{item.specification},#{item.goodsImg},
             (#{item.studentId},#{item.organId},#{item.goodsId},#{item.goodsCategoryId},#{item.goodsCategoryName},#{item.goodsName},#{item.goodsBrand},#{item.specification},#{item.goodsImg},
-            #{item.status}, #{item.startTime},
+            #{item.orderId},#{item.changeOrderId},#{item.status}, #{item.startTime},
             #{item.endTime}, NOW(), NOW())
             #{item.endTime}, NOW(), NOW())
         </foreach>
         </foreach>
     </insert>
     </insert>
@@ -158,8 +169,55 @@
     </update>
     </update>
     <select id="getListByEndTime" resultMap="StudentInstrument">
     <select id="getListByEndTime" resultMap="StudentInstrument">
         <![CDATA[
         <![CDATA[
-        SELECT * FROM student_instrument WHERE end_time_ >= #{startTime} AND end_time_ <= #{endTime}
-     ]]>
+        SELECT *
+        FROM student_instrument
+        WHERE end_time_ >= #{startTime}
+          AND end_time_ <= #{endTime}
+        ]]>
+    </select>
+
+    <select id="getByOrderId" resultMap="StudentInstrument">
+        SELECT *
+        FROM student_instrument
+        WHERE change_order_id_ = #{orderId}
+    </select>
+
+    <select id="getStudentInstrument" resultMap="StudentInstrument">
+        SELECT *
+        FROM student_instrument
+        WHERE student_id_ = #{studentId}
+          AND goods_id_ = #{goodsId}
+          AND del_flag_ = 0
+        ORDER BY id_ DESC
+        LIMIT 1
+    </select>
+
+    <select id="getOldStudentInstrument" resultMap="StudentInstrument">
+        SELECT spo.user_id_ student_id_,
+        spo.organ_id_,
+        g.id_ goods_id_,
+        g.goods_category_id_,
+        gc.name_ goods_category_name_,
+        g.name_ goods_name_,
+        g.brand_ goods_brand_,
+        g.specification_,
+        g.image_ goods_img_,
+        spo.create_time_ start_time_,
+        DATE_ADD(spo.create_time_, INTERVAL 1 YEAR) end_time_,
+        spo.id_ order_id_
+        FROM student_payment_order_detail spod
+        LEFT JOIN student_payment_order spo ON spo.id_ = spod.payment_order_id_
+        LEFT JOIN student_payment_order_detail spod2 ON spod2.payment_order_id_ = spo.id_
+        LEFT JOIN goods g ON g.id_ = spod2.goods_id_list_
+        LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
+        WHERE spo.status_ = 'SUCCESS'
+        AND spod2.type_ = 'MUSICAL'
+        AND (spod.goods_id_list_ IN ('437', '438', '439', '440', '441', '442', '443') OR
+        FIND_IN_SET('76', spod.goods_id_list_))
+        <if test="startTime != null ">
+            AND spo.pay_time_ >= #{startTime}
+        </if>
+        ORDER BY spo.create_time_ ASC
     </select>
     </select>
 
 
 </mapper>
 </mapper>

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/StudentRepairMapper.xml

@@ -210,7 +210,7 @@
                 AND sr.student_instrument_id_ = #{studentInstrumentId}
                 AND sr.student_instrument_id_ = #{studentInstrumentId}
             </if>
             </if>
             <if test="hasExemptionAmount != null and hasExemptionAmount ==1">
             <if test="hasExemptionAmount != null and hasExemptionAmount ==1">
-                AND sr.exemption_amount_ > #{exemptionAmount}
+                AND sr.exemption_amount_ > 0
             </if>
             </if>
             <if test="hasExemptionAmount != null and hasExemptionAmount ==0">
             <if test="hasExemptionAmount != null and hasExemptionAmount ==0">
                 AND sr.exemption_amount_ = 0
                 AND sr.exemption_amount_ = 0

+ 4 - 0
mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java

@@ -169,4 +169,8 @@ public interface TaskRemoteService {
 	 */
 	 */
 	@GetMapping("task/updateGrade")
 	@GetMapping("task/updateGrade")
 	void updateGrade();
 	void updateGrade();
+
+	//乐保历史数据处理
+	@GetMapping("task/maintenanceOldDateAdd")
+	void maintenanceOldDateAdd();
 }
 }

+ 5 - 0
mec-client-api/src/main/java/com/ym/mec/task/fallback/TaskRemoteServiceFallback.java

@@ -210,4 +210,9 @@ public class TaskRemoteServiceFallback implements TaskRemoteService {
     public void maintenanceNotice() {
     public void maintenanceNotice() {
 		logger.info("乐保到期提醒推送失败");
 		logger.info("乐保到期提醒推送失败");
     }
     }
+
+    @Override
+    public void maintenanceOldDateAdd() {
+		logger.info("乐保历史数据处理失败");
+    }
 }
 }

+ 19 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/MaintenanceOldDataAddTask.java

@@ -0,0 +1,19 @@
+package com.ym.mec.task.jobs;
+
+import com.ym.mec.task.TaskRemoteService;
+import com.ym.mec.task.core.BaseTask;
+import com.ym.mec.task.core.TaskException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class MaintenanceOldDataAddTask extends BaseTask {
+
+	@Autowired
+	private TaskRemoteService taskRemoteService;
+
+	@Override
+	public void execute() throws TaskException {
+		taskRemoteService.maintenanceOldDateAdd();
+	}
+}

+ 98 - 2
mec-web/src/main/java/com/ym/mec/web/controller/StudentInstrumentController.java

@@ -4,16 +4,15 @@ package com.ym.mec.web.controller;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.EmployeeDao;
 import com.ym.mec.biz.dal.dao.EmployeeDao;
-import com.ym.mec.biz.dal.dao.StudentDao;
 import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
 import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
 import com.ym.mec.biz.dal.entity.Employee;
 import com.ym.mec.biz.dal.entity.Employee;
-import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 import com.ym.mec.biz.dal.page.StudentInstrumentQueryInfo;
 import com.ym.mec.biz.dal.page.StudentInstrumentQueryInfo;
 import com.ym.mec.biz.service.StudentInstrumentService;
 import com.ym.mec.biz.service.StudentInstrumentService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.util.date.DateUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiImplicitParams;
@@ -29,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
 @RequestMapping("studentInstrument")
 @RequestMapping("studentInstrument")
@@ -79,9 +79,105 @@ public class StudentInstrumentController extends BaseController {
         if (studentInstrument.getStudentId() == null) {
         if (studentInstrument.getStudentId() == null) {
             return failed("学生id不能为空");
             return failed("学生id不能为空");
         }
         }
+        StudentInstrument oldInstrument = studentInstrumentService.getStudentInstrument(studentInstrument.getStudentId(), studentInstrument.getGoodsId());
+        if (oldInstrument != null) {
+            return failed("学生乐器信息已存在,请核查");
+        }
+
+        Date nowDate = new Date();
+        //不是乐保
+        if (studentInstrument.getStatus().equals(0)) {
+            studentInstrument.setStartTime(null);
+            studentInstrument.setEndTime(null);
+        }
+        if (studentInstrument.getStatus().equals(1)) {
+            if (studentInstrument.getStartTime() == null) {
+                return failed("乐保开始时间不能为空");
+            }
+            if (studentInstrument.getEndTime() == null) {
+                return failed("乐保结束时间不能为空");
+            }
+            if (studentInstrument.getStartTime().compareTo(nowDate) > 0) {
+                return failed("乐保开始时间不能大于当前时间");
+            }
+            if (studentInstrument.getEndTime().compareTo(nowDate) <= 0) {
+                return failed("乐保结束时间不能小于当前时间");
+            }
+        }
+        studentInstrument.setOperation(sysUser.getId());
         SysUser student = sysUserFeignService.queryUserById(studentInstrument.getStudentId());
         SysUser student = sysUserFeignService.queryUserById(studentInstrument.getStudentId());
         studentInstrument.setOrganId(student.getOrganId());
         studentInstrument.setOrganId(student.getOrganId());
         return succeed(studentInstrumentService.addStudentInstrument(studentInstrument));
         return succeed(studentInstrumentService.addStudentInstrument(studentInstrument));
     }
     }
 
 
+
+    @ApiOperation(value = "获取乐保信息")
+    @GetMapping("/getInfo")
+    @PreAuthorize("@pcs.hasPermissions('studentInstrument/getInfo')")
+    public HttpResponseResult<StudentInstrument> getInfo(Long id, Integer studentId) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed("用户信息获取失败");
+        }
+        StudentInstrument studentInstrument = studentInstrumentService.get(id);
+        if (studentInstrument == null || !studentInstrument.getStudentId().equals(studentId)) {
+            return failed("学生乐器信息不存在");
+        }
+        return succeed(studentInstrument);
+    }
+
+
+    @ApiOperation(value = "修改乐保信息")
+    @PostMapping("/update")
+    @PreAuthorize("@pcs.hasPermissions('studentInstrument/update')")
+    public HttpResponseResult<StudentInstrument> update(StudentInstrument studentInstrument) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed("用户信息获取失败");
+        }
+        if (studentInstrument.getStudentId() == null) {
+            return failed("学生id不能为空");
+        }
+        Date nowDate = new Date();
+        //不是乐保
+        if (studentInstrument.getStatus().equals(0)) {
+            studentInstrument.setStartTime(null);
+            studentInstrument.setEndTime(null);
+        }
+        if (studentInstrument.getStatus().equals(1)) {
+            if (studentInstrument.getStartTime() == null) {
+                return failed("乐保开始时间不能为空");
+            }
+            if (studentInstrument.getEndTime() == null) {
+                return failed("乐保结束时间不能为空");
+            }
+            if (studentInstrument.getStartTime().compareTo(nowDate) > 0) {
+                return failed("乐保开始时间不能大于当前时间");
+            }
+            if (studentInstrument.getEndTime().compareTo(nowDate) <= 0) {
+                return failed("乐保结束时间不能小于当前时间");
+            }
+        }
+        studentInstrument.setOperation(sysUser.getId());
+        SysUser student = sysUserFeignService.queryUserById(studentInstrument.getStudentId());
+        studentInstrument.setOrganId(student.getOrganId());
+        return succeed(studentInstrumentService.updateStudentInstrument(studentInstrument));
+    }
+
+    @ApiOperation(value = "删除学生乐器信息")
+    @PostMapping("/del")
+    @PreAuthorize("@pcs.hasPermissions('studentInstrument/del')")
+    public HttpResponseResult<StudentInstrument> del(Long id, Integer studentId) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed("用户信息获取失败");
+        }
+        StudentInstrument studentInstrument = studentInstrumentService.get(id);
+        if (studentInstrument == null || !studentInstrument.getStudentId().equals(studentId)) {
+            return failed("学生乐器信息不存在");
+        }
+        studentInstrument.setOperation(sysUser.getId());
+        studentInstrument.setDelFlag(1);
+        return succeed(studentInstrumentService.updateStudentInstrument(studentInstrument));
+    }
 }
 }

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

@@ -354,4 +354,10 @@ public class TaskController extends BaseController {
 	public void updateGrade(){
 	public void updateGrade(){
 		studentService.updateGrade();
 		studentService.updateGrade();
 	}
 	}
+
+	//乐保历史数据处理
+	@GetMapping("/maintenanceOldDateAdd")
+	public void maintenanceOldDateAdd(){
+		studentInstrumentService.addOldStudentInstrument();
+	}
 }
 }