From 22a2b16cb7b2803f2c4dbbd4c871ae3ee5131b4a Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Wed, 6 Jan 2021 18:04:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lz/config/ShiroConfig.java | 1 + .../app/controller/DingDingController.java | 125 ++++++++++++++ .../app/controller/TestController.java | 163 +++++++++--------- 3 files changed, 211 insertions(+), 78 deletions(-) create mode 100644 src/main/java/com/lz/modules/app/controller/DingDingController.java diff --git a/src/main/java/com/lz/config/ShiroConfig.java b/src/main/java/com/lz/config/ShiroConfig.java index dda98d86..eb62fd20 100644 --- a/src/main/java/com/lz/config/ShiroConfig.java +++ b/src/main/java/com/lz/config/ShiroConfig.java @@ -52,6 +52,7 @@ public class ShiroConfig { Map filterMap = new LinkedHashMap<>(); filterMap.put("/webjars/**", "anon"); filterMap.put("/oneCode/**", "anon"); + filterMap.put("/dingding/**", "anon"); filterMap.put("/file/**", "anon"); filterMap.put("/test/**", "anon"); filterMap.put("/druid/**", "anon"); diff --git a/src/main/java/com/lz/modules/app/controller/DingDingController.java b/src/main/java/com/lz/modules/app/controller/DingDingController.java new file mode 100644 index 00000000..c462f300 --- /dev/null +++ b/src/main/java/com/lz/modules/app/controller/DingDingController.java @@ -0,0 +1,125 @@ +package com.lz.modules.app.controller; + + +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request; +import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response; +import com.lz.common.utils.DingTalkUtil; +import com.lz.common.utils.R; +import com.lz.common.utils.StringUtil; +import com.lz.modules.app.entity.StaffEntity; +import com.lz.modules.app.service.StaffService; +import com.lz.modules.third.entity.ThirdAppConfig; +import com.lz.modules.third.service.ThirdAppConfigService; +import com.taobao.api.ApiException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.net.URLEncoder; + +@RestController +@Slf4j +@RequestMapping("/dingding") +public class DingDingController { + + + @Autowired + private ThirdAppConfigService thirdAppConfigService; + + @Autowired + private DingTalkUtil dingTalkUtil; + + @Autowired + private StaffService staffService; + + + static String homeUrl = "https://lzmanagement.ldxinyong.com/digitization"; + + //http://localhost:8080/lz_management/dingding/msg?username=18458195149&title=%E8%AF%B7%E6%B3%A8%E6%84%8F&content=%E9%A1%B9%E7%9B%AE%E8%A6%81%E8%BF%87%E6%9C%9F%E4%BA%86 + @RequestMapping("/msg") + public R dingdingxiaoxi(String username, String title, String content) { + String appid = "856016278"; + StaffEntity staffEntity = staffService.selectByPhone(username); + ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid); + String token = dingTalkUtil.getAccessTokenWitchEntity(thirdAppConfig); + String url = homeUrl; + if (url.contains("?")) { + url += "&halokit=" + System.currentTimeMillis(); + } else { + url += "?halokit=" + System.currentTimeMillis(); + } + url += "&detail=1&id=1&detailId=" + 1; + url = URLEncoder.encode(url); + + url = "dingtalk://dingtalkclient/action/openapp?corpid=" + thirdAppConfig.getCorpId() + + "&container_type=work_platform&app_id=0_" + + appid + "&redirect_type=jump&redirect_url=" + url; + try { + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"); + OapiMessageCorpconversationAsyncsendV2Request req = new OapiMessageCorpconversationAsyncsendV2Request(); + req.setAgentId(Long.parseLong(appid)); + req.setUseridList(staffEntity.getEmployeeId());//员工 id + OapiMessageCorpconversationAsyncsendV2Request.Msg obj1 = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); + obj1.setMsgtype("action_card"); + OapiMessageCorpconversationAsyncsendV2Request.ActionCard obj2 = new OapiMessageCorpconversationAsyncsendV2Request.ActionCard(); + obj2.setSingleTitle(title); + obj2.setSingleUrl(url); + obj2.setMarkdown( + getMarkDown(content) + ); + obj2.setTitle(title); + obj1.setActionCard(obj2); + req.setMsg(obj1); + OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(req, token); + log.info("钉钉请求返回{}", rsp.getBody()); + //插入数据库 + } catch (ApiException e) { + e.printStackTrace(); + return R.error("抛出异常"); + } + return R.ok(); + } + + + public static String getMarkDown(String content) { + StringBuilder sb = new StringBuilder(); + char[] cs = content.toCharArray(); + int i = 0; + int j = 0; + for (char c : cs) { + if (i == 0) { + if (c == '/') { + sb.append("#"); + } else { + sb.append("# ").append(c); + } + } else { + if (c == '/') { + if (j == 0) { + sb.append("\n"); + } + j++; + sb.append("#"); + continue; + } else { + j = 0; + String xx = sb.toString(); + if(StringUtil.isNotBlank(xx)){ + char [] yy = xx.toCharArray(); + if(yy[yy.length -1 ] == '#'){ + sb.append(" "); + } + } + sb.append(c); + } + } + i++; + } + log.info(" getmarkdown :" + sb.toString()); + return sb.toString(); + } + +} diff --git a/src/main/java/com/lz/modules/app/controller/TestController.java b/src/main/java/com/lz/modules/app/controller/TestController.java index cd3f6a0a..5fbdb4d2 100644 --- a/src/main/java/com/lz/modules/app/controller/TestController.java +++ b/src/main/java/com/lz/modules/app/controller/TestController.java @@ -3,6 +3,11 @@ package com.lz.modules.app.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request; +import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response; +import com.lz.common.utils.DingTalkUtil; import com.lz.common.utils.NumberUtil; import com.lz.common.utils.R; import com.lz.modules.app.dto.ApprovalDto; @@ -29,6 +34,9 @@ import com.lz.modules.sys.entity.app.ResultRecord; import com.lz.modules.sys.service.SysUserService; import com.lz.modules.sys.service.app.ResultDetailService; import com.lz.modules.sys.service.app.ResultRecordService; +import com.lz.modules.third.entity.ThirdAppConfig; +import com.lz.modules.third.service.ThirdAppConfigService; +import com.taobao.api.ApiException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; +import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -73,7 +82,7 @@ public class TestController { private IEquipmentInfoService equipmentInfoService; @RequestMapping("/test/xx") - public void test(){ + public void test() { ResultRecord resultRecord = new ResultRecord(); resultRecord.setAllScore(new BigDecimal(10)); resultRecord.setLastScore(new BigDecimal(8)); @@ -83,21 +92,21 @@ public class TestController { @RequestMapping("/test/department") - public void department(){ + public void department() { List departmentsEntityList = departmentsService.selectEntityByParentDepartmentId("0"); - for(DepartmentsEntity child1:departmentsEntityList){ + for (DepartmentsEntity child1 : departmentsEntityList) { child1.setLevel(1); departmentsService.updateById(child1); List departmentsEntityList2 = departmentsService.selectEntityByParentDepartmentId(child1.getDepartmentId()); - for(DepartmentsEntity child2: departmentsEntityList2){ + for (DepartmentsEntity child2 : departmentsEntityList2) { child2.setLevel(2); departmentsService.updateById(child2); List departmentsEntityList3 = departmentsService.selectEntityByParentDepartmentId(child2.getDepartmentId()); - for(DepartmentsEntity child3: departmentsEntityList3){ + for (DepartmentsEntity child3 : departmentsEntityList3) { child3.setLevel(3); departmentsService.updateById(child3); List departmentsEntityList4 = departmentsService.selectEntityByParentDepartmentId(child3.getDepartmentId()); - for(DepartmentsEntity child4: departmentsEntityList4){ + for (DepartmentsEntity child4 : departmentsEntityList4) { child4.setLevel(4); departmentsService.updateById(child4); } @@ -107,9 +116,9 @@ public class TestController { } @RequestMapping("/test/relate") - public void relate(){ + public void relate() { List list = departmentsStaffRelateService.selectAll(); - for(DepartmentsStaffRelateEntity l:list){ + for (DepartmentsStaffRelateEntity l : list) { DepartmentsEntity departmentsEntity = departmentsService.selectByDepartmentId(l.getDepartmentId()); l.setLevel(departmentsEntity.getLevel()); departmentsStaffRelateService.updateById(l); @@ -118,36 +127,36 @@ public class TestController { /** * { - * "type": "node", - * "left": 818, - * "top": 510, - * "uuid": "id3", - * "prev": [ - * "id1", - * "id2" - * ], - * "next": [ - * "id4", - * "id5" - * ], - * "formData": { - * "stepName": "名称1", - * "ruleGroupList": [{ - * "name": "名称2", - * "nextStep": "id5" - * }, - * { - * "name": "名称6", - * "nextStep": "id7" - * } - * ] - * }, - * "nextIfId": "id12", - * "nextElseId": "id11" + * "type": "node", + * "left": 818, + * "top": 510, + * "uuid": "id3", + * "prev": [ + * "id1", + * "id2" + * ], + * "next": [ + * "id4", + * "id5" + * ], + * "formData": { + * "stepName": "名称1", + * "ruleGroupList": [{ + * "name": "名称2", + * "nextStep": "id5" + * }, + * { + * "name": "名称6", + * "nextStep": "id7" + * } + * ] + * }, + * "nextIfId": "id12", + * "nextElseId": "id11" * } */ @RequestMapping("/test/step") - public void step(){ + public void step() { Long staffId = 294l; ResultRecord resultRecord = new ResultRecord(); resultRecord.setType(2); @@ -156,13 +165,13 @@ public class TestController { resultRecord.setDepartmentId(departmentsStaffRelateEntity.getDepartmentId()); List test = resultDetailService.getStepList(resultRecord); List list = new ArrayList<>(); - if(CollectionUtils.isNotEmpty(test)){ + if (CollectionUtils.isNotEmpty(test)) { Step step = test.get(0); StaffEntity staffEntity = staffService.selectStaffById(staffId); - if(staffEntity !=null && !staffEntity.getName().equals(step.getName())){ + if (staffEntity != null && !staffEntity.getName().equals(step.getName())) { list.add(staffEntity.getName()); } - for(Step s:test){ + for (Step s : test) { list.add(s.getName()); } } @@ -170,33 +179,32 @@ public class TestController { List flowModels = new ArrayList<>(); FlowModel flowModel = new FlowModel(); - for(String s:list){ + for (String s : list) { } } - @RequestMapping("/test/userinfo") - public void userinfo(){ + public void userinfo() { } @RequestMapping("/test/init") - public void testinit(){ + public void testinit() { List allDeparmentIds = staffService.selectAllDeparmentIdsByDepartmentParentId("1"); //获取部门下所有人员 List staffIds = staffService.staffsByAllDeparmentIds(allDeparmentIds); - List collect=resultRecordService.listObjs(new QueryWrapper() - .eq("is_delete", 0) + List collect = resultRecordService.listObjs(new QueryWrapper() + .eq("is_delete", 0) .eq("type", 2) - .like("month_time","2020-09") - .in("department_id",allDeparmentIds) - .in("staff_id",staffIds) + .like("month_time", "2020-09") + .in("department_id", allDeparmentIds) + .in("staff_id", staffIds) .select(" DISTINCT staff_id")); List collect1 = new ArrayList<>(); - if(CollectionUtils.isNotEmpty(collect)){ + if (CollectionUtils.isNotEmpty(collect)) { collect1 = collect.stream().map(o -> o.toString()).collect(Collectors.toList()); System.out.println(); } @@ -204,12 +212,11 @@ public class TestController { } - // http://localhost:8080/lz_management/test/restore @RequestMapping("/test/restore") - public void restore() throws Exception{ + public void restore() throws Exception { List staffEntities = staffService.selectAll(); - for(StaffEntity staffEntity:staffEntities){ + for (StaffEntity staffEntity : staffEntities) { //doRestore(staffEntity.getId()); } } @@ -221,36 +228,36 @@ public class TestController { StaffEntity staff = staffService.selectStaffById(staffId); List resultRecords = resultRecordService.selectResultRecordAllByStaffId(staffId); Date node = sdf.parse("2020-09-29 19:08:07"); - if(resultRecords== null || resultRecords.size() == 0){ + if (resultRecords == null || resultRecords.size() == 0) { log.info("staffid = " + staffId + " ,没有数据"); return; } boolean flag = true; - for(ResultRecord resultRecord:resultRecords){ - if(resultRecord.getGmtCreate().getTime() > node.getTime()){ - List resultDetails = resultDetailService.selectByRecordIdAndType(resultRecord.getId(),1); - if(resultDetails !=null && resultDetails.size() > 0){ + for (ResultRecord resultRecord : resultRecords) { + if (resultRecord.getGmtCreate().getTime() > node.getTime()) { + List resultDetails = resultDetailService.selectByRecordIdAndType(resultRecord.getId(), 1); + if (resultDetails != null && resultDetails.size() > 0) { flag = false; - log.info("staff_id " + staff.getId() + ",name = " + staff.getName() + " ,己经正常"); - return ; + log.info("staff_id " + staff.getId() + ",name = " + staff.getName() + " ,己经正常"); + return; } } } - if(flag){ - for(ResultRecord resultRecord:resultRecords){ - if(resultRecord.getGmtCreate().getTime() > node.getTime()){ + if (flag) { + for (ResultRecord resultRecord : resultRecords) { + if (resultRecord.getGmtCreate().getTime() > node.getTime()) { resultRecord.setIsDelete(1); - log.info("staff_id " + staff.getId() + ",name = " + staff.getName() + " ,删除不要数据"); + log.info("staff_id " + staff.getId() + ",name = " + staff.getName() + " ,删除不要数据"); resultRecordService.updateResultRecordById(resultRecord); } } - for(int i = resultRecords.size() - 1 ;i >= 0 ; i --){ + for (int i = resultRecords.size() - 1; i >= 0; i--) { ResultRecord resultRecord = resultRecords.get(i); - if(resultRecord.getGmtCreate().getTime() < node.getTime()){ - List resultDetails = resultDetailService.selectByRecordIdAndType(resultRecord.getId(),1); - if(resultDetails !=null && resultDetails.size() > 0){ + if (resultRecord.getGmtCreate().getTime() < node.getTime()) { + List resultDetails = resultDetailService.selectByRecordIdAndType(resultRecord.getId(), 1); + if (resultDetails != null && resultDetails.size() > 0) { resultRecord.setIsDelete(0); - log.info("staff_id " + staff.getId() + ",name = " + staff.getName() + " ,数据恢复"); + log.info("staff_id " + staff.getId() + ",name = " + staff.getName() + " ,数据恢复"); resultRecordService.updateResultRecordById(resultRecord); break; } @@ -261,15 +268,15 @@ public class TestController { // http://localhost:8080/lz_management/test/resultrecord?resultRecordId=475 @RequestMapping("/test/resultrecord") - public void resultRecorcd(Long resultRecordId) throws Exception{ + public void resultRecorcd(Long resultRecordId) throws Exception { R r = resultRecordService.initFlowRecord(resultRecordId); } // http://localhost:8080/lz_management/test/getAuth?userId=298 @RequestMapping("/test/getAuth") - public R getAuth(Long userId) throws Exception{ - Map map = staffRoleService.getRoleByUserId(userId); - return R.ok().put("data",map); + public R getAuth(Long userId) throws Exception { + Map map = staffRoleService.getRoleByUserId(userId); + return R.ok().put("data", map); } @Autowired @@ -277,7 +284,7 @@ public class TestController { // http://localhost:8080/lz_management/test/testmaster @RequestMapping("/test/testmaster") - public R testmaster(Long userId) throws Exception{ + public R testmaster(Long userId) throws Exception { List masterPMs = staffRoleMapper.selectStaffRolesByDepartmentLevelList(Arrays.asList(new String[]{RoleEnums.MASTER_PM.getName()})); @@ -287,11 +294,11 @@ public class TestController { public static void main(String[] args) { String a = "{\"313\":[17,20,13]}"; - Map map = JSONObject.parseObject(a,Map.class); + Map map = JSONObject.parseObject(a, Map.class); List roleIds = null; for (Map.Entry entry : map.entrySet()) { - if(entry.getValue() !=null ){ - roleIds = JSON.parseArray(entry.getValue().toString(),Long.class); + if (entry.getValue() != null) { + roleIds = JSON.parseArray(entry.getValue().toString(), Long.class); } } System.out.println(roleIds); @@ -334,10 +341,10 @@ public class TestController { public R equpinfo() { List equipmentInfos = equipmentInfoService.selectAll(); - for(EquipmentInfo equipmentInfo : equipmentInfos){ + for (EquipmentInfo equipmentInfo : equipmentInfos) { DepartmentsStaffRelateEntity departmentsStaffRelateEntity = departmentsStaffRelateService.selectByStaffId(equipmentInfo.getUserId()); - if(departmentsStaffRelateEntity !=null){ - equipmentInfo.setDepartId(NumberUtil.objToLongDefault(departmentsStaffRelateEntity.getDepartmentId(),-1)); + if (departmentsStaffRelateEntity != null) { + equipmentInfo.setDepartId(NumberUtil.objToLongDefault(departmentsStaffRelateEntity.getDepartmentId(), -1)); } equipmentInfoService.updateCoverEquipmentInfoById(equipmentInfo); }