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
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.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.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 共享接口-计量单位
 *
 * @author czt
 */
@Component
public class WhjlShareApi2013PR2 {
    @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;
 
    private static final String DEPT_ID = "5327_001";
 
 
    /**
     * 获取列表信息
     * whjlShareApi2013PR2#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;
    }
 
    /**
     * 获取质检报告大米检验结果
     * whjlShareApi2013PR2#listItemShareApi2013Dm
     *
     * @return
     */
    @DataProvider
    public List<ShareApi2013Dm> listItemShareApi2013Dm(String code) {
        return JSON.parseArray(code, ShareApi2013Dm.class);
    }
 
    /**
     * 获取质检报告小麦粉检验结果
     * whjlShareApi2013P2R#listItemShareApi2013Xmf
     *
     * @return
     */
    @DataProvider
    public List<ShareApi2013Xmf> listItemShareApi2013Xmf(String code) {
        return JSON.parseArray(code, ShareApi2013Xmf.class);
    }
 
    /**
     * 获取质检报告大豆检验结果
     * whjlShareApi2013PR2#listItemShareApi2013Dd
     *
     * @return
     */
    @DataProvider
    public List<ShareApi2013Dd> listItemShareApi2013Dd(String code) {
        return JSON.parseArray(code, ShareApi2013Dd.class);
    }
 
    /**
     * 获取质检报告食用油检验结果
     * whjlShareApi2013PR2#listItemShareApi2013Syy
     *
     * @return
     */
    @DataProvider
    public List<ShareApi2013Syy> listItemShareApi2013Syy(String code) {
        return JSON.parseArray(code, ShareApi2013Syy.class);
    }
 
    /**
     * 更新或修改
     * whjlShareApi2012PR#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);
    }
 
 
    /**
     * 删除
     * whjlShareApi2012PR#delData
     *
     * @param data
     * @return
     */
    @Expose
    public String delData(WhjlShareApi2013 data) {
        apiInfoDataRep.deleteById(data.getQlyOrgReportId());
        return null;
    }
    /**
     * 更新数据
     * whjlShareApi2013PR2#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(null == responseDto){
                return "更新失败!";
            }
            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#sysDataToDept
     */
    @Expose
    public void sysDataToDept(){
        //获取所有数据
        List<WhjlShareApi2013> list = listData();
        if(null == list || list.isEmpty()){
            return;
        }
        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);
            fz40WhjlMQuality.setCompanyId(configData.getCompanyId());
            fz40WhjlMQuality.setDeptId(DEPT_ID);
            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);
                }
            }
 
        }
    }
}