1 files added
8 files modified
| | |
| | | import com.kidgrow.common.model.SysUserOrg; |
| | | import com.kidgrow.common.service.ISuperService; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | * @return SysUserOrg对象 |
| | | */ |
| | | SysUserOrg findByObject(SysUserOrg sysUserOrg); |
| | | List<SysUserOrg> getListByMap(Map<String, Object> params); |
| | | } |
| | | |
| | |
| | | import com.kidgrow.usercenter.vo.SysOrganizationVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cglib.beans.BeanCopier; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | map.put("id", ""+id); |
| | | map.put("name", collect.get(id).getOrgName()); |
| | | map.put("level", collect.get(id).getOrgLevel()); |
| | | map.put("parentId", collect.get(id).getOrgParentId()); |
| | | List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId() == id).map(e -> e.getId()).collect(Collectors.toList()); |
| | | if (childs.size() > 0) { |
| | | List<Map<String, Object>> treeData = getTreeData(id, sysOrganizations); |
| | |
| | | public SysUserOrg findByObject(SysUserOrg sysUserOrg){ |
| | | return baseMapper.findByObject(sysUserOrg); |
| | | } |
| | | |
| | | /** |
| | | * 根据自定义对象查询 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SysUserOrg> getListByMap(Map<String, Object> params) { |
| | | List<SysUserOrg> sysUserOrg = baseMapper.selectByMap(params); |
| | | return sysUserOrg; |
| | | } |
| | | } |
| | |
| | | List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList()); |
| | | |
| | | List<SysRole> sysRoles = roleUserService.findRolesByUserIds(userIds); |
| | | |
| | | // Map<String, Object> map = new HashMap<String, Object>(); |
| | | // List<SysOrganization> sysOrganizationList=organizationService.fin(); |
| | | list.forEach(u -> u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId())) |
| | | .collect(Collectors.toList()))); |
| | | } |
| | |
| | | package com.kidgrow.usercenter.controller; |
| | | |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.model.SysOrganization; |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.model.SysUserOrg; |
| | | import com.kidgrow.usercenter.service.ISysOrganizationService; |
| | | import com.kidgrow.usercenter.service.ISysUserOrgService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Api(tags = "用户与部门") |
| | | public class SysUserOrgController { |
| | | @Autowired |
| | | private ISysUserOrgService iSysUserOrgService; |
| | | private ISysUserOrgService sysUserOrgService; |
| | | @Autowired |
| | | private ISysOrganizationService sysOrganizationService; |
| | | |
| | | @PostMapping("getListByMap") |
| | | public List<SysUserOrg> getListByMap(@RequestParam Map<String,Object> map){ |
| | | List<SysUserOrg> sysUserOrgs = iSysUserOrgService.listByMap(map); |
| | | List<SysUserOrg> sysUserOrgs = sysUserOrgService.listByMap(map); |
| | | return sysUserOrgs; |
| | | } |
| | | |
| | | /** |
| | | * 根据条件查询列表 |
| | | * |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "根据条件查询列表") |
| | | @GetMapping |
| | | public ResultBody listByMap(@RequestParam Map<String, Object> map) { |
| | | return ResultBody.ok().data(sysUserOrgService.listByMap(map)).msg("查询成功"); |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody SysUserOrg sysUserOrg, BindingResult bindingResult, @LoginUser SysUser sysUser) { |
| | | if (bindingResult.hasErrors()) { |
| | | return ResultBody.failed().msg(bindingResult.getFieldError().getDefaultMessage()); |
| | | } else { |
| | | //先查出来父节点的信息 |
| | | if (sysUserOrg.getUserId() != null) { |
| | | String createUserOrgCode = ""; |
| | | List<SysOrganization> userOrgData = sysUser.getOrganizations(); |
| | | if (userOrgData != null) { |
| | | if (userOrgData.size() == 2) { |
| | | createUserOrgCode = userOrgData.get(1).getOrgCode(); |
| | | } |
| | | } |
| | | if (!createUserOrgCode.isEmpty()) { |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("user_id", sysUserOrg.getUserId()); |
| | | List<SysUserOrg> userOrgList = sysUserOrgService.getListByMap(map); |
| | | if (userOrgList.size() > 0) { |
| | | for (int i = 0; i < userOrgList.size(); i++) { |
| | | if (sysUserOrg.getId().equals(userOrgList.get(i).getId())) { |
| | | userOrgList.get(i).setOrgId(sysUserOrg.getOrgId()); |
| | | } |
| | | userOrgList.get(i).setEnabled(sysUserOrg.getEnabled()); |
| | | userOrgList.get(i).setCreateUserOrgCode(createUserOrgCode); |
| | | } |
| | | } else { |
| | | userOrgList = new ArrayList<>(); |
| | | //查出来的上级组织信息建立用户关系 |
| | | //借用字段承载数据 |
| | | SysOrganization sysOrganization = sysOrganizationService.getById(sysUserOrg.getUpdateUserId()); |
| | | if (sysOrganization != null) { |
| | | SysUserOrg sysUserOrgTemp = new SysUserOrg(); |
| | | sysUserOrgTemp.setOrgId(sysOrganization.getId()); |
| | | sysUserOrgTemp.setUserId(sysUserOrg.getUserId()); |
| | | sysUserOrgTemp.setEnabled(sysUserOrg.getEnabled()); |
| | | sysUserOrgTemp.setCreateUserOrgCode(createUserOrgCode); |
| | | userOrgList.add(sysUserOrgTemp); |
| | | |
| | | sysUserOrg.setUpdateUserId(0L); |
| | | sysUserOrg.setCreateUserOrgCode(createUserOrgCode); |
| | | userOrgList.add(sysUserOrg); |
| | | } else { |
| | | return ResultBody.failed().data(null).msg("该组织的上级组织数据异常!"); |
| | | } |
| | | } |
| | | boolean v = sysUserOrgService.saveOrUpdateBatch(userOrgList); |
| | | if (v) { |
| | | return ResultBody.ok().data(sysUserOrg).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().data(null).msg("数据保存失败!"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed().data(null).msg("该组织数据不完整!"); |
| | | } |
| | | } else { |
| | | return ResultBody.failed().data(null).msg("该组数据不完整!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |
| | | @ApiOperation(value = "删除") |
| | | @DeleteMapping("/{id}") |
| | | public ResultBody delete(@PathVariable Long id) { |
| | | sysUserOrgService.removeById(id); |
| | | return ResultBody.ok().msg("删除成功"); |
| | | } |
| | | |
| | | /** |
| | | * 查询 |
| | | */ |
| | | @ApiOperation(value = "查询") |
| | | @GetMapping("/{id}") |
| | | public ResultBody findById(@PathVariable Long id) { |
| | | SysUserOrg model = sysUserOrgService.getById(id); |
| | | return ResultBody.ok().data(model).msg("查询成功"); |
| | | } |
| | | } |
| | |
| | | package com.kidgrow.common.model; |
| | | |
| | | import com.kidgrow.common.model.SuperModel; |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.NoArgsConstructor; |
| | | import org.hibernate.validator.constraints.*; |
| | | import java.util.Date; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @version 1.0 |
| | | * @Description: 用户和组织关系表<br> |
| | | * @Project: 用户中心<br> |
| | | * @CreateDate: Created in 2020-03-31 11:01:35 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | * @version 1.0 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | |
| | | /** |
| | | * 用户id |
| | | */ |
| | | @NotBlank(message = "用户id不能为空") |
| | | @JsonSerialize(using = ToStringSerializer.class) |
| | | @NotNull(message = "用户id不能为空") |
| | | private Long userId; |
| | | /** |
| | | * 组织ID |
| | | */ |
| | | @NotBlank(message = "组织ID不能为空") |
| | | @JsonSerialize(using = ToStringSerializer.class) |
| | | @NotNull(message = "组织ID不能为空") |
| | | private Long orgId; |
| | | /** |
| | | * 数据权限code |
| | | */ |
| | | private String createUserOrgCode; |
| | | /** |
| | | * 状态,1启用,0停用 |
| | | */ |
| | | private Boolean enabled; |
| | |
| | | <script type="text/html" id="user-table-bar"> |
| | | <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a> |
| | | <a class="layui-btn layui-btn-xs" lay-event="reset">重置密码</a> |
| | | <a class="layui-btn layui-btn-xs" lay-event="org">分配组织</a> |
| | | <a class="layui-btn layui-btn-xs" lay-event="del">删除</a> |
| | | </script> |
| | | |
| | |
| | | headers:{'Authorization': 'Bearer ' + config.getToken().access_token}, |
| | | page: true, |
| | | cols: [[ |
| | | {type: 'numbers'}, |
| | | {field: 'id', sort: true, title: '用户编号'}, |
| | | {field: 'username', sort: true, title: '账号'}, |
| | | {field: 'nickname', sort: true, title: '用户名'}, |
| | | {field: 'mobile', sort: true, title: '手机号'}, |
| | | {sort: true, title: '性别',templet:function (d) { |
| | | return d.sex==0?"男":"女" |
| | | }}, |
| | | { field: 'id', sort: true, width: 200, title: '标识' }, |
| | | { field: 'username', sort: true, width: 100, title: '账号' }, |
| | | { field: 'nickname', sort: true, width: 200, title: '用户名' }, |
| | | { field: 'mobile', sort: true, width: 150, title: '手机号' }, |
| | | { |
| | | sort: true, templet: function (d) { |
| | | sort: true, title: '性别', templet: function (d) { |
| | | return d.sex == 0 ? "男" : "女" |
| | | }, width: 100 |
| | | }, |
| | | { |
| | | sort: true, width: 200, templet: function (d) { |
| | | return util.toDateString(d.createTime); |
| | | }, title: '创建时间' |
| | | }, |
| | | {field: 'enabled',width: 100, sort: true, templet: '#user-tpl-state', title: '状态'}, |
| | | {fixed: 'right', align: 'center', toolbar: '#user-table-bar', title: '操作', width: 195} |
| | | { fixed: 'right', align: 'center', toolbar: '#user-table-bar', title: '操作', width: 300 } |
| | | ]] |
| | | }); |
| | | |
| | |
| | | } |
| | | }, 'delete'); |
| | | }); |
| | | } else if (layEvent === "org") { |
| | | admin.putTempData('t_user', data); |
| | | admin.popupCenter({ |
| | | title: "分配组织", |
| | | path: 'pages/system/user_org_form.html', |
| | | finish: function () { |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | |
| | | |
| | | // 回显user数据 |
| | | var user = admin.getTempData('t_user'); |
| | | console.log(user); |
| | | $('#user-form').attr('method', 'POST'); |
| | | if (user) { |
| | | form.val('user-form', user); |
New file |
| | |
| | | <!-- user表单弹窗 --> |
| | | <form id="user-org-form" lay-filter="user-org-form" class="layui-form model-form"> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">账号</label> |
| | | <div class="layui-input-block"> |
| | | <input name="username" type="text" class="layui-input" maxlength="20" lay-verify="required" required |
| | | readonly /> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">用户名</label> |
| | | <div class="layui-input-block"> |
| | | <input name="nickname" type="text" class="layui-input" maxlength="20" lay-verify="required" required |
| | | readonly /> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">组织</label> |
| | | <div class="layui-input-block"> |
| | | <div id="org-tree" class="demo-tree demo-tree-box" style="max-height: 300px; overflow-y:scroll;"></div> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">选定组织</label> |
| | | <div class="layui-input-block"> |
| | | <input name="orgName" id="orgName" type="text" class="layui-input" maxlength="20" lay-verify="required" |
| | | required readonly /> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">状态</label> |
| | | <div class="layui-input-block"> |
| | | <input type="radio" name="enabled" value="0" title="启用" /> |
| | | <input type="radio" name="enabled" value="1" title="禁用" /> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item model-form-footer"> |
| | | <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button> |
| | | <button class="layui-btn" lay-filter="user-org-form-submit" lay-submit>保存</button> |
| | | </div> |
| | | <input name="id" id="id" type="hidden" /> |
| | | <input name="orgId" id="orgId" type="hidden" /> |
| | | <input name="userId" id="userId" type="hidden" /> |
| | | <input name="updateUserId" id="updateUserId" type="hidden" /> |
| | | </form> |
| | | |
| | | <script> |
| | | layui.use(['layer', 'admin', 'form', "tree", 'table', 'config', 'formSelects'], function () { |
| | | var table = layui.table; |
| | | var config = layui.config; |
| | | var layer = layui.layer; |
| | | var admin = layui.admin; |
| | | var form = layui.form; |
| | | var formSelects = layui.formSelects; |
| | | var tree = layui.tree; |
| | | |
| | | //$("input[name=enabled][value==0]").prop("checked", "true"); |
| | | // 回显user数据 |
| | | var user = admin.getTempData('t_user'); |
| | | $('#user-org-form').attr('method', 'POST'); |
| | | if (user) { |
| | | form.val('user-org-form', user); |
| | | $("#id").val(""); |
| | | $("#userId").val(user.id); |
| | | admin.req('api-user/sysuserorg', { user_id: user.id }, function (data) { |
| | | if (data.code == 0) { |
| | | debugger |
| | | if (data.data.length > 1) { |
| | | let useData = data.data[1]; |
| | | $("#orgId").val(useData.orgId); |
| | | $("#userId").val(useData.userId); |
| | | $("#id").val(useData.id); |
| | | if (useData.enabled) { |
| | | //$("input[name=enabled][value=0]").prop("checked", "true"); |
| | | //$("input[name=enabled][value=1]").prop("checked", "false"); |
| | | } |
| | | else { |
| | | //$("input[name=enabled][value=0]").prop("checked", "false"); |
| | | //$("input[name=enabled][value=1]").prop("checked", "true"); |
| | | } |
| | | admin.req('api-user/sysorganization/' + useData.orgId, {}, function (dataName) { |
| | | if (dataName.code == 0) { |
| | | if (dataName.data != null) { |
| | | $("#orgName").val(dataName.data.orgName); |
| | | } |
| | | else { |
| | | |
| | | layer.msg("当前组织数据获取失败!", { icon: 2, time: 1000 }); |
| | | } |
| | | } |
| | | else { |
| | | layer.msg(data.msg, { icon: 2, time: 1000 }); |
| | | } |
| | | }, 'get') |
| | | } |
| | | else { |
| | | $("#userId").val(user.id); |
| | | $("#id").val(""); |
| | | } |
| | | } |
| | | else { |
| | | layer.msg(data.msg, { icon: 2, time: 2000 }, function () { |
| | | admin.finishPopupCenter(); |
| | | }); |
| | | } |
| | | }, 'get'); |
| | | } |
| | | else { |
| | | layer.msg('数据异常,请重新打开!', { icon: 2, time: 2000 }, function () { |
| | | admin.finishPopupCenter(); |
| | | }); |
| | | } |
| | | |
| | | //组织结构树 |
| | | admin.req('api-user/sysorganization/getTree', { is_del: 0, enabled: 1 }, function (data) { |
| | | if (0 === data.code) { |
| | | tree({ |
| | | elem: "#org-tree", |
| | | nodes: data.data, |
| | | click: function (node) { |
| | | //将数据赋值 |
| | | if (node.level == 2) { |
| | | $("#orgId").val(node.id); |
| | | $("#orgName").val(node.name); |
| | | $("#updateUserId").val(node.parentId); |
| | | } |
| | | } |
| | | }); |
| | | } else { |
| | | layer.msg(data.msg, { icon: 2, time: 1000 }); |
| | | } |
| | | }, 'get'); |
| | | |
| | | // 表单提交事件 |
| | | form.on('submit(user-org-form-submit)', function (data) { |
| | | layer.load(2); |
| | | if (!strUtil.isEmpty($("#orgId").val())) { |
| | | if (data.field != null) { |
| | | data.field.enabled = (data.field.enabled == 0) ? fase : true; |
| | | admin.req('api-user/sysuserorg', JSON.stringify(data.field), function (data) { |
| | | layer.closeAll('loading'); |
| | | debugger |
| | | if (data.code == 0) { |
| | | layer.msg(data.msg, { icon: 1, time: 1000 }); |
| | | admin.finishPopupCenter(); |
| | | } else { |
| | | layer.msg(data.msg, { icon: 2, time: 1000 }); |
| | | } |
| | | }, "POST"); |
| | | } |
| | | else { |
| | | layer.msg("数据异常!", { icon: 2, time: 1000 }); |
| | | } |
| | | } |
| | | else { |
| | | layer.msg("请点击选择一个组织的部门节点!", { icon: 2, time: 1000 }); |
| | | } |
| | | |
| | | return false; |
| | | }); |
| | | }); |
| | | </script> |