Browse Source

设备流量卡过期消息

李进 1 year ago
parent
commit
a69840a3de

+ 5 - 0
device-api-service/pom.xml

@@ -114,6 +114,11 @@
             <artifactId>xy-magic-api</artifactId>
             <version>1.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.xy</groupId>
+            <artifactId>msg-sdk</artifactId>
+            <version>1.0</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 11 - 34
device-api-service/src/main/java/com/xy/job/DeviceChargingJob.java

@@ -5,19 +5,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xy.collections.map.JHashMap;
+import com.xy.collections.map.JMap;
 import com.xy.device.EnumDeviceCharging;
-import com.xy.dto.be.MercDto;
-import com.xy.entity.DeviceCharging;
-import com.xy.enums.ChannelType;
 import com.xy.mapper.DeviceChargingMapper;
-import com.xy.service.be.MercService;
 import com.xy.utils.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -30,8 +25,6 @@ public class DeviceChargingJob {
 
     private DeviceChargingMapper deviceChargingMapper;
 
-    private MercService mercService;
-
     /**
      * 设备管理费过期消息
      *
@@ -47,9 +40,7 @@ public class DeviceChargingJob {
             deviceChargingTimeout(now, end, now, 1, 1000);
         };
         //欠费
-        FunctionUtils.NoParamsNoResult timeout2 = () -> {
-            deviceChargingTimeout(null, now, now, 1, 1000);
-        };
+        FunctionUtils.NoParamsNoResult timeout2 = () -> deviceChargingTimeout(null, now, now, 1, 1000);
         timeout1.run();
         timeout2.run();
         return ReturnT.SUCCESS;
@@ -57,32 +48,18 @@ public class DeviceChargingJob {
 
     private void deviceChargingTimeout(String begin, String end, String thisTime, long current, long size) {
         //查询数据
-        IPage<DeviceCharging> iPage = Page.of(current, size);
-        IPage<Long> longIPage = deviceChargingMapper.deviceChargingTimeout(iPage, begin, end);
-        List<Long> records = longIPage.getRecords();
-        if (!Emptys.check(records)) {
+        IPage<Long> longIPage = deviceChargingMapper.deviceChargingTimeout(Page.of(current, size), begin, end);
+        List<Long> mercIds = longIPage.getRecords();
+        if (!Emptys.check(mercIds)) {
             return;
         }
-        List<MercDto.Vo> mercs = mercService.list(new MercDto.SelectList().setMercIds(records)).getData();
         //发送消息
-        MsgUtils.sendMsg(15L, () -> {
-            List<MsgUtils.MsgInfo> msgInfos = new ArrayList<>(mercs.size());
-            mercs.forEach(merc -> {
-                String contactPhone = merc.getContactPhone();
-                if (!Emptys.check(contactPhone)) {
-                    return;
-                }
-                MsgUtils.MsgInfo msgInfo = new MsgUtils.MsgInfo()
-                        .setChannelType(ChannelType.SMS.getCode())
-                        .setMpOpenIds(Arrays.asList(contactPhone))
-                        .setParams(new JHashMap<String, Object>()
-                                .set("dateTime", thisTime)
-                                .set("code", 1234)
-                        );
-                msgInfos.add(msgInfo);
-            });
-            return msgInfos;
-        });
+        JMap<String, Object> params = new JHashMap<>();
+        MsgUtils.sendMsg(15L, mercIds)
+                .sms(merc -> new MsgUtils.MsgInfo(merc.getContactPhone(), params))
+                .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), params))
+                .mini(userInfo -> new MsgUtils.MsgInfo(userInfo.getWechatOpenid(), params))
+                .builder();
         //下一页
         current++;
         deviceChargingTimeout(begin, end, thisTime, current, size);

+ 66 - 0
device-api-service/src/main/java/com/xy/job/DeviceSimJob.java

@@ -0,0 +1,66 @@
+package com.xy.job;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xy.collections.map.JHashMap;
+import com.xy.collections.map.JMap;
+import com.xy.device.EnumDeviceCharging;
+import com.xy.mapper.DeviceSimMapper;
+import com.xy.utils.*;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 设备流量卡job
+ */
+@Slf4j
+@Component
+@AllArgsConstructor
+public class DeviceSimJob {
+
+    private DeviceSimMapper deviceSimMapper;
+
+    /**
+     * 设备流量卡过期消息
+     *
+     * @return
+     */
+    @XxlJob("deviceSimTimeout")
+    public ReturnT<String> deviceSimTimeout() {
+        String now = DataTime.getSring();
+        //即将过期
+        FunctionUtils.NoParamsNoResult timeout1 = () -> {
+            int day = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_200.getCode(), Integer.class);
+            String end = DataTime.getStringAround(0, 0, day, 0, 0, 0);
+            deviceSimTimeout(now, end, now, 1, 1000);
+        };
+        //欠费
+        FunctionUtils.NoParamsNoResult timeout2 = () -> deviceSimTimeout(null, now, now, 1, 1000);
+        timeout1.run();
+        timeout2.run();
+        return ReturnT.SUCCESS;
+    }
+
+    private void deviceSimTimeout(String begin, String end, String thisTime, long current, long size) {
+        IPage<Long> longIPage = deviceSimMapper.deviceSimTimeout(Page.of(current, size), begin, end);
+        List<Long> mercIds = longIPage.getRecords();
+        if (!Emptys.check(mercIds)) {
+            return;
+        }
+        //发送消息
+        JMap<String, Object> params = new JHashMap<>();
+        MsgUtils.sendMsg(15L, mercIds)
+                .sms(merc -> new MsgUtils.MsgInfo(merc.getContactPhone(), params))
+                .official(userInfo -> new MsgUtils.MsgInfo(userInfo.getMpOpenid(), params))
+                .mini(userInfo -> new MsgUtils.MsgInfo(userInfo.getWechatOpenid(), params))
+                .builder();
+        //下一页
+        current++;
+        deviceSimTimeout(begin, end, thisTime, current, size);
+    }
+}

+ 10 - 0
device-api-service/src/main/java/com/xy/mapper/DeviceSimMapper.java

@@ -24,4 +24,14 @@ public interface DeviceSimMapper extends BaseMapper<DeviceSim> {
      * @return
      */
     IPage<DeviceSimDto.PageVo> page(IPage page, @Param("queryPage") DeviceSimDto.Page queryPage);
+
+    /**
+     * 管流量卡过期
+     *
+     * @param page
+     * @param begin
+     * @param end
+     * @return
+     */
+    IPage<Long> deviceSimTimeout(IPage page, @Param("begin") String begin, @Param("end") String end);
 }

+ 16 - 0
device-api-service/src/main/java/com/xy/mapper/mapper/DeviceSimMapper.xml

@@ -68,4 +68,20 @@
         </if>
         order by dsim.timeout asc
     </select>
+
+    <select id="deviceSimTimeout" resultType="java.lang.Long">
+        select merc_id
+        from device_sysinfo dsi
+        join device_info di on(dsi.device_id = di.device_id)
+        join device_sim dsim on(dsi.sim_iccid = dsim.id)
+        where
+        1 = 1
+        <if test="begin != null">
+            and dsim.timeout >= #{begin}
+        </if>
+        <if test="end != null">
+            and dsim.timeout &lt;= #{end}
+        </if>
+        GROUP BY di.merc_id
+    </select>
 </mapper>

+ 0 - 88
device-api-service/src/main/java/com/xy/utils/MsgUtils.java

@@ -1,88 +0,0 @@
-package com.xy.utils;
-
-import cn.hutool.core.bean.BeanUtil;
-import com.xy.collections.list.JArrayList;
-import com.xy.collections.map.JMap;
-import com.xy.dto.MsgConfigDto;
-import com.xy.dto.MsgConfigTestDto;
-import com.xy.service.MsgSendApiService;
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-public class MsgUtils {
-
-    /**
-     * 发送消息
-     *
-     * @param configId 消息配置id
-     * @param func     消息内容集合
-     */
-    public static void sendMsg(Long configId, FunctionUtils.NoParamsResult<List<MsgInfo>> func) {
-        List<MsgInfo> msgInfos = func.run();
-        sendMsg(configId, msgInfos);
-    }
-
-    /**
-     * 发送消息
-     *
-     * @param configId 消息配置id
-     * @param msgInfos 消息内容集合
-     */
-    public static void sendMsg(Long configId, List<MsgInfo> msgInfos) {
-        if (!Emptys.check(msgInfos)) {
-            return;
-        }
-        MsgSendApiService msgSendApiService = SpringBeanUtils.getBean(MsgSendApiService.class);
-        JMap<Integer, List<MsgInfo>> msgInfosJMaps = new JArrayList<>(msgInfos).toMap(MsgInfo::getChannelType).group();
-        //获取消息配置
-        MsgConfigDto.Vo msgConfig = R.feignCheckData(msgSendApiService.getMsgConfig(new MsgConfigDto.Vo().setId(configId)));
-        if (!Emptys.check(msgConfig)) {
-            return;
-        }
-        //获取消息配置业务参数
-        List<MsgConfigTestDto.BizParam> bizParams = R.feignCheckData(msgSendApiService.getBizParamByMsgConfig(new MsgConfigTestDto.MsgConfig().setConfigId(configId)));
-        if (!Emptys.check(bizParams)) {
-            return;
-        }
-        List<MsgConfigTestDto.BizData> bizDataList = BeanUtil.copyToList(bizParams, MsgConfigTestDto.BizData.class);
-        List<MsgConfigTestDto.BizData> sendList = new ArrayList<>();
-        bizDataList.forEach(bizData -> {
-            List<MsgInfo> msgInfosList = msgInfosJMaps.get(Integer.valueOf(bizData.getChannelType()).intValue());
-            if (!Emptys.check(msgInfosList)) {
-                return;
-            }
-            msgInfosList.forEach(msgInfo -> {
-                bizData.setReceivers(new HashSet<>(msgInfo.getMpOpenIds()))
-                        .setTemplateParams(msgInfo.getParams());
-                sendList.add(bizData);
-            });
-        });
-        //消息推送
-        msgSendApiService.sendByMsgConfig(new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(sendList));
-    }
-
-    @Data
-    @Accessors(chain = true)
-    public static class MsgInfo {
-
-        /**
-         * 发送渠道类型,枚举 ChannelType
-         */
-        private Integer channelType;
-
-        /**
-         * 接收人
-         */
-        private List<String> mpOpenIds;
-
-        /**
-         * 消息内容
-         */
-        private Map<String, Object> params;
-    }
-}