Browse Source

oa数据对接

yumeng 4 years ago
parent
commit
0f93b06bf6
23 changed files with 1135 additions and 22 deletions
  1. 27 2
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java
  2. 14 2
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  3. 6 2
      module-common/src/main/java/cn/com/ctop/common/module/utils/HttpUtils.java
  4. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouHistoryReportTaskServiceImpl.java
  5. 9 4
      module-oa/src/main/java/cn/com/ctop/oa/modules/constant/QYWxConstant.java
  6. 248 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/controller/WechatCheckinDataController.java
  7. 248 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/controller/WechatUserListController.java
  8. 134 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/entity/WechatCheckinData.java
  9. 63 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/entity/WechatUserList.java
  10. 59 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/enums/DepartEnum.java
  11. 15 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/WechatCheckinDataMapper.java
  12. 15 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/WechatUserListMapper.java
  13. 5 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/xml/WechatCheckinDataMapper.xml
  14. 5 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/xml/WechatUserListMapper.xml
  15. 15 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatCheckinDataService.java
  16. 1 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatTokenService.java
  17. 0 4
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatUserInfoService.java
  18. 15 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatUserListService.java
  19. 119 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatCheckinDataServiceImpl.java
  20. 10 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatDepartmentServiceImpl.java
  21. 28 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatTokenServiceImpl.java
  22. 0 8
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatUserInfoServiceImpl.java
  23. 98 0
      module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatUserListServiceImpl.java

+ 27 - 2
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -181,6 +181,7 @@ public class DateUtils extends PropertyEditorSupport {
     public static Calendar getCalendar() {
         return Calendar.getInstance();
     }
+
     /**
      * 指定毫秒数表示的日历
      *
@@ -213,15 +214,17 @@ public class DateUtils extends PropertyEditorSupport {
         }
         return null;
     }
+
     /**
      * 当前日期
      *
-     * @return 系统当前时间
      * @param l
+     * @return 系统当前时间
      */
     public static Date getDate(long l) {
         return new Date();
     }
+
     /**
      * 日期转换为字符串
      *
@@ -235,9 +238,11 @@ public class DateUtils extends PropertyEditorSupport {
         }
         return date_sdf.format(date);
     }
+
     public static Date getDate() {
         return new Date();
     }
+
     /**
      * 格式化时间
      *
@@ -592,7 +597,7 @@ public class DateUtils extends PropertyEditorSupport {
      * @return 如果转换成功则返回转换后的日期
      * @throws
      */
-    public static Calendar parseCalendar(String src, String pattern){
+    public static Calendar parseCalendar(String src, String pattern) {
 
         Date date = parseDate(src, pattern);
         Calendar cal = Calendar.getInstance();
@@ -711,6 +716,26 @@ public class DateUtils extends PropertyEditorSupport {
         return dateFormat.format(getDate);
     }
 
+    public static Date stampToTime(Long ms) throws ParseException {
+        long msl = ms * 1000;
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date temp = null;
+        if (ms != null) {
+            try {
+                String str = sdf.format(msl);
+                temp = sdf.parse(str);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+        return temp;
+    }
+
+    public static void main(String[] args) throws ParseException {
+        Date date = stampToTime(1599524171L);
+        System.err.println(date);
+    }
+
     /**
      * String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
      * HH:mm:ss“ * @param text String类型的时间值

+ 14 - 2
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -12,9 +12,12 @@ import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
+import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
 import cn.com.ctop.oa.modules.service.IWechatDepartmentService;
+import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.report.service.IReportService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -57,11 +60,20 @@ public class SampleTest {
 
     @Autowired
     private IWechatDepartmentService wechatDepartment;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private IWechatUserListService wechatUserInfoService;
+    @Autowired
+    private IWechatCheckinDataService wechatCheckinDataService;
 
 
     @Test
     public void getDepartment() {
-        wechatDepartment.getDepartment();
+        wechatCheckinDataService.getCheckinData();
+        //  wechatUserInfoService.getUserList();
+        // wechatDepartment.getDepartment();
+        // kuaishouInterfaceService.getSuZaoList("a34853c230e1b949eddbe569023dbc40", 7022550L, 1, "2020-09-15", "2020-09-16");
 
     }
 
@@ -72,7 +84,7 @@ public class SampleTest {
         queryWrapper.eq("media_id", 2);
         List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
         for (CtopOauthToken token : list) {
-            kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-03-10", "2020-09-10", "history");
+            kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-03-14", "2020-09-14", "history");
 
         }
 

+ 6 - 2
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpUtils.java

@@ -328,9 +328,12 @@ public class HttpUtils {
             HttpPost httppost = new HttpPost(url);
             httppost.setHeader("User-Agent", USER_AGENT);
             httppost.addHeader("Content-Type", "application/json");
-            for (String key : headers.keySet()) {
-                httppost.setHeader(key, headers.get(key));
+            if (!Check.isNull(headers)) {
+                for (String key : headers.keySet()) {
+                    httppost.setHeader(key, headers.get(key));
+                }
             }
+
             httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
             HttpEntity respentity;
 
@@ -679,6 +682,7 @@ public class HttpUtils {
         String strReturn = "";
         try {
             String uri = url + "?" + mapParamsSortToStringBySeperator(params, "&");
+            System.err.println(uri);
             HttpGet httpGet = new HttpGet(uri);
             if (headers != null) {
                 Iterator<String> keyIter = headers.keySet().iterator();

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouHistoryReportTaskServiceImpl.java

@@ -269,6 +269,7 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
 
 
     private void getHistoryTypeList() {
+
         historyTypeList = new ArrayList<>();
         historyTypeList.add(5);
        /* historyTypeList.add(1);

+ 9 - 4
module-oa/src/main/java/cn/com/ctop/oa/modules/constant/QYWxConstant.java

@@ -4,12 +4,17 @@ public class QYWxConstant {
     public static final String QYWX_CORP_ID = "ww24b8a47826f5875f";
     public static final Integer QYWX_AGENT_ID = 1000004;
     public static final String QYWX_CORP_SECRET = "1YWGDtuZWrQDl6US3OPHG8_pvuNgP1TeUsOmfRk6GmQ";
+
+
+    public static final Integer QYWX_OA_AGENT_ID = 3010011;
+    public static final String QYWX_OA_CORP_SECRET = "MDeiFSCwIlcmcR1zrYvmjNlsoYFGl8I770uuUezWgGE";
+
+
     public static final String QYWX_API_URL = "https://qyapi.weixin.qq.com";  //企业微信api域名
     public static final String QYWX_DEPART_LIST = "https://qyapi.weixin.qq.com/cgi-bin/department/list";  //获取部门列表
     public static final String QYWX_GET_TOKEN = "/cgi-bin/gettoken";  //获取token
-    public static final String QYWX_USER_SIMPLELIST = "/cgi-bin/user/simplelist";  //获取部门下员工简单信息
-    public static final String QYWX_USER_LIST = "/cgi-bin/user/list";  //获取部门下员工详细信息
-    public static final String QYWX_CONVERT_TO_OPENID = "/cgi-bin/user/convert_to_openid";  //获取部门下员工详细信息
-    public static final String QYWX_GET_LOGIN_USERINFO = "/cgi-bin/user/getuserinfo";  //获取当前登录员工USERID
+    public static final String QYWX_USER_SIMPLELIST = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist";  //获取部门下员工简单信息
+    public static final String QYWX_CHECKIN_DATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata";  //获取部门下员工简单信息
+
 
 }

+ 248 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/controller/WechatCheckinDataController.java

@@ -0,0 +1,248 @@
+package cn.com.ctop.oa.modules.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.oa.modules.entity.WechatCheckinData;
+import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 企业微信用户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-09-15
+ */
+@Slf4j
+@Api(tags = "企业微信用户")
+@RestController
+@RequestMapping("/oa/wechatCheckinData")
+public class WechatCheckinDataController {
+    @Autowired
+    private IWechatCheckinDataService wechatCheckinDataService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param wechatCheckinData
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-分页列表查询")
+    @ApiOperation(value = "企业微信用户-分页列表查询", notes = "企业微信用户-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<WechatCheckinData>> queryPageList(WechatCheckinData wechatCheckinData,
+                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                          HttpServletRequest req) {
+        Result<IPage<WechatCheckinData>> result = new Result<>();
+        QueryWrapper<WechatCheckinData> queryWrapper = QueryGenerator.initQueryWrapper(wechatCheckinData, req.getParameterMap());
+        Page<WechatCheckinData> page = new Page<WechatCheckinData>(pageNo, pageSize);
+        IPage<WechatCheckinData> pageList = wechatCheckinDataService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param wechatCheckinData
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-添加")
+    @ApiOperation(value = "企业微信用户-添加", notes = "企业微信用户-添加")
+    @PostMapping(value = "/add")
+    public Result<WechatCheckinData> add(@RequestBody WechatCheckinData wechatCheckinData) {
+        Result<WechatCheckinData> result = new Result<>();
+        try {
+            wechatCheckinDataService.save(wechatCheckinData);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param wechatCheckinData
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-编辑")
+    @ApiOperation(value = "企业微信用户-编辑", notes = "企业微信用户-编辑")
+    @PutMapping(value = "/edit")
+    public Result<WechatCheckinData> edit(@RequestBody WechatCheckinData wechatCheckinData) {
+        Result<WechatCheckinData> result = new Result<WechatCheckinData>();
+        WechatCheckinData wechatCheckinDataEntity = wechatCheckinDataService.getById(wechatCheckinData.getId());
+        if (wechatCheckinDataEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = wechatCheckinDataService.updateById(wechatCheckinData);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-通过id删除")
+    @ApiOperation(value = "企业微信用户-通过id删除", notes = "企业微信用户-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        try {
+            wechatCheckinDataService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-批量删除")
+    @ApiOperation(value = "企业微信用户-批量删除", notes = "企业微信用户-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<WechatCheckinData> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<WechatCheckinData> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.wechatCheckinDataService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-通过id查询")
+    @ApiOperation(value = "企业微信用户-通过id查询", notes = "企业微信用户-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<WechatCheckinData> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<WechatCheckinData> result = new Result<>();
+        WechatCheckinData wechatCheckinData = wechatCheckinDataService.getById(id);
+        if (wechatCheckinData == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(wechatCheckinData);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<WechatCheckinData> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                WechatCheckinData wechatCheckinData = JSON.parseObject(deString, WechatCheckinData.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(wechatCheckinData, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<WechatCheckinData> pageList = wechatCheckinDataService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "企业微信用户列表");
+        mv.addObject(NormalExcelConstants.CLASS, WechatCheckinData.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("企业微信用户列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<WechatCheckinData> listWechatCheckinDatas = ExcelImportUtil.importExcel(file.getInputStream(), WechatCheckinData.class, params);
+                wechatCheckinDataService.saveBatch(listWechatCheckinDatas);
+                return Result.ok("文件导入成功!数据行数:" + listWechatCheckinDatas.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 248 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/controller/WechatUserListController.java

@@ -0,0 +1,248 @@
+package cn.com.ctop.oa.modules.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.oa.modules.entity.WechatUserList;
+import cn.com.ctop.oa.modules.service.IWechatUserListService;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 企业微信用户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-09-15
+ */
+@Slf4j
+@Api(tags = "企业微信用户")
+@RestController
+@RequestMapping("/wechat/wechatUserList")
+public class WechatUserListController {
+    @Autowired
+    private IWechatUserListService wechatUserListService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param wechatUserList
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-分页列表查询")
+    @ApiOperation(value = "企业微信用户-分页列表查询", notes = "企业微信用户-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<WechatUserList>> queryPageList(WechatUserList wechatUserList,
+                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                       HttpServletRequest req) {
+        Result<IPage<WechatUserList>> result = new Result<>();
+        QueryWrapper<WechatUserList> queryWrapper = QueryGenerator.initQueryWrapper(wechatUserList, req.getParameterMap());
+        Page<WechatUserList> page = new Page<WechatUserList>(pageNo, pageSize);
+        IPage<WechatUserList> pageList = wechatUserListService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param wechatUserList
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-添加")
+    @ApiOperation(value = "企业微信用户-添加", notes = "企业微信用户-添加")
+    @PostMapping(value = "/add")
+    public Result<WechatUserList> add(@RequestBody WechatUserList wechatUserList) {
+        Result<WechatUserList> result = new Result<>();
+        try {
+            wechatUserListService.save(wechatUserList);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param wechatUserList
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-编辑")
+    @ApiOperation(value = "企业微信用户-编辑", notes = "企业微信用户-编辑")
+    @PutMapping(value = "/edit")
+    public Result<WechatUserList> edit(@RequestBody WechatUserList wechatUserList) {
+        Result<WechatUserList> result = new Result<WechatUserList>();
+        WechatUserList wechatUserListEntity = wechatUserListService.getById(wechatUserList.getId());
+        if (wechatUserListEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = wechatUserListService.updateById(wechatUserList);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-通过id删除")
+    @ApiOperation(value = "企业微信用户-通过id删除", notes = "企业微信用户-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        try {
+            wechatUserListService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-批量删除")
+    @ApiOperation(value = "企业微信用户-批量删除", notes = "企业微信用户-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<WechatUserList> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<WechatUserList> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.wechatUserListService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "企业微信用户-通过id查询")
+    @ApiOperation(value = "企业微信用户-通过id查询", notes = "企业微信用户-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<WechatUserList> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<WechatUserList> result = new Result<>();
+        WechatUserList wechatUserList = wechatUserListService.getById(id);
+        if (wechatUserList == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(wechatUserList);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<WechatUserList> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                WechatUserList wechatUserList = JSON.parseObject(deString, WechatUserList.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(wechatUserList, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<WechatUserList> pageList = wechatUserListService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "企业微信用户列表");
+        mv.addObject(NormalExcelConstants.CLASS, WechatUserList.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("企业微信用户列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<WechatUserList> listWechatUserLists = ExcelImportUtil.importExcel(file.getInputStream(), WechatUserList.class, params);
+                wechatUserListService.saveBatch(listWechatUserLists);
+                return Result.ok("文件导入成功!数据行数:" + listWechatUserLists.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 134 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/entity/WechatCheckinData.java

@@ -0,0 +1,134 @@
+package cn.com.ctop.oa.modules.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 企业微信用户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-09-15
+ */
+@Data
+@TableName("ctop_wechat_checkin_data")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_wechat_checkin_data对象", description = "企业微信用户")
+public class WechatCheckinData {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.UUID)
+    @ApiModelProperty(value = "id")
+    private String id;
+    /**
+     * 部门id
+     */
+    @Excel(name = "部门id", width = 15)
+    @ApiModelProperty(value = "部门id")
+    private String departId;
+    /**
+     * 用户
+     */
+    @Excel(name = "用户", width = 15)
+    @ApiModelProperty(value = "用户")
+    private String userId;
+    /**
+     * 打开规则名称
+     */
+    @Excel(name = "打开规则名称", width = 15)
+    @ApiModelProperty(value = "打开规则名称")
+    private String groupName;
+    /**
+     * 打卡类型
+     */
+    @Excel(name = "打卡类型", width = 15)
+    @ApiModelProperty(value = "打卡类型")
+    private String checkinType;
+    /**
+     * 异常类型
+     */
+    @Excel(name = "异常类型", width = 15)
+    @ApiModelProperty(value = "异常类型")
+    private String exceptionType;
+    /**
+     * 打卡时间
+     */
+    @ApiModelProperty(value = "打卡时间")
+    private Date checkinTime;
+    /**
+     * 打开地点
+     */
+    @Excel(name = "打开地点", width = 15)
+    @ApiModelProperty(value = "打开地点")
+    private String locationTitle;
+    /**
+     * 打开地点详情
+     */
+    @Excel(name = "打开地点详情", width = 15)
+    @ApiModelProperty(value = "打开地点详情")
+    private String locationDetail;
+    /**
+     * 打卡wifi名称
+     */
+    @Excel(name = "打卡wifi名称", width = 15)
+    @ApiModelProperty(value = "打卡wifi名称")
+    private String wifiname;
+    /**
+     * 打卡备注
+     */
+    @Excel(name = "打卡备注", width = 15)
+    @ApiModelProperty(value = "打卡备注")
+    private String notes;
+    /**
+     * 打卡的MAC地址/bssid
+     */
+    @Excel(name = "打卡的MAC地址/bssid", width = 15)
+    @ApiModelProperty(value = "打卡的MAC地址/bssid")
+    private String wifimac;
+    /**
+     * 打卡的附件media_id
+     */
+    @Excel(name = "打卡的附件media_id", width = 15)
+    @ApiModelProperty(value = "打卡的附件media_id")
+    private String mediaids;
+    /**
+     * 位置打卡地点纬度
+     */
+    @Excel(name = "位置打卡地点纬度", width = 15)
+    @ApiModelProperty(value = "位置打卡地点纬度")
+    private String lat;
+    /**
+     * 位置打卡地点经度
+     */
+    @Excel(name = "位置打卡地点经度", width = 15)
+    @ApiModelProperty(value = "位置打卡地点经度")
+    private String lng;
+    /**
+     * 打卡设备id
+     */
+    @Excel(name = "打卡设备id", width = 15)
+    @ApiModelProperty(value = "打卡设备id")
+    private String deviceid;
+    /**
+     * createTime
+     */
+    @ApiModelProperty(value = "createTime")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+}

+ 63 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/entity/WechatUserList.java

@@ -0,0 +1,63 @@
+package cn.com.ctop.oa.modules.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 企业微信用户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-09-15
+ */
+@Data
+@TableName("ctop_wechat_user_list")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_wechat_user_list对象", description = "企业微信用户")
+public class WechatUserList {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.UUID)
+    @ApiModelProperty(value = "id")
+    private String id;
+    /**
+     * 成员名称
+     */
+    @Excel(name = "成员名称", width = 15)
+    @ApiModelProperty(value = "成员名称")
+    private String userName;
+    /**
+     * 成员id
+     */
+    @Excel(name = "成员id", width = 15)
+    @ApiModelProperty(value = "成员id")
+    private String userId;
+    /**
+     * 部门id
+     */
+    @Excel(name = "部门id", width = 15)
+    @ApiModelProperty(value = "部门id")
+    private String departId;
+    /**
+     * createTime
+     */
+    @ApiModelProperty(value = "createTime")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+}

+ 59 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/enums/DepartEnum.java

@@ -0,0 +1,59 @@
+package cn.com.ctop.oa.modules.enums;
+
+
+import cn.com.ctop.common.module.utils.Check;
+
+public enum DepartEnum {
+
+
+    depart1("快手事业部"),
+    depart2("头条事业部"),
+    depart3("销售部"),
+    depart4("研发中心部"),
+    depart5("内容中心部"),
+    depart6("媒介部"),
+    depart7("渠道部"),
+    depart8("制片部"),
+    depart9("法务部"),
+    depart10("财务部"),
+    depart11("人事行政部");
+
+
+    private String departName;
+
+
+    private DepartEnum(String departName) {
+        this.departName = departName;
+
+    }
+
+    public static Boolean getDepart(String departNameStr) {
+        if (Check.isNull(departNameStr)) {
+            return false;
+        }
+        for (DepartEnum departEnum : DepartEnum.values()) {
+            String departName = departEnum.getDepartName();
+
+            if (departNameStr.equals(departName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    public String getDepartName() {
+        return departName;
+    }
+
+    public void setDepartName(String departName) {
+        this.departName = departName;
+    }
+
+    @Override
+    public String toString() {
+        return "DepartEnum{" +
+                "departName='" + departName + '\'' +
+                '}';
+    }
+}

+ 15 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/WechatCheckinDataMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.oa.modules.mapper;
+
+import cn.com.ctop.oa.modules.entity.WechatCheckinData;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 企业微信用户
+ *
+ * @author: jeecg-boot
+ * @date: 2020-09-15
+ * @cersion: V1.0
+ */
+public interface WechatCheckinDataMapper extends BaseMapper<WechatCheckinData> {
+
+}

+ 15 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/WechatUserListMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.oa.modules.mapper;
+
+import cn.com.ctop.oa.modules.entity.WechatUserList;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 企业微信用户
+ *
+ * @author: jeecg-boot
+ * @date: 2020-09-15
+ * @cersion: V1.0
+ */
+public interface WechatUserListMapper extends BaseMapper<WechatUserList> {
+
+}

+ 5 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/xml/WechatCheckinDataMapper.xml

@@ -0,0 +1,5 @@
+<?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="cn.com.ctop.oa.modules.mapper.WechatCheckinDataMapper">
+
+</mapper>

+ 5 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/mapper/xml/WechatUserListMapper.xml

@@ -0,0 +1,5 @@
+<?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="cn.com.ctop.oa.modules.mapper.WechatUserListMapper">
+
+</mapper>

+ 15 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatCheckinDataService.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.oa.modules.service;
+
+import cn.com.ctop.oa.modules.entity.WechatCheckinData;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 企业微信用户
+ * @Author: jeecg-boot
+ * @Date: 2020-09-15
+ * @Version: V1.0
+ */
+public interface IWechatCheckinDataService extends IService<WechatCheckinData> {
+    void getCheckinData();
+
+}

+ 1 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatTokenService.java

@@ -4,4 +4,5 @@ import java.util.Map;
 
 public interface IWechatTokenService {
     Map<String, Object> getQYWXAccessToken();
+    Map<String, Object> getOAAccessToken();
 }

+ 0 - 4
module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatUserInfoService.java

@@ -1,4 +0,0 @@
-package cn.com.ctop.oa.modules.service;
-
-public interface IWechatUserInfoService {
-}

+ 15 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatUserListService.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.oa.modules.service;
+
+import cn.com.ctop.oa.modules.entity.WechatUserList;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 企业微信用户
+ * @Author: jeecg-boot
+ * @Date: 2020-09-15
+ * @Version: V1.0
+ */
+public interface IWechatUserListService extends IService<WechatUserList> {
+    void getUserList();
+
+}

+ 119 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatCheckinDataServiceImpl.java

@@ -0,0 +1,119 @@
+package cn.com.ctop.oa.modules.service.impl;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.oa.modules.constant.QYWxConstant;
+import cn.com.ctop.oa.modules.entity.WechatCheckinData;
+import cn.com.ctop.oa.modules.entity.WechatUserList;
+import cn.com.ctop.oa.modules.mapper.WechatCheckinDataMapper;
+import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
+import cn.com.ctop.oa.modules.service.IWechatTokenService;
+import cn.com.ctop.oa.modules.service.IWechatUserListService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 企业微信用户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-09-15
+ */
+@Service
+@Slf4j
+public class WechatCheckinDataServiceImpl extends ServiceImpl<WechatCheckinDataMapper, WechatCheckinData> implements IWechatCheckinDataService {
+    @Autowired
+    private IWechatTokenService tokenService;
+    @Autowired
+    private IWechatUserListService userListService;
+
+    @Override
+    public void getCheckinData() {
+        try {
+            Map<String, Object> qywxAccessToken = tokenService.getOAAccessToken();
+            System.err.println(qywxAccessToken);
+            if ((Integer) qywxAccessToken.get("code") != 0) {
+                log.error("企业微信获取token失败,返回信息:{}", qywxAccessToken.get("message"));
+                throw new Exception("企业微信获取token失败");
+            }
+
+            List<WechatUserList> list = userListService.list();
+            if (Check.isNull(list)) {
+                return;
+            }
+
+
+            //  params.put("access_token", (String) qywxAccessToken.get("accessToken"));
+            for (WechatUserList userList : list) {
+                // params.remove("useridlist");
+                JSONObject params = new JSONObject();
+
+                String userId = userList.getUserId();
+                String departId = userList.getDepartId();
+                params.put("opencheckindatatype", 3);
+
+                JSONArray userArr = new JSONArray();
+
+                userArr.add(userId);
+                params.put("useridlist", userArr);
+                params.put("starttime", 1598889600);
+                params.put("endtime", 1600099200);
+
+
+                String resultStr = HttpUtils.httpPostRequestTest(QYWxConstant.QYWX_CHECKIN_DATA + "?access_token=" + qywxAccessToken.get("accessToken"), params.toJSONString(), null);
+                JSONObject resultJson = JSONObject.parseObject(resultStr);
+                System.err.println(resultJson);
+                Integer errcode = resultJson.getInteger("errcode");
+                if (errcode == 0) {
+                    JSONArray checkindata = resultJson.getJSONArray("checkindata");
+                    if (!Check.isNull(checkindata)) {
+                        for (int i = 0; i < checkindata.size(); i++) {
+                            JSONObject jsonObject = checkindata.getJSONObject(i);
+                            if (!Check.isNull(jsonObject)) {
+                                WechatCheckinData checkinData = new WechatCheckinData();
+                                checkinData.setDepartId(departId);
+                                checkinData.setUserId(userId);
+                                java.util.Date checkDate = DateUtils.stampToTime(jsonObject.getLong("checkin_time"));
+                                checkinData.setCheckinTime(checkDate);
+                                checkinData.setWifiname(jsonObject.getString("wifiname"));
+                                checkinData.setNotes(jsonObject.getString("notes"));
+                                checkinData.setLat(jsonObject.getString("lng"));
+                                checkinData.setLocationDetail(jsonObject.getString("location_detail"));
+                                checkinData.setGroupName(jsonObject.getString("groupname"));
+                                checkinData.setDeviceid(jsonObject.getString("deviceid"));
+                                checkinData.setCheckinType(jsonObject.getString("checkin_type"));
+                                checkinData.setExceptionType(jsonObject.getString("exception_type"));
+                                checkinData.setLocationTitle(jsonObject.getString("location_title"));
+                                checkinData.setWifimac(jsonObject.getString("wifimac"));
+                                checkinData.setMediaids(jsonObject.getJSONArray("mediaids").toJSONString());
+                                checkinData.setLat(jsonObject.getString("lat"));
+                                this.save(checkinData);
+
+                            }
+                        }
+
+                    }
+
+
+                } else {
+                    //     throw new Exception("企业微信获取部门列表");
+
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+
+}

+ 10 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatDepartmentServiceImpl.java

@@ -4,6 +4,7 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.oa.modules.constant.QYWxConstant;
 import cn.com.ctop.oa.modules.entity.WechatDepartment;
+import cn.com.ctop.oa.modules.enums.DepartEnum;
 import cn.com.ctop.oa.modules.mapper.WechatDepartmentMapper;
 import cn.com.ctop.oa.modules.service.IWechatDepartmentService;
 import cn.com.ctop.oa.modules.service.IWechatTokenService;
@@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -56,12 +58,20 @@ public class WechatDepartmentServiceImpl extends ServiceImpl<WechatDepartmentMap
                     for (int i = 0; i < department.size(); i++) {
                         JSONObject departJson = department.getJSONObject(i);
                         if (!Check.isNull(departJson)) {
+                            Boolean isTrueOrFalse = DepartEnum.getDepart(departJson.getString("name"));
+                            if (!isTrueOrFalse) {
+                                continue;
+                            }
+                            Map<String, Object> deleteMap = new HashMap<>();
+                            deleteMap.put("depart_name", departJson.getString("name"));
+                            wechatDepartmentMapper.deleteByMap(deleteMap);
                             WechatDepartment depart = new WechatDepartment();
                             depart.setDepartId(departJson.getString("id"));
                             depart.setDepartName(departJson.getString("name"));
                             depart.setParentId(departJson.getString("parentid"));
                             depart.setDepartOrder(departJson.getString("order"));
                             wechatDepartmentMapper.insert(depart);
+
                         }
 
                     }

+ 28 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatTokenServiceImpl.java

@@ -40,4 +40,32 @@ public class WechatTokenServiceImpl implements IWechatTokenService {
         return returnMap;
     }
 
+    public Map<String, Object> getOAAccessToken() {
+        Map<String, Object> returnMap = new HashMap<>();
+
+        try {
+            TreeMap<String, Object> params = new TreeMap<>();
+            params.put("corpid", QYWxConstant.QYWX_CORP_ID);
+            params.put("corpsecret", QYWxConstant.QYWX_OA_CORP_SECRET);
+            String resultStr = HttpUtils.httpGetRequest(QYWxConstant.QYWX_API_URL + QYWxConstant.QYWX_GET_TOKEN, null, params);
+            //System.out.println(resultStr);
+            JSONObject resultJson = JSONObject.parseObject(resultStr);
+            Integer errcode = resultJson.getInteger("errcode");
+            if (errcode == 0) {
+                returnMap.put("code", 0);
+                returnMap.put("accessToken", resultJson.getString("access_token"));
+
+
+            } else {
+                returnMap.put("code", errcode);
+                returnMap.put("message", resultJson.getString("errmsg"));
+            }
+        } catch (Exception e) {
+            returnMap.put("code", -1);
+            returnMap.put("message", "系统错误");
+        }
+
+        return returnMap;
+    }
+
 }

+ 0 - 8
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatUserInfoServiceImpl.java

@@ -1,8 +0,0 @@
-package cn.com.ctop.oa.modules.service.impl;
-
-import cn.com.ctop.oa.modules.service.IWechatUserInfoService;
-import org.springframework.stereotype.Service;
-
-@Service
-public class WechatUserInfoServiceImpl implements IWechatUserInfoService {
-}

+ 98 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatUserListServiceImpl.java

@@ -0,0 +1,98 @@
+package cn.com.ctop.oa.modules.service.impl;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.oa.modules.constant.QYWxConstant;
+import cn.com.ctop.oa.modules.entity.WechatDepartment;
+import cn.com.ctop.oa.modules.entity.WechatUserList;
+import cn.com.ctop.oa.modules.mapper.WechatUserListMapper;
+import cn.com.ctop.oa.modules.service.IWechatDepartmentService;
+import cn.com.ctop.oa.modules.service.IWechatTokenService;
+import cn.com.ctop.oa.modules.service.IWechatUserListService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * 企业微信用户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-09-15
+ */
+@Service
+@Slf4j
+public class WechatUserListServiceImpl extends ServiceImpl<WechatUserListMapper, WechatUserList> implements IWechatUserListService {
+
+    @Autowired
+    private IWechatTokenService tokenService;
+    @Autowired
+    private IWechatDepartmentService departmentService;
+
+    @Override
+    public void getUserList() {
+        try {
+            Map<String, Object> qywxAccessToken = tokenService.getQYWXAccessToken();
+            if ((Integer) qywxAccessToken.get("code") != 0) {
+                log.error("企业微信获取token失败,返回信息:{}", qywxAccessToken.get("message"));
+                throw new Exception("企业微信获取token失败");
+            }
+
+
+            TreeMap<String, Object> params = new TreeMap<>();
+            params.put("access_token", qywxAccessToken.get("accessToken"));
+
+
+            List<WechatDepartment> list = departmentService.list();
+            if (Check.isNull(list)) {
+                return;
+            }
+
+            for (WechatDepartment department : list) {
+                params.remove("department_id");
+                String departId = department.getDepartId();
+                params.put("department_id", departId);
+                String resultStr = HttpUtils.httpGetRequest(QYWxConstant.QYWX_USER_SIMPLELIST, null, params);
+                JSONObject resultJson = JSONObject.parseObject(resultStr);
+                Integer errcode = resultJson.getInteger("errcode");
+                if (errcode == 0) {
+                    JSONArray userlist = resultJson.getJSONArray("userlist");
+                    if (!Check.isNull(userlist)) {
+                        for (int i = 0; i < userlist.size(); i++) {
+                            JSONObject userJson = userlist.getJSONObject(i);
+                            if (!Check.isNull(userJson)) {
+                                String userid = userJson.getString("userid");
+                                String id = departId + "_" + userid;
+                                WechatUserList userList = new WechatUserList();
+                                userList.setId(id);
+                                userList.setDepartId(departId);
+                                userList.setUserId(userid);
+                                userList.setUserName(userJson.getString("name"));
+                                this.saveOrUpdate(userList);
+                            }
+
+                        }
+
+                    }
+
+
+                } else {
+                    throw new Exception("企业微信获取用户列表失败");
+
+                }
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}