Commit 1fe7874d authored by hanbing's avatar hanbing

静态信息接口-方案数据-方案信息

parent f111ce96
package net.wanji.utc.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
RestTemplate restTemplate = new RestTemplate(factory);
restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(30000);
factory.setReadTimeout(30000);
return factory;
}
}
\ No newline at end of file
...@@ -7,6 +7,7 @@ import net.wanji.utc.vo.CrossInfoInVO; ...@@ -7,6 +7,7 @@ import net.wanji.utc.vo.CrossInfoInVO;
import net.wanji.utc.common.genericentity.OutVO; import net.wanji.utc.common.genericentity.OutVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -39,4 +40,12 @@ public class StaticInfoController { ...@@ -39,4 +40,12 @@ public class StaticInfoController {
return ResponseEntity.ok("success"); return ResponseEntity.ok("success");
} }
@PostMapping("/schemePhaseLights")
@ApiOperation(value = "方案数据-方案信息、相位信息、灯组信息", notes = "方案数据-方案信息、相位信息、灯组信息")
public ResponseEntity schemePhaseLights(HttpServletRequest request,
@RequestBody SchemePhaseLightsInVO schemePhaseLightsInVO) throws Exception {
staticInfoService.schemePhaseLights(schemePhaseLightsInVO);
return ResponseEntity.ok("success");
}
} }
package net.wanji.utc.mapper;
import net.wanji.utc.po.CrossSchemePO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Kent HAN
* @date 2022/11/16 17:28
*/
public interface CrossSchemeMapper {
void insertBatch(@Param("entities") List<CrossSchemePO> crossSchemePOList);
}
package net.wanji.utc.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/16 16:09
*/
@Data
public class CrossSchemePO {
/** 方案ID */
@ApiModelProperty(name = "方案ID",notes = "")
private Integer id ;
/** 方案号 */
@ApiModelProperty(name = "方案号",notes = "")
private String no ;
/** 方案名称 */
@ApiModelProperty(name = "方案名称",notes = "")
private String name ;
/** 路口ID */
@ApiModelProperty(name = "路口ID",notes = "")
private String crossId ;
/** 周期 */
@ApiModelProperty(name = "周期",notes = "")
private Integer cycle ;
/** 协调相位ID */
@ApiModelProperty(name = "协调相位ID",notes = "")
private Integer coordPhase ;
/** 相位差 */
@ApiModelProperty(name = "相位差",notes = "")
private Integer offset ;
/** 数据来源:1信号机;2平台 */
@ApiModelProperty(name = "数据来源:1信号机;2平台",notes = "")
private Integer source ;
/** 删除标识:1删除;0未删除 */
@ApiModelProperty(name = "删除标识:1删除;0未删除",notes = "")
private Integer isDeleted ;
/** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
...@@ -8,6 +8,6 @@ import java.util.List; ...@@ -8,6 +8,6 @@ import java.util.List;
* @author Kent HAN * @author Kent HAN
* @date 2022/11/15 13:18 * @date 2022/11/15 13:18
*/ */
public interface HkService { public interface HkStaticInfoService {
List<CrossInfoPO> crossBasicInfo(); List<CrossInfoPO> crossBasicInfo();
} }
package net.wanji.utc.service;
import net.wanji.utc.common.genericentity.ManufacturerRes;
import net.wanji.utc.vo.DetailCrossInfoVO;
/**
* @author Kent HAN
* @date 2022/11/16 11:03
*/
public interface OthersStaticInfoService {
ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(String manufacturerAbbr);
}
package net.wanji.utc.service.SchemePhaseLights;
/**
* @author Kent HAN
* @date 2022/11/16 15:20
*/
public interface HkCrossSchemeService {
void hkCrossSchemeInfo(String crossCode) throws Exception;
}
package net.wanji.utc.service.SchemePhaseLights.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import net.wanji.utc.common.commonentity.HttpRequest;
import net.wanji.utc.common.constant.Constants;
import net.wanji.utc.common.typeenum.BasicEnum;
import net.wanji.utc.mapper.CrossSchemeMapper;
import net.wanji.utc.po.CrossSchemePO;
import net.wanji.utc.service.SchemePhaseLights.HkCrossSchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 方案数据-方案信息
*
* @author Kent HAN
* @date 2022/11/16 15:27
*/
@Service
public class HkCrossSchemeServiceImpl implements HkCrossSchemeService {
@Value("${signal.manufacturer.hk.artemisPath}")
private String artemisPath;
@Autowired
private ArtemisConfig artemisConfig;
@Autowired
CrossSchemeMapper crossSchemeMapper;
@Override
public void hkCrossSchemeInfo(String crossCode) throws Exception {
List<CrossSchemePO> crossSchemePOList = new ArrayList<>();
// 请求3.1.3接口
Map<String, String> path = getPathMapByApiCode("uploadPatternCodeList");
Map<String, String> queryMap = new HashMap<>();
queryMap.put("crossCode", crossCode);
String phasePlanResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, null, queryMap,
null, "application/json", null);
JSONObject object = JSON.parseObject(phasePlanResult);
if(Constants.HK_SUCCESS_CODE.equals(object.getInteger(Constants.HK_CODE_KEY))) {
JSONArray data = object.getJSONArray("data");
for (int i = 0; i < data.size(); i++) {
JSONObject obj = data.getJSONObject(i);
String patternNo = obj.getString("patternNo");
String patternName = obj.getString("patternName");
// 请求3.1.4接口
Map<String, String> path2 = getPathMapByApiCode("getCrossPlanDetail");
Map<String, String> queryMap2 = new HashMap<>();
queryMap2.put("crossCode", crossCode);
queryMap2.put("patternNo", patternNo);
String phaseDetailResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path2, null, queryMap2,
null, "application/json", null);
JSONObject object2 = JSON.parseObject(phaseDetailResult);
if(Constants.HK_SUCCESS_CODE.equals(object2.getInteger(Constants.HK_CODE_KEY))) {
JSONArray data2 = object2.getJSONArray("data");
for (int j = 0; j < data2.size(); j++) {
JSONObject obj2 = data2.getJSONObject(j);
Integer cycle = obj2.getInteger("cycle");
Integer coordPhase = obj2.getInteger("coordPhase");
Integer offset = obj2.getInteger("offset");
// 构造数据库记录
CrossSchemePO crossSchemePO = new CrossSchemePO();
crossSchemePO.setNo(patternNo);
crossSchemePO.setName(patternName);
crossSchemePO.setCrossId(crossCode);
crossSchemePO.setCycle(cycle);
crossSchemePO.setCoordPhase(coordPhase);
crossSchemePO.setOffset(offset);
crossSchemePO.setSource(2);
crossSchemePO.setIsDeleted(0);
crossSchemePOList.add(crossSchemePO);
}
}
}
}
// 写入数据库
crossSchemeMapper.insertBatch(crossSchemePOList);
}
private Map<String, String> getPathMapByApiCode(String apiCode) {
Map<String, String> res = new HashMap<>();
HttpRequest httpRequest = new HttpRequest(BasicEnum.ManufacturerEnum.HK.getAbbr(), apiCode);
res.put("http://", artemisPath + httpRequest.getUrl());
return res;
}
}
...@@ -4,8 +4,11 @@ import net.wanji.utc.common.baseentity.BaseCrossInfo; ...@@ -4,8 +4,11 @@ import net.wanji.utc.common.baseentity.BaseCrossInfo;
import net.wanji.utc.common.genericentity.ManufacturerRes; import net.wanji.utc.common.genericentity.ManufacturerRes;
import net.wanji.utc.common.genericentity.OutVO; import net.wanji.utc.common.genericentity.OutVO;
import net.wanji.utc.vo.DetailCrossInfoVO; import net.wanji.utc.vo.DetailCrossInfoVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
public interface StaticInfoService { public interface StaticInfoService {
ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO); ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO);
void schemePhaseLights(SchemePhaseLightsInVO schemePhaseLightsInVO) throws Exception;
} }
...@@ -13,7 +13,7 @@ import net.wanji.utc.mapper.CrossInfoMapper; ...@@ -13,7 +13,7 @@ import net.wanji.utc.mapper.CrossInfoMapper;
import net.wanji.utc.mapper.ManufacturerInfoMapper; import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.CrossInfoPO; import net.wanji.utc.po.CrossInfoPO;
import net.wanji.utc.po.ManufacturerInfoPO; import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.HkService; import net.wanji.utc.service.HkStaticInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -28,7 +28,7 @@ import java.util.Map; ...@@ -28,7 +28,7 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@Service @Service
public class HkServiceImpl implements HkService { public class HkStaticInfoServiceImpl implements HkStaticInfoService {
@Value("${signal.manufacturer.hk.artemisPath}") @Value("${signal.manufacturer.hk.artemisPath}")
private String artemisPath; private String artemisPath;
@Autowired @Autowired
......
package net.wanji.utc.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import net.wanji.utc.common.commonentity.HttpRequest;
import net.wanji.utc.common.genericentity.ManufacturerRes;
import net.wanji.utc.service.OthersStaticInfoService;
import net.wanji.utc.util.HttpRestUtil;
import net.wanji.utc.util.StringUtils;
import net.wanji.utc.vo.DetailCrossInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
/**
* @author Kent HAN
* @date 2022/11/16 11:03
*/
@Service
public class OthersStaticInfoServiceImpl implements OthersStaticInfoService {
@Autowired
private HttpRestUtil httpRestUtil;
@Override
public ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(String manufacturerAbbr) {
HttpRequest httpRequest = new HttpRequest(manufacturerAbbr, "queryCrossing");
String result = httpRestUtil.doExecute(httpRequest.getUrl(), httpRequest.getHeaders(), HttpMethod.POST, null);
if (StringUtils.isEmpty(result)) {
return null;
}
return JSON.parseObject(result, new TypeReference<ManufacturerRes<DetailCrossInfoVO>>() {});
}
}
...@@ -3,12 +3,18 @@ package net.wanji.utc.service.impl; ...@@ -3,12 +3,18 @@ package net.wanji.utc.service.impl;
import net.wanji.utc.common.genericentity.ManufacturerRes; import net.wanji.utc.common.genericentity.ManufacturerRes;
import net.wanji.utc.common.typeenum.BasicEnum; import net.wanji.utc.common.typeenum.BasicEnum;
import net.wanji.utc.mapper.CrossInfoMapper; import net.wanji.utc.mapper.CrossInfoMapper;
import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.CrossInfoPO; import net.wanji.utc.po.CrossInfoPO;
import net.wanji.utc.service.HkService; import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.HkStaticInfoService;
import net.wanji.utc.service.OthersStaticInfoService;
import net.wanji.utc.service.SchemePhaseLights.HkCrossSchemeService;
import net.wanji.utc.service.StaticInfoService; import net.wanji.utc.service.StaticInfoService;
import net.wanji.utc.common.baseentity.BaseCrossInfo; import net.wanji.utc.common.baseentity.BaseCrossInfo;
import net.wanji.utc.common.genericentity.OutVO; import net.wanji.utc.common.genericentity.OutVO;
import net.wanji.utc.util.ListUtil;
import net.wanji.utc.vo.DetailCrossInfoVO; import net.wanji.utc.vo.DetailCrossInfoVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -23,18 +29,59 @@ import java.util.Objects; ...@@ -23,18 +29,59 @@ import java.util.Objects;
@Service @Service
public class StaticInfoServiceImpl implements StaticInfoService { public class StaticInfoServiceImpl implements StaticInfoService {
@Autowired @Autowired
HkService hkService; HkStaticInfoService hkStaticInfoService;
@Autowired @Autowired
CrossInfoMapper crossInfoMapper; CrossInfoMapper crossInfoMapper;
@Autowired
OthersStaticInfoService othersStaticInfoService;
@Autowired
ManufacturerInfoMapper manufacturerInfoMapper;
@Autowired
HkCrossSchemeService hkCrossSchemeService;
@Override @Override
public ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO) { public ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO) {
List<CrossInfoPO> crossInfoPOList = new ArrayList<>(); List<CrossInfoPO> crossInfoPOList = new ArrayList<>();
ManufacturerRes<DetailCrossInfoVO> res = new ManufacturerRes<>(); ManufacturerRes<DetailCrossInfoVO> res = new ManufacturerRes<>();
if (Objects.equals(BasicEnum.ManufacturerEnum.HK.getAbbr(), outVO.getManufacturerAbbr())) { if (Objects.equals(BasicEnum.ManufacturerEnum.HK.getAbbr(), outVO.getManufacturerAbbr())) {
crossInfoPOList = hkService.crossBasicInfo(); crossInfoPOList = hkStaticInfoService.crossBasicInfo();
} else { } else {
// todo 其他厂商 // 其他厂商
res = othersStaticInfoService.crossBasicInfo(outVO.getManufacturerAbbr());
if (null == res) {
return null;
}
List<DetailCrossInfoVO> dataContent = res.getDatalist();
if (ListUtil.isEmpty(dataContent)) {
return null;
}
for (DetailCrossInfoVO vo : dataContent) {
String id = vo.getTelesemeId();
CrossInfoPO crossInfoPO = crossInfoMapper.selectByPrimaryKey(id);
if (null != crossInfoPO) {
continue;
}
crossInfoPO = new CrossInfoPO();
// 用信号机ID作为路口ID
crossInfoPO.setId(id);
crossInfoPO.setName(vo.getCrossName());
crossInfoPO.setCode(id);
ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectByAbbr(vo.getManufacturerAbbr());
if (manufacturerInfoPO != null) {
crossInfoPO.setManufacturerId(manufacturerInfoPO.getId());
}
crossInfoPO.setIp(vo.getIp());
crossInfoPO.setPort(vo.getPort());
// 经纬度
Double longitude = vo.getLon();
Double latitude = vo.getLat();
crossInfoPO.setLocation(longitude + "," + latitude);
crossInfoPO.setVersion(vo.getVersion());
crossInfoPO.setModel(vo.getModel());
crossInfoPO.setInstallTime(vo.getInstallTime());
crossInfoPOList.add(crossInfoPO);
}
} }
//存储信号机信息 //存储信号机信息
if (crossInfoPOList.size() == 0) { if (crossInfoPOList.size() == 0) {
...@@ -43,4 +90,20 @@ public class StaticInfoServiceImpl implements StaticInfoService { ...@@ -43,4 +90,20 @@ public class StaticInfoServiceImpl implements StaticInfoService {
crossInfoMapper.insertBatch(crossInfoPOList); crossInfoMapper.insertBatch(crossInfoPOList);
return res; return res;
} }
@Override
public void schemePhaseLights(SchemePhaseLightsInVO schemePhaseLightsInVO) throws Exception {
String manufacturerAbbr = schemePhaseLightsInVO.getManufacturerAbbr();
if (Objects.equals(BasicEnum.ManufacturerEnum.HK.getAbbr(), manufacturerAbbr)) {
// 海康
// 方案信息
String crossCode = schemePhaseLightsInVO.getCrossCode();
hkCrossSchemeService.hkCrossSchemeInfo(crossCode);
// 相位信息
// 灯组信息
} else {
// todo 其他厂商
}
}
} }
package net.wanji.utc.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import net.wanji.utc.common.genericentity.ManufacturerRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
import java.util.Iterator;
import java.util.Map;
@Component
public class HttpRestUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpRestUtil.class);
@Autowired
private RestTemplate restTemplate;
/**
* @description: 发送GET请求,支持转换类型,应用多变性返回值,classType返回值类型
* @param url 请求URL
* @param param 请求参数
* @param classType 转换对象
* @return T 返回结果
*/
public <T> T doGet(String url, Map<String, String> headers, String param, Class<T> classType) {
long startTime = System.currentTimeMillis();
LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求头 = {} || 请求参数 = {}",
url, "GET", JSON.toJSONString(headers), JSON.toJSONString(param));
//封装httpEntity
HttpEntity httpEntity = getHttpEntity(headers, param);
//发送请求
ResponseEntity<T> responseEntity;
try {
responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, classType);
} catch (ResourceAccessException e) {
LOGGER.error("HttpRestUtil -> doExecute 捕获IOException异常,{}", e.getMessage());
try {
Thread.sleep(1000);
} catch (Exception ex) {
LOGGER.error("HttpRestUtil -> doExecute 暂停2S异常!", ex);
}
responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, classType);
}
//响应状态值 200 201 202
boolean statusBool = false;
if (HttpStatus.OK.equals(responseEntity.getStatusCode()) || HttpStatus.CREATED.equals(responseEntity.getStatusCode()) || HttpStatus.ACCEPTED.equals(responseEntity.getStatusCode())) {
statusBool = true;
}
if (null != responseEntity && statusBool) {
T result = responseEntity.getBody();
LOGGER.info("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime, JSON.toJSONString(result));
if (StringUtils.isEmpty(result)) {
return null;
}
return result;
} else {
LOGGER.error("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime ,JSON.toJSONString(responseEntity.getBody()));
// throw new RuntimeException("调用接口 = " + url + " || " +
// "失败状态 = " + responseEntity.getStatusCode() + " || " +
// "响应 = " + JSON.toJSONString(responseEntity.getBody()));
throw new HttpClientErrorException(responseEntity.getStatusCode(),
"调用接口 = " + url + " || " +
"失败状态 = " + responseEntity.getStatusCode() + " || " +
"响应 = " + responseEntity.getBody());
}
}
/**
* @description: 发送POST请求,支持转换类型,应用多变性返回值,classType返回值类型
* @param url 请求URL
* @param headers 请求头
* @param param 请求参数
* @param classType 转换类型
* @return T 返回结果
*/
public <T> T doPost(String url, Map<String, String> headers, String param, Class<T> classType) {
long startTime = System.currentTimeMillis();
LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求头 = {} || 请求参数 = {}",
url, "POST", JSON.toJSONString(headers), JSON.toJSONString(param));
//封装httpEntity
HttpEntity httpEntity = getHttpEntity(headers, param);
ResponseEntity<T> responseEntity;
try {
responseEntity = restTemplate.postForEntity(url, httpEntity, classType);
} catch (ResourceAccessException e) {
LOGGER.error("HttpRestUtil -> doPost 捕获IOException异常,{}" + e.getMessage());
try {
Thread.sleep(2000);
} catch (Exception ex) {
LOGGER.error("HttpRestUtil -> doExecute 暂停2S异常!");
}
responseEntity = restTemplate.postForEntity(url, httpEntity, classType);
}
//响应状态值 200 201 202
boolean statusBool = false;
if (HttpStatus.OK.equals(responseEntity.getStatusCode()) || HttpStatus.CREATED.equals(responseEntity.getStatusCode()) || HttpStatus.ACCEPTED.equals(responseEntity.getStatusCode())) {
statusBool = true;
}
if (null != responseEntity && statusBool) {
T result = responseEntity.getBody();
LOGGER.info("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime ,JSON.toJSONString(responseEntity.getBody()));
if (StringUtils.isEmpty(result)) {
return null;
}
return result;
} else {
LOGGER.error("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime ,JSON.toJSONString(responseEntity.getBody()));
throw new HttpClientErrorException(responseEntity.getStatusCode(),
"调用接口 = " + url + " || " +
"失败状态 = " + responseEntity.getStatusCode() + " || " +
"响应 = " + responseEntity.getBody());
}
}
/**
* @description: 发送POST请求,返回固定的返回类型ManufacturerRes
* @param url 请求URL
* @param headers 请求头
* @param param 请求参数
* @return ManufacturerRes<T> 返回结果
*/
public <T> ManufacturerRes<T> doPost(String url, Map<String, String> headers, String param) {
String result = doExecute(url, headers, HttpMethod.POST, param);
if (StringUtils.isEmpty(result)) {
return null;
}
// 转化结果
return JSON.parseObject(result, new TypeReference<ManufacturerRes<T>>() {});
}
/**
* @description: 发送请求,返回string字符串,需要自己转换,应用返回结果简单的请求
* @param url 请求地址
* @param headers 请求头
* @param method 请求类型 POST、GET
* @param param 参数
* @return String 返回结果
*/
public String doExecute(String url, Map<String, String> headers, HttpMethod method, String param) {
long startTime = System.currentTimeMillis();
LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求头 = {} || 请求参数 = {}",
url, method.name(), JSON.toJSONString(headers), JSON.toJSONString(param));
//封装httpEntity
HttpEntity httpEntity = getHttpEntity(headers, param);
//发送请求
ResponseEntity<String> responseEntity;
try {
responseEntity = restTemplate.exchange(url, method, httpEntity, String.class);
} catch (ResourceAccessException e) {
LOGGER.error("HttpRestUtil -> doExecute 捕获IOException异常,{}", e.getMessage());
try {
Thread.sleep(2000);
} catch (Exception ex) {
LOGGER.error("HttpRestUtil -> doExecute 暂停2S异常!", ex);
}
responseEntity = restTemplate.exchange(url, method, httpEntity, String.class);
}
//ResponseEntity<String> responseEntity = get().exchange(url, method, httpEntity, String.class);
//响应状态值 200 201 202
boolean statusBool = false;
if (HttpStatus.OK.equals(responseEntity.getStatusCode()) || HttpStatus.CREATED.equals(responseEntity.getStatusCode()) || HttpStatus.ACCEPTED.equals(responseEntity.getStatusCode())) {
statusBool = true;
}
if (null != responseEntity && statusBool) {
String result = responseEntity.getBody();
LOGGER.info("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime, result);
if (StringUtils.isEmpty(result)) {
return null;
}
return result;
} else {
LOGGER.error("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime ,responseEntity.getBody());
throw new HttpClientErrorException(responseEntity.getStatusCode(),
"调用接口 = " + url + " || " +
"失败状态 = " + responseEntity.getStatusCode() + " || " +
"响应 = " + responseEntity.getBody());
}
}
/**
* @description: 发送get请求,占位符方式请求
* @param url 请求地址
* @param classType 请返回类型
* @param uriVariables 参数
* @return
*/
public <T> T doGet(String url, Class<T> classType, Object... uriVariables) {
long startTime = System.currentTimeMillis();
LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求参数 = {}",
url, "GET", JSON.toJSONString(uriVariables));
//发送请求
ResponseEntity<T> responseEntity;
try {
responseEntity = restTemplate.getForEntity(url, classType, uriVariables);
} catch (ResourceAccessException e) {
LOGGER.error("HttpRestUtil -> doExecute 捕获IOException异常," + e.getMessage());
try {
Thread.sleep(2000);
} catch (Exception ex) {
LOGGER.error("HttpRestUtil -> doExecute 暂停2S异常!"+ ex.getMessage());
}
responseEntity = restTemplate.getForEntity(url, classType, uriVariables);
}
//响应状态值 200 201 202
boolean statusBool = false;
if (HttpStatus.OK.equals(responseEntity.getStatusCode()) || HttpStatus.CREATED.equals(responseEntity.getStatusCode()) || HttpStatus.ACCEPTED.equals(responseEntity.getStatusCode())) {
statusBool = true;
}
if (null != responseEntity && statusBool) {
T result = responseEntity.getBody();
LOGGER.info("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(uriVariables), System.currentTimeMillis() - startTime, result);
if (StringUtils.isEmpty(result)) {
return null;
}
return result;
} else {
LOGGER.error("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(uriVariables), System.currentTimeMillis() - startTime ,responseEntity.getBody());
throw new HttpClientErrorException(responseEntity.getStatusCode(),
"调用接口 = " + url + " || " +
"失败状态 = " + responseEntity.getStatusCode() + " || " +
"响应 = " + responseEntity.getBody());
}
}
/**
* 发送POST请求,表单形式提交请求
* @param url 请求URL
* @param classType 返回对象类型
* @param param 请求参数
* @param <T> 返回结果
* @return
*/
public <T> T doPost(String url, Class<T> classType, Map<String, Object> param) {
long startTime = System.currentTimeMillis();
LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求参数 = {}", url, "POST", JSON.toJSONString(param));
MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
for (String key : param.keySet()) {
postParameters.add(key, param.get(key));
}
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers);
T t = restTemplate.postForObject(url, r, classType);
LOGGER.info("请求地址 = {} || 请求参数 = {} || 响应时长 = {} || 响应结果 = {}",
url, JSON.toJSONString(param), System.currentTimeMillis() - startTime, JSON.toJSONString(t));
return t;
}
private static HttpEntity getHttpEntity(Map<String, String> headers, String param) {
HttpHeaders httpHeaders = new HttpHeaders();
Iterator iterator = headers.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, String> entry = (Map.Entry)iterator.next();
String key = entry.getKey();
if (!httpHeaders.containsKey(key)) {
httpHeaders.add(key, entry.getValue());
}
}
return new HttpEntity(param, httpHeaders);
}
}
package net.wanji.utc.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.CollationKey;
import java.text.Collator;
import java.util.*;
import java.util.function.Supplier;
public class ListUtil {
public final static String SORT_DESC = "desc";
public final static String SORT_ASC = "asc";
/**
* list 相位序号排序
* @param resultList
*/
public static void listSort(List<Map<String, Object>> resultList) {
Collections.sort(resultList, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
String phaseNo1=o1.get("phaseOrderNo").toString();
String phaseNo2=o2.get("phaseOrderNo").toString();
Collator instance = Collator.getInstance();
return instance.compare(phaseNo1, phaseNo2);
}
});
}
/**
* 时段排序
* @param jarray
*/
public static void JSONlistSort(JSONArray jarray) {
List<JSONObject> resultList=new ArrayList<JSONObject>();
for (int i = 0; i < jarray.size(); i++) {
resultList.add((JSONObject) jarray.get(i));
}
Collections.sort(resultList, new Comparator<JSONObject>() {
@Override
public int compare(JSONObject o1, JSONObject o2) {
String startTime1 = o1.getString("from") ;
String startTime2 = o2.getString("from") ;
int St1=Integer.valueOf(startTime1);
int St2=Integer.valueOf(startTime2);
return (St1-St2);
}
});
jarray.clear();
for (int j = 0; j < resultList.size(); j++) {
jarray.add(resultList.get(j));
}
System.out.println(jarray);
}
/**
* 时段排序
* @param resultList
*/
public static void listSortTime(List<Map<String, Object>> resultList) {
Collections.sort(resultList, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
String startTime1=o1.get("from").toString();
String startTime2=o2.get("from").toString();
int St1=Integer.valueOf(startTime1);
int St2=Integer.valueOf(startTime2);
//Collator instance = Collator.getInstance();
return (St1-St2);
}
});
}
/**
* list week排序
* @param resultList
*/
public static void listSortWeek(List<Map<String, Object>> resultList) {
Collections.sort(resultList, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
String phaseNo1=o1.get("weekId").toString();
String phaseNo2=o2.get("weekId").toString();
Collator instance = Collator.getInstance();
return instance.compare(phaseNo1, phaseNo2);
}
});
}
/**
* list week排序
* @param jarray
*/
public static void listSortWeek(JSONArray jarray) {
List<JSONObject> resultList=new ArrayList<JSONObject>();
for (int i = 0; i < jarray.size(); i++) {
resultList.add((JSONObject) jarray.get(i));
}
Collections.sort(resultList, new Comparator<JSONObject>() {
public int compare(JSONObject o1, JSONObject o2) {
if (null==o1.getString("weekDay")) {
o1.put("weekDay", 0);
}
if (null==o2.getString("weekDay")) {
o2.put("weekDay", 0);
}
String startTime1 = o1.getString("weekDay") ;
String startTime2 = o2.getString("weekDay") ;
int St1=Integer.valueOf(startTime1);
int St2=Integer.valueOf(startTime2);
return (St1-St2);
}
});
jarray.clear();
for (int j = 0; j < resultList.size(); j++) {
jarray.add(resultList.get(j));
}
System.out.println(jarray);
}
/**
* <p>Description:[List集合排序类(可按中文排序)]</p>
* @param list 目标集合
* @param property 排序字段名
* @param sortType 正序 (SORT_ASC)、倒序 (SORT_DESC)
* @param isCN 是否按中文排序
* @author: hfx
*/
public static <T> void sortList(List<T> list, final String property, final String sortType, final boolean isCN) {
Collections.sort(list, new Comparator<T>() {
private Collator collator = null;
public int compare(T a, T b) {
int ret = 0;
Field field = ReflectionUtils.findField(a.getClass(), property);
String getterMethodName = "get" + org.apache.commons.lang3.StringUtils.capitalize(property);
Method method = ReflectionUtils.findMethod(a.getClass(), getterMethodName);
Object value_a = ReflectionUtils.invokeMethod(method, a);
Object value_b = ReflectionUtils.invokeMethod(method, b);
if (field.getType() == String.class) {
if (isCN) {
collator = Collator.getInstance();
CollationKey key1 = collator.getCollationKey(value_a.toString());
CollationKey key2 = collator.getCollationKey(value_b.toString());
if (sortType != null && sortType.equals(SORT_DESC)) {
ret = key2.compareTo(key1);
} else {
ret = key1.compareTo(key2);
}
} else {
if (sortType != null && sortType.equals(SORT_DESC)) {
ret = value_b.toString().compareTo(value_a.toString());
} else {
ret = value_a.toString().compareTo(value_b.toString());
}
}
} else if (field.getType() == Integer.class || field.getType() == Long.class || field.getType() == BigDecimal.class) {
BigDecimal decA = new BigDecimal(value_a.toString());
BigDecimal decB = new BigDecimal(value_b.toString());
if (sortType != null && sortType.equals(SORT_DESC)) {
ret = decB.compareTo(decA);
} else {
ret = decA.compareTo(decB);
}
} else if (field.getType() == Date.class) {
if (sortType != null && sortType.equals(SORT_DESC)) {
ret = ((Date) value_b).compareTo((Date) value_a);
} else {
ret = ((Date) value_a).compareTo((Date) value_b);
}
}
return ret;
}
});
}
/**
* <p>Description:[List集合排序类(默认不按照中文排序)]</p>
* @param list 目标集合
* @param property 排序字段名
* @param sortType 正序 (SORT_ASC)、倒序 (SORT_DESC)
* @author: hfx
*/
public static <T> void sortList(List<T> list, final String property, final String sortType) {
sortList(list, property, sortType, false);
}
/**
* <p>Description:[对象数组排序(可按中文排序)]</p>
* @param array 对象数组
* @param property 排序字段名
* @param sortType 正序 (SORT_ASC)、倒序 (SORT_DESC)
* @param isCN 是否按中文排序
* @author: hfx
*/
public static <T> void sortObjectArray(T[] array, final String property, final String sortType, final boolean isCN) {
Arrays.sort(array, new Comparator<T>() {
private Collator collator = null;
public int compare(T a, T b) {
int ret = 0;
Field field = ReflectionUtils.findField(a.getClass(), property);
String getterMethodName = "get" + org.apache.commons.lang3.StringUtils.capitalize(property);
Method method = ReflectionUtils.findMethod(a.getClass(), getterMethodName);
Object value_a = ReflectionUtils.invokeMethod(method, a);
Object value_b = ReflectionUtils.invokeMethod(method, b);
if (field.getType() == String.class) {
if (isCN) {
collator = Collator.getInstance();
CollationKey key1 = collator.getCollationKey(value_a.toString());
CollationKey key2 = collator.getCollationKey(value_b.toString());
if (sortType != null && sortType.equals(SORT_DESC)) {
ret = key2.compareTo(key1);
} else {
ret = key1.compareTo(key2);
}
} else {
if (sortType != null && sortType.equals(SORT_DESC)) {
ret = value_b.toString().compareTo(value_a.toString());
} else {
ret = value_a.toString().compareTo(value_b.toString());
}
}
} else if (field.getType() == Integer.class || field.getType() == Long.class || field.getType() == BigDecimal.class) {
BigDecimal decA = new BigDecimal(value_a.toString());
BigDecimal decB = new BigDecimal(value_b.toString());
if (sortType != null && sortType.equals(SORT_DESC))
ret = decB.compareTo(decA);
else
ret = decA.compareTo(decB);
} else if (field.getType() == Date.class) {
if (sortType != null && sortType.equals(SORT_DESC))
ret = ((Date) value_b).compareTo((Date) value_a);
else
ret = ((Date) value_a).compareTo((Date) value_b);
}
return ret;
}
});
}
/**
* <p>Description:[对象数组排序(默认不按照中文排序)]</p>
* @param array 对象数组
* @param property 排序字段名
* @param sortType 正序 (SORT_ASC)、倒序 (SORT_DESC)
* @author: hfx
*/
public static <T> void sortObjectArray(T[] array, final String property, final String sortType) {
sortObjectArray(array, property, sortType, false);
}
/**
* <p>Description:[字符串数组排序(可按中文排序)]</p>
* @param array 字符串数组
* @param sortType 正序 (SORT_ASC)、倒序 (SORT_DESC)
* @param isCN 是否按中文排序
* @author: hfx
*/
public static <T> void sortArray(T[] array, final String sortType, final boolean isCN) {
if (sortType != null && sortType.equals(SORT_DESC)) {
if (isCN) {
Arrays.sort(array, Collections.reverseOrder(Collator.getInstance(Locale.CHINA)));
} else {
Arrays.sort(array, Collections.reverseOrder());
}
} else {
if (isCN) {
Arrays.sort(array, Collator.getInstance(Locale.CHINA));
} else {
Arrays.sort(array);
}
}
}
/**
* <p>Description:[字符串数组排序(默认不按照中文排序)]</p>
* @param array 字符串数组
* @param sortType 正序 (SORT_ASC)、倒序 (SORT_DESC)
* @author: hfx
*/
public static <T> void sortArray(T[] array, final String sortType) {
sortArray(array, sortType, false);
}
/**
* <p>Description:[获取list的toString(值以逗号分隔,无中括号)]</p>
* @param list
* @return
* @author: hfx
*/
public static <T> String getString(List<T> list) {
Iterator<T> it = list.iterator();
if (!it.hasNext()) {
return "";
}
StringBuilder sb = new StringBuilder();
for (; ; ) {
T e = it.next();
sb.append(e);
if (!it.hasNext()) {
return sb.toString();
}
sb.append(',').append(' ');
}
}
/**
* <p>Description:[获取set的toString(值以逗号分隔,无中括号)]</p>
* @param set
* @return
* @author:武超强
*/
public static <T> String getString(Set<T> set) {
Iterator<T> it = set.iterator();
if (!it.hasNext())
return "";
StringBuilder sb = new StringBuilder();
for (; ; ) {
T e = it.next();
sb.append(e);
if (!it.hasNext())
return sb.toString();
sb.append(',').append(' ');
}
}
/**
* <p>Description:[获取数组的toString(值以逗号分隔,无中括号)]</p>
* @param arr
* @return
* @author: hfx
*/
public static <T> String getString(T[] arr) {
List<T> list = Arrays.asList(arr);
return getString(list);
}
/**
* @Description: [验证集合是否为空:null或size==0 返回false] <br/>
* @param collection 集合
* @return 空或size==0 返回false
* @author: hfx
*/
public static boolean isNotEmpty(Collection collection) {
if (collection == null || collection.size() < 1) {
return false;
} else {
return true;
}
}
/**
* @Description: [验证集合是否为空:null或size==0 返回true] <br/>
* @param collection 集合
* @return 空或size==0 返回true
* @author: hfx
*/
public static boolean isEmpty(Collection collection) {
return !isNotEmpty(collection);
}
public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target) {
return copyListProperties(sources, target, null);
}
public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target, BeanCopyUtilCallBack<S, T> callBack) {
List<T> list = new ArrayList<>(sources.size());
for (S source : sources) {
T t = target.get();
BeanUtils.copyProperties(source, t);
list.add(t);
if (callBack != null) {
callBack.callBack(source, t);
}
}
return list;
}
@FunctionalInterface
public interface BeanCopyUtilCallBack <S, T> {
/**
* 回调
*
* @param s
* @param t
*/
void callBack(S s, T t);
}
}
\ No newline at end of file
package net.wanji.utc.util;
import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
@Slf4j
public class StringUtils extends org.apache.commons.lang3.StringUtils {
/**
* @description: 判断字符串是否为空
* @param value 字符串
* @return java.lang.Boolean 空:false 不是空:true
*/
public static Boolean isNotEmpty(String value) {
if (value == null || value.length() == 0) {
return false;
}
return true;
}
/**
* @description: 判断字符串是否为空
* @param value 字符串
* @return java.lang.Boolean 空:true 不是空:false
*/
public static Boolean isEmpty(String value) {
if (value == null || value.length() == 0) {
return true;
}
return false;
}
/**
* @description: 判断对象是否为空
* @param obj 对象
* @return java.lang.Boolean 空:true 不是空:false
*/
public static Boolean isEmpty(Object obj) {
if (null == obj) {
return true;
}
return false;
}
/**
* @description: 判断字符串是否为空、空字符、null
* @param string 字符串
* @return java.lang.Boolean 空:true 不是空:false
*/
public static Boolean isRedisEmpty(String string) {
if (StringUtils.isEmpty(string) || "null".equals(string) || "".equals(string)) {
return true;
}
return false;
}
/**
* @description: null转化为空字符
* @param str 字符串对象
* @return java.lang.String 空字符
*/
public static String replaceNullToEmpty(String str) {
if (str == null) {
str = "";
}
return str;
}
/**
* @description: 根据字符串获取Integer值,空字符串返回null
* @param str 字符串
* @return java.lang.Integer
*/
public static Integer getIntValue(String str) {
if (org.apache.commons.lang3.StringUtils.isBlank(str)) {
return null;
}
if (!isNumeric(str)) {
return null;
}
return Integer.parseInt(str);
}
/**
* @description: 根据字符串获取Double值,空字符串返回null
* @param str 字符串
* @return java.lang.Double
*/
public static Double getDoubleValue(String str) {
if (org.apache.commons.lang3.StringUtils.isBlank(str)) {
return null;
}
if (!isNumber(str)) {
return null;
}
return Double.parseDouble(str);
}
/**
* @description: 根据字符串获取BigDecimal值,空字符串返回null
* @param str 字符串
* @return BigDecimal
*/
public static BigDecimal getBigDecimalValue(String str) {
if (org.apache.commons.lang3.StringUtils.isBlank(str)) {
return null;
}
if (!isNumber(str)) {
return null;
}
return new BigDecimal(str);
}
/**
* <p>Description:[判断字符串是否为整数]</p>
* @param str 字符串
* @return boolean 是否是整数
*/
public static boolean isNumeric(String str) {
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
/**
* <p>Description:[判断字符串是否为数字类型]</p>
* @param str 字符串
* @return boolean 是否是数字类型
*/
public static boolean isNumber(String str) {
String reg = "^[0-9]+(.[0-9]+)?$";
return str.matches(reg);
}
/**
* <p>Description:[字符串数组转int数组]</p>
* @param strings 字符串数组
* @return int[] int类型数组
*/
public static int[] stringArrayToIntArray(String[] strings) {
try {
if (null == strings || strings.length == 0) {
return null;
}
int[] ints = new int[strings.length];
if (ints.length > 0) {
for (int i = 0; i < strings.length; i++) {
if (isBlank(strings[i])) {
ints[i] = 0;
} else {
ints[i] = Integer.parseInt(strings[i]);
}
}
}
return ints;
} catch (Exception e) {
log.error(e.getMessage());
return null;
}
}
/**
* <p>Description:[字符串数组转Long数组]</p>
* @param strings 字符串数组
* @return int[] int类型数组
*/
public static Long[] stringArrayToLongArray(String[] strings) {
if (null == strings || strings.length == 0) {
return null;
}
Long[] longs = new Long[strings.length];
if (null != longs && longs.length > 0) {
for (int i = 0; i < strings.length; i++) {
longs[i] = Long.parseLong(strings[i]);
}
}
return longs;
}
/**
* <p>Description:[字符类型list转Integer类型List]</p>
* @param stringList 字符串数组
* @return List<Integer> Integer类型List
*/
public static List<Integer> stringListToIntegerList(List<String> stringList) {
if (null == stringList || stringList.size() == 0) {
return null;
}
List<Integer> integerList = new ArrayList<>();
for (String string : stringList) {
integerList.add(getIntValue(string));
}
return integerList;
}
/**
* <p>Description:[字符类型list转Long类型List]</p>
* @param stringList 字符串数组
* @return List<Long> Long类型List
*/
public static List<Long> stringListToLongList(List<String> stringList) {
if (null == stringList || stringList.size() == 0) {
return null;
}
List<Long> longList = new ArrayList<>();
for (String string : stringList) {
if(isEmpty(string)||string.equals("null")){
continue;
}
longList.add(Long.parseLong(string));
}
return longList;
}
/**
* <p>Description:[字符串转小写字符串]</p>
* @param origString 原始字符串
* @return 转换后的字符串
*/
public static String getLowerString(String origString) {
if (StringUtils.isBlank(origString)) {
return origString;
}
return origString.toLowerCase();
}
/**
* <p>Description:[字符串转小写字符串]</p>
* @param origString 原始字符串
* @return 转换后的字符串
*/
public static String getUpperString(String origString) {
if (StringUtils.isBlank(origString)) {
return origString;
}
return origString.toUpperCase();
}
/**
* <p>Description:[判断字符串是否只包含数字和字母]</p>
*/
public static boolean containLetterAndNumber(String string) {
return string.matches("[0-9A-Za-z]*");
}
/**
* <p>Description:[判断字符串是否只包含数字和横杠(电话号校验)]</p>
*/
public static boolean isPhone(String string) {
return string.matches("[0-9-]*");
}
/**
* <p>Description:[过滤表情符号]</p>
*/
public static String filterEmoji(String string) {
if(StringUtils.isEmpty(string)){
return null;
}
//Pattern emoji = Pattern.compile ("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Pattern emoji = Pattern.compile ("(?:[\uD83C\uDF00-\uD83D\uDDFF]|[\uD83E\uDD00-\uD83E\uDDFF]|[\uD83D\uDE00-\uD83D\uDE4F]|[\uD83D\uDE80-\uD83D\uDEFF]|[\u2600-\u26FF]\uFE0F?|[\u2700-\u27BF]\uFE0F?|\u24C2\uFE0F?|[\uD83C\uDDE6-\uD83C\uDDFF]{1,2}|[\uD83C\uDD70\uD83C\uDD71\uD83C\uDD7E\uD83C\uDD7F\uD83C\uDD8E\uD83C\uDD91-\uD83C\uDD9A]\uFE0F?|[\u0023\u002A\u0030-\u0039]\uFE0F?\u20E3|[\u2194-\u2199\u21A9-\u21AA]\uFE0F?|[\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55]\uFE0F?|[\u2934\u2935]\uFE0F?|[\u3030\u303D]\uFE0F?|[\u3297\u3299]\uFE0F?|[\uD83C\uDE01\uD83C\uDE02\uD83C\uDE1A\uD83C\uDE2F\uD83C\uDE32-\uD83C\uDE3A\uD83C\uDE50\uD83C\uDE51]\uFE0F?|[\u203C\u2049]\uFE0F?|[\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE]\uFE0F?|[\u00A9\u00AE]\uFE0F?|[\u2122\u2139]\uFE0F?|\uD83C\uDC04\uFE0F?|\uD83C\uDCCF\uFE0F?|[\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA]\uFE0F?)",Pattern.UNICODE_CASE | Pattern . CASE_INSENSITIVE ) ;
Matcher emojiMatcher = emoji.matcher(string);
if (emojiMatcher.find()) {
string = emojiMatcher.replaceAll("");
}
return string;
}
/**
* <p>Description:[获取URL文件名称KEY]</p>
* @param imgUrl
* @return String
*/
public static String getFileUrlName(String imgUrl) {
if (imgUrl == null) {
return null;
}
String[] strs = imgUrl.split("/");
if(strs == null || strs.length == 0){
return null;
}
String temp = strs[strs.length - 1];
if(StringUtils.isBlank(temp)){
return null;
}
if (temp.lastIndexOf(".") < 0) {
return null;
}
temp = temp.substring(0, temp.lastIndexOf("."));
return temp;
}
/**
* <p>Description:[获取uuid]</p>
*/
public static String getUUID() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
/**
* <p>Description:[获取两个字符串数组交集]</p>
* @param str1 字符串1(逗号分隔)
* @param str2 字符串2(逗号分隔)
*/
public static String getIntersection(String str1, String str2){
String[] ary1 = str1.split(",");
String[] ary2 = str2.split(",");
Set<String> result = new HashSet<>();
for (String s1: ary1) {
for (String s2: ary2) {
if(s1.equalsIgnoreCase(s2)){
result.add(s1.trim());
}
}
}
return result.toString().replace("[","").replace("]","");
}
}
...@@ -5,6 +5,7 @@ import net.wanji.utc.common.commonentity.Direction; ...@@ -5,6 +5,7 @@ import net.wanji.utc.common.commonentity.Direction;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date;
import java.util.List; import java.util.List;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
...@@ -15,6 +16,14 @@ public class DetailCrossInfoVO extends BaseCrossInfo { ...@@ -15,6 +16,14 @@ public class DetailCrossInfoVO extends BaseCrossInfo {
private String crossName; private String crossName;
//路口类型,2行人过街 3 丁字口 4 十字口 5 五岔口 6 六岔口 //路口类型,2行人过街 3 丁字口 4 十字口 5 五岔口 6 六岔口
private String crossType; private String crossType;
private String ip;
private Integer port;
// 版本号
private String version;
// 型号
private String model ;
// 安装时间
private Date installTime;
//经度 //经度
private Double lon; private Double lon;
//纬度 //纬度
......
package net.wanji.utc.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Kent HAN
* @date 2022/11/16 13:23
*/
@Data
@ApiModel(value = "CrossInfoInVO", description = "查询方案数据-方案信息、相位信息、灯组信息输入参数")
public class SchemePhaseLightsInVO {
@ApiModelProperty(value = "厂商缩写 HK-海康")
String manufacturerAbbr;
@ApiModelProperty(value = "信号机唯一标识")
private String crossCode;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.utc.mapper.CrossSchemeMapper">
<resultMap type="net.wanji.utc.po.CrossSchemePO" id="BaseResultMap">
<result property="id" column="id"/>
<result property="no" column="no"/>
<result property="name" column="name"/>
<result property="crossId" column="cross_id"/>
<result property="cycle" column="cycle"/>
<result property="coordPhase" column="coord_phase"/>
<result property="offset" column="offset"/>
<result property="source" column="source"/>
<result property="isDeleted" column="is_deleted"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
<!-- 批量新增数据 -->
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_cross_scheme(no,name,cross_id,cycle,coord_phase,offset,source,is_deleted)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.no},#{entity.name},#{entity.crossId},#{entity.cycle},#{entity.coordPhase},#{entity.offset},#{entity.source},#{entity.isDeleted})
</foreach>
</insert>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment