add 导入工具-用户权限
This commit is contained in:
+115
-38
@@ -1,71 +1,148 @@
|
|||||||
package com.jero.modules.laws.localTool.controller;
|
package com.jero.modules.laws.localTool.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.jero.common.api.vo.Result;
|
import com.jero.common.api.vo.Result;
|
||||||
import com.jero.common.aspect.annotation.AutoLog;
|
import com.jero.common.aspect.annotation.AutoLog;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
import com.jero.modules.laws.localTool.entity.Part;
|
import com.jero.modules.laws.localTool.entity.Part;
|
||||||
import com.jero.modules.laws.localTool.entity.StandardEarlyWarning;
|
import com.jero.modules.laws.localTool.entity.UserPermissionVO;
|
||||||
import com.jero.modules.system.entity.SysDictItem;
|
import com.jero.modules.system.entity.SysDictItem;
|
||||||
|
import com.jero.modules.system.entity.SysRole;
|
||||||
|
import com.jero.modules.system.entity.SysUser;
|
||||||
|
import com.jero.modules.system.entity.SysUserRole;
|
||||||
import com.jero.modules.system.service.ISysDictItemService;
|
import com.jero.modules.system.service.ISysDictItemService;
|
||||||
|
import com.jero.modules.system.service.ISysRoleService;
|
||||||
|
import com.jero.modules.system.service.ISysUserRoleService;
|
||||||
|
import com.jero.modules.system.service.ISysUserService;
|
||||||
import com.spire.ms.System.Collections.ArrayList;
|
import com.spire.ms.System.Collections.ArrayList;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.io.File;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: liao
|
* @Author: liao
|
||||||
* @Date: 2023/10/31 16:49
|
* @Date: 2023/10/31 16:49
|
||||||
* @Description: 工具
|
* @Description: 工具
|
||||||
*/
|
*/
|
||||||
@Api(tags="工具")
|
@Api(tags="导入工具")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/laws/localTool/util")
|
@RequestMapping("/laws/localTool/importUtil")
|
||||||
public class LawsUtilController {
|
public class LawsUtilController {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private ISysDictItemService sysDictItemService;
|
private ISysDictItemService sysDictItemService;
|
||||||
|
@Resource
|
||||||
|
private ISysUserService sysUserService;
|
||||||
|
@Resource
|
||||||
|
private ISysRoleService sysRoleService;
|
||||||
|
@Resource
|
||||||
|
private ISysUserRoleService sysUserRoleService;
|
||||||
|
|
||||||
@GetMapping(value = "/import")
|
@AutoLog(value = "导入工具-零部件")
|
||||||
public void newModelImplementation() {
|
@ApiOperation(value = "导入工具-零部件", notes = "导入工具-零部件")
|
||||||
|
@PostMapping(value = "/importPart")
|
||||||
|
public Result<String> importPart(HttpServletRequest request) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
ImportParams params = new ImportParams();
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||||
params.setHeadRows(1);
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||||
String filePath = "D:\\Download\\browser\\Chrome\\中国重汽法规智库\\零部件导入.xlsx";
|
int count = 0;
|
||||||
List<Part> parts = ExcelImportUtil.importExcel(new File(filePath), Part.class, params);
|
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
||||||
List<SysDictItem> sysDictItems = new ArrayList();
|
MultipartFile file = entry.getValue();
|
||||||
for (int i = 0; i < parts.size(); i++) {
|
ImportParams params = new ImportParams();
|
||||||
SysDictItem dictItem = new SysDictItem();
|
params.setHeadRows(1);
|
||||||
// 字典id
|
try {
|
||||||
dictItem.setDictId("1696007957666533377");
|
List<Part> importExcel = ExcelImportUtil.importExcel(file.getInputStream(), Part.class, params);
|
||||||
// 父节点
|
List<SysDictItem> sysDictItems = new ArrayList();
|
||||||
dictItem.setParentId("0");
|
for (int i = 0; i < importExcel.size(); i++) {
|
||||||
// 是否标签管理显示(显示)
|
SysDictItem dictItem = new SysDictItem();
|
||||||
dictItem.setIsTagDict(1);
|
// 字典id
|
||||||
// 状态(启用)
|
dictItem.setDictId("1696007957666533377");
|
||||||
dictItem.setStatus(1);
|
// 父节点
|
||||||
dictItem.setDelFlag(0);
|
dictItem.setParentId("0");
|
||||||
// 排序
|
// 是否标签管理显示(显示)
|
||||||
dictItem.setSortOrder(i + 1);
|
dictItem.setIsTagDict(1);
|
||||||
// 字典项值
|
// 状态(启用)
|
||||||
dictItem.setItemValue(parts.get(i).getCode());
|
dictItem.setStatus(1);
|
||||||
// 字典项名称
|
dictItem.setDelFlag(0);
|
||||||
dictItem.setItemText(parts.get(i).getName());
|
// 排序
|
||||||
sysDictItems.add(dictItem);
|
dictItem.setSortOrder(i + 1);
|
||||||
|
// 字典项值
|
||||||
|
dictItem.setItemValue(importExcel.get(i).getCode());
|
||||||
|
// 字典项名称
|
||||||
|
dictItem.setItemText(importExcel.get(i).getName());
|
||||||
|
dictItem.setIsReadOnly(2);
|
||||||
|
sysDictItems.add(dictItem);
|
||||||
|
}
|
||||||
|
sysDictItemService.saveBatch(sysDictItems, sysDictItems.size());
|
||||||
|
count += importExcel.size();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JeroBootException("导入错误");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sysDictItemService.saveBatch(sysDictItems, sysDictItems.size());
|
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println("================导入零部件===============");
|
System.out.println("================导入零部件===============");
|
||||||
System.out.println("耗时:" + (end - start) + ",同步:" + parts.size() + "条数据");
|
System.out.println("耗时:" + (end - start) + ",同步:" + count + "条数据");
|
||||||
System.out.println("=======================================");
|
System.out.println("=======================================");
|
||||||
|
return Result.OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "导入工具-用户权限")
|
||||||
|
@ApiOperation(value = "导入工具-用户权限", notes = "导入工具-用户权限")
|
||||||
|
@PostMapping(value = "/importUserPermission")
|
||||||
|
public Result<String> userPermissionImport(HttpServletRequest request) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||||
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||||
|
int count = 0;
|
||||||
|
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
||||||
|
MultipartFile file = entry.getValue();
|
||||||
|
ImportParams params = new ImportParams();
|
||||||
|
params.setHeadRows(1);
|
||||||
|
try {
|
||||||
|
List<UserPermissionVO> importExcel = ExcelImportUtil.importExcel(file.getInputStream(), UserPermissionVO.class, params);
|
||||||
|
List<SysUserRole> insertList = new ArrayList();
|
||||||
|
List<SysUser> userList = sysUserService.list();
|
||||||
|
List<SysRole> roleList = sysRoleService.list();
|
||||||
|
Map<String, String> userMap = new HashMap<>();
|
||||||
|
Map<String, String> roleMap = new HashMap<>();
|
||||||
|
userList.forEach(user -> userMap.put(user.getUsername(), user.getId()));
|
||||||
|
roleList.forEach(role -> roleMap.put(role.getRoleName(), role.getId()));
|
||||||
|
importExcel.forEach(userPermissionVO -> {
|
||||||
|
SysUserRole userRole = new SysUserRole();
|
||||||
|
String userId = userMap.get(userPermissionVO.getUsername());
|
||||||
|
if (StringUtils.isBlank(userId)) {
|
||||||
|
throw new JeroBootException("工号:" + userPermissionVO.getUsername() + ",用户名:"
|
||||||
|
+ userPermissionVO.getRealName() + ",在用户表中不存在");
|
||||||
|
}
|
||||||
|
userRole.setUserId(userId);
|
||||||
|
String roleId = roleMap.get(userPermissionVO.getRoleName());
|
||||||
|
if (StringUtils.isBlank(roleId)) {
|
||||||
|
throw new JeroBootException("角色:" + userPermissionVO.getRoleName() + ",在角色表中不存在");
|
||||||
|
}
|
||||||
|
userRole.setRoleId(roleId);
|
||||||
|
insertList.add(userRole);
|
||||||
|
});
|
||||||
|
sysUserRoleService.saveBatch(insertList, insertList.size());
|
||||||
|
count += insertList.size();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JeroBootException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
System.out.println("================导入用户权限===============");
|
||||||
|
System.out.println("耗时:" + (end - start) + ",同步:" + count + "条数据");
|
||||||
|
System.out.println("=======================================");
|
||||||
|
return Result.OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package com.jero.modules.laws.localTool.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: liao
|
||||||
|
* @Date: 2023/11/9 17:10
|
||||||
|
* @Description: 用户权限
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value="用户权限", description="用户权限")
|
||||||
|
public class UserPermissionVO {
|
||||||
|
/**分类代码*/
|
||||||
|
@Excel(name = "USERID", width = 15)
|
||||||
|
@ApiModelProperty(value = "工号")
|
||||||
|
private java.lang.String username;
|
||||||
|
|
||||||
|
/**显示名称*/
|
||||||
|
@Excel(name = "USERNAME", width = 15)
|
||||||
|
@ApiModelProperty(value = "用户名")
|
||||||
|
private java.lang.String realName;
|
||||||
|
|
||||||
|
/**设计规范*/
|
||||||
|
@Excel(name = "ROLENAME", width = 15)
|
||||||
|
@ApiModelProperty(value = "角色名称")
|
||||||
|
private java.lang.String roleName;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user