delete 删除查询日志

This commit is contained in:
lijiarao
2021-10-12 16:31:24 +08:00
parent 38e36f6e7c
commit 92b9458c3a
10 changed files with 158 additions and 51 deletions
+1 -1
View File
@@ -406,7 +406,7 @@ CREATE TABLE `sys_depart` (
`depart_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '机构/部门名称',
`depart_name_en` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '英文名',
`depart_name_abbr` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '缩写',
`depart_order` int(11) NULL DEFAULT 0 COMMENT '排序',
`depart_order` int(11) NULL DEFAULT 1 COMMENT '排序',
`description` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '描述',
`org_category` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '1' COMMENT '机构类别 1公司,2组织机构,2岗位',
`org_type` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构类型 1一级部门 2子部门',
@@ -21,22 +21,22 @@ import java.util.Objects;
@Slf4j
public class ImportExcelUtil {
public static Result<?> importReturnRes(int errorLines, int successLines, List<String> errorMessage) throws IOException {
public static Result<?> importReturnRes(int errorLines, List<String> errorMessage) {
if (errorLines == 0) {
return Result.OK("" + successLines + "行数据全部导入成功!");
return Result.OK("导入成功!");
} else {
JSONObject result = new JSONObject(5);
int totalCount = successLines + errorLines;
result.put("totalCount", totalCount);
result.put("errorCount", errorLines);
result.put("successCount", successLines);
result.put("msg", "总上传行数:" + totalCount + ",已导入行数:" + successLines + ",错误次数:" + errorLines +",错误信息:" +errorMessage);
String fileUrl = PmsUtil.saveErrorTxtByList(errorMessage, "userImportExcelErrorLog");
//JSONObject result = new JSONObject(5);
//int totalCount = successLines + errorLines;
//result.put("totalCount", totalCount);
//result.put("errorCount", errorLines);
//result.put("successCount", successLines);
//result.put("msg", "总上传行数:" + totalCount + ",已导入行数:" + successLines + ",错误次数:" + errorLines +",错误信息:" +errorMessage);
//String fileUrl = PmsUtil.saveErrorTxtByList(errorMessage, "userImportExcelErrorLog");
//int lastIndex = fileUrl.lastIndexOf(File.separator);
//String fileName = fileUrl.substring(lastIndex + 1);
//result.put("fileUrl", "/sys/common/static/" + fileUrl);
//result.put("fileName", fileName);
throw new JeroBootException("文件导入失败:"+errorMessage);
throw new JeroBootException(errorMessage.toString());
}
}
@@ -78,17 +78,17 @@ public class ImportExcelUtil {
int lineNumber = i + 1;
// 通过索引名判断出错信息
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE)) {
errorMessage.add("" + lineNumber + " 行:角色编码已经存在,忽略导入");
errorMessage.add("" + lineNumber + " 行:角色编码已经存在。");
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_JOB_CLASS_NAME)) {
errorMessage.add("" + lineNumber + " 行:任务类名已经存在,忽略导入");
errorMessage.add("" + lineNumber + " 行:任务类名已经存在。");
}else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_CODE)) {
errorMessage.add("" + lineNumber + " 行:职务编码已经存在,忽略导入");
errorMessage.add("" + lineNumber + " 行:职务编码已经存在。");
}else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE)) {
errorMessage.add("" + lineNumber + " 行:部门编码已经存在,忽略导入");
errorMessage.add("" + lineNumber + " 行:部门编码已经存在。");
}else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_DEPART_DEPART_NAME)) {
errorMessage.add("" + lineNumber + " 行:部门名称已经存在,忽略导入");
errorMessage.add("" + lineNumber + " 行:部门名称已经存在。");
}else {
errorMessage.add("" + lineNumber + " 行:未知错误,忽略导入");
errorMessage.add("" + lineNumber + " 行:未知错误");
log.error(e.getMessage(), e);
}
}
@@ -8,6 +8,8 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.groups.Default;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
@@ -42,13 +44,32 @@ public class ValidUtil {
StringBuilder msg = new StringBuilder();
Set<ConstraintViolation<Object>> set = validator.validate(object, groups);
for (ConstraintViolation<Object> constraintViolation : set) {
msg.append(constraintViolation.getMessage()).append("<br/>");
msg.append(constraintViolation.getMessage()).append("");
}
if (StringUtils.isNotBlank(msg)) {
throw new JeroBootException(msg.toString());
}
}
/**
* 手动校验@Vaild并抛出异常信息list
*
* @param object 待校验对象
* @param groups 待校验的组
* @return errorList
*/
public static String validateReturnList(Object object, Class<?>... groups){
StringBuilder msg = new StringBuilder();
Set<ConstraintViolation<Object>> set = validator.validate(object, groups);
for (ConstraintViolation<Object> constraintViolation : set) {
msg.append(constraintViolation.getMessage()).append("");
}
if (msg.length()>0){
return msg.substring(0,msg.length()-1);
}
return msg.toString();
}
/**
* @Description 校验全部数据格式
* @Author lqt
@@ -256,7 +256,7 @@ public class QuartzJobController {
}
}
}
return ImportExcelUtil.importReturnRes(errorLines,successLines,errorMessage);
return ImportExcelUtil.importReturnRes(errorLines,errorMessage);
}
/**
@@ -1,6 +1,7 @@
package com.jero.modules.system.controller;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
@@ -8,6 +9,10 @@ import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.system.vo.SysDepartTreeModel;
import com.jero.common.util.ValidUtil;
import com.jero.modules.system.model.SysDepartExcel;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import com.jero.common.api.vo.Result;
import com.jero.common.constant.CacheConstant;
@@ -31,9 +36,11 @@ import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -306,6 +313,10 @@ public class SysDepartController {
QueryWrapper<SysDepart> queryWrapper = QueryGenerator.initQueryWrapper(sysDepart, request.getParameterMap());
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
String selections = request.getParameter("selections");
if(!oConvertUtils.isEmpty(selections)){
queryWrapper.in("id",selections.split(","));
}
List<SysDepart> pageList = sysDepartService.list(queryWrapper);
//按字典排序
Collections.sort(pageList, new Comparator<SysDepart>() {
@@ -331,13 +342,13 @@ public class SysDepartController {
* @return
*/
//@RequiresRoles({"admin"})
@Transactional(rollbackFor = Exception.class)
@RequiresPermissions("sys:depart:import")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException{
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<String> errorMessageList = new ArrayList<>();
List<SysDepart> listSysDeparts = null;
List<SysDepartExcel> listSysDeparts = null;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
@@ -346,39 +357,35 @@ public class SysDepartController {
params.setHeadRows(1);
params.setNeedSave(true);
//导入Excel格式校验,看匹配的字段文本概率
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDepart.class, params);
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDepartExcel.class, params,1.0);
if(!t){
return Result.error("导入Excel校验失败 ");
}
try {
// orgCode编码长度
int codeLength = YouBianCodeUtil.zhanweiLength;
listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepart.class, params);
listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepartExcel.class, params);
//按长度排序
Collections.sort(listSysDeparts, new Comparator<SysDepart>() {
Collections.sort(listSysDeparts, new Comparator<SysDepartExcel>() {
@Override
public int compare(SysDepart arg0, SysDepart arg1) {
public int compare(SysDepartExcel arg0, SysDepartExcel arg1) {
return arg0.getOrgCode().length() - arg1.getOrgCode().length();
}
});
List<String> errorMessage = new ArrayList<>();
int num = 0;
for (SysDepart sysDepart : listSysDeparts) {
for (SysDepartExcel sysDepart : listSysDeparts) {
String orgCode = sysDepart.getOrgCode();
if(orgCode.length() > codeLength) {
String parentCode = orgCode.substring(0, orgCode.length()-codeLength);
QueryWrapper<SysDepart> queryWrapper = new QueryWrapper<SysDepart>();
queryWrapper.eq("org_code", parentCode);
try {
SysDepart parentDept = sysDepartService.getOne(queryWrapper);
if(!parentDept.equals(null)) {
if(parentDept != null) {
sysDepart.setParentId(parentDept.getId());
} else {
sysDepart.setParentId("");
}
}catch (Exception e) {
//没有查找到parentDept
}
}else{
sysDepart.setParentId("");
}
@@ -386,7 +393,32 @@ public class SysDepartController {
sysDepart.setOrgType(sysDepart.getOrgCode().length()/codeLength+"");
//update-end---author:liusq Date:20210223 for:批量导入部门以后,不能追加下一级部门 #2245------------
sysDepart.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
ImportExcelUtil.importDateSaveOne(sysDepart, ISysDepartService.class, errorMessageList, num, CommonConstant.SQL_INDEX_UNIQ_DEPART_ORG_CODE);
int lineNumber = num +1;
try {
String error = ValidUtil.validateReturnList(sysDepart);
if (StringUtils.isNotBlank(error)){
errorMessage.add("" + lineNumber + " 行:"+ error);
}
LambdaQueryWrapper<SysDepart> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysDepart::getDepartName,sysDepart.getDepartName());
if (sysDepartService.count(wrapper) > 0) {
errorMessage.add("" + lineNumber + " 行:部门名称已经存在");
}
LambdaQueryWrapper<SysDepart> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(SysDepart::getOrgCode,sysDepart.getOrgCode());
if (sysDepartService.count(wrapper1) > 0) {
errorMessage.add("" + lineNumber + " 行:部门编码已经存在");
}
if (errorMessage.isEmpty()){
SysDepart sysDepart1 = new SysDepart();
BeanUtils.copyProperties(sysDepart,sysDepart1);
sysDepart1.setDepartOrder(new BigDecimal(String.valueOf(sysDepart.getDepartOrder())));
sysDepartService.save(sysDepart1);
}
} catch (Exception e) {
errorMessage.add("" + lineNumber + " 行:未知错误");
log.error(e.getMessage(), e);
}
num++;
}
//清空部门缓存
@@ -394,7 +426,7 @@ public class SysDepartController {
Set keys4 = redisTemplate.keys(CacheConstant.SYS_DEPART_IDS_CACHE + "*");
redisTemplate.delete(keys3);
redisTemplate.delete(keys4);
return ImportExcelUtil.importReturnRes(errorMessageList.size(), listSysDeparts.size() - errorMessageList.size(), errorMessageList);
return ImportExcelUtil.importReturnRes(errorMessage.size(), errorMessage);
} catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("文件导入失败:"+e.getMessage());
@@ -517,7 +517,7 @@ public class SysDictController {
errorMessage.add("" + lineNumber + " 行:字典编码已经存在,忽略导入。");
}
}
return ImportExcelUtil.importReturnRes(errorLines,successLines,errorMessage);
return ImportExcelUtil.importReturnRes(errorLines,errorMessage);
} catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("文件导入失败:"+e.getMessage());
@@ -769,21 +769,14 @@ public class SysUserController {
errorLines++;
errorMessage.add("" + lineNumber + " 行:电子邮件已经存在。");
}
sysUserService.save(sysUserExcel);
successLines++;
}catch (JeroBootException e) {
errorLines++;
errorMessage.add("" + lineNumber + " 行:" + e.getMessage());
} catch (Exception e) {
//errorLines++;
String message = e.getMessage().toLowerCase();
// 通过索引名判断出错信息
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_WORK_NO)) {
errorMessage.add("" + lineNumber + " 行:工号已经存在。");
} else {
errorMessage.add("" + lineNumber + " 行:未知错误");
log.error(e.getMessage(), e);
if (errorLines == 0){
sysUserService.save(sysUserExcel);
}
successLines++;
} catch (Exception e) {
// 通过索引名判断出错信息
errorMessage.add("" + lineNumber + " 行:未知错误");
log.error(e.getMessage(), e);
}
String userId = sysUserExcel.getId();
// 批量将部门和用户信息建立关联关系
@@ -819,7 +812,7 @@ public class SysUserController {
}
}
}
return ImportExcelUtil.importReturnRes(errorLines,successLines,errorMessage);
return ImportExcelUtil.importReturnRes(errorLines,errorMessage);
}
/**
@@ -12,6 +12,7 @@ import org.springframework.format.annotation.NumberFormat;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@@ -54,6 +55,7 @@ public class SysDepart implements Serializable {
/**机构类别 1公司,2组织机构,2岗位*/
@Excel(name="机构类别",width=15,dicCode="org_category",orderNum = "3")
private String orgCategory;
/**机构类型*/
private String orgType;
/**机构编码*/
@@ -61,6 +63,7 @@ public class SysDepart implements Serializable {
private String orgCode;
/**手机号*/
@Excel(name="电话",width=15,orderNum = "5")
@Pattern(regexp = "^((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(17[0135678])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$",message = "手机号码格式错误")
private String mobile;
/**传真*/
private String fax;
@@ -0,0 +1,58 @@
package com.jero.modules.system.model;
import com.jero.common.aspect.annotation.Dict;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
/**
* @author liJiaRao
* @date 2021-10-12 14:29
*/
@Data
public class SysDepartExcel {
/**父机构ID*/
@Excel(name="上级部门",width=15,orderNum = "1",dictTable = "sys_depart",dicText = "depart_name",dicCode = "id")
private String parentId;
/**机构/部门名称*/
@Excel(name="机构/部门名称",width=15)
private String departName;
/**排序*/
@Excel(name="排序",width=15,orderNum = "4")
@Min(value = 1,message = "排序最小为1,最大为99999")
@Max(value = 99999,message = "排序最小为1,最大为99999")
@Pattern(regexp = "^[1-9](\\d{0,4})$",message = "排序格式错误")
private String departOrder;
/**描述*/
@Excel(name="描述",width=15)
private String description;
/**机构类别 1公司,2组织机构,2岗位*/
@Excel(name="机构类别",width=15,dicCode="org_category",orderNum = "3")
private String orgCategory;
/**机构编码*/
@Excel(name="机构编码",width=15,orderNum = "2")
private String orgCode;
/**手机号*/
@Excel(name="电话",width=15,orderNum = "5")
@Pattern(regexp = "^((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(17[0135678])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$",message = "手机号码格式错误")
private String mobile;
/**传真*/
private String fax;
/**地址*/
@Excel(name="地址",width=15,orderNum = "6")
private String address;
/**备注*/
@Excel(name="备注",width=15,orderNum = "7")
private String memo;
/**机构类型*/
private String orgType;
/**删除状态(0,正常,1已删除)*/
@Dict(dicCode = "del_flag")
private String delFlag;
}
@@ -65,7 +65,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
List<String> list = ImportExcelUtil.importDateSave(listSysRoles, ISysRoleService.class, errorStrs, CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE);
errorLines+=list.size();
successLines+=(listSysRoles.size()-errorLines);
return ImportExcelUtil.importReturnRes(errorLines,successLines,list);
return ImportExcelUtil.importReturnRes(errorLines,list);
}
@Override