package com.fzzy.otherview.whhpjl.pr;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.bstek.dorado.annotation.DataProvider;
|
import com.bstek.dorado.annotation.DataResolver;
|
import com.bstek.dorado.annotation.Expose;
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.data.ApiParam;
|
import com.fzzy.api.dto.ResponseDto;
|
import com.fzzy.api.entity.ApiConfs;
|
import com.fzzy.api.entity.ApiInfoData;
|
import com.fzzy.api.service.ApiCommonService;
|
import com.fzzy.api.service.ApiPushManager;
|
import com.fzzy.api.service.ApiRemoteService;
|
import com.fzzy.api.utils.Base64Util;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.view.repository.ApiInfoDataRep;
|
import com.fzzy.async.fzzy40.entity.Fz40Quality;
|
import com.fzzy.async.whhpjl.entity.*;
|
import com.fzzy.async.whhpjl.repository.*;
|
import com.fzzy.data.ConfigData;
|
import com.fzzy.otherview.whhpjl.WhjlConstant;
|
import com.fzzy.otherview.whhpjl.dto.*;
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.io.BufferedReader;
|
import java.io.FileReader;
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.Base64;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 共享接口-计量单位
|
*
|
* @author czt
|
*/
|
@Component
|
public class WhjlShareApi2013PR {
|
@Autowired
|
private ApiCommonService apiCommonService;
|
@Autowired
|
private ApiPushManager apiPushManager;
|
@Autowired
|
private ApiInfoDataRep apiInfoDataRep;
|
@Autowired
|
private ConfigData configData;
|
@Autowired
|
private Fz40ToWhjlSync2013Rep fz40ToWhjlSync2013Rep;
|
|
@Autowired
|
private Fz40ToWhjlSync2013DmRep fz40ToWhjlSync2013DmRep;
|
|
@Autowired
|
private Fz40ToWhjlSync2013DdRep fz40ToWhjlSync2013DdRep;
|
|
@Autowired
|
private Fz40ToWhjlSync2013XmfRep fz40ToWhjlSync2013XmfRep;
|
|
@Autowired
|
private Fz40ToWhjlSync2013SyyRep fz40ToWhjlSync2013SyyRep;
|
|
/**
|
* 获取列表信息
|
* whjlShareApi2013PR#listData
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<WhjlShareApi2013> listData() {
|
List<ApiInfoData> result = apiInfoDataRep.getDataByInteId(WhjlConstant.API_CODE_2013);
|
if (null == result || result.isEmpty()) {
|
return null;
|
}
|
List<WhjlShareApi2013> list = new ArrayList<>();
|
WhjlShareApi2013 whjlShareApiData;
|
for (ApiInfoData infoData : result) {
|
whjlShareApiData = JSONObject.parseObject(infoData.getData(), WhjlShareApi2013.class);
|
whjlShareApiData.setKqdm(infoData.getKqdm());
|
whjlShareApiData.setCzbz(infoData.getCzbz());
|
whjlShareApiData.setUpdateTime(infoData.getUpdateTime());
|
list.add(whjlShareApiData);
|
}
|
return list;
|
}
|
|
/**
|
* 获取质检报告大米检验结果
|
* whjlShareApi2013PR#listItemShareApi2013Dm
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<ShareApi2013Dm> listItemShareApi2013Dm(String code) {
|
return JSON.parseArray(code, ShareApi2013Dm.class);
|
}
|
|
/**
|
* 获取质检报告小麦粉检验结果
|
* whjlShareApi2013PR#listItemShareApi2013Xmf
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<ShareApi2013Xmf> listItemShareApi2013Xmf(String code) {
|
return JSON.parseArray(code, ShareApi2013Xmf.class);
|
}
|
|
/**
|
* 获取质检报告大豆检验结果
|
* whjlShareApi2013PR#listItemShareApi2013Dd
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<ShareApi2013Dd> listItemShareApi2013Dd(String code) {
|
return JSON.parseArray(code, ShareApi2013Dd.class);
|
}
|
|
/**
|
* 获取质检报告食用油检验结果
|
* whjlShareApi2013PR#listItemShareApi2013Syy
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<ShareApi2013Syy> listItemShareApi2013Syy(String code) {
|
return JSON.parseArray(code, ShareApi2013Syy.class);
|
}
|
|
/**
|
* 更新或修改
|
* whjlShareApi2013PR#saveData
|
*
|
* @param data
|
* @return
|
*/
|
@DataResolver
|
public void saveData(WhjlShareApi2013 data) {
|
ApiInfoData infoData = new ApiInfoData();
|
infoData.setId(data.getQlyOrgReportId());
|
infoData.setKqdm(data.getKqdm());
|
infoData.setInteType(WhjlConstant.API_CATEGORY_20);
|
infoData.setInteId(WhjlConstant.API_CODE_2013);
|
infoData.setUpdateTime(new Date());
|
infoData.setDataId(data.getQlyOrgReportId());
|
infoData.setData(JSON.toJSONString(data));
|
infoData.setCzbz(data.getCzbz());
|
infoData.setRemarks("备注信息");
|
|
apiInfoDataRep.save(infoData);
|
}
|
|
|
/**
|
* 删除
|
* whjlShareApi2013PR#delData
|
*
|
* @param data
|
* @return
|
*/
|
@Expose
|
public String delData(WhjlShareApi2013 data) {
|
apiInfoDataRep.deleteById(data.getQlyOrgReportId());
|
return null;
|
}
|
|
/**
|
* 更新数据
|
* whjlShareApi2013PR#pullData
|
*
|
* @param items
|
* @return
|
*/
|
@Expose
|
public String pullData(List<WhjlShareApi2013> items) {
|
|
|
//获取配置信息
|
List<ApiConfs> apiConfs = apiCommonService.listCacheConf();
|
if (null == apiConfs || apiConfs.isEmpty()) {
|
return "系统没有获取到库区配置信息,执行失败";
|
}
|
|
ApiRemoteService apiService;
|
ApiParam param;
|
ResponseDto responseDto;
|
ApiInfoData infoData;
|
String result = "";
|
List<WhjlShareApi2013> list;
|
for (ApiConfs apiConf : apiConfs) {
|
apiService = apiPushManager.getApiRemoteService(apiConf.getPushProtocol());
|
if (null == apiService) {
|
continue;
|
}
|
//封装参数
|
param = new ApiParam(apiConf, WhjlConstant.API_CATEGORY_20, WhjlConstant.API_CODE_2013);
|
responseDto = apiService.pullData(param, apiConf);
|
|
if (responseDto.getSuccess() == 0) {
|
list = JSONObject.parseArray(responseDto.getData(), WhjlShareApi2013.class);
|
if(null != list && list.size() > 0){
|
for (WhjlShareApi2013 shareData : list) {
|
//保存文件
|
//路径
|
String basePath = configData.getImgPath() + "COMMON/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
|
|
//文件id
|
|
if(StringUtils.isNotEmpty(shareData.getReportFile())){
|
String fileId = ContextUtil.getTimeId(1000);
|
String fileName = "附件"+ ".pdf";
|
Base64Util.saveBase64ToFile(shareData.getReportFile(),basePath + fileId + ".pdf");
|
|
shareData.setFileId(fileId);
|
shareData.setFileName(fileName);
|
shareData.setFileTime(new Date());
|
|
// shareData.setReportFile(null);
|
}
|
|
shareData.setCzbz(Constant.CZBZ_U);
|
|
// shareData.setYjfajgList(JSON.toJSONString(shareData.getYjfajg()));
|
// shareData.setCzbz(Constant.CZBZ_U);
|
infoData = new ApiInfoData();
|
infoData.setId(shareData.getQlyOrgReportId());
|
infoData.setKqdm(apiConf.getKqdm());
|
infoData.setInteType(WhjlConstant.API_CATEGORY_20);
|
infoData.setInteId(WhjlConstant.API_CODE_2013);
|
infoData.setUpdateTime(new Date());
|
infoData.setDataId(shareData.getQlyOrgReportId());
|
infoData.setData(JSON.toJSONString(shareData));
|
infoData.setCzbz(Constant.CZBZ_U);
|
apiInfoDataRep.save(infoData);
|
}
|
}
|
}
|
result += responseDto.toString();
|
return result;
|
}
|
return null;
|
}
|
|
/**
|
* 同步至库区数据库
|
* whjlShareApi2013PR#sysData
|
*
|
* @return
|
*/
|
@Expose
|
public String sysData() {
|
List<WhjlShareApi2013> list = listData();
|
//转换成库区软件需要的格式并保存
|
Fz40Quality fz40Quality = null;
|
for (WhjlShareApi2013 whjlShareApi2013 : list) {
|
fz40Quality = new Fz40Quality();
|
}
|
return null;
|
}
|
|
|
public static void main(String[] args) {
|
// 1. 指定文件路径(替换为你的实际路径)
|
String filePath = "C:\\Users\\ws183\\Desktop\\b.txt";
|
|
// 2. 读取并转换数据
|
List<WhjlShareApi2013> dataList = readJsonFileToList(filePath);
|
|
for (WhjlShareApi2013 data : dataList) {
|
//保存文件
|
String basePath = "D:/IGDS/FILE/" + "COMMON/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
|
|
String fileId = ContextUtil.getTimeId(1000);
|
String fileName = "附件"+ ".pdf";
|
Base64Util.base64StringToPDF(data.getReportFile(),basePath , fileId + ".pdf");
|
|
}
|
// 3. 打印结果
|
if (dataList != null) {
|
System.out.println("成功读取 " + dataList.size() + " 条数据:");
|
dataList.forEach(System.out::println);
|
}
|
}
|
|
private static List<WhjlShareApi2013> readJsonFileToList(String filePath) {
|
// 读取文件内容
|
String jsonContent = readFileContent(filePath);
|
if (jsonContent == null || jsonContent.trim().isEmpty()) {
|
return new ArrayList<>();
|
}
|
|
//解析JSON
|
|
List<WhjlShareApi2013> list = JSONObject.parseArray(jsonContent, WhjlShareApi2013.class);
|
|
return list;
|
}
|
|
private static String readFileContent(String filePath) {
|
StringBuilder content = new StringBuilder();
|
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
String line;
|
while ((line = reader.readLine()) != null) {
|
content.append(line);
|
}
|
return content.toString();
|
} catch (IOException e) {
|
System.err.println("文件读取失败: " + e.getMessage());
|
return null;
|
}
|
}
|
|
/**
|
* 同步至库区数据库
|
* whjlShareApi2013PR#sysDataToDept
|
*/
|
@Expose
|
public void sysDataToDept(){
|
//获取所有数据
|
List<WhjlShareApi2013> list = listData();
|
Fz40WhjlMQuality fz40WhjlMQuality = null;
|
for (WhjlShareApi2013 whjlShareApi2013 : list) {
|
fz40WhjlMQuality = new Fz40WhjlMQuality();
|
fz40WhjlMQuality.setProvReserve(Constant.YN_Y);
|
fz40WhjlMQuality.setId(whjlShareApi2013.getQlyOrgReportId());
|
String basePath = configData.getImgPath() + "COMMON/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/";
|
|
if(StringUtils.isNotEmpty(whjlShareApi2013.getReportFile())){
|
|
String fileId = ContextUtil.getTimeId(1000) + ".pdf";
|
String fileName = "附件"+ ".pdf";
|
Base64Util.base64StringToPDF(whjlShareApi2013.getReportFile(),basePath , fileId );
|
|
|
whjlShareApi2013.setFileId(fileId);
|
whjlShareApi2013.setFileName(fileName);
|
whjlShareApi2013.setFileTime(new Date());
|
whjlShareApi2013.setReportFile(null);
|
}
|
BeanUtils.copyProperties(whjlShareApi2013, fz40WhjlMQuality);
|
fz40ToWhjlSync2013Rep.save(fz40WhjlMQuality);
|
if(whjlShareApi2013.getOrgReportNoodlesList() != null){
|
List<ShareApi2013Xmf> orgReportNoodlesList = whjlShareApi2013.getOrgReportNoodlesList();
|
for (ShareApi2013Xmf shareApi2013Xmf : orgReportNoodlesList) {
|
Fz40WhjlCheckItemXmf fz40WhjlCheckItemXmf = new Fz40WhjlCheckItemXmf();
|
BeanUtils.copyProperties(shareApi2013Xmf,fz40WhjlCheckItemXmf);
|
if(StringUtils.isEmpty(fz40WhjlCheckItemXmf.getQlyOrgReportNoodlesId())) continue;
|
fz40ToWhjlSync2013XmfRep.save(fz40WhjlCheckItemXmf);
|
}
|
}
|
if(whjlShareApi2013.getOrgReportSoybeanList() != null){
|
List<ShareApi2013Dd> orgReportSoybeanList = whjlShareApi2013.getOrgReportSoybeanList();
|
for (ShareApi2013Dd shareApi2013Dd : orgReportSoybeanList) {
|
Fz40WhjlCheckItemDd fz40WhjlCheckItemDd = new Fz40WhjlCheckItemDd();
|
BeanUtils.copyProperties(shareApi2013Dd,fz40WhjlCheckItemDd);
|
if(StringUtils.isEmpty(fz40WhjlCheckItemDd.getQlyOrgReportSoybeanId())) continue;
|
|
fz40ToWhjlSync2013DdRep.save(fz40WhjlCheckItemDd);
|
}
|
}
|
if(whjlShareApi2013.getOrgReportRiceList() != null){
|
List<ShareApi2013Dm> orgReportRiceList = whjlShareApi2013.getOrgReportRiceList();
|
for (ShareApi2013Dm shareApi2013Dm : orgReportRiceList) {
|
Fz40WhjlCheckItemDm fz40WhjlCheckItemDm = new Fz40WhjlCheckItemDm();
|
BeanUtils.copyProperties(shareApi2013Dm,fz40WhjlCheckItemDm);
|
if(StringUtils.isEmpty(fz40WhjlCheckItemDm.getQlyOrgReportRiceId())) continue;
|
|
fz40ToWhjlSync2013DmRep.save(fz40WhjlCheckItemDm);
|
}
|
}
|
if(whjlShareApi2013.getOrgReportOilList() != null){
|
List<ShareApi2013Syy> orgReportOilList = whjlShareApi2013.getOrgReportOilList();
|
for (ShareApi2013Syy shareApi2013Syy : orgReportOilList) {
|
Fz40WhjlCheckItemSyy fz40WhjlCheckItemSyy = new Fz40WhjlCheckItemSyy();
|
BeanUtils.copyProperties(shareApi2013Syy,fz40WhjlCheckItemSyy);
|
if(StringUtils.isEmpty(fz40WhjlCheckItemSyy.getQlyOrgReportOilId())) continue;
|
|
fz40ToWhjlSync2013SyyRep.save(fz40WhjlCheckItemSyy);
|
}
|
}
|
|
}
|
}
|
}
|