src/main/java/com/fzzy/api/timer/ApiWhjlScheduled.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/api/view/repository/ApiInfoDataRep.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/async/whhpjl/impl/Fz40ToWhjlSync1212.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/otherview/whhpjl/WhjlShareApi20132.view.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/otherview/whhpjl/dto/WhjlShareApi2013.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlShareApi2013PR2.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/push/whhpjl/dto/WhjlPullReqDto.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/fzzy/api/timer/ApiWhjlScheduled.java
@@ -1,10 +1,14 @@ package com.fzzy.api.timer; import com.fzzy.api.data.ApiParam; import com.fzzy.otherview.whhpjl.pr.WhjlShareApi2013PR2; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Date; /** * @Description 武汉军粮省平台 @@ -26,10 +30,16 @@ log.info("------->>>>>>>>>>武汉黄陂军粮,系统定时统计共享接口省质检报告"); Date endTime = new Date(); Date startTime = DateUtils.addDays(endTime, -1); ApiParam param1 = new ApiParam(); param1.setStart(startTime); param1.setEnd(endTime); //获取共享数据 whjlShareApi2013PR2.pullData(null); whjlShareApi2013PR2.pullData(param1); //同步至库区数据库 whjlShareApi2013PR2.sysDataToDept(); whjlShareApi2013PR2.sysDataToDept(param1); } } src/main/java/com/fzzy/api/view/repository/ApiInfoDataRep.java
@@ -8,6 +8,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; public interface ApiInfoDataRep extends JpaRepository<ApiInfoData, String>, JpaSpecificationExecutor<ApiInfoData> { @@ -32,6 +33,15 @@ List<ApiInfoData> getDataByInteId(@Param("inteId") String inteId); /** * 根据接口编码查询数据 * * @param inteId * @return */ @Query("from ApiInfoData where inteId=:inteId and updateTime >=:start and updateTime <:end order by updateTime") List<ApiInfoData> getDataByInteId(@Param("inteId") String inteId, @Param("start") Date start, @Param("end") Date end); /** * 根据表单主键更新操作标志状态 * * @param id 主键ID src/main/java/com/fzzy/async/whhpjl/impl/Fz40ToWhjlSync1212.java
@@ -137,6 +137,7 @@ apiData.setLspzmc(lspz.get(0).getName());//品种名称 } if (sysData.getFoodVariety().startsWith("2")){ apiData.setLspzmc("面粉");//品种名称 apiData.setKctzbh("1234567891234567002");//库存台账ID apiData.setKctzcppcid("12312332132145002");//库存台账批次ID apiData.setJldwbm("12");//计量单位编码 @@ -150,6 +151,7 @@ apiData.setCpmc("精致小麦粉");//产品编号 } if (sysData.getFoodVariety().startsWith("1")){ apiData.setLspzmc("大米");//品种名称 apiData.setKctzbh("1234567891234567001");//库存台账ID apiData.setKctzcppcid("12312332132145001");//库存台账批次ID apiData.setJldwbm("12");//计量单位编码 @@ -163,6 +165,7 @@ } if (sysData.getFoodVariety().startsWith("3")){ apiData.setLspzmc("食用油");//品种名称 apiData.setKctzbh("1234567891234567003");//库存台账ID apiData.setKctzcppcid("12312332132145003");//库存台账批次ID apiData.setJldwbm("13");//计量单位编码 src/main/java/com/fzzy/otherview/whhpjl/WhjlShareApi20132.view.xml
@@ -526,12 +526,27 @@ <Property name="label">检验结论</Property> </PropertyDef> </DataType> <DataType name="dtTest"> <Property name="creationType">com.fzzy.api.data.ApiParam</Property> <PropertyDef name="start"> <Property name="dataType">DateTime</Property> <Property name="label">开始时间</Property> </PropertyDef> <PropertyDef name="end"> <Property name="dataType">DateTime</Property> <Property name="label">截止时间</Property> </PropertyDef> </DataType> </Model> <View layout="regionPadding:10"> <Property name="packages">font-awesome,css-common</Property> <DataSet id="dsMain"> <Property name="dataType">[dtMain]</Property> <Property name="dataProvider">whjlShareApi2013PR2#listData</Property> </DataSet> <DataSet id="dsTest"> <ClientEvent name="onReady">self.insert({});</ClientEvent> <Property name="dataType">dtTest</Property> </DataSet> <Container layout="regionPadding:10" layoutConstraint="top"> <Property name="exClassName">bg-color</Property> @@ -582,13 +597,8 @@ <Property name="exClassName">btn-flush</Property> </Button> <Button layoutConstraint="left"> <ClientEvent name="onClick">var select = view.get("#dgMain").get("selection");
 view.get("#ajaxPull").set("parameter",select).execute(function(result){
 view.get("#dsMain").flushAsync();
 $notify(result);
 });
 </ClientEvent> <Property name="caption">手动更新</Property> <ClientEvent name="onClick">view.get("#testWarn").show()</ClientEvent> <Property name="caption">手动拉取</Property> <Property name="iconClass">fa fa-hand-o-up</Property> <Property name="exClassName">btn-default</Property> </Button> @@ -601,12 +611,7 @@ <Property name="exClassName">btn-flush</Property> </Button> <Button layoutConstraint="left"> <ClientEvent name="onClick">
 var select = view.get("#dgMain").get("selection");
 view.get("#ajaxsysDataToDept").execute(function(result){
 view.get("#dsMain").flushAsync();
 $notify(result);
 });</ClientEvent> <ClientEvent name="onClick">view.get("#testWarn2").show()</ClientEvent> <Property name="caption">同步至库区</Property> <Property name="iconClass">fa fa-hand-o-up</Property> <Property name="exClassName">btn-default</Property> @@ -1320,6 +1325,101 @@ </Children> <Tools/> </Dialog> <Dialog id="testWarn" layout="padding:10;regionPadding:10"> <Property name="width">40%</Property> <Property name="iconClass">fa fa-flag-o</Property> <Property name="closeable">false</Property> <Property name="caption">起止时间</Property> <Buttons> <Button id="btnOk"> <ClientEvent name="onClick"> var data = view.get("#dsTest.data");
 view.get("#ajaxPull").set("parameter",data).execute(function(result){
 self.get("parent").hide();
 view.get("#dsMain").flushAsync();
 $notify(result);
 });
</ClientEvent> <Property name="caption">确定拉取</Property> <Property name="iconClass">fa fa-check</Property> </Button> <Button> <ClientEvent name="onClick">self.get("parent").hide();</ClientEvent> <Property name="caption">取消</Property> <Property name="iconClass">fa fa-times-circle</Property> <Property name="width">90</Property> </Button> </Buttons> <Children> <AutoForm> <Property name="dataSet">dsTest</Property> <Property name="cols">*</Property> <Property name="labelWidth">110</Property> <Property name="labelAlign">right</Property> <Property name="labelSeparator">:</Property> <AutoFormElement> <Property name="name">start</Property> <Property name="property">start</Property> <Editor/> </AutoFormElement> <AutoFormElement> <Property name="name">end</Property> <Property name="property">end</Property> <Editor/> </AutoFormElement> <Label layoutConstraint="colSpan:2"> <Property name="text">说明:必须填写起止时间!</Property> </Label> </AutoForm> </Children> <Tools/> </Dialog> <Dialog id="testWarn2" layout="padding:10;regionPadding:10"> <Property name="width">40%</Property> <Property name="iconClass">fa fa-flag-o</Property> <Property name="closeable">false</Property> <Property name="caption">起止时间</Property> <Buttons> <Button id="btnOk2"> <ClientEvent name="onClick"> var data = view.get("#dsTest.data");
 view.get("#ajaxsysDataToDept").set("parameter",data).execute(function(result){
 self.get("parent").hide();
 $notify(result);
 });
</ClientEvent> <Property name="caption">确定推送</Property> <Property name="iconClass">fa fa-check</Property> </Button> <Button> <ClientEvent name="onClick">self.get("parent").hide();</ClientEvent> <Property name="caption">取消</Property> <Property name="iconClass">fa fa-times-circle</Property> <Property name="width">90</Property> </Button> </Buttons> <Children> <AutoForm> <Property name="dataSet">dsTest</Property> <Property name="cols">*</Property> <Property name="labelWidth">110</Property> <Property name="labelAlign">right</Property> <Property name="labelSeparator">:</Property> <AutoFormElement> <Property name="name">start</Property> <Property name="property">start</Property> <Editor/> </AutoFormElement> <AutoFormElement> <Property name="name">end</Property> <Property name="property">end</Property> <Editor/> </AutoFormElement> <Label layoutConstraint="colSpan:2"> <Property name="text">说明:必须填写起止时间!</Property> </Label> </AutoForm> </Children> <Tools/> </Dialog> <ListDropDown id="listDropYN"> <Property name="items">是,否</Property> </ListDropDown> src/main/java/com/fzzy/otherview/whhpjl/dto/WhjlShareApi2013.java
@@ -18,6 +18,8 @@ public class WhjlShareApi2013 implements Serializable { private static final long serialVersionUID = 1L; public static String SORT_PROP = "qlyOrgReportId"; private String qlyOrgReportId; //质检报告id private String orderId; //订单表ID private String sampleId; //样品表ID src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlShareApi2013PR2.java
@@ -5,9 +5,11 @@ import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.annotation.Expose; import com.bstek.dorado.data.provider.Page; import com.fzzy.api.Constant; import com.fzzy.api.data.ApiParam; import com.fzzy.api.dto.ResponseDto; import com.fzzy.api.entity.Api1202; import com.fzzy.api.entity.ApiConfs; import com.fzzy.api.entity.ApiInfoData; import com.fzzy.api.service.ApiCommonService; @@ -21,12 +23,22 @@ import com.fzzy.data.ConfigData; import com.fzzy.otherview.whhpjl.WhjlConstant; import com.fzzy.otherview.whhpjl.dto.*; import lombok.extern.slf4j.Slf4j; 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.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Component; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -36,6 +48,8 @@ * * @author czt */ @Slf4j @Component public class WhjlShareApi2013PR2 { @Autowired @@ -73,6 +87,23 @@ @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; } public List<WhjlShareApi2013> listDataByTime(Date start, Date end) { List<ApiInfoData> result = apiInfoDataRep.getDataByInteId(WhjlConstant.API_CODE_2013, start, end); if (null == result || result.isEmpty()) { return null; } @@ -168,15 +199,16 @@ apiInfoDataRep.deleteById(data.getQlyOrgReportId()); return null; } /** * 更新数据 * whjlShareApi2013PR2#pullData * * @param items * @param * @return */ @Expose public String pullData(List<WhjlShareApi2013> items) { public String pullData(ApiParam param1) { //获取配置信息 @@ -198,14 +230,19 @@ } //封装参数 param = new ApiParam(apiConf, WhjlConstant.API_CATEGORY_20, WhjlConstant.API_CODE_2013); //设置起始时间 param.setStart(param1.getStart()); param.setEnd(param1.getEnd()); responseDto = apiService.pullData(param, apiConf); if(null == responseDto){ if (null == responseDto) { return "更新失败!"; } if (responseDto.getSuccess() == 0) { list = JSONObject.parseArray(responseDto.getData(), WhjlShareApi2013.class); if(null != list && list.size() > 0){ if (null != list && list.size() > 0) { for (WhjlShareApi2013 shareData : list) { //保存文件 //路径 @@ -213,10 +250,10 @@ //文件id if(StringUtils.isNotEmpty(shareData.getReportFile())){ if (StringUtils.isNotEmpty(shareData.getReportFile())) { String fileId = ContextUtil.getTimeId(1000); String fileName = "附件"+ ".pdf"; Base64Util.saveBase64ToFile(shareData.getReportFile(),basePath + fileId + ".pdf"); String fileName = "附件" + ".pdf"; Base64Util.base64StringToPDF(shareData.getReportFile(), basePath, fileId + ".pdf"); shareData.setFileId(fileId); shareData.setFileName(fileName); @@ -253,75 +290,81 @@ * whjlShareApi2013PR#sysDataToDept */ @Expose public void sysDataToDept(){ public void sysDataToDept(ApiParam param1) { //获取所有数据 List<WhjlShareApi2013> list = listData(); if(null == list || list.isEmpty()){ List<WhjlShareApi2013> list = listDataByTime(param1.getStart(), param1.getEnd()); 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") + "/"; try { if(StringUtils.isNotEmpty(whjlShareApi2013.getReportFile())){ fz40WhjlMQuality = new Fz40WhjlMQuality(); fz40WhjlMQuality.setProvReserve(Constant.YN_Y); fz40WhjlMQuality.setId(whjlShareApi2013.getQlyOrgReportId()); String basePath = configData.getImgPath() + "COMMON/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/"; String fileId = ContextUtil.getTimeId(1000) + ".pdf"; String fileName = "附件"+ ".pdf"; Base64Util.base64StringToPDF(whjlShareApi2013.getReportFile(),basePath , fileId ); 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); whjlShareApi2013.setFileId(fileId); whjlShareApi2013.setFileName(fileName); whjlShareApi2013.setFileTime(new Date()); whjlShareApi2013.setReportFile(null); log.info("存入附件信息={}", fileName); } } 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); 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.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; 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; fz40ToWhjlSync2013DmRep.save(fz40WhjlCheckItemDm); fz40ToWhjlSync2013DdRep.save(fz40WhjlCheckItemDd); } } } 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; 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; fz40ToWhjlSync2013SyyRep.save(fz40WhjlCheckItemSyy); 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); } } } catch (Exception e) { log.error("同步数据失败!", e); continue; } } } } src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java
@@ -6,9 +6,11 @@ import com.fzzy.push.whhpjl.dto.WhjlReqDto; import com.fzzy.push.whhpjl.dto.WhjlRespDto; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; /** * 武汉军粮省平台-上传数据服务类 @@ -20,59 +22,141 @@ @Component public class Whjl2023HttpClientUtil { @Autowired private RestTemplate restTemplate; /** * 数据上报post请求 * * @param url * @param reqData * @return */ public WhjlRespDto postPushData(String url, WhjlReqDto reqData) { public WhjlRespDto postPushData(String url, WhjlReqDto reqData) throws Exception { log.info("---------接口请求地址:" + url + "----------参数:" + JSON.toJSONString(reqData) + "---------"); BufferedReader in = null; URL urls = new URL(url); HttpURLConnection connection = null; OutputStream outputStream = null; String rs = ""; WhjlRespDto responseDto; try { rs = restTemplate.postForObject(url, reqData, String.class); connection = (HttpURLConnection) urls.openConnection(); connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8"); connection.setRequestProperty("Accept", "*/*"); connection.setRequestProperty("Range", "bytes=" + ""); connection.setConnectTimeout(20000); connection.setReadTimeout(30000); connection.setRequestMethod("POST"); } catch (Exception e) { System.out.println("发生异常"); log.error(e.getMessage(), e); rs = null; return new WhjlRespDto(99, e.getMessage()); outputStream = connection.getOutputStream(); outputStream.write(JSON.toJSONString(reqData).getBytes("UTF-8")); try { connection.connect(); if (connection.getResponseCode() == 200) { in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); String line = ""; while ((line = in.readLine()) != null) { rs += line; } }else{ log.error("http状态:" + connection.getResponseCode()); log.error("http消息:" + connection.getResponseMessage()); } } catch (Exception e) { System.out.println("发生异常"); log.error(e.getMessage(), e); rs = null; return new WhjlRespDto(99, e.getMessage()); } log.info("---------接口返回:" + rs + "---------"); responseDto = JSON.parseObject(rs, WhjlRespDto.class); if (responseDto == null) return new WhjlRespDto(99, "接口请求发生未知错误"); return responseDto; } finally { try { outputStream.close(); if (in != null) { in.close(); } } catch (Exception e) { } outputStream = null; if (connection != null) connection.disconnect(); connection = null; } log.info("---------接口返回:" + rs + "---------"); responseDto = JSON.parseObject(rs, WhjlRespDto.class); if (responseDto == null) return new WhjlRespDto(99, "接口请求发生未知错误"); return responseDto; } /** * 数据上报post请求 * * @param url * @param reqData * @return */ public WhjlPullRespDto postPullData(String url, WhjlPullReqDto reqData) { public WhjlPullRespDto postPullData(String url, WhjlPullReqDto reqData) throws Exception { log.info("---------接口请求地址:" + url + "----------参数:" + JSON.toJSONString(reqData) + "---------"); BufferedReader in = null; URL urls = new URL(url); HttpURLConnection connection = null; OutputStream outputStream = null; String rs = ""; WhjlPullRespDto responseDto; try { rs = restTemplate.postForObject(url, reqData, String.class); connection = (HttpURLConnection) urls.openConnection(); connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8"); connection.setRequestProperty("Accept", "*/*"); connection.setRequestProperty("Range", "bytes=" + ""); connection.setConnectTimeout(20000); connection.setReadTimeout(30000); connection.setRequestMethod("POST"); } catch (Exception e) { System.out.println("发生异常"); log.error(e.getMessage(), e); rs = null; return new WhjlPullRespDto(99, null); outputStream = connection.getOutputStream(); outputStream.write(JSON.toJSONString(reqData).getBytes("UTF-8")); try { connection.connect(); if (connection.getResponseCode() == 200) { in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); String line = ""; while ((line = in.readLine()) != null) { rs += line; } } else { log.error("http状态:" + connection.getResponseCode()); log.error("http消息:" + connection.getResponseMessage()); } } catch (Exception e) { log.error(e.getMessage(), e); rs = null; return new WhjlPullRespDto(99, null); } log.info("---------接口返回:" + rs + "---------"); responseDto = JSON.parseObject(rs, WhjlPullRespDto.class); if (responseDto == null) { return new WhjlPullRespDto(99, "接口请求发生未知错误"); } return responseDto; } finally { try { outputStream.close(); if (in != null) { in.close(); } } catch (Exception e) { } outputStream = null; if (connection != null) connection.disconnect(); connection = null; } log.info("---------接口返回:" + rs + "---------"); responseDto = JSON.parseObject(rs, WhjlPullRespDto.class); if (responseDto == null) return new WhjlPullRespDto(99, "接口请求发生未知错误"); return responseDto; } } src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java
@@ -19,6 +19,7 @@ import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateFormatUtils; import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -352,6 +353,13 @@ reqData.setUid(conf.getUserName()); //应用码 reqData.setAppcode(conf.getAppCode()); if(null != param.getStart()){ reqData.setStarttime(DateFormatUtils.format(param.getStart(), "yyyy-MM-dd HH:mm:ss")); } if(null != param.getEnd()){ reqData.setEndtime(DateFormatUtils.format(param.getEnd(), "yyyy-MM-dd HH:mm:ss")); } //时间戳 reqData.setTimestamp(Long.valueOf(ContextUtil.getCurTimeMillis())); //身份签名,对应用码_授权码_站点编码_报文ID_时间戳进行MD5算法签名 src/main/java/com/fzzy/push/whhpjl/dto/WhjlPullReqDto.java
@@ -36,4 +36,14 @@ * 身份签名 */ private String accesstoken; /** * 开始时间 */ private String starttime; /** * 截止时间 */ private String endtime; }