|
|
|
|
@ -0,0 +1,275 @@
|
|
|
|
|
package com.nmgs.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.nmgs.config.ResultData;
|
|
|
|
|
import com.nmgs.entity.Consistent;
|
|
|
|
|
import com.nmgs.entity.WhiteCarnoList;
|
|
|
|
|
import com.nmgs.entity.WhiteCarnoLogTable;
|
|
|
|
|
import com.nmgs.mapper.Mapper;
|
|
|
|
|
import com.nmgs.mapper.WhiteCarnoListMapper;
|
|
|
|
|
import com.nmgs.mapper.WhiteCarnoLogMapper;
|
|
|
|
|
import com.nmgs.service.ISelectData;
|
|
|
|
|
import com.nmgs.service.IWhiteBatchImportSerive;
|
|
|
|
|
import com.nmgs.service.IWhiteCarnoListSerive;
|
|
|
|
|
import com.nmgs.service.IWhiteCarnoLogService;
|
|
|
|
|
import com.nmgs.util.LogUtil;
|
|
|
|
|
import com.nmgs.util.PropertiesUtil;
|
|
|
|
|
import com.nmgs.util.PubTools;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Service
|
|
|
|
|
public class WhiteBatchImportSeriveImpl implements IWhiteBatchImportSerive {
|
|
|
|
|
|
|
|
|
|
public Mapper iMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setiMapper(Mapper iMapper) {
|
|
|
|
|
this.iMapper = iMapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WhiteCarnoListMapper whiteCarnoListMapper;
|
|
|
|
|
public WhiteCarnoLogMapper whiteCarnoLogMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setWhiteCarnoListMapper(WhiteCarnoListMapper whiteCarnoListMapper) {
|
|
|
|
|
this.whiteCarnoListMapper = whiteCarnoListMapper;
|
|
|
|
|
}
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setWhiteCarnoLogMapper(WhiteCarnoLogMapper whiteCarnoLogMapper) {
|
|
|
|
|
this.whiteCarnoLogMapper = whiteCarnoLogMapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject insertData(Object params) throws Exception {
|
|
|
|
|
Map<String,Object> map=(Map<String,Object>)params;
|
|
|
|
|
JSONObject json=new JSONObject();
|
|
|
|
|
String txtLog="";
|
|
|
|
|
String logShowExist="";
|
|
|
|
|
String filename=map.get("filename").toString();
|
|
|
|
|
String opermano=map.get("opermano").toString();
|
|
|
|
|
String opermaname=map.get("opermaname").toString();
|
|
|
|
|
String zdyzh=map.get("zdyzh").toString();
|
|
|
|
|
String zdyzhAccount=map.get("zdyzhAccount").toString();
|
|
|
|
|
String mfld=map.get("mfld").toString();
|
|
|
|
|
String mfldAccount=map.get("mfldAccount").toString();
|
|
|
|
|
String zdyzhDis=map.get("zdyzhDis").toString();
|
|
|
|
|
String mfldDis=map.get("mfldDis").toString();
|
|
|
|
|
|
|
|
|
|
List<WhiteCarnoList> users = new ArrayList<WhiteCarnoList>();//新增的数据
|
|
|
|
|
List<WhiteCarnoList> usersUpdate = new ArrayList<WhiteCarnoList>();//修改的数据:根据车牌号和颜色查询是否存在数据,存在则更新
|
|
|
|
|
List<WhiteCarnoLogTable> carnoLogAdd = new ArrayList<WhiteCarnoLogTable>();//操作日志
|
|
|
|
|
int count = 0;
|
|
|
|
|
//当前项目的目录
|
|
|
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
String fileDirName = sdf.format(new Date());
|
|
|
|
|
String folderPath = com.nmgs.util.PathUtil.webappsPath + "\\CarNoFile\\"+fileDirName+"\\"+filename;
|
|
|
|
|
File fileTemp=new File(folderPath);
|
|
|
|
|
if (!fileTemp.exists())
|
|
|
|
|
{
|
|
|
|
|
txtLog="附件不存在";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}else{
|
|
|
|
|
FileInputStream fileInputStream = new FileInputStream(folderPath);
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(fileInputStream);
|
|
|
|
|
List<List<Object>> read = reader.read(3);
|
|
|
|
|
// 方式2:忽略表头的中文,直接读取表的内容
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
txtLog += "\n";
|
|
|
|
|
if(read.size()>0){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + "白名单批量导入文件名称-->" + filename + "\n";
|
|
|
|
|
}
|
|
|
|
|
for ( int k=0;k<read.size()-1;k++) {//由于最后一行内容是填报人信息, 所以不管
|
|
|
|
|
List<Object> row=read.get(k);
|
|
|
|
|
try{
|
|
|
|
|
if(!PubTools.isEmpty(row.get(1)) && !PubTools.isEmpty(row.get(2)) && !PubTools.isEmpty(row.get(3))
|
|
|
|
|
&& !PubTools.isNull(row.get(1).toString()) && !PubTools.isNull(row.get(2).toString()) &&
|
|
|
|
|
!PubTools.isNull(row.get(3).toString())){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
WhiteCarnoList user = new WhiteCarnoList();
|
|
|
|
|
WhiteCarnoLogTable carNoLog = new WhiteCarnoLogTable();
|
|
|
|
|
|
|
|
|
|
//校验车牌
|
|
|
|
|
boolean isregex = PubTools.isregex(row.get(1).toString());
|
|
|
|
|
if(!isregex){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + row.get(1).toString() + ":车牌号码不正确!!" + "\n";
|
|
|
|
|
}else{
|
|
|
|
|
if (row.get(1).toString().trim().toUpperCase().contains("I") || row.get(1).toString().trim().toUpperCase().contains("O"))
|
|
|
|
|
{
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + row.get(1).toString() + ":车牌号码不能包含I/O(i/o)字母!";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int color = getColor(row.get(2).toString());
|
|
|
|
|
if(color <0){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + row.get(1).toString() + ":车牌颜色选择错误!";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
user.setId(UUID.randomUUID().toString().replace("-","").substring(0,32));
|
|
|
|
|
user.setAcarno(row.get(1).toString());//车牌号
|
|
|
|
|
user.setColor(color);//车牌颜色
|
|
|
|
|
user.setDescrib(row.get(3).toString());//车辆描述
|
|
|
|
|
user.setEnddt(sd.parse(row.get(4).toString()));//有效结束日期
|
|
|
|
|
user.setDt(sd.parse(PubTools.getCurrentDate()));
|
|
|
|
|
user.setBegdt(sd.parse(PubTools.getCurrentDate()));
|
|
|
|
|
user.setBegdate(sd.parse(PubTools.getCurrentDate()));
|
|
|
|
|
user.setDataflag("1");//默认启用
|
|
|
|
|
user.setVerno("0");
|
|
|
|
|
|
|
|
|
|
//处理所属单位以及memo信息处理
|
|
|
|
|
if(!PubTools.isNull(zdyzh)){//自定义组合
|
|
|
|
|
user.setMemo(zdyzh);
|
|
|
|
|
user.setDiscrp(zdyzhDis);
|
|
|
|
|
user.setAccount(Integer.parseInt(zdyzhAccount));
|
|
|
|
|
}else{
|
|
|
|
|
if (!PubTools.isNull(mfld)){
|
|
|
|
|
String[] ckgFree=mfld.split(",");
|
|
|
|
|
String memoDb="";
|
|
|
|
|
for (int i = 0; i < ckgFree.length; i++){
|
|
|
|
|
String r = ckgFree[i]+"";
|
|
|
|
|
if (!PubTools.isNull(ckgFree[i]+"")){
|
|
|
|
|
//不足两位补0,
|
|
|
|
|
if (Integer.parseInt(ckgFree[i]+"") < 10){
|
|
|
|
|
memoDb += PubTools.GetHex("0" + ckgFree[i]+"" + "0" + ckgFree[i]+"" + "00" + "0" + ckgFree[i]+"" + "00");
|
|
|
|
|
}else if(Integer.parseInt(ckgFree[i]+"") < 100 && Integer.parseInt(ckgFree[i]+"")>=10){//两位的
|
|
|
|
|
memoDb += PubTools.GetHex(ckgFree[i]+"" + ckgFree[i]+"" + "00" + ckgFree[i]+"" + "00");
|
|
|
|
|
}else{
|
|
|
|
|
memoDb += PubTools.GetHex(ckgFree[i].substring(0,2)+ ckgFree[i].substring(0,2)+ ckgFree[i].substring(0,2)+ ckgFree[i].substring(0,2)+ ckgFree[i].substring(0,2));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
user.setMemo(memoDb);
|
|
|
|
|
user.setDiscrp(mfldDis);
|
|
|
|
|
user.setAccount(Integer.parseInt(mfldAccount));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//根据车牌和颜色判断车牌是否已经存在
|
|
|
|
|
Map<String,Object> mapParas=new HashMap<String,Object>();
|
|
|
|
|
mapParas.put("acarNo",row.get(1).toString()) ;
|
|
|
|
|
mapParas.put("color",color) ;
|
|
|
|
|
List<WhiteCarnoList> whiteCarnoList = whiteCarnoListMapper.getWhiteCarnoList(mapParas);
|
|
|
|
|
if(whiteCarnoList.size()>0){
|
|
|
|
|
WhiteCarnoList whiteCarnoList1 = whiteCarnoList.get(0);
|
|
|
|
|
logShowExist += whiteCarnoList1.getAcarno() + ",";
|
|
|
|
|
user.setId(whiteCarnoList1.getId());
|
|
|
|
|
user.setVehicleType(whiteCarnoList1.getVehicleType());
|
|
|
|
|
user.setVehicleClass(whiteCarnoList1.getVehicleClass());
|
|
|
|
|
user.setBak1(whiteCarnoList1.getBak1());
|
|
|
|
|
user.setBak2(whiteCarnoList1.getBak2());
|
|
|
|
|
user.setBak3(whiteCarnoList1.getBak3());
|
|
|
|
|
usersUpdate.add(user);
|
|
|
|
|
}else{
|
|
|
|
|
user.setVehicleType(0);
|
|
|
|
|
user.setVehicleClass(0);
|
|
|
|
|
user.setBak1("");
|
|
|
|
|
user.setBak2("");
|
|
|
|
|
user.setBak3("");
|
|
|
|
|
users.add(user);
|
|
|
|
|
}
|
|
|
|
|
//memo设置
|
|
|
|
|
BeanUtils.copyProperties(user,carNoLog,"id");
|
|
|
|
|
carNoLog.setId(UUID.randomUUID().toString().replace("-","").substring(0,32));
|
|
|
|
|
carNoLog.setOperdate(sd.parse(PubTools.getCurrentDate()));
|
|
|
|
|
carNoLog.setOpertype(Consistent.IMPORT_BATCH);
|
|
|
|
|
carNoLog.setOpertypename(Consistent.IMPORT_BATCH_NAME);
|
|
|
|
|
carNoLog.setOpermano(opermano);
|
|
|
|
|
carNoLog.setOpermaname(opermaname);
|
|
|
|
|
carNoLog.setIdbusiness(user.getId());
|
|
|
|
|
carnoLogAdd.add(carNoLog);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + row.get(1).toString() + "【白名单文件没有按规定填写,请检查!!】 ";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int ret=-1;
|
|
|
|
|
if (users.size()>0){
|
|
|
|
|
for(WhiteCarnoList whiteCarnoList:users){
|
|
|
|
|
int i = this.whiteCarnoListMapper.insertData(whiteCarnoList);
|
|
|
|
|
if(i<1){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + "导入失败!! ";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (usersUpdate.size()>0){
|
|
|
|
|
for(WhiteCarnoList whiteCarnoList:usersUpdate){
|
|
|
|
|
int i = this.whiteCarnoListMapper.updateById(whiteCarnoList);
|
|
|
|
|
if(i<1){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + "导入失败!! ";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (carnoLogAdd.size()>0){
|
|
|
|
|
for(WhiteCarnoLogTable whiteCarnoList:carnoLogAdd){
|
|
|
|
|
int i = this.whiteCarnoLogMapper.insert(whiteCarnoList);
|
|
|
|
|
if(i<1){
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + "导入失败!! ";
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!PubTools.isNull(logShowExist)){
|
|
|
|
|
txtLog += "已存在车牌:"+logShowExist + "\n";
|
|
|
|
|
}
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + "成功,共计:【" + count + "】条 ";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
txtLog += PubTools.getCurrentDate() + "白名单批量导入异常:" + ex.getMessage() + "\n";
|
|
|
|
|
}
|
|
|
|
|
json.put("txtLog",txtLog);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getColor(String colorName){
|
|
|
|
|
String sql="select t.VALUE AS LABEL from white_PLATE_COLOR t where t.TEXT='"+colorName+"'";
|
|
|
|
|
List selectforlist = this.iMapper.selectforlist(sql);
|
|
|
|
|
int ret=-1;
|
|
|
|
|
if(selectforlist.size()>0){
|
|
|
|
|
Map<String,Object> o =(Map<String,Object>) selectforlist.get(0);
|
|
|
|
|
if(o.get("LABEL") instanceof BigDecimal){
|
|
|
|
|
ret=((BigDecimal) o.get("LABEL")).intValue();
|
|
|
|
|
}else if(o.get("LABEL") instanceof Integer){
|
|
|
|
|
ret=(Integer) o.get("LABEL");
|
|
|
|
|
}else{
|
|
|
|
|
ret=Integer.parseInt(o.get("LABEL").toString()) ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|