增加第三方同步服务公共逻辑

This commit is contained in:
gaoben 2024-07-05 18:20:47 +08:00
parent 8113e6d10a
commit cd7f845993
2 changed files with 360 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package net.shapelight.modules.ten.service;
import net.shapelight.modules.ten.entity.TenCellEntity;
public interface TenSyncService {
//国资处
public void syncA001Batch(TenCellEntity cellEntity);
public int syncA001ByXgh(TenCellEntity cellEntity,String xgh);
}

View File

@ -0,0 +1,346 @@
package net.shapelight.modules.ten.service.impl;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import lombok.extern.slf4j.Slf4j;
import net.shapelight.common.config.GlobalValue;
import net.shapelight.common.config.MinioConfig;
import net.shapelight.common.utils.*;
import net.shapelight.commons.engine.sdk.PicSDK;
import net.shapelight.modules.app.entity.AppUserEntity;
import net.shapelight.modules.app.entity.AppUserScopeEntity;
import net.shapelight.modules.app.service.AppUserScopeService;
import net.shapelight.modules.app.service.AppUserService;
import net.shapelight.modules.excel.listener.PersonExcelListener;
import net.shapelight.modules.excel.model.PersonModel;
import net.shapelight.modules.nettyapi.service.ServerApiService;
import net.shapelight.modules.ten.dao.TenPersonDao;
import net.shapelight.modules.ten.entity.*;
import net.shapelight.modules.ten.service.*;
import net.shapelight.modules.vo.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import java.util.regex.Pattern;
//import net.shapelight.modules.dev.mqtt.CmdProcess;
/**
* 此方法调用第三方接口同步人员信息接口根据第三方提供
* 返回数据根据jsonObject解析
*/
@Service("tenSyncService")
@Slf4j
public class TenSyncServiceImpl implements TenSyncService {
@Autowired
private GlobalValue globalValue;
@Autowired
private MinioConfig minioConfig;
@Autowired
private MinioClient minioClient;
@Autowired
private TenPersonService tenPersonService;
public int syncA001ByXgh(TenCellEntity cellEntity,String xgh) {
JSONObject params = JSONObject.parseObject("{\n" +
" \"reqSerialNum\": \"YFMJ_202406051816209365\",\n" +
" \"data\": {\n" +
" \"resourceID\": \"1112826\",\n" +
" \"orderByParam\": \"\",\n" +
" \"pageSize\": \"10\",\n" +
" \"isUseStore\": \"Y\",\n" +
" \"page\": \"1\",\n" +
" \"increaseParam\": \"xgh='"+xgh+"'\"\n" +
" },\n" +
" \"errCode\": \"\",\n" +
" \"msgToSysID\": \"YHZX\",\n" +
" \"errMsg\": \"\",\n" +
" \"sign\": \"BXu6sNoXfhx7/Aqqr+GK59z0DGwZeolN5klYz3TVrRZr4mlqddtVbMInjgAJLZRFpssnHiF/a9+66TztsDefJiDadWY3Ea1KFwjd5QLgeabVXy6qUF9Uv5kqRD5yzF3irREuDsOxbi4ryGf4L67tjnyvexatrwWdEmO4t4aRAgqPh6N7RkHqJ6STb5sbmzUACgLDOr4J0lEg7olGrzsN2vVwd63dYnXHDGp81jS+bj+1TqoIKX2+FkxlcJ5AGsl0TZ3LJ86Xs5dJucyRsfmRVKs1wBGHsQfQgpAaIHGr4CfbJzf4F+fAcopYD55qduWyjYp0rZoPzCeKbAKSa3owEw==\",\n" +
" \"msgFromSysID\": \"YFMJ\",\n" +
" \"time\": \"20240605181620\",\n" +
" \"nonce\": \"1204439618\",\n" +
" \"msgCode\": \"C001\",\n" +
" \"correlationSerialNum\": \"73b20360b6ed401faa8e185d6d56720f\"\n" +
"}");
/**
* {
* "correlationSerialNum": "9be7d98a-6848-4c24-84e5-1e2d8c0532a2",
* "data": {
* "page": 1,
* "pageSize": 20,
* "resourceID": 1112826,
* "result": {
* "content": [
* ["4120103088", "李胜", "/9j/4AAQSkZJRgABAgAAAQA", "2020-02-20 13:09:28", "2"]
* ],
* "head": "XGH,XM,ZP,ZPCJSJ,YHLB",
* "tablename": "V_XJ_NDXY_ZP"
* },
* "resultSize": 1,
* "source": "SSJH",
* "totalSize": 1* },
* "errCode": "0",
* "errMsg": "",
* "msgCode": "C001",
* "msgFromSysID": "SJJH",
* "msgToSysID": "YFMJ",
* "nonce": "1550375149",
* "reqSerialNum": "SJJH20240606161213417",
* "sign": "GEVvIRhDxxnIA68/+TTrTToDz58ZgZupHJuiCSnBQ9gZhXIuBsqW8NiDaZ4uyIz0TIRWaSuka4zUNLOz+edwOUI1G7PBYqjtbCuKubSjBYNoQ41CRbI7Ya29mPOxXi4vCxkai0h98R6urVVnTfHuZkW6OX8Gc0XRjh3qQFr0Qj8=",
* "time": "20240606161213"
* }
*/
//第一条//http://localhost:8018/api/test/realTimeDataRequest
//
// String res = RestTemplateUtils.postHttp(globalValue.getSyncA001(),params);
String res = RestTemplateUtils.postHttp("",params);
// String res = RestTemplateUtils.postHttp("http://localhost:8018/cell/api/test/realTimeDataRequest",params);
JSONObject resJson = JSONObject.parseObject(res);
//注意判断resJson是不是null
String errorCode = resJson.getString("errCode");
if(errorCode.equals("0")){
JSONObject data = resJson.getJSONObject("data");
int resultSize = data.getIntValue("resultSize");
if(resultSize>0){
//保存第一条
JSONObject result = data.getJSONObject("result");
JSONArray content = result.getJSONArray("content");
// JSONObject student = content.getJSONObject(0);
JSONArray student = content.getJSONArray(0);
// List<String> studentInfo = JSON.parseObject(content.getJSONObject(0).toJSONString(),new TypeReference<List<String>>(){});
String xh = (String)student.get(0);
String name = (String)student.get(1);
String picBase64 = (String)student.get(2);
TenPersonEntity tenPerson = new TenPersonEntity();
Date now = new Date();
long id = new SnowflakeIdWorker().nextId();
tenPerson.setPersonId(id);
tenPerson.setUuid(UUIDUtil.uuid());
tenPerson.setTenantId(cellEntity.getTenantId());
tenPerson.setCreateBy("sync");
tenPerson.setRegisterType(Constant.RESGISTER_TYPE_FILE);
tenPerson.setStatus(Constant.PESON_SUATUS_NOMOR);
tenPerson.setCreateTime(now);
tenPerson.setLastUpdateTime(now);
tenPerson.setName(name);
tenPerson.setGender(1);
tenPerson.setNation(1);
tenPerson.setCellId(cellEntity.getCellId());
tenPerson.setPersonType(5000);
tenPerson.setOpenId(xh);
try {
//保存原始图片
String userFileUrl = globalValue.getImagesDir() + "/" +
tenPerson.getCellId().toString() + "/" +
tenPerson.getPersonId().toString() + "/";
String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg";
byte[] b = Base64.getDecoder().decode(picBase64.replace("\n",""));
InputStream inputStream = new ByteArrayInputStream(b);
PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1);
putObjectOptions.setContentType("image/jpeg");
minioClient.putObject(
minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions);
inputStream.close();
tenPerson.setOrgImage(orgImageFileName);
tenPerson.setFaceImage(orgImageFileName);
tenPersonService.save3d(tenPerson);
} catch (Exception e) {
e.printStackTrace();
}
}
return resultSize;
}else{
return 0;
}
}
public int syncA001(TenCellEntity cellEntity,int pageIndex) {
//国资处
/**
* {
* "reqSerialNum": "YFMJ_202406051816209365",
* "data": {
* "resourceID": "1112826",
* "orderByParam": "",
* "pageSize": "20",
* "isUseStore": "Y",
* "page": "1",
* "increaseParam": "xgh='4120103088'"
* },
* "errCode": "",
* "msgToSysID": "YHZX",
* "errMsg": "",
* "sign": "BXu6sNoXfhx7/Aqqr+GK59z0DGwZeolN5klYz3TVrRZr4mlqddtVbMInjgAJLZRFpssnHiF/a9+66TztsDefJiDadWY3Ea1KFwjd5QLgeabVXy6qUF9Uv5kqRD5yzF3irREuDsOxbi4ryGf4L67tjnyvexatrwWdEmO4t4aRAgqPh6N7RkHqJ6STb5sbmzUACgLDOr4J0lEg7olGrzsN2vVwd63dYnXHDGp81jS+bj+1TqoIKX2+FkxlcJ5AGsl0TZ3LJ86Xs5dJucyRsfmRVKs1wBGHsQfQgpAaIHGr4CfbJzf4F+fAcopYD55qduWyjYp0rZoPzCeKbAKSa3owEw==",
* "msgFromSysID": "YFMJ",
* "time": "20240605181620",
* "nonce": "1204439618",
* "msgCode": "C001",
* "correlationSerialNum": "73b20360b6ed401faa8e185d6d56720f"
* }
*/
JSONObject params = JSONObject.parseObject("{\n" +
" \"reqSerialNum\": \"YFMJ_202406051816209365\",\n" +
" \"data\": {\n" +
" \"resourceID\": \"1112826\",\n" +
" \"orderByParam\": \"\",\n" +
" \"pageSize\": \"1\",\n" +
" \"isUseStore\": \"Y\",\n" +
" \"page\": \""+pageIndex+"\",\n" +
" \"increaseParam\": \"xgh='4120103088'\"\n" +
" },\n" +
" \"errCode\": \"\",\n" +
" \"msgToSysID\": \"YHZX\",\n" +
" \"errMsg\": \"\",\n" +
" \"sign\": \"BXu6sNoXfhx7/Aqqr+GK59z0DGwZeolN5klYz3TVrRZr4mlqddtVbMInjgAJLZRFpssnHiF/a9+66TztsDefJiDadWY3Ea1KFwjd5QLgeabVXy6qUF9Uv5kqRD5yzF3irREuDsOxbi4ryGf4L67tjnyvexatrwWdEmO4t4aRAgqPh6N7RkHqJ6STb5sbmzUACgLDOr4J0lEg7olGrzsN2vVwd63dYnXHDGp81jS+bj+1TqoIKX2+FkxlcJ5AGsl0TZ3LJ86Xs5dJucyRsfmRVKs1wBGHsQfQgpAaIHGr4CfbJzf4F+fAcopYD55qduWyjYp0rZoPzCeKbAKSa3owEw==\",\n" +
" \"msgFromSysID\": \"YFMJ\",\n" +
" \"time\": \"20240605181620\",\n" +
" \"nonce\": \"1204439618\",\n" +
" \"msgCode\": \"C001\",\n" +
" \"correlationSerialNum\": \"73b20360b6ed401faa8e185d6d56720f\"\n" +
"}");
/**
* {
* "correlationSerialNum": "9be7d98a-6848-4c24-84e5-1e2d8c0532a2",
* "data": {
* "page": 1,
* "pageSize": 20,
* "resourceID": 1112826,
* "result": {
* "content": [
* ["4120103088", "李胜", "/9j/4AAQSkZJRgABAgAAAQA", "2020-02-20 13:09:28", "2"]
* ],
* "head": "XGH,XM,ZP,ZPCJSJ,YHLB",
* "tablename": "V_XJ_NDXY_ZP"
* },
* "resultSize": 1,
* "source": "SSJH",
* "totalSize": 1* },
* "errCode": "0",
* "errMsg": "",
* "msgCode": "C001",
* "msgFromSysID": "SJJH",
* "msgToSysID": "YFMJ",
* "nonce": "1550375149",
* "reqSerialNum": "SJJH20240606161213417",
* "sign": "GEVvIRhDxxnIA68/+TTrTToDz58ZgZupHJuiCSnBQ9gZhXIuBsqW8NiDaZ4uyIz0TIRWaSuka4zUNLOz+edwOUI1G7PBYqjtbCuKubSjBYNoQ41CRbI7Ya29mPOxXi4vCxkai0h98R6urVVnTfHuZkW6OX8Gc0XRjh3qQFr0Qj8=",
* "time": "20240606161213"
* }
*/
//第一条//http://localhost:8018/api/test/realTimeDataRequest
// String res = RestTemplateUtils.postHttp("http://dapi.xjtu.edu.cn:8484/c001Service/realTimeDataRequest",params);
String res = RestTemplateUtils.postHttp("http://localhost:8018/cell/api/test/realTimeDataRequest",params);
JSONObject resJson = JSONObject.parseObject(res);
//注意判断resJson是不是null
String errorCode = resJson.getString("errCode");
if(errorCode.equals("0")){
JSONObject data = resJson.getJSONObject("data");
int totalSize = data.getIntValue("totalSize");
if(totalSize>0){
//保存第一条
JSONObject result = data.getJSONObject("result");
JSONArray content = result.getJSONArray("content");
// JSONObject student = content.getJSONObject(0);
JSONArray student = content.getJSONArray(0);
// List<String> studentInfo = JSON.parseObject(content.getJSONObject(0).toJSONString(),new TypeReference<List<String>>(){});
String xh = (String)student.get(0);
String name = (String)student.get(1);
String picBase64 = (String)student.get(2);
//判断人员是否重复
// List<TenPersonEntity> pList = tenPersonService.getByOpenId(xh);
List<TenPersonEntity> pList = new ArrayList<>();
//已经通不过不需在同步
if(pList.size()>0){
}else{
TenPersonEntity tenPerson = new TenPersonEntity();
Date now = new Date();
long id = new SnowflakeIdWorker().nextId();
tenPerson.setPersonId(id);
tenPerson.setUuid(UUIDUtil.uuid());
tenPerson.setTenantId(cellEntity.getTenantId());
tenPerson.setCreateBy("sync");
tenPerson.setRegisterType(Constant.RESGISTER_TYPE_FILE);
tenPerson.setStatus(Constant.PESON_SUATUS_NOMOR);
tenPerson.setCreateTime(now);
tenPerson.setLastUpdateTime(now);
tenPerson.setName(name);
tenPerson.setGender(1);
tenPerson.setNation(1);
tenPerson.setCellId(cellEntity.getCellId());
tenPerson.setPersonType(5000);
tenPerson.setOpenId(xh);
try {
//保存原始图片
String userFileUrl = globalValue.getImagesDir() + "/" +
tenPerson.getCellId().toString() + "/" +
tenPerson.getPersonId().toString() + "/";
String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg";
byte[] b = Base64.getDecoder().decode(picBase64.replace("\n",""));
InputStream inputStream = new ByteArrayInputStream(b);
PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1);
putObjectOptions.setContentType("image/jpeg");
minioClient.putObject(
minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions);
inputStream.close();
tenPerson.setOrgImage(orgImageFileName);
tenPerson.setFaceImage(orgImageFileName);
tenPersonService.save3d(tenPerson);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return totalSize;
}else{
return -1;
}
}
@Override
public void syncA001Batch(TenCellEntity cellEntity) {
int total = syncA001(cellEntity,1);
log.debug("同步inxex1");
if(total>1){
for(int i = 2;i<total;i++){
syncA001(cellEntity,i);
log.debug("同步inxex"+i);
}
}
}
}