Преглед на файлове

供客户端调用的接口

lqc преди 4 години
родител
ревизия
29839358c0

+ 165 - 0
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxCashWorkClientController.java

@@ -0,0 +1,165 @@
+package com.mokamrp.privates.controller.pangu;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.mokamrp.privates.entity.pangu.FosterwxWorkServeHandle;
+import com.mokamrp.privates.help.AjaxResult;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashMobile;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashScheduleTaskList;
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
+import com.mokamrp.privates.mapper.pojo.Corp;
+import com.mokamrp.privates.service.CorpService;
+import com.mokamrp.privates.service.pangu.FosterwxCashMobileService;
+import com.mokamrp.privates.service.pangu.FosterwxCashScheduleTaskListService;
+import com.mokamrp.privates.service.pangu.FosterwxMobileService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.List;
+
+/**
+ * @Classname FosterwxCashWorkClientController
+ * @Description TODO
+ * @Date 2021/10/26 9:41 上午
+ * @Created by luqiucheng
+ */
+@RestController
+@RequestMapping("/server")
+@Api(tags = "供客户端调用接口")
+@Slf4j
+public class FosterwxCashWorkClientController {
+    @Autowired
+    private FosterwxCashScheduleTaskListService fosterwxCashScheduleTaskListService;
+
+    @Autowired
+    private CorpService corpService;
+
+    @Autowired
+    private FosterwxMobileService fosterwxMobileService;
+
+    @Autowired
+    private FosterwxCashMobileService fosterwxCashMobileService;
+
+
+    @PostMapping("/getTaskInfo")
+    @ApiOperation(value = "返回凌晨到当前时间的未发送的数据,主体 昵称/团队id 昵称 两两一组必须有数据")
+    public Object getTaskInfo(FosterwxWorkServeHandle handle) {
+        log.info("客户端请求的信息:{}", handle);
+
+        String errInfo = checkParam(handle);
+
+        // 报错的的情况返回报错信息
+        if (!errInfo.isEmpty()) return AjaxResult.error(errInfo);
+
+        // 根据参数获取账号信息
+        FosterwxMobile fosterwxMobile = getAccountInfo(handle);
+
+        if (null == fosterwxMobile) return AjaxResult.error("根据参数无法获取所属账号");
+
+        // 根据手机id 获取分组id
+        FosterwxCashMobile fosterwxCashMobile = fosterwxCashMobileService.getOne(new LambdaQueryWrapper<FosterwxCashMobile>().eq(FosterwxCashMobile::getMobileId, fosterwxMobile.getId()).last("LIMIT 1"));
+
+        if (null == fosterwxCashMobile) return AjaxResult.error("该账号未划入变现分组");
+
+        LocalDate now = LocalDate.now();
+        LocalDateTime firstDateTime = LocalDateTime.of(now, LocalTime.MIN);
+        LocalDateTime lastDateTime = LocalDateTime.now();
+
+        LambdaQueryWrapper<FosterwxCashScheduleTaskList> fosterwxCashScheduleTaskListLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        // 企微任务
+        fosterwxCashScheduleTaskListLambdaQueryWrapper.eq(FosterwxCashScheduleTaskList::getType, 2);
+        // 分组id
+        fosterwxCashScheduleTaskListLambdaQueryWrapper.eq(FosterwxCashScheduleTaskList::getGroupId, fosterwxCashMobile.getGroupId());
+        // 已生成的任务 待发送的任务
+        fosterwxCashScheduleTaskListLambdaQueryWrapper.in(FosterwxCashScheduleTaskList::getStatus, 2, 4);
+
+        fosterwxCashScheduleTaskListLambdaQueryWrapper.between(FosterwxCashScheduleTaskList::getSendTime, firstDateTime, lastDateTime);
+
+        List<FosterwxCashScheduleTaskList> fosterwxCashScheduleTaskListList = fosterwxCashScheduleTaskListService.list(fosterwxCashScheduleTaskListLambdaQueryWrapper);
+
+        fosterwxCashScheduleTaskListList.forEach(fosterwxCashScheduleTaskList -> {
+            fosterwxCashScheduleTaskListService.updateById(new FosterwxCashScheduleTaskList() {{
+                setId(fosterwxCashScheduleTaskList.getId());
+                setStatus(5);
+                setUpdateAt(LocalDateTime.now());
+            }});
+        });
+
+        return AjaxResult.success(fosterwxCashScheduleTaskListList);
+    }
+
+    /**
+     * 根据参数获取账号信息
+     * @since: 1.18.1
+     * @param: [handle]
+     * @return: com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile
+     * @author: lqc
+     * @date: 2021/10/26
+     */
+    private FosterwxMobile getAccountInfo(FosterwxWorkServeHandle handle) {
+        FosterwxMobile fosterwxMobile = new FosterwxMobile();
+
+        // 主体 手机号 组
+        if (null != handle.getCorpName() && !handle.getCorpName().isEmpty()) {
+            // 获取主题信息
+            Corp corp = corpService.getOne(new LambdaQueryWrapper<Corp>().eq(Corp::getName, handle.getCorpName()).last("LIMIT 1"));
+            if (null != handle.getMobileNo() && !handle.getMobileNo().isEmpty()) {
+                if (null == corp) return null;
+
+                fosterwxMobile = fosterwxMobileService.getOne(new LambdaQueryWrapper<FosterwxMobile>().eq(FosterwxMobile::getMobileNo, handle.getMobileNo()).eq(FosterwxMobile::getWorkWxCorpId, corp.getId()).last("LIMIT 1"));
+
+                return fosterwxMobile;
+            }
+
+            // 主体 昵称 组
+            if (null != handle.getNickName() && !handle.getNickName().isEmpty()) {
+                if (null == corp) return null;
+
+                fosterwxMobile = fosterwxMobileService.getOne(new LambdaQueryWrapper<FosterwxMobile>().eq(FosterwxMobile::getCustserviceName, handle.getNickName()).eq(FosterwxMobile::getWorkWxCorpId, corp.getId()).last("LIMIT 1"));
+
+                return fosterwxMobile;
+            }
+        }
+
+        // 团队id 昵称 组
+        if (null != handle.getNickName() && !handle.getNickName().isEmpty() && null != handle.getTeamId() && !handle.getTeamId().isEmpty()) {
+            fosterwxMobile = fosterwxMobileService.getOne(new LambdaQueryWrapper<FosterwxMobile>().eq(FosterwxMobile::getTeamId, handle.getTeamId()).eq(FosterwxMobile::getCustserviceName, handle.getNickName()).last("LIMIT 1"));
+
+            return fosterwxMobile;
+        }
+    }
+
+    /**
+     * 检查入参
+     * @since: 1.18.1
+     * @param: [handle]
+     * @return: java.lang.String
+     * @author: lqc
+     * @date: 2021/10/26
+     */
+    private String checkParam(FosterwxWorkServeHandle handle) {
+        // 判断主体 手机号 组
+        if (null != handle.getMobileNo() && !handle.getMobileNo().isEmpty() && null != handle.getCorpName() && !handle.getCorpName().isEmpty()) {
+            return null;
+        }
+
+        // 判断主体 昵称 组
+        if (null != handle.getNickName() && !handle.getNickName().isEmpty() && null != handle.getCorpName() && !handle.getCorpName().isEmpty()) {
+            return null;
+        }
+
+        // 判断团队id 昵称 组
+        if (null != handle.getNickName() && !handle.getNickName().isEmpty() && null != handle.getTeamId() && !handle.getTeamId().isEmpty()) {
+            return null;
+        }
+
+        return "参数没有设置全,无法根据现有信息获取任务";
+    }
+}

+ 21 - 0
src/main/java/com/mokamrp/privates/entity/pangu/FosterwxWorkServeHandle.java

@@ -0,0 +1,21 @@
+package com.mokamrp.privates.entity.pangu;
+
+import lombok.Data;
+
+/**
+ * @Classname FosterwxWorkServeHandle
+ * @Description TODO
+ * @Date 2021/10/26 10:17 上午
+ * @Created by luqiucheng
+ */
+@Data
+public class FosterwxWorkServeHandle {
+    // 主体
+    private String corpName;
+    // 昵称
+    private String nickName;
+    // 团队id
+    private String teamId;
+    // 手机号
+    private String mobileNo;
+}