소스 검색

Merge branch 'master' of http://47.100.37.243:10080/wutt/manHourHousekeeper

cs 2 년 전
부모
커밋
877b8f58b6

+ 3 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/CompanyController.java

@@ -83,7 +83,7 @@ public class CompanyController {
             HttpRespMsg msg = new HttpRespMsg();
             String token = request.getHeader("TOKEN");
             User user = userMapper.selectById(token);
-            //判断时间
+            /*//判断时间
             long now = System.currentTimeMillis();
             if (syncLog.get(token) == null) {
                 syncLog.put(token, now);
@@ -110,7 +110,7 @@ public class CompanyController {
                         }
                     }
                 }
-            }
+            }*/
 
             Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", user.getCompanyId()));
             Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", company.getId()).eq("is_active",1));
@@ -123,7 +123,7 @@ public class CompanyController {
             if (companyDingding != null) {
                 System.out.println("===========同步钉钉===========");
                 String rest = dingDingService.syncCorpMembs(companyDingding.getCorpid());
-                syncLog.remove(user.getCompanyId()+"_status");
+                /*syncLog.remove(user.getCompanyId()+"_status");*/
                 if (rest.startsWith("调用失败")) {
                     msg.setError(rest);
                 } else {

+ 37 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -55,7 +55,7 @@ public class WeiXinCorpController {
     //获取企业永久授权码
     public static final String GET_CORP_PERMANENT_CODE_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code?suite_access_token=SUITE_ACCESS_TOKEN";
     public static final String GET_CORP_ACCESSTOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token?suite_access_token=SUITE_ACCESS_TOKEN";
-
+    public static final String GET_AUTH_INFO = "https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info?suite_access_token=SUITE_ACCESS_TOKEN";
     //获取成员详情
     public static final String GET_USER_INFO_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID";
     //获取部门列表
@@ -2048,16 +2048,45 @@ public class WeiXinCorpController {
             exception.printStackTrace();
         }
         if (wxCorpInfo.getAuthMode() == 0) {
+            //修正: 获取企业的人员授权范围
+            JSONArray allowUserList = null;
+            JSONArray allowPartyList = null;
+            try {
+                String url = GET_AUTH_INFO.replaceAll("SUITE_ACCESS_TOKEN", getSuiteAccessToken());
+                JSONObject map = new JSONObject();
+                map.put("auth_corpid",wxCorpInfo.getCorpid());
+                map.put("permanent_code",wxCorpInfo.getPermanentCode());
+                HttpHeaders headers = new HttpHeaders();
+                headers.setContentType(MediaType.APPLICATION_JSON);
+                HttpEntity<JSONObject> detailEntity = new HttpEntity<>(map, headers);
+                ResponseEntity<String> detailResponseEntity = restTemplate.postForEntity(url, detailEntity, String.class);
+                JSONObject json = JSONObject.parseObject(detailResponseEntity.getBody());
+                System.out.println("获取企业授权返回:"+json.toJSONString());
+                if (json.containsKey("auth_corp_info")){
+                    JSONArray jsonArray = json.getJSONObject("auth_info").getJSONArray("agent");
+                    for (int i=0;i<jsonArray.size(); i++) {
+                        JSONObject jsonObject = jsonArray.getJSONObject(i);
+                        if (jsonObject.getString("name").equals("工时管家")) {
+                            System.out.println(jsonObject);
+                            JSONObject privilege = jsonObject.getJSONObject("privilege");
+                            allowUserList = privilege.getJSONArray("allow_user");
+                            allowPartyList = privilege.getJSONArray("allow_party");
+                            break;
+                        }
+                    }
+                }
+            } catch (Exception exception) {
+                exception.printStackTrace();
+            }
             //管理员授权模式下,获取部门人员
             int companyRootDeptId = 1;
-            JSONArray usersUnderRootArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
-            System.out.println("获取到公司下的员工数量="+usersUnderRootArray.size());
             SysRole defaultRole = sysRoleMapper.selectOne(
                     new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
             List<User> allCorpWxUserList = new ArrayList<>();
-            for (int m=0;m<usersUnderRootArray.size(); m++) {
-                JSONObject userJson = usersUnderRootArray.getJSONObject(m);
-                System.out.println(userJson.toString());
+            //单独授权的人员,获取人员详情进行处理
+            for (int i=0;i<allowUserList.size(); i++) {
+                String allowUserId = allowUserList.getString(i);
+                JSONObject userJson = getUserInfo(curCorpAccessToken, allowUserId);
                 String curUserid = userJson.getString("userid");
                 String openUserid = userJson.getString("open_userid");
                 //跳过非激活状态的员工
@@ -2067,8 +2096,8 @@ public class WeiXinCorpController {
                 JSONArray userDeptArray = userJson.getJSONArray("department");
                 //取最末级的,也就是最大的deptId
                 int maxDeptId = 1;
-                for (int i=0;i<userDeptArray.size(); i++) {
-                    int curId = userDeptArray.getInteger(i);
+                for (int m=0;m<userDeptArray.size(); m++) {
+                    int curId = userDeptArray.getInteger(m);
                     if (curId > maxDeptId) maxDeptId = curId;
                 }
                 user.setId(SnowFlake.nextId()+"")

+ 34 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DingDingServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -72,6 +73,8 @@ public class DingDingServiceImpl implements DingDingService {
     @Resource
     private SysRoleMapper sysRoleMapper;
     @Resource
+    private HttpServletRequest request;
+    @Resource
     private SysModuleMapper sysModuleMapper;
     @Resource
     private LeaveQuotaNumService leaveQuotaNumService;
@@ -135,6 +138,8 @@ public class DingDingServiceImpl implements DingDingService {
     @Value("${configEnv.isDev}")
     private boolean isDev;//是否是本地开发环境
 
+    public static final HashMap<String, Long> syncLog = new HashMap();
+
     @Override
     public synchronized HttpRespMsg initSystem(String corpid) throws ApiException {
         System.out.println("========接收到initSystem请求===corpid="+corpid);
@@ -351,6 +356,34 @@ public class DingDingServiceImpl implements DingDingService {
     public String syncCorpMembs(String corpid) throws ApiException {
         CompanyDingding dingding = companyDingdingMapper.selectById(corpid);
         String accessToken = null;
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        //判断时间
+        long now = System.currentTimeMillis();
+        if (syncLog.get(token) == null) {
+            syncLog.put(token, now);
+            syncLog.put(user.getCompanyId()+"_status", 1L);
+        } else {
+            if (now - syncLog.get(token) < 30*1000) {
+                //msg.setError("调用过于频繁,请稍后再试");
+                return MessageUtils.message("Company.callError");
+            } else {
+                //检查是否当前公司有同步的正在进行
+                if (syncLog.get(user.getCompanyId()+"_status") == null) {
+                    //没有进行中的任务,更新最近同步的时间
+                    syncLog.put(token, now);
+                    syncLog.put(user.getCompanyId()+"_status", 1L);
+                } else {
+                    if (now - syncLog.get(token) > 0.5*3600*1000) {
+                        //更新最近同步的时间
+                        syncLog.put(token, now);
+                    } else {
+                        //msg.setError("同步正在进行中,请稍后再试");
+                        return MessageUtils.message("Company.synError");
+                    }
+                }
+            }
+        }
         if (dingding == null) {
             System.out.println("corpid不存在=="+corpid);
             return "调用失败:corpid不存在==";
@@ -388,6 +421,7 @@ public class DingDingServiceImpl implements DingDingService {
             System.out.println("syncCorpMembs 开始获取部门, accessToken="+accessToken);
             //获取授权的部门
             getAuthedDeptsAndUsers(dingding, accessToken);
+            syncLog.remove(user.getCompanyId()+"_status");
             return "调用成功";
         }
     }

+ 47 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/TaskProgressServiceImpl.java

@@ -1,11 +1,14 @@
 package com.management.platform.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
 import com.management.platform.service.TaskProgressService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.service.TprogressPaticipatorsService;
+import com.management.platform.service.WxCorpInfoService;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.ListUtil;
 import com.management.platform.util.MessageUtils;
@@ -45,6 +48,10 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
     private ProjectMapper projectMapper;
     @Resource
     private TaskCommentMapper taskCommentMapper;
+    @Resource
+    private WxCorpInfoService wxCorpInfoService;
+    @Resource
+    private WxCorpInfoMapper wxCorpInfoMapper;
     //String[] statusList = new String[]{"状态正常", "存在风险", "进展逾期"};
     @Override
     public HttpRespMsg addProgress(TaskProgress progress, String participatorIds, HttpServletRequest request) {
@@ -77,7 +84,9 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
         String updateStr = creator.getName()+MessageUtils.message("stages.upTask") + status;
         comment.setContent(updateStr);
         taskCommentMapper.insert(comment);
-
+        Task task = taskMapper.selectById(progress.getTaskId());
+        Project project = projectMapper.selectById(task.getProjectId());
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", creator.getCompanyId()));
         if (!StringUtils.isEmpty(participatorIds)) {
             List<String> ids = ListUtil.convertLongIdsArrayToList(participatorIds);
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", ids));
@@ -87,16 +96,50 @@ public class TaskProgressServiceImpl extends ServiceImpl<TaskProgressMapper, Tas
                 item.setUserId(user.getId());
                 item.setUserName(user.getName());
                 tprogressPaticipatorsMapper.insert(item);
-
                 //发消息通知进展
                 Information information = new Information();
-                information.setContent(""+progress.getTaskId());
+                Integer projectId = taskMapper.selectById(progress.getTaskId()).getProjectId();
+                information.setContent(""+projectId);
                 information.setMsg(updateStr);
                 information.setUserId(user.getId());
                 information.setType(2);
                 informationMapper.insert(information);
-
                 //TODO:如果关联了微信或者企业微信,可以推送通知
+                if(user.getCorpwxUserid()!=null){
+                    String corpwxUserid = user.getCorpwxUserid();
+                    //推送到企业微信
+                    JSONObject json=new JSONObject();
+                    JSONArray dataJson=new JSONArray();
+                    JSONObject jsonObj=new JSONObject();
+                    jsonObj.put("key", "项目名称");
+                    jsonObj.put("value",project.getProjectName());
+
+                    JSONObject jsonObj1=new JSONObject();
+                    jsonObj1.put("key", "任务名称");
+                    jsonObj1.put("value",task.getName());
+
+                    JSONObject jsonObj2=new JSONObject();
+                    jsonObj2.put("key", "进展内容");
+                    jsonObj2.put("value",progress.getContent());
+
+                    JSONObject jsonObj3=new JSONObject();
+                    jsonObj3.put("key", "任务状态");
+                    switch (progress.getStatus()){
+                        case 0:jsonObj3.put("value","状态正常");
+                        break;
+                        case 1:jsonObj3.put("value","存在风险");
+                        break;
+                        case 2:jsonObj3.put("value","进展逾期");
+                    }
+                    dataJson.add(jsonObj);
+                    dataJson.add(jsonObj1);
+                    dataJson.add(jsonObj2);
+                    dataJson.add(jsonObj3);
+                    json.put("template_id","tty9TkCAAASja8aiHGlheqEHQ7OIpRyg");
+                    json.put("url","https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww4e237fd6abb635af&redirect_uri=http://worktime.ttkuaiban.com/api/corpWXAuth&response_type=code&scope=snsapi_base&state=0#wechat_redirect");
+                    json.put("content_item",dataJson);
+                    wxCorpInfoService.sendWXCorpTemplateMsg(wxCorpInfo, corpwxUserid, json);
+                }
             }
         }