feat: 迁移国内标准法规部分5 标准号验证 导入 导出

This commit is contained in:
super_liu
2021-06-04 22:53:52 +08:00
parent 8457c5ce97
commit 7ae47063b4
15 changed files with 1426 additions and 31 deletions
@@ -0,0 +1,59 @@
package com.adc.da.slrs.sarLawsInfo.controller;
import cn.hutool.core.util.ZipUtil;
import com.adc.da.http.PageInfo;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.sarLawsInfo.page.SarLawsInfoEOPage;
import com.adc.da.slrs.sarLawsInfo.service.ISarLawsInfoService;
import com.adc.da.util.LoginUserUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.adc.da.slrs.sarLawsInfo.entity.SarLawsInfo;
import io.swagger.annotations.Api;
import com.adc.da.base.web.BaseController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* <p>
* 前端控制器
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
@RestController
@Api(tags = "福田标准法规--标准法规库--法规信息")
@RequestMapping("/sarLawsInfo/sar-laws-info")
public class SarLawsInfoController extends BaseController<SarLawsInfo> {
private static final Logger logger = LoggerFactory.getLogger(SarLawsInfoController.class);
@Autowired
private ISarLawsInfoService sarLawsInfoEOService;
}
@@ -0,0 +1,16 @@
package com.adc.da.slrs.sarLawsInfo.dao;
import com.adc.da.slrs.sarLawsInfo.entity.SarLawsInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
public interface SarLawsInfoDao extends BaseMapper<SarLawsInfo> {
}
@@ -0,0 +1,110 @@
package com.adc.da.slrs.sarLawsInfo.entity;
import com.adc.da.base.entity.BaseEntity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value="SarLawsInfo对象", description="")
public class SarLawsInfo extends BaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId("ID")
private String id;
@ApiModelProperty(value = "法规分类(INLAND国内,FOREIGN国外)")
@TableField("LAWS_TYPE")
private String lawsType;
@ApiModelProperty(value = "国家地区")
@TableField("COUNTRY")
private String country;
@ApiModelProperty(value = "文件性质")
@TableField("LAWS_PROPERTY")
private String lawsProperty;
@ApiModelProperty(value = "文件号")
@TableField("LAWS_NUMBER")
private String lawsNumber;
@ApiModelProperty(value = "文件名称")
@TableField("LAWS_NAME")
private String lawsName;
@ApiModelProperty(value = "文件状态")
@TableField("LAWS_STATE")
private String lawsState;
@ApiModelProperty(value = "发布日期")
@TableField("ISSUE_TIME")
private String issueTime;
@ApiModelProperty(value = "实施日期")
@TableField("PUT_TIME")
private LocalDateTime putTime;
@ApiModelProperty(value = "代替文件号")
@TableField("REPLACE_LAWS_NUM")
private String replaceLawsNum;
@ApiModelProperty(value = "文件英文名称")
@TableField("LAWS_EN_NAME")
private String lawsEnName;
@ApiModelProperty(value = "被代替文件号")
@TableField("REPLACED_LAWS_NUM")
private String replacedLawsNum;
@TableField("CREATION_USER")
private String creationUser;
@ApiModelProperty(value = "是否有效")
@TableField("VALID_FLAG")
private BigDecimal validFlag;
@ApiModelProperty(value = "创建时间")
@TableField("CREATION_TIME")
private LocalDateTime creationTime;
@ApiModelProperty(value = "修改时间")
@TableField("MODIFY_TIME")
private LocalDateTime modifyTime;
@ApiModelProperty(value = "内容摘要")
@TableField("SYNOPSIS")
private String synopsis;
@ApiModelProperty(value = "引用标准")
@TableField("CITE_STAND")
private String citeStand;
@ApiModelProperty(value = "被引用标准")
@TableField("CITED_STAND")
private String citedStand;
@ApiModelProperty(value = "是否法规清单相关(0否 1是)")
@TableField("IS_RELATE_ACCESS")
private String isRelateAccess;
}
@@ -0,0 +1,113 @@
package com.adc.da.slrs.sarLawsInfo.page;
import com.adc.da.base.page.BasePage;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
@Data
@ApiModel(value="SarLawsInfo分页对象", description="")
public class SarLawsInfoEOPage extends BasePage {
private Date modifyTime;
private Date modifyTime1;
private Date modifyTime2;
private String modifyTimeOperator = "=";
private Date creationTime;
private Date creationTime1;
private Date creationTime2;
private String creationTimeOperator = "=";
private String validFlag;
private String validFlagOperator = "=";
private String creationUser;
private String creationUserOperator = "=";
private String relevanceFile;
private String relevanceFileOperator = "=";
private String opinionFile;
private String opinionFileOperator = "=";
private String lawsFile;
private String lawsFileOperator = "=";
private String linkUri;
private String linkUriOperator = "=";
private String responsibleUnit;
private String responsibleUnitOperator = "=";
private String applyAuth;
private String applyAuthOperator = "like";
private String energyKind;
private String energyKindOperator = "like";
private String applyArctic;
private String applyArcticOperator = "like";
private String replaceLawsNum;
private String replacedLawsNum;
//需求变动,特此修改(byl,原 private String replaceLawsNumOperator = "=";
private String replaceLawsNumOperator = "like";
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date putTime;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date putTime1;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date putTime2;
private String putTimeOperator = "=";
private String issueTime;
private String issueTime1;
private String issueTime2;
private String issueTimeOperator = "=";
private String lawsState;
private String lawsStateOperator = "=";
private String issueUnit;
private String issueUnitOperator = "=";
private String lawsName;
private String lawsNameOperator = "like";
private String lawsNumber;
private String lawsNumberOperator = "like";
private String lawsProperty;
private String lawsPropertyOperator = "=";
private String country;
private String countryOperator = "=";
private String lawsType;
private String lawsTypeOperator = "=";
private String id;
private String idOperator = "=";
private String menuId;
private List<String> menuIdList;
//为了在sql中区分修改操作
private String updateFlag;
//新加字段
private String synopsis;
private String lawsEnName;
private String category;
private String[] replaceLawsNumList;
private String[] applyArcticList;
private String[] energyKindList;
private String[] applyAuthList;
private List<String> menuRoleList;
private String numberName;
private String synchronId;
private String[] idlist;
// 树结构增加搜索条件
private String collectMenuId;
private String labelMenuId;
private String advanceSearchVOStr;
private String advanceSearchStr;
private String isRelateAccess;
private String ids;
private String proType;
private String userId;
private Integer nowOrder;
private Integer nowOrderBy;
private String orderBy1 = "SAR_LAWS_INFO.issue_time";
private String order1 = "desc";
}
@@ -0,0 +1,39 @@
package com.adc.da.slrs.sarLawsInfo.page;
import com.adc.da.base.page.BasePage;
import io.swagger.annotations.ApiModel;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
@Data
@ApiModel(value="", description="")
public class SarLawsItemValEOPage extends BasePage {
private String modifyTime;
private String modifyTime1;
private String modifyTime2;
private String modifyTimeOperator = "=";
private String creationTime;
private String creationTime1;
private String creationTime2;
private String creationTimeOperator = "=";
private String validFlag;
private String validFlagOperator = "=";
private String propertyVal;
private String propertyValOperator = "=";
private String propertyType;
private String propertyTypeOperator = "=";
private String lawsItemId;
private String lawsItemIdOperator = "=";
private String id;
private String idOperator = "=";
}
@@ -0,0 +1,62 @@
package com.adc.da.slrs.sarLawsInfo.page;
import com.adc.da.base.page.BasePage;
import io.swagger.annotations.ApiModel;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
@Data
@ApiModel(value="", description="")
public class SarLawsItemsEOPage extends BasePage {
private String modifyTime;
private String modifyTime1;
private String modifyTime2;
private String modifyTimeOperator = "=";
private String creationTime;
private String creationTime1;
private String creationTime2;
private String creationTimeOperator = "=";
private String creationUser;
private String creationUserOperator = "=";
private String validFlag;
private String validFlagOperator = "=";
private String remarks;
private String remarksOperator = "=";
private String responsibleUnit;
private String responsibleUnitOperator = "like";
private String energyKind;
private String energyKindOperator = "=";
private String applyArctic;
private String applyArcticOperator = "=";
private String tackTime;
private String tackTime1;
private String tackTime2;
private String tackTimeOperator = "=";
private String parts;
private String partsOperator = "=";
private String itemsName;
private String itemsNameOperator = "=";
private String itemsNum;
private String itemsNumOperator = "=";
private String lawsId;
private String lawsIdOperator = "=";
private String id;
private String idOperator = "=";
private String updateFlag;
private String processFlag;
private String nameOrRequest;
private String[] idlist;
private String fileType;
private String proType;
private String productId;
}
@@ -0,0 +1,19 @@
package com.adc.da.slrs.sarLawsInfo.service;
import com.adc.da.person.entity.PersonMsgEO;
import com.adc.da.slrs.sarLawsInfo.entity.SarLawsInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.poi.ss.usermodel.Row;
/**
* <p>
* 服务类
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
public interface ISarLawsInfoService extends IService<SarLawsInfo> {
boolean isRowEmpty(Row row);
}
@@ -0,0 +1,80 @@
package com.adc.da.slrs.sarLawsInfo.service.impl;
import com.adc.da.common.SelectionTypeEnum;
import com.adc.da.person.entity.PersonMsgEO;
import com.adc.da.person.service.IPersonMsgEOService;
import com.adc.da.slrs.sarLawsInfo.entity.SarLawsInfo;
import com.adc.da.slrs.sarLawsInfo.dao.SarLawsInfoDao;
import com.adc.da.slrs.sarLawsInfo.page.SarLawsInfoEOPage;
import com.adc.da.slrs.sarLawsInfo.service.ISarLawsInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Clob;
import java.util.*;
/**
* <p>
* 服务实现类
* </p>
*
* @author super_liu
* @since 2021-06-01
*/
@Service
public class SarLawsInfoServiceImpl extends ServiceImpl<SarLawsInfoDao, SarLawsInfo> implements ISarLawsInfoService {
@Autowired
private SarLawsInfoDao dao;
@Autowired
private IPersonMsgEOService personMsgEOService;
//判断row是否为空 空返回true
public boolean isRowEmpty(Row row) {
if (null == row) {
return true;
}
int firstCellNum = row.getFirstCellNum(); //第一个列位置
int lastCellNum = row.getLastCellNum(); //最后一列位置
int nullCellNum = 0; //空列数量
for (int c = firstCellNum; c < lastCellNum; c++) {
Cell cell = row.getCell(c);
if (null == cell || CellType.BLANK == cell.getCellType()) {
nullCellNum ++;
continue;
}
String value = "";
switch (cell.getCellType()) {
case NUMERIC: // 数字
//如果为时间格式的内容
value = String.valueOf(cell.getNumericCellValue());
break;
case STRING: // 字符串
value = cell.getStringCellValue();
break;
case BOOLEAN: // Boolean
value = cell.getBooleanCellValue() + "";
break;
case FORMULA: // 公式
value = cell.getCellFormula() + "";
break;
default:
break;
}
if (StringUtils.isEmpty(value)) {
nullCellNum ++;
}
}
//所有列都为空
if (nullCellNum == (lastCellNum - firstCellNum)) {
return true;
}
return false;
}
}
@@ -108,4 +108,10 @@ public class SarStandAttrDetails extends BaseEntity {
@TableField("IS_JANSUO")
private String isJansuo;
@TableField(exist = false)
private String attrValue;
@TableField(exist = false)
private String areaName;
}
@@ -9,6 +9,7 @@ import com.adc.da.exception.AdcDaBaseException;
import com.adc.da.http.PageInfo;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.sarLawsInfo.service.ISarLawsInfoService;
import com.adc.da.slrs.sarStandardsInfo.entity.*;
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
import com.adc.da.util.LoginUserUtil;
@@ -66,6 +67,9 @@ public class SarStandardsInfoController extends BaseController<SarStandardsInfo>
@Value("${file.downloadUrl}")
private String fileDownloadPath;
@Autowired
ISarLawsInfoService sarLawsInfoEOService;
@ApiOperation(value = "|SarStandardsInfoEO|自定义分页查询")
@GetMapping("/getSarStandardsInfoPage")
//@RequiresPermissions("lawss:sarStandardsInfo:getSarStandardsInfoPage")
@@ -180,33 +184,227 @@ public class SarStandardsInfoController extends BaseController<SarStandardsInfo>
}
}
// @ApiOperation(value = "|SysCorpEO|导出excel")
// @GetMapping(value = "/exportStandardsInfoExcel")
// public void exportStandardsInfoExcel(StandardsInfoExcelVO standardsInfoExcelVO,HttpServletResponse response,
// HttpServletRequest request) throws Exception {
// OutputStream os = null;
// Workbook workbook = null;
// try {
// if(StringUtils.isEmpty(standardsInfoExcelVO.getExportName())||standardsInfoExcelVO.getExportName().equals("null")){
// standardsInfoExcelVO.setExportName("标准法规信息");
// }
// response.setHeader("Content-Disposition",
// "attachment; filename=" + ReadExcel.encodeFileName(standardsInfoExcelVO.getExportName()+".xlsx",
// request));
// response.setContentType("application/force-download");
// // 导出所有数据
// List<SarStandardsInfo> datas = sarStandardsInfoEOService.getExportDatas(standardsInfoExcelVO);
// workbook = StandExportUtil.exportDatas(datas,standardsInfoExcelVO.getStandType());
// os = response.getOutputStream();
// workbook.write(os);
// os.flush();
// } catch (IOException e) {
// logger.error(e.getMessage(), e);
// throw new AdcDaBaseException("下载文件失败,请重试");
// } finally {
// IOUtils.closeQuietly(os);
// }
// }
@ApiOperation(value = "|SysCorpEO|导出excel")
@GetMapping(value = "/exportStandardsInfoExcel")
public void exportStandardsInfoExcel(StandardsInfoExcelVO standardsInfoExcelVO,HttpServletResponse response,
HttpServletRequest request) throws Exception {
OutputStream os = null;
Workbook workbook = null;
try {
if(StringUtils.isEmpty(standardsInfoExcelVO.getExportName())||standardsInfoExcelVO.getExportName().equals("null")){
standardsInfoExcelVO.setExportName("标准法规信息");
}
response.setHeader("Content-Disposition",
"attachment; filename=" + ReadExcel.encodeFileName(standardsInfoExcelVO.getExportName()+".xlsx",
request));
response.setContentType("application/force-download");
// 导出所有数据
List<SarStandardsInfo> datas = sarStandardsInfoEOService.getExportDatas(standardsInfoExcelVO);
workbook = StandExportUtil.exportDatas(datas,standardsInfoExcelVO.getStandType());
os = response.getOutputStream();
workbook.write(os);
os.flush();
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new AdcDaBaseException("下载文件失败,请重试");
} finally {
IOUtils.closeQuietly(os);
}
}
@ApiOperation(value = "|SarStandardsInfoEO|导入")
@PostMapping(value = "/importZipStandardsInfo")
//401问题2021-03-31暂时注释掉 liuhuiwen
// @RequiresPermissions("lawss:sarStandardsInfo:importZipStandardsInfo")
public ResponseMessage<SarStandardsInfo> importStandardsInfoFile(@RequestParam(value = "file", required = false) MultipartFile file, String standType, String menuId) throws Exception {
//验证文件名是否合格
//截取后缀名
int pos = file.getOriginalFilename().lastIndexOf(".");
String str = file.getOriginalFilename().substring(pos+1).toLowerCase();
String filenameorg = file.getOriginalFilename().substring(0,pos);
//判断上传文件必须是zip
if (!str.equals("zip")) {
return Result.error("fail", "请上传zip文件");
}
String path = filePath + "/modal/"+filenameorg;
File saveDirectory = new File(path);
if(!saveDirectory.isDirectory()){
saveDirectory.mkdir();
}
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path +"/"+ file.getOriginalFilename()));
try{
//解压缩
String zipEntryName = FileUnZip.unZipFiles(path +"/"+ file.getOriginalFilename(),path);
// 数据相关处理,
// 1.获取其中的Excel,
List<File> excelfilelist = FileUnZip.readImpExcelFile(zipEntryName);
System.gc();
if(excelfilelist.size()<1){
int i = 0;
for(File file1:excelfilelist){
if(file1.getName().indexOf("导入模板")>-1){
i++;
}
}
if(i==0){
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "压缩包内没有上传导入模板Excel");
}
} else if (excelfilelist.size()>1) {
int i = 0;
for(File file1:excelfilelist){
if(file1.getName().indexOf("导入模板")>-1){
i++;
}
}
if(i>1){
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "压缩包内有多个导入模板Excel");
}
}
File excelfile = excelfilelist.get(0);
for(File file1:excelfilelist){
if(file1.getName().indexOf("导入模板")>-1){
excelfile = file1;
}
}
// 导入参数设置,默认即可
Workbook workbook = null;
try {
workbook = WorkbookFactory.create(excelfile);
List<Map<String,String>> dataList = new ArrayList<>();
if (workbook != null) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Sheet sheet = workbook.getSheetAt(0);
if (sheet != null) {
StringBuilder headerSb = new StringBuilder();
int rowNos = sheet.getLastRowNum();// 得到excel的总记录条数
for (int i = 0; i <= rowNos; i++) {// 遍历行
Row row = sheet.getRow(i);
Row headerRow = sheet.getRow(0);
boolean isBlank = sarLawsInfoEOService.isRowEmpty(row);
if(row != null && !isBlank){
int columNos = headerRow.getLastCellNum();// 表头总共的列数
Map<String,String> rowList = new LinkedHashMap<>();
for (int j = 0; j < columNos; j++) {
Cell cell = row.getCell(j);
Cell headerCell = headerRow.getCell(j);
if(cell != null){
if (i == 0) {
cell.setCellType(CellType.STRING);
headerSb.append(cell.getStringCellValue() + ",");
} else {
if(CellType.NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)){
Date d = cell.getDateCellValue();
rowList.put(headerCell.getStringCellValue(),df.format(d));
}else{
cell.setCellType(CellType.STRING);
rowList.put(headerCell.getStringCellValue(),cell.getStringCellValue());
}
}
} else {
if (i != 0) {
rowList.put(headerCell.getStringCellValue(),"");
}
}
}
if (i != 0) {
dataList.add(rowList);
}
}
}
// 校验头部是否符合模板
String fields = FieldConvertUtil.exportBaseFieldNames + "," + FieldConvertUtil.exportAttrFieldNamesInland + ",";
if ("FOREIGN".equals(standType)) {
fields = FieldConvertUtil.exportBaseFieldNamesForeign + "," + FieldConvertUtil.exportAttrFieldNamesForeign + ",";
}
String excelHeader = headerSb.toString();
if (!fields.equals(excelHeader)) {
workbook.close();
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
}
}
}
//导入
if(dataList!=null &&!dataList.isEmpty()){
try {
String unzipfilepath = zipEntryName;
ResponseMessage<SarStandardsInfo> message = sarStandardsInfoEOService.importSarStandardsInfoData(dataList, standType,menuId,unzipfilepath);
workbook.close();
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return message;
} catch (Exception e) {
workbook.close();
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", e.getMessage());
}
}else{
if (workbook != null) {
workbook.close();
}
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "没有可导入的数据,请检查!");
}
} catch (NoSuchElementException e){
if (workbook != null) {
workbook.close();
}
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "没有可导入的数据,请检查!");
} catch (Exception e) {
if (workbook != null) {
workbook.close();
}
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
}
} catch (Exception e) {
//删除原上传文件
FileUnZip.deleteDir(saveDirectory);
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
}
}
@ApiOperation(value = "|SarStandardsInfoEO|验证输入的标准号")
@PostMapping("/validateStandNumber")
//@RequiresPermissions("lawss:sarStandardsInfo:selectReplaceStandNum")
public ResponseMessage validateStandNumber(SarStandardsInfoEOPage page) throws Exception {
if (StringUtils.isNotEmpty(page.getStandNumber()) && StringUtils.isNotEmpty(page.getStandSort())) {
String standnumber = "";
if(StringUtils.isNotEmpty(page.getStandYear()) && !"null".equals(page.getStandYear())){
standnumber = page.getStandSort() + " " + page.getStandNumber() + "-" + page.getStandYear();
} else {
standnumber = page.getStandSort() + " " + page.getStandNumber();
}
List<SarStandardsInfo> standlist = sarStandardsInfoEOService.selectStandardsByStandnumber(standnumber, page.getStandType());
if (standlist.size() > 0) {
if (StringUtils.isNotEmpty(page.getId())) {
// 如果是修改,判断id是否一样
for (int i = 0; i < standlist.size(); i++) {
if (standlist.get(i).getId().equals(page.getId())) {
continue;
} else {
return Result.error(standnumber + "标准号已存在");
}
}
return Result.success();
} else {
return Result.error(standnumber + "标准号已存在");
}
} else {
return Result.success();
}
} else {
return Result.success();
}
}
}
@@ -1,6 +1,7 @@
package com.adc.da.slrs.sarStandardsInfo.entity;
import com.adc.da.base.entity.BaseEntity;
import com.adc.da.slrs.sarStandAttrDetails.entity.SarStandAttrDetails;
import com.adc.da.slrs.sarStandItems.entity.SarStandItems;
import com.adc.da.sys.entity.DicTypeEO;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -139,6 +140,8 @@ public class SarStandardsInfo extends BaseEntity {
@TableField(exist = false)
private List<DicTypeEO> dicTypeList = new ArrayList(); // 记录标准涉及到的所有数据字典数据
@TableField(exist = false)
private List<SarStandAttrDetails> attrInfoList = new ArrayList<>();
@TableField(exist = false)
private Map<String, Object> attrInfoMap = new LinkedHashMap<>(); //属性表字段与值
@TableField(exist = false)
private String sarStandAttrEOStr; //新增修改时属性表信息
@@ -28,11 +28,11 @@ public interface ISarStandardsInfoService extends IService<SarStandardsInfo> {
//
int deleteSarStandards(String ids);
//
// List<SarStandardsInfo> getExportDatas (StandardsInfoExcelVO standardsInfoExcelVO) throws Exception;
List<SarStandardsInfo> getExportDatas (StandardsInfoExcelVO standardsInfoExcelVO) throws Exception;
//
// ResponseMessage<SarStandardsInfo> importSarStandardsInfoData(List<Map<String,String>> dataList, String standType, String menuId, String filepath);
ResponseMessage<SarStandardsInfo> importSarStandardsInfoData(List<Map<String,String>> dataList, String standType, String menuId, String filepath);
//
// List<SarStandardsInfo> selectStandardsByStandnumber(String replaceStandNum, String standType);
List<SarStandardsInfo> selectStandardsByStandnumber(String replaceStandNum, String standType);
//
// SarStandardsInfo selectStandardsInfoByKey(String id) throws Exception;
//
@@ -2,11 +2,16 @@ package com.adc.da.slrs.sarStandardsInfo.service.impl;
import com.adc.da.att.entity.AttFileEO;
import com.adc.da.att.service.IAttFileEOService;
import com.adc.da.att.vo.AttFileVo;
import com.adc.da.common.*;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.person.dao.PersonCollectEODao;
import com.adc.da.person.dao.PersonShareEODao;
import com.adc.da.person.entity.PersonMsgEO;
import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.slrs.sarStandAttrDetails.dao.SarStandAttrDetailsDao;
import com.adc.da.slrs.sarStandAttrDetails.entity.SarStandAttrDetails;
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
import com.adc.da.slrs.sarStandFile.dao.SarStandFileDao;
import com.adc.da.slrs.sarStandFile.entity.SarStandFile;
@@ -27,23 +32,30 @@ import com.adc.da.slrs.sysInfo.service.SysInfoEOService;
import com.adc.da.sys.common.SelectionResult;
import com.adc.da.sys.constant.ValueStateEnum;
import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.sys.entity.DicTypeEO;
import com.adc.da.util.LoginUserUtil;
import com.adc.da.util.UUIDUtils;
import com.adc.da.utils.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.sql.Clob;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* <p>
@@ -92,6 +104,9 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
@Autowired
private SarStandAttrInfoDao sarStandAttrInfoEODao;
@Autowired
private SarStandAttrDetailsDao sarStandAttrDetailsEODao;
@Autowired
private SarStandMenuDao sarStandMenuEODao;
@@ -1044,4 +1059,674 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
}
}
/***
* @Description: 查询导出数据
* @Author: yangxuenan
* @Date: 2020/9/15 10:58
* @Param: [exportType, exportContent]
* @Return: java.util.List<com.adc.da.lawss.dto.SarStandExportDto>
*/
public List<SarStandardsInfo> getExportDatas (StandardsInfoExcelVO standardsInfoExcelVO) throws Exception {
SarStandardsInfoEOPage page = new SarStandardsInfoEOPage();
BeanUtils.copyProperties(standardsInfoExcelVO,page);
if ("apart".equals(standardsInfoExcelVO.getExportType())) {
page.setIdlist(standardsInfoExcelVO.getExportContent().split(","));
} else {
JSONObject jsonObject = JSONObject.fromObject(standardsInfoExcelVO.getExportContent());
page = (SarStandardsInfoEOPage)JSONObject.toBean(jsonObject, SarStandardsInfoEOPage.class);
page.setStandType(standardsInfoExcelVO.getStandType());
//查询当前登录人角色拥有权限的菜单
List<String> getMenuIdList = sarMenuEOService.queryRoleMenuIdList(page.getStandType()+"_STAND",null);
if(getMenuIdList != null && !getMenuIdList.isEmpty()){
page.setMenuRoleList(getMenuIdList);
} else {
page.setMenuRoleList(null);
}
List<String> ids = sarMenuEOService.getChildMenuList(page.getMenuId());
if (ids != null && !ids.isEmpty()) {
page.setMenuAllChildrenIdList(ids);
}
if (org.apache.commons.lang.StringUtils.isNotBlank(page.getAdvanceSearchVOStr())) {
List<SarAdvanceSearchVO> searchList = com.alibaba.fastjson.JSONObject.parseArray(page.getAdvanceSearchVOStr(),SarAdvanceSearchVO.class);
String advanceStr = SarAdvanceSearchUtil.createSql(searchList);
if (StringUtils.isNotBlank(advanceStr)) {
page.setAdvanceSearchStr(advanceStr);
} else {
page.setAdvanceSearchStr(null);
}
}
}
page.setOrderBy("SAR_STANDARDS_INFO.issue_time is null,SAR_STANDARDS_INFO.issue_time desc,SAR_STANDARDS_INFO.id");
page.setUserId(LoginUserUtil.getUserId());
List<SarStandardsInfo> getList = dao.getSarStandardsExportInfo(page);
attrInfoShow(getList);
return getList;
}
public ResponseMessage<SarStandardsInfo> importSarStandardsInfoData(List<Map<String,String>> dataList, String standType, String menuId, String filepath){
//此处需要做各种验证,数据库操作
try {
//验证导入数据是否符合规则
Map map = validateImportDatas(dataList, standType, filepath);
boolean isOk = (boolean) map.get("result");
if (!isOk) {
//验证没有通过
String message = (String) map.get("message");
return Result.error("fail", message);
}
//将导入数据循环新增至相应表
List<SarStandardsInfo> list = (List<SarStandardsInfo>) map.get("resultList");
int countSuccess = 0;
for (SarStandardsInfo sarStandardsInfoEO : list) {
sarStandardsInfoEO.setStandType(standType);
sarStandardsInfoEO.setMenuId(menuId);
createSarStandardsInfo(sarStandardsInfoEO);
countSuccess++;
}
String msg = "成功导入" + countSuccess + "";
return Result.success("0", msg, null);
} catch (Exception e) {
logger.error(e.getMessage(),e);
return Result.error("导入失败");
}
}
public Map validateImportDatas(List<Map<String,String>> dataList, String standType, String filepath) throws Exception{
//存放数据验证结果信息
List<String> stringMessage = new ArrayList<>();
int i = 1; //记录行号
List<String> standnumberlist = new ArrayList<>(); // 记录验证过后的编码,用来判断是否有重复
//循环验证数据
List<SarStandardsInfo> standList = new ArrayList<>();
for (Map<String,String> dataMap : dataList) {
i++;
int countError = 0; //记录失败数据数量
String errorMsg = "<p>第" + i + "行:<p>";
List<String> baseFieldsList = Arrays.asList(FieldConvertUtil.exportBaseFieldNames.split(","));
List<String> attrFieldsList = Arrays.asList(FieldConvertUtil.exportAttrFieldNamesInland.split(","));
if ("FOREIGN".equals(standType)) {
baseFieldsList = Arrays.asList(FieldConvertUtil.exportBaseFieldNamesForeign.split(","));
attrFieldsList = Arrays.asList(FieldConvertUtil.exportAttrFieldNamesForeign.split(","));
}
// 遍历map 找出基础表,属性表数据字段和对应值
SarStandardsInfo sarStandardsInfoEO = new SarStandardsInfo();
List<SarStandAttrDetails> attrList = new ArrayList<>();
String zrbmOrgNames = "";
for (Map.Entry<String,String> entry : dataMap.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
if ("责任部门".equals(name)) {
zrbmOrgNames = value;
}
if (baseFieldsList.contains(name)) {
SarStandImportDto.compareFieldAndName(name,value,sarStandardsInfoEO);
} else if (attrFieldsList.contains(name)){
// 根据name查字段
SarStandAttrDetails fieldEO = sarStandAttrDetailsEODao.selectFieldByName(name,standType+"_STAND");
if (fieldEO != null) {
fieldEO.setAttrValue(value);
attrList.add(fieldEO);
}
}
}
sarStandardsInfoEO.setAttrInfoList(attrList);
// 验证基础表数据信息
Map<String,String> beseResultMap = validateBaseDatas(sarStandardsInfoEO,standType,errorMsg,countError,standnumberlist);
errorMsg = beseResultMap.get("errorMsg");
countError = Integer.parseInt(beseResultMap.get("countError"));
Map<String,String> attrResultMap = validateAttrDatas(sarStandardsInfoEO,standType,filepath,errorMsg,countError,zrbmOrgNames);
errorMsg = attrResultMap.get("errorMsg");
countError = Integer.parseInt(attrResultMap.get("countError"));
if (countError > 0) {
stringMessage.add(errorMsg);
}
standList.add(sarStandardsInfoEO);
}
Map map = new HashMap();
if (stringMessage.isEmpty()) {
map.put("result", true);
map.put("resultList", standList);
map.put("message", "");
} else {
map.put("result", false);
String html = "";
for (String message : stringMessage) {
html += message + "</br>";
}
map.put("message", html);
}
return map;
}
public Map validateBaseDatas(SarStandardsInfo dto, String standType,String errorMsg,int countError,List<String> standnumberlist) throws Exception {
Map<String,String> map = new HashMap();
// 验证国家及关联标准类别
DicTypeEO dic = new DicTypeEO();
List<DicTypeEO> getDic = new ArrayList<>();
boolean aorb = false;
//重要度 B 只有 编号 类别 名称 英文名称 标准年份 必填
if (StringUtils.isNotEmpty(dto.getIsRelateAccess())) {
if ("A".equals(dto.getIsRelateAccess())) {
dto.setIsRelateAccess("1");
aorb = true;
} else if ("B".equals(dto.getIsRelateAccess())) {
dto.setIsRelateAccess("0");
} else {
errorMsg += "<p>重要度只能为A/B;<p>";
countError++;
}
} else {
errorMsg += "<p>重要度不能为空;<p>";
countError++;
}
//编号必填
if (StringUtils.isNotEmpty(dto.getStandNumber())) {
String str = getRightDate(dto.getStandNumber());
dto.setStandNumber(str);
if (dto.getStandNumber().length() > 100) {
errorMsg += "<p>标准编号不能超过100个字符;<p>";
countError++;
}
String regEx="^[A-z0-9-.]*$";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
if (!m.matches()) {
errorMsg += "<p>标准编号只能输入字母 数字 . -;<p>";
countError++;
}
} else {
errorMsg += "<p>标准编号不能为空;<p>";
countError++;
}
//类别必填
if (StringUtils.isNotEmpty(dto.getStandSort())) {
dic.setDicTypeName(dto.getStandSort());
dic.setDicTypeCode("STANDCLASSIFY");
getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
if (getDic.size() == 1) {
dto.setStandSort(getDic.get(0).getDicTypeCode());
} else if (getDic.size() > 0) {
errorMsg += "<p>标准类别不明确;<p>";
countError++;
} else {
errorMsg += "<p>标准类别不存在;<p>";
countError++;
}
} else {
errorMsg += "<p>标准类别不能为空;<p>";
countError++;
}
//年份必填
if (StringUtils.isNotEmpty(dto.getStandYear())) {
String regEx="^[0-9a-zA-Z]+$";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(dto.getStandYear());
if (!m.matches() || dto.getStandYear().length() > 20) {
errorMsg += "<p>标准年份只能输入20位以内的数字,字母;<p>";
countError++;
}
} else if (StringUtils.isEmpty(dto.getStandYear()) && "INLAND".equals(standType)) {
errorMsg += "<p>标准年份不能为空;<p>";
countError++;
}
//中文名称
if (StringUtils.isNotEmpty(dto.getStandName())) {
String str = getRightDate(dto.getStandName());
dto.setStandName(str);
if (dto.getStandName().length() > 500) {
errorMsg += "<p>中文名称不能超过500个字符;<p>";
countError++;
}
} else {
errorMsg += "<p>中文名称不能为空;<p>";
countError++;
}
//英文名称
if (StringUtils.isNotEmpty(dto.getStandEnName())) {
String str = getRightDate(dto.getStandEnName());
dto.setStandEnName(str);
if (dto.getStandEnName().length() > 1000) {
errorMsg += "<p>英文名称不能超过1000个字符;<p>";
countError++;
}
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
errorMsg += "<p>英文名称不能输入中文;<p>";
countError++;
}
} else {
errorMsg += "<p>英文名称不能为空;<p>";
countError++;
}
if (StringUtils.isNotEmpty(dto.getCountry())) {
if ("INLAND".equals(standType)) {
if (!"中国".equals(dto.getCountry())) {
errorMsg += "<p>国内标准法规适用区域只能为中国;<p>";
countError++;
}
}
if (dto.getCountry().length() > 100){
errorMsg += "<p>适用区域不能超过100个字符;<p>";
countError++;
} else {
String countryName = dto.getCountry();
dic.setDicTypeName(dto.getCountry());
dic.setDicTypeCode("COUNTRY");
getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
if (getDic.size() == 1) {
dto.setCountry(getDic.get(0).getDicTypeCode());
// 在国家地区不为空的情况下去判断标准类别
} else if (getDic.size() > 0) {
errorMsg += "<p>适用区域不明确;<p>";
countError++;
} else {
errorMsg += "<p>适用区域不存在;<p>";
countError++;
}
}
}
if (StringUtils.isNotEmpty(dto.getStandState())) {
dic.setDicTypeName(dto.getStandState());
dic.setDicTypeCode("STANDSTATE");
if (dto.getStandState().length() > 500) {
errorMsg += "<p>标准状态不能超过500个字符;<p>";
countError++;
} else if (!"计划修订".equals(dto.getStandState())) {
errorMsg += "<p>标准状态只能填写为计划修订;<p>";
countError++;
} else {
getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
if (getDic != null) {
if (getDic.size() == 1) {
dto.setStandState(getDic.get(0).getDicTypeCode());
} else if (getDic.size() > 0) {
errorMsg += "<p>标准状态不明确;<p>";
countError++;
} else {
errorMsg += "<p>标准状态不存在;<p>";
countError++;
}
} else {
errorMsg += "<p>标准状态不存在;<p>";
countError++;
}
}
}
if (StringUtils.isNotBlank(dto.getIssueTime())) {
if (!DateUtil.isValidDate(dto.getIssueTime()) && !"已发布".equals(dto.getIssueTime()) && !"TBD".equals(dto.getIssueTime())) {
errorMsg += "<p>发布日期格式不正确;<p>";
countError++;
}
} else if ("1".equals(dto.getIsRelateAccess()) && StringUtils.isBlank(dto.getIssueTime())) {
if(aorb) {
errorMsg += "<p>发布日期不能为空;<p>";
countError++;
}
}
if (StringUtils.isNotEmpty(dto.getSynopsis())) {
String str = getRightDate(dto.getSynopsis());
dto.setSynopsis(str);
if (dto.getSynopsis().length() > 500) {
errorMsg += "<p>文本说明不能超过500个字符;<p>";
countError++;
}
}
// 标准号唯一性验证
if (StringUtils.isNotEmpty(dto.getStandNumber()) && StringUtils.isNotEmpty(dto.getStandYear()) && StringUtils.isNotEmpty(dto.getStandSort())) {
String standnumber = dto.getStandSort() + " " + dto.getStandNumber() + "-" + dto.getStandYear();
String numberLen = standnumber+"-"+dto.getStandYear();
if(numberLen.length()<=1000){
SarStandardsInfo sarStandardsInfoEO = new SarStandardsInfo();
sarStandardsInfoEO.setStandNumber(standnumber);
sarStandardsInfoEO.setStandType(standType);
List<SarStandardsInfo> standlist = dao.selectStandardsByStandnumber(sarStandardsInfoEO);
if (standlist.size() > 0) {
errorMsg += standnumber + "<p>标准号已存在;<p>";
countError++;
} else if (standnumberlist.contains(standnumber)) {
errorMsg += "<p>导入数据存在标准号" + standnumber + "的重复数据;<p>";
countError++;
} else {
standnumberlist.add(standnumber);
}
}
}
map.put("errorMsg",errorMsg);
map.put("countError",String.valueOf(countError));
return map;
}
public Map validateAttrDatas(SarStandardsInfo dto, String standType,String filepath,String errorMsg,int countError,String zrbmOrgNames) throws Exception {
Map<String,String> map = new HashMap();
//根据重要度判断字段必填
String isMustStr = "no";
List<String> isMustList = new ArrayList<>();
if ("1".equals(dto.getIsRelateAccess())) {
if ("INLAND".equals(standType)) {
isMustStr = "GKDW,CYSD,CLLX,YQLX,XCXSSRQ,ZCCSSRQ,EOPSSRQ,FBJG,ZRBM,FGWHR,DTBJH,YYBJ,CBBH";//,DTBJH,YYBJ
} else if ("FOREIGN".equals(standType)) {
isMustStr = "CLLX,YQLX,XCXSSRQ,ZCCSSRQ,EOPSSRQ,ZRBM,FGWHR,DTBJH,DXBZ,YYBJ,CBBH";
}
}else{
if ("INLAND".equals(standType)) {
isMustStr = "FGWHR";//,DTBJH,YYBJ
}
}
isMustList = Arrays.asList(isMustStr.split(","));
Boolean putTimeState = false;
String putTimeFieldStr = "XCXSSRQ,ZCCSSRQ,EOPSSRQ";
List<String> putTimeFieldList = Arrays.asList(putTimeFieldStr.split(","));
List<SarStandAttrDetails> attrList = dto.getAttrInfoList();
if (attrList != null && !attrList.isEmpty()) {
if (StringUtils.isNotBlank(zrbmOrgNames)) {
zrbmOrgNames = sysInfoEOService.getOrgIdByName(zrbmOrgNames,null);
}
Map<String,Object> attrInfoMap = new HashMap<>();
for (SarStandAttrDetails detailsEO : attrList) {
// 根据不同字段类型进行不同验证
String attrType = detailsEO.getAttrType();
String attrName = detailsEO.getAttrName();
String attrValue = detailsEO.getAttrValue();
String attrField = detailsEO.getAttrField();
String selVal = detailsEO.getSelVal();
Long attrLen = detailsEO.getAttrLen();
// 判断是否为必填项
if (isMustList.contains(attrField) && StringUtils.isEmpty(attrValue)) {
errorMsg += "<p>"+attrName + "不能为空;<p>";
countError++;
}
if (StandAttrTypeEnum.INPUT_STR.getValue().equals(attrType)) {
if (StringUtils.isNotEmpty(attrValue)) {
String str = getRightDate(attrValue);
attrValue = str;
if (attrValue.length() > attrLen) {
errorMsg += "<p>"+attrName + "不能超过"+ attrLen +"个字符;<p>";
countError++;
}
}
if ("DTBJH".equals(attrField) || ",YYBJ".equals(attrField) || "BYYBJ".equals(attrField) || "CBBH".equals(attrField)) {
String regEx = "^[\\s0-9a-zA-Z/.-]*";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(attrValue);
if (!m.matches()) {
String name = "";
switch (attrField){
case "DTBJH":
name = "代替标准编号";
break;
case "CBBH":
name = "对应其他标准";
break;
case "YYBJ":
name = "引用标准";
break;
case "BYYBJ":
name = "被引用标准";
break;
default:
break;
}
errorMsg += "<p>" + name + "只能为(字母、数字、.、-);<p>";
countError++;
}
}
attrInfoMap.put(attrField,attrValue);
} else if (StandAttrTypeEnum.INPUT_NUM.getValue().equals(attrType)) {
if (StringUtils.isNotEmpty(attrValue)) {
String str = getRightDate(attrValue);
attrValue = str;
if (attrValue.length() > attrLen) {
errorMsg += "<p>"+attrName + "不能超过"+ attrLen +"个字符;<p>";
countError++;
}
}
int value = Integer.parseInt(attrValue);
attrInfoMap.put(attrField,value);
} else if (StandAttrTypeEnum.SELECT_OPTION.getValue().equals(attrType) || StandAttrTypeEnum.SEL_OPTS.getValue().equals(attrType)) {
String saveCode = "";
if (StringUtils.isNotEmpty(attrValue)) {
attrValue = attrValue.replace("", ",");
String[] valueArr = attrValue.split(",");
if (StandAttrTypeEnum.SELECT_OPTION.getValue().equals(attrType) && valueArr.length > 1) {
errorMsg += "<p>"+attrName + "单选字段只能输入一个选项;<p>";
countError++;
} else if(valueArr.length>20){
errorMsg += "<p>"+attrName + "选项不能超过20个;<p>";
countError++;
} else if (attrValue.length() > attrLen) {
errorMsg += "<p>"+attrName + "不能超过500个字符;<p>";
countError++;
} else {
Set set = new HashSet();
if ("SVPPS".equals(attrField)) {
for (int e = 0; e < valueArr.length; e++) {
set.add(valueArr[e]);
String svppsId = sysInfoEOService.getSvppsIdByName(valueArr[e]);
if (StringUtils.isNotBlank(svppsId)) {
saveCode += svppsId + ',';
} else {
errorMsg += "<p>"+attrName + valueArr[e] + "不存在;<p>";
countError++;
}
}
}else if (SelectionTypeEnum.GZZXX.getValue().equals(selVal)) {
for (int e = 0; e < valueArr.length; e++) {
set.add(valueArr[e]);
String id = sysInfoEOService.getGroupIdByNames(valueArr[e]);
if (StringUtils.isNotBlank(id)) {
saveCode += id + ',';
} else {
errorMsg += "<p>"+attrName + valueArr[e] + "不存在;<p>";
countError++;
}
}
} else if (SelectionTypeEnum.USERLIST.getValue().equals(selVal)) {
if ("FO".equals(attrField) && StringUtils.isBlank(zrbmOrgNames)) {
set.add(valueArr);
errorMsg += "<p>FO不存在;<p>";
countError++;
} else {
for (int e = 0; e < valueArr.length; e++) {
set.add(valueArr[e]);
if (!"FO".equals(attrField)) {
zrbmOrgNames = "";
}
String userId = sysInfoEOService.getUserIdByName(valueArr[e],zrbmOrgNames);
if (StringUtils.isNotBlank(userId)) {
saveCode += userId + ',';
} else {
errorMsg += "<p>"+attrName + valueArr[e] + "不存在;<p>";
countError++;
}
}
}
} else if (SelectionTypeEnum.ORGLIST.getValue().equals(selVal)) {
for (int e = 0; e < valueArr.length; e++) {
set.add(valueArr[e]);
String id = null;
if (attrName.equals("责任部门") || attrName.equals("相关部门")){
id = sysInfoEOService.getOrgIdByName(valueArr[e],"DEPART");
}else {
id = sysInfoEOService.getOrgIdByName(valueArr[e],null);
}
if (StringUtils.isNotBlank(id)) {
saveCode += id + ',';
} else {
errorMsg +="<p>"+ attrName + valueArr[e] + "不存在;<p>";
countError++;
}
}
} else if (SelectionTypeEnum.ROLELIST.getValue().equals(selVal)) {
for (int e = 0; e < valueArr.length; e++) {
set.add(valueArr[e]);
String id = sysInfoEOService.getRoleIdByName(valueArr[e]);
if (StringUtils.isNotBlank(id)) {
saveCode += id + ',';
} else {
errorMsg +="<p>"+ attrName + valueArr[e] + "不存在;<p>";
countError++;
}
}
} else {
for (int e = 0; e < valueArr.length; e++) {
set.add(valueArr[e]);
DicTypeEO dic = new DicTypeEO();
List<DicTypeEO> getDic = new ArrayList<>();
dic.setDicTypeName(valueArr[e]);
dic.setDicTypeCode(selVal);
getDic = dicTypeEODao.getDicTypeByDicTypeName(dic);
if (getDic != null && getDic.size() > 0) {
saveCode += getDic.get(0).getDicTypeCode() + ',';
} else {
errorMsg += "<p>"+attrName + valueArr[e] + "不存在;<p>";
countError++;
}
}
}
if (valueArr.length > set.size()){
errorMsg +="<p>"+ attrName + "存在重复数据;<p>";
countError++;
}
if (!saveCode.equals("")){
saveCode = saveCode.substring(0,saveCode.length()-1);
}
}
}
attrInfoMap.put(attrField,saveCode);
} else if (StandAttrTypeEnum.DATE_PICKER.getValue().equals(attrType)) {
if (StringUtils.isNotBlank(attrValue)) {
String[] timeArr = attrValue.split(",");
if (timeArr.length > 1) {
errorMsg += "<p>"+attrName + "只能输入一个日期;<p>";
countError++;
} else {
if (!DateUtil.isValidDate(attrValue)) {
errorMsg += "<p>"+attrName + "格式不正确;<p>";
countError++;
} else {
attrInfoMap.put(attrField,attrValue);
}
}
}
} else if (StandAttrTypeEnum.DATE_PIC_OPTS.getValue().equals(attrType)) {
if (StringUtils.isNotBlank(attrValue)) {
String[] timeArr = attrValue.split(",");
if (timeArr.length > 8) {
errorMsg += "<p>"+attrName + "不能超过8个日期;<p>";
countError++;
} else {
if (putTimeFieldList.contains(attrField) && DateUtil.isValidDate(attrValue)) {
putTimeState = true;
}
if (!DateUtil.isValidDate(attrValue) && !"N/A".equals(attrValue) && !"TBD".equals(attrValue) && !"已实施".equals(attrValue)) {
errorMsg += "<p>"+attrName + "格式不正确;<p>";
countError++;
} else {
attrInfoMap.put(attrField,attrValue);
}
}
} else {
if (putTimeFieldList.contains(attrField)) {
putTimeState = true;
}
}
} else if (StandAttrTypeEnum.FILE.getValue().equals(attrType)) {
String saveFiles = "";
if (StringUtils.isNotEmpty(attrValue)) {
attrValue = attrValue.replace("", ",");
String[] filelist = attrValue.split(",");
if (filelist != null && filelist.length > 8) {
errorMsg += "<p>"+attrName + "不能超过8个<p>";
countError++;
} else {
for (int ind = 0; ind < filelist.length; ind++) {
String filename = filelist[ind];
String resultMes = ExcelUtil.validatePattern(filename);
if(StringUtils.isNotEmpty(resultMes)){
errorMsg +="<p>"+ attrName + resultMes +"<p>";
countError++;
continue;
}
List<File> nowfilelist = FileUnZip.readFileByFilename(filepath, filename);
if (nowfilelist.size() <= 0) {
errorMsg += "<p>压缩包中没有" + filename + "文件;<p>";
countError++;
} else {
// 判断文件大小是否超过200M
if (nowfilelist.get(0).length() > 200 * 1024 * 1024) {
errorMsg +="<p>"+ filename + "文件大小超过200M;<p>";
countError++;
continue;
}
AttFileVo fileid = attFileEOService.saveFileInfo(nowfilelist.get(0));
saveFiles += fileid.getAttId() + ",";
}
}
if (saveFiles != "") {
saveFiles = saveFiles.substring(0, saveFiles.length() - 1);
}
}
}
attrInfoMap.put(attrField,saveFiles);
} else if (StandAttrTypeEnum.TEXTAREA.getValue().equals(attrType)) {
if (StringUtils.isNotEmpty(attrValue)) {
String str = getRightDate(attrValue);
attrValue = str;
if (attrValue.length() > attrLen) {
errorMsg += "<p>"+attrName + "不能超过"+ attrLen +"个字符;<p>";
countError++;
}
}
attrInfoMap.put(attrField,attrValue);
}
}
//三个实施日期至少有一个日期格式
// if (!putTimeState) {
// errorMsg += "实施日期必须有一项为日期格式;";
// countError++;
// }
String attrStr = JSON.toJSONString(attrInfoMap, SerializerFeature.WriteMapNullValue);
dto.setSarStandAttrEOStr(attrStr);
}
map.put("errorMsg",errorMsg);
map.put("countError",String.valueOf(countError));
return map;
}
public String getRightDate(String str) {
String strhours = str;
if (strhours.length() > 2) {
String strh = strhours.substring(strhours.length() - 2, strhours.length()); //截取
if (strh.equals(".0")) {
strhours = strhours.substring(0, strhours.length() - 2); //截掉
}
}
return strhours;
}
/**
* 新增过程中验证标准号
*
* @param
* @return
* @author gaoyan
* date 2018-11-13
*/
public List<SarStandardsInfo> selectStandardsByStandnumber(String replaceStandNum, String standType) {
SarStandardsInfo sarStandardsInfoEO = new SarStandardsInfo();
sarStandardsInfoEO.setStandNumber(replaceStandNum);
sarStandardsInfoEO.setStandType(standType);
return dao.selectStandardsByStandnumber(sarStandardsInfoEO);
}
}