Commit c2edff36 authored by fangxinjiang's avatar fangxinjiang

电子印章代码附件上传到税友-fxj

parent 2078c786
...@@ -49,6 +49,10 @@ public class SocialFriendConfig { ...@@ -49,6 +49,10 @@ public class SocialFriendConfig {
// url拉结果数据 // url拉结果数据
@Value("${socialFriend.urlGetInfo}") @Value("${socialFriend.urlGetInfo}")
private String urlGetInfo; private String urlGetInfo;
// url拉结果数据
@Value("${socialFriend.urlUpload}")
private String urlUpload;
private static final String APP_KEY = "appKey"; private static final String APP_KEY = "appKey";
private static final String TIMESTAMP = "timestamp"; private static final String TIMESTAMP = "timestamp";
...@@ -144,6 +148,66 @@ public class SocialFriendConfig { ...@@ -144,6 +148,66 @@ public class SocialFriendConfig {
return addId; return addId;
} }
/**
* @param : type 1社保增 2社保减 3医保增 4医保减
* @Description: 推送任务接口
* @Author: hgw
* @Date: 2024-12-9 16:54:31
* @return: java.lang.String
**/
public String uploadPng(RestTemplate restTemplate, String fileName, String file, TSocialFriendBackLog backLog) {
String urlStr = "";
String appAddUrl = urlPre + urlUpload;
String version = "1.0.0";
String timestamp = String.valueOf(new Date().getTime());
String xReqNonce = "1";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// */*
headers.add("accept", MediaType.ALL_VALUE);
headers.add(APP_KEY, appKey);
headers.add(TIMESTAMP, timestamp);
try {
String signature = SocialFriendSign.qianMing(getMapParam(appKey, appSecret, xReqNonce, version, timestamp, null));
headers.add("signature", signature);
} catch (SignatureException e) {
log.error("税友签名失败", e);
return urlStr;
}
headers.add(X_REQ_NONCE, xReqNonce);
headers.add(VERSION, version);
JSONObject json = new JSONObject();
// 文件名称
json.put("wjmc", fileName);
// 文件内容
json.put("wjnr", file);
// 业务类型 参保、停保、参保业务签名、停保业务签名、人员补缴、缴费工资变更、缴费工资业务签名
// json.put("ywlx", vo.getUnitCreditCode())
// 行政区划代码 户里的缴纳地,精确到市 "340100"
HttpEntity<String> formEntity = new HttpEntity<>(json.toString(), headers);
String dataResultList = restTemplate.postForObject(appAddUrl, formEntity, String.class);
// {"head":{"code":"00000000","description":"成功","msg":"成功","time":"2024-12-06 17:10:26","status":"Y"
// ,"body":{"requestId":"85440b327d71466abcd9c5c81d5bb172"
if (Common.isNotNull(dataResultList)) {
backLog.setLogInfo(dataResultList);
backLog.setCreateTime(LocalDateTime.now());
JSONObject dataObject = JSON.parseObject(dataResultList);
String head = dataObject.getString("head");
if (Common.isNotNull(head)) {
JSONObject headObject = JSON.parseObject(head);
String status = headObject.getString("status");
if ("Y".equals(status)) {
String body = dataObject.getString("body");
JSONObject bodyObject = JSON.parseObject(body);
urlStr = bodyObject.getString("wjlj");
}
}
}
return urlStr;
}
/** /**
* @param json 总传参json * @param json 总传参json
* @param type 1社保增 2社保减 3医保增 4医保减 * @param type 1社保增 2社保减 3医保增 4医保减
......
...@@ -41,5 +41,5 @@ public interface TSocialFriendPushService extends IService<TSocialInfo> { ...@@ -41,5 +41,5 @@ public interface TSocialFriendPushService extends IService<TSocialInfo> {
**/ **/
R<String> pushFriend(List<String> dispatchIdList); R<String> pushFriend(List<String> dispatchIdList);
R<URL> doExportRoster(String socialId, String type, String unitCreditCode); R<String> doExportRoster(String socialId, String type, String unitCreditCode);
} }
...@@ -143,7 +143,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -143,7 +143,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
String thisTime = DateUtil.getThisTime(); String thisTime = DateUtil.getThisTime();
List<TSocialFriendBackLog> backLogList = new ArrayList<>(); List<TSocialFriendBackLog> backLogList = new ArrayList<>();
TSocialFriendBackLog backLog; TSocialFriendBackLog backLog;
R<URL> urlR; R<String> urlR;
for (SociaFriendYgsAddVo vo : ygsAddlist) { for (SociaFriendYgsAddVo vo : ygsAddlist) {
// 0:未到时间不动; 1:推送; 2:转人工 // 0:未到时间不动; 1:推送; 2:转人工
canPushType = this.getCanPushType(socialSetMap, vo); canPushType = this.getCanPushType(socialSetMap, vo);
...@@ -156,7 +156,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -156,7 +156,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
// 房工接口,获取 企业职工社会保险增员花名册 url // 房工接口,获取 企业职工社会保险增员花名册 url
urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode()); urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode());
if (urlR != null && urlR.getCode()==200 && Common.isNotNull(urlR.getData())) { if (urlR != null && urlR.getCode()==200 && Common.isNotNull(urlR.getData())) {
vo.setQyzgshbxzyhmc(urlR.getData().toString()); vo.setQyzgshbxzyhmc(urlR.getData());
} }
requestId = socialFriendConfig.pushFriendByInfo(restTemplate, vo, type, thisTime, backLog); requestId = socialFriendConfig.pushFriendByInfo(restTemplate, vo, type, thisTime, backLog);
if (Common.isEmpty(requestId)) { if (Common.isEmpty(requestId)) {
...@@ -221,7 +221,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -221,7 +221,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
String thisTime = DateUtil.getThisTime(); String thisTime = DateUtil.getThisTime();
List<TSocialFriendBackLog> backLogList = new ArrayList<>(); List<TSocialFriendBackLog> backLogList = new ArrayList<>();
TSocialFriendBackLog backLog; TSocialFriendBackLog backLog;
R<URL> urlR; R<String> urlR;
for (SociaFriendYgsAddVo vo : ysdAddlist) { for (SociaFriendYgsAddVo vo : ysdAddlist) {
// 0:未到时间不动; 1:推送; 2:转人工 // 0:未到时间不动; 1:推送; 2:转人工
canPushType = this.getCanPushTypeYsd(socialSetMap, vo); canPushType = this.getCanPushTypeYsd(socialSetMap, vo);
...@@ -234,7 +234,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -234,7 +234,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
// 房工接口,获取 企业职工基本医疗保险参保登记表 url // 房工接口,获取 企业职工基本医疗保险参保登记表 url
urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode()); urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode());
if (urlR != null && urlR.getCode()==200 && Common.isNotNull(urlR.getData())) { if (urlR != null && urlR.getCode()==200 && Common.isNotNull(urlR.getData())) {
vo.setQyzgjbylbxcbdjb(urlR.getData().toString()); vo.setQyzgjbylbxcbdjb(urlR.getData());
} }
requestId = socialFriendConfig.pushFriendByInfo(restTemplate, vo, type, thisTime, backLog); requestId = socialFriendConfig.pushFriendByInfo(restTemplate, vo, type, thisTime, backLog);
if (Common.isEmpty(requestId)) { if (Common.isEmpty(requestId)) {
...@@ -401,7 +401,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -401,7 +401,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
* @return * @return
**/ **/
@Override @Override
public R<URL> doExportRoster(String socialId, String type, String unitCreditCode) { public R<String> doExportRoster(String socialId, String type, String unitCreditCode) {
SocialHandleSearchVo searchVo = new SocialHandleSearchVo(); SocialHandleSearchVo searchVo = new SocialHandleSearchVo();
if (Common.isEmpty(socialId) || Common.isEmpty(type) || Common.isEmpty(unitCreditCode)){ if (Common.isEmpty(socialId) || Common.isEmpty(type) || Common.isEmpty(unitCreditCode)){
return R.failed(CommonConstants.PARAM_IS_NOT_ERROR); return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
...@@ -450,7 +450,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -450,7 +450,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
* @Param * @Param
* @return * @return
**/ **/
public R<URL> doExportRosterMedical(SocialHandleSearchVo searchVo, public R<String> doExportRosterMedical(SocialHandleSearchVo searchVo,
String type, String type,
String fileName, String fileName,
String projectRoot, String projectRoot,
...@@ -624,7 +624,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -624,7 +624,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
outFile = new File(tempPath); outFile = new File(tempPath);
inputStreamOut = new FileInputStream(outFile); inputStreamOut = new FileInputStream(outFile);
// 转换成图片 完成后清理流 // 转换成图片 完成后清理流
return excelToImage.excelToImg(inputStreamOut,ossUtil); TSocialFriendBackLog backLog = new TSocialFriendBackLog();
R<String> ulrR = excelToImage.excelToImg(inputStreamOut,socialFriendConfig,restTemplate, backLog);
tSocialFriendBackLogService.save(backLog);
return ulrR;
}catch (Exception e){ }catch (Exception e){
return R.failed("税友附件生成异常:"+e.getMessage()); return R.failed("税友附件生成异常:"+e.getMessage());
}finally { }finally {
...@@ -684,7 +687,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -684,7 +687,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
* @Param * @Param
* @return * @return
**/ **/
public R<URL> doExportRosterSocial(SocialHandleSearchVo searchVo, public R<String> doExportRosterSocial(SocialHandleSearchVo searchVo,
String type, String type,
String fileName, String fileName,
String projectRoot, String projectRoot,
...@@ -884,7 +887,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -884,7 +887,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
outFile = new File(tempPath); outFile = new File(tempPath);
inputStreamOut = new FileInputStream(outFile); inputStreamOut = new FileInputStream(outFile);
// 转换成图片 完成后清理流 // 转换成图片 完成后清理流
return excelToImage.excelToImg(inputStreamOut,ossUtil); TSocialFriendBackLog backLog = new TSocialFriendBackLog();
R<String> ulrR = excelToImage.excelToImg(inputStreamOut,socialFriendConfig,restTemplate, backLog);
tSocialFriendBackLogService.save(backLog);
return ulrR;
}catch (Exception e){ }catch (Exception e){
return R.failed("税友附件生成异常:"+e.getMessage()); return R.failed("税友附件生成异常:"+e.getMessage());
}finally { }finally {
......
...@@ -6,8 +6,10 @@ import com.spire.xls.Worksheet; ...@@ -6,8 +6,10 @@ import com.spire.xls.Worksheet;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil; import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import groovyjarjarpicocli.CommandLine; import com.yifu.cloud.plus.v1.yifu.social.config.SocialFriendConfig;
import com.yifu.cloud.plus.v1.yifu.social.entity.TSocialFriendBackLog;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -23,6 +25,46 @@ import java.net.URL; ...@@ -23,6 +25,46 @@ import java.net.URL;
@Component @Component
public class ExcelToImage { public class ExcelToImage {
public R<String> excelToImg(InputStream inputStream , SocialFriendConfig socialFriendConfig
, RestTemplate restTemplate, TSocialFriendBackLog backLog){
if (null == inputStream || null == socialFriendConfig){
return R.failed(CommonConstants.RESULT_DATA_FAIL+":带印章excel生成图片传参异常");
}
String projectRoot = System.getProperty(CommonConstants.USER_DIR);
//加载Excel工作表
Workbook wb = new Workbook();
wb.loadFromHtml(inputStream);
//获取工作表
Worksheet sheet = wb.getWorksheets().get(0);
//调用方法将Excel工作表保存为图片
sheet.saveToImage(projectRoot+"\\ToImg.png");
File file = null;
try {
file = new File(projectRoot+"\\ToImg.png");
if (file.exists()){
String key = System.currentTimeMillis() + file.getName();
// TODO - shuiyou
String url = socialFriendConfig.uploadPng(restTemplate, key, file.toString(), backLog);
return R.ok(url);
}
} catch (Exception e) {
return R.failed(CommonConstants.RESULT_DATA_FAIL+":ExcelToImage转换异常-"+e.getMessage());
} finally {
if (file.exists()){
file.delete();
}
if (null != inputStream){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return R.failed(CommonConstants.RESULT_DATA_FAIL);
}
public R<URL> excelToImg(InputStream inputStream ,OSSUtil ossUtil){ public R<URL> excelToImg(InputStream inputStream ,OSSUtil ossUtil){
if (null == inputStream || null == ossUtil){ if (null == inputStream || null == ossUtil){
return R.failed(CommonConstants.RESULT_DATA_FAIL+":带印章excel生成图片传参异常"); return R.failed(CommonConstants.RESULT_DATA_FAIL+":带印章excel生成图片传参异常");
...@@ -82,4 +124,5 @@ public class ExcelToImage { ...@@ -82,4 +124,5 @@ public class ExcelToImage {
//调用方法将Excel保存为PCL //调用方法将Excel保存为PCL
sheet.saveToFile("ToPCL.pcl", String.valueOf(FileFormat.PCL));*/ sheet.saveToFile("ToPCL.pcl", String.valueOf(FileFormat.PCL));*/
} }
} }
...@@ -65,5 +65,6 @@ socialFriend: ...@@ -65,5 +65,6 @@ socialFriend:
urlPre : https://test-openapi.17win.com urlPre : https://test-openapi.17win.com
urlPush : /gateway/socins/hrss/employee/v2/register urlPush : /gateway/socins/hrss/employee/v2/register
urlGetInfo : /gateway/socins/hrss/employee/v2/getRegisterFeedback urlGetInfo : /gateway/socins/hrss/employee/v2/getRegisterFeedback
urlUpload : /gateway/file/upload
appKey : 89357285571962202409230949030 appKey : 89357285571962202409230949030
appSecret : V52dkvxtFUgIvzlfNE9G8g== appSecret : V52dkvxtFUgIvzlfNE9G8g==
\ No newline at end of file
...@@ -61,5 +61,6 @@ socialFriend: ...@@ -61,5 +61,6 @@ socialFriend:
urlPre : https://test-openapi.17win.com urlPre : https://test-openapi.17win.com
urlPush : /gateway/socins/hrss/employee/v2/register urlPush : /gateway/socins/hrss/employee/v2/register
urlGetInfo : /gateway/socins/hrss/employee/v2/getRegisterFeedback urlGetInfo : /gateway/socins/hrss/employee/v2/getRegisterFeedback
urlUpload : /gateway/file/upload
appKey : 89357285571962202409230949030 appKey : 89357285571962202409230949030
appSecret : V52dkvxtFUgIvzlfNE9G8g== appSecret : V52dkvxtFUgIvzlfNE9G8g==
\ No newline at end of file
...@@ -60,5 +60,6 @@ socialFriend: ...@@ -60,5 +60,6 @@ socialFriend:
urlPre : https://test-openapi.17win.com urlPre : https://test-openapi.17win.com
urlPush : /gateway/socins/hrss/employee/v2/register urlPush : /gateway/socins/hrss/employee/v2/register
urlGetInfo : /gateway/socins/hrss/employee/v2/getRegisterFeedback urlGetInfo : /gateway/socins/hrss/employee/v2/getRegisterFeedback
urlUpload : /gateway/file/upload
appKey : 89357285571962202409230949030 appKey : 89357285571962202409230949030
appSecret : V52dkvxtFUgIvzlfNE9G8g== appSecret : V52dkvxtFUgIvzlfNE9G8g==
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment