Przeglądaj źródła

add 乐保历史数据处理

周箭河 4 lat temu
rodzic
commit
a780676aa3

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

@@ -47,4 +47,11 @@ public interface StudentInstrumentDao extends BaseDAO<Long, StudentInstrument> {
      * @return
      */
     StudentInstrument getStudentInstrument(@Param("studentId") Integer studentId, @Param("goodsId") Integer goodsId);
+
+    /**
+     * 获取用户已购买乐保的商品的记录
+     * @param startTime
+     * @return
+     */
+    List<StudentInstrument> getOldStudentInstrument(@Param("startTime") Date startTime);
 }

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

@@ -72,4 +72,7 @@ public interface StudentInstrumentService extends BaseService<Long, StudentInstr
      */
     StudentInstrument getStudentInstrument(Integer studentId,Integer goodsId);
 
+
+    Boolean addOldStudentInstrument();
+
 }

+ 37 - 2
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.util.date.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -371,7 +372,41 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     }
 
     @Override
-    public StudentInstrument getStudentInstrument(Integer studentId,Integer goodsId) {
-        return studentInstrumentDao.getStudentInstrument(studentId,goodsId);
+    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, -30);
+        }
+        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;
     }
 }

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

@@ -183,7 +183,39 @@
     </select>
 
     <select id="getStudentInstrument" resultMap="StudentInstrument">
-        SELECT * FROM student_instrument WHERE student_id_ = #{studentId} AND goods_id_ = #{goodsId} AND del_flag_ = 0
+        SELECT *
+        FROM student_instrument
+        WHERE student_id_ = #{studentId}
+          AND goods_id_ = #{goodsId}
+          AND del_flag_ = 0
+    </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.create_time_ >= #{startTime}
+        </if>
+        ORDER BY spo.create_time_ ASC
     </select>
 
 </mapper>

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

@@ -163,4 +163,8 @@ public interface TaskRemoteService {
 	//乐保到期提醒
 	@GetMapping("task/maintenanceNotice")
 	void maintenanceNotice();
+
+	//乐保历史数据处理
+	@GetMapping("task/maintenanceOldDateAdd")
+	void maintenanceOldDateAdd();
 }

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

@@ -205,4 +205,9 @@ public class TaskRemoteServiceFallback implements TaskRemoteService {
     public void maintenanceNotice() {
 		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();
+	}
+}

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

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