| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- package com.uas.eis.service.Impl;
- import cn.hutool.http.HttpRequest;
- 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.sdk.dto.UpdateCustVendDTO;
- 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.Synchronized;
- 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.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.time.temporal.TemporalAdjusters;
- 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.complexity_query_url}")
- private String COMPLEXITY_QUERY_URL;
- /** 自动化查询接口地址 */
- @Value("${STK.query_url}")
- private String QUERY_URL;
- /** 公司组织编码 */
- @Value("${STK.s_org_code}")
- private String S_ORG_CODE;
- /**
- * 获取客商信息接口编码
- * */
- @Value("${STK.get_travelling_merchant}")
- private String GET_TRAVELLING_MERCHANT;
- /** 新增修改客商信息接口请求编码 */
- @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();
- }
- //头部请求参数
- Map<String,String> headerMap = null;
- try {
- headerMap = getHeaderMap(sourceDataList);
- } catch (Exception e) {
- log.error("STK加密异常:{}",e.getMessage());
- }
- //新增修改客商信息对象集合
- //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,headerMap);
- 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(QUERY_URL+CASH_FLOW_ITEMS_REQUEST_CODE,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 HttpResultResponse buildPostParam(Integer page,Integer size,QueryCashFlowItemsDto dtoParam) throws Exception {
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- //加签方法的重要参数
- JSONObject request=new JSONObject(4);
- request.put("page",page);
- request.put("size",size);
- //传入参数 此处案例仅放置了时间,可自行添加
- JSONObject param=new JSONObject();
- //param.put("UPDATE_TIME_start","2024-05-09 14:24:06");
- //param.put("UPDATE_TIME_end","2024-05-09 15:01:28");
- //param.put("TASKNO","P2022032200000041");
- //param.put("TASKCODE","202409");
- request.put("param",dtoParam);
- String content = request.toString();
- //加签方法第一个参数
- 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);
- //加签
- String sign = STKSignUtil.HMACSHA256(signBuilder.toString(),STK_APP_KEY);
- log.info("STK,原始签名:"+signBuilder.toString());
- log.info("STK,加密签名:"+sign);
- Map<String,String> header = new HashMap<>();
- header.put("appid",STK_APP_ID);
- header.put("timestamp", timestamp);
- header.put("sign", sign);
- header.put("Content-Type", "application/json");
- HttpResultResponse resultResponse = HuToolUtils.post(QUERY_URL+CASH_FLOW_ITEMS_REQUEST_CODE
- ,request, header);
- log.info("示例返回:{}",JSONObject.toJSONString(resultResponse));
- return resultResponse ;
- }
- @Override
- public HttpResultResponse buildKMPostParam(Integer page, Integer size, QueryAccountantProjectDto dto) throws Exception {
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- //加签方法的重要参数
- JSONObject request=new JSONObject(4);
- request.put("page",page);
- request.put("size",size);
- //传入参数 此处案例仅放置了时间,可自行添加
- JSONObject param=new JSONObject();
- //param.put("UPDATE_TIME_start","2024-05-09 14:24:06");
- //param.put("UPDATE_TIME_end","2024-05-09 15:01:28");
- //param.put("TASKNO","P2022032200000041");
- //param.put("TASKCODE","202409");
- request.put("param",dto);
- String content = request.toString();
- //加签方法第一个参数
- 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);
- //加签
- String sign = STKSignUtil.HMACSHA256(signBuilder.toString(),STK_APP_KEY);
- log.info("STK,原始签名:"+signBuilder.toString());
- log.info("STK,加密签名:"+sign);
- Map<String,String> header = new HashMap<>();
- header.put("appid",STK_APP_ID);
- header.put("timestamp", timestamp);
- header.put("sign", sign);
- header.put("Content-Type", "application/json");
- HttpResultResponse resultResponse = HuToolUtils.post(QUERY_URL+ACCOUNTANT_PROJECT_REQUEST_CODE
- ,request, header);
- log.info("示例返回:{}",JSONObject.toJSONString(resultResponse));
- return resultResponse ;
- }
- @Override
- public SaveOrChangeCustomerDataVo updateKSPostParam(SaveOrChangeCustomerDetailDto dto) throws Exception {
- //时间戳
- /*String timestamp = Long.toString(System.currentTimeMillis());
- //每一条数据在这里构造,根据实际情况修改
- JSONObject request=new JSONObject(4);
- *//*Field[] fields = dto.getClass().getDeclaredFields();
- for(Field field : fields){
- String fieldName = field.getName();
- if(getValueByFieldName(fieldName,dto)!=null)
- request.put(fieldName, getValueByFieldName(fieldName,dto));
- }*//*
- request.put("NAME","紫光展讯通信惠州有限公司");
- request.put("S_CODE","2024-07-04 17:11:43");
- request.put("UID_TYPE","01");
- request.put("UID","91441300MA4WY7CN2T");
- request.put("CUSTOMER_TYPE","C0201");
- request.put("IS_VALID","1");
- request.put("CREATED_ORG","HRORGI0000000001");
- request.put("CREATED_SYSTEM","ZHONGTAI");
- request.put("ISTEMPORARY","0");
- request.put("MDM_CODE",null);
- request.put("CREAT_AT","2024-07-04 17:11:43");
- request.put("UPDATE_AT","2024-07-04 17:11:43");
- request.put("SERIAL","23468156486151");
- //param参数构造 并传入你构造的每一条数据参数,此处例:1条
- JSONObject requestparam=new JSONObject(4);
- requestparam.put("param",request);
- String content = requestparam.toString();
- //加签方法第一个参数
- 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);
- //加签
- String sign = STKSignUtil.HMACSHA256(signBuilder.toString(),STK_APP_KEY);
- System.out.println("原始:"+signBuilder);
- System.out.println("签名:"+sign);
- System.out.println("content:"+content);
- //请求数据(接口地址根据测试环境与正式环境变更)
- String body = HttpRequest.post(SAVE_OR_UPDATE_URL+SAVE_OR_UPDATE_REQUEST_CODE)
- .header("appid",STK_APP_ID) //请求头
- .header("timestamp", timestamp)
- .header("sign", sign)
- .header("Content-Type", "application/json")
- .body(content) //请求参数
- .timeout(20000) //超时时间
- .execute().body();
- log.info("修改客商返回信息:{}",body);*/
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- //应用id
- String appid = "bc81efc8_b2c6_4670_818e_e2710a45";
- //应用key
- String appkey = "9a1ae28bc9104deb86f74575acc1c2d6";
- //接口代码
- String apiCode = "18c60d85eb0646a080341b64310109f1";
- //每一条数据在这里构造,根据实际情况修改
- JSONObject request=new JSONObject(4);
- request.put("NAME","紫光展讯通信惠州有限公司");
- request.put("S_CODE","2024-07-04 17:11:43");
- request.put("UID_TYPE","01");
- request.put("UID","91441300MA4WY7CN2T");
- request.put("CUSTOMER_TYPE","C0201");
- request.put("IS_VALID","1");
- request.put("CREATED_ORG","HRORGI0000000001");
- request.put("CREATED_SYSTEM","ZHONGTAI");
- request.put("ISTEMPORARY","0");
- request.put("MDM_CODE",null);
- request.put("CREAT_AT","2024-07-04 17:11:43");
- request.put("UPDATE_AT","2024-07-04 17:11:43");
- request.put("SERIAL","23468156486151");
- //param参数构造 并传入你构造的每一条数据参数,此处例:1条
- JSONObject requestparam=new JSONObject(4);
- requestparam.put("param",request);
- String content = requestparam.toString();
- //加签方法第一个参数
- StringBuilder signBuilder = new StringBuilder("appid").append("=").append(appid).append("&")
- .append(content).append("&")
- .append("timestamp").append("=").append(timestamp).append("&")
- .append("key").append("=").append(appkey);
- //加签
- String sign = STKSignUtil.HMACSHA256(signBuilder.toString(),appkey);
- System.out.println("原始:"+signBuilder);
- System.out.println("签名:"+sign);
- System.out.println("content:"+content);
- //请求数据(接口地址根据测试环境与正式环境变更)
- String body = HttpRequest.post("http://10.67.2.187/api/oapigw/api/oapisvc/automicUpsertApi/"+apiCode)
- .header("appid",appid) //请求头
- .header("timestamp", timestamp)
- .header("sign", sign)
- .header("Content-Type", "application/json")
- .body(content) //请求参数
- .timeout(20000) //超时时间
- .execute().body();
- System.out.println("返回结果:"+body);
- return JSONObject.parseObject(body,SaveOrChangeCustomerDataVo.class);
- }
- /**
- * 根据属性名获取该类此属性的值
- * @param fieldName
- * @param object
- * @return
- */
- private static Object getValueByFieldName(String fieldName,Object object){
- String firstLetter=fieldName.substring(0,1).toUpperCase();
- String getter = "get"+firstLetter+fieldName.substring(1);
- try {
- Method method = object.getClass().getMethod(getter, new Class[]{});
- Object value = method.invoke(object, new Object[] {});
- return value;
- } catch (Exception e) {
- return null;
- }
- }
- @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;
- }
- @Override
- public TravellingMerchantVo queryTravelingMerchantList(QueryTravellingMerchantDto dto) throws Exception {
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- //加签方法的重要参数
- //若该接口需要传入一些参数 如:name、age等等
- //则直接在这个位置put即可
- JSONObject request=new JSONObject(4);
- request.put("code",GET_TRAVELLING_MERCHANT);
- request.put("s_orgcode",S_ORG_CODE);//119030009
- //request.put("start_time","2022-11-02 09:38:23");
- //request.put("end_time","2025-01-06 22:04:47");
- //request.put("jslx","合并口径");
- //request.put("dwmc","担保集团");
- request.put("page",dto.getPage());
- request.put("size",dto.getSize());
- String content = request.toString();
- //加签方法第一个参数
- 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);
- //加签
- String sign = STKSignUtil.HMACSHA256(signBuilder.toString(),STK_APP_KEY);
- System.out.println("原始:"+signBuilder);
- System.out.println("签名:"+sign);
- System.out.println("content:"+content);
- //请求数据 (接口地址根据测试环境与正式环境变更)
- String body = HttpRequest.post(COMPLEXITY_QUERY_URL)
- .header("appid",STK_APP_ID) //请求头
- .header("timestamp", timestamp)
- .header("sign", sign)
- .header("Content-Type", "application/json")
- .body(content) //请求参数
- .timeout(20000) //超时时间
- .execute().body();
- //JSONObject jsonObject = JSON.parseObject(body);
- //JSONObject dataObject = jsonObject.getJSONObject("data");
- //JSONArray listArray = dataObject.getJSONArray("list");
- System.out.println("返回结果:"+body);
- //System.out.println("返回结果:"+listArray.size());
- return JSONObject.parseObject(body,TravellingMerchantVo.class); //返回结果
- }
- /**
- * POST请求头部参数封装
- * */
- public Map<String,String> getHeaderMap(Object dto) throws Exception {
- log.info("STK,加密前参数:{}",JSONObject.toJSONString(dto));
- //时间戳
- String timestamp = Long.toString(System.currentTimeMillis());
- //获取签名
- String sign = getSign(dto,timestamp);
- log.info("STK,加密后的签名:"+sign);
- 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,String timestamp) throws Exception {
- String content = dto.toString();
- //加签方法第一个参数
- 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);
- }
- }
|