From 91b4ea8c01a654c2418c992d195323c4c0875b23 Mon Sep 17 00:00:00 2001 From: erdanergou Date: Fri, 11 Nov 2022 10:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../depository_manage/config/PortConfig.java | 13 + .../ApprovalTemplate.java | 56 ++++ .../Approval_template_apply_data.java | 17 ++ ...Approval_template_apply_data_contents.java | 25 ++ .../Approval_template_approver.java | 24 ++ .../Approval_template_summary_info.java | 18 ++ .../config/WebMvcConfig.java | 2 +- .../DepositoryRecordController.java | 38 ++- .../controller/PageController.java | 6 +- .../intercepter/UserInterceptor.java | 3 + .../service/impl/QyWxOperationService.java | 89 ++++++ src/main/resources/templates/index.html | 4 +- .../pages/application/application-out.html | 267 +++++++++++------- .../dreamchaser/depository_manage/Test.java | 10 +- 14 files changed, 448 insertions(+), 124 deletions(-) create mode 100644 src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/ApprovalTemplate.java create mode 100644 src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data.java create mode 100644 src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data_contents.java create mode 100644 src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_approver.java create mode 100644 src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_summary_info.java diff --git a/src/main/java/com/dreamchaser/depository_manage/config/PortConfig.java b/src/main/java/com/dreamchaser/depository_manage/config/PortConfig.java index 25c93712..b9dbe1f7 100644 --- a/src/main/java/com/dreamchaser/depository_manage/config/PortConfig.java +++ b/src/main/java/com/dreamchaser/depository_manage/config/PortConfig.java @@ -109,4 +109,17 @@ public class PortConfig { e.printStackTrace(); } } + + // 获取当前登录用户所在部门的企业微信id + public static JSONObject getUserPortByQyWx(Integer mainPortId){ + String url = external_url+"/org/getgovcont"; + Map map = new HashMap<>(); + map.put("id",mainPortId); + map.put("idstr",String.valueOf(mainPortId)); + String jsonString = JSONObject.toJSONString(map); + String s = HttpUtils.doPost(url, jsonString); + JSONObject jsonObject = JSONObject.parseObject(s); + JSONObject data = jsonObject.getJSONObject("data"); + return data; + } } diff --git a/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/ApprovalTemplate.java b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/ApprovalTemplate.java new file mode 100644 index 00000000..4a0e157e --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/ApprovalTemplate.java @@ -0,0 +1,56 @@ +package com.dreamchaser.depository_manage.config.QyWx_approval_template; + +import lombok.Data; + +import java.util.List; + + +/** + * 用于审批模板的创建 + */ +@Data +public class ApprovalTemplate { + + /** + * 申请人userid,此审批申请将以此员工身份提交,申请人需在应用可见范围内 + */ + private String creator_userid; + + /** + * 模板id。可在“获取审批申请详情”、“审批状态变化回调通知”中获得,也可在审批模板的模板编辑页面链接中获得。暂不支持通过接口提交[打卡补卡][调班]模板审批单。 + */ + private String template_id; + + /** + * 审批人模式:0-通过接口指定审批人、抄送人(此时approver、notifyer等参数可用); 1-使用此模板在管理后台设置的审批流程(需要保证审批流程中没有“申请人自选”节点),支持条件审批。默认为0 + */ + private int use_template_approver; + + /** + * 提单者提单部门id,不填默认为主部门 + */ + private int choose_department; + + + /** + * 抄送人节点userid列表,仅use_template_approver为0时生效。 + */ + private List notifyer; + + /** + * 抄送方式:1-提单时抄送(默认值); 2-单据通过后抄送;3-提单和单据通过后抄送。仅use_template_approver为0时生效。 + */ + private int notify_type; + + /** + * 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data” + */ + private Approval_template_apply_data apply_data; + + /** + * 摘要信息,用于显示在审批通知卡片、审批列表的摘要信息,最多3行 + */ + private List summary_list; + + +} diff --git a/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data.java b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data.java new file mode 100644 index 00000000..ad9ebdc2 --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data.java @@ -0,0 +1,17 @@ +package com.dreamchaser.depository_manage.config.QyWx_approval_template; + +import lombok.Data; + +import java.util.List; + +/** + * 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data” + */ +@Data +public class Approval_template_apply_data { + /** + * 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选; + * Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;Location-位置;RelatedApproval-关联审批单;Formula-公式;DateRange-时长 + */ + private List contents; +} diff --git a/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data_contents.java b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data_contents.java new file mode 100644 index 00000000..55fba872 --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_apply_data_contents.java @@ -0,0 +1,25 @@ +package com.dreamchaser.depository_manage.config.QyWx_approval_template; + +import lombok.Data; + +/** + * 控件相关数据 + */ +@Data +public class Approval_template_apply_data_contents { + /** + * 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选; + * ;Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;Location-位置;RelatedApproval-关联审批单;Formula-公式;DateRange-时长; + */ + private String control; + /** + * 控件id:控件的唯一id,可通过“获取审批模板详情”接口获取 + */ + private String id; + + /** + * 控件值 ,需在此为申请人在各个控件中填写内容不同控件有不同的赋值参数,具体说明详见附录。模板配置的控件属性为必填时,对应value值需要有值。 + */ + private Object value; + +} diff --git a/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_approver.java b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_approver.java new file mode 100644 index 00000000..7bc68f23 --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_approver.java @@ -0,0 +1,24 @@ +package com.dreamchaser.depository_manage.config.QyWx_approval_template; + +import lombok.Data; + +import java.util.List; + +/** + * 审批流程信息,用于指定审批申请的审批流程,支持单人审批、多人会签、多人或签,可能有多个审批节点,仅use_template_approver为0时生效。 + */ +@Data +public class Approval_template_approver { + /** + * 节点审批方式:1-或签;2-会签,仅在节点为多人审批时有效 + */ + private int attr; + + /** + * 审批节点审批人userid列表,若为多人会签、多人或签,需填写每个人的userid + */ + private List userid; + + + +} diff --git a/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_summary_info.java b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_summary_info.java new file mode 100644 index 00000000..e318076b --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/config/QyWx_approval_template/Approval_template_summary_info.java @@ -0,0 +1,18 @@ +package com.dreamchaser.depository_manage.config.QyWx_approval_template; + +import lombok.Data; + +/** + * 摘要行信息 + */ +@Data +public class Approval_template_summary_info { + /** + * 摘要行显示文字,用于记录列表和消息通知的显示,不要超过20个字符 + */ + private String text; + /** + * 摘要行显示语言,中文:zh_CN(注意不是zh-CN),英文:en + */ + private String lang; +} diff --git a/src/main/java/com/dreamchaser/depository_manage/config/WebMvcConfig.java b/src/main/java/com/dreamchaser/depository_manage/config/WebMvcConfig.java index 2f9334dd..6f04e575 100644 --- a/src/main/java/com/dreamchaser/depository_manage/config/WebMvcConfig.java +++ b/src/main/java/com/dreamchaser/depository_manage/config/WebMvcConfig.java @@ -15,7 +15,7 @@ public class WebMvcConfig implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new UserInterceptor()) .addPathPatterns("/**") - .excludePathPatterns("/login", "/register", "/sendCode", "/error","/QyWxLogin","/callback") + .excludePathPatterns("/login", "/register", "/sendCode", "/error","/QyWxLogin","/callback","/getMaterialAll") .excludePathPatterns("classpath:/static/**") .excludePathPatterns("/static/**"); } diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java index 5ff5086d..0e021238 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java @@ -309,18 +309,34 @@ public class DepositoryRecordController { map.put("parentId",id); } integer += depositoryRecordService.insertApplicationOutMin(map); + + // 开启一个线程执行发送信息操作 + new Thread(new Runnable() { + @Override + public void run() { + // 向企业微信中对应用户发送消息 + JSONObject jsonObject = qyWxOperationService.sendQyWxToApplicationOutMessage(departMentHeadQyWxName.toString(), ObjectFormatUtil.toInteger(id), true,crypt); + // 将当前返回结果保存到redis中 + Map QyWxMessageMap = new HashMap<>(); + QyWxMessageMap.put("MsgId",jsonObject.getString("msgid")); + QyWxMessageMap.put("responseCode",jsonObject.getString("response_code")); + // key user:300450:QyWxOut:1 + // 申请人number + redisTemplateForHash.opsForHash().putAll("user:"+userToken.getNumber()+":QyWxOutId:"+id,QyWxMessageMap); + // 设置过期时间为三天 + redisTemplateForHash.expire("user:"+userToken.getNumber()+":QyWxOutId:"+id,72,TimeUnit.HOURS); + } + }).start(); + + // 开启一个线程开启审批 + new Thread(new Runnable() { + @Override + public void run() { + + } + }).start(); + } - // 向企业微信中对应用户发送消息 - JSONObject jsonObject = qyWxOperationService.sendQyWxToApplicationOutMessage(departMentHeadQyWxName.toString(), ObjectFormatUtil.toInteger(id), true,crypt); - // 将当前返回结果保存到redis中 - Map QyWxMessageMap = new HashMap<>(); - QyWxMessageMap.put("MsgId",jsonObject.getString("msgid")); - QyWxMessageMap.put("responseCode",jsonObject.getString("response_code")); - // key user:300450:QyWxOut:1 - // 申请人number - redisTemplateForHash.opsForHash().putAll("user:"+userToken.getNumber()+":QyWxOutId:"+id,QyWxMessageMap); - // 设置过期时间为三天 - redisTemplateForHash.expire("user:"+userToken.getNumber()+":QyWxOutId:"+id,72,TimeUnit.HOURS); }else{ // 插入主订单 map.put("departmenthead",departmentHeadId.toString()); diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java b/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java index 3aedbbac..a52e921a 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java @@ -134,8 +134,10 @@ public class PageController { - - + @GetMapping("/getMaterialAll") + public String getMaterialAll(){ + return "pages/material/selectMaterial"; + } diff --git a/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java b/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java index fb19ecc4..0123e1cd 100644 --- a/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java +++ b/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java @@ -42,6 +42,9 @@ public class UserInterceptor extends HandlerInterceptorAdapter { session.invalidate(); return true; } + if("/getMaterialAll".equals(request.getServletPath())){ + return true; + } if("/getCaptchaid".equals(request.getServletPath())){ return true; } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/QyWxOperationService.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/QyWxOperationService.java index 6f8c78d0..4c2248ed 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/QyWxOperationService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/QyWxOperationService.java @@ -3,7 +3,11 @@ package com.dreamchaser.depository_manage.service.impl; import cn.hutool.core.lang.Snowflake; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.dreamchaser.depository_manage.config.PortConfig; import com.dreamchaser.depository_manage.config.QyWxConfig; +import com.dreamchaser.depository_manage.config.QyWx_approval_template.ApprovalTemplate; +import com.dreamchaser.depository_manage.config.QyWx_approval_template.Approval_template_apply_data; +import com.dreamchaser.depository_manage.config.QyWx_approval_template.Approval_template_apply_data_contents; import com.dreamchaser.depository_manage.config.QyWx_template_card.*; import com.dreamchaser.depository_manage.controller.PageController; import com.dreamchaser.depository_manage.entity.*; @@ -1345,5 +1349,90 @@ public class QyWxOperationService { } + /** + * 用于发送出库审批 + * @param userAgent + * @return + */ + public JSONObject sendOutApprovalTemplate(String userAgent,UserByPort userToken,Integer mainId){ + + // 获取当前出库主订单 + ApplicationOutRecordP mainRecord = depositoryRecordMapper.findApplicationOutRecordPById(mainId); + // 获取当前出库明细 + List minRecordList = depositoryRecordMapper.findApplicationOutRecordMinByParent(mainId); + + + // 定义审批模板 + ApprovalTemplate approvalTemplate = new ApprovalTemplate(); + + // 获取申请人的userId + String workwechat = userToken.getWorkwechat(); + + // 设置申请人 + approvalTemplate.setCreator_userid(workwechat); + + // 设置模板id + approvalTemplate.setTemplate_id(QyWxConfig.out_template_id); + + // 设置审批人模式为在管理后台设置的审批流程 + approvalTemplate.setUse_template_approver(1); + + // 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data” + Approval_template_apply_data approval_template_apply_data = new Approval_template_apply_data(); + + //定义模板控件——发起人 + Approval_template_apply_data_contents approval_template_apply_data_contents_initiator = new Approval_template_apply_data_contents(); + + // 控件类型 + approval_template_apply_data_contents_initiator.setControl("Contact"); + // 控件id + approval_template_apply_data_contents_initiator.setId("Contact-1668051509196"); + + // 成员控件值(control参数为Contact,且value参数为members) + Map members_initiator = new HashMap<>(); + Map contact_user = new HashMap<>(); + List> membersMap_initiator = new ArrayList<>(); + contact_user.put("userid",workwechat); + contact_user.put("name",userToken.getName()); + membersMap_initiator.add(contact_user); + members_initiator.put("members",membersMap_initiator); + approval_template_apply_data_contents_initiator.setValue(members_initiator); + + //定义模板控件——发起时间 + Approval_template_apply_data_contents approval_template_apply_data_contents_time = new Approval_template_apply_data_contents(); + approval_template_apply_data_contents_time.setControl("Date"); + approval_template_apply_data_contents_time.setId("Date-1668051535322"); + + Map members_time = new HashMap<>(); + Map contact_time = new HashMap<>(); + contact_time.put("type","hour"); + contact_time.put("s_timestamp", String.valueOf(System.currentTimeMillis()/1000)); + members_time.put("date",contact_time); + approval_template_apply_data_contents_time.setValue(members_time); + + //定义模板控件——所在部门 + Approval_template_apply_data_contents approval_template_apply_data_contents_department = new Approval_template_apply_data_contents(); + approval_template_apply_data_contents_department.setControl("Contact"); + approval_template_apply_data_contents_department.setId("Contact-1668048405619"); + + // 获取当前登录用户部门与企业微信部门对照 + JSONObject userPortByQyWx = PortConfig.getUserPortByQyWx(userToken.getMaindeparment()); + String portName = userPortByQyWx.getString("name"); + Integer portByQyWxInteger = userPortByQyWx.getInteger("wechatorganizationid"); + + + // 部门控件值(control参数为Contact,且value参数为members) + Map members_port = new HashMap<>(); + Map contact_port = new HashMap<>(); + List> membersMap_port = new ArrayList<>(); + contact_port.put("openapi_id",portByQyWxInteger.toString()); + contact_port.put("name",portName); + membersMap_port.add(contact_user); + members_port.put("departments",membersMap_port); + approval_template_apply_data_contents_department.setValue(members_port); + + return null; + } + } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 14c6bc70..204f6ad5 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -157,6 +157,8 @@ miniAdmin = layui.miniAdmin; + + var dataByConfig; var uid = $("#uid").text(); var options = { clearUrl: "/static/api/clear.json", // 缓存清理接口 @@ -224,7 +226,7 @@ timestamp: data.timestamp, // 必填,生成签名的时间戳 nonceStr: data.noncestr, // 必填,生成签名的随机串 signature: data.jsapi_ticket_enterprises,// 必填,签名,见 附录-JS-SDK使用权限签名算法 - jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来 + jsApiList: ['invoke','thirdPartyOpenPage','scanQRCode'] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来 }); } }); diff --git a/src/main/resources/templates/pages/application/application-out.html b/src/main/resources/templates/pages/application/application-out.html index 58d65c21..ae97119f 100644 --- a/src/main/resources/templates/pages/application/application-out.html +++ b/src/main/resources/templates/pages/application/application-out.html @@ -12,22 +12,29 @@