dcs před 4 měsíci
rodič
revize
39d4a9846e

+ 45 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/controller/ReminderController.java

@@ -2,6 +2,7 @@ package com.bosshand.virgo.api.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.api.model.Reminder;
+import com.bosshand.virgo.api.model.RemoteReminder;
 import com.bosshand.virgo.api.service.QuartzService;
 import com.bosshand.virgo.api.service.ReminderService;
 import com.bosshand.virgo.core.response.Response;
@@ -86,5 +87,49 @@ public class ReminderController {
         return Response.ok();
     }
 
+    //============================================远程提醒设备设置=================================================================
+
+    @ApiOperation("远程获取分页")
+    @RequestMapping(value = "/remote/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response listRemoteReminder(@RequestBody RemoteReminder remoteReminder, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = reminderService.getRemoteReminderTotalCount(remoteReminder);
+        List<RemoteReminder> dataList = reminderService.getRemoteReminderLimit(remoteReminder, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+    @ApiOperation("远程详情")
+    @RequestMapping(value = "/remote/{id}", method = RequestMethod.GET)
+    public Response getRemoteReminder(@PathVariable long id) {
+        return Response.ok(reminderService.getRemoteReminder(id));
+    }
+
+    @ApiOperation("远程保存")
+    @RequestMapping(value = "/remote", method = RequestMethod.POST)
+    public Response insertRemoteReminder(@RequestBody RemoteReminder remoteReminder) {
+        remoteReminder.setCode(String.valueOf(System.currentTimeMillis()));
+        RemoteReminder r = reminderService.insertRemoteReminder(remoteReminder);
+        //quartzService.executeJobRemoteReminderQuartz(r);
+        return Response.ok(r);
+    }
+
+    @ApiOperation("远程更新")
+    @RequestMapping(value = "/remote/update", method = RequestMethod.PUT)
+    public Response updateRemoteReminder(@RequestBody RemoteReminder remoteReminder) {
+        reminderService.updateRemoteReminder(remoteReminder);
+        return Response.ok();
+    }
+
+    @ApiOperation("远程删除")
+    @RequestMapping(value = "/remote/delete/{id}", method = RequestMethod.DELETE)
+    public Response deleteRemoteReminder(@PathVariable long id) {
+        RemoteReminder remoteReminder = reminderService.getRemoteReminder(id);
+        reminderService.deleteRemoteReminder(id);
+        //quartzService.deleteJobRemoteReminderQuartz(remoteReminder);
+        return Response.ok();
+    }
+
 
 }

+ 24 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/RemoteReminderDao.java

@@ -0,0 +1,24 @@
+package com.bosshand.virgo.api.dao;
+
+import com.bosshand.virgo.api.model.RemoteReminder;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface RemoteReminderDao {
+
+    int insert(RemoteReminder remoteReminder);
+
+    int update(RemoteReminder remoteReminder);
+
+    int delete(long id);
+
+    RemoteReminder get(long id);
+
+    List<RemoteReminder> getList(RemoteReminder remoteReminder);
+
+    int getTotalCount(RemoteReminder remoteReminder);
+
+    List<RemoteReminder> getLimit(@Param("p") RemoteReminder p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
+}

+ 116 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/RemoteReminder.java

@@ -0,0 +1,116 @@
+package com.bosshand.virgo.api.model;
+
+/**
+ * 远程提醒
+ */
+public class RemoteReminder {
+
+    private long id;
+
+    /**
+     * 系统生成code
+     */
+    private String code;
+
+    /**
+     * 组织id
+     */
+    private long organizationId;
+    /**
+     * 项目id
+     */
+    private long projectId;
+    /**
+     * 提醒类型
+     */
+    private Integer type;
+    /**
+     * 提醒人员列表
+     */
+    private String userList;
+    /**
+     * 提醒设备列表
+     */
+    private String deviceIds;
+    /**
+     * 提醒时间
+     */
+    private String date;
+
+    /**
+     * 附加字段
+     */
+    private String data;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public long getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(long projectId) {
+        this.projectId = projectId;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getUserList() {
+        return userList;
+    }
+
+    public void setUserList(String userList) {
+        this.userList = userList;
+    }
+
+    public String getDeviceIds() {
+        return deviceIds;
+    }
+
+    public void setDeviceIds(String deviceIds) {
+        this.deviceIds = deviceIds;
+    }
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+}

+ 2 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/operate/dao/OperateDeviceDao.java

@@ -24,4 +24,6 @@ public interface OperateDeviceDao {
     public List<OperateDevice> limit(@Param("od") OperateDevice od, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
 
     List<OperateDevice> getDeviceLevelIds(List<Long> list);
+
+    List<OperateDevice> getIds(List<Long> list);
 }

+ 31 - 1
virgo.api/src/main/java/com/bosshand/virgo/api/service/QuartzService.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.api.model.JobInfo;
 import com.bosshand.virgo.api.model.Project;
 import com.bosshand.virgo.api.model.Reminder;
+import com.bosshand.virgo.api.model.RemoteReminder;
 import org.quartz.*;
 import org.quartz.impl.matchers.GroupMatcher;
 import org.slf4j.Logger;
@@ -96,7 +97,7 @@ public class QuartzService {
         String jobName = reminder.getId() + "_" + reminder.getName();
         String jobClassName = "com.bosshand.virgo.api.job.JobReminderQuartz";
 
-        // 示例:2023年10月1日12点(UTC时间)
+        // 示例:2025-02-21T08:31:27.000Z(UTC时间)
         Instant futureTime = Instant.parse(reminder.getDate());
 
         // 计算延迟时间(毫秒)
@@ -114,6 +115,35 @@ public class QuartzService {
         this.deleteCronJob(jobName, DEFAULT_JOB_GROUP, TRIGGER_PRE + jobName, DEFAULT_TRIGGER_GROUP);
     }
 
+    /**
+     * 远程提醒任务
+     */
+    public void executeJobRemoteReminderQuartz(RemoteReminder remoteReminder) {
+
+        String jobName = remoteReminder.getId() + "_" + remoteReminder.getCode();
+        String jobClassName = "com.bosshand.virgo.api.job.JobRemoteReminderQuartz";
+
+        JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(remoteReminder));
+
+        // 示例:10:30
+        String date = remoteReminder.getDate();
+        String[] split = date.split(":");
+
+        // "0 30 10 * * ?" 每天上午10点30分
+        String cron = "0 " + split[1] + " " + split[0] + " * * ?";
+
+        // 执行任务
+        addCronJob(jobName, cron, jobClassName, data);
+    }
+
+    /**
+     * 删除远程提醒任务
+     */
+    public void deleteJobRemoteReminderQuartz(RemoteReminder remoteReminder) {
+        String jobName = remoteReminder.getId() + "_" + remoteReminder.getCode();
+        this.deleteCronJob(jobName, DEFAULT_JOB_GROUP, TRIGGER_PRE + jobName, DEFAULT_TRIGGER_GROUP);
+    }
+
     public String addCronJob(String jobName, String cron, String jobClassName, JSONObject data) {
         try {
             // 当前任务不存在才进行添加

+ 34 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/ReminderService.java

@@ -3,7 +3,9 @@ package com.bosshand.virgo.api.service;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.api.dao.ReminderDao;
+import com.bosshand.virgo.api.dao.RemoteReminderDao;
 import com.bosshand.virgo.api.model.Reminder;
+import com.bosshand.virgo.api.model.RemoteReminder;
 import com.bosshand.virgo.core.utils.StringUtil;
 import com.bosshand.virgo.core.utils.WeChatUtil;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -23,6 +25,9 @@ public class ReminderService {
     @Autowired
     ReminderDao reminderDao;
 
+    @Autowired
+    RemoteReminderDao remoteReminderDao;
+
     @Autowired
     ManagerClient managerClient;
 
@@ -153,5 +158,34 @@ public class ReminderService {
         log.info("在" + m + "时间点给userId:" + userId + "发送消息成功.");
     }
 
+    //================================================远程提醒设备设置========================================================================
+
+    public int getRemoteReminderTotalCount(RemoteReminder remotereminder) {
+        return remoteReminderDao.getTotalCount(remotereminder);
+    }
+
+    public List<RemoteReminder> getRemoteReminderLimit(RemoteReminder remotereminder, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return remoteReminderDao.getLimit(remotereminder, currIndex, pageSize);
+    }
+
+    public RemoteReminder getRemoteReminder(long id) {
+        return remoteReminderDao.get(id);
+    }
+
+    public RemoteReminder insertRemoteReminder(RemoteReminder remotereminder) {
+        remoteReminderDao.insert(remotereminder);
+        return remotereminder;
+    }
+
+    public RemoteReminder updateRemoteReminder(RemoteReminder remotereminder) {
+        remoteReminderDao.update(remotereminder);
+        return remotereminder;
+    }
+
+    public int deleteRemoteReminder(long id) {
+        return remoteReminderDao.delete(id);
+    }
+
 
 }

+ 18 - 0
virgo.api/src/main/resources/mapper/OperateDeviceMapper.xml

@@ -198,5 +198,23 @@
         </choose>
     </select>
 
+    <select id="getIds" resultMap="OperateDeviceResult">
+        SELECT * FROM operate_device
+        <choose>
+            <when test="list.size > 0">
+                where id in (
+                <foreach collection="list" item="item" index="index" separator=",">
+                    #{item}
+                </foreach>
+                )
+            </when>
+            <otherwise>
+                where 1=0
+            </otherwise>
+        </choose>
+    </select>
+
+
+
 
 </mapper>

+ 113 - 0
virgo.api/src/main/resources/mapper/RemoteReminderMapper.xml

@@ -0,0 +1,113 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.dao.RemoteReminderDao">
+
+    <resultMap type="com.bosshand.virgo.api.model.RemoteReminder" id="result">
+        <id column="id" property="id"/>
+        <result column="code" property="code"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="projectId" property="projectId"/>
+        <result column="type" property="type"/>
+        <result column="date" property="date"/>
+        <result column="userList" property="userList"/>
+        <result column="deviceIds" property="deviceIds"/>
+        <result column="data" property="data"/>
+    </resultMap>
+
+    <select id="get" resultMap="result">
+        SELECT * FROM remote_reminder where id = #{id}
+    </select>
+
+    <select id="getList" resultMap="result">
+        select * from remote_reminder
+        <where>
+            <if test="id != 0">
+                and id = #{id}
+            </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="projectId != 0">
+                and projectId = #{projectId}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="date != null">
+                and date = #{date}
+            </if>
+            <if test="deviceIds != null">
+                and deviceIds = #{deviceIds}
+            </if>
+        </where>
+    </select>
+
+    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO remote_reminder (`code`, `organizationId`, `projectId`, `type`, `date`, `userList`, `deviceIds`, `data`)
+        VALUES (#{code}, #{organizationId}, #{projectId}, #{type}, #{date}, #{userList}, #{deviceIds}, #{data})
+    </insert>
+
+    <update id="delete">
+        DELETE FROM remote_reminder WHERE id = #{id}
+    </update>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.model.RemoteReminder">
+        UPDATE remote_reminder
+        <trim prefix="set" suffixOverrides=",">
+            <if test="organizationId!=0">organizationId=#{organizationId},</if>
+            <if test="projectId!=0">projectId=#{projectId},</if>
+            <if test="type!=null">type=#{type},</if>
+            <if test="date!=null">date=#{date},</if>
+            <if test="userList!=null">userList=#{userList},</if>
+            <if test="deviceIds!=null">deviceIds=#{deviceIds},</if>
+            <if test="data!=null">data=#{data},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.RemoteReminder" resultType="Integer">
+        SELECT count(*) FROM remote_reminder
+        <where>
+            <if test="id != 0">
+                and id = #{id}
+            </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="projectId != 0">
+                and projectId = #{projectId}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="date != null">
+                and date = #{date}
+            </if>
+        </where>
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        SELECT a.* FROM remote_reminder a
+        <where>
+            <if test="p.id != 0">
+                and a.id = #{p.id}
+            </if>
+            <if test="p.organizationId != 0">
+                and a.organizationId = #{p.organizationId}
+            </if>
+            <if test="p.projectId != 0">
+                and a.projectId = #{p.projectId}
+            </if>
+            <if test="p.type != null">
+                and a.type = #{p.type}
+            </if>
+            <if test="p.date != null">
+                and a.date = #{p.date}
+            </if>
+        </where>
+        limit #{currIndex} , #{pageSize}
+    </select>
+
+</mapper>