#chabaodao-4# e签宝优化
This commit is contained in:
parent
71792ec032
commit
27732527f4
|
|
@ -0,0 +1,9 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.constant;
|
||||
|
||||
|
||||
public class Constants {
|
||||
public static String TENANT_KEY = "t024j0gfn0";
|
||||
public static String SysUserId = "1167276462243069953";
|
||||
|
||||
public static String templatePath = "/nfs/data/weatempfiles/downloadtemp";
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.constant;
|
||||
|
||||
import com.weaver.workflow.common.constant.list.requestlist.RequestListDimensionEnum;
|
||||
|
||||
public enum DownLoadTypeEnum {
|
||||
|
||||
INFORMATION("0","info", "info","签署文件下载"),
|
||||
CONTRACT("1","contract", "contract","签署文件下载"),
|
||||
INCOME("2","income", "income","签署文件下载"),
|
||||
EMPLOYMENT("3","employment", "employment","签署文件下载"),
|
||||
RESIGN("4","resign", "resign","签署文件下载");
|
||||
|
||||
private String code;
|
||||
private String type;
|
||||
|
||||
private String path;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private DownLoadTypeEnum(String code,String type, String path,String fileName) {
|
||||
this.code = code;
|
||||
this.type = type;
|
||||
this.path = path;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.seconddev.chapanda.hrm.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.hrm.constant.DownLoadTypeEnum;
|
||||
import com.weaver.seconddev.chapanda.hrm.service.HrmDownloadFilesService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/secondev/chapanda/hrm/cert")
|
||||
public class HrmCertificateFilesController {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(HrmCertificateFilesController.class);
|
||||
|
||||
@Autowired
|
||||
HrmDownloadFilesService hrmDownloadFilesService;
|
||||
|
||||
/***
|
||||
*
|
||||
* @param paramMap
|
||||
* @return
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@PostMapping("/getincomepath")
|
||||
public WeaResult<Object> getIncomePath(@RequestBody Map<String,Object> paramMap){
|
||||
String data = String.valueOf(paramMap.get("data"));
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
log.error("decodedData:{}",decodedData);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
String newZipFilePath = hrmDownloadFilesService.convertZipFile(dataArray, DownLoadTypeEnum.INCOME.getPath());
|
||||
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
dataMap.put("filepath",newZipFilePath);
|
||||
return WeaResult.success(dataMap);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 离职证明下载接口
|
||||
* @param paramMap
|
||||
* @return
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@PostMapping("/getresignpath")
|
||||
public WeaResult<Object> getResignPath(@RequestBody Map<String,Object> paramMap){
|
||||
String data = String.valueOf(paramMap.get("data"));
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
log.error("decodedData:{}",decodedData);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
String newZipFilePath = hrmDownloadFilesService.convertZipFile(dataArray, DownLoadTypeEnum.RESIGN.getPath());
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
dataMap.put("filepath",newZipFilePath);
|
||||
return WeaResult.success(dataMap);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 在职证明下载接口
|
||||
* @param paramMap
|
||||
* @return
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@PostMapping("/getemploymentpath")
|
||||
public WeaResult<Object> getEmploymentPath(@RequestBody Map<String,Object> paramMap){
|
||||
String data = String.valueOf(paramMap.get("data"));
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
String newZipFilePath = hrmDownloadFilesService.convertZipFile(dataArray,DownLoadTypeEnum.EMPLOYMENT.getPath());
|
||||
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
dataMap.put("filepath",newZipFilePath);
|
||||
return WeaResult.success(dataMap);
|
||||
}
|
||||
|
||||
|
||||
@WeaPermission(publicPermission = true)
|
||||
@PostMapping("/getcontractpath")
|
||||
public WeaResult<Object> getContractPath(@RequestBody Map<String,Object> paramMap){
|
||||
String data = String.valueOf(paramMap.get("data"));
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
String newZipFilePath = hrmDownloadFilesService.convertZipFile(dataArray, DownLoadTypeEnum.CONTRACT.getPath());
|
||||
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
dataMap.put("filepath",newZipFilePath);
|
||||
return WeaResult.success(dataMap);
|
||||
}
|
||||
|
||||
/***
|
||||
* 电子签名模板预览接口
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@GetMapping("/downloadZip")
|
||||
public ResponseEntity downloadZip(HttpServletRequest request) throws IOException{
|
||||
String data = request.getParameter("data");
|
||||
String type = request.getParameter("type");
|
||||
log.error("data2:{}",data);
|
||||
log.error("typ2e:{}",type);
|
||||
String filename = "";
|
||||
try{
|
||||
DownLoadTypeEnum[] values = DownLoadTypeEnum.values();
|
||||
for (DownLoadTypeEnum item : values) {
|
||||
log.error("item.getCode():{}",item.getCode());
|
||||
if(item.getCode().equals(type)){
|
||||
filename = DownLoadTypeEnum.INCOME.getFileName();
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(filename)){
|
||||
filename = URLEncoder.encode(filename, "UTF-8"); // 使用UTF-8编码
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
|
||||
log.error("filename2:{}",filename);
|
||||
|
||||
if(StringUtils.isNotBlank(filename)){
|
||||
log.error("data:{}",data);
|
||||
String zipFilePath = "";
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
zipFilePath = hrmDownloadFilesService.convertBase64Data(data);
|
||||
}
|
||||
log.error("zipFilePath:{}",zipFilePath);
|
||||
if(StringUtils.isNotBlank(zipFilePath) && zipFilePath.contains(Constants.templatePath) && new File(zipFilePath).exists()){
|
||||
// 文件转成字节数组
|
||||
File file = ResourceUtils.getFile(zipFilePath);
|
||||
byte[] fileBytes = Files.readAllBytes(file.toPath());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename2 = filename+"-"+sdf.format(new Date())+".zip";
|
||||
log.error("filename2:{}",filename2);
|
||||
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + new String(filename2.getBytes(), "UTF-8") + "\"")
|
||||
.body(fileBytes);
|
||||
}else{
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new String("文件下载失败".getBytes(), "utf-8"));
|
||||
}
|
||||
}else{
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new String("文件下载失败".getBytes(), "utf-8"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 测试接口
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@GetMapping("/test")
|
||||
public WeaResult<Object> test(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Map<String, Object> recordMap = new HashMap<String,Object>();
|
||||
recordMap.put("test","test");
|
||||
return WeaResult.success(recordMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,390 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.eteams.file.client.file.FileData;
|
||||
import com.weaver.eteams.file.client.file.FileObj;
|
||||
import com.weaver.file.ud.api.FileDownloadService;
|
||||
import com.weaver.seconddev.chapanda.hrm.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.hrm.service.HrmDownloadFilesService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import java.util.Base64;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/secondev/chapanda/hrm/info")
|
||||
public class HrmInformationFilesController {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(HrmInformationFilesController.class);
|
||||
|
||||
@Autowired
|
||||
private FileDownloadService fileDownloadService;
|
||||
|
||||
@Autowired
|
||||
HrmDownloadFilesService hrmDownloadFilesService;
|
||||
|
||||
@WeaPermission(publicPermission = true)
|
||||
@PostMapping("/getinformationpath")
|
||||
public WeaResult<Object> getInformationPath(@RequestBody Map<String,Object> paramMap){
|
||||
String data = String.valueOf(paramMap.get("data"));
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
log.error("decodedData:{}",decodedData);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = sdf.format(new Date())+".zip";
|
||||
|
||||
String directoryPath = Constants.templatePath+File.separator+sdf.format(new Date());
|
||||
// 将字符串路径转换为Path对象
|
||||
Path path = Paths.get(directoryPath);
|
||||
// 检查目录是否存在
|
||||
if (Files.notExists(path)) {
|
||||
try {
|
||||
Files.createDirectories(path);
|
||||
} catch (IOException e) {
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
}
|
||||
|
||||
String zipFilePath = directoryPath+File.separator+filename;
|
||||
try {
|
||||
log.error("path:{}",zipFilePath);
|
||||
FileOutputStream fos = new FileOutputStream(zipFilePath);
|
||||
ZipOutputStream zos = new ZipOutputStream(fos);
|
||||
for(int i=0;i<dataArray.size();i++){
|
||||
JSONObject dataObject = dataArray.getJSONObject(i);
|
||||
String jobNum = dataObject.getString("jobnum");
|
||||
String userName = dataObject.getString("username");
|
||||
String fileId = dataObject.getString("fileid");
|
||||
|
||||
log.error("fileId:{}",fileId);
|
||||
log.error("userName:{}",userName);
|
||||
log.error("jobNum:{}",jobNum);
|
||||
|
||||
if(StringUtils.isNotBlank(fileId)){
|
||||
try {
|
||||
FileData fileData = fileDownloadService.downloadFile(Long.parseLong(fileId));
|
||||
FileObj fileObj = fileData.getFileObj();
|
||||
// 获取文件的输入流
|
||||
InputStream inputStream = fileData.getInputStream();
|
||||
log.error("inputStream:{}",inputStream.available());
|
||||
String fileName = fileObj.getName();
|
||||
log.error("fileName:{}",fileName);
|
||||
byte[] filedata = hrmDownloadFilesService.convertInputStreamToBytes(inputStream);
|
||||
|
||||
addFileToZip(zos, filedata, fileName,jobNum,userName);
|
||||
} catch (IOException e) {
|
||||
log.error("e:" , e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zos.close();
|
||||
fos.close();
|
||||
}catch (IOException e){
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
|
||||
String newZipFilePath = "";
|
||||
File zipFile = new File(zipFilePath);
|
||||
if(zipFile.exists()){
|
||||
newZipFilePath = zipFile.getPath();
|
||||
}
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
dataMap.put("filepath",newZipFilePath);
|
||||
return WeaResult.success(dataMap);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 电子签名模板预览接口
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@GetMapping("/downloadZip")
|
||||
public ResponseEntity downloadZip(HttpServletRequest request) throws IOException{
|
||||
String data = request.getParameter("data");
|
||||
log.error("data:{}",data);
|
||||
String zipFilePath = "";
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
zipFilePath = hrmDownloadFilesService.convertBase64Data(data);
|
||||
}
|
||||
log.error("zipFilePath:{}",zipFilePath);
|
||||
if(StringUtils.isNotBlank(zipFilePath) && zipFilePath.contains(Constants.templatePath) && new File(zipFilePath).exists()){
|
||||
// 文件转成字节数组
|
||||
File file = ResourceUtils.getFile(zipFilePath);
|
||||
byte[] fileBytes = Files.readAllBytes(file.toPath());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = sdf.format(new Date())+".zip";
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
|
||||
.body(fileBytes);
|
||||
}else{
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new String("文件下载失败".getBytes(), "utf-8"));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/downloadZip2")
|
||||
public void downloadZip2(HttpServletRequest request,HttpServletResponse response) {
|
||||
try {
|
||||
String data = request.getParameter("data");
|
||||
log.error("data:{}",data);
|
||||
String zipFilePath = "";
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
zipFilePath = hrmDownloadFilesService.convertBase64Data(data);
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = sdf.format(new Date())+".zip";
|
||||
|
||||
log.error("zipFilePath:{}",zipFilePath);
|
||||
|
||||
File file = ResourceUtils.getFile(zipFilePath);
|
||||
byte[] fileBytes = Files.readAllBytes(file.toPath());
|
||||
|
||||
// 清空response
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
//Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
|
||||
//attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
|
||||
// filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
|
||||
// 告知浏览器文件的大小
|
||||
response.addHeader("Content-Length", "" + fileBytes);
|
||||
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
response.setContentType("application/octet-stream");
|
||||
outputStream.write(fileBytes);
|
||||
outputStream.flush();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 电子签名模板预览接口
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@GetMapping("/downloadFiles")
|
||||
public ResponseEntity<byte[]> downloadFiles(HttpServletRequest request){
|
||||
String data = request.getParameter("data");
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
log.error("decodedData:{}",decodedData);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
for(int i=0;i<dataArray.size();i++){
|
||||
JSONObject dataObject = dataArray.getJSONObject(i);
|
||||
String jobNum = dataObject.getString("jobnum");
|
||||
String userName = dataObject.getString("username");
|
||||
String fileId = dataObject.getString("fileid");
|
||||
|
||||
log.error("fileId:{}",fileId);
|
||||
log.error("userName:{}",userName);
|
||||
log.error("jobNum:{}",jobNum);
|
||||
|
||||
if(StringUtils.isNotBlank(fileId)){
|
||||
try {
|
||||
FileData fileData = fileDownloadService.downloadFile(Long.parseLong(fileId));
|
||||
FileObj fileObj = fileData.getFileObj();
|
||||
// 获取文件的输入流
|
||||
InputStream inputStream = fileData.getInputStream();
|
||||
log.error("inputStream:{}",inputStream.available());
|
||||
String fileName = fileObj.getName();
|
||||
log.error("fileName:{}",fileName);
|
||||
byte[] filedata = hrmDownloadFilesService.convertInputStreamToBytes(inputStream);
|
||||
|
||||
addFileToZip(zos, filedata, fileName,jobNum,userName);
|
||||
} catch (IOException e) {
|
||||
log.error("e:" , e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (IOException e){
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = sdf.format(new Date())+".zip";
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
|
||||
.body(baos.toByteArray());
|
||||
}
|
||||
|
||||
|
||||
// 将文件添加到zip输出流
|
||||
private void addFileToZip(ZipOutputStream zos, byte[] fileData, String entryName,String jobNum,String fileName) throws IOException {
|
||||
ZipEntry entry = new ZipEntry(fileName+"_"+jobNum+"/"+entryName);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(fileData);
|
||||
zos.closeEntry();
|
||||
}
|
||||
/**
|
||||
* 测试接口
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@WeaPermission(publicPermission = true)
|
||||
@GetMapping("/test")
|
||||
public WeaResult<Object> test(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Map<String, Object> recordMap = new HashMap<String,Object>();
|
||||
recordMap.put("test","test");
|
||||
return WeaResult.success(recordMap);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String originalString = "/nfs/data/weatempfiles/downloadtemp/1111/1111.zip";
|
||||
|
||||
//
|
||||
// String originalString = "[{\"fielid\":\"1169600692452909062\",\"jobnum\":\"10000000000\",\"username\":\"王文猛\"},{\"fielid\":\"1169600688166330369\",\"jobnum\":\"10000000000\",\"username\":\"王文猛\"},{\"fielid\":\"1167396240209780739\",\"jobnum\":\"1000002229\",\"username\":\"崔晓龙\"},{\"fielid\":\"1167650515133440001\",\"jobnum\":\"1000002805\",\"username\":\"刘琪琪\"},{\"fielid\":\"1167395969819779075\",\"jobnum\":\"1000003958\",\"username\":\"刘颖慧\"},{\"fielid\":\"1169538849218813953\",\"jobnum\":\"1000003958\",\"username\":\"刘颖慧\"},{\"fielid\":\"1169601053305659394\",\"jobnum\":\"1000003958\",\"username\":\"刘颖慧\"},{\"fielid\":\"1169543698203336705\",\"jobnum\":\"1000003958\",\"username\":\"刘颖慧\"},{\"fielid\":\"1169501139481452545\",\"jobnum\":\"1000004336\",\"username\":\"蒋欢\"},{\"fielid\":\"1167403559018602499\",\"jobnum\":\"1000004410\",\"username\":\"刘贤松\"},{\"fielid\":\"1167394818600771585\",\"jobnum\":\"1000004846\",\"username\":\"刘刚菊\"},{\"fielid\":\"1167389900896772097\",\"jobnum\":\"1000006146\",\"username\":\"周娟\"},{\"fielid\":\"1169540279359037441\",\"jobnum\":\"1000006146\",\"username\":\"周娟\"},{\"fielid\":\"1167718573191520257\",\"jobnum\":\"1000006146\",\"username\":\"周娟\"}]";
|
||||
// 将字符串转换为字节数组
|
||||
byte[] bytesToEncode = originalString.getBytes();
|
||||
|
||||
// 创建Base64编码器
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
|
||||
// 编码字节数组
|
||||
String encodedString = encoder.encodeToString(bytesToEncode);
|
||||
|
||||
System.out.println("Encoded String: " + encodedString);
|
||||
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
|
||||
// 解码Base64字符串
|
||||
byte[] bytesDecoded = decoder.decode(encodedString);
|
||||
|
||||
// 将字节数组转换回字符串
|
||||
String decodedString = new String(bytesDecoded);
|
||||
|
||||
System.out.println("Decoded String: " + decodedString);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param response
|
||||
* @功能描述 下载文件:
|
||||
*/
|
||||
@RequestMapping("/downloadFiles2")
|
||||
public void downloadFiles2(HttpServletRequest request,HttpServletResponse response) {
|
||||
try {
|
||||
String data = request.getParameter("data");
|
||||
log.error("data:{}",data);
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
String decodedData = hrmDownloadFilesService.convertBase64Data(data);
|
||||
log.error("decodedData:{}",decodedData);
|
||||
if(StringUtils.isNotBlank(decodedData)){
|
||||
try{
|
||||
dataArray = JSONArray.parseArray(decodedData);
|
||||
}catch (Exception e){
|
||||
log.error("{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.error("dataArray:{}",dataArray.size());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
for(int i=0;i<dataArray.size();i++){
|
||||
JSONObject dataObject = dataArray.getJSONObject(i);
|
||||
String jobNum = dataObject.getString("jobnum");
|
||||
String userName = dataObject.getString("username");
|
||||
String fileId = dataObject.getString("fileid");
|
||||
|
||||
log.error("fileId:{}",fileId);
|
||||
log.error("userName:{}",userName);
|
||||
log.error("jobNum:{}",jobNum);
|
||||
|
||||
if(StringUtils.isNotBlank(fileId)){
|
||||
try {
|
||||
FileData fileData = fileDownloadService.downloadFile(Long.parseLong(fileId));
|
||||
FileObj fileObj = fileData.getFileObj();
|
||||
// 获取文件的输入流
|
||||
InputStream inputStream = fileData.getInputStream();
|
||||
log.error("inputStream:{}",inputStream.available());
|
||||
String fileName = fileObj.getName();
|
||||
log.error("fileName:{}",fileName);
|
||||
byte[] filedata = hrmDownloadFilesService.convertInputStreamToBytes(inputStream);
|
||||
|
||||
addFileToZip(zos, filedata, fileName,jobNum,userName);
|
||||
} catch (IOException e) {
|
||||
log.error("e:" , e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = sdf.format(new Date())+".zip";
|
||||
|
||||
// 清空response
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
//Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
|
||||
//attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
|
||||
// filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
|
||||
// 告知浏览器文件的大小
|
||||
response.addHeader("Content-Length", "" + baos.size());
|
||||
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
response.setContentType("application/octet-stream");
|
||||
outputStream.write(baos.toByteArray());
|
||||
outputStream.flush();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public interface HrmDownloadFilesService {
|
||||
|
||||
byte[] convertInputStreamToBytes(InputStream inputStream);
|
||||
|
||||
String convertBase64Data(String base64Data);
|
||||
|
||||
String convertZipFile(JSONArray dataArray, String downloadType);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.eteams.file.client.file.FileData;
|
||||
import com.weaver.eteams.file.client.file.FileObj;
|
||||
import com.weaver.file.ud.api.FileDownloadService;
|
||||
import com.weaver.seconddev.chapanda.hrm.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.hrm.service.HrmDownloadFilesService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/***
|
||||
* author:shil
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class HrmDownloadFilesServiceImpl implements HrmDownloadFilesService {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(HrmDownloadFilesServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
HrmDownloadFilesService hrmDownloadFilesService;
|
||||
|
||||
@Autowired
|
||||
private FileDownloadService fileDownloadService;
|
||||
|
||||
/***
|
||||
* 将InputStream转换为byte[]
|
||||
* @param inputStream
|
||||
* @return
|
||||
*/
|
||||
public byte[] convertInputStreamToBytes(InputStream inputStream) {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
try{
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
byteStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
log.error("byteStream:{}",byteStream.toByteArray().length);
|
||||
}catch (IOException e) {
|
||||
log.error("e:{}",e.getMessage());
|
||||
}
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param base64Data
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String convertBase64Data(String base64Data) {
|
||||
String decodedData = "";
|
||||
try{
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
// 解码Base64字符串
|
||||
byte[] bytesDecoded = decoder.decode(base64Data);
|
||||
// 将字节数组转换回字符串
|
||||
decodedData = new String(bytesDecoded, StandardCharsets.UTF_8);
|
||||
}catch (Exception e){
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
return decodedData;
|
||||
}
|
||||
|
||||
|
||||
public String convertZipFile(JSONArray dataArray,String downloadType) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = sdf.format(new Date())+".zip";
|
||||
|
||||
String directoryPath = Constants.templatePath+ File.separator+downloadType+File.separator+sdf.format(new Date());
|
||||
// 将字符串路径转换为Path对象
|
||||
Path path = Paths.get(directoryPath);
|
||||
// 检查目录是否存在
|
||||
if (Files.notExists(path)) {
|
||||
try {
|
||||
Files.createDirectories(path);
|
||||
} catch (IOException e) {
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
}
|
||||
|
||||
String zipFilePath = directoryPath+File.separator+filename;
|
||||
FileOutputStream fos = null;
|
||||
ZipOutputStream zos = null;
|
||||
try {
|
||||
log.error("path:{}",zipFilePath);
|
||||
fos = new FileOutputStream(zipFilePath);
|
||||
zos = new ZipOutputStream(fos);
|
||||
for(int i=0;i<dataArray.size();i++){
|
||||
JSONObject dataObject = dataArray.getJSONObject(i);
|
||||
String fileId = dataObject.getString("fileid");
|
||||
log.error("fileId:{}",fileId);
|
||||
if(StringUtils.isNotBlank(fileId)){
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
FileData fileData = fileDownloadService.downloadFile(Long.parseLong(fileId));
|
||||
FileObj fileObj = fileData.getFileObj();
|
||||
// 获取文件的输入流
|
||||
inputStream = fileData.getInputStream();
|
||||
log.error("inputStream:{}",inputStream.available());
|
||||
String fileName = fileObj.getName();
|
||||
log.error("fileName:{}",fileName);
|
||||
byte[] filedata = hrmDownloadFilesService.convertInputStreamToBytes(inputStream);
|
||||
|
||||
addFileToZip(zos, filedata, fileName);
|
||||
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("e:" , e);
|
||||
}finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
zos.close();
|
||||
fos.close();
|
||||
}catch (IOException e){
|
||||
log.error("e:{}",e);
|
||||
}finally {
|
||||
try {
|
||||
if (zos != null) {
|
||||
zos.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("e:{}",e);
|
||||
}
|
||||
}
|
||||
|
||||
String newZipFilePath = "";
|
||||
File zipFile = new File(zipFilePath);
|
||||
if(zipFile.exists()){
|
||||
newZipFilePath = zipFile.getPath();
|
||||
}
|
||||
return newZipFilePath;
|
||||
}
|
||||
|
||||
// 将文件添加到zip输出流
|
||||
private void addFileToZip(ZipOutputStream zos, byte[] fileData, String entryName) throws IOException {
|
||||
// ZipEntry entry = new ZipEntry(fileName+"_"+jobNum+"/"+entryName);
|
||||
ZipEntry entry = new ZipEntry(entryName);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(fileData);
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String data = "L25mcy9kYXRhL3dlYXRlbXBmaWxlcy9kb3dubG9hZHRlbXAvcmVzaWduLzIwMjUwODI2MTczNjU3L+emu+iBjOivgeaYji0yMDI1MDgyNjE3MzY1Ny56aXA=";
|
||||
HrmDownloadFilesServiceImpl HrmDownloadFilesServiceImpl = new HrmDownloadFilesServiceImpl();
|
||||
String decodedData = HrmDownloadFilesServiceImpl.convertBase64Data(data);
|
||||
System.out.println(decodedData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,430 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class CommonUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(CommonUtils.class);
|
||||
|
||||
public static JSONObject toJSON(String data){
|
||||
if(!StringUtils.isEmpty(data)){
|
||||
try {
|
||||
return JSONObject.parseObject(data);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Long getJSONLong(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getLong(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getJSONInteger(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getInteger(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static String getJSONString(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return null2String(json.getString(key));
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getJSONObject(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONArray getJSONArray(JSONObject json, String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getJSONArray(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(JSONArray json, int idx){
|
||||
if(json != null && json.size() > idx){
|
||||
try {
|
||||
return json.getJSONObject(idx);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String mapToStrData(Map<String, Object> para){
|
||||
if(para != null) {
|
||||
return JSONObject.toJSON(para).toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void strToLongList(List<Long> list,String strs){
|
||||
strToLongList(list,strs,true);
|
||||
}
|
||||
|
||||
public static void strToLongList(List<Long> list,String strs,boolean isDist){
|
||||
if(list == null){
|
||||
return;
|
||||
}
|
||||
if(StringUtils.isEmpty(strs)){
|
||||
return;
|
||||
}
|
||||
|
||||
String[] strList = StringUtils.split(strs, ",");
|
||||
for(String str:strList){
|
||||
if(StringUtils.isEmpty(str)){
|
||||
continue;
|
||||
}
|
||||
|
||||
long id = getLongValue(str);
|
||||
if(id > 0l && (isDist == false || !list.contains(id))){
|
||||
list.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLongValue(Object v){
|
||||
return getLongValue(null2String(v));
|
||||
}
|
||||
|
||||
public static long getLongValue(String v) {
|
||||
return getLongValue(v, -1);
|
||||
}
|
||||
|
||||
public static long getLongValue(String v, long def) {
|
||||
try {
|
||||
return Long.parseLong(v);
|
||||
} catch (Exception ex) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIntValue(Object o){
|
||||
return getIntValue(null2String(o));
|
||||
}
|
||||
|
||||
public static int getIntValue(String s){
|
||||
return getIntValue(s,-1);
|
||||
}
|
||||
|
||||
public static int getIntValue(String s, int def){
|
||||
try {
|
||||
return NumberUtils.toInt(s);
|
||||
} catch (Exception ex) {
|
||||
return def;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String null2String(Object s) {
|
||||
return s == null ? "" : s.toString();
|
||||
}
|
||||
|
||||
public static String null2String(Object s, String def) {
|
||||
return s == null ? (def == null ? "" : def) : s.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String stringReplace(String sou, String s1, String s2) {
|
||||
//int idx = sou.indexOf(s1);
|
||||
//if (idx < 0) {
|
||||
// return sou;
|
||||
//}
|
||||
//return sou.substring(0, idx) + s2 + StringReplace(sou.substring(idx + s1.length()), s1, s2);
|
||||
sou = null2String(sou);
|
||||
s1 = null2String(s1);
|
||||
s2 = null2String(s2);
|
||||
try{
|
||||
sou = sou.replace(s1, s2);
|
||||
}catch(Exception e){
|
||||
//System.out.println(e);//将未知异常打印出来,便于检查错误。
|
||||
}
|
||||
return sou;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊字符
|
||||
*
|
||||
* @param s 要替换特殊的字符串
|
||||
* @return 替换完成的字符串
|
||||
*/
|
||||
public static String toScreen(String s) {
|
||||
char c[] = s.toCharArray();
|
||||
char ch;
|
||||
int i = 0;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
while (i < c.length) {
|
||||
ch = c[i++];
|
||||
|
||||
if (ch == '\r')
|
||||
buf.append("");
|
||||
else if (ch == '\n')
|
||||
buf.append("");
|
||||
else
|
||||
buf.append(ch);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊字符
|
||||
*
|
||||
* @param s 要替换特殊的字符串
|
||||
* @return 替换完成的字符串
|
||||
*/
|
||||
public static String toExcel(String s) {
|
||||
if (s == null) return "";
|
||||
//因本方法会将字符串 &符号转换,故先将欧元符号转义符转换为其Unicode码
|
||||
s = s.replaceAll("€", "\u20AC");
|
||||
String str = toScreen(s);
|
||||
str = stringReplace(str, "∠", "∠");
|
||||
str = stringReplace(str, "φ", "φ");
|
||||
str = stringReplace(str, """, "\"");
|
||||
str = stringReplace(str, " ", "%nbsp");
|
||||
//str=Util.StringReplace(str,"'","‘");
|
||||
str = stringReplace(str, "<", "<");
|
||||
str = stringReplace(str, ">", ">");
|
||||
str = stringReplace(str, "&dt;&at;", "<br>");
|
||||
str = stringReplace(str, "&", "&");
|
||||
str = stringReplace(str, "<br>", "&dt;&at;");
|
||||
if ("&dt;&at;".equals(str)) {
|
||||
str = "";
|
||||
}
|
||||
//在方法最后,又将欧元符号置换为转义符
|
||||
str = str.replaceAll("\u20AC", "€");
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String delHtml(final String inputString) {
|
||||
String htmlStr = toExcel(inputString); // 含html标签的字符串
|
||||
|
||||
String textStr = "";
|
||||
java.util.regex.Pattern p_script;
|
||||
java.util.regex.Matcher m_script;
|
||||
java.util.regex.Pattern p_html;
|
||||
java.util.regex.Matcher m_html;
|
||||
|
||||
try {
|
||||
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
|
||||
|
||||
String regEx_script = "<[/s]*?script[^>]*?>[/s/S]*?<[/s]*?//[/s]*?script[/s]*?>"; // 定义script的正则表达式{或<script[^>]*?>[/s/S]*?<//script>
|
||||
|
||||
p_script = java.util.regex.Pattern.compile(regEx_script, java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
m_script = p_script.matcher(htmlStr);
|
||||
htmlStr = m_script.replaceAll(""); // 过滤script标签
|
||||
|
||||
p_html = java.util.regex.Pattern.compile(regEx_html, java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
m_html = p_html.matcher(htmlStr);
|
||||
htmlStr = m_html.replaceAll(""); // 过滤html标签
|
||||
|
||||
textStr = htmlStr;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Html2Text: " + e.getMessage());
|
||||
}
|
||||
|
||||
return htmlToTxt(textStr).trim();// 返回文本字符串
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字符串中的html格式
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static String htmlToTxt(String input) {
|
||||
if (input == null || input.trim().equals("")) {
|
||||
return "";
|
||||
}
|
||||
// 去掉所有html元素,
|
||||
String str = input.replaceAll("<[a-zA-Z]+[1-9]?[^><]*>", "");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
//==new=
|
||||
|
||||
public static int getIntValue(Object s, int def){
|
||||
return getIntValue(null2String(s));
|
||||
}
|
||||
|
||||
public static List<Long> strToLongList(String strs){
|
||||
List<Long> list = new ArrayList<Long>();
|
||||
strToLongList(list,strs,true);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static int dateInterval(String fromdate, String todate) {
|
||||
Calendar fromcalendar = getCalendar(fromdate);
|
||||
Calendar tocalendar = getCalendar(todate);
|
||||
|
||||
if (fromcalendar == null || tocalendar == null)
|
||||
return 0;
|
||||
|
||||
return (int) ((tocalendar.getTimeInMillis() - fromcalendar.getTimeInMillis()) / 3600 / 24 / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param datetime - 给定的日期时间,格式为 '2004-05-12 12:00:23' 或者 '2004-05-12'
|
||||
* @return 返回给定日历, 如果格式不正确,返回null
|
||||
*/
|
||||
public static Calendar getCalendar(String datetime) {
|
||||
int datetimelength = datetime.length() ;
|
||||
|
||||
switch(datetimelength) {
|
||||
case 19 :
|
||||
return getCalendar(datetime , "yyyy'-'MM'-'dd' 'HH:mm:ss") ;
|
||||
case 10 :
|
||||
return getCalendar(datetime , "yyyy'-'MM'-'dd") ;
|
||||
default :
|
||||
return null ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param datetime - 给定的日期时间
|
||||
* @param formart - 给定的日期时间的格式
|
||||
* @return 返回给定日历, 如果格式不正确,返回null
|
||||
*/
|
||||
public static Calendar getCalendar(String datetime, String formart) {
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(formart) ;
|
||||
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
try {
|
||||
calendar.setTime(SDF.parse(datetime)) ;
|
||||
} catch (ParseException e) {
|
||||
return null ;
|
||||
}
|
||||
|
||||
return calendar ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回当前时间字符,格式为 yyyy'-'MM'-'dd
|
||||
*
|
||||
* 返回当前时间字符,默认格式为yyyy'-'MM'-'dd
|
||||
*
|
||||
* 如 2004-09-07
|
||||
*/
|
||||
public static String getCurrentDateString() {
|
||||
String timestrformart = "yyyy'-'MM'-'dd" ;
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(timestrformart) ;
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
|
||||
return SDF.format(calendar.getTime()) ;
|
||||
}
|
||||
|
||||
public static String getMessage(String msgMode,String key,String val){
|
||||
key = null2String(key).trim();
|
||||
val = null2String(val).trim();
|
||||
msgMode = null2String(msgMode).trim();
|
||||
if(!"".equals(msgMode) && !"".equals(key)) {
|
||||
msgMode = msgMode.replaceAll(key, val);
|
||||
}
|
||||
return msgMode;
|
||||
}
|
||||
|
||||
public static List<Long> tranStrToLongList(Object idListObj){
|
||||
List<Long> docIds = new ArrayList<Long>();
|
||||
if(idListObj != null) {
|
||||
try {
|
||||
JSONArray idObjs = JSONArray.parseArray(null2String(idListObj));
|
||||
for (Object idObj : idObjs) {
|
||||
long id = getLongValue(idObj);
|
||||
if (id > 0l) {
|
||||
docIds.add(id);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("trans error :{}", idListObj);
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return docIds;
|
||||
}
|
||||
|
||||
public Map<String, Object> requestToMap(HttpServletRequest request) {
|
||||
Map<String, String[]> properties = request.getParameterMap();//把请求参数封装到Map<String, String[]>中
|
||||
Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
Iterator<Map.Entry<String, String[]>> iter = properties.entrySet().iterator();
|
||||
String name = "";
|
||||
String value = "";
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, String[]> entry = iter.next();
|
||||
name = entry.getKey();
|
||||
Object valueObj = entry.getValue();
|
||||
if (null == valueObj) {
|
||||
value = "";
|
||||
} else if (valueObj instanceof String[]) {
|
||||
String[] values = (String[]) valueObj;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
value = values[i] + ",";
|
||||
}
|
||||
value = value.substring(0, value.length() - 1);
|
||||
} else {
|
||||
value = valueObj.toString();
|
||||
}
|
||||
returnMap.put(name, value);
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
|
||||
public Long convertStringToLong(String str) {
|
||||
try {
|
||||
return Long.valueOf(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,366 @@
|
|||
package com.weaver.seconddev.chapanda.hrm.util;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.ebuilder.datasource.api.entity.ExecuteSqlEntity;
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SourceType;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SqlParamType;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.DynamicParamDto;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.FieldQuery;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.GroupQuery;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.TableQuery;
|
||||
import com.weaver.ebuilder.datasource.api.service.DataSetService;
|
||||
import com.weaver.ebuilder.datasource.api.service.impl.EbFormDataService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* DatabaseUtil 是一个数据库工具类,提供了一些执行 SQL 查询和操作的方法。
|
||||
*/
|
||||
|
||||
|
||||
@Component
|
||||
public class DatabaseUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(DatabaseUtils.class);
|
||||
|
||||
@Autowired
|
||||
private DataSetService dataSetService;
|
||||
|
||||
@Autowired
|
||||
private EbFormDataService dataService;
|
||||
|
||||
|
||||
/**
|
||||
* 执行 SQL 并返回结果。
|
||||
*
|
||||
* @param entity 包含执行 SQL 的相关信息的对象
|
||||
* @return 包含查询结果的 Map 对象
|
||||
* @throws RuntimeException 当 SQL 执行失败时抛出异常
|
||||
*/
|
||||
public Map<String, Object> executeSql(ExecuteSqlEntity entity) {
|
||||
Map<String, Object> map = dataSetService.executeSql(entity);
|
||||
if ("FAIL".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT))) {
|
||||
log.error("sql执行失败=>{}", JSONObject.toJSONString(map));
|
||||
throw new RuntimeException("sql执行异常");
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行分页 SQL 查询并返回结果。
|
||||
*
|
||||
* @param entity 包含执行 SQL 和分页信息的对象
|
||||
* @param pageNo 当前页码
|
||||
* @param pageSize 每页的数据条数
|
||||
* @return 包含查询结果的 Map 对象
|
||||
* @throws RuntimeException 当 SQL 执行失败时抛出异常
|
||||
*/
|
||||
public Map<String, Object> executeSql(ExecuteSqlEntity entity, int pageNo, int pageSize) {
|
||||
entity.setPageNo(pageNo);
|
||||
entity.setPageSize(pageSize);
|
||||
Map<String, Object> map = dataSetService.executeForQuery(entity);
|
||||
if ("FAIL".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT))) {
|
||||
log.error("sql执行失败=>{}", JSONObject.toJSONString(map));
|
||||
throw new RuntimeException("sql执行异常");
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个包含执行 SQL 的对象。
|
||||
*
|
||||
* @param sql 需要执行的 SQL
|
||||
* @param groupId 数据源分组的 ID
|
||||
* @paramDesc 数据源分组的 ID 获取方式 【select APPLICATION_MARK,APPLICATION_name from eteams.ds_mark_service_relation】
|
||||
* @return 包含执行 SQL 的对象
|
||||
*/
|
||||
public ExecuteSqlEntity getExecuteSqlEntity(String sql, String groupId) {
|
||||
log.error("sql=>{}", sql);
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.LOGIC);
|
||||
executeSqlEntity.setGroupKey("0");
|
||||
return executeSqlEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 SQL 进行 Base64 编码。
|
||||
*
|
||||
* @param sql 需要进行编码的 SQL
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
public String base64(String sql) {
|
||||
return Base64.encode(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源列表。
|
||||
*
|
||||
* @param map 包含数据源列表信息的 Map 对象
|
||||
* @return 数据源列表的 Map 对象
|
||||
*/
|
||||
public List<Map<String, Object>> getDataSourceList(Map<String, Object> map) {
|
||||
List<Map<String, Object>> entity = new ArrayList();
|
||||
if ("OK".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT)) && map.get("count") != null && CommonUtils.getIntValue(map.get("count")) > 0) {
|
||||
entity = (List) map.get("records");
|
||||
}
|
||||
|
||||
return keyToLowerCase((List) entity);
|
||||
}
|
||||
|
||||
public Map<String, Object> getOneDataSource(Map<String, Object> map) {
|
||||
List<Map<String, Object>> entity = getDataSourceList(map);
|
||||
return (Map)(CollectionUtil.isNotEmpty(entity) ? (Map)entity.get(0) : new HashMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Map 对象中的键转换为小写。
|
||||
*
|
||||
* @param orgMapList 需要转换键的 Map 对象列表
|
||||
* @return 转换后的 Map 对象列表
|
||||
*/
|
||||
public List<Map<String, Object>> keyToLowerCase(List<Map<String, Object>> orgMapList) {
|
||||
List<Map<String, Object>> resultList = new ArrayList();
|
||||
Iterator var2 = orgMapList.iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
Map<String, Object> stringObjectMap = (Map) var2.next();
|
||||
resultList.add(keyToLowerCase(stringObjectMap));
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Map 对象中的键转换为小写。
|
||||
*
|
||||
* @param orgMap 需要转换键的 Map 对象
|
||||
* @return 转换后的 Map 对象
|
||||
*/
|
||||
public Map<String, Object> keyToLowerCase(Map<String, Object> orgMap) {
|
||||
Map<String, Object> resultMap = new HashMap();
|
||||
if (orgMap != null && !orgMap.isEmpty()) {
|
||||
Set<Map.Entry<String, Object>> entrySet = orgMap.entrySet();
|
||||
Iterator var3 = entrySet.iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
Map.Entry<String, Object> entry = (Map.Entry) var3.next();
|
||||
String key = (String) entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
resultMap.put(key.toLowerCase(), value);
|
||||
}
|
||||
return resultMap;
|
||||
} else {
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据数据库类型 找到对应数据库
|
||||
*
|
||||
* @param sourceType sourceType 枚举类
|
||||
* ETEAMS :数据仓库
|
||||
* FORM: ebuilder表单
|
||||
* LOGIC: 各模块提供业务数据(逻辑表)
|
||||
* EXTERNAL: 外部数据源
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getDataGroups(String sourceType, Boolean flag) {
|
||||
GroupQuery query = new GroupQuery();
|
||||
query.setSourceType(SourceType.valueOf(sourceType));
|
||||
query.setShowSqlDataset(flag);
|
||||
|
||||
|
||||
DynamicParamDto dynamicParamDto = new DynamicParamDto();
|
||||
dynamicParamDto.setUserId(10000L);
|
||||
dynamicParamDto.setTenantKey("tk");
|
||||
|
||||
query.setDynamicParamDto(dynamicParamDto);
|
||||
|
||||
return dataSetService.getDataGroups(query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据表
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getDataSets(String sourceType, String groupId, Integer pageNum, Integer pageSize) {
|
||||
|
||||
TableQuery tableQuery = new TableQuery();
|
||||
tableQuery.setSourceType(SourceType.valueOf(sourceType));
|
||||
tableQuery.setGroupId(groupId);
|
||||
//非必传
|
||||
//tableQuery.setName(name);
|
||||
tableQuery.setPageNo(pageNum);
|
||||
tableQuery.setPageSize(pageSize);
|
||||
return dataSetService.getDataSetsByPage(tableQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段
|
||||
* sourceType :LOGIC
|
||||
* sourceId : 8494845523559165780
|
||||
* groupId : weaver-crm-service
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getFields(String sourceType, String sourceId, String groupId) {
|
||||
FieldQuery query = new FieldQuery();
|
||||
query.setSourceType(SourceType.valueOf(sourceType));
|
||||
query.setSourceId(sourceId);
|
||||
query.setGroupId(groupId);
|
||||
return dataSetService.getFields(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql
|
||||
* sourceType :LOGIC
|
||||
* groupId : weaver-ebuilder-app-service
|
||||
* sql : select * from ebda_app limit 10
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> execute(String sourceType, String groupId, String sql) {
|
||||
//执行sql 参数sourceType groupId sql
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
return dataSetService.executeSql(executeSqlEntity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> executeUpdate(String sourceType, String groupId, String sql) {
|
||||
//执行sql 参数sourceType groupId sql
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
return dataSetService.executeForUpdate(executeSqlEntity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> executeForQuery(String sourceType, String groupId, String sql,List<SqlParamEntity> sqlparam) {
|
||||
//执行sql 参数sourceType groupId sql sqlparam
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
executeSqlEntity.setParams(sqlparam);
|
||||
return dataSetService.executeSql(executeSqlEntity);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param sql
|
||||
* @param sqlparam
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> executeForUpdate(String sourceType, String groupId, String sql,List<SqlParamEntity> sqlparam) {
|
||||
//执行sql 参数sourceType groupId sql sqlparam
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
executeSqlEntity.setParams(sqlparam);
|
||||
return dataSetService.executeForUpdate(executeSqlEntity);
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sql
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public String getMysqlPagedSql(String sql,int pageNo, int pageSize) {
|
||||
if(pageNo<=0){
|
||||
pageNo = 1;
|
||||
}
|
||||
|
||||
if(pageSize<=0){
|
||||
pageSize = 20;
|
||||
}
|
||||
|
||||
int start = (pageNo-1)*pageSize;
|
||||
int end = pageNo*pageSize;
|
||||
|
||||
return new StringBuffer().append(sql).append(
|
||||
" LIMIT "+start+","+(end-start)).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取sql入参
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public List<SqlParamEntity> querySqlParamEntity(List<String> list){
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
for (String str : list){
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(str);
|
||||
sqlparam.add(sqlParamEntity);
|
||||
}
|
||||
return sqlparam;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param dataSql
|
||||
* @param paramList
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getSqlList(String sourceType,String groupId,String dataSql,List<String> paramList){
|
||||
List<SqlParamEntity> sqlParamList = querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = getDataSourceList(result);
|
||||
return recordList;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param dataSql
|
||||
* @param paramList
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getSqlMap(String sourceType,String groupId,String dataSql,List<String> paramList){
|
||||
Map<String, Object> recordMap = new HashMap<String, Object>();
|
||||
List<SqlParamEntity> sqlParamList = querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = getDataSourceList(result);
|
||||
if(recordList.size() > 0){
|
||||
recordMap = recordList.get(0);
|
||||
}
|
||||
return recordMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -76,4 +76,7 @@ public class Constants {
|
|||
|
||||
public static String assessment360Table = "uf_cpjg";
|
||||
|
||||
public static String zpssyfzd = "extzhaoxushishiyuefen_431582_1686993167";
|
||||
public static String jjcdzdm = "extzhaopinjinjidu_431582_1886847991";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class HrmPerformanceDao {
|
|||
|
||||
String dataSql =" select hiredate as rzrq,zhgzr as lzrq,zzrq,personnel_status as ryzt,subcompany as gs,yjbm as bm1,ejbm as bm2,sanjbm as bm3,sijbm as bm4,rylb,location as gzdd" +
|
||||
" from uf_jcl_employee_information \n" +
|
||||
" where id = ? " +
|
||||
" where glzzyg = ? " +
|
||||
" and tenant_key = ? \n" +
|
||||
" and delete_type = 0 " ;
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ public class Esb2BeisenJobRequirementAction implements EsbServerlessRpcRemoteInt
|
|||
String xqmc = (String) params.get("xqmc");
|
||||
String gzzz = String.valueOf(params.get("gzzz"));
|
||||
String rzzg = String.valueOf(params.get("rzzg "));
|
||||
String zxssyf = String.valueOf(params.get("zxssyf"));
|
||||
String jjcd = String.valueOf(params.get("jjcd"));
|
||||
|
||||
log.error("orgId:" + orgId);
|
||||
String dataId = jobRequirement2BeisenUtil.sendJobRequirement(requirementStatus,requirementType,
|
||||
|
|
@ -189,7 +191,7 @@ public class Esb2BeisenJobRequirementAction implements EsbServerlessRpcRemoteInt
|
|||
workExperience,
|
||||
kind,
|
||||
isSecrecy,
|
||||
originalCode,nlyq,zpgw,zwmc,beisenDutyUserId,xqmc,gzzz,rzzg);
|
||||
originalCode,nlyq,zpgw,zwmc,beisenDutyUserId,xqmc,gzzz,rzzg,zxssyf,jjcd);
|
||||
|
||||
log.error("dataId:" + dataId);
|
||||
// if(StringUtils.isNotBlank(dataId)){
|
||||
|
|
|
|||
|
|
@ -71,8 +71,11 @@ public class Esb2BeisenJobRequirementCreateAction implements EsbServerlessRpcRem
|
|||
|
||||
String nlyq = String.valueOf(params.get("nlyq"));
|
||||
|
||||
|
||||
String zpgw = String.valueOf(params.get("zpgw"));
|
||||
String zwmc = String.valueOf(params.get("zwmc"));
|
||||
String zxssyf = String.valueOf(params.get("zxssyf"));
|
||||
String jjcd = String.valueOf(params.get("jjcd"));
|
||||
|
||||
log.error("requirementStatus:" + requirementStatus);
|
||||
log.error("originalId:" + originalId);
|
||||
|
|
@ -159,9 +162,10 @@ public class Esb2BeisenJobRequirementCreateAction implements EsbServerlessRpcRem
|
|||
}
|
||||
|
||||
String gzzz = String.valueOf(params.get("gzzz"));
|
||||
String rzzg = String.valueOf(params.get("rzzg "));
|
||||
|
||||
String rzzg = String.valueOf(params.get("rzzg"));
|
||||
log.error("rzzg:" + rzzg);
|
||||
log.error("orgId:" + orgId);
|
||||
|
||||
String dataId = jobRequirement2BeisenUtil.sendJobRequirement(requirementStatus,requirementType,
|
||||
requestname,beisenCreateUserId,
|
||||
createDate,requirementCount,
|
||||
|
|
@ -182,7 +186,8 @@ public class Esb2BeisenJobRequirementCreateAction implements EsbServerlessRpcRem
|
|||
beisenDutyUserId,
|
||||
xqmc,
|
||||
gzzz,
|
||||
rzzg);
|
||||
rzzg,zxssyf,jjcd
|
||||
);
|
||||
|
||||
|
||||
log.error("dataId:" + dataId);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/***
|
||||
* 废弃,由雪峰重写了
|
||||
*/
|
||||
@Service("Esb2BeisenOfferCronJob")
|
||||
public class Esb2BeisenOfferCronJob implements EsbServerlessRpcRemoteInterface {
|
||||
private final static Logger log = LoggerFactory.getLogger(Esb2BeisenOfferCronJob.class);
|
||||
|
|
|
|||
|
|
@ -78,6 +78,16 @@ public class Esb2BeisenPerformanceCronJobNew implements EsbServerlessRpcRemoteIn
|
|||
fieldList.add("ppdj");
|
||||
fieldList.add("jxhdid");
|
||||
|
||||
fieldList.add("rzrq");
|
||||
fieldList.add("lzrq");
|
||||
fieldList.add("zzrq");
|
||||
fieldList.add("ryzt");
|
||||
fieldList.add("gs");
|
||||
fieldList.add("bm1");
|
||||
fieldList.add("bm2");
|
||||
fieldList.add("bm3");
|
||||
fieldList.add("bm4");
|
||||
fieldList.add("gzdd");
|
||||
|
||||
String token = token2BeiSenUtil.getToken();
|
||||
log.error("token:{}",token);
|
||||
|
|
@ -380,6 +390,8 @@ public class Esb2BeisenPerformanceCronJobNew implements EsbServerlessRpcRemoteIn
|
|||
Map.Entry<String, Object> entry = iterator.next();
|
||||
String emKey = entry.getKey();
|
||||
String emValue = entry.getValue().toString();
|
||||
log.error("emKey:{}",emKey);
|
||||
log.error("emValue:{}",emValue);
|
||||
dataJson.put(emKey,emValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ public class JobRequirement2BeisenUtil {
|
|||
int beisenDutyUserId,
|
||||
String xqmc,
|
||||
String gzzz,
|
||||
String rzzg
|
||||
String rzzg,
|
||||
String zxssyf,
|
||||
String jjcd
|
||||
){
|
||||
String data = "";
|
||||
String token = token2BeiSenUtil.getToken();
|
||||
|
|
@ -177,6 +179,10 @@ public class JobRequirement2BeisenUtil {
|
|||
JSONObject customProperties = new JSONObject();
|
||||
customProperties.put(Constants.nyyqzdm,nlyq);
|
||||
customProperties.put(Constants.zwzd,zwmc);
|
||||
|
||||
customProperties.put(Constants.zpssyfzd,zxssyf);
|
||||
customProperties.put(Constants.jjcdzdm,jjcd);
|
||||
|
||||
bodyJson.put("customProperties",customProperties);
|
||||
}
|
||||
log.error("beisenDutyUserId:{}",beisenDutyUserId);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.weaver.seconddev.chapanda.feishu.controller;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -20,26 +21,135 @@ public class QueryFeishuCardDataController {
|
|||
|
||||
Iterator<Map.Entry<String, Object>> iterator = params.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
log.error("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
||||
}
|
||||
String challenge = "";
|
||||
if(params.containsKey("challenge")){
|
||||
challenge = params.get("challenge").toString();
|
||||
// String challenge = "";
|
||||
// if(params.containsKey("challenge")){
|
||||
// challenge = params.get("challenge").toString();
|
||||
// }
|
||||
// String token = "";
|
||||
// if(params.containsKey("token")){
|
||||
// token = params.get("token").toString();
|
||||
// }
|
||||
// String type = "";
|
||||
// if(params.containsKey("type")){
|
||||
// type = params.get("type").toString();
|
||||
// }
|
||||
|
||||
// dataMap.put("challenge",challenge);
|
||||
// dataMap.put("token",token);
|
||||
// dataMap.put("type",type);
|
||||
// returnJson.put("challenge",challenge);
|
||||
|
||||
// AAqzTJll9BcFE
|
||||
|
||||
boolean isTrue = false;
|
||||
if(params.containsKey("event")){
|
||||
String event = params.get("event").toString();
|
||||
log.error("event:{}",event);
|
||||
if(StringUtils.isNotBlank(event)){
|
||||
isTrue = convertData(event);
|
||||
}
|
||||
}
|
||||
String token = "";
|
||||
if(params.containsKey("token")){
|
||||
token = params.get("token").toString();
|
||||
|
||||
JSONObject returnJson = new JSONObject();
|
||||
log.error("isTrue:{}",isTrue);
|
||||
if(isTrue){
|
||||
JSONObject dataJson = new JSONObject();
|
||||
dataJson.put("template_id","AAq9MOwxqoNUF");
|
||||
JSONObject template_variable = new JSONObject();
|
||||
template_variable.put("zzrs","2000");
|
||||
template_variable.put("jdlzrs","20");
|
||||
template_variable.put("jdrzrs","30");
|
||||
template_variable.put("ycqrs","1900");
|
||||
template_variable.put("qjrs","10");
|
||||
template_variable.put("cdztrs","50");
|
||||
template_variable.put("srtx","5");
|
||||
template_variable.put("zztx","3");
|
||||
template_variable.put("zntx","1");
|
||||
dataJson.put("template_variable",template_variable);
|
||||
|
||||
JSONObject cardJson = new JSONObject();
|
||||
cardJson.put("type","template");
|
||||
cardJson.put("data",dataJson);
|
||||
|
||||
returnJson.put("card",cardJson);
|
||||
log.error("returnJson:{}",returnJson.toJSONString());
|
||||
}else{
|
||||
JSONObject dataJson = new JSONObject();
|
||||
dataJson.put("template_id","AAqzTJll9BcFE");
|
||||
JSONObject template_variable = new JSONObject();
|
||||
dataJson.put("template_variable",template_variable);
|
||||
JSONObject cardJson = new JSONObject();
|
||||
cardJson.put("type","template");
|
||||
cardJson.put("data",dataJson);
|
||||
returnJson.put("card",cardJson);
|
||||
log.error("returnJson:{}",returnJson.toJSONString());
|
||||
}
|
||||
String type = "";
|
||||
if(params.containsKey("type")){
|
||||
type = params.get("type").toString();
|
||||
|
||||
return returnJson;
|
||||
}
|
||||
|
||||
|
||||
public boolean convertData(String data){
|
||||
boolean isTrue = false;
|
||||
if(data.contains("observer") && data.contains("owner")){
|
||||
int oberIndex = data.indexOf("observer"); //100
|
||||
int ownerIndex = data.indexOf("owner"); //10
|
||||
|
||||
log.error("oberIndex:{}",oberIndex);
|
||||
log.error("ownerIndex:{}",ownerIndex);
|
||||
|
||||
String ownerOpenId = "";
|
||||
String oberOpenId = "";
|
||||
if(oberIndex <= ownerIndex){
|
||||
String ownerData = data.substring(ownerIndex,data.length());
|
||||
String oberData = data.substring(oberIndex,ownerIndex);
|
||||
log.error("ownerData:{}"+ownerData);
|
||||
log.error("oberData:{}"+oberData);
|
||||
if(ownerData.contains("open_id")){
|
||||
ownerData = ownerData.substring(ownerData.indexOf("open_id")+8);
|
||||
if(ownerData.contains(",")){
|
||||
ownerOpenId = ownerData.substring(0,ownerData.indexOf(","));
|
||||
}
|
||||
}
|
||||
|
||||
if(oberData.contains("open_id")){
|
||||
oberData = oberData.substring(oberData.indexOf("open_id")+8);
|
||||
System.out.println("oberData:"+oberData);
|
||||
if(oberData.contains(",")){
|
||||
oberOpenId = oberData.substring(0,oberData.indexOf(","));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
String oberData = data.substring(oberIndex,data.length());
|
||||
String ownerData = data.substring(ownerIndex,oberIndex);
|
||||
log.error("ownerData:{}"+ownerData);
|
||||
log.error("oberData:{}"+oberData);
|
||||
|
||||
if(ownerData.contains("open_id")){
|
||||
ownerData = ownerData.substring(ownerData.indexOf("open_id")+8);
|
||||
if(ownerData.contains(",")){
|
||||
ownerOpenId = ownerData.substring(0,ownerData.indexOf(","));
|
||||
}
|
||||
}
|
||||
|
||||
if(oberData.contains("open_id")){
|
||||
oberData = oberData.substring(oberData.indexOf("open_id")+8);
|
||||
if(oberData.contains(",")){
|
||||
oberOpenId = oberData.substring(0,oberData.indexOf(","));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.error("ownerOpenId:{}"+ownerOpenId);
|
||||
log.error("oberOpenId:{}"+oberOpenId);
|
||||
|
||||
if(StringUtils.isNotBlank(ownerOpenId) && StringUtils.isNotBlank(oberOpenId) && ownerOpenId.equals(oberOpenId)){
|
||||
isTrue = true;
|
||||
}
|
||||
}
|
||||
JSONObject dataMap = new JSONObject();
|
||||
dataMap.put("challenge",challenge);
|
||||
dataMap.put("token",token);
|
||||
dataMap.put("type",type);
|
||||
return dataMap;
|
||||
return isTrue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,4 +53,6 @@ public class Constants {
|
|||
|
||||
public static String consoleViolationVideo = "0";
|
||||
|
||||
public static String cosCenterTable = "uf_cos_center";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.weaver.seconddev.chapanda.sap.constant;
|
||||
|
||||
|
||||
public class Constants {
|
||||
public static String TENANT_KEY = "t024j0gfn0";
|
||||
public static String SysUserId = "1167276462243069953";
|
||||
|
||||
public static String cosCenterTable = "uf_cos_center";
|
||||
|
||||
public static String sapHost = "http://10.10.7.237:50000";
|
||||
|
||||
public static String queryIF311 = "/RESTAdapter/OA/IF311";
|
||||
|
||||
public static String hrmDepartmentCustomTable = "ft_1154218872715993098";
|
||||
|
||||
public static String hrmLegalEntity = "uf_legal_entity";
|
||||
|
||||
public static String Username = "POQ_EHR";
|
||||
|
||||
public static String Password = "P@ss123456";
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
package com.weaver.seconddev.chapanda.sap.dao;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.seconddev.chapanda.sap.util.DatabaseUtils;
|
||||
import com.weaver.seconddev.chapanda.sap.constant.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class Esb2SapUpdateIncorporatedDao {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(Esb2SapUpdateIncorporatedDao.class);
|
||||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
|
||||
/***
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> updateIncorporatedCompany(String BUKRS_T,String BUKRS){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
try{
|
||||
String dataSql =" update "+Constants.hrmLegalEntity+" set sapbm = '"+BUKRS+"' " +
|
||||
" where delete_type = 0\n" +
|
||||
" and mc ='"+BUKRS_T+"' and tenant_key = '"+Constants.TENANT_KEY+"'" ;
|
||||
|
||||
log.error("dataSql:" + dataSql);
|
||||
result = databaseUtils.execute(sourceType, groupId, dataSql);
|
||||
|
||||
log.error("result:{}", JSON.toJSONString(result));
|
||||
|
||||
}catch (Exception e){
|
||||
log.error("e:" + e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public String queryCostCenterDataId(String KOSTL){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
String dataid = "";
|
||||
try{
|
||||
String dataSql =" select id from " + Constants.cosCenterTable +
|
||||
" where bh = ? and tenant_key=? \n" +
|
||||
" and delete_type=0 " ;
|
||||
|
||||
log.error("dataSql:{}" , dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(KOSTL);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("recordList:{}" , recordList.size());
|
||||
if(recordList.size() > 0){
|
||||
dataid = String.valueOf(recordList.get(0).get("id"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("e:{}" , e);
|
||||
}
|
||||
return dataid;
|
||||
}
|
||||
|
||||
|
||||
public String queryHrmDepartmentCustomId(String KOSTL){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
String dataid = "";
|
||||
try{
|
||||
String dataSql =" select form_data_id from eteams." + Constants.hrmDepartmentCustomTable +
|
||||
" where oid = ? and tenant_key=? \n" +
|
||||
" and delete_type=0 " ;
|
||||
|
||||
log.error("dataSql:{}" , dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(KOSTL);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("recordList:{}" , recordList.size());
|
||||
if(recordList.size() > 0){
|
||||
dataid = String.valueOf(recordList.get(0).get("form_data_id"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("e:{}" , e);
|
||||
}
|
||||
return dataid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String queryHrmIncorporatedCompany(String BUKRS_T){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
String dataid = "";
|
||||
try{
|
||||
String dataSql =" select id from " + Constants.hrmLegalEntity +
|
||||
" where mc = ? and tenant_key=? \n" +
|
||||
" and delete_type=0 " ;
|
||||
|
||||
log.error("dataSql:{}" , dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(BUKRS_T);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("recordList:{}" , recordList.size());
|
||||
if(recordList.size() > 0){
|
||||
dataid = String.valueOf(recordList.get(0).get("id"));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("e:{}" , e);
|
||||
}
|
||||
return dataid;
|
||||
}
|
||||
|
||||
public Map<String, Object> updateHrmDepartment(String deptFormDataId,String costCenterId,String companyId){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
try{
|
||||
String dataSql =" update eteams.ft_1154218872715993098 set frgs='"+companyId+"',cbzx='"+costCenterId+"' " +
|
||||
" where form_data_id ='"+deptFormDataId+"' and tenant_key='"+Constants.TENANT_KEY+"' \n" +
|
||||
" and delete_type=0 " ;
|
||||
|
||||
log.error("dataSql:{}" , dataSql);
|
||||
result = databaseUtils.execute(sourceType, groupId, dataSql);
|
||||
|
||||
log.error("result:{}", JSON.toJSONString(result));
|
||||
|
||||
}catch (Exception e){
|
||||
log.error("e:{}" , e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> updateHrmEmployee(String deptFormDataId,String costCenterId,String companyId){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
try{
|
||||
String dataSql =" update eteams.ft_1152026012537184302 set frgs='"+companyId+"',cbzx='"+costCenterId+"' " +
|
||||
" where department in( select id from eteams.department where formdata='"+deptFormDataId+"' and tenant_key='"+Constants.TENANT_KEY+"' and delete_type=0 ) and tenant_key='"+Constants.TENANT_KEY+"' \n" +
|
||||
" and delete_type=0 " ;
|
||||
|
||||
log.error("dataSql:{}" , dataSql);
|
||||
result = databaseUtils.execute(sourceType, groupId, dataSql);
|
||||
log.error("result:{}", JSON.toJSONString(result));
|
||||
}catch (Exception e){
|
||||
log.error("e:{}" , e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package com.weaver.seconddev.chapanda.sap.dao;
|
||||
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.seconddev.chapanda.sap.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.sap.util.DatabaseUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class FormFieldDao {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(FormFieldDao.class);
|
||||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fieldId
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> queryFieldOptionByFieldid(String fieldId){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
Map<String, Object> optionMap = new HashMap<String, Object>();
|
||||
try{
|
||||
|
||||
String dataSql =" select name,value_key from field_option where field_id=? " +
|
||||
" and tenant_key=? \n" +
|
||||
" and delete_type=0" ;
|
||||
|
||||
log.error("dataSql:" + dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(fieldId);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("queryFromTableField:"+recordList.size());
|
||||
for(Map<String,Object> recordMap : recordList ) {
|
||||
String name = String.valueOf(recordMap.get("name"));
|
||||
String value_key = String.valueOf(recordMap.get("value_key"));
|
||||
optionMap.put(value_key,name);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("queryFromTableField:e:" + e);
|
||||
}
|
||||
return optionMap;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public Map<String,Object> queryTableFormId(String tableName){
|
||||
String sourceType = "LOGIC";
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
Map<String, Object> recordMap = new HashMap<String, Object>();
|
||||
try{
|
||||
String dataSql =" select id,app_id from ebdf_obj where table_name=? and delete_type=0 and tenant_key=?" ;
|
||||
log.error("dataSql:" + dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(tableName);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("queryTableFormId:"+recordList.size());
|
||||
if(recordList.size()>0){
|
||||
recordMap = recordList.get(0);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("queryTableFormId:e:" + e);
|
||||
}
|
||||
return recordMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataKeyList
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> queryFromTableField(String formTable,List<String> dataKeyList){
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
Map<String, Object> fieldMap = new HashMap<String, Object>();
|
||||
try{
|
||||
String dataKey = dataKeyList.stream().collect(Collectors.joining(","));
|
||||
dataKey = "'"+dataKey.replace(",","','")+"'" ;
|
||||
|
||||
String dataSql =" select id,form_id,title,data_key " +
|
||||
" from form_field " +
|
||||
" where form_id in( select form_id from form_table where table_name=? and delete_type=0 and tenant_key=? ) \n" +
|
||||
" and data_key in("+dataKey+")\n" +
|
||||
" and sub_form_id is null " +
|
||||
" and tenant_key=? \n" +
|
||||
" and delete_type=0" ;
|
||||
|
||||
log.error("queryFromTableField--dataSql:" + dataSql);
|
||||
List<String> paramList = new ArrayList<>(100);
|
||||
paramList.add(formTable);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
paramList.add(Constants.TENANT_KEY);
|
||||
|
||||
List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
log.error("queryFromTableField:"+recordList.size());
|
||||
for(Map<String,Object> recordMap : recordList ) {
|
||||
String data_key = String.valueOf(recordMap.get("data_key"));
|
||||
String id = String.valueOf(recordMap.get("id"));
|
||||
fieldMap.put(data_key,id);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("queryFromTableField:e:" + e);
|
||||
}
|
||||
return fieldMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.weaver.seconddev.chapanda.sap.entity;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* packageName com.weaver.seconddev.chapanda.esign.entity
|
||||
*
|
||||
* @ClassName OkHttpDto
|
||||
* @Author shil
|
||||
* @Date 2025/8/12 15:37
|
||||
* @Description TODO
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class OkHttpDto {
|
||||
|
||||
int responseCode;
|
||||
String responseBody;
|
||||
|
||||
int dataCode;
|
||||
String dataMsg;
|
||||
|
||||
JSONObject dataJson;
|
||||
|
||||
public int getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public void setResponseCode(int responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public String getResponseBody() {
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
public void setResponseBody(String responseBody) {
|
||||
this.responseBody = responseBody;
|
||||
}
|
||||
|
||||
public int getDataCode() {
|
||||
return dataCode;
|
||||
}
|
||||
|
||||
public void setDataCode(int dataCode) {
|
||||
this.dataCode = dataCode;
|
||||
}
|
||||
|
||||
public String getDataMsg() {
|
||||
return dataMsg;
|
||||
}
|
||||
|
||||
public void setDataMsg(String dataMsg) {
|
||||
this.dataMsg = dataMsg;
|
||||
}
|
||||
|
||||
public JSONObject getDataJson() {
|
||||
return dataJson;
|
||||
}
|
||||
|
||||
public void setDataJson(JSONObject dataJson) {
|
||||
this.dataJson = dataJson;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
package com.weaver.seconddev.chapanda.sap.esb;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
|
||||
import com.weaver.seconddev.chapanda.sap.util.Esb2SapIncorporatedCompanyUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("Esb2SapIncorporatedCompanyCron")
|
||||
public class Esb2SapIncorporatedCompanyCron implements EsbServerlessRpcRemoteInterface {
|
||||
private final static Logger log = LoggerFactory.getLogger(Esb2SapIncorporatedCompanyCron.class);
|
||||
|
||||
@Autowired
|
||||
Esb2SapIncorporatedCompanyUtil esb2SapIncorporatedCompanyUtil;
|
||||
|
||||
@Override
|
||||
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
|
||||
log.error("Esb2QunjieTestAttachmentCron");
|
||||
// List<Map<String,Object>> dataList
|
||||
// OkHttpDto okHttpDto = esb2SapIncorporatedCompanyUtil.queryIF311List();
|
||||
//
|
||||
// log.error("getResponseCode:{}",okHttpDto.getResponseCode());
|
||||
//
|
||||
// if(okHttpDto.getResponseCode() == 200){
|
||||
// JSONObject dataJson = okHttpDto.getDataJson();
|
||||
JSONObject dataJson = convertData();
|
||||
JSONArray dataList = new JSONArray();
|
||||
if(dataJson.containsKey("data")){
|
||||
dataList = dataJson.getJSONArray("data");
|
||||
}
|
||||
|
||||
log.error("dataList:{}",dataList.size());
|
||||
|
||||
if(dataList.size()>0){
|
||||
/***
|
||||
* 更新公司法人
|
||||
*/
|
||||
esb2SapIncorporatedCompanyUtil.updateIncorporatedCompany(dataList);
|
||||
/**
|
||||
* 更新成本中心
|
||||
*/
|
||||
esb2SapIncorporatedCompanyUtil.updateCostCenter(dataList);
|
||||
/**
|
||||
* 更新部门成本中心、人员成本中心
|
||||
*/
|
||||
esb2SapIncorporatedCompanyUtil.updateDeptEmployeeCostCenter(dataList);
|
||||
}
|
||||
// else{
|
||||
// return WeaResult.fail(500,"SAP接口获取为空");
|
||||
// }
|
||||
// }else{
|
||||
// return WeaResult.fail(500,okHttpDto.getDataMsg());
|
||||
// }
|
||||
|
||||
// esb2SapIncorporatedCompanyUtil.updateEmployeeCostCenter(dataList);
|
||||
|
||||
Map<String, Object> actionMap = new HashMap<String, Object>();
|
||||
actionMap.put("code",200);
|
||||
actionMap.put("msg","同步成功");
|
||||
|
||||
return WeaResult.success(actionMap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JSONObject convertData(){
|
||||
log.error("convertData");
|
||||
JSONArray bodyArray = new JSONArray();
|
||||
String reposponseBody = "{\"RETURN\":[{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":836567,\"KOSTL\":\"10EAE15030\",\"KOSTL_T\":\"部门测试1\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":2025659,\"KOSTL\":\"10EAE15041\",\"KOSTL_T\":\"部门测试2\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":2335391,\"KOSTL\":\"10EAE15031\",\"KOSTL_T\":\"部门测试2\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":2025659,\"KOSTL\":\"10EAE15032\",\"KOSTL_T\":\"部门测试3\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":2335391,\"KOSTL\":\"10EAE15033\",\"KOSTL_T\":\"部门测试4\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":836567,\"KOSTL\":\"10EAE15033\",\"KOSTL_T\":\"部门测试4\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":836567,\"KOSTL\":\"10EAE15040\",\"KOSTL_T\":\"部门测试1\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":836567,\"KOSTL\":\"10EAE15041\",\"KOSTL_T\":\"部门测试2\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"},{\"P_ID\":\"28C626567F2311F09C870000005DF48A\",\"BUMEN\":2025659,\"KOSTL\":\"10EAE15033\",\"KOSTL_T\":\"部门测试4\",\"BUKRS\":1000,\"BUKRS_T\":\"四川百茶百道实业股份有限公司\"}]}";
|
||||
if(StringUtils.isNotBlank(reposponseBody)){
|
||||
JSONObject msgJson = JSONObject.parseObject(reposponseBody);
|
||||
log.error("msgJson:{}",msgJson.toJSONString());
|
||||
if(msgJson.containsKey("RETURN")){
|
||||
String returnStr = msgJson.getString("RETURN");
|
||||
log.error("returnStr:{}",returnStr);
|
||||
if(!"[]".equals(returnStr)){
|
||||
JSONArray returnArray = msgJson.getJSONArray("RETURN");
|
||||
log.error("returnArray:{}",returnArray.size());
|
||||
for (int i = 0; i < returnArray.size(); i++) {
|
||||
JSONObject dataJson = returnArray.getJSONObject(i);
|
||||
|
||||
String P_ID = dataJson.getString("P_ID");
|
||||
String BUMEN = dataJson.getString("BUMEN");
|
||||
String KOSTL = dataJson.getString("KOSTL");
|
||||
String BUKRS = dataJson.getString("BUKRS");
|
||||
String KOSTL_T = dataJson.getString("KOSTL_T");
|
||||
String BUKRS_T = dataJson.getString("BUKRS_T");
|
||||
|
||||
log.error("KOSTL:{}",KOSTL);
|
||||
log.error("BUKRS:{}",BUKRS);
|
||||
log.error("BUMEN:{}",BUMEN);
|
||||
log.error("BUKRS_T:{}",BUKRS_T);
|
||||
|
||||
JSONObject dataMap = new JSONObject();
|
||||
dataMap.put("P_ID",P_ID);
|
||||
dataMap.put("BUMEN",BUMEN);
|
||||
dataMap.put("KOSTL",KOSTL);
|
||||
dataMap.put("BUKRS",BUKRS);
|
||||
dataMap.put("KOSTL_T",KOSTL_T);
|
||||
dataMap.put("BUKRS_T",BUKRS_T);
|
||||
bodyArray.add(dataMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.error("bodyArray:{}",bodyArray.size());
|
||||
JSONObject responseDataJson = new JSONObject();
|
||||
responseDataJson.put("data",bodyArray);
|
||||
return responseDataJson;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,422 @@
|
|||
package com.weaver.seconddev.chapanda.sap.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class CommonUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(CommonUtils.class);
|
||||
|
||||
public static JSONObject toJSON(String data){
|
||||
if(!StringUtils.isEmpty(data)){
|
||||
try {
|
||||
return JSONObject.parseObject(data);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Long getJSONLong(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getLong(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getJSONInteger(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getInteger(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static String getJSONString(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return null2String(json.getString(key));
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(JSONObject json,String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getJSONObject(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONArray getJSONArray(JSONObject json, String key){
|
||||
if(json != null && json.containsKey(key)){
|
||||
try {
|
||||
return json.getJSONArray(key);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(JSONArray json, int idx){
|
||||
if(json != null && json.size() > idx){
|
||||
try {
|
||||
return json.getJSONObject(idx);
|
||||
}catch (Throwable t){
|
||||
log.error(t.getMessage(),t);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String mapToStrData(Map<String, Object> para){
|
||||
if(para != null) {
|
||||
return JSONObject.toJSON(para).toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void strToLongList(List<Long> list,String strs){
|
||||
strToLongList(list,strs,true);
|
||||
}
|
||||
|
||||
public static void strToLongList(List<Long> list,String strs,boolean isDist){
|
||||
if(list == null){
|
||||
return;
|
||||
}
|
||||
if(StringUtils.isEmpty(strs)){
|
||||
return;
|
||||
}
|
||||
|
||||
String[] strList = StringUtils.split(strs, ",");
|
||||
for(String str:strList){
|
||||
if(StringUtils.isEmpty(str)){
|
||||
continue;
|
||||
}
|
||||
|
||||
long id = getLongValue(str);
|
||||
if(id > 0l && (isDist == false || !list.contains(id))){
|
||||
list.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLongValue(Object v){
|
||||
return getLongValue(null2String(v));
|
||||
}
|
||||
|
||||
public static long getLongValue(String v) {
|
||||
return getLongValue(v, -1);
|
||||
}
|
||||
|
||||
public static long getLongValue(String v, long def) {
|
||||
try {
|
||||
return Long.parseLong(v);
|
||||
} catch (Exception ex) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIntValue(Object o){
|
||||
return getIntValue(null2String(o));
|
||||
}
|
||||
|
||||
public static int getIntValue(String s){
|
||||
return getIntValue(s,-1);
|
||||
}
|
||||
|
||||
public static int getIntValue(String s, int def){
|
||||
try {
|
||||
return NumberUtils.toInt(s);
|
||||
} catch (Exception ex) {
|
||||
return def;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String null2String(Object s) {
|
||||
return s == null ? "" : s.toString();
|
||||
}
|
||||
|
||||
public static String null2String(Object s, String def) {
|
||||
return s == null ? (def == null ? "" : def) : s.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String stringReplace(String sou, String s1, String s2) {
|
||||
//int idx = sou.indexOf(s1);
|
||||
//if (idx < 0) {
|
||||
// return sou;
|
||||
//}
|
||||
//return sou.substring(0, idx) + s2 + StringReplace(sou.substring(idx + s1.length()), s1, s2);
|
||||
sou = null2String(sou);
|
||||
s1 = null2String(s1);
|
||||
s2 = null2String(s2);
|
||||
try{
|
||||
sou = sou.replace(s1, s2);
|
||||
}catch(Exception e){
|
||||
//System.out.println(e);//将未知异常打印出来,便于检查错误。
|
||||
}
|
||||
return sou;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊字符
|
||||
*
|
||||
* @param s 要替换特殊的字符串
|
||||
* @return 替换完成的字符串
|
||||
*/
|
||||
public static String toScreen(String s) {
|
||||
char c[] = s.toCharArray();
|
||||
char ch;
|
||||
int i = 0;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
while (i < c.length) {
|
||||
ch = c[i++];
|
||||
|
||||
if (ch == '\r')
|
||||
buf.append("");
|
||||
else if (ch == '\n')
|
||||
buf.append("");
|
||||
else
|
||||
buf.append(ch);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊字符
|
||||
*
|
||||
* @param s 要替换特殊的字符串
|
||||
* @return 替换完成的字符串
|
||||
*/
|
||||
public static String toExcel(String s) {
|
||||
if (s == null) return "";
|
||||
//因本方法会将字符串 &符号转换,故先将欧元符号转义符转换为其Unicode码
|
||||
s = s.replaceAll("€", "\u20AC");
|
||||
String str = toScreen(s);
|
||||
str = stringReplace(str, "∠", "∠");
|
||||
str = stringReplace(str, "φ", "φ");
|
||||
str = stringReplace(str, """, "\"");
|
||||
str = stringReplace(str, " ", "%nbsp");
|
||||
//str=Util.StringReplace(str,"'","‘");
|
||||
str = stringReplace(str, "<", "<");
|
||||
str = stringReplace(str, ">", ">");
|
||||
str = stringReplace(str, "&dt;&at;", "<br>");
|
||||
str = stringReplace(str, "&", "&");
|
||||
str = stringReplace(str, "<br>", "&dt;&at;");
|
||||
if ("&dt;&at;".equals(str)) {
|
||||
str = "";
|
||||
}
|
||||
//在方法最后,又将欧元符号置换为转义符
|
||||
str = str.replaceAll("\u20AC", "€");
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String delHtml(final String inputString) {
|
||||
String htmlStr = toExcel(inputString); // 含html标签的字符串
|
||||
|
||||
String textStr = "";
|
||||
java.util.regex.Pattern p_script;
|
||||
java.util.regex.Matcher m_script;
|
||||
java.util.regex.Pattern p_html;
|
||||
java.util.regex.Matcher m_html;
|
||||
|
||||
try {
|
||||
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
|
||||
|
||||
String regEx_script = "<[/s]*?script[^>]*?>[/s/S]*?<[/s]*?//[/s]*?script[/s]*?>"; // 定义script的正则表达式{或<script[^>]*?>[/s/S]*?<//script>
|
||||
|
||||
p_script = java.util.regex.Pattern.compile(regEx_script, java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
m_script = p_script.matcher(htmlStr);
|
||||
htmlStr = m_script.replaceAll(""); // 过滤script标签
|
||||
|
||||
p_html = java.util.regex.Pattern.compile(regEx_html, java.util.regex.Pattern.CASE_INSENSITIVE);
|
||||
m_html = p_html.matcher(htmlStr);
|
||||
htmlStr = m_html.replaceAll(""); // 过滤html标签
|
||||
|
||||
textStr = htmlStr;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Html2Text: " + e.getMessage());
|
||||
}
|
||||
|
||||
return htmlToTxt(textStr).trim();// 返回文本字符串
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字符串中的html格式
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static String htmlToTxt(String input) {
|
||||
if (input == null || input.trim().equals("")) {
|
||||
return "";
|
||||
}
|
||||
// 去掉所有html元素,
|
||||
String str = input.replaceAll("<[a-zA-Z]+[1-9]?[^><]*>", "");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
//==new=
|
||||
|
||||
public static int getIntValue(Object s, int def){
|
||||
return getIntValue(null2String(s));
|
||||
}
|
||||
|
||||
public static List<Long> strToLongList(String strs){
|
||||
List<Long> list = new ArrayList<Long>();
|
||||
strToLongList(list,strs,true);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static int dateInterval(String fromdate, String todate) {
|
||||
Calendar fromcalendar = getCalendar(fromdate);
|
||||
Calendar tocalendar = getCalendar(todate);
|
||||
|
||||
if (fromcalendar == null || tocalendar == null)
|
||||
return 0;
|
||||
|
||||
return (int) ((tocalendar.getTimeInMillis() - fromcalendar.getTimeInMillis()) / 3600 / 24 / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param datetime - 给定的日期时间,格式为 '2004-05-12 12:00:23' 或者 '2004-05-12'
|
||||
* @return 返回给定日历, 如果格式不正确,返回null
|
||||
*/
|
||||
public static Calendar getCalendar(String datetime) {
|
||||
int datetimelength = datetime.length() ;
|
||||
|
||||
switch(datetimelength) {
|
||||
case 19 :
|
||||
return getCalendar(datetime , "yyyy'-'MM'-'dd' 'HH:mm:ss") ;
|
||||
case 10 :
|
||||
return getCalendar(datetime , "yyyy'-'MM'-'dd") ;
|
||||
default :
|
||||
return null ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param datetime - 给定的日期时间
|
||||
* @param formart - 给定的日期时间的格式
|
||||
* @return 返回给定日历, 如果格式不正确,返回null
|
||||
*/
|
||||
public static Calendar getCalendar(String datetime, String formart) {
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(formart) ;
|
||||
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
try {
|
||||
calendar.setTime(SDF.parse(datetime)) ;
|
||||
} catch (ParseException e) {
|
||||
return null ;
|
||||
}
|
||||
|
||||
return calendar ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回当前时间字符,格式为 yyyy'-'MM'-'dd
|
||||
*
|
||||
* 返回当前时间字符,默认格式为yyyy'-'MM'-'dd
|
||||
*
|
||||
* 如 2004-09-07
|
||||
*/
|
||||
public static String getCurrentDateString() {
|
||||
String timestrformart = "yyyy'-'MM'-'dd" ;
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(timestrformart) ;
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
|
||||
return SDF.format(calendar.getTime()) ;
|
||||
}
|
||||
|
||||
public static String getMessage(String msgMode,String key,String val){
|
||||
key = null2String(key).trim();
|
||||
val = null2String(val).trim();
|
||||
msgMode = null2String(msgMode).trim();
|
||||
if(!"".equals(msgMode) && !"".equals(key)) {
|
||||
msgMode = msgMode.replaceAll(key, val);
|
||||
}
|
||||
return msgMode;
|
||||
}
|
||||
|
||||
public static List<Long> tranStrToLongList(Object idListObj){
|
||||
List<Long> docIds = new ArrayList<Long>();
|
||||
if(idListObj != null) {
|
||||
try {
|
||||
JSONArray idObjs = JSONArray.parseArray(null2String(idListObj));
|
||||
for (Object idObj : idObjs) {
|
||||
long id = getLongValue(idObj);
|
||||
if (id > 0l) {
|
||||
docIds.add(id);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("trans error :{}", idListObj);
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return docIds;
|
||||
}
|
||||
|
||||
public Map<String, Object> requestToMap(HttpServletRequest request) {
|
||||
Map<String, String[]> properties = request.getParameterMap();//把请求参数封装到Map<String, String[]>中
|
||||
Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
Iterator<Map.Entry<String, String[]>> iter = properties.entrySet().iterator();
|
||||
String name = "";
|
||||
String value = "";
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, String[]> entry = iter.next();
|
||||
name = entry.getKey();
|
||||
Object valueObj = entry.getValue();
|
||||
if (null == valueObj) {
|
||||
value = "";
|
||||
} else if (valueObj instanceof String[]) {
|
||||
String[] values = (String[]) valueObj;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
value = values[i] + ",";
|
||||
}
|
||||
value = value.substring(0, value.length() - 1);
|
||||
} else {
|
||||
value = valueObj.toString();
|
||||
}
|
||||
returnMap.put(name, value);
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,366 @@
|
|||
package com.weaver.seconddev.chapanda.sap.util;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.ebuilder.datasource.api.entity.ExecuteSqlEntity;
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SourceType;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SqlParamType;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.DynamicParamDto;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.FieldQuery;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.GroupQuery;
|
||||
import com.weaver.ebuilder.datasource.api.query.dto.dw.TableQuery;
|
||||
import com.weaver.ebuilder.datasource.api.service.DataSetService;
|
||||
import com.weaver.ebuilder.datasource.api.service.impl.EbFormDataService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* DatabaseUtil 是一个数据库工具类,提供了一些执行 SQL 查询和操作的方法。
|
||||
*/
|
||||
|
||||
|
||||
@Component
|
||||
public class DatabaseUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(DatabaseUtils.class);
|
||||
|
||||
@Autowired
|
||||
private DataSetService dataSetService;
|
||||
|
||||
@Autowired
|
||||
private EbFormDataService dataService;
|
||||
|
||||
|
||||
/**
|
||||
* 执行 SQL 并返回结果。
|
||||
*
|
||||
* @param entity 包含执行 SQL 的相关信息的对象
|
||||
* @return 包含查询结果的 Map 对象
|
||||
* @throws RuntimeException 当 SQL 执行失败时抛出异常
|
||||
*/
|
||||
public Map<String, Object> executeSql(ExecuteSqlEntity entity) {
|
||||
Map<String, Object> map = dataSetService.executeSql(entity);
|
||||
if ("FAIL".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT))) {
|
||||
log.error("sql执行失败=>{}", JSONObject.toJSONString(map));
|
||||
throw new RuntimeException("sql执行异常");
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行分页 SQL 查询并返回结果。
|
||||
*
|
||||
* @param entity 包含执行 SQL 和分页信息的对象
|
||||
* @param pageNo 当前页码
|
||||
* @param pageSize 每页的数据条数
|
||||
* @return 包含查询结果的 Map 对象
|
||||
* @throws RuntimeException 当 SQL 执行失败时抛出异常
|
||||
*/
|
||||
public Map<String, Object> executeSql(ExecuteSqlEntity entity, int pageNo, int pageSize) {
|
||||
entity.setPageNo(pageNo);
|
||||
entity.setPageSize(pageSize);
|
||||
Map<String, Object> map = dataSetService.executeForQuery(entity);
|
||||
if ("FAIL".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT))) {
|
||||
log.error("sql执行失败=>{}", JSONObject.toJSONString(map));
|
||||
throw new RuntimeException("sql执行异常");
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个包含执行 SQL 的对象。
|
||||
*
|
||||
* @param sql 需要执行的 SQL
|
||||
* @param groupId 数据源分组的 ID
|
||||
* @paramDesc 数据源分组的 ID 获取方式 【select APPLICATION_MARK,APPLICATION_name from eteams.ds_mark_service_relation】
|
||||
* @return 包含执行 SQL 的对象
|
||||
*/
|
||||
public ExecuteSqlEntity getExecuteSqlEntity(String sql, String groupId) {
|
||||
log.error("sql=>{}", sql);
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.LOGIC);
|
||||
executeSqlEntity.setGroupKey("0");
|
||||
return executeSqlEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 SQL 进行 Base64 编码。
|
||||
*
|
||||
* @param sql 需要进行编码的 SQL
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
public String base64(String sql) {
|
||||
return Base64.encode(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源列表。
|
||||
*
|
||||
* @param map 包含数据源列表信息的 Map 对象
|
||||
* @return 数据源列表的 Map 对象
|
||||
*/
|
||||
public List<Map<String, Object>> getDataSourceList(Map<String, Object> map) {
|
||||
List<Map<String, Object>> entity = new ArrayList();
|
||||
if ("OK".equals(CommonUtils.null2String(map.get("status")).toUpperCase(Locale.ROOT)) && map.get("count") != null && CommonUtils.getIntValue(map.get("count")) > 0) {
|
||||
entity = (List) map.get("records");
|
||||
}
|
||||
|
||||
return keyToLowerCase((List) entity);
|
||||
}
|
||||
|
||||
public Map<String, Object> getOneDataSource(Map<String, Object> map) {
|
||||
List<Map<String, Object>> entity = getDataSourceList(map);
|
||||
return (Map)(CollectionUtil.isNotEmpty(entity) ? (Map)entity.get(0) : new HashMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Map 对象中的键转换为小写。
|
||||
*
|
||||
* @param orgMapList 需要转换键的 Map 对象列表
|
||||
* @return 转换后的 Map 对象列表
|
||||
*/
|
||||
public List<Map<String, Object>> keyToLowerCase(List<Map<String, Object>> orgMapList) {
|
||||
List<Map<String, Object>> resultList = new ArrayList();
|
||||
Iterator var2 = orgMapList.iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
Map<String, Object> stringObjectMap = (Map) var2.next();
|
||||
resultList.add(keyToLowerCase(stringObjectMap));
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Map 对象中的键转换为小写。
|
||||
*
|
||||
* @param orgMap 需要转换键的 Map 对象
|
||||
* @return 转换后的 Map 对象
|
||||
*/
|
||||
public Map<String, Object> keyToLowerCase(Map<String, Object> orgMap) {
|
||||
Map<String, Object> resultMap = new HashMap();
|
||||
if (orgMap != null && !orgMap.isEmpty()) {
|
||||
Set<Map.Entry<String, Object>> entrySet = orgMap.entrySet();
|
||||
Iterator var3 = entrySet.iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
Map.Entry<String, Object> entry = (Map.Entry) var3.next();
|
||||
String key = (String) entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
resultMap.put(key.toLowerCase(), value);
|
||||
}
|
||||
return resultMap;
|
||||
} else {
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据数据库类型 找到对应数据库
|
||||
*
|
||||
* @param sourceType sourceType 枚举类
|
||||
* ETEAMS :数据仓库
|
||||
* FORM: ebuilder表单
|
||||
* LOGIC: 各模块提供业务数据(逻辑表)
|
||||
* EXTERNAL: 外部数据源
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getDataGroups(String sourceType, Boolean flag) {
|
||||
GroupQuery query = new GroupQuery();
|
||||
query.setSourceType(SourceType.valueOf(sourceType));
|
||||
query.setShowSqlDataset(flag);
|
||||
|
||||
|
||||
DynamicParamDto dynamicParamDto = new DynamicParamDto();
|
||||
dynamicParamDto.setUserId(10000L);
|
||||
dynamicParamDto.setTenantKey("tk");
|
||||
|
||||
query.setDynamicParamDto(dynamicParamDto);
|
||||
|
||||
return dataSetService.getDataGroups(query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据表
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getDataSets(String sourceType, String groupId, Integer pageNum, Integer pageSize) {
|
||||
|
||||
TableQuery tableQuery = new TableQuery();
|
||||
tableQuery.setSourceType(SourceType.valueOf(sourceType));
|
||||
tableQuery.setGroupId(groupId);
|
||||
//非必传
|
||||
//tableQuery.setName(name);
|
||||
tableQuery.setPageNo(pageNum);
|
||||
tableQuery.setPageSize(pageSize);
|
||||
return dataSetService.getDataSetsByPage(tableQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段
|
||||
* sourceType :LOGIC
|
||||
* sourceId : 8494845523559165780
|
||||
* groupId : weaver-crm-service
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getFields(String sourceType, String sourceId, String groupId) {
|
||||
FieldQuery query = new FieldQuery();
|
||||
query.setSourceType(SourceType.valueOf(sourceType));
|
||||
query.setSourceId(sourceId);
|
||||
query.setGroupId(groupId);
|
||||
return dataSetService.getFields(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql
|
||||
* sourceType :LOGIC
|
||||
* groupId : weaver-ebuilder-app-service
|
||||
* sql : select * from ebda_app limit 10
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> execute(String sourceType, String groupId, String sql) {
|
||||
//执行sql 参数sourceType groupId sql
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
return dataSetService.executeSql(executeSqlEntity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> executeUpdate(String sourceType, String groupId, String sql) {
|
||||
//执行sql 参数sourceType groupId sql
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
return dataSetService.executeForUpdate(executeSqlEntity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> executeForQuery(String sourceType, String groupId, String sql,List<SqlParamEntity> sqlparam) {
|
||||
//执行sql 参数sourceType groupId sql sqlparam
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
executeSqlEntity.setParams(sqlparam);
|
||||
return dataSetService.executeSql(executeSqlEntity);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param sql
|
||||
* @param sqlparam
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> executeForUpdate(String sourceType, String groupId, String sql,List<SqlParamEntity> sqlparam) {
|
||||
//执行sql 参数sourceType groupId sql sqlparam
|
||||
ExecuteSqlEntity executeSqlEntity = new ExecuteSqlEntity();
|
||||
executeSqlEntity.setSql(base64(sql));
|
||||
executeSqlEntity.setGroupId(groupId);
|
||||
executeSqlEntity.setSourceType(SourceType.valueOf(sourceType));
|
||||
executeSqlEntity.setParams(sqlparam);
|
||||
return dataSetService.executeForUpdate(executeSqlEntity);
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sql
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public String getMysqlPagedSql(String sql,int pageNo, int pageSize) {
|
||||
if(pageNo<=0){
|
||||
pageNo = 1;
|
||||
}
|
||||
|
||||
if(pageSize<=0){
|
||||
pageSize = 20;
|
||||
}
|
||||
|
||||
int start = (pageNo-1)*pageSize;
|
||||
int end = pageNo*pageSize;
|
||||
|
||||
return new StringBuffer().append(sql).append(
|
||||
" LIMIT "+start+","+(end-start)).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取sql入参
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public List<SqlParamEntity> querySqlParamEntity(List<String> list){
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
for (String str : list){
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(str);
|
||||
sqlparam.add(sqlParamEntity);
|
||||
}
|
||||
return sqlparam;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param dataSql
|
||||
* @param paramList
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getSqlList(String sourceType,String groupId,String dataSql,List<String> paramList){
|
||||
List<SqlParamEntity> sqlParamList = querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = getDataSourceList(result);
|
||||
return recordList;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param dataSql
|
||||
* @param paramList
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getSqlMap(String sourceType,String groupId,String dataSql,List<String> paramList){
|
||||
Map<String, Object> recordMap = new HashMap<String, Object>();
|
||||
List<SqlParamEntity> sqlParamList = querySqlParamEntity(paramList);
|
||||
Map<String, Object> result = executeForQuery(sourceType, groupId, dataSql, sqlParamList);
|
||||
List<Map<String, Object>> recordList = getDataSourceList(result);
|
||||
if(recordList.size() > 0){
|
||||
recordMap = recordList.get(0);
|
||||
}
|
||||
return recordMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
package com.weaver.seconddev.chapanda.sap.util;
|
||||
|
||||
import com.weaver.ebuilder.form.client.entity.data.*;
|
||||
import com.weaver.ebuilder.form.client.service.data.RemoteSimpleDataService;
|
||||
import com.weaver.framework.rpc.annotation.RpcReference;
|
||||
import com.weaver.publishkit.api.util.PublishKitRuntimeUtil;
|
||||
import com.weaver.seconddev.chapanda.sap.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.sap.dao.FormFieldDao;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class EbuilderOperateUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(EbuilderOperateUtils.class);
|
||||
|
||||
@Autowired
|
||||
FormFieldDao formFieldDao;
|
||||
|
||||
@Autowired
|
||||
private PublishKitRuntimeUtil publishKitRuntimeUtil;
|
||||
|
||||
@RpcReference(group = "ebuilderform")
|
||||
private RemoteSimpleDataService remoteSimpleDataService;
|
||||
|
||||
public EBDataChangeResult bacthInsertEbForm(String formTable,List<EBDataReqDto> datas) {
|
||||
|
||||
log.error("bacthInsertDbForm");
|
||||
EBDataChangeResult ebDataChangeResult = new EBDataChangeResult();
|
||||
|
||||
Map<String,Object> recordMap= formFieldDao.queryTableFormId(formTable);
|
||||
|
||||
String formId = recordMap.get("id").toString();
|
||||
String appId = recordMap.get("app_id").toString();
|
||||
log.error("formId:{}",formId);
|
||||
log.error("appId:{}",appId);
|
||||
|
||||
if(StringUtils.isNotBlank(formId) && StringUtils.isNotBlank(appId)){
|
||||
|
||||
RemoteSimpleDataService remoteSimpleDataService = publishKitRuntimeUtil.buildRpcService(RemoteSimpleDataService.class, "ebuilderform", appId);
|
||||
|
||||
EBDataChangeReqDto ebDataChangeReqDto = new EBDataChangeReqDto();
|
||||
|
||||
// 构建基础参数; objId 表单id, operator 操作人, tenantKey 租户
|
||||
ebDataChangeReqDto.setHeader(new EBDataReqHeader(formId, Constants.SysUserId, Constants.TENANT_KEY));
|
||||
|
||||
EBDataReqOperation operation = new EBDataReqOperation();
|
||||
operation.setAsyncPostProcess(false);
|
||||
ebDataChangeReqDto.setOperation(operation);
|
||||
|
||||
// 主表数据参数
|
||||
// Map<String, Object> fieldMap = formFieldDao.queryFromTableField(formTable,fieldList);
|
||||
// if("uf_yzgl".equals(formTable)){
|
||||
// for(int i=0;i<dataList.size();i++){
|
||||
// Map<String,Object> dataMap = dataList.get(i);
|
||||
// EBDataReqDto ebDataReqDto = new EBDataReqDto();
|
||||
// List<EBDataReqDetailDto> mainData = new ArrayList<EBDataReqDetailDto>();
|
||||
// for(int n=0;n<fieldList.size();n++){
|
||||
// if(fieldList.get(n).equals("yzzl")){
|
||||
// String fieldId = fieldMap.get(fieldList.get(n)).toString();
|
||||
// mainData.add(new EBDataReqDetailDto(fieldId, "2"));
|
||||
// }else{
|
||||
// if(dataMap.containsKey(fieldList.get(n)) && fieldMap.containsKey(fieldList.get(n))){
|
||||
// String value = dataMap.get(fieldList.get(n)).toString();
|
||||
// String fieldId = fieldMap.get(fieldList.get(n)).toString();
|
||||
//
|
||||
// log.error("fieldId:{}",fieldId);
|
||||
// log.error("value:{}",value);
|
||||
//
|
||||
// mainData.add(new EBDataReqDetailDto(fieldId, value));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ebDataReqDto.setMainDatas(mainData);
|
||||
// datas.add(ebDataReqDto);
|
||||
// }
|
||||
// }else{
|
||||
// for(int i=0;i<dataList.size();i++){
|
||||
// Map<String,Object> dataMap = dataList.get(i);
|
||||
// EBDataReqDto ebDataReqDto = new EBDataReqDto();
|
||||
// List<EBDataReqDetailDto> mainData = new ArrayList<EBDataReqDetailDto>();
|
||||
// for(int n=0;n<fieldList.size();n++){
|
||||
// if(dataMap.containsKey(fieldList.get(n)) && fieldMap.containsKey(fieldList.get(n))){
|
||||
// String value = dataMap.get(fieldList.get(n)).toString();
|
||||
// String fieldId = fieldMap.get(fieldList.get(n)).toString();
|
||||
//
|
||||
// log.error("fieldId:{}",fieldId);
|
||||
// log.error("value:{}",value);
|
||||
//
|
||||
// mainData.add(new EBDataReqDetailDto(fieldId, value));
|
||||
// }
|
||||
// }
|
||||
// ebDataReqDto.setMainDatas(mainData);
|
||||
// datas.add(ebDataReqDto);
|
||||
// }
|
||||
// }
|
||||
ebDataChangeReqDto.setDatas(datas);
|
||||
ebDataChangeResult = remoteSimpleDataService.saveFormData(ebDataChangeReqDto);
|
||||
}
|
||||
return ebDataChangeResult;
|
||||
}
|
||||
|
||||
|
||||
// public EBDataChangeResult bacthAppendEbDetail(String rcid,int points,String mainid) {
|
||||
//
|
||||
// EBDataChangeReqDto ebDataChangeReqDto = new EBDataChangeReqDto();
|
||||
// ebDataChangeReqDto.setHeader(new EBDataReqHeader("1120080325150089217", Constants.SysUserId, Constants.TENANT_KEY));
|
||||
//
|
||||
// // 请求操作信息
|
||||
// EBDataReqOperation ebDataReqOperation = new EBDataReqOperation();
|
||||
// ebDataReqOperation.setUpdateType(EBDataUpdateType.ids);
|
||||
// // 数据组装
|
||||
// List<EBDataReqDto> datas = new ArrayList<>();
|
||||
// // 第一个数据项
|
||||
// EBDataReqDto ebDataReqDto1 = new EBDataReqDto();
|
||||
// List<EBDataReqDetailDto> mainDatas1 = new ArrayList<>();
|
||||
// // 主表数据组装
|
||||
// mainDatas1.add(new EBDataReqDetailDto("id", mainid, false));
|
||||
// ebDataReqDto1.setMainDatas(mainDatas1);
|
||||
//
|
||||
// /****************** 设置明细操作方式 - 不做覆盖 需要追加 ******************/
|
||||
// Map<Long, EBDataReqOperationInfo> detailDatas = new HashMap<>();
|
||||
// EBDataReqOperationInfo detailOperation = new EBDataReqOperationInfo();
|
||||
// detailOperation.setCover(false);
|
||||
// detailOperation.setNeedAdd(true);
|
||||
// detailDatas.put(1120080376580644874L, detailOperation);
|
||||
// ebDataReqOperation.setDetailDatas(detailDatas);
|
||||
//
|
||||
// // 明细行数据组装
|
||||
// Map<Long, List<List<EBDataReqDetailDto>>> detailDatas1 = new HashMap<>();
|
||||
// List<List<EBDataReqDetailDto>> detailDataList1 = new ArrayList<>();
|
||||
// List<EBDataReqDetailDto> detailData1 = new ArrayList<EBDataReqDetailDto>();
|
||||
// // 第一个明细表 第一条数据
|
||||
// detailData1.add(new EBDataReqDetailDto("1120167723322155008", rcid, false));
|
||||
// detailData1.add(new EBDataReqDetailDto("1120080728843460609", String.valueOf(points), false));
|
||||
// detailDataList1.add(detailData1);
|
||||
// detailDatas1.put(1120080376580644874L, detailDataList1);
|
||||
// ebDataReqDto1.setDetailDatas(detailDatas1);
|
||||
// datas.add(ebDataReqDto1);
|
||||
//
|
||||
// ebDataChangeReqDto.setOperation(ebDataReqOperation);
|
||||
//
|
||||
// // 设置数据
|
||||
// ebDataChangeReqDto.setDatas(datas);
|
||||
// EBDataChangeResult ebDataChangeResult = remoteSimpleDataService.updateFormData(ebDataChangeReqDto);
|
||||
//
|
||||
// return ebDataChangeResult;
|
||||
// }
|
||||
|
||||
public EBDataChangeResult bacthEditEbForm(String formTable,List<EBDataReqDto> datas) {
|
||||
|
||||
EBDataChangeResult ebDataChangeResult = new EBDataChangeResult();
|
||||
|
||||
Map<String,Object> recordMap= formFieldDao.queryTableFormId(formTable);
|
||||
|
||||
String formId = recordMap.get("id").toString();
|
||||
String appId = recordMap.get("app_id").toString();
|
||||
log.error("formId:{}",formId);
|
||||
log.error("appId:{}",appId);
|
||||
|
||||
if (StringUtils.isNotBlank(formId) && StringUtils.isNotBlank(appId)) {
|
||||
|
||||
RemoteSimpleDataService remoteSimpleDataService = publishKitRuntimeUtil.buildRpcService(RemoteSimpleDataService.class, "ebuilderform", appId);
|
||||
|
||||
/**
|
||||
* 直接通过id更新数据, 即update table set a = '11' where id = 1
|
||||
*/
|
||||
EBDataChangeReqDto ebDataChangeReqDto = new EBDataChangeReqDto();
|
||||
// 构建基础参数; objId 表单id, operator 操作人, tenantKey 租户
|
||||
ebDataChangeReqDto.setHeader(new EBDataReqHeader(formId, Constants.SysUserId, Constants.TENANT_KEY));
|
||||
// 请求操作信息
|
||||
EBDataReqOperation ebDataReqOperation = new EBDataReqOperation();
|
||||
ebDataReqOperation.setUpdateType(EBDataUpdateType.ids);
|
||||
// 若数据写入后就要从前台看到数据或者立即操作本次写入的数据, 需要调整后置处理为同步 权限处理完成再返回
|
||||
ebDataReqOperation.setAsyncPostProcess(false);
|
||||
ebDataChangeReqDto.setOperation(ebDataReqOperation);
|
||||
// 数据没有找到的时候是否新增数据
|
||||
EBDataReqOperationInfo ebDataReqOperationInfo = new EBDataReqOperationInfo();
|
||||
ebDataReqOperationInfo.setNeedAdd(true);
|
||||
ebDataReqOperation.setMainData(ebDataReqOperationInfo);
|
||||
ebDataChangeReqDto.setOperation(ebDataReqOperation);
|
||||
ebDataChangeReqDto.setDatas(datas);
|
||||
ebDataChangeResult = remoteSimpleDataService.updateFormData(ebDataChangeReqDto);
|
||||
}
|
||||
return ebDataChangeResult;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,332 @@
|
|||
package com.weaver.seconddev.chapanda.sap.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.ebuilder.form.client.entity.data.EBDataChangeResult;
|
||||
import com.weaver.ebuilder.form.client.entity.data.EBDataReqDetailDto;
|
||||
import com.weaver.ebuilder.form.client.entity.data.EBDataReqDto;
|
||||
import com.weaver.seconddev.chapanda.sap.constant.Constants;
|
||||
import com.weaver.seconddev.chapanda.sap.dao.Esb2SapUpdateIncorporatedDao;
|
||||
import com.weaver.seconddev.chapanda.sap.dao.FormFieldDao;
|
||||
import com.weaver.seconddev.chapanda.sap.entity.OkHttpDto;
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Component
|
||||
public class Esb2SapIncorporatedCompanyUtil {
|
||||
private final static Logger log = LoggerFactory.getLogger(Esb2SapIncorporatedCompanyUtil.class);
|
||||
|
||||
@Autowired
|
||||
FormFieldDao formFieldDao;
|
||||
|
||||
@Autowired
|
||||
EbuilderOperateUtils ebuilderOperateUtils;
|
||||
|
||||
@Autowired
|
||||
Esb2SapUpdateIncorporatedDao esb2SapUpdateIncorporatedDao;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public OkHttpDto queryIF311List(){
|
||||
OkHttpDto okHttpDto = doPostReqeustByOkHttp();
|
||||
return okHttpDto;
|
||||
}
|
||||
|
||||
public OkHttpDto doPostReqeustByOkHttp(){
|
||||
String msg = "";
|
||||
OkHttpDto okHttpDto = new OkHttpDto();
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.build();
|
||||
// JSONObject bodyJson = new JSONObject();
|
||||
// JSONObject dataJson = new JSONObject();
|
||||
// dataJson.put("DATA",BUMEN);
|
||||
// bodyJson.put("data",dataJson);
|
||||
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
RequestBody body = RequestBody.create(mediaType, "{}");
|
||||
String authorization = Base64.getUrlEncoder().encodeToString((Constants.Username + ":" + Constants.Password).getBytes());
|
||||
try {
|
||||
log.error(Constants.sapHost+Constants.queryIF311);
|
||||
Request request = new Request.Builder()
|
||||
.url(Constants.sapHost+Constants.queryIF311)
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.addHeader("Authorization", "Basic "+authorization)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
int code = response.code();
|
||||
log.error("code:{}",code);
|
||||
msg = response.body().string();
|
||||
log.error("msg:"+msg);
|
||||
|
||||
okHttpDto.setResponseCode(code);
|
||||
okHttpDto.setResponseBody(msg);
|
||||
convertData(msg,okHttpDto);
|
||||
|
||||
} catch (IOException e) {
|
||||
okHttpDto.setResponseCode(500);
|
||||
okHttpDto.setDataMsg("请求异常:"+e.getMessage());
|
||||
log.error("e:"+e);
|
||||
}
|
||||
return okHttpDto;
|
||||
}
|
||||
|
||||
|
||||
public void convertData(String reposponseBody, OkHttpDto okHttpDto){
|
||||
JSONArray bodyArray = new JSONArray();
|
||||
|
||||
if(StringUtils.isNotBlank(reposponseBody)){
|
||||
JSONObject msgJson = JSONObject.parseObject(reposponseBody);
|
||||
if(msgJson.containsKey("RETURN")){
|
||||
String returnStr = msgJson.getString("RETURN");
|
||||
if(!"[]".equals(returnStr)){
|
||||
JSONArray returnArray = msgJson.getJSONArray("RETURN");
|
||||
for (int i = 0; i < returnArray.size(); i++) {
|
||||
JSONObject dataJson = returnArray.getJSONObject(i);
|
||||
|
||||
String P_ID = dataJson.getString("P_ID");
|
||||
String BUMEN = dataJson.getString("BUMEN");
|
||||
String KOSTL = dataJson.getString("KOSTL");
|
||||
String BUKRS = dataJson.getString("BUKRS");
|
||||
String KOSTL_T = dataJson.getString("KOSTL_T");
|
||||
String BUKRS_T = dataJson.getString("BUKRS_T");
|
||||
|
||||
log.error("KOSTL:{}",KOSTL);
|
||||
log.error("BUKRS:{}",BUKRS);
|
||||
log.error("BUMEN:{}",BUMEN);
|
||||
log.error("BUKRS_T:{}",BUKRS_T);
|
||||
|
||||
JSONObject dataMap = new JSONObject();
|
||||
dataMap.put("P_ID",P_ID);
|
||||
dataMap.put("BUMEN",BUMEN);
|
||||
dataMap.put("KOSTL",KOSTL);
|
||||
dataMap.put("BUKRS",BUKRS);
|
||||
dataMap.put("KOSTL_T",KOSTL_T);
|
||||
dataMap.put("BUKRS_T",BUKRS_T);
|
||||
bodyArray.add(dataMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.error("bodyArray:{}",bodyArray.size());
|
||||
JSONObject responseDataJson = new JSONObject();
|
||||
responseDataJson.put("data",bodyArray);
|
||||
okHttpDto.setDataJson(responseDataJson);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 批量更新法人代表
|
||||
* @param costCenterList
|
||||
*/
|
||||
public void updateIncorporatedCompany(JSONArray costCenterList){
|
||||
log.error("costCenterList:{}",costCenterList.size());
|
||||
for(int i=0;i<costCenterList.size();i++){
|
||||
|
||||
JSONObject dataMap = costCenterList.getJSONObject(i);
|
||||
|
||||
String BUKRS_T = String.valueOf(dataMap.get("BUKRS_T"));
|
||||
String BUKRS = String.valueOf(dataMap.get("BUKRS"));
|
||||
log.error("BUKRS_T:{}",BUKRS_T);
|
||||
log.error("BUKRS:{}",BUKRS);
|
||||
esb2SapUpdateIncorporatedDao.updateIncorporatedCompany(BUKRS_T,BUKRS);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 批量新增/更新成本中心
|
||||
* @param costCenterList
|
||||
*/
|
||||
public List<String> updateCostCenter(JSONArray costCenterList){
|
||||
List<String> ebList = new ArrayList<String>();
|
||||
|
||||
List<String> fieldList = new ArrayList<String>();
|
||||
fieldList.add("bh");
|
||||
fieldList.add("mc");
|
||||
try {
|
||||
log.error("costCenterList:"+costCenterList.size());
|
||||
if(costCenterList.size()>0){
|
||||
JSONArray costCenterArray = convertData2CostCenter(costCenterList);
|
||||
Map<String, Object> fieldMap = formFieldDao.queryFromTableField(Constants.cosCenterTable,fieldList);
|
||||
List<EBDataReqDto> addDatas = new ArrayList<EBDataReqDto>();
|
||||
List<EBDataReqDto> updateDatas = new ArrayList<EBDataReqDto>();
|
||||
|
||||
for(int i=0;i<costCenterArray.size();i++){
|
||||
JSONObject dataMap = costCenterArray.getJSONObject(i);
|
||||
EBDataReqDto ebDataReqDto = new EBDataReqDto();
|
||||
List<EBDataReqDetailDto> mainData = new ArrayList<EBDataReqDetailDto>();
|
||||
|
||||
String KOSTL = String.valueOf(dataMap.getString("KOSTL"));
|
||||
String ufId = esb2SapUpdateIncorporatedDao.queryCostCenterDataId(KOSTL);
|
||||
log.error("ufId:{}",ufId);
|
||||
|
||||
if(StringUtils.isNotBlank(ufId)) {
|
||||
log.error("修改");
|
||||
mainData.add(new EBDataReqDetailDto("id", ufId));
|
||||
for(int n=0;n<fieldList.size();n++) {
|
||||
if (dataMap.containsKey(fieldList.get(n)) && fieldMap.containsKey(fieldList.get(n))) {
|
||||
String value = dataMap.getString(fieldList.get(n));
|
||||
String fieldId = fieldMap.get(fieldList.get(n)).toString();
|
||||
|
||||
log.error("fieldId:{}", fieldId);
|
||||
log.error("value:{}", value);
|
||||
|
||||
mainData.add(new EBDataReqDetailDto(fieldId, value));
|
||||
}
|
||||
}
|
||||
ebDataReqDto.setMainDatas(mainData);
|
||||
updateDatas.add(ebDataReqDto);
|
||||
|
||||
}else{
|
||||
for(int n=0;n<fieldList.size();n++){
|
||||
if(dataMap.containsKey(fieldList.get(n)) && fieldMap.containsKey(fieldList.get(n))){
|
||||
String value = dataMap.getString(fieldList.get(n));
|
||||
String fieldId = fieldMap.get(fieldList.get(n)).toString();
|
||||
|
||||
log.error("fieldId:{}",fieldId);
|
||||
log.error("value:{}",value);
|
||||
|
||||
mainData.add(new EBDataReqDetailDto(fieldId, value));
|
||||
}
|
||||
}
|
||||
ebDataReqDto.setMainDatas(mainData);
|
||||
addDatas.add(ebDataReqDto);
|
||||
}
|
||||
}
|
||||
log.error("addDatas:{}",addDatas.size());
|
||||
log.error("updateDatas:{}",updateDatas.size());
|
||||
|
||||
if(addDatas.size() > 0){
|
||||
EBDataChangeResult addEbDataChangeResult = ebuilderOperateUtils.bacthInsertEbForm(Constants.cosCenterTable,addDatas);
|
||||
boolean isTrue = addEbDataChangeResult.getStatus();
|
||||
log.error("message:{}",addEbDataChangeResult.getMessage());
|
||||
log.error("isTrue1:{}",isTrue);
|
||||
if(isTrue){
|
||||
ebList.addAll(addEbDataChangeResult.getDataIds());
|
||||
}
|
||||
}
|
||||
|
||||
if(updateDatas.size() > 0){
|
||||
|
||||
EBDataChangeResult updateEbDataChangeResult = ebuilderOperateUtils.bacthEditEbForm(Constants.cosCenterTable,updateDatas);
|
||||
boolean isTrue = updateEbDataChangeResult.getStatus();
|
||||
log.error("isTrue2:{}",isTrue);
|
||||
log.error("message2:{}",updateEbDataChangeResult.getMessage());
|
||||
if(isTrue){
|
||||
ebList.addAll(updateEbDataChangeResult.getDataIds());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("e:"+e);
|
||||
}
|
||||
return ebList;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 批量更新部门成本中心
|
||||
* @param costCenterList
|
||||
* @return
|
||||
*/
|
||||
public void updateDeptEmployeeCostCenter(JSONArray costCenterList){
|
||||
try {
|
||||
log.error("costCenterList:"+costCenterList.size());
|
||||
if(costCenterList.size()>0){
|
||||
for(int i=0;i<costCenterList.size();i++){
|
||||
JSONObject dataMap = costCenterList.getJSONObject(i);
|
||||
String BUMEN = String.valueOf(dataMap.getString("BUMEN")); //oId
|
||||
String KOSTL = String.valueOf(dataMap.getString("KOSTL"));
|
||||
String BUKRS_T = String.valueOf(dataMap.getString("BUKRS_T"));
|
||||
|
||||
log.error("BUMEN:{}",BUMEN);
|
||||
log.error("KOSTL:{}",KOSTL);
|
||||
log.error("BUKRS_T:{}",BUKRS_T);
|
||||
|
||||
String deptFormDataId = "";
|
||||
if(StringUtils.isNotBlank(BUMEN)){
|
||||
deptFormDataId = esb2SapUpdateIncorporatedDao.queryHrmDepartmentCustomId(BUMEN);
|
||||
}
|
||||
String costCenterId = "";
|
||||
if(StringUtils.isNotBlank(KOSTL)){
|
||||
costCenterId = esb2SapUpdateIncorporatedDao.queryCostCenterDataId(KOSTL);
|
||||
}
|
||||
String companyId = "";
|
||||
if(StringUtils.isNotBlank(BUKRS_T)){
|
||||
companyId = esb2SapUpdateIncorporatedDao.queryHrmIncorporatedCompany(BUKRS_T);
|
||||
}
|
||||
log.error("deptFormDataId:{},costCenterId:{},companyId:{}",deptFormDataId,costCenterId,companyId);
|
||||
if(StringUtils.isNotBlank(deptFormDataId)){
|
||||
esb2SapUpdateIncorporatedDao.updateHrmDepartment(deptFormDataId,costCenterId,companyId);
|
||||
|
||||
esb2SapUpdateIncorporatedDao.updateHrmEmployee(deptFormDataId,costCenterId,companyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("e:"+e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public void updateEmployeeCostCenter(List<Map<String,Object>> costCenterList){
|
||||
// try {
|
||||
// log.error("costCenterList:"+costCenterList.size());
|
||||
// if(costCenterList.size()>0){
|
||||
// for(int i=0;i<costCenterList.size();i++){
|
||||
// Map<String,Object> dataMap = costCenterList.get(i);
|
||||
// String BUMEN = String.valueOf(dataMap.get("BUMEN")); //oId
|
||||
// String KOSTL = String.valueOf(dataMap.get("KOSTL"));
|
||||
// String BUKRS_T = String.valueOf(dataMap.get("BUKRS_T"));
|
||||
// String deptFormDataId = "";
|
||||
// if(StringUtils.isNotBlank(BUMEN)){
|
||||
// deptFormDataId = esb2SapUpdateIncorporatedDao.queryHrmDepartmentCustomId(BUMEN);
|
||||
// }
|
||||
// String costCenterId = "";
|
||||
// if(StringUtils.isNotBlank(KOSTL)){
|
||||
// costCenterId = esb2SapUpdateIncorporatedDao.queryCostCenterDataId(KOSTL);
|
||||
// }
|
||||
// String companyId = "";
|
||||
// if(StringUtils.isNotBlank(BUKRS_T)){
|
||||
// companyId = esb2SapUpdateIncorporatedDao.queryHrmIncorporatedCompany(BUKRS_T);
|
||||
// }
|
||||
// log.error("deptFormDataId:{},costCenterId:{},companyId:{}",deptFormDataId,costCenterId,companyId);
|
||||
// if(StringUtils.isNotBlank(deptFormDataId)){
|
||||
// esb2SapUpdateIncorporatedDao.updateHrmEmployee(deptFormDataId,costCenterId,companyId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("e:"+e);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public JSONArray convertData2CostCenter(JSONArray costCenterList){
|
||||
JSONArray dataArray = new JSONArray();
|
||||
|
||||
for(int i=0;i<costCenterList.size();i++){
|
||||
JSONObject costCenterMap = costCenterList.getJSONObject(i);
|
||||
String KOSTL = String.valueOf(costCenterMap.getString("KOSTL"));
|
||||
String KOSTL_T = String.valueOf(costCenterMap.getString("KOSTL_T"));
|
||||
JSONObject dataJson = new JSONObject();
|
||||
dataJson.put("bh",KOSTL);
|
||||
dataJson.put("mc",KOSTL_T);
|
||||
dataArray.add(dataJson);
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue