czt
20 小时以前 9f6dacf7b39e5aeba37d8faf575c9e56d8cbe51a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
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);
                }
            }
 
        }
    }
}