| 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.view.repository.ApiInfoDataRep; | 
| import com.fzzy.otherview.whhpjl.WhjlConstant; | 
| import com.fzzy.otherview.whhpjl.dto.WhjlApi1102; | 
| 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:YAN | 
|  */ | 
| @Component | 
| public class WhjlApi1102PR { | 
|   | 
|     @Autowired | 
|     private ApiCommonService apiCommonService; | 
|     @Autowired | 
|     private ApiPushManager apiPushManager; | 
|     @Autowired | 
|     private ApiInfoDataRep apiInfoDataRep; | 
|   | 
|     /** | 
|      * 获取列表信息 | 
|      * whjlApi1102PR#listData | 
|      * | 
|      * @return | 
|      */ | 
|     @DataProvider | 
|     public List<WhjlApi1102> listData() { | 
|         List<ApiInfoData> result = apiInfoDataRep.getDataByInteId(WhjlConstant.API_CODE_1102); | 
|         if (null == result || result.isEmpty()) { | 
|             return null; | 
|         } | 
|         List<WhjlApi1102> list = new ArrayList<>(); | 
|         WhjlApi1102 whjlApi1102; | 
|         for (ApiInfoData infoData : result) { | 
|             whjlApi1102 = JSONObject.parseObject(infoData.getData(), WhjlApi1102.class); | 
|             whjlApi1102.setKqdm(infoData.getKqdm()); | 
|             whjlApi1102.setCzbz(infoData.getCzbz()); | 
|             whjlApi1102.setUpdateTime(infoData.getUpdateTime()); | 
|             whjlApi1102.setBizId(infoData.getDataId()); | 
|             list.add(whjlApi1102); | 
|         } | 
|         return list; | 
|     } | 
|   | 
|     /** | 
|      * 更新或修改 | 
|      * whjlApi1102PR#saveData | 
|      * | 
|      * @param data | 
|      * @return | 
|      */ | 
|     @DataResolver | 
|     public void saveData(WhjlApi1102 data) { | 
|         ApiInfoData infoData = new ApiInfoData(); | 
|         infoData.setId(data.getBizId()); | 
|         infoData.setKqdm(data.getKqdm()); | 
|         infoData.setInteType(WhjlConstant.API_CATEGORY_11); | 
|         infoData.setInteId(WhjlConstant.API_CODE_1102); | 
|         infoData.setUpdateTime(new Date()); | 
|         infoData.setDataId(data.getBizId()); | 
|         infoData.setData(JSON.toJSONString(data)); | 
|         infoData.setCzbz(data.getCzbz()); | 
|         infoData.setRemarks("备注信息"); | 
|   | 
|         apiInfoDataRep.save(infoData); | 
|     } | 
|   | 
|     /** | 
|      * 删除 | 
|      * whjlApi1102PR#delData | 
|      * | 
|      * @param data | 
|      * @return | 
|      */ | 
|     @Expose | 
|     public String delData(WhjlApi1102 data) { | 
|         apiInfoDataRep.deleteById(data.getBizId()); | 
|         return null; | 
|     } | 
|   | 
|     /** | 
|      * 上传 | 
|      * whjlApi1102PR#pushData | 
|      * | 
|      * @param items | 
|      * @return | 
|      */ | 
|     @Expose | 
|     public String pushData(List<WhjlApi1102> items) { | 
|         ResponseDto responseDto; | 
|         String result = ""; | 
|   | 
|         String kqdm = items.get(0).getKqdm(); | 
|         ApiConfs apiConf = apiCommonService.getConf(kqdm); | 
|   | 
|         if (null == apiConf) { | 
|             return "系统没有获取到当前库区配置信息,执行失败"; | 
|         } | 
|   | 
|         //封装参数 | 
|         ApiParam param = new ApiParam(apiConf, WhjlConstant.API_CATEGORY_11, WhjlConstant.API_CODE_1102); | 
|   | 
|         //获取实现接口 | 
|         ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol()); | 
|         if (null == apiService) { | 
|             return "系统没有当前推送协议配置,执行失败"; | 
|         } | 
|   | 
|         //推送,数据为集合形式 | 
|         responseDto = apiService.pushData(param, apiConf, items); | 
|         if (responseDto.getSuccess() == 0) { | 
|             //推送成功,更新数据上传状态 | 
|             ApiInfoData infoData; | 
|             for (WhjlApi1102 data : items) { | 
|                 if (Constant.CZBZ_I.equals(data.getCzbz())) { | 
|   | 
|                     infoData = new ApiInfoData(); | 
|                     infoData.setId(data.getBizId()); | 
|                     infoData.setKqdm(data.getKqdm()); | 
|                     infoData.setInteType(WhjlConstant.API_CATEGORY_11); | 
|                     infoData.setInteId(WhjlConstant.API_CODE_1102); | 
|                     infoData.setUpdateTime(new Date()); | 
|                     infoData.setDataId(data.getBizId()); | 
|   | 
|                     data.setCzbz(Constant.CZBZ_U); | 
|                     infoData.setCzbz(Constant.CZBZ_U); | 
|                     infoData.setData(JSON.toJSONString(data)); | 
|   | 
|                     apiInfoDataRep.save(infoData); | 
|                 } | 
|             } | 
|             result += responseDto.toString(); | 
|         } | 
|         return result; | 
|     } | 
| } |