123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- package com.ruoyi.web.controller.system;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.convert.Convert;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.util.ArrayUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONArray;
- import cn.hutool.json.JSONObject;
- import cn.hutool.json.JSONUtil;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.annotation.Security;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.core.domain.entity.SysDept;
- import com.ruoyi.common.core.domain.entity.SysRole;
- import com.ruoyi.common.core.domain.entity.SysUser;
- import com.ruoyi.common.core.page.TableDataInfo;
- import com.ruoyi.common.enums.BusinessType;
- import com.ruoyi.common.exception.ServiceException;
- import com.ruoyi.common.utils.SecurityUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.UserUtil;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.system.domain.vo.SysUserExportVo;
- import com.ruoyi.system.domain.vo.SysUserImportVo;
- import com.ruoyi.system.service.ISysDeptService;
- import com.ruoyi.system.service.ISysRoleService;
- import com.ruoyi.system.service.ISysUserService;
- import com.ruoyi.zhdd.domain.GatewayUserDetail;
- import com.ruoyi.zhdd.domain.GatewayUserPage;
- import com.ruoyi.zhdd.domain.Resource;
- import com.ruoyi.zhdd.domain.bo.ResourceBo;
- import com.ruoyi.zhdd.feign.FeignUserManageService;
- import com.ruoyi.zhdd.service.IResourceService;
- import lombok.Data;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 用户信息
- *
- * @author ruoyi
- */
- @RestController
- @RequestMapping("/system/user")
- @Slf4j
- public class SysUserController extends BaseController {
- @Autowired
- private ISysUserService userService;
- @Autowired
- private ISysRoleService roleService;
- @Autowired
- private FeignUserManageService feignUserManageService;
- @Autowired
- private ISysDeptService deptService;
- @Autowired
- private IResourceService resourceService;
- /**
- * 获取用户列表
- */
- @GetMapping("/list")
- public TableDataInfo list(SysUser user) {
- return userService.selectPageUserList(user);
- }
- @Log(title = "用户管理", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public void export(SysUser user, HttpServletResponse response) {
- List<SysUser> list = userService.selectUserList(user);
- List<SysUserExportVo> listVo = BeanUtil.copyToList(list, SysUserExportVo.class);
- for (int i = 0; i < list.size(); i++) {
- SysDept dept = list.get(i).getDept();
- SysUserExportVo vo = listVo.get(i);
- if (ObjectUtil.isNotEmpty(dept)) {
- vo.setDeptName(dept.getDeptName());
- vo.setLeader(dept.getLeader());
- }
- }
- ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
- }
- @Log(title = "用户管理", businessType = BusinessType.IMPORT)
- @PostMapping("/importData")
- public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
- List<SysUserImportVo> userListVo = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class);
- List<SysUser> userList = BeanUtil.copyToList(userListVo, SysUser.class);
- String operName = getUsername();
- String message = userService.importUser(userList, updateSupport, operName);
- return AjaxResult.success(message);
- }
- @GetMapping("/importTemplate")
- public void importTemplate(HttpServletResponse response) {
- ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
- }
- /**
- * 根据用户编号获取详细信息
- */
- @GetMapping(value = {"/", "/{userId}"})
- public AjaxResult getInfo(@PathVariable(value = "userId", required = false) String userId) {
- // userService.checkUserDataScope(userId);
- Map<String, Object> ajax = new HashMap<>();
- List<SysRole> roles = roleService.selectRoleAll();
- ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
- // ajax.put("posts", postService.selectPostAll());
- ajax.put("posts", new ArrayList<>());
- if (StringUtils.isNotNull(userId)) {
- ajax.put("user", userService.selectUserById(userId));
- // ajax.put("postIds", postService.selectPostListByUserId(userId));
- ajax.put("postIds", new ArrayList<>());
- ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
- }
- return AjaxResult.success(ajax);
- }
- /**
- * 新增用户
- */
- // @Log(title = "用户管理", businessType = BusinessType.INSERT)
- // @PostMapping
- // public AjaxResult add(@Validated @RequestBody SysUser user) {
- // if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) {
- // return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
- // } else if (StringUtils.isNotEmpty(user.getPhonenumber())
- // && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
- // return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
- // } else if (StringUtils.isNotEmpty(user.getEmail())
- // && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
- // return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
- // }
- // user.setCreateBy(getUsername());
- // user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
- // return toAjax(userService.insertUser(user));
- // }
- /**
- * 修改用户
- */
- @Log(title = "用户管理", businessType = BusinessType.UPDATE)
- @PutMapping
- @Security
- public AjaxResult edit(@Validated @RequestBody SysUser user) {
- /*userService.checkUserAllowed(user);
- if (StringUtils.isNotEmpty(user.getPhonenumber())
- && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
- return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
- } else if (StringUtils.isNotEmpty(user.getEmail())
- && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
- return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
- }*/
- user.setUpdateBy(UserUtil.getCacheLoginUser().getUsername());
- return toAjax(userService.updateUser(user));
- }
- /**
- * 删除用户
- */
- @Log(title = "用户管理", businessType = BusinessType.DELETE)
- @DeleteMapping("/{userIds}")
- @Security
- public AjaxResult remove(@PathVariable String[] userIds) {
- if (ArrayUtil.contains(userIds, getUserId())) {
- return error("当前用户不能删除");
- }
- return toAjax(userService.deleteUserByIds(userIds));
- }
- /**
- * 重置密码
- */
- @Log(title = "用户管理", businessType = BusinessType.UPDATE)
- @PutMapping("/resetPwd")
- public AjaxResult resetPwd(@RequestBody SysUser user) {
- userService.checkUserAllowed(user);
- user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
- user.setUpdateBy(getUsername());
- return toAjax(userService.resetPwd(user));
- }
- /**
- * 状态修改
- */
- @Log(title = "用户管理", businessType = BusinessType.UPDATE)
- @PutMapping("/changeStatus")
- public AjaxResult changeStatus(@RequestBody SysUser user) {
- userService.checkUserAllowed(user);
- user.setUpdateBy(getUsername());
- return toAjax(userService.updateUserStatus(user));
- }
- /**
- * 根据用户编号获取授权角色
- */
- @GetMapping("/authRole/{userId}")
- public AjaxResult authRole(@PathVariable("userId") String userId) {
- SysUser user = userService.selectUserById(userId);
- List<SysRole> roles = roleService.selectRolesByUserId(userId);
- Map<String, Object> ajax = new HashMap<>();
- ajax.put("user", user);
- ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
- return AjaxResult.success(ajax);
- }
- /**
- * 用户授权角色
- */
- @Log(title = "用户管理", businessType = BusinessType.GRANT)
- @PutMapping("/authRole")
- @Security
- public AjaxResult insertAuthRole(String userId, String[] roleIds) {
- userService.insertUserAuth(userId, roleIds);
- return success();
- }
- @PostMapping("/syncUc")
- @Security
- public void syncUc() {
- List<SysUser> list = userService.list();
- for (SysUser sysUser : list) {
- this.edit(sysUser);
- }
- }
- @GetMapping("/searchGatewayUser")
- @Security
- public AjaxResult searchGatewayUser(@RequestParam String name) {
- GatewayUserPage gatewayUserPage = feignUserManageService.userPage(name, 1, 500);
- log.info("获取网关用户数据:{}", gatewayUserPage);
- List<GatewayUserPage.UserDetail> users = new ArrayList<>();
- if (gatewayUserPage != null && gatewayUserPage.getCode() == 200) {
- int total = gatewayUserPage.getData().getTotal();
- if (total > 0) {
- users = gatewayUserPage.getData().getRows();
- for (GatewayUserPage.UserDetail row : users) {
- // 查询本系统是否存在该用户
- SysUser sysUser = userService.selectUserById(row.getUserId());
- if (sysUser != null) {
- row.setLocalFlag("1");
- } else {
- row.setLocalFlag("0");
- }
- }
- }
- }
- return AjaxResult.success(users);
- }
- @PostMapping("/syncGatewayUser")
- @Security
- public AjaxResult<Void> syncGatewayUser(@RequestBody JSONObject jsonObject) {
- String userId = jsonObject.getStr("userId");
- if (StrUtil.isBlank(userId)) {
- return AjaxResult.error("用户id不能为空!");
- }
- // 先查询本系统是否存在
- SysUser sysUser = userService.selectUserById(userId);
- if (sysUser != null) {
- return AjaxResult.error("系统已存在,请在本系统管理该用户!");
- }
- // 查询网关用户信息,并保存到系统
- GatewayUserDetail gatewayUserDetail = feignUserManageService.userDetail(userId);
- log.info("四维用户详情:{}", gatewayUserDetail);
- // 如果非空则新增到数据库
- if (gatewayUserDetail.getCode() == 200 && gatewayUserDetail.getData() != null && StrUtil.isNotBlank(gatewayUserDetail.getData().getUserId())) {
- GatewayUserDetail.UserDetail data = gatewayUserDetail.getData();
- SysUser newUser = new SysUser();
- // 如果是企业用户,则查询是否存在企业信息,存在则新增企业部门,同时往应急仓库新增一个数据
- if (data.getUserGroupId() == 4) {
- GatewayUserDetail.EntInfo entInfo = data.getEntInfo();
- if (entInfo == null || StrUtil.isBlank(entInfo.getEntName()) || StrUtil.isBlank(entInfo.getOwnerId()) || StrUtil.isBlank(entInfo.getOwnerCategory())) {
- throw new ServiceException("企业用户未绑定企业,不能使用此系统");
- }
- newUser.setDeptId(entInfo.getOwnerId());
- newUser.setOrgId(entInfo.getOwnerId());
- SysDept sysDept = deptService.selectDeptById(entInfo.getOwnerId());
- String locationType = "2";
- if (sysDept == null) {
- sysDept = new SysDept();
- sysDept.setDeptId(entInfo.getOwnerId());
- sysDept.setDeptName(entInfo.getEntName());
- sysDept.setFlag("0");
- // 根据企业类型放置不同的目录中
- if ("危货业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10001");
- } else if ("普货业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10002");
- } else if ("客运业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10003");
- } else if ("出租车业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10004");
- } else if ("公交运输业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10005");
- } else if ("汽车租赁业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10006");
- } else if ("检测站业户".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10007");
- } else if ("网约车平台".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10008");
- } else if ("维修站".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10009");
- } else if ("其他".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10010");
- } else if ("公路工程".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10011");
- } else if ("水运工程".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10012");
- locationType = "1";
- } else if ("航运企业".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10013");
- locationType = "1";
- } else if ("港口码头".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10014");
- locationType = "1";
- } else if ("水上游览经营".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10015");
- locationType = "1";
- } else if ("货运场站".equals(entInfo.getOwnerCategory())) {
- sysDept.setParentId("10016");
- }
- deptService.insertDept(sysDept);
- }
- List<Resource> resourcesList = resourceService.list(Wrappers.<Resource>lambdaQuery().eq(Resource::getManageUnitId, entInfo.getOwnerId()));
- if (resourcesList == null || resourcesList.size() == 0) {
- // 新增应急仓库
- ResourceBo resource = new ResourceBo();
- resource.setAdminOrgName(entInfo.getAdminOrgName());
- resource.setResourceType(1);
- resource.setName(entInfo.getEntName() + "仓库");
- resource.setManageUnit(entInfo.getEntName());
- resource.setContactName(data.getName());
- resource.setContactPhone(data.getMobile());
- resource.setLocationType(locationType);
- resource.setManageUnitId(entInfo.getOwnerId());
- // 默认为宿迁市交通局坐标
- resource.setLatitude("33.961569");
- resource.setLongitude("118.260139");
- resourceService.insertByBo(resource);
- }
- }
- newUser.setUserId(data.getUserId());
- newUser.setUserName(data.getUserName());
- newUser.setNickName(data.getName());
- newUser.setUserType(Convert.toStr(data.getUserGroupId()));
- newUser.setPhonenumber(data.getMobile());
- newUser.setPassword(SecurityUtils.encryptPassword("tocc!suqian"));
- newUser.setStatus("0");
- newUser.setDelFlag("0");
- newUser.setUpdateBy("gateway");
- newUser.setUpdateTime(new Date());
- newUser.setCreateBy("gateway");
- newUser.setCreateTime(new Date());
- userService.insertUser(newUser);
- } else {
- return AjaxResult.error("网关未查询到该用户信息!");
- }
- return AjaxResult.success();
- }
- @GetMapping("/compareDept")
- public void compareDept() {
- String s = FileUtil.readUtf8String("/Users/huangcheng/Desktop/siweidept");
- JSONArray jsonArray = JSONUtil.parseArray(s);
- List<SiweiDept> siweiDepts = JSONUtil.toList(jsonArray, SiweiDept.class);
- List<SysDept> list = deptService.list();
- /////////////////////////
- List<String> siweiIds = siweiDepts.stream().map(SiweiDept::getId).collect(Collectors.toList());
- List<String> hsIds = list.stream().map(SysDept::getDeptId).collect(Collectors.toList());
- System.out.println("四维存在,华设不存在" + CollUtil.subtract(siweiIds, hsIds));
- System.out.println("四维不存在,华设存在" + CollUtil.subtract(hsIds, siweiIds));
- /////////////////////////
- Map<String, SiweiDept> siweiDeptIds = siweiDepts.stream().collect(Collectors.toMap(SiweiDept::getId, a -> a));
- for (SysDept sysDept : list) {
- String deptid = sysDept.getDeptId();
- SiweiDept siweiDept = siweiDeptIds.get(deptid);
- if (siweiDept != null) {
- if (StrUtil.isBlank(siweiDept.getParentId())) {
- siweiDept.setParentId("0");
- }
- if (StrUtil.isNotBlank(siweiDept.getFullName())) {
- siweiDept.setFullName(siweiDept.getFullName().replace("-", "/"));
- }
- try {
- if (!sysDept.getParentId().equals(siweiDept.getParentId()) || !sysDept.getDeptName().equals(siweiDept.getName()) || !sysDept.getFlag().equals(Convert.toStr(siweiDept.getFlag())) || !sysDept.getFullName().equals(siweiDept.getFullName())) {
- System.out.println("华设:" + sysDept.getDeptId() + "-" + sysDept.getParentId() + "-" + sysDept.getDeptName() + "-" + sysDept.getFullName());
- System.out.println("四维:" + siweiDept.getId() + "-" + siweiDept.getParentId() + "-" + siweiDept.getName() + "-" + siweiDept.getFullName());
- }
- // if (!sysDept.getDeptName().equals(siweiDept.getName())) {
- // System.out.println("华设:" + sysDept.getDeptId() + "-" + sysDept.getDeptName());
- // System.out.println("四维:" + siweiDept.getId() + "-" + siweiDept.getName());
- // }
- // if (!sysDept.getParentId().equals(siweiDept.getParentId()) || !sysDept.getFullName().equals(siweiDept.getFullName())) {
- // System.out.println("华设:" + sysDept.getDeptId() + "-" + sysDept.getParentId() + "-" + sysDept.getFullName());
- // System.out.println("四维:" + siweiDept.getId() + "-" + siweiDept.getParentId() + "-" + siweiDept.getFullName());
- // }
- } catch (Exception e) {
- System.out.println("错误华设:" + sysDept);
- System.out.println("错误四维:" + siweiDept);
- }
- }
- }
- }
- @Data
- public static class SiweiDept {
- private String id;
- private String name;
- private String parentId;
- private Integer flag;
- private String fullName;
- }
- // public static void main(String[] args) {
- // String s = FileUtil.readUtf8String("/Users/huangcheng/Desktop/temp");
- // JSONArray jsonArray = JSONUtil.parseArray(s);
- // List<SiweiDept> siweiDepts = JSONUtil.toList(jsonArray, SiweiDept.class);
- // for (SiweiDept siweiDept : siweiDepts) {
- // System.out.println(StrUtil.concat(true, "INSERT INTO sys_dept (dept_id, parent_id, ancestors, dept_name, flag, full_name) VALUES ('",
- // siweiDept.getId(),
- // "', '",
- // siweiDept.getParentId(),
- // "', '0,35e6872a8c46440fbca1b1c01862a380,7298cf74a4ae4b0d9181286fa6647266', '",
- // siweiDept.getName(),
- // "', '1', '",
- // siweiDept.getFullName().replace("-", "/"),
- // "');"));
- // }
- // }
- }
|