YYC
2025-05-16 fd33b1408f39e30fcfee037468ace9050e27b739
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
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.data.SyncProtocol;
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.view.repository.ApiInfoDataRep;
import com.fzzy.otherview.whhpjl.WhjlConstant;
import com.fzzy.otherview.whhpjl.dto.WhjlShareApi2002;
import com.fzzy.otherview.whhpjl.dto.WhjlShareApi2003;
import com.fzzy.otherview.whhpjl.dto.WhjlShareApi2004;
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 WhjlShareApi2004PR {
    @Autowired
    private ApiCommonService apiCommonService;
    @Autowired
    private ApiPushManager apiPushManager;
    @Autowired
    private ApiInfoDataRep apiInfoDataRep;
 
    /**
     * 获取列表信息
     * whjlShareApi2004PR#listData
     *
     * @return
     */
    @DataProvider
    public List<WhjlShareApi2004> listData() {
        List<ApiInfoData> result = apiInfoDataRep.getDataByInteId(WhjlConstant.API_CODE_2004);
        if (null == result || result.isEmpty()) {
            return null;
        }
        List<WhjlShareApi2004> list = new ArrayList<>();
        WhjlShareApi2004 whjlShareApiData;
        for (ApiInfoData infoData : result) {
            whjlShareApiData = JSONObject.parseObject(infoData.getData(), WhjlShareApi2004.class);
            whjlShareApiData.setKqdm(infoData.getKqdm());
            whjlShareApiData.setCzbz(infoData.getCzbz());
            whjlShareApiData.setUpdateTime(infoData.getUpdateTime());
            list.add(whjlShareApiData);
        }
        return list;
    }
 
 
    /**
     * 更新或修改
     * whjlShareApi2004PR#saveData
     *
     * @param data
     * @return
     */
    @DataResolver
    public void saveData(WhjlShareApi2004 data) {
        ApiInfoData infoData = new ApiInfoData();
        infoData.setId(data.getTyshxydm());
        infoData.setKqdm(data.getKqdm());
        infoData.setInteType(WhjlConstant.API_CATEGORY_20);
        infoData.setInteId(WhjlConstant.API_CODE_2004);
        infoData.setUpdateTime(new Date());
        infoData.setDataId(data.getTyshxydm());
        infoData.setData(JSON.toJSONString(data));
        infoData.setCzbz(data.getCzbz());
        infoData.setRemarks("备注信息");
 
        apiInfoDataRep.save(infoData);
    }
 
 
    /**
     * 删除
     * whjlShareApi2004PR#delData
     *
     * @param data
     * @return
     */
    @Expose
    public String delData(WhjlShareApi2004 data) {
        apiInfoDataRep.deleteById(data.getTyshxydm());
        return null;
    }
 
    /**
     * 更新数据
     * whjlShareApi2004PR#pullData
     *
     * @param items
     * @return
     */
    @Expose
    public String pullData(List<WhjlShareApi2004> items) {
 
 
        //获取配置信息
        List<ApiConfs> apiConfs = apiCommonService.listCacheConf();
        if (null == apiConfs || apiConfs.isEmpty()) {
            return "系统没有获取到库区配置信息,执行失败";
        }
 
        ApiRemoteService apiService;
        ApiParam param;
        ResponseDto responseDto;
        ApiInfoData infoData;
        String result = "";
        List<WhjlShareApi2004> list;
        for (ApiConfs apiConf : apiConfs) {
            if(!apiConf.getSyncProtocol().equals(SyncProtocol.FZZY_V40_WHJL.getCode())){
                continue;
            }
            apiService = apiPushManager.getApiRemoteService(apiConf.getPushProtocol());
            if (null == apiService) {
                continue;
            }
            //封装参数
            param = new ApiParam(apiConf, WhjlConstant.API_CATEGORY_20, WhjlConstant.API_CODE_2004);
            responseDto = apiService.pullData(param, apiConf);
 
            if (responseDto.getSuccess() == 0) {
                list = JSONObject.parseArray(responseDto.getData(), WhjlShareApi2004.class);
                if(null != list && list.size() > 0){
                    for (WhjlShareApi2004 shareData : list) {
                        shareData.setCzbz(Constant.CZBZ_U);
                        infoData = new ApiInfoData();
                        infoData.setId(shareData.getTyshxydm());
                        infoData.setKqdm(apiConf.getKqdm());
                        infoData.setInteType(WhjlConstant.API_CATEGORY_20);
                        infoData.setInteId(WhjlConstant.API_CODE_2004);
                        infoData.setUpdateTime(new Date());
                        infoData.setDataId(shareData.getTyshxydm());
                        infoData.setData(JSON.toJSONString(shareData));
                        infoData.setCzbz(Constant.CZBZ_U);
                        apiInfoDataRep.save(infoData);
                    }
                }
            }
            result += responseDto.toString();
            return result;
        }
        return null;
    }
}