|
|
package com.nmgs.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.nmgs.entity.GreenTraffic;
|
|
|
import com.nmgs.entity.GreenTrafficCheckPic;
|
|
|
import com.nmgs.entity.GreenTrafficCheckResult;
|
|
|
import com.nmgs.mapper.GreenTrafficCheckPicMapper;
|
|
|
import com.nmgs.mapper.GreenTrafficCheckMapper;
|
|
|
import com.nmgs.mapper.GreenTrafficCheckResultMapper;
|
|
|
import com.nmgs.mapper.GreenTrafficMapper;
|
|
|
import com.nmgs.service.IGreenTrafficService;
|
|
|
import com.nmgs.util.PropertiesUtil;
|
|
|
import org.apache.commons.codec.Charsets;
|
|
|
import org.apache.cxf.endpoint.Client;
|
|
|
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
|
|
|
import org.apache.cxf.transport.http.HTTPConduit;
|
|
|
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class GreenTrafficServiceImpl implements IGreenTrafficService {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private GreenTrafficMapper greenTrafficMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GreenTrafficCheckMapper greenTrafficCheckMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GreenTrafficCheckPicMapper greenTrafficCheckPicMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GreenTrafficCheckResultMapper greenTrafficCheckResultMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private Executor greenTrafficThreadPool;
|
|
|
|
|
|
|
|
|
public static Logger logger = LoggerFactory.getLogger(GreenTrafficServiceImpl.class);
|
|
|
|
|
|
/**
|
|
|
* 获取绿通数据
|
|
|
* @param params
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<GreenTraffic> getGreenTrafficList(Map<String, Object> params) {
|
|
|
|
|
|
|
|
|
//从配置文件中读取数据库连接类型
|
|
|
params.put("DBTYPE", PropertiesUtil.getValue("DBType"));
|
|
|
|
|
|
//设置分页
|
|
|
Integer pageNum = (Integer) params.get("pageNum");
|
|
|
Integer pageSize = (Integer) params.get("pageSize");
|
|
|
Page<GreenTraffic> page = new Page<>(pageNum,pageSize);
|
|
|
|
|
|
|
|
|
|
|
|
page = greenTrafficMapper.getGreenTrafficList(page,params);
|
|
|
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取查验数据
|
|
|
*
|
|
|
* @param params
|
|
|
* @param token
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> getGreenTrafficCheckFromData(Map<String, Object> params, String token) throws Exception {
|
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
//从配置文件中读取数据库连接类型
|
|
|
params.put("DBTYPE", PropertiesUtil.getValue("DBType"));
|
|
|
|
|
|
|
|
|
//如果流水号没有的话,直接返回失败
|
|
|
if(null == params.get("id") || "".equals(params.get("id"))){
|
|
|
resultMap.put("checkFromData","{}");
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
//根据绿通流水号查询数据库中是否存储了 查验信息
|
|
|
/*List<GreenTrafficCheck> checkList = greenTrafficCheckMapper.getCheckListByListNo(params);
|
|
|
logger.info("查询数据库查验信息结果checkList=============="+checkList.size());
|
|
|
List<GreenTrafficCheck> checkList = null;*/
|
|
|
|
|
|
|
|
|
//如果查到数据直接返回
|
|
|
/*if(null != checkList && checkList.size() > 0){
|
|
|
logger.info("========返回数据库结果==========");
|
|
|
|
|
|
//设置数据
|
|
|
String jsonString = JSON.toJSONString(checkList.get(0));
|
|
|
resultMap.put("checkFromData",JSONObject.parseObject(jsonString));
|
|
|
|
|
|
return resultMap;
|
|
|
}*/
|
|
|
//如果没找到数据,则需要调用接口查询数据,并且将数据存储在数据库中
|
|
|
//else{
|
|
|
logger.info("========需要调用接口查询数据==========");
|
|
|
|
|
|
//从配置文件读取绿通数据
|
|
|
String url = PropertiesUtil.getValue("LvTongVehicleInfoURL");
|
|
|
|
|
|
logger.info("获取查验车辆信息的url=============="+url);
|
|
|
|
|
|
//判断url是否为空
|
|
|
if("".equals(url)){
|
|
|
throw new Exception("url配置未找到");
|
|
|
}
|
|
|
|
|
|
//构建JSON参数
|
|
|
/*String urlParam = "{\"vehicleId\": \""+params.get("vehicleId")+"\"," +
|
|
|
"\"startTime\": \""+params.get("startTime")+"\"," +
|
|
|
"\"endTime\": \""+params.get("endTime")+"\"," +
|
|
|
"\"pageNum\":1," +
|
|
|
"\"pageSize\": 50}";*/
|
|
|
String urlParam = "{\"id\": \""+params.get("id")+"\"}";
|
|
|
|
|
|
logger.info("获取查验车辆信息拼接的参数=============="+urlParam);
|
|
|
|
|
|
|
|
|
//获取车辆检查信息
|
|
|
String infoData = postHttpUrl(url,urlParam,token);
|
|
|
|
|
|
logger.info("获取查验车辆信息接口返回=============="+infoData);
|
|
|
|
|
|
if(null != infoData && !"".equals(infoData)){
|
|
|
|
|
|
//解析获取的结果
|
|
|
JSONObject jsonObject = JSONObject.parseObject(infoData);
|
|
|
String msg = (String) jsonObject.get("msg");
|
|
|
int result = (int) jsonObject.get("result");
|
|
|
//result == 0 获取数据成功
|
|
|
if(result == 0){
|
|
|
JSONObject data = (JSONObject) jsonObject.get("data");
|
|
|
|
|
|
logger.info("获取查验车辆信息接口转成JSON=============="+data.toString());
|
|
|
|
|
|
if(!data.isEmpty()){
|
|
|
|
|
|
//根据结果赋值 车辆类型 查验结果 交易时间
|
|
|
data.put("checkResult",getNameByNo((Integer) data.get("checkResult"),"checkResult"));
|
|
|
data.put("vehicleType",greenTrafficMapper.getVehicleTypeNameByType((Integer) data.get("vehicleType")));
|
|
|
data.put("vehicleId",params.get("vehicleId"));
|
|
|
data.put("dt",params.get("dt"));
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.00");
|
|
|
data.put("payFee",decimalFormat.format(data.get("payFee")));
|
|
|
|
|
|
|
|
|
//根据流水号,从流水表里取出需要的数据
|
|
|
Map<String,Object> outPort = greenTrafficMapper.getOutPortByListNo((String) params.get("listNo"));
|
|
|
//获取通行方式、起点站、终点站
|
|
|
data.put("entollStationName",(String) outPort.get("ENTOLLSTATIONNAME"));
|
|
|
data.put("extollStationName",(String) outPort.get("EXTOLLSTATIONNAME"));
|
|
|
|
|
|
BigDecimal cardtp = (BigDecimal) outPort.get("CARDTP");
|
|
|
data.put("transactionType",getNameByNo(cardtp.intValue(),"carTtp"));
|
|
|
|
|
|
/*
|
|
|
//将数据存储在数据库中
|
|
|
GreenTrafficCheck greenTrafficCheck = JSON.parseObject(data.toString(), GreenTrafficCheck.class);
|
|
|
//设置绿通流水号
|
|
|
greenTrafficCheck.setListNo((String) params.get("listNo"));
|
|
|
greenTrafficCheck.setCheckDataJson(data.toString());
|
|
|
logger.info("JSON数据转实体类======greenTrafficCheck========"+greenTrafficCheck.toString());
|
|
|
|
|
|
//新增数据
|
|
|
int addResult = greenTrafficCheckMapper.insert(greenTrafficCheck);
|
|
|
if(addResult < 0){
|
|
|
throw new Exception("新增查验信息失败");
|
|
|
}*/
|
|
|
|
|
|
//返回数据
|
|
|
resultMap.put("checkFromData",data);
|
|
|
}else{
|
|
|
resultMap.put("checkFromData","{}");
|
|
|
}
|
|
|
return resultMap;
|
|
|
|
|
|
}
|
|
|
//-2 是登录失效
|
|
|
else if(result == -1){
|
|
|
resultMap.put("checkFromData","-1");
|
|
|
return resultMap;
|
|
|
}else{
|
|
|
throw new Exception("获取绿通车辆信息数据失败");
|
|
|
}
|
|
|
}else{
|
|
|
throw new Exception("获取绿通车辆信息数据失败");
|
|
|
}
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
|
|
|
private String getNameByNo(Integer no, String type) {
|
|
|
String noName = "";
|
|
|
if("carTtp".equals(type)){
|
|
|
switch (no) {
|
|
|
case 2:
|
|
|
noName = "其他方式";
|
|
|
break;
|
|
|
case 23:
|
|
|
noName = "ETC通行";
|
|
|
break;
|
|
|
// ...
|
|
|
default:
|
|
|
noName = "";
|
|
|
}
|
|
|
}else if("checkResult".equals(type)){
|
|
|
switch (no) {
|
|
|
case 1:
|
|
|
noName = "合格";
|
|
|
break;
|
|
|
default:
|
|
|
noName = "不合格";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return noName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取绿通查验照片
|
|
|
* @param params
|
|
|
* @param token
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> getGreenTrafficCheckFromPicData(Map<String, Object> params, String token) throws Exception {
|
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
//从配置文件中读取数据库连接类型
|
|
|
params.put("DBTYPE", PropertiesUtil.getValue("DBType"));
|
|
|
|
|
|
List<String> picList = new ArrayList<>();
|
|
|
|
|
|
//如果流水号没有的话,直接返回失败
|
|
|
if(null == params.get("listNo") || "".equals(params.get("listNo"))){
|
|
|
throw new Exception("绿通流水号为空");
|
|
|
}
|
|
|
|
|
|
//定义循环次数,先定义5次
|
|
|
int taskCount = 5; // 任务数量
|
|
|
|
|
|
//是否停止线程
|
|
|
boolean isStop = true;
|
|
|
|
|
|
//一直循环取,直到取到空就停止
|
|
|
while(isStop){
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(taskCount); // 同步工具
|
|
|
//循环调用取图片接口
|
|
|
for (int i = 1; i <= taskCount; i++) {
|
|
|
Map<String, Object> paramsWebService = new HashMap<>();
|
|
|
paramsWebService.put("listNO", params.get("listNo")+"_"+i);
|
|
|
paramsWebService.put("imgType", "1");
|
|
|
greenTrafficThreadPool.execute( () -> {
|
|
|
try {
|
|
|
picList.add(getPic(paramsWebService));
|
|
|
} catch (Exception e) {
|
|
|
logger.info("获取图片失败========"+e);
|
|
|
picList.add("");
|
|
|
}
|
|
|
countDownLatch.countDown();
|
|
|
});
|
|
|
}
|
|
|
countDownLatch.await();
|
|
|
logger.info("主线程工作结束=============="+picList.toString());
|
|
|
|
|
|
|
|
|
//遍历数据,是否有空,有空就停止执行
|
|
|
for (String pic : picList) {
|
|
|
if("".equals(pic)){
|
|
|
isStop = false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
logger.info("是否停止取图片=======isStop======="+isStop);
|
|
|
}
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (String picUrl : picList) {
|
|
|
JSONArray jsonArrayPic = new JSONArray();
|
|
|
jsonArrayPic.add("");
|
|
|
jsonArrayPic.add(picUrl);
|
|
|
jsonArray.add(jsonArrayPic);
|
|
|
}
|
|
|
//设置数据
|
|
|
resultMap.put("checkPic",jsonArray);
|
|
|
return resultMap;
|
|
|
|
|
|
|
|
|
|
|
|
//从数据库查询图片信息
|
|
|
/*List<GreenTrafficCheckPic> checkPicList = greenTrafficCheckPicMapper.getCheckPicListBylistNo(params);
|
|
|
logger.info("查询数据库查验图片结果checkList=============="+checkPicList.size());
|
|
|
|
|
|
//如果查到数据直接返回
|
|
|
if(null != checkPicList && checkPicList.size() > 0){
|
|
|
logger.info("========返回数据库结果==========");
|
|
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
//按照接口返回的形式封装数据:[[]]
|
|
|
for (GreenTrafficCheckPic greenTrafficCheckPic : checkPicList) {
|
|
|
JSONArray jsonArrayPic = new JSONArray();
|
|
|
jsonArrayPic.add(greenTrafficCheckPic.getTypeName());
|
|
|
jsonArrayPic.add(greenTrafficCheckPic.getPicData());
|
|
|
jsonArray.add(jsonArrayPic);
|
|
|
}
|
|
|
//设置数据
|
|
|
resultMap.put("checkPic",jsonArray);
|
|
|
return resultMap;
|
|
|
}*/
|
|
|
//如果没找到数据,则需要调用接口查询数据,并且将数据存储在数据库中
|
|
|
//else{
|
|
|
//从配置文件读取绿通图片查询数据
|
|
|
/* String url = PropertiesUtil.getValue("LvTongVehiclePicURL");
|
|
|
|
|
|
logger.info("获取查验车辆图片的url=============="+url);
|
|
|
|
|
|
//判断url是否为空
|
|
|
if("".equals(url)){
|
|
|
throw new Exception("url配置未找到");
|
|
|
}
|
|
|
|
|
|
//构建JSON参数
|
|
|
String urlParam = "{\"vehicleId\": \""+params.get("vehicleId")+"\"," +
|
|
|
"\"startTime\": \""+params.get("startTime")+"\"," +
|
|
|
"\"endTime\": \""+params.get("endTime")+"\"," +
|
|
|
"\"checkId\":\"\"}";
|
|
|
|
|
|
//假数据
|
|
|
*//* String urlParam = "{\"vehicleId\": \"晋MB3537_01\"," +
|
|
|
"\"startTime\": \"2023-10-25 09:44:56\"," +
|
|
|
"\"endTime\": \"2023-10-25 09:44:56\"," +
|
|
|
"\"pageNum\":\"\"}";*//*
|
|
|
|
|
|
logger.info("获取查验车辆图片拼接的参数=============="+urlParam);
|
|
|
|
|
|
|
|
|
//获取车辆图片数据
|
|
|
String picData = postHttpUrl(url,urlParam,token);
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("获取查验车辆图片接口返回=============="+picData);
|
|
|
|
|
|
if(null != picData && !"".equals(picData)){
|
|
|
|
|
|
//解析获取的结果
|
|
|
JSONObject jsonObject = JSONObject.parseObject(picData);
|
|
|
String msg = (String) jsonObject.get("msg");
|
|
|
int result = (int) jsonObject.get("result");
|
|
|
//result == 0 获取数据成功
|
|
|
if(result == 0){
|
|
|
JSONArray jSONArray = (JSONArray) jsonObject.get("data");
|
|
|
|
|
|
logger.info("获取查验车辆图片接口转成JSON=============="+jSONArray.toString());
|
|
|
if(null != jSONArray){
|
|
|
|
|
|
|
|
|
//货物照序号
|
|
|
int itemNum = 1;
|
|
|
//快检设备照序号
|
|
|
int equPicNum = 1;
|
|
|
|
|
|
//其他照片顺序号
|
|
|
int otherNum = 1;
|
|
|
|
|
|
//存数据库
|
|
|
List<GreenTrafficCheckPic> pics = new ArrayList<>();
|
|
|
for (Object array : jSONArray) {
|
|
|
JSONArray arr = (JSONArray) array;
|
|
|
GreenTrafficCheckPic greenTrafficCheckPic = new GreenTrafficCheckPic();
|
|
|
greenTrafficCheckPic.setListNo((String) params.get("listNo"));
|
|
|
logger.info("照片类型=====(String) arr.get(0)========="+(String) arr.get(0));
|
|
|
String type = this.getTypeName((String) arr.get(0));
|
|
|
logger.info("照片类型=====type========="+type);
|
|
|
//如果是货物照,给type后面拼接具体数字确保唯一
|
|
|
if("5".equals(type)){
|
|
|
type = type+'_'+itemNum++;
|
|
|
}
|
|
|
//如果是快检设备照,给type后面拼接具体数字确保唯一
|
|
|
if("6".equals(type)){
|
|
|
type = type+'_'+equPicNum++;
|
|
|
}
|
|
|
|
|
|
//如果是其他照片,给type后面拼接具体数字确保唯一
|
|
|
if("99".equals(type)){
|
|
|
type = type+'_'+otherNum++;
|
|
|
}
|
|
|
greenTrafficCheckPic.setPicType(type);
|
|
|
greenTrafficCheckPic.setPicData((String) arr.get(1));
|
|
|
logger.info("JSON数据转实体类=====greenTrafficCheckPic========="+greenTrafficCheckPic.toString());
|
|
|
pics.add(greenTrafficCheckPic);
|
|
|
}
|
|
|
|
|
|
//批量新增数据
|
|
|
int addResult = greenTrafficCheckPicMapper.saveAll(params,pics);
|
|
|
if(addResult < 0){
|
|
|
throw new Exception("新增图片信息失败");
|
|
|
}
|
|
|
resultMap.put("checkPic",jSONArray);
|
|
|
}else{
|
|
|
resultMap.put("checkPic","{}");
|
|
|
}
|
|
|
return resultMap;
|
|
|
|
|
|
}//-2 是登录失效
|
|
|
else if(result == -2){
|
|
|
resultMap.put("checkPic","-2");
|
|
|
return resultMap;
|
|
|
}//-1 是未找到车辆信息
|
|
|
else if(result == -1){
|
|
|
resultMap.put("checkPic","{}");
|
|
|
return resultMap;
|
|
|
}else{
|
|
|
throw new Exception("获取绿通车辆图片数据失败");
|
|
|
}
|
|
|
}else{
|
|
|
throw new Exception("获取绿通车辆图片数据失败");
|
|
|
}*/
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
private String getPic(Map<String, Object> paramsWebService) throws Exception {
|
|
|
Client client = getClient(PropertiesUtil.getValue("LWZXCommonServiceUrl"));
|
|
|
Object[] objects;
|
|
|
//json的形式
|
|
|
objects = client.invoke("GetImgByListNO2",new JSONObject(paramsWebService).toString());
|
|
|
//如果不为空,解析json
|
|
|
if(null != objects[0] && !"".equals(objects[0])){
|
|
|
JSONObject jsonObject = JSONObject.parseObject((String) objects[0]);
|
|
|
Integer resultCode = (Integer) jsonObject.get("resultCode");
|
|
|
if(resultCode == 1){
|
|
|
String resultData = (String) jsonObject.get("resultData");
|
|
|
if(resultData.equals("[\"2\"]")){
|
|
|
return "";
|
|
|
}else{
|
|
|
return resultData;
|
|
|
}
|
|
|
}else{
|
|
|
return "";
|
|
|
}
|
|
|
}else{
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 更新稽核结论
|
|
|
* @param greenTrafficCheckResult
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
public int saveOrUpdateCheckResult(GreenTrafficCheckResult greenTrafficCheckResult) throws Exception {
|
|
|
|
|
|
int res = 0;
|
|
|
|
|
|
if(null == greenTrafficCheckResult){
|
|
|
throw new Exception("数据为空,更新失败");
|
|
|
}
|
|
|
|
|
|
//先根据绿通流水号查询,是否已经有数据
|
|
|
GreenTrafficCheckResult CheckResult = greenTrafficCheckResultMapper.getCheckResultListByListNo(greenTrafficCheckResult.getListNo());
|
|
|
|
|
|
//如果对象不为空就更新
|
|
|
if(null != CheckResult && (null != CheckResult.getListNo() && !"".equals(CheckResult.getListNo()))){
|
|
|
CheckResult.setCheckResult(greenTrafficCheckResult.getCheckResult());
|
|
|
|
|
|
//设置修改条件:绿通流水号相同
|
|
|
LambdaQueryWrapper<GreenTrafficCheckResult> LambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
LambdaQueryWrapper.eq(null != CheckResult.getListNo() && !"".equals(CheckResult.getListNo()),
|
|
|
GreenTrafficCheckResult::getListNo,
|
|
|
CheckResult.getListNo());
|
|
|
|
|
|
res = greenTrafficCheckResultMapper.update(CheckResult,LambdaQueryWrapper);
|
|
|
}
|
|
|
//如果为空就插入
|
|
|
else{
|
|
|
res = greenTrafficCheckResultMapper.insert(greenTrafficCheckResult);
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void exportGreenTrafficExcle(String params, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
//设置导出文件名称
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
Date date = new Date();
|
|
|
String filename = "绿通查验数据-" + simpleDateFormat.format(date) + ".xlsx";
|
|
|
|
|
|
HashMap<String,Object> paramsMap = new HashMap<>();
|
|
|
|
|
|
//如果传进来的参数有值,拼接参数
|
|
|
|
|
|
if(null != params && !"".equals(params)){
|
|
|
paramsMap = JSON.parseObject(params, HashMap.class);
|
|
|
}
|
|
|
|
|
|
//根据条件查询绿通数据
|
|
|
//从配置文件中读取数据库连接类型
|
|
|
paramsMap.put("DBTYPE", PropertiesUtil.getValue("DBType"));
|
|
|
//设置分页
|
|
|
Integer pageNum = (Integer) paramsMap.get("pageNum");
|
|
|
Integer pageSize = (Integer) paramsMap.get("pageSize");
|
|
|
//设置数据条数,不超过五万条
|
|
|
Page<GreenTraffic> page = new Page<>(pageNum,50000);
|
|
|
page = greenTrafficMapper.getGreenTrafficList(page,paramsMap);
|
|
|
|
|
|
|
|
|
//创建一个Excel表格
|
|
|
Workbook wb = new XSSFWorkbook();
|
|
|
|
|
|
|
|
|
//创建sheet页面
|
|
|
Sheet sheet = wb.createSheet("绿通");
|
|
|
|
|
|
|
|
|
//如果没有数据,返回一个空的Excel
|
|
|
List<GreenTraffic> records = page.getRecords();
|
|
|
if(null == records){
|
|
|
//导出Excel
|
|
|
writeToExcel(response,wb,filename);
|
|
|
}
|
|
|
|
|
|
//定义一个标题数组
|
|
|
String[] title = {"流水号", "车牌号码","车牌颜色", "车种", "路段", "收费站", "统计日期", "车道操作时间", "收费员工号", "收费员姓名", "应收金额", "现金实收金额", "非现金实收金额",};
|
|
|
|
|
|
|
|
|
//设置统计时间日期格式
|
|
|
SimpleDateFormat simpleDateFormatClassData = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
SimpleDateFormat simpleDateFormatDt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
//定义内容数据
|
|
|
List<String[]> rowValues = new ArrayList<>();
|
|
|
for (GreenTraffic greenTraffic : records) {
|
|
|
String[] rowValue = {
|
|
|
null == greenTraffic.getListNo()? "" :greenTraffic.getListNo(),
|
|
|
null == greenTraffic.getAcarNo() ? "" : greenTraffic.getAcarNo(),
|
|
|
null == greenTraffic.getATypeValue() ? "" : greenTraffic.getATypeValue(),
|
|
|
null == greenTraffic.getKindValue() ? "" : greenTraffic.getKindValue(),
|
|
|
null == greenTraffic.getRoadName() ? "" : greenTraffic.getRoadName(),
|
|
|
null == greenTraffic.getStaName() ? "" : greenTraffic.getStaName(),
|
|
|
null == greenTraffic.getClassDate() ? "" : simpleDateFormatClassData.format(greenTraffic.getClassDate()) ,
|
|
|
null == greenTraffic.getDt() ? "" : simpleDateFormatDt.format(greenTraffic.getDt()),
|
|
|
greenTraffic.getManNo()+"",
|
|
|
null == greenTraffic.getMan() ? "" : greenTraffic.getMan(),
|
|
|
greenTraffic.getCash().intValue()+"",
|
|
|
greenTraffic.getInCash().intValue()+"",
|
|
|
greenTraffic.getPayCash().intValue()+"",
|
|
|
};
|
|
|
rowValues.add(rowValue);
|
|
|
}
|
|
|
|
|
|
//设置标题单元格式
|
|
|
CellStyle cellStyleTitle = wb.createCellStyle();
|
|
|
cellStyleTitle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//设置背景色
|
|
|
cellStyleTitle.setFillPattern((short) 1);//必须设置 否则无效
|
|
|
//设置水平垂直居中
|
|
|
cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
cellStyleTitle.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
// 设置边框样式
|
|
|
cellStyleTitle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
|
|
|
cellStyleTitle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
|
|
|
cellStyleTitle.setBorderRight(XSSFCellStyle.BORDER_THIN);
|
|
|
cellStyleTitle.setBorderTop(XSSFCellStyle.BORDER_THIN);
|
|
|
//定义标题内容
|
|
|
Row currentRow = sheet.createRow(0);
|
|
|
// 往Excel表格中添加标题的数据
|
|
|
for (int j = 0; j < title.length; j++) {
|
|
|
// 设置列宽
|
|
|
sheet.setColumnWidth(j, 4100);
|
|
|
Cell cell = currentRow.createCell(j);
|
|
|
cell.setCellStyle(cellStyleTitle);
|
|
|
//每个单元格的值目前做 String 处理
|
|
|
//cell.setCellType(CellType.STRING);
|
|
|
cell.setCellValue(title[j]);
|
|
|
}
|
|
|
|
|
|
|
|
|
//设置内容单元格式
|
|
|
CellStyle cellStyleValue = wb.createCellStyle();
|
|
|
//设置水平垂直居中
|
|
|
cellStyleValue.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
cellStyleValue.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
// 设置边框样式
|
|
|
cellStyleValue.setBorderBottom(XSSFCellStyle.BORDER_THIN);
|
|
|
cellStyleValue.setBorderLeft(XSSFCellStyle.BORDER_THIN);
|
|
|
cellStyleValue.setBorderRight(XSSFCellStyle.BORDER_THIN);
|
|
|
cellStyleValue.setBorderTop(XSSFCellStyle.BORDER_THIN);
|
|
|
//往Excel表格中添加具体数据
|
|
|
for (int i = 1; i < rowValues.size(); i++) {
|
|
|
Row Row = sheet.createRow(i);
|
|
|
for (int j = 0; j < title.length; j++) {
|
|
|
// 设置列宽
|
|
|
sheet.setColumnWidth(j, 4100);
|
|
|
Cell cell = Row.createCell(j);
|
|
|
cell.setCellStyle(cellStyleValue);
|
|
|
//每个单元格的值目前做 String 处理
|
|
|
//cell.setCellType(CellType.STRING);
|
|
|
cell.setCellValue(rowValues.get(i)[j]);
|
|
|
}
|
|
|
}
|
|
|
//导出Excel
|
|
|
writeToExcel(response,wb,filename);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取照片类型
|
|
|
* @param typeName
|
|
|
* @return type
|
|
|
*/
|
|
|
private String getTypeName(String typeName) {
|
|
|
String type = "";
|
|
|
Map<String, Object> picType = greenTrafficCheckPicMapper.getPicType(typeName);
|
|
|
logger.info("picType=============="+picType.size());
|
|
|
logger.info("picType=============="+picType.toString());
|
|
|
if(null != picType && picType.size() >= 2){
|
|
|
type = picType.get("VALUE")+"";
|
|
|
}else{
|
|
|
type = "99";
|
|
|
}
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 远程调用绿通url,获取数据
|
|
|
* @param URL
|
|
|
* @return
|
|
|
*/
|
|
|
private String postHttpUrl(String URL,String params,String token) throws Exception{
|
|
|
// 1. 获取访问地址URL
|
|
|
URL url = new URL(URL);
|
|
|
// 2. 创建HttpURLConnection对象
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
/* 3. 设置请求参数等 */
|
|
|
// 请求方式
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
|
|
// 设置连接超时时间
|
|
|
connection.setConnectTimeout(3000);
|
|
|
//设置是否向 HttpUrlConnection 输出,对于post请求,参数要放在 http 正文内,因此需要设为true,默认为false。
|
|
|
connection.setDoOutput(true);
|
|
|
// 设置是否从 HttpUrlConnection读入,默认为true
|
|
|
connection.setDoInput(true);
|
|
|
// 设置是否使用缓存
|
|
|
connection.setUseCaches(false);
|
|
|
// 设置此 HttpURLConnection 实例是否应该自动执行 HTTP 重定向
|
|
|
connection.setInstanceFollowRedirects(true);
|
|
|
// 设置使用标准编码格式编码参数的名-值对
|
|
|
connection.setRequestProperty("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
//connection.setRequestProperty("token","test");
|
|
|
|
|
|
//添加 HTTP HEAD 中的一些参数。
|
|
|
//JDK8中,HttpURLConnection默认开启Keep-Alive
|
|
|
//connection.setRequestProperty("Connection", "Keep-Alive");
|
|
|
|
|
|
//连接
|
|
|
connection.connect();
|
|
|
/* 4. 处理输入输出 */
|
|
|
// 写入参数到请求中
|
|
|
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);//解决传参时中文乱码
|
|
|
out.write(params);
|
|
|
out.flush();
|
|
|
out.close();
|
|
|
// 从连接中读取响应信息
|
|
|
String result = "";
|
|
|
int code = connection.getResponseCode();
|
|
|
if (code == 200) {
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));//解决解析中文乱码
|
|
|
String line;
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
result += line + "\n";
|
|
|
}
|
|
|
reader.close();
|
|
|
}
|
|
|
// 5. 断开连接
|
|
|
connection.disconnect();
|
|
|
|
|
|
// 处理结果
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 把Excel写到response里,返回前端
|
|
|
* @param response
|
|
|
* @param wb
|
|
|
* @param fileName
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public void writeToExcel(HttpServletResponse response, Workbook wb, String fileName) throws Exception {
|
|
|
OutputStream os = null;
|
|
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
response.setCharacterEncoding(Charsets.UTF_8.name());
|
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s", new String(URLEncoder.encode(fileName, Charsets.UTF_8.name())
|
|
|
.getBytes(Charsets.UTF_8), Charsets.ISO_8859_1)));
|
|
|
os = response.getOutputStream();
|
|
|
wb.write(os);
|
|
|
os.flush();
|
|
|
}
|
|
|
|
|
|
|
|
|
/*@Test
|
|
|
public void test() throws Exception{
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("listNO", "GetImgByListNO2");
|
|
|
params.put("imgType", "1");
|
|
|
Client client = getClient(PropertiesUtil.getValue("LWZXCommonServiceUrl2"));
|
|
|
Object[] objects;
|
|
|
//json的形式
|
|
|
objects = client.invoke("GetWebServiceData", "10",new JSONObject(params).toString());
|
|
|
if (objects.length > 0) {
|
|
|
System.out.println(objects.toString());
|
|
|
}
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
public static Client getClient(String path) {
|
|
|
// 创建动态客户端
|
|
|
int CXF_CLIENT_CONNECT_TIMEOUT = 4 * 60000;
|
|
|
int CXF_CLIENT_RECEIVE_TIMEOUT = 4 * 60000;
|
|
|
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
|
|
|
Client client = dcf.createClient(path);
|
|
|
HTTPConduit conduit = (HTTPConduit) client.getConduit();
|
|
|
HTTPClientPolicy policy = new HTTPClientPolicy();
|
|
|
policy.setConnectionTimeout(CXF_CLIENT_CONNECT_TIMEOUT);
|
|
|
policy.setReceiveTimeout(CXF_CLIENT_RECEIVE_TIMEOUT);
|
|
|
conduit.setClient(policy);
|
|
|
return client;
|
|
|
}
|
|
|
}
|