1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package com.tzld.piaoquan.wecom.job;
- import com.alibaba.fastjson.JSONObject;
- import com.tzld.piaoquan.wecom.component.HttpPoolClient;
- import com.tzld.piaoquan.wecom.dao.mapper.StaffMapper;
- import com.tzld.piaoquan.wecom.model.po.Staff;
- import com.tzld.piaoquan.wecom.model.po.StaffExample;
- import com.tzld.piaoquan.wecom.service.AccessTokenService;
- import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
- import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
- import com.xxl.job.core.biz.model.ReturnT;
- import com.xxl.job.core.handler.annotation.XxlJob;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import org.springframework.util.CollectionUtils;
- import java.io.IOException;
- import java.util.List;
- import java.util.stream.Collectors;
- import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.GET_WE_COM_FOLLOW_USER_LIST;
- @Slf4j
- @Component
- public class WeComStaffDataJob {
- @Autowired
- private HttpPoolClient httpPoolClient;
- @Autowired
- private AccessTokenService accessTokenService;
- @Autowired
- private StaffMapper staffMapper;
- @XxlJob("insertStaffJob")
- public ReturnT<String> insertStaff(String param) {
- try {
- List<String> carrierIdList = getCarrierIdList();
- for (String carrierId : carrierIdList) {
- StaffExample example = new StaffExample();
- example.createCriteria().andCarrierIdEqualTo(carrierId);
- List<Staff> staffList = staffMapper.selectByExample(example);
- if (CollectionUtils.isEmpty(staffList)) {
- Staff staff = new Staff();
- staff.setCarrierId(carrierId);
- staff.setRemark("");
- staffMapper.insert(staff);
- }
- }
- } catch (Exception e) {
- LarkRobotUtil.sendMessage("更新员工失败");
- log.error("insertStaff error", e);
- }
- return ReturnT.SUCCESS;
- }
- public List<String> getCarrierIdList() throws IOException {
- String weComAccessToken = accessTokenService.getWeComAccessToken();
- String url = String.format(GET_WE_COM_FOLLOW_USER_LIST + "?access_token=%s", weComAccessToken);
- String res = httpPoolClient.get(url);
- JSONObject jsonObject = JSONObject.parseObject(res);
- Integer errcode = jsonObject.getInteger("errcode");
- if (errcode == 0) {
- return jsonObject.getJSONArray("follow_user").stream().map(String::valueOf).collect(Collectors.toList());
- }
- return null;
- }
- }
|