瀏覽代碼

Merge branch '20251119-wyp-weCom' into test

wangyunpeng 2 天之前
父節點
當前提交
1b549a2891
共有 17 個文件被更改,包括 453 次插入29 次删除
  1. 1 0
      api-module/src/main/java/com/tzld/piaoquan/api/common/enums/ExceptionEnum.java
  2. 1 1
      api-module/src/main/java/com/tzld/piaoquan/api/controller/wecom/thirdpart/WeComThirdPartyAccountController.java
  3. 15 0
      api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/wecom/thirdpart/ext/ThirdPartWeComStaffMapperExt.java
  4. 3 0
      api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComUserDetailJob.java
  5. 10 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/LoginOutResponse.java
  6. 3 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/ThirdPartyAccountConfigParam.java
  7. 2 1
      api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/ThirdPartyAccountListParam.java
  8. 1 1
      api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/ThirdPartyAccountLogOutParam.java
  9. 11 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/po/wecom/thirdpart/ThirdPartWeComStaff.java
  10. 70 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/po/wecom/thirdpart/ThirdPartWeComStaffExample.java
  11. 1 1
      api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/WeComThirdPartyAccountService.java
  12. 7 0
      api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/WeComThirdPartyService.java
  13. 227 10
      api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/impl/WeComThirdPartyAccountServiceImpl.java
  14. 25 0
      api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/impl/WeComThirdPartyServiceImpl.java
  15. 23 8
      api-module/src/main/resources/mapper/wecom/thirdpart/ThirdPartWeComStaffMapper.xml
  16. 46 0
      api-module/src/main/resources/mapper/wecom/thirdpart/ext/ThirdPartWeComStaffMapperExt.xml
  17. 7 7
      api-module/src/main/resources/mybatis-api-wecomThirdpart-generator-config.xml

+ 1 - 0
api-module/src/main/java/com/tzld/piaoquan/api/common/enums/ExceptionEnum.java

@@ -51,6 +51,7 @@ public enum ExceptionEnum {
     // 三方平台 自动拉群群发
     THIRD_PART_STAFF_NOT_FOUND(5001, "账号不存在"),
     THIRD_PART_ROOM_NOT_FOUND(5002, "群不存在"),
+    THIRD_PART_LOGOUT_FAILED(5003, "企微账号退出失败"),
 
     // 用户上传内容管理
     PQ_LOGIN_FAIL(6001, "票圈登录失败"),

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/controller/wecom/thirdpart/WeComThirdPartyAccountController.java

@@ -24,7 +24,7 @@ public class WeComThirdPartyAccountController {
     private WeComThirdPartyAccountService service;
 
     @GetMapping("/getQrCode")
-    public CommonResponse<AccountQrCodeVO> getQrCode(@RequestParam String id) {
+    public CommonResponse<AccountQrCodeVO> getQrCode(@RequestParam Long id) {
         return CommonResponse.success(service.getQrCode(id));
     }
 

+ 15 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/wecom/thirdpart/ext/ThirdPartWeComStaffMapperExt.java

@@ -0,0 +1,15 @@
+package com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext;
+
+import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyAccountListParam;
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface ThirdPartWeComStaffMapperExt {
+
+    int getAccountCount(@Param("param") ThirdPartyAccountListParam param);
+
+    List<ThirdPartWeComStaff> getAccountList(@Param("param") ThirdPartyAccountListParam param,
+                                             @Param("offset") int offset, @Param("pageSize") Integer pageSize);
+}

+ 3 - 0
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComUserDetailJob.java

@@ -80,6 +80,9 @@ public class WeComUserDetailJob {
                             });
                     if (commonResponse.getErrcode() == 0) {
                         LoginInfo loginInfo = commonResponse.getData();
+                        staff.setName(loginInfo.getUser_info().getObject().getNickname());
+                        staff.setRealName(loginInfo.getUser_info().getObject().getRealname());
+                        staff.setMobile(loginInfo.getUser_info().getObject().getMobile());
                         staff.setAvatar(loginInfo.getUser_info().getObject().getAvatar());
                         staff.setName(loginInfo.getUser_info().getObject().getNickname());
                         staff.setUpdateTime(new Date());

+ 10 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/LoginOutResponse.java

@@ -0,0 +1,10 @@
+package com.tzld.piaoquan.api.model.param.wecom.thirdpart;
+
+import lombok.Data;
+
+@Data
+public class LoginOutResponse {
+    private Integer errcode;
+    private String errmsg;
+    private Object data;
+}

+ 3 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/ThirdPartyAccountConfigParam.java

@@ -8,6 +8,9 @@ import java.util.List;
 @Data
 public class ThirdPartyAccountConfigParam {
 
+    @ApiModelProperty(value = "账号id")
+    private Long accountId;
+
     @ApiModelProperty(value = "投放场景")
     private String putScene;
     @ApiModelProperty(value = "渠道")

+ 2 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/ThirdPartyAccountListParam.java

@@ -1,10 +1,11 @@
 package com.tzld.piaoquan.api.model.param.wecom.thirdpart;
 
+import com.tzld.piaoquan.api.model.param.PageParam;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @Data
-public class ThirdPartyAccountListParam {
+public class ThirdPartyAccountListParam extends PageParam {
 
     @ApiModelProperty(value = "企微主体名称")
     private String corpName;

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/param/wecom/thirdpart/ThirdPartyAccountLogOutParam.java

@@ -6,5 +6,5 @@ import lombok.Data;
 @Data
 public class ThirdPartyAccountLogOutParam {
     @ApiModelProperty(value = "账号id")
-    private String id;
+    private Long id;
 }

+ 11 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/po/wecom/thirdpart/ThirdPartWeComStaff.java

@@ -19,6 +19,8 @@ public class ThirdPartWeComStaff {
 
     private String qrImage;
 
+    private String realName;
+
     private Integer status;
 
     private Integer autoCreateRoom;
@@ -91,6 +93,14 @@ public class ThirdPartWeComStaff {
         this.qrImage = qrImage;
     }
 
+    public String getRealName() {
+        return realName;
+    }
+
+    public void setRealName(String realName) {
+        this.realName = realName;
+    }
+
     public Integer getStatus() {
         return status;
     }
@@ -137,6 +147,7 @@ public class ThirdPartWeComStaff {
         sb.append(", thirdUuid=").append(thirdUuid);
         sb.append(", avatar=").append(avatar);
         sb.append(", qrImage=").append(qrImage);
+        sb.append(", realName=").append(realName);
         sb.append(", status=").append(status);
         sb.append(", autoCreateRoom=").append(autoCreateRoom);
         sb.append(", createTime=").append(createTime);

+ 70 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/po/wecom/thirdpart/ThirdPartWeComStaffExample.java

@@ -646,6 +646,76 @@ public class ThirdPartWeComStaffExample {
             return (Criteria) this;
         }
 
+        public Criteria andRealNameIsNull() {
+            addCriterion("real_name is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameIsNotNull() {
+            addCriterion("real_name is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameEqualTo(String value) {
+            addCriterion("real_name =", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameNotEqualTo(String value) {
+            addCriterion("real_name <>", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameGreaterThan(String value) {
+            addCriterion("real_name >", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameGreaterThanOrEqualTo(String value) {
+            addCriterion("real_name >=", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameLessThan(String value) {
+            addCriterion("real_name <", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameLessThanOrEqualTo(String value) {
+            addCriterion("real_name <=", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameLike(String value) {
+            addCriterion("real_name like", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameNotLike(String value) {
+            addCriterion("real_name not like", value, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameIn(List<String> values) {
+            addCriterion("real_name in", values, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameNotIn(List<String> values) {
+            addCriterion("real_name not in", values, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameBetween(String value1, String value2) {
+            addCriterion("real_name between", value1, value2, "realName");
+            return (Criteria) this;
+        }
+
+        public Criteria andRealNameNotBetween(String value1, String value2) {
+            addCriterion("real_name not between", value1, value2, "realName");
+            return (Criteria) this;
+        }
+
         public Criteria andStatusIsNull() {
             addCriterion("`status` is null");
             return (Criteria) this;

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/WeComThirdPartyAccountService.java

@@ -11,7 +11,7 @@ import java.util.List;
 
 public interface WeComThirdPartyAccountService {
 
-    AccountQrCodeVO getQrCode(String id);
+    AccountQrCodeVO getQrCode(Long id);
 
     Boolean getNeedCheckCode(String uuid);
 

+ 7 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/WeComThirdPartyService.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.api.service.wecom.thirdparty;
 
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.*;
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComCorp;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoom;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff;
 
@@ -20,6 +21,8 @@ public interface WeComThirdPartyService {
 
     LoginInfo getRunClientByUuid(UuidRequest request);
 
+    List<ThirdPartWeComCorp> getCorpListByIds(List<Long> ids);
+
     List<GetInnerContactsResponse.ContactItem> getInnerContacts(GetInnerContactsRequest request);
 
     List<ExternalContactsResponse.ContactItem> getExternalContacts(GetExternalContactsRequest request);
@@ -52,8 +55,12 @@ public interface WeComThirdPartyService {
 
     ThirdPartWeComRoom getRoomByRoomId(Long roomid);
 
+    ThirdPartWeComStaff getStaffById(Long id);
+
     ThirdPartWeComStaff getStaffByUuid(String uuid);
 
+    List<ThirdPartWeComStaff> getStaffListByThirdStaffIds(List<Long> thirdStaffIds);
+
     void updateStaffStatus(UpdateStaffStatusRequest request);
 
     void updateAutoCreateRoomStatus(UpdateAutoCreateRoomStatusRequest request);

+ 227 - 10
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/impl/WeComThirdPartyAccountServiceImpl.java

@@ -1,20 +1,35 @@
 package com.tzld.piaoquan.api.service.wecom.thirdparty.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
+import com.tzld.piaoquan.api.common.enums.wecom.ThirdPartWeComStaffStatusEnum;
+import com.tzld.piaoquan.api.common.exception.CommonException;
 import com.tzld.piaoquan.api.component.WeComThirdPartyApiClient;
+import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComStaffConfigMapper;
+import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComStaffConfigTaskContentMapper;
+import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComStaffConfigTaskMapper;
+import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComStaffMapper;
+import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComStaffMapperExt;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.*;
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.*;
 import com.tzld.piaoquan.api.model.vo.IdNameVO;
 import com.tzld.piaoquan.api.model.vo.contentplatform.AccountQrCodeVO;
+import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigTaskContentVO;
+import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigTaskVO;
 import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigVO;
 import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountVO;
 import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyAccountService;
 import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyService;
+import com.tzld.piaoquan.growth.common.utils.DistributedIdGenerator;
 import com.tzld.piaoquan.growth.common.utils.RedisUtils;
 import com.tzld.piaoquan.growth.common.utils.page.Page;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
@@ -24,28 +39,99 @@ public class WeComThirdPartyAccountServiceImpl implements WeComThirdPartyAccount
     private WeComThirdPartyApiClient apiClient;
     @Autowired
     private WeComThirdPartyService weComThirdPartyService;
+    @Autowired
+    private ThirdPartWeComStaffMapper staffMapper;
+    @Autowired
+    private ThirdPartWeComStaffConfigMapper staffConfigMapper;
+    @Autowired
+    private ThirdPartWeComStaffConfigTaskMapper staffConfigTaskMapper;
+    @Autowired
+    private ThirdPartWeComStaffConfigTaskContentMapper staffConfigTaskContentMapper;
+    @Autowired
+    private ThirdPartWeComStaffMapperExt staffMapperExt;
 
     @Autowired
     private RedisUtils redisUtils;
 
     @Override
-    public AccountQrCodeVO getQrCode(String id) {
-        return null;
+    public AccountQrCodeVO getQrCode(Long id) {
+        InitRequest initRequest = new InitRequest();
+        if (Objects.nonNull(id)) {
+            ThirdPartWeComStaff staff = weComThirdPartyService.getStaffById(id);
+            if (Objects.isNull(staff)) {
+                throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "企微账号不存在");
+            }
+            initRequest.setVid(String.valueOf(staff.getThirdStaffId()));
+        }
+        initRequest.setProxySituation(0);
+        initRequest.setDeverType("ipad");
+        String initResponseStr = apiClient.init(initRequest);
+        CommonResponse<InitResponse> initResponse =
+                JSONObject.parseObject(initResponseStr, new TypeReference<CommonResponse<InitResponse>>() {});
+        String uuid = initResponse.getData().getUuid();
+        String qrCodeResponseStr = apiClient.getQrCode(new UuidRequest(uuid));
+        CommonResponse<QrCodeResponse> qrCodeResponse =
+                JSONObject.parseObject(qrCodeResponseStr, new TypeReference<CommonResponse<QrCodeResponse>>() {});
+        if (qrCodeResponse.getErrcode() != 0) {
+            log.error("WeComThirdPartyService get qr code failed, request: {}, response: {}", initRequest, qrCodeResponse);
+            return null;
+        }
+        AccountQrCodeVO result = new AccountQrCodeVO();
+        result.setUuid(uuid);
+        result.setQrcode(qrCodeResponse.getData().getQrcode());
+        result.setKey(qrCodeResponse.getData().getKey());
+        result.setTtl(qrCodeResponse.getData().getTtl());
+        return result;
     }
 
     @Override
     public Boolean getNeedCheckCode(String uuid) {
-        return null;
+        String needVerifyCode = "needVerifyCode:uuid:" + uuid;
+        return redisUtils.containsKey(needVerifyCode);
     }
 
     @Override
     public void setCheckCode(CheckCodeRequest param) {
-
+        apiClient.checkCode(param);
     }
 
     @Override
     public Page<ThirdPartyAccountVO> list(ThirdPartyAccountListParam param) {
-        return null;
+        Page<ThirdPartyAccountVO> result = new Page<>(param.getPageNum(), param.getPageSize());
+        int offset = (param.getPageNum() - 1) * param.getPageSize();
+        int count = staffMapperExt.getAccountCount(param);
+        result.setTotalSize(count);
+        if (count == 0) {
+            return result;
+        }
+        List<ThirdPartWeComStaff> staffList = staffMapperExt.getAccountList(param, offset, param.getPageSize());
+        List<ThirdPartyAccountVO> list = buildThirdPartyAccountVOList(staffList);
+        result.setObjs(list);
+        return result;
+    }
+
+    private List<ThirdPartyAccountVO> buildThirdPartyAccountVOList(List<ThirdPartWeComStaff> staffList) {
+        List<Long> corpIds = staffList.stream().map(ThirdPartWeComStaff::getCorpId).collect(Collectors.toList());
+        List<ThirdPartWeComCorp> corpList = weComThirdPartyService.getCorpListByIds(corpIds);
+        Map<Long, ThirdPartWeComCorp> corpMap = corpList.stream()
+                .collect(Collectors.toMap(ThirdPartWeComCorp::getId, corp -> corp));
+
+        List<ThirdPartyAccountVO> result = new ArrayList<>();
+        for (ThirdPartWeComStaff staff : staffList) {
+            ThirdPartyAccountVO vo = new ThirdPartyAccountVO();
+            vo.setId(staff.getThirdStaffId());
+            vo.setCorpName(corpMap.get(staff.getCorpId()).getName());
+            vo.setAccountName(staff.getName());
+            vo.setRealName(staff.getRealName());
+            vo.setMobile(staff.getMobile());
+            vo.setStatus(staff.getStatus());
+            vo.setQrImage(staff.getQrImage());
+            vo.setAvatar(staff.getAvatar());
+            vo.setThirdStaffId(staff.getThirdStaffId());
+            vo.setThirdUuid(staff.getThirdUuid());
+            result.add(vo);
+        }
+        return result;
     }
 
     @Override
@@ -55,18 +141,149 @@ public class WeComThirdPartyAccountServiceImpl implements WeComThirdPartyAccount
 
     @Override
     public ThirdPartyAccountConfigVO getAccountConfig(ThirdPartyConfigGetParam param) {
-        return null;
+        ThirdPartWeComStaffConfig config = getStaffConfig(param.getId());
+        if (Objects.isNull(config)) {
+            return null;
+        }
+        List<ThirdPartWeComStaff> pushStaffList = getStaffConfigPushList(config);
+        Map<Long, String> pushStaffMap = pushStaffList.stream()
+                .collect(Collectors.toMap(ThirdPartWeComStaff::getThirdStaffId, ThirdPartWeComStaff::getName));
+        List<ThirdPartWeComStaffConfigTask> taskList = getStaffConfigTasks(config.getId());
+        List<String> taskIds = taskList.stream().map(ThirdPartWeComStaffConfigTask::getId).collect(Collectors.toList());
+        List<ThirdPartWeComStaffConfigTaskContent> contentList = getStaffConfigTaskContents(taskIds);
+        Map<String, List<ThirdPartWeComStaffConfigTaskContent>> taskContentMap = contentList.stream()
+                .collect(Collectors.groupingBy(ThirdPartWeComStaffConfigTaskContent::getTaskId));
+        ThirdPartyAccountConfigVO result = new ThirdPartyAccountConfigVO();
+        result.setPutScene(config.getPutScene());
+        result.setChannel(config.getChannel());
+        result.setSwitchFlag(config.getSwitchFlag());
+        result.setOpenRoomSendSwitchNum(config.getOpenRoomSendSwitchNum());
+        if (Objects.nonNull(config.getPrimaryThirdStaffId())) {
+            result.setPrimaryThirdStaffId(config.getPrimaryThirdStaffId());
+            result.setPrimaryThirdStaffName(pushStaffMap.get(config.getPrimaryThirdStaffId()));
+        }
+        if (Objects.nonNull(config.getSecondThirdStaffId())) {
+            result.setSecondThirdStaffId(config.getSecondThirdStaffId());
+            result.setSecondThirdStaffName(pushStaffMap.get(config.getSecondThirdStaffId()));
+        }
+        result.setTaskList(taskList.stream().map(task -> {
+            ThirdPartyAccountConfigTaskVO vo = new ThirdPartyAccountConfigTaskVO();
+            vo.setSwitchFlag(task.getSwitchFlag());
+            vo.setSendTime(JSONObject.parseArray(task.getSendTime(), String.class));
+            vo.setRandomMin(task.getRandomMin());
+            vo.setSeq(task.getSeq());
+            List<ThirdPartWeComStaffConfigTaskContent> contents = taskContentMap.get(task.getId());
+            vo.setContentList(contents.stream().map(content -> {
+                ThirdPartyAccountConfigTaskContentVO contentVO = new ThirdPartyAccountConfigTaskContentVO();
+                contentVO.setType(content.getType());
+                contentVO.setContent(content.getContent());
+                contentVO.setSource(content.getSource());
+                contentVO.setSourceContent(content.getSourceContent());
+                contentVO.setSeq(content.getSeq());
+                return contentVO;
+            }).collect(Collectors.toList()));
+            return vo;
+        }).collect(Collectors.toList()));
+        return result;
+    }
+
+    private List<ThirdPartWeComStaff> getStaffConfigPushList(ThirdPartWeComStaffConfig config) {
+        List<Long> thirdStaffIds = new ArrayList<>();
+        if (Objects.nonNull(config.getPrimaryThirdStaffId())) {
+            thirdStaffIds.add(config.getPrimaryThirdStaffId());
+        }
+        if (Objects.nonNull(config.getSecondThirdStaffId())) {
+            thirdStaffIds.add(config.getSecondThirdStaffId());
+        }
+        return weComThirdPartyService.getStaffListByThirdStaffIds(thirdStaffIds);
+    }
+
+    private ThirdPartWeComStaffConfig getStaffConfig(Long accountId) {
+        ThirdPartWeComStaffConfigExample example = new ThirdPartWeComStaffConfigExample();
+        example.createCriteria().andStaffIdEqualTo(accountId).andStatusEqualTo(1);
+        List<ThirdPartWeComStaffConfig> configs = staffConfigMapper.selectByExample(example);
+        if (configs.isEmpty()) {
+            return null;
+        }
+        return configs.get(0);
+    }
+
+    private List<ThirdPartWeComStaffConfigTask> getStaffConfigTasks(String configId) {
+        ThirdPartWeComStaffConfigTaskExample example = new ThirdPartWeComStaffConfigTaskExample();
+        example.createCriteria().andConfigIdEqualTo(configId);
+        return staffConfigTaskMapper.selectByExample(example);
+    }
+
+    private List<ThirdPartWeComStaffConfigTaskContent> getStaffConfigTaskContents(List<String> taskIds) {
+        ThirdPartWeComStaffConfigTaskContentExample example = new ThirdPartWeComStaffConfigTaskContentExample();
+        example.createCriteria().andTaskIdIn(taskIds);
+        return staffConfigTaskContentMapper.selectByExample(example);
     }
 
     @Override
     public void saveAccountConfig(ThirdPartyAccountConfigParam param) {
-
+        // todo check param
+        ThirdPartWeComStaffConfig config = getStaffConfig(param.getAccountId());
+        if (Objects.nonNull(config)) {
+            config.setStatus(0);
+            config.setUpdateTime(new Date());
+            staffConfigMapper.updateByPrimaryKey(config);
+        }
+        ThirdPartWeComStaffConfig newConfig = new ThirdPartWeComStaffConfig();
+        newConfig.setId(DistributedIdGenerator.generate());
+        newConfig.setStaffId(param.getAccountId());
+        newConfig.setPutScene(param.getPutScene());
+        newConfig.setChannel(param.getChannel());
+        newConfig.setSwitchFlag(param.getSwitchFlag());
+        newConfig.setOpenRoomSendSwitchNum(param.getOpenRoomSendSwitchNum());
+        newConfig.setPrimaryThirdStaffId(param.getPrimaryThirdStaffId());
+        newConfig.setSecondThirdStaffId(param.getSecondThirdStaffId());
+        newConfig.setStatus(1);
+        newConfig.setCreateTime(new Date());
+        newConfig.setUpdateTime(new Date());
+        staffConfigMapper.insert(newConfig);
+        for (ThirdPartyAccountConfigTaskParam taskParam : param.getTaskList()) {
+            ThirdPartWeComStaffConfigTask newTask = new ThirdPartWeComStaffConfigTask();
+            newTask.setConfigId(newConfig.getId());
+            newTask.setSwitchFlag(taskParam.getSwitchFlag());
+            newTask.setSendTime(JSONObject.toJSONString(taskParam.getSendTime()));
+            newTask.setRandomMin(taskParam.getRandomMin());
+            newTask.setSeq(taskParam.getSeq());
+            newTask.setCreateTime(new Date());
+            newTask.setUpdateTime(new Date());
+            staffConfigTaskMapper.insert(newTask);
+            for (ThirdPartyAccountConfigTaskContentParam taskContentParam : taskParam.getContentList()) {
+                ThirdPartWeComStaffConfigTaskContent newContent = new ThirdPartWeComStaffConfigTaskContent();
+                newContent.setTaskId(newTask.getId());
+                newContent.setType(taskContentParam.getType());
+                newContent.setContent(taskContentParam.getContent());
+                newContent.setSource(taskContentParam.getSource());
+                newContent.setSourceContent(taskContentParam.getSourceContent());
+                newContent.setSeq(taskContentParam.getSeq());
+                newContent.setCreateTime(new Date());
+                newContent.setUpdateTime(new Date());
+                staffConfigTaskContentMapper.insert(newContent);
+            }
+        }
+        // todo 配置同步
     }
 
     @Override
     public void logout(ThirdPartyAccountLogOutParam param) {
-
+        ThirdPartWeComStaff staff = weComThirdPartyService.getStaffById(param.getId());
+        if (Objects.isNull(staff)) {
+            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "企微账号不存在");
+        }
+        String logoutResponseStr = apiClient.loginOut(new UuidRequest(staff.getThirdUuid()));
+        CommonResponse<LoginOutResponse> logoutResponse =
+                JSONObject.parseObject(logoutResponseStr, new TypeReference<CommonResponse<LoginOutResponse>>() {});
+        if (logoutResponse.getErrcode() != 0) {
+            log.error("WeComThirdPartyService logout failed, request: {}, response: {}", staff.getThirdUuid(), logoutResponse);
+            throw new CommonException(ExceptionEnum.THIRD_PART_LOGOUT_FAILED.getCode(), "企微账号退出失败");
+        }
+        staff.setStatus(ThirdPartWeComStaffStatusEnum.QUIT.getVal());
+        staff.setUpdateTime(new Date());
+        staffMapper.updateByPrimaryKey(staff);
     }
 
-
 }

+ 25 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/thirdparty/impl/WeComThirdPartyServiceImpl.java

@@ -153,6 +153,7 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
             existStaff.setThirdStaffId(userObject.getUser_id());
             existStaff.setCorpId(existCorp.getId());
             existStaff.setName(userObject.getNickname());
+            existStaff.setRealName(userObject.getRealname());
             existStaff.setMobile(userObject.getMobile());
             existStaff.setAvatar(userObject.getAvatar());
             existStaff.setThirdStaffId(userObject.getUser_id());
@@ -161,6 +162,7 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
         } else {
             existStaff.setCorpId(existCorp.getId());
             existStaff.setName(userObject.getNickname());
+            existStaff.setRealName(userObject.getRealname());
             existStaff.setMobile(userObject.getMobile());
             existStaff.setAvatar(userObject.getAvatar());
             existStaff.setThirdUuid(uuid);
@@ -223,6 +225,17 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
         return list.get(0);
     }
 
+    @Override
+    public List<ThirdPartWeComCorp> getCorpListByIds(List<Long> ids) {
+        ThirdPartWeComCorpExample example = new ThirdPartWeComCorpExample();
+        example.createCriteria().andIdIn(ids);
+        List<ThirdPartWeComCorp> list = thirdPartWeComCorpMapper.selectByExample(example);
+        if (list.isEmpty()) {
+            return null;
+        }
+        return list;
+    }
+
     @Override
     public List<GetInnerContactsResponse.ContactItem> getInnerContacts(GetInnerContactsRequest request) {
         List<GetInnerContactsResponse.ContactItem> result = new ArrayList<>();
@@ -480,6 +493,11 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
         return roomList.get(0);
     }
 
+    @Override
+    public ThirdPartWeComStaff getStaffById(Long id) {
+        return thirdPartWeComStaffMapper.selectByPrimaryKey(id);
+    }
+
     @Override
     public ThirdPartWeComStaff getStaffByUuid(String uuid) {
         ThirdPartWeComStaffExample example = new ThirdPartWeComStaffExample();
@@ -491,6 +509,13 @@ public class WeComThirdPartyServiceImpl implements WeComThirdPartyService {
         return staffList.get(0);
     }
 
+    @Override
+    public List<ThirdPartWeComStaff> getStaffListByThirdStaffIds(List<Long> thirdStaffIds) {
+        ThirdPartWeComStaffExample example = new ThirdPartWeComStaffExample();
+        example.createCriteria().andThirdStaffIdIn(thirdStaffIds);
+        return thirdPartWeComStaffMapper.selectByExample(example);
+    }
+
     @Override
     public void updateStaffStatus(UpdateStaffStatusRequest request) {
         ThirdPartWeComStaff staff = getStaffByName(request.getStaffName());

+ 23 - 8
api-module/src/main/resources/mapper/wecom/thirdpart/ThirdPartWeComStaffMapper.xml

@@ -10,6 +10,7 @@
     <result column="third_uuid" jdbcType="VARCHAR" property="thirdUuid" />
     <result column="avatar" jdbcType="VARCHAR" property="avatar" />
     <result column="qr_image" jdbcType="VARCHAR" property="qrImage" />
+    <result column="real_name" jdbcType="VARCHAR" property="realName" />
     <result column="status" jdbcType="INTEGER" property="status" />
     <result column="auto_create_room" jdbcType="INTEGER" property="autoCreateRoom" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
@@ -74,8 +75,8 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, corp_id, mobile, `name`, third_staff_id, third_uuid, avatar, qr_image, `status`, 
-    auto_create_room, create_time, update_time
+    id, corp_id, mobile, `name`, third_staff_id, third_uuid, avatar, qr_image, real_name, 
+    `status`, auto_create_room, create_time, update_time
   </sql>
   <select id="selectByExample" parameterType="com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaffExample" resultMap="BaseResultMap">
     select
@@ -113,14 +114,14 @@
   <insert id="insert" parameterType="com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff">
     insert into third_part_we_com_staff (id, corp_id, mobile, 
       `name`, third_staff_id, third_uuid, 
-      avatar, qr_image, `status`, 
-      auto_create_room, create_time, update_time
-      )
+      avatar, qr_image, real_name, 
+      `status`, auto_create_room, create_time, 
+      update_time)
     values (#{id,jdbcType=BIGINT}, #{corpId,jdbcType=BIGINT}, #{mobile,jdbcType=VARCHAR}, 
       #{name,jdbcType=VARCHAR}, #{thirdStaffId,jdbcType=BIGINT}, #{thirdUuid,jdbcType=VARCHAR}, 
-      #{avatar,jdbcType=VARCHAR}, #{qrImage,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, 
-      #{autoCreateRoom,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
-      )
+      #{avatar,jdbcType=VARCHAR}, #{qrImage,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, 
+      #{status,jdbcType=INTEGER}, #{autoCreateRoom,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
+      #{updateTime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff">
     insert into third_part_we_com_staff
@@ -149,6 +150,9 @@
       <if test="qrImage != null">
         qr_image,
       </if>
+      <if test="realName != null">
+        real_name,
+      </if>
       <if test="status != null">
         `status`,
       </if>
@@ -187,6 +191,9 @@
       <if test="qrImage != null">
         #{qrImage,jdbcType=VARCHAR},
       </if>
+      <if test="realName != null">
+        #{realName,jdbcType=VARCHAR},
+      </if>
       <if test="status != null">
         #{status,jdbcType=INTEGER},
       </if>
@@ -234,6 +241,9 @@
       <if test="record.qrImage != null">
         qr_image = #{record.qrImage,jdbcType=VARCHAR},
       </if>
+      <if test="record.realName != null">
+        real_name = #{record.realName,jdbcType=VARCHAR},
+      </if>
       <if test="record.status != null">
         `status` = #{record.status,jdbcType=INTEGER},
       </if>
@@ -261,6 +271,7 @@
       third_uuid = #{record.thirdUuid,jdbcType=VARCHAR},
       avatar = #{record.avatar,jdbcType=VARCHAR},
       qr_image = #{record.qrImage,jdbcType=VARCHAR},
+      real_name = #{record.realName,jdbcType=VARCHAR},
       `status` = #{record.status,jdbcType=INTEGER},
       auto_create_room = #{record.autoCreateRoom,jdbcType=INTEGER},
       create_time = #{record.createTime,jdbcType=TIMESTAMP},
@@ -293,6 +304,9 @@
       <if test="qrImage != null">
         qr_image = #{qrImage,jdbcType=VARCHAR},
       </if>
+      <if test="realName != null">
+        real_name = #{realName,jdbcType=VARCHAR},
+      </if>
       <if test="status != null">
         `status` = #{status,jdbcType=INTEGER},
       </if>
@@ -317,6 +331,7 @@
       third_uuid = #{thirdUuid,jdbcType=VARCHAR},
       avatar = #{avatar,jdbcType=VARCHAR},
       qr_image = #{qrImage,jdbcType=VARCHAR},
+      real_name = #{realName,jdbcType=VARCHAR},
       `status` = #{status,jdbcType=INTEGER},
       auto_create_room = #{autoCreateRoom,jdbcType=INTEGER},
       create_time = #{createTime,jdbcType=TIMESTAMP},

+ 46 - 0
api-module/src/main/resources/mapper/wecom/thirdpart/ext/ThirdPartWeComStaffMapperExt.xml

@@ -0,0 +1,46 @@
+<?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.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComStaffMapperExt">
+
+    <select id="getAccountCount" resultType="java.lang.Integer">
+        select count(1)
+        from third_part_we_com_staff staff
+        join third_part_we_com_corp corp on staff.corp_id = corp.id
+        <where>
+            <trim prefixOverrides="and">
+                <if test="param.corpName != null">
+                    and corp.name = #{param.corpName}
+                </if>
+                <if test="param.accountName != null">
+                    and staff.name = #{param.accountName}
+                </if>
+                <if test="param.mobile != null">
+                    and staff.mobile = #{param.mobile}
+                </if>
+            </trim>
+        </where>
+    </select>
+
+    <select id="getAccountList"
+            resultType="com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff">
+        select staff.*
+        from third_part_we_com_staff staff
+        join third_part_we_com_corp corp on staff.corp_id = corp.id
+        <where>
+            <trim prefixOverrides="and">
+                <if test="param.corpName != null">
+                    and corp.name = #{param.corpName}
+                </if>
+                <if test="param.accountName != null">
+                    and staff.name = #{param.accountName}
+                </if>
+                <if test="param.mobile != null">
+                    and staff.mobile = #{param.mobile}
+                </if>
+            </trim>
+        </where>
+        order by staff.id desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+</mapper>

+ 7 - 7
api-module/src/main/resources/mybatis-api-wecomThirdpart-generator-config.xml

@@ -53,14 +53,14 @@
 <!--        <table tableName="third_part_we_com_corp" domainObjectName="ThirdPartWeComCorp" alias=""/>-->
 <!--        <table tableName="third_part_we_com_room" domainObjectName="ThirdPartWeComRoom" alias=""/>-->
 <!--        <table tableName="third_part_we_com_room_user" domainObjectName="ThirdPartWeComRoomUser" alias=""/>-->
-        <table tableName="third_part_we_com_room_config" domainObjectName="ThirdPartWeComRoomConfig" alias=""/>
-        <table tableName="third_part_we_com_room_config_task" domainObjectName="ThirdPartWeComRoomConfigTask" alias=""/>
-        <table tableName="third_part_we_com_room_config_task_content" domainObjectName="ThirdPartWeComRoomConfigTaskContent" alias=""/>
-<!--        <table tableName="third_part_we_com_staff" domainObjectName="ThirdPartWeComStaff" alias=""/>-->
+<!--        <table tableName="third_part_we_com_room_config" domainObjectName="ThirdPartWeComRoomConfig" alias=""/>-->
+<!--        <table tableName="third_part_we_com_room_config_task" domainObjectName="ThirdPartWeComRoomConfigTask" alias=""/>-->
+<!--        <table tableName="third_part_we_com_room_config_task_content" domainObjectName="ThirdPartWeComRoomConfigTaskContent" alias=""/>-->
+        <table tableName="third_part_we_com_staff" domainObjectName="ThirdPartWeComStaff" alias=""/>
 <!--        <table tableName="third_part_we_com_staff_user" domainObjectName="ThirdPartWeComStaffUser" alias=""/>-->
-        <table tableName="third_part_we_com_staff_config" domainObjectName="ThirdPartWeComStaffConfig" alias=""/>
-        <table tableName="third_part_we_com_staff_config_task" domainObjectName="ThirdPartWeComStaffConfigTask" alias=""/>
-        <table tableName="third_part_we_com_staff_config_task_content" domainObjectName="ThirdPartWeComStaffConfigTaskContent" alias=""/>
+<!--        <table tableName="third_part_we_com_staff_config" domainObjectName="ThirdPartWeComStaffConfig" alias=""/>-->
+<!--        <table tableName="third_part_we_com_staff_config_task" domainObjectName="ThirdPartWeComStaffConfigTask" alias=""/>-->
+<!--        <table tableName="third_part_we_com_staff_config_task_content" domainObjectName="ThirdPartWeComStaffConfigTaskContent" alias=""/>-->
 <!--        <table tableName="third_part_we_com_msg" domainObjectName="ThirdPartWeComMsg" alias=""/>-->
     </context>