LG88888888 3 年之前
父節點
當前提交
6901c38134

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IWeixinUserService.java

@@ -25,6 +25,8 @@ public interface IWeixinUserService {
         //u8假期
         Map<String,Object>U8Vacation(String id);
 
+        Map<String,Object>WeixinWork() throws IOException, ParseException;
+
         //同步假期信息到平台
         Map<String ,Object>synchronizationVacation() throws ParseException, IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException;
 

+ 186 - 113
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/WeixinUserImpl.java

@@ -14,10 +14,7 @@ import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.type.TypeReference;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.constant.FillRuleConstant;
-import org.jeecg.common.util.FillRuleUtil;
-import org.jeecg.common.util.RedisUtil;
-import org.jeecg.common.util.SpringContextHolder;
-import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.common.util.*;
 import org.jeecg.modules.geke.attendance.entity.Attendance;
 import org.jeecg.modules.geke.attendance.service.IAttendanceService;
 import org.jeecg.modules.geke.salary.entity.Salary;
@@ -30,15 +27,15 @@ import org.jeecg.modules.openapi4j.service.DepartmentService;
 import org.jeecg.modules.openapi4j.service.PersonService;
 import org.jeecg.modules.openapi4j.service.SalaryService;
 import org.jeecg.modules.openapi4j.util.PropUtil;
-import org.jeecg.modules.system.entity.Datatb;
-import org.jeecg.modules.system.entity.SysDepart;
-import org.jeecg.modules.system.entity.SysUser;
-import org.jeecg.modules.system.entity.SysUserDepart;
+import org.jeecg.modules.system.entity.*;
 import org.jeecg.modules.system.mapper.SysPositionMapper;
 import org.jeecg.modules.system.service.*;
 import org.jeecg.modules.system.util.MyHttpUtils;
 import org.jeecg.modules.system.util.UrlData;
 import org.jeecg.modules.system.vo.*;
+import org.jeecg.modules.workOvertime.entity.workOvertime;
+import org.jeecg.modules.workOvertime.service.IworkOvertimeService;
+import org.jeecg.modules.workOvertime.service.impl.workOvertimeServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -87,11 +84,15 @@ public class WeixinUserImpl implements IWeixinUserService{
     @Autowired
     private  ISysPositionService positionService;
 
+    @Autowired
+    private  IworkOvertimeService iworkOvertimeService;
+
     @Autowired
     private RedisUtil redisUtil;
 
     private DepartmentService departmentService=new DepartmentService();
 
+
     private PersonService personService=new PersonService();
 
     private SalaryService service=new SalaryService();
@@ -161,12 +162,17 @@ public class WeixinUserImpl implements IWeixinUserService{
                     sysUser.setPost(one);
                 }
             }
+            SysUserRole sysUserRole=new SysUserRole();
+            sysUserRole.setUserId(ls.getUserid());
+            sysUserRole.setRoleId("1473241527673765890");
             String userIden = "1";
             if (ls.getIs_leader_in_dept() != null && ls.getIs_leader_in_dept().length > 0) {
                 if (ls.getIs_leader_in_dept()[0].equals("1") || ls.getIs_leader_in_dept()[0] == "1") {
                     userIden = "2";
+                    sysUserRole.setRoleId("1462659329857978370");
                 }
             }
+
             sysUser.setUserIdentity(Integer.parseInt(userIden));
             String[] department = ls.getDepartment();
             if (department.length > 0) {
@@ -179,8 +185,11 @@ public class WeixinUserImpl implements IWeixinUserService{
                     Boolean aBoolean = sysUserDepartService.saveUserDepart(sysUserDepart);
                 }
             }
+            sysUser.setCode(ls.getUserid());
+            sysUser.setUsername(ls.getUserid());
+            sysUser.setWorkNo(ls.getUserid());
             sysUser.setDepartIds(depids);
-            Boolean add = sysUserService.add(sysUser);
+            Boolean add = sysUserService.add(sysUser,sysUserRole);
         }catch (Exception e){
             e.printStackTrace();
             StringWriter sw = new StringWriter();
@@ -431,7 +440,8 @@ public class WeixinUserImpl implements IWeixinUserService{
         Map<String, Object> params = Maps.newHashMap();
         Map<String, Object> headers = Maps.newHashMap();
         ObjectMapper mapper = new ObjectMapper();
-        List<WeixinSign> ls=null;
+        List<List<String>> lists=new ArrayList<>();
+        List<WeixinSign> ls=new ArrayList<>();
         headers.put("Content-Type", "application/json; charset=utf-8");
         Map mapTypes = null;
         String errcode = "";
@@ -441,15 +451,21 @@ public class WeixinUserImpl implements IWeixinUserService{
             params.put("opencheckindatatype", "3");
             params.put("starttime", startDate);
             params.put("endtime", endDate);
-            params.put("useridlist", userIds);
-            String rows = MyHttpUtils.httpPostRequestWithJson(createtUrl, headers, params);
-            mapTypes = JSON.parseObject(rows);
-            errcode = mapTypes.get("errcode").toString();
-            if (errcode.equals("0")) {
-                String checkindata = mapTypes.get("checkindata").toString();//获取考勤结果集的字符串
-                List<WeixinSign> list = mapper.readValue(checkindata, new TypeReference<List<WeixinSign>>() {
-                });
-                ls = list;
+            lists.add(userIds);
+            if (userIds.size()>100){
+                lists= groupList(userIds);
+            }
+            for (List li:lists){
+                params.put("useridlist", li);
+                String rows = MyHttpUtils.httpPostRequestWithJson(createtUrl, headers, params);
+                mapTypes = JSON.parseObject(rows);
+                errcode = mapTypes.get("errcode").toString();
+                if (errcode.equals("0")) {
+                    String checkindata = mapTypes.get("checkindata").toString();//获取考勤结果集的字符串
+                    List<WeixinSign> list = mapper.readValue(checkindata, new TypeReference<List<WeixinSign>>() {
+                    });
+                    ls.addAll(list);
+                }
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -472,7 +488,6 @@ public class WeixinUserImpl implements IWeixinUserService{
         Map<String,Object>map=new HashMap<>();
         UrlData.getToken();
         UrlData.getSignToken();
-        getToaccount();
         String msg="ok";
         Calendar calendar = Calendar.getInstance();//获取系统时间实列
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");//日期格式化
@@ -491,8 +506,6 @@ public class WeixinUserImpl implements IWeixinUserService{
         startDate = stDate.getTime() / 1000;
         endDate = enDate.getTime() / 1000;
         try {
-            UrlData.getSignToken();
-            UrlData.getToken();
             List<String> list = WeixinUserIdList();
             if (list != null && list.size() > 0) {
                 attendanceService.DeleteDateAttendance(sdf.format(stDate), sdf.format(enDate), list);
@@ -545,6 +558,43 @@ public class WeixinUserImpl implements IWeixinUserService{
         return map;
     }
 
+    /**
+     * 加班信息
+     * @return
+     */
+    @Override
+    public Map<String, Object> WeixinWork() throws IOException, ParseException {
+        Map<String,Object>map=new HashMap<>();
+        UrlData.getVacationToken();
+        UrlData.getToken();
+        String msg="ok";
+
+            Calendar calendar = Calendar.getInstance();//获取系统时间实列
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");//日期格式化
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//获取前端传过来的时间获取月份的总天数
+            String sDate = "";
+            String eDate = "";
+            Date stDate = null;
+            Date enDate = null;
+            long startDate;
+            long endDate;
+            sDate = simpleDateFormat.format(new Date()) + "-01 00:00:00";
+            eDate = simpleDateFormat.format(new Date()) + "-" + actualMaximum + " 23:59:59";
+            stDate = sdf.parse(sDate);
+            enDate = sdf.parse(eDate);
+            startDate = stDate.getTime() / 1000;
+            endDate = enDate.getTime() / 1000;
+            List<String> list = WeixinVacationList(String.valueOf(startDate), String.valueOf(endDate),"5");
+            for (String ls:list){//循环审批id
+                workOvertime workOvertime = WeixinWorks(ls);
+                if (workOvertime!=null) {
+                    Boolean aBoolean = iworkOvertimeService.workSave(workOvertime);
+                }
+            }
+        return null;
+    }
+
     /**
      * 获取微信审批实列id
      * @param startDate
@@ -557,7 +607,7 @@ public class WeixinUserImpl implements IWeixinUserService{
         List<String>lt=new ArrayList<>();
         List<Map<String,Object>>ps=new ArrayList<>();
         Map<String,Object>map=new HashMap<>();
-        String cursor="0";
+        int cursor=0;
         headers.put("Content-Type", "application/json; charset=utf-8");
         ObjectMapper mapper = new ObjectMapper();//json转换实列
         Map<String, Object> params = Maps.newHashMap();//企业微信审批号请求的参数集合
@@ -565,7 +615,6 @@ public class WeixinUserImpl implements IWeixinUserService{
             String createUrl = "https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovalinfo?access_token=" + UrlData.VacationToken;//调用企业微信审批号接口
             params.put("starttime", startDate);//开始时间参数
             params.put("endtime", endDate);//结束时间参数
-            params.put("cursor", cursor);//游标,数据超过100条通过返回的next_cursor字段值进行递归拉取
             params.put("size", 100);//获取数据大小最大100
 
             if (type!=null&&!type.equals("")){
@@ -574,15 +623,16 @@ public class WeixinUserImpl implements IWeixinUserService{
                 ps.add(map);
                 params.put("filters", ps);
             }
-            while (!cursor.equals("")&&cursor!=null) {
+            while (cursor!=-1) {
+                params.put("cursor", cursor);//游标,数据超过100条通过返回的next_cursor字段值进行递归拉取
                 String data = MyHttpUtils.httpPostRequestWithJson(createUrl, headers, params);
                 WeixinApp weixinApp = JSONArray.parseObject(data, WeixinApp.class);//json格式转换实体
                 if (weixinApp.getErrcode().equals("0")) {
                     lt.addAll(weixinApp.getSp_no_list());
                     if (weixinApp.getNext_cursor() != null) {
-                        cursor = weixinApp.getNext_cursor();
+                        cursor=Integer.parseInt(weixinApp.getNext_cursor());
                     } else {
-                        cursor = "";
+                        cursor =-1;
                     }
 
                 }
@@ -604,7 +654,7 @@ public class WeixinUserImpl implements IWeixinUserService{
         headers.put("Content-Type", "application/json; charset=utf-8");
         ObjectMapper mapper = new ObjectMapper();//json转换实列
         Map<String, Object> params = Maps.newHashMap();
-        Vacation vacation=new Vacation();
+        Vacation vacation=null;
         String errcode = "";
         Map mapTypes = null;
         try {
@@ -615,12 +665,14 @@ public class WeixinUserImpl implements IWeixinUserService{
             errcode = mapTypes.get("errcode").toString();//获取接口返回的状态码
             if (errcode.equals("0")) {//判断接口是否请求成功
                 WeixinApproval weixinApproval = JSONArray.parseObject(mapTypes.get("info").toString(), WeixinApproval.class);//字符串转实体类
-                if (weixinApproval != null) {//获取数据库字段所需的数据
+                if (weixinApproval != null&&weixinApproval.getSp_status().equals("2")) {//获取数据库字段所需的数据
+                    vacation=new Vacation();
                     vacation.setId(weixinApproval.getSp_no());
                     vacation.setState(weixinApproval.getSp_status());
                     String us = weixinApproval.getApplyer().toString();
                     mapTypes = JSON.parseObject(us);
                     vacation.setUserId(mapTypes.get("userid").toString());
+                    vacation.setUserDate(new Date(Long.parseLong(weixinApproval.getApply_time())*1000));
                     List<Object> apply_data = weixinApproval.getApply_data();
                     String o = apply_data.get(0).toString();
                     mapTypes = JSON.parseObject(o);
@@ -665,6 +717,74 @@ public class WeixinUserImpl implements IWeixinUserService{
         }
         return vacation;
     }
+
+
+    /**
+     * 获取微信审批实列-加班信息
+     * @param ls
+     * @return
+     * @throws IOException
+     */
+    public workOvertime WeixinWorks(String ls) throws IOException {
+        Map<String, Object> headers = Maps.newHashMap();//请求头集合
+        headers.put("Content-Type", "application/json; charset=utf-8");
+        ObjectMapper mapper = new ObjectMapper();//json转换实列
+        Map<String, Object> params = Maps.newHashMap();
+        workOvertime work=null;
+        String errcode = "";
+        Map mapTypes = null;
+        try {
+            String createUrl = "https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovaldetail?access_token=" + UrlData.VacationToken;//调用企业微信审批详情接口
+            params.put("sp_no", ls);//审批id参数
+            String res = MyHttpUtils.httpPostRequestWithJson(createUrl, headers, params);//发送请求
+            mapTypes = JSON.parseObject(res);//json格式转换为map集合
+            errcode = mapTypes.get("errcode").toString();//获取接口返回的状态码
+            if (errcode.equals("0")) {//判断接口是否请求成功
+                WeixinApproval weixinApproval = JSONArray.parseObject(mapTypes.get("info").toString(), WeixinApproval.class);//字符串转实体类
+                if (weixinApproval != null&&weixinApproval.getSp_status().equals("2")) {//获取数据库字段所需的数据
+                    work=new workOvertime();
+                    work.setCode(weixinApproval.getSp_no());
+                    String us = weixinApproval.getApplyer().toString();
+                    mapTypes = JSON.parseObject(us);
+                    work.setPerson(mapTypes.get("userid").toString());
+                   work.setDept(mapTypes.get("partyid").toString());
+                   work.setCommitDate(new Date(Long.valueOf(weixinApproval.getApply_time()) * 1000));
+                    List<Object> apply_data = weixinApproval.getApply_data();
+                    String o = apply_data.get(0).toString();
+                    mapTypes = JSON.parseObject(o);
+                    String contents = mapTypes.get("contents").toString();
+                    List<Map<String, Object>> tl = mapper.readValue(contents, new TypeReference<List<Map<String, Object>>>() {
+                    });
+                    Map value = null;
+                    Map types = null;
+                    for (Map ll : tl) {
+                        Object s = ll.get("control");
+                        if (s.equals("Attendance")) {
+                            value = (Map) ll.get("value");
+                            value = (Map) value.get("attendance");
+                            value = (Map) value.get("date_range");
+                            long lt = new Long(value.get("new_begin").toString());
+                            Date beginDate = new Date(lt * 1000);
+                            long ltt = new Long(value.get("new_end").toString());
+                            Date EndDate = new Date(ltt * 1000);
+                            //计算天数
+                            long countD = new Long(value.get("new_duration").toString());
+                            long countDa = countD / 3600;
+                            work.setBeginDate(beginDate);
+                            work.setEndDate(EndDate);
+                            work.setDuration(String.valueOf(countDa));
+                        }else if (s.equals("Textarea")){
+                            value = (Map) ll.get("value");
+                            work.setDemo(value.get("text").toString());
+                        }
+                    }
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return work;
+    }
     @Override
     public Map<String, Object> synchronizationVacation() throws ParseException, IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
       Map<String,Object>map=new HashMap<>();
@@ -675,7 +795,6 @@ public class WeixinUserImpl implements IWeixinUserService{
             Calendar calendar = Calendar.getInstance();//获取系统时间实列
             SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");//日期格式化
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            //calendar.setTime(simpleDateFormat.parse(date));
             int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//获取前端传过来的时间获取月份的总天数
             String sDate = "";
             String eDate = "";
@@ -693,7 +812,9 @@ public class WeixinUserImpl implements IWeixinUserService{
             List<String> list = WeixinVacationList(String.valueOf(startDate), String.valueOf(endDate),"1");
                     for (String ls:list){//循环审批id
                         Vacation vacation = WeixinVacationdetail(ls);
-                       Boolean t= vacationService.saveVacation(vacation);
+                        if (vacation!=null) {
+                            Boolean t = vacationService.saveVacation(vacation);
+                        }
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -722,57 +843,26 @@ public class WeixinUserImpl implements IWeixinUserService{
      */
     @Override
     public Map<String, Object> WeiXinToU8ByDept() throws IOException, OpenAPIException {
-        Map<String, Object> map = WeixinDept();
-        UrlData.getToken();
+        getToaccount();
         Map<String, Object> parm =new HashMap<>();
         Map<String,Object>pt=new HashMap<>();
         Map<String,Object>maps=new HashMap<>();
-        ObjectMapper mapper = new ObjectMapper();
-        String code="06";
-        String cods="";
         String msg="ok";
-        if (map.get("code").equals("0")) {
-            Object deptlist = map.get("deptlist");
-            List<WeixinDepart> list = mapper.readValue(deptlist.toString(), new TypeReference<List<WeixinDepart>>() {
-            });//将部门字符串转换为集合
-            for (WeixinDepart ls : list) {
-                if (!ls.getParentid().equals("0")){
-                    if (ls.getParentid().equals("1")){
-                         cods=code+ls.getId();
-                         for (WeixinDepart l:list){
-                             if (l.getParentid().equals(ls.getId())){
-                                 l.setName_en(code+ls.getId());
-                             }
-                         }
-                    }else {
-                        if (Integer.parseInt(ls.getId())<10){
-                            cods=ls.getName_en()+"0"+ls.getId();
-                            for (WeixinDepart l:list){
-                                if (l.getParentid().equals(ls.getId())){
-                                    l.setName_en(ls.getName_en()+"0"+ls.getId());
-                                }
-                            }
-                        }else {
-                            cods=ls.getName_en()+ls.getId();
-                            for (WeixinDepart l:list){
-                                if (l.getParentid().equals(ls.getId())){
-                                    l.setName_en(ls.getName_en()+ls.getId());
-                                }
-                            }
-                        }
-                    }
-                    parm.put("code",cods);
-                    parm.put("name",ls.getName());
-                    pt.put("department",parm);
-                    String s = JSONObject.toJSONString(pt);
+        List<SysDepart> sysDeparts = sysDepartService.listDept();
+        if (sysDeparts!=null&&sysDeparts.size()>0){
+            for (SysDepart depart:sysDeparts){
+                parm.put("code",depart.getOrgCode());
+                parm.put("name",depart.getDepartName());
+                pt.put("department",parm);
+                String s = JSONObject.toJSONString(pt);
                     String s1 = DepartAdd(s);
                     if (!s1.equals("0")){
                         msg=s1;
                     }
-                }
-                System.out.println("编码:"+cods+"名称:"+ls.getName());
+                System.out.println("编码:"+depart.getOrgCode()+"名称:"+depart.getDepartName());
             }
         }
+
         maps.put("msg",msg);
         return maps;
     }
@@ -812,55 +902,24 @@ public class WeixinUserImpl implements IWeixinUserService{
      */
     @Override
     public Map<String, Object> WeixinToU8ByUser() throws OpenAPIException {
-        String code="06";
-        String codes="";
         String msg="ok";
+        getToaccount();
         Map<String, Object> maps = new HashMap<>();
         List<SysUser> list = sysUserService.list();
-        List<SysDepart> deps = sysDepartService.list();
         if (list.size() > 0) {
-            for (SysDepart d : deps) {
-                if (!d.getParentId().equals("0")){
-                    if (d.getParentId().equals("1")){
-                        d.setDelFlag(code+d.getId());
-                        for (SysDepart l:deps){
-                            if (l.getParentId().equals(d.getId())){
-                                l.setDelFlag(code+d.getId());
-                            }
-                        }
-                    }else {
-                        if (Integer.parseInt(d.getId())<10){
-                            d.setDelFlag(d.getDelFlag()+"0"+d.getId());
-                            for (SysDepart l:deps){
-                                if (l.getParentId().equals(d.getId())){
-                                    l.setDelFlag(d.getDelFlag()+"0"+d.getId());
-                                }
-                            }
-                        }else {
-                            d.setDelFlag(d.getDelFlag()+d.getId());
-                            for (SysDepart l:deps){
-                                if (l.getParentId().equals(d.getId())){
-                                    l.setDelFlag(d.getDelFlag()+d.getId());
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
             for (SysUser ls : list) {
                 Map<String, Object> map = new HashMap<>();
                 Map<String, Object> parm = new HashMap<>();
                 List<SysDepart> sysDeparts = sysDepartService.queryUserDeparts(ls.getId());
-                map.put("code", ls.getCode());
-                map.put("name", ls.getRealname());
-                    for (SysDepart l : deps) {
-                        if (l.getId().equals(sysDeparts.get(0).getId())){
-                            codes=l.getDelFlag();
-                        }
+                for (SysDepart depart:sysDeparts){
+                    if (!depart.getId().equals("1")){
+                        map.put("cdept_num",depart.getOrgCode());
+                        map.put("cdept_name", depart.getDepartName());
+                        break;
                     }
-                    map.put("cdept_num", codes);
-                    map.put("cdept_name", sysDeparts.get(0).getDepartName());
+                }
+                map.put("code", ls.getWorkNo());
+                map.put("name", ls.getRealname());
                     map.put("rsex", ls.getSex());
                     map.put("cpsnmobilephone", ls.getPhone());
                     map.put("cpsnemail", ls.getEmail());
@@ -890,6 +949,7 @@ public class WeixinUserImpl implements IWeixinUserService{
     public Map<String, Object> WeixinToPtByDept() throws OpenAPIException, IOException {
         Map<String,Object>maps=new HashMap<>();
         String msg="ok";
+        UrlData.getToken();
         try {
             ObjectMapper mapper = new ObjectMapper();
             Map<String, Object> map = WeixinDept();
@@ -1055,6 +1115,19 @@ public class WeixinUserImpl implements IWeixinUserService{
         getToaccount= prop.getProperty("to_account");
 
     }
-
+    public static List<List<String>> groupList(List<String> list) {
+        List<List<String>> listGroup = new ArrayList<List<String>>();
+        int listSize = list.size();
+        //子集合的长度
+        int toIndex = 100;
+        for (int i = 0; i < list.size(); i += 100) {
+            if (i + 100 > listSize) {
+                toIndex = listSize - i;
+            }
+            List<String> newList = list.subList(i, i + toIndex);
+            listGroup.add(newList);
+        }
+        return listGroup;
+    }
 }
 

+ 9 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/vo/WeixinUser.java

@@ -31,8 +31,17 @@ public class WeixinUser<extattr> {
     private  String []external_attr;
     private  String external_corp_name;
     private  String open_userid;
+    private  String external_position;
     private List<Object> direct_leader=new ArrayList<>();
 
+    public String getExternal_position() {
+        return external_position;
+    }
+
+    public void setExternal_position(String external_position) {
+        this.external_position = external_position;
+    }
+
     public List<Object> getDirect_leader() {
         return direct_leader;
     }