11.9开发

This commit is contained in:
hejinbo
2023-11-09 17:34:12 +08:00
parent ae2c8fe59f
commit 94d3f1cb1e
10 changed files with 351 additions and 124 deletions
@@ -13,6 +13,7 @@ import com.ruoyi.wisdomarbitrate.service.IDeptIdentifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -49,6 +50,17 @@ public class DeptIdentifyController extends BaseController {
return deptIdentifyService.enableDept(deptIdentify);
}
/**
* 上传自定义公章
* @param deptIdentify
* @param file
* @return
*/
@PostMapping("sealUpload")
public AjaxResult sealUpload(@Validated @RequestBody DeptIdentify deptIdentify
,@RequestParam("file") MultipartFile file){
return deptIdentifyService.sealUpload(deptIdentify,file);
}
@@ -80,9 +80,8 @@ public class SealUtil {
*
* @return
*/
public static EsignHttpResponse getFileUploadUrl() throws EsignDemoException {
public static EsignHttpResponse getFileUploadUrl(String filePath) throws EsignDemoException {
//自定义的文件封装类,传入文件地址可以获取文件的名称大小,文件流等数据
String filePath = "D:\\develop\\Snipaste_2023-10-27_09-59-23.jpg";
EsignFileBean esignFileBean = new EsignFileBean(filePath);
String apiaddr="/v3/files/file-key";
//请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
@@ -42,5 +42,9 @@ public class CaseAttach {
* 用户账户
*/
private String userName;
/**
* 印章状态(0未启用,1已启用)
*/
private Integer sealStatus;
}
@@ -2,7 +2,6 @@ package com.ruoyi.wisdomarbitrate.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import java.util.Date;
public class DeptIdentify extends BaseEntity {
@@ -39,6 +38,30 @@ public class DeptIdentify extends BaseEntity {
/** 认证授权流程ID */
private String authFlowId;
public String getSealId() {
return sealId;
}
public void setSealId(String sealId) {
this.sealId = sealId;
}
/** 印章id */
private String sealId;
/**
* 附件id
*/
private Integer annexId;
public Integer getAnnexId() {
return annexId;
}
public void setAnnexId(Integer annexId) {
this.annexId = annexId;
}
public String getAuthFlowId() {
return authFlowId;
}
@@ -3,6 +3,7 @@ package com.ruoyi.wisdomarbitrate.service;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.EsignDemoException;
import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -15,4 +16,8 @@ public interface IDeptIdentifyService {
DeptIdentify selectDeptIndefiUrl(DeptIdentify deptIdentify) throws EsignDemoException;
AjaxResult enableDept(DeptIdentify deptIdentify);
AjaxResult sealUpload(DeptIdentify deptIdentify, MultipartFile file);
}
@@ -1,18 +1,26 @@
package com.ruoyi.wisdomarbitrate.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
import com.ruoyi.common.exception.EsignDemoException;
import com.ruoyi.common.utils.SealUtil;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.wisdomarbitrate.domain.CaseAttach;
import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
import com.ruoyi.wisdomarbitrate.mapper.CaseAttachMapper;
import com.ruoyi.wisdomarbitrate.mapper.DeptIdentifyMapper;
import com.ruoyi.wisdomarbitrate.service.IDeptIdentifyService;
import com.ruoyi.wisdomarbitrate.utils.SignAward;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Date;
import java.util.List;
@@ -21,6 +29,8 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
@Autowired
private DeptIdentifyMapper deptIdentifyMapper;
@Autowired
private CaseAttachMapper caseAttachMapper;
@Override
@@ -54,16 +64,16 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
DeptIdentify deptIdentifyselect = deptIdentifysnew.get(0);
EsignHttpResponse identifyUrl = SignAward.deptIdentifyUrl(deptIdentifyselect);
JsonObject signUrlJsonObject = gson.fromJson(identifyUrl.getBody(), JsonObject.class);
int code = signUrlJsonObject.get("code").getAsInt();
JsonObject signUrlData = signUrlJsonObject.getAsJsonObject("data");
String url = signUrlData.get("authUrl").getAsString();
//获取本次认证授权流程ID
String authFlowId = signUrlData.get("authFlowId").getAsString();
deptIdentify.setAuthFlowId(authFlowId);
deptIdentifynew.setIdentifyUrl(url);
}
deptIdentify.setIdentifyDate(new Date());
int row = deptIdentifyMapper.updateDeptIdentify(deptIdentify);
}
return deptIdentifynew;
}
@@ -96,5 +106,53 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
}
@Override
public AjaxResult sealUpload(DeptIdentify deptIdentify, MultipartFile file) {
try {
if (file.isEmpty()) {
return AjaxResult.error("请选择要上传的文件");
}
String filePath = RuoYiConfig.getUploadPath();
// 上传
String fileName = FileUploadUtils.upload(filePath, file);
List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentifyBydeptid(deptIdentify);
if (deptIdentifies != null && deptIdentifies.size() > 0) {
for (DeptIdentify identify : deptIdentifies) {
//先判断企业用户是否授予资源管理权限
String authFlowId = identify.getAuthFlowId();
EsignHttpResponse response1 = SealUtil.queryAuthProcess(authFlowId);
JSONObject jsonObject1 = JSONObject.parseObject(response1.getBody());
int authorizedStatus = jsonObject1.getJSONObject("data").getIntValue("authorizedStatus");
if (authorizedStatus == 1){//授权流程状态 0流程过期失效 1已授权 2授权中 3审批未通过
String prefix = "/profile";
int startIndex = fileName.indexOf(prefix);
startIndex += prefix.length();
String annexPath = "/uploadPath" + fileName.substring(startIndex);
//创建机构图片印章
EsignHttpResponse response = SignAward.createOrgByImage(identify, annexPath);
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
int code = jsonObject.getIntValue("code");
if (code == 0) { //业务码,0表示成功,非0表示异常。
String sealId = jsonObject.getJSONObject("data").getString("sealId");
identify.setSealId(sealId);
identify.setIsUse(0); //设置印章使用状态为未启用
//保存到表里
int i = deptIdentifyMapper.updateDeptIdentify(identify);
if (i>0){
return AjaxResult.success("上传成功");
}
}
}
return AjaxResult.error("企业用户未授予资源管理权限");
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (EsignDemoException e) {
e.printStackTrace();
}
return AjaxResult.error();
}
}
@@ -1,5 +1,7 @@
package com.ruoyi.wisdomarbitrate.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -208,4 +210,79 @@ public class FixSelectFlowDetailUtils {
}
}
}
/**
* 定时查询企业内部印章审核状态
*
* @throws EsignDemoException
*/
@Scheduled(cron = "0/30 * * * * ?")
@Transactional
public void searchForInstitutionalSeal() {
try {
DeptIdentify deptIdentify = new DeptIdentify();
deptIdentify.setIsUse(0);
List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentifylist(deptIdentify);
if (deptIdentifies != null && deptIdentifies.size() > 0) {
for (DeptIdentify identify : deptIdentifies) {
//查询企业内部印章
Integer annexId = identify.getAnnexId();
if (annexId == null){
//说明之前没有下载过
EsignHttpResponse response = SignAward.orgOwnSealList(identify);
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
JSONObject data = jsonObject.getJSONObject("data");
JSONArray seals = data.getJSONArray("seals");
for (int i = 0; i < seals.size(); i++){
JSONObject seal = seals.getJSONObject(i);
int statusDescription = seal.getIntValue("statusDescription");
if (statusDescription==1){//印章状态 1已启用,2待审核,3审核不通过,4 挂起
//已启用证明审核通过,下载到数据库
String sealImageDownloadUrl = seal.getString("sealImageDownloadUrl");
LocalDate now = LocalDate.now();
String year = Integer.toString(now.getYear());
String month = String.format("%02d", now.getMonthValue());
String day = String.format("%02d", now.getDayOfMonth());
String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
String savePath = "/home/ruoyi/uploadPath/upload/";
// 创建日期目录
File saveFolder = new File(saveFolderPath);
if (!saveFolder.exists()) {
saveFolder.mkdirs();
}
String resultFilePath = saveFolderPath + "/" + fileName;
File resultFilePathFile = new File(resultFilePath);
if (!resultFilePathFile.exists()) {
resultFilePathFile.createNewFile();
}
boolean downLoadFile = FileTransformation.downLoadFileByUrl(sealImageDownloadUrl, resultFilePath);
if (downLoadFile) {
CaseAttach caseAttach = new CaseAttach();
caseAttach.setAnnexType(10); //10代表印章图片
caseAttach.setAnnexPath(savePath);
caseAttach.setAnnexName(saveName);
caseAttach.setSealStatus(1); //1代表印章启用
int i1 = caseAttachMapper.save(caseAttach);
if (i1>0){
//将附件id保存到公章管理表里
Integer annexId1 = caseAttach.getAnnexId();
identify.setAnnexId(annexId1);
deptIdentifyMapper.updateDeptIdentify(identify);
}
}
}
}
}
}
}
} catch (EsignDemoException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -1,5 +1,6 @@
package com.ruoyi.wisdomarbitrate.utils;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -9,6 +10,7 @@ import com.ruoyi.common.exception.EsignDemoException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.EsignApplicaConfig;
import com.ruoyi.common.utils.EsignHttpHelper;
import com.ruoyi.common.utils.SealUtil;
import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
import com.ruoyi.wisdomarbitrate.domain.SealSignRecord;
@@ -23,7 +25,6 @@ public class SignAward {
private static String eSignAppSecret = EsignApplicaConfig.EsignAppSecret;
public static void main(String[] args) throws EsignDemoException {
Gson gson = new Gson();
@@ -89,8 +90,6 @@ public class SignAward {
// System.out.println("机构印章名称:" +sealNames.substring(0,sealNames.length()-1));
//查询签署流程详情
// EsignHttpResponse signFlowDetail = signFlowDetail(sealSignRecord);
// JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(),JsonObject.class);
@@ -120,14 +119,12 @@ public class SignAward {
// System.out.println(signFlowDetailJsonObject);
}
/**
* 查询签署流程详情
*
* @return
*/
public static EsignHttpResponse signFlowDetail(SealSignRecord sealSignRecord) throws EsignDemoException {
@@ -145,6 +142,7 @@ public class SignAward {
/**
* 发起签署
*
* @return
* @throws EsignDemoException
*/
@@ -277,6 +275,7 @@ public class SignAward {
/**
* 获取合同文件签名链接
*
* @return
* @throws EsignDemoException
*/
@@ -304,6 +303,7 @@ public class SignAward {
/**
* 获取合同文件用印链接
*
* @return
* @throws EsignDemoException
*/
@@ -387,6 +387,7 @@ public class SignAward {
//发起接口请求
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
}
/**
* 查询企业认证印章信息
*/
@@ -404,9 +405,9 @@ public class SignAward {
}
/**
* 获取文件签名印章位置
*
* @return
* @throws EsignDemoException
*/
@@ -432,15 +433,37 @@ public class SignAward {
*
* @return
*/
public static EsignHttpResponse createOrgByImage(DeptIdentify deptIdentify) throws EsignDemoException {
public static EsignHttpResponse createOrgByImage(DeptIdentify deptIdentify, String filePath) throws EsignDemoException {
//获取认证授权流程ID
String authFlowId = deptIdentify.getAuthFlowId();
//查询认证授权流程详情
EsignHttpResponse response = SealUtil.queryAuthProcess(authFlowId);
String body = response.getBody();
if (body != null) {
JSONObject jsonObject = JSONObject.parseObject(body);
//查询授权流程状态
int authorizedStatus = jsonObject.getJSONObject("data").getIntValue("authorizedStatus");
if (authorizedStatus == 1) {//0 -流程过期失效 1 - 已授权 2 - 授权中 3 - 审批未通过
String apiaddr = "/v3/seals/org-seals/create-by-image";
String orgId = deptIdentify.getOrgId();
String sealImageFileKey = "";
//上传印章图片
//步骤一:获取印章图片上传地址fileUploadUrl
EsignHttpResponse response1 = SealUtil.getFileUploadUrl(filePath);
JSONObject jsonObject1 = JSONObject.parseObject(response1.getBody());
String fileUploadUrl = jsonObject1.getJSONObject("data").getString("fileUploadUrl");
//步骤二:将印章图片文件流上传到fileUploadUrl
EsignHttpResponse response2 = SealUtil.fileStreamUpload(fileUploadUrl, filePath);
JSONObject jsonObject2 = JSONObject.parseObject(response2.getBody());
int errCode = jsonObject2.getIntValue("errCode");
if (errCode == 0){ //业务码,0表示成功,非0表示异常。
//获取步骤一里面的fileKey
String sealImageFileKey = jsonObject1.getJSONObject("data").getString("fileKey");
String sealName = deptIdentify.getSealName();
//请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
String jsonParm = "{\n" +
" \"orgId\": \"" + orgId + "\",\n" +
" \"sealImageFileKey\": \"" + sealImageFileKey + "\",\n" +
" \"sealName\": \"企业公章1\",\n" +
" \"sealName\": \" " + sealName + " \",\n" +
" \"sealWidth\": 50,\n" +
" \"sealHeight\": 50,\n" +
"}";
@@ -449,10 +472,31 @@ public class SignAward {
//生成签名鉴权方式的的header
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
//发起接口请求
EsignHttpResponse response = EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
System.out.println(response);
return response;
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
}
}
}
return null;
}
/**
* 查询企业内部印章
*/
public static EsignHttpResponse orgOwnSealList(DeptIdentify deptIdentify) throws EsignDemoException {
String orgId=deptIdentify.getOrgId();
int pageNum=1;
int pageSize=20;
String apiaddr="/v3/seals/org-own-seal-list?orgId="+orgId+"&pageNum="+pageNum+"&pageSize="+pageSize;
//请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
String jsonParm=null;
//请求方法
EsignRequestType requestType= EsignRequestType.GET;
//生成签名鉴权方式的的header
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
//发起接口请求
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr,requestType , jsonParm, header,true);
}
}
@@ -12,10 +12,11 @@
<result property="note" column="note" />
<result property="userId" column="use_id" />
<result property="userName" column="use_account" />
<result property="sealStatus" column="seal_status" />
</resultMap>
<insert id="save" useGeneratedKeys="true" keyProperty="annexId">
INSERT INTO case_attach (case_appli_id, annex_name, annex_path , annex_type,note,use_id,use_account)
VALUES (#{caseAppliId}, #{annexName}, #{annexPath},#{annexType},#{note},#{userId},#{userName})
INSERT INTO case_attach (case_appli_id, annex_name, annex_path , annex_type,note,use_id,use_account,seal_status)
VALUES (#{caseAppliId}, #{annexName}, #{annexPath},#{annexType},#{note},#{userId},#{userName},#{sealStatus})
</insert>
<delete id="deleteByFileIds">
delete from case_attach
@@ -14,6 +14,9 @@
<result property="phonenumber" column="phonenumber" />
<result property="deptName" column="dept_name" />
<result property="sealName" column="seal_name" />
<result property="orgId" column="org_id" />
<result property="authFlowId" column="auth_flow_id" />
<result property="sealId" column="seal_id" />
</resultMap>
@@ -28,7 +31,7 @@
</select>
<select id="selectDeptIdentifyBydeptid" parameterType="DeptIdentify" resultMap="DeptIdentifyResult">
SELECT d.id ,d.dept_id ,d.user_id
SELECT d.id ,d.dept_id ,d.user_id ,d.org_id ,d.auth_flow_id
from dept_identify d
<where>
<if test="deptId != null">
@@ -53,8 +56,8 @@
</insert>
<select id="selectDeptIdentifylist" parameterType="DeptIdentify" resultMap="DeptIdentifyResult">
SELECT d.id ,d.dept_id ,d.user_id, d.identify_status ,d.identify_date ,d.is_use , d.seal_name, sd.dept_name ,
u.nick_name ,u.phonenumber
SELECT d.id ,d.dept_id ,d.user_id, d.identify_status ,d.identify_date ,d.is_use , d.seal_name,
d.org_id , d.seal_id ,sd.dept_name , u.nick_name ,u.phonenumber
from dept_identify d left join sys_dept sd on d.dept_id = sd.dept_id
left join sys_user u on u.user_id = d.user_id
<where>
@@ -90,6 +93,7 @@
<if test="isUse != null">is_use = #{isUse},</if>
<if test="identifyStatus != null ">identify_status = #{identifyStatus},</if>
<if test="sealName != null and sealName != ''">seal_name = #{sealName},</if>
<if test="sealId != null and sealId != ''">seal_id = #{sealId},</if>
</set>
where id = #{id}
</update>