| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- package com.uas.eis.service.Impl;
- import com.alibaba.fastjson.JSONObject;
- import com.uas.eis.dao.BaseDao;
- import com.uas.eis.dao.SqlRowList;
- import com.uas.eis.dto.stksto.QueryAccountantProjectDto;
- import com.uas.eis.dto.stksto.QueryCashFlowItemsDto;
- import com.uas.eis.dto.stksto.QueryTravellingMerchantDto;
- import com.uas.eis.dto.stksto.StkCommonDto;
- import com.uas.eis.sdk.dto.CustvendDTO;
- import com.uas.eis.sdk.dto.SaveOrChangeCustomerDetailDto;
- import com.uas.eis.sdk.dto.SaveOrChangeCustomerDto;
- import com.uas.eis.service.RequestSTKService;
- import com.uas.eis.utils.HuToolUtils;
- import com.uas.eis.utils.STKSignUtil;
- import com.uas.eis.vo.stkVo.*;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.jdbc.core.BeanPropertyRowMapper;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Service
- @Slf4j
- public class RequestSTKServiceImpl implements RequestSTKService {
- @Value("${STK.app_id}")
- private String STK_APP_ID;
- @Value("${STK.app_key}")
- private String STK_APP_KEY;
- /** 新增修改客商信息接口地址 */
- @Value("${STK.save_or_update_url}")
- private String SAVE_OR_UPDATE_URL;
- /** 自动化查询接口地址 */
- @Value("${STK.query_url}")
- private String QUERY_URL;
- /** 公司组织编码 */
- @Value("${STK.s_org_code}")
- private String S_ORG_CODE;
- /** 新增修改客商信息接口请求编码 */
- @Value("${STK.save_or_update_request_code}")
- private String SAVE_OR_UPDATE_REQUEST_CODE ;
- /** 查询现金流量项目接口编码 */
- @Value("${STK.cash_flow_items_request_code}")
- private String CASH_FLOW_ITEMS_REQUEST_CODE;
- /** 查询会计科目方法编码 */
- @Value("${STK.accountant_project_request_code}")
- private String ACCOUNTANT_PROJECT_REQUEST_CODE;
- @Autowired
- private BaseDao baseDao;
- /**
- * 获取客商相关数据
- * */
- @Override
- public TravellingMerchantVo selectTravellingMerchantList(QueryTravellingMerchantDto dto, String url){
- dto.setS_orgcode(S_ORG_CODE);
- log.info("请求参数dto,content:"+JSONObject.toJSONString(dto));
- //头部请求参数
- Map<String,String> headerMap = null;
- try {
- headerMap = getHeaderMap(dto);
- } catch (Exception e) {
- log.error("STK加密异常:{}",e.getMessage());
- }
- //请求数据 (接口地址根据测试环境与正式环境变更)
- HttpResultResponse resultResponse = HuToolUtils.post(url,dto,headerMap);
- if(!resultResponse.getSuccess()){
- log.error(resultResponse.getMessage());
- return null;
- }
- log.info("STK,获取客商信息返回结果:{}",JSONObject.toJSONString(resultResponse));
- if(StringUtils.isBlank(resultResponse.getBody())){
- return null;
- }
- //System.out.println("返回结果:"+listArray.size());
- return JSONObject.parseObject(resultResponse.getBody(),TravellingMerchantVo.class); //返回结果
- }
- @Override
- public SaveOrChangeCustomerVo saveOrChangeCustomer(List<SaveOrChangeCustomerDetailDto> sourceDataList) {
- if(CollectionUtils.isEmpty(sourceDataList)){
- log.info("深投控,新增修改客商信息数据为空");
- return new SaveOrChangeCustomerVo();
- }
- //新增修改客商信息对象集合
- //List<SaveOrChangeCustomerDetailDto> detailDtos = doSaveOrUpdateCustomerParam(sourceDataList);
- //调用深投控新增修改客商信息
- SaveOrChangeCustomerDto changeCustomerDto = new SaveOrChangeCustomerDto();
- changeCustomerDto.setParam(sourceDataList);
- HttpResultResponse resultResponse = HuToolUtils.post(SAVE_OR_UPDATE_URL+SAVE_OR_UPDATE_REQUEST_CODE,changeCustomerDto);
- log.info("深投控,新增修改客商信息,返回结果数据{}",JSONObject.toJSONString(resultResponse));
- if(!resultResponse.getSuccess()){
- log.info("深投控,新增修改客商信息数据异常:{}",resultResponse.getMessage());
- }
- return JSONObject.parseObject(resultResponse.getBody(), SaveOrChangeCustomerVo.class);
- }
- @Override
- public CashFlowItemsVo getCashFlowItems(StkCommonDto dto) {
- /*StkCommonDto stkCommonDto = new StkCommonDto();
- stkCommonDto.setParam(dto);*/
- //头部请求参数
- Map<String,String> headerMap = null;
- try {
- headerMap = getHeaderMap(dto);
- } catch (Exception e) {
- log.error("STK加密异常:{}",e.getMessage());
- }
- HttpResultResponse resultResponse = HuToolUtils.post("https://192.168.2.179/api/oapigw/api/oapisvc/automicApi/89edb885a8cf4412b870233fc89fb381",dto,headerMap);
- log.info("深投控,现金流项目,返回结果数据{}",JSONObject.toJSONString(resultResponse));
- if(!resultResponse.getSuccess()){
- log.info("深投控,现金流项目数据异常:{}",resultResponse.getMessage());
- }
- return JSONObject.parseObject(resultResponse.getBody(), CashFlowItemsVo.class);
- }
- @Override
- public AccountantProjectVo getAccountantProject(QueryAccountantProjectDto dto) {
- StkCommonDto stkCommonDto = new StkCommonDto();
- stkCommonDto.setParam(dto);
- //头部请求参数
- Map<String,String> headerMap = null;
- try {
- headerMap = getHeaderMap(dto);
- } catch (Exception e) {
- log.error("STK加密异常:{}",e.getMessage());
- }
- HttpResultResponse resultResponse = HuToolUtils.post(QUERY_URL+ACCOUNTANT_PROJECT_REQUEST_CODE,stkCommonDto,headerMap);
- log.info("深投控,会计项目,返回结果数据{}",JSONObject.toJSONString(resultResponse));
- if(!resultResponse.getSuccess()){
- log.info("深投控,会计项目数据异常:{}",resultResponse.getMessage());
- }
- return JSONObject.parseObject(resultResponse.getBody(),AccountantProjectVo.class);
- }
- /**
- * 新增修改客商信息请求参数封装
- * @Param 数据库查询数据
- * */
- private List<SaveOrChangeCustomerDetailDto> doSaveOrUpdateCustomerParam(List<Object> sourceDataList){
- if(CollectionUtils.isEmpty(sourceDataList)){
- return new ArrayList<>();
- }
- List<SaveOrChangeCustomerDetailDto> detailDtos = new ArrayList<>();
- sourceDataList.stream().forEach(p->{
- SaveOrChangeCustomerDetailDto detailDto = new SaveOrChangeCustomerDetailDto();
- // todo 数据处理, 业务数据需要将 List<Object>中的Object换成数据库查询出的对象类型
- detailDtos.add(detailDto);
- });
- return detailDtos;
- }
- @Override
- public List<CustvendDTO> queryList() {
- List<CustvendDTO> custvendDTO = new ArrayList<CustvendDTO>();
- SqlRowList rs = baseDao.queryForRowSet("select * from STK_CUSTVEND_CS");
- while (rs.next()) {
- CustvendDTO custvend = baseDao.getJdbcTemplate().queryForObject("select * from STK_CUSTVEND_CS where id = " + rs.getInt("id"), new BeanPropertyRowMapper<CustvendDTO>(CustvendDTO.class));
- custvendDTO.add(custvend);
- }
- return custvendDTO;
- }
- /**
- * POST请求头部参数封装
- * */
- public Map<String,String> getHeaderMap(Object dto) throws Exception {
- //获取签名
- String sign = getSign(dto);
- log.info("STK,加密后的签名:"+sign);
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- Map<String,String> headerMap = new HashMap<>();
- headerMap.put("appid",STK_APP_ID);
- headerMap.put("timestamp",timestamp);
- headerMap.put("sign",sign);
- headerMap.put("Content-Type","application/json");
- return headerMap;
- }
- /**
- * 获取深投控加密参数
- * */
- public String getSign(Object dto) throws Exception {
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- String content = JSONObject.toJSONString(dto);
- //加签方法第一个参数
- StringBuilder signBuilder = new StringBuilder("appid").append("=").append(STK_APP_ID).append("&")
- .append(content).append("&")
- .append("timestamp").append("=").append(timestamp).append("&")
- .append("key").append("=").append(STK_APP_KEY);
- log.info("STK,加密前参数:"+signBuilder.toString());
- //加签
- return STKSignUtil.HMACSHA256(signBuilder.toString(),STK_APP_KEY);
- }
- }
|