李天标 3 年之前
父節點
當前提交
b48dc9c56d

+ 21 - 0
pom.xml

@@ -215,6 +215,27 @@
 			<artifactId>easypoi-base</artifactId>
 			<version>RELEASE</version>
 		</dependency>
+		<!--定时任务-->
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.projectlombok</groupId>
+			<artifactId>lombok</artifactId>
+			<optional>true</optional>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 50 - 0
src/main/java/com/szwl/controller/ScheduledService.java

@@ -0,0 +1,50 @@
+package com.szwl.controller;
+
+import com.szwl.service.TDepartmentService;
+import com.szwl.service.TShandeMchService;
+import com.szwl.service.es.EsTCoinOrderService;
+import com.szwl.service.es.EsTOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+import java.util.Calendar;
+
+
+@Configuration //1.主要用于标记配置类,兼备Component的效果。
+@Component
+@EnableScheduling // 2.开启定时任务
+public class ScheduledService {
+    @Autowired
+    private TDepartmentService tDepartmentService;
+    @Autowired
+    private TShandeMchService tShandeMchService;
+    @Autowired
+    EsTCoinOrderService esTCoinOrderService;
+    @Autowired
+    EsTOrderService esTOrderService;
+
+    //值日通知
+    @Scheduled(cron = "0 20 8 * * ?")
+    public void scheduled(){
+        Calendar calendar = Calendar.getInstance();
+        int number = calendar.get(Calendar.DAY_OF_WEEK);
+        if(number!=1){
+            tDepartmentService.onTime();
+        }
+    }
+    @Scheduled(cron = "0 55 17 * * ?")
+    public void scheduled2(){
+        Calendar calendar = Calendar.getInstance();
+        int number = calendar.get(Calendar.DAY_OF_WEEK);
+        if(number!=1){
+            tDepartmentService.onTime2();
+        }
+    }
+
+
+
+}

+ 20 - 0
src/main/java/com/szwl/controller/TDepartmentController.java

@@ -0,0 +1,20 @@
+package com.szwl.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 部门表(用于研发部值日通知) 前端控制器
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-07-14
+ */
+@RestController
+@RequestMapping("/tDepartment")
+public class TDepartmentController {
+
+}
+

+ 16 - 0
src/main/java/com/szwl/mapper/TDepartmentMapper.java

@@ -0,0 +1,16 @@
+package com.szwl.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.szwl.model.entity.TDepartment;
+
+/**
+ * <p>
+ * 部门表(用于研发部值日通知) Mapper 接口
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-07-14
+ */
+public interface TDepartmentMapper extends BaseMapper<TDepartment> {
+
+}

+ 21 - 0
src/main/java/com/szwl/mapper/xml/TDepartmentMapper.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.szwl.mapper.TDepartmentMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.szwl.model.entity.TDepartment">
+        <id column="id" property="id" />
+        <result column="create_date" property="createDate" />
+        <result column="modify_date" property="modifyDate" />
+        <result column="name" property="name" />
+        <result column="phone" property="phone" />
+        <result column="flag" property="flag" />
+        <result column="type" property="type" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, create_date, modify_date, name, phone, flag, type
+    </sql>
+
+</mapper>

+ 43 - 0
src/main/java/com/szwl/model/entity/TDepartment.java

@@ -0,0 +1,43 @@
+package com.szwl.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 部门表(用于研发部值日通知)
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-07-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="TDepartment对象", description="部门表(用于研发部值日通知)")
+public class TDepartment implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    private Long id;
+
+    private Date createDate;
+
+    private Date modifyDate;
+
+    private String name;
+
+    private String phone;
+
+    private String flag;
+
+    private String type;
+
+
+}

+ 19 - 0
src/main/java/com/szwl/service/TDepartmentService.java

@@ -0,0 +1,19 @@
+package com.szwl.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.szwl.model.entity.TDepartment;
+
+/**
+ * <p>
+ * 部门表(用于研发部值日通知) 服务类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-07-14
+ */
+public interface TDepartmentService extends IService<TDepartment> {
+
+    void onTime();
+
+    void onTime2();
+}

+ 3 - 0
src/main/java/com/szwl/service/TShandeMchService.java

@@ -17,4 +17,7 @@ import java.math.BigDecimal;
 public interface TShandeMchService extends MyIService<TShandeMch> {
 
     public String refund(Long id , String refundSn , BigDecimal refundAmount , String refundReason , String altRefInfo) throws UnsupportedEncodingException;
+
+    void jiesuan();
+
 }

+ 111 - 0
src/main/java/com/szwl/service/impl/TDepartmentServiceImpl.java

@@ -0,0 +1,111 @@
+package com.szwl.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.szwl.mapper.TDepartmentMapper;
+import com.szwl.model.entity.TDepartment;
+import com.szwl.model.entity.TEquipment;
+import com.szwl.model.utils.YunPianSms;
+import com.szwl.service.TDepartmentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ * 部门表(用于研发部值日通知) 服务实现类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2022-07-14
+ */
+@Service
+public class TDepartmentServiceImpl extends ServiceImpl<TDepartmentMapper, TDepartment> implements TDepartmentService {
+    @Autowired
+    private TDepartmentMapper tDepartmentMapper;
+    private static final String appid = "07784f5fedb508046c841b391005b7de";
+    @Override
+    public void onTime() {
+        LambdaQueryWrapper<TDepartment> query = Wrappers.lambdaQuery();
+        query.eq(TDepartment::getType,"1");
+        List<TDepartment> tDepartments = tDepartmentMapper.selectList(query);
+        int j = 0;
+        String result = null;
+        if(tDepartments.size()>0){
+            for(int i = 0;i < tDepartments.size();i++ ){
+                TDepartment tDepartment = tDepartments.get(i);
+                if(tDepartment.getFlag().equals("1")){
+                    j++;
+                    String name = null;
+                    String phone = null;
+                    tDepartment.setFlag("0");
+                    tDepartment.setModifyDate(new Date());
+                    tDepartmentMapper.updateById(tDepartment);
+                    if(i==(tDepartments.size()-1)){
+                        TDepartment tDepartment1 = tDepartments.get(0);
+                        tDepartment1.setFlag("1");
+                        tDepartment1.setModifyDate(new Date());
+                        phone = tDepartment1.getPhone();
+                        name = tDepartment1.getName();
+                        tDepartmentMapper.updateById(tDepartment1);
+                    }else{
+                        TDepartment tDepartment1 = tDepartments.get(i+1);
+                        tDepartment1.setFlag("1");
+                        tDepartment1.setModifyDate(new Date());
+                        phone = tDepartment1.getPhone();
+                        name = tDepartment1.getName();
+                        tDepartmentMapper.updateById(tDepartment1);
+                    }
+                    try {
+                        result = YunPianSms.sendSms(appid, getMessage(name), phone);
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                    break;
+                }
+            }
+            if(j==0){
+                TDepartment tDepartment1 = tDepartments.get(0);
+                tDepartment1.setFlag("1");
+                tDepartment1.setModifyDate(new Date());
+                String phone = tDepartment1.getPhone();
+                String name = tDepartment1.getName();
+                tDepartmentMapper.updateById(tDepartment1);
+                try {
+                    result = YunPianSms.sendSms(appid, getMessage(name), phone);
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    @Override
+    public void onTime2() {
+
+        LambdaQueryWrapper<TDepartment> query = Wrappers.lambdaQuery();
+        query.eq(TDepartment::getType,"1");
+        query.eq(TDepartment::getFlag,"1");
+        List<TDepartment> tDepartments = tDepartmentMapper.selectList(query);
+        if(tDepartments.size()>0){
+            String result = null;
+            TDepartment tDepartment = tDepartments.get(0);
+            String phone = tDepartment.getPhone();
+            String name = tDepartment.getName();
+            try {
+                result = YunPianSms.sendSms(appid, getMessage(name), phone);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    private String getMessage(String name) {
+
+        String message = "尊敬的"+name+",今天轮到您值日办公室了。";
+        return message;
+    }
+}

+ 9 - 3
src/main/java/com/szwl/service/impl/TShandeMchServiceImpl.java

@@ -11,6 +11,7 @@ import cn.com.sand.hmpay.vo.response.TradeResponse;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.szwl.feign.bean.PayFeign;
+import com.szwl.mapper.TOrderMapper;
 import com.szwl.model.bo.R;
 import com.szwl.model.entity.TEquipment;
 import com.szwl.model.entity.TOrder;
@@ -27,7 +28,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.List;
+import java.util.*;
 
 /**
  * <p>
@@ -83,7 +84,7 @@ public class TShandeMchServiceImpl extends ServiceImpl<TShandeMchMapper, TShande
     @Autowired
     TProductService productService;
     @Autowired
-    TShandeMchService tShandeMchService;
+    TShandeMchMapper tShandeMchMapper;
     @Autowired
     EsTEquipmentService esTEquipmentService;
 
@@ -98,7 +99,7 @@ public class TShandeMchServiceImpl extends ServiceImpl<TShandeMchMapper, TShande
         //获取金额表的今日金额
         LambdaQueryWrapper<TShandeMch> query = Wrappers.lambdaQuery();
         query.eq(TShandeMch::getAdminId,order.getAdminId());
-        List<TShandeMch> list = tShandeMchService.list(query);
+        List<TShandeMch> list = tShandeMchMapper.selectList(query);
         if(list.size()>0){
             TShandeMch shandeMch = list.get(0);
             BigDecimal todayBalance = shandeMch.getTodayBalance();
@@ -167,5 +168,10 @@ public class TShandeMchServiceImpl extends ServiceImpl<TShandeMchMapper, TShande
         return tradeResponse.getData();
     }
 
+    @Override
+    public void jiesuan() {
+
+    }
+
 
 }