Commit 8041561c authored by 王琮's avatar 王琮

修改邀访导入

parent 61a9c5fb
......@@ -27,7 +27,7 @@ public class OssINfoUtil {
SEPARATOR = File.separator;
}
@Value("${global.path.base_upload_location}")
@Value("${global.base_upload_location}")
private String baseUploadLocation;
public OssInfo filePath(MultipartFile multipartFile, String temp) {
......
......@@ -210,8 +210,6 @@ public class CyEpExcelUtil {
* strings 下拉内容
*/
public static void selectList(Workbook workbook, int firstRow, int lastRow, int firstCol, int lastCol, String[] strings) {
Sheet sheet = workbook.getSheetAt(0);
// 生成下拉列表
// 只对(x,x)单元格有效
......
......@@ -233,11 +233,20 @@ public class VisitInfomationController extends CyPaginationController<VisitInfoM
@PostMapping("/importExcel")
@CyEptSm4EnableAnno
public CyResult importSysUser(MultipartFile file,HttpServletResponse response) throws ParseException {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
visitInfomationServiceImpl.importUserExcel(file,response));
}
@CyOpeLogAnno(title = "内勤系统-用户管理-导出用户", businessType = CyLogTypeEnum.EXPORT)
@ApiOperation(value = "下载错误信息", notes = "下载错误信息")
@PostMapping("/downFalseFile")
@CyEptSm4EnableAnno
public CyResult downFile(String fileName, HttpServletResponse response) throws Exception {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
visitInfomationServiceImpl.download(fileName, response));
}
}
......@@ -4,7 +4,6 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class ExportVisitInfoDto {
......
......@@ -103,4 +103,6 @@ public interface VisitInfomationService {
* @return
*/
List<VisitInfoMation> findByUser(VisitUser visitUser);
int download(String fileName, HttpServletResponse response) throws Exception;
}
......@@ -2,10 +2,12 @@ package org.rcisoft.sys.visit.service.impl;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.excel.util.FileUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.common.component.CyGlobal;
import org.rcisoft.core.component.CyDownErrorTxtComp;
import org.rcisoft.core.exception.CyServiceException;
import org.rcisoft.core.jwt.util.CyJwtUtil;
......@@ -33,18 +35,25 @@ import org.rcisoft.sys.visit.entity.VisitUser;
import org.rcisoft.sys.visit.service.VisitInfomationService;
import org.rcisoft.sys.wbac.user.dto.ErrorDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.rcisoft.core.model.CyPageInfo;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
......@@ -57,6 +66,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -92,6 +102,12 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
@Autowired
private CyDownErrorTxtComp errorTxt;
@Value("${global.base_upload_location}")
private String baseUploadLocation;
@Value("${global.temp_location}")
private String tempLocation;
@Autowired
private SysUserServiceImpl sysUserService;
......@@ -152,12 +168,12 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
u.setUserId(sysUser.getBusinessId());
} else {
// 存在覆盖
if (sysUserList.get(0).getUserType().equals("0")){
throw new CyServiceException(500,"员工不能作为访客!");
if (sysUserList.get(0).getUserType().equals("0")) {
throw new CyServiceException(500, "员工不能作为访客!");
}
if (sysUserList.get(0).getUserType().equals("1")){
if (sysUserList.get(0).getBlacklistFlag().toString().equals("1")){
throw new CyServiceException(500,"不能邀请黑名单内的访客!");
if (sysUserList.get(0).getUserType().equals("1")) {
if (sysUserList.get(0).getBlacklistFlag().toString().equals("1")) {
throw new CyServiceException(500, "不能邀请黑名单内的访客!");
}
sysUser.setBusinessId(sysUserList.get(0).getBusinessId());
sysUserRepositorys.updateSysUser(sysUser);
......@@ -187,13 +203,14 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
visitInfomation.getBusinessId() + "的邀访信息信息");
return new CyPersistModel(line);
}
/**
* 禁用 邀访信息
*
* @param visitInfomation
* @return
*/
public CyPersistModel forbidden(VisitInfoMation visitInfomation){
public CyPersistModel forbidden(VisitInfoMation visitInfomation) {
visitInfomation.setVisitStatus("2");
// 禁用邀访信息
int line = baseMapper.updateById(visitInfomation);
......@@ -540,7 +557,7 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
}
@Override
public ImportVistInfoDTO importUserExcel(MultipartFile file,HttpServletResponse response) throws ParseException {
public ImportVistInfoDTO importUserExcel(MultipartFile file, HttpServletResponse response) throws ParseException {
ImportVistInfoDTO importVistInfoDTO = new ImportVistInfoDTO();
Calendar calendar = Calendar.getInstance();
String nowTime = new SimpleDateFormat("yyyyMMddHHmmss").format(calendar.getTime());
......@@ -556,16 +573,6 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
if (!flag) {
throw new CyServiceException(CyResSvcExcEnum.EXCEL_IMPORT_HEADER_ERROR);
}
if (!flag || !CyCompareToolUtils.compareFileName(file, "邀访信息", 0, 0)) {
String errorBefore = "上传模板错误请重新下载!";
errorText(errorBefore, importVistInfoDTO, maps, fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.EXCEL_IMPORT_HEADER_ERROR);
}
return importVistInfoDTO;
}
/** 从excel表中读到数据,有一部分为空值 */
List<ExportVisitInfoDto> visitInfoDtoList = CyEpExcelUtil.importExcel(file, 2, 1, ExportVisitInfoDto.class);
/** 校验后没有问题的数据 */
......@@ -574,23 +581,9 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
//判断整个Excel是不是为空 计算非空数据有多少条
int information = CyCompareToolUtils.cmpareInformation(visitInfoDtoList);
if (information == 0) {
String errorBefore = "Excel文件不可为空,请检查Excel文件是否填写!";
errorText(errorBefore, importVistInfoDTO, maps, fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
return importVistInfoDTO;
throw new CyServiceException("Excel文件不可为空,请检查Excel文件是否填写!");
} else if (information > 500) {
String errorMore = "单次导入数据不可超过500,请检查!";
errorText(errorMore, importVistInfoDTO, maps, fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
return importVistInfoDTO;
throw new CyServiceException("单次导入数据不可超过500,请检查!");
} else {
//去除空数据
try {
......@@ -729,7 +722,7 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
if (null != maps && maps.size() > 0) {
importVistInfoDTO.setFilename(fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
......@@ -742,6 +735,81 @@ public class VisitInfomationServiceImpl extends ServiceImpl<VisitInfomationRepos
return baseMapper.findByUser(visitUser);
}
public void exportTxtPaper(List<Map<Integer, List<String>>> list, String filename) throws Exception {
String basePath = baseUploadLocation.substring(0, baseUploadLocation.lastIndexOf("/") - 1);
String path = basePath + tempLocation + "/";
File file = new File(path);
File file1 = new File(path + filename);
if (!file.isDirectory()) {
file.mkdirs();
}
if (!file1.exists()) {
boolean boo = file1.createNewFile();
if (!boo) {
log.info("文件创建失败");
}
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1, false), "utf-8"), 10240);
try {
Iterator var8 = list.iterator();
while (var8.hasNext()) {
Map<Integer, List<String>> map = (Map) var8.next();
Iterator var10 = map.keySet().iterator();
while (var10.hasNext()) {
Integer s = (Integer) var10.next();
List<String> list1 = (List) map.get(s);
if (s != -1) {
out.write("第" + s + "行");
}
for (int i = 0; i < list1.size(); ++i) {
Object var10001 = list1.get(i);
out.write((String) var10001 + "\r\n");
out.write(" ");
}
out.newLine();
}
}
} catch (Exception var22) {
log.info("context:" + var22);
} finally {
try {
out.flush();
out.close();
} catch (IOException var21) {
log.info("context:" + var21);
}
}
}
/**
* 下载错误文件
*
* @param response
*/
@Override
public int download(String fileName, HttpServletResponse response) {
String basePath = baseUploadLocation.substring(0, baseUploadLocation.lastIndexOf("/") - 1);
String path = basePath + tempLocation + "/" + fileName;
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/x-msdownload");
response.setHeader("Content-Disposition",
"attachment;filename=" + fileName);
File file = null;
ServletOutputStream os = null;
try {
file = new File(path);
os = response.getOutputStream();
byte bytes[] = FileUtils.readFileToByteArray(file);//read文件成字节数组,然后将字节数组写入os输出流中去
os.write(bytes);
os.flush();
os.close();
} catch (Exception e) {
log.info("context:" + e);
}
return 1;
}
void errorText(String error, ImportVistInfoDTO importVistInfoDTO, List<Map<Integer, List<String>>> maps, String fileName) {
List<String> strings = new ArrayList<String>();
......
......@@ -85,8 +85,8 @@ logging:
# com.alibaba.nacos: debug
global:
#base_upload_location: /working/file/
base_upload_location: D:\working\file
base_upload_location: /working/file/
#base_upload_location: D:\working\file
base_discovery: 'http://124.71.16.228:18088/file/'
code_generate_location: /code
video_location: /video
......
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