作者 zhangFan

新增redis设置

... ... @@ -55,10 +55,10 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-thymeleaf</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
... ... @@ -196,282 +196,9 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!--IMF需要的包-->
<!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ws.commons.schema/XmlSchema -->
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.neethi/neethi -->
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>2.0.4</version>
</dependency>
<!-- LOG -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.cxf.xjcplugins/cxf-xjc-boolean -->
<dependency>
<groupId>org.apache.cxf.xjcplugins</groupId>
<artifactId>cxf-xjc-boolean</artifactId>
<version>3.2.3</version>
</dependency>
<!--添加本地IMF包-->
<dependency>
<groupId>com.caac</groupId>
<artifactId>imf</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/IMFClient.1.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>imfmessage</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/imfmsg.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>process</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProcessService.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>apiconfig</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/apiConfig.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>upload</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/UploadService.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>heartbeat</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/HeartbeatService.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>returnxml</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/returnXml.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hyperic/sigar -->
<dependency>
<groupId>org.hyperic</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sigar.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cxf</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>xjc</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-xjc-bug671-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>maven.org.apache</groupId>
<artifactId>cxf</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-manifest.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.cxf.xjc</groupId>
<artifactId>dv</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-xjc-dv-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.cxf.xjc</groupId>
<artifactId>ts</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-xjc-ts-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.xml</groupId>
<artifactId>xmlsec</artifactId>
<version>1.4.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xmlsec-1.4.4.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.disthub2.impl</groupId>
<artifactId>cl3e</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/CL3Export.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.disthub2.impl</groupId>
<artifactId>cl3ne</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/CL3Nonexport.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>axis2</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.axis2.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>commonservices</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.commonservices.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>defaultconfig</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.defaultconfig.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>fta</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.fta.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>headers</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.headers.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>jmqi</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.jmqi.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms.nojndi</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.jms.Nojndi.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>pcf</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.pcf.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>postcard</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.postcard.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>soap</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.soap.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>tools.ras</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.tools.ras.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>etclient</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mqetclient.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mqjms</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mqjms.jar</systemPath>
<!-- https://mvnrepository.com/artifact/javax.resource/connector -->
</dependency>
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/connector.jar</systemPath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
... ...
... ... @@ -6,16 +6,14 @@ package com.tianbo.warehouse;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableScheduling
//@EnableEurekaClient
@EnableEurekaClient
@EnableTransactionManagement
@MapperScan("com.tianbo.warehouse.dao")
public class WarehouseApplication {
... ...
package com.tianbo.warehouse.controller;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.SysDept;
import com.tianbo.warehouse.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author
* @time 2019-12-18 11:39
*/
@RestController
@RequestMapping("/dept")
public class DeptController {
@Autowired
SysDeptService sysDeptService;
@GetMapping("/list")
public ResultJson findAllDept(){
ResultJson resultJson = new ResultJson();
resultJson.setData(sysDeptService.findAllDept());
resultJson.setMsg("success");
resultJson.setCode("1");
return resultJson;
}
@PostMapping("/add")
public ResultJson addDept(@RequestBody SysDept sysDept){
ResultJson resultJson = new ResultJson();
int count = sysDeptService.insertSelective(sysDept);
if(count >0){
resultJson.setMsg("新增成功");
resultJson.setCode("1");
}else {
resultJson.setMsg("新增失败,请稍后重试");
resultJson.setCode("0");
}
return resultJson;
}
@PutMapping("/edit")
public ResultJson updateDept(@RequestBody SysDept sysDept){
ResultJson resultJson = new ResultJson();
int count = sysDeptService.updateByPrimaryKeySelective(sysDept);
if(count >0){
resultJson.setMsg("更新成功");
resultJson.setCode("1");
}else {
resultJson.setMsg("更新失败,请稍后重试");
resultJson.setCode("0");
}
return resultJson;
}
@DeleteMapping("/del")
public ResultJson updateDept(@RequestParam Integer id){
ResultJson resultJson = new ResultJson();
int count = sysDeptService.deleteByPrimaryKey(id);
if(count >0){
resultJson.setMsg("删除成功");
resultJson.setCode("1");
}else {
resultJson.setMsg("删除失败,请稍后重试");
resultJson.setCode("0");
}
return resultJson;
}
}
... ...
... ... @@ -3,20 +3,15 @@ package com.tianbo.warehouse.controller;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.dao.PERMISSIONMapper;
import com.tianbo.warehouse.model.PERMISSION;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
@RestController()
... ... @@ -94,4 +89,16 @@ public class PermssionController {
}
return resultJson;
}
@LogAnnotation(moduleName = "权限管理",operate = "权限批量删除")
@GetMapping("/findByRoleId")
public ResultJson findByRoleId(@RequestParam Integer roleId){
ResultJson resultJson = new ResultJson();
List<PERMISSION> list = permissionService.findByRoleId(roleId);
resultJson.setData(list);
resultJson.setCode("1");
resultJson.setMsg("SUCCESS");
return resultJson;
}
}
... ...
... ... @@ -20,6 +20,7 @@ public class RoleController {
@Autowired
RoleService roleService;
@GetMapping("/list")
public PageInfo<ROLE> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
... ...
... ... @@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/user")
... ... @@ -97,8 +99,12 @@ public class UserController {
}
@PutMapping("/roleset")
public ResultJson roleSet(@RequestBody UserRole userRole){
public ResultJson roleSet(@RequestBody Map<String,Object> map){
Integer id = (Integer) map.get("id");
List<Integer> roles = (List<Integer>) map.get("setRole");
UserRole userRole = new UserRole();
userRole.setUserId(id);
userRole.setRoleIds(roles);
int i = userService.setUserRole(userRole);
return i==1 ? new ResultJson("200","设置角色成功") :new ResultJson("500","设置角色失败");
... ...
... ... @@ -3,7 +3,6 @@ package com.tianbo.warehouse.dao;
import com.tianbo.warehouse.model.PERMISSION;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
public interface PERMISSIONMapper {
... ... @@ -25,6 +24,8 @@ public interface PERMISSIONMapper {
List<PERMISSION> findByUserId(Integer userId);
List<PERMISSION> findByRoleId(Integer roleId);
List<String> findRoleListByUrl(String permissionUrl);
List<PERMISSION> getRolePermisson(Integer roleId);
... ...
package com.tianbo.warehouse.dao;
import com.tianbo.warehouse.model.SysDept;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface SysDeptMapper {
int deleteByPrimaryKey(Integer id);
int insert(SysDept record);
int insertSelective(SysDept record);
SysDept selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SysDept record);
int updateByPrimaryKey(SysDept record);
List<SysDept> findAllDept();
}
... ...
package com.tianbo.warehouse.model;
import java.util.Date;
import java.util.List;
public class SysDept {
private Integer id;
private Integer pid;
private String deptname;
private String deptdesc;
private String depttype;
private Boolean isroot;
private String createby;
private Date createtime;
private String updateby;
private Date updatetme;
private Boolean isdelete;
private String remark;
private String remark1;
private List<SysDept> children;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public String getDeptname() {
return deptname;
}
public void setDeptname(String deptname) {
this.deptname = deptname == null ? null : deptname.trim();
}
public String getDeptdesc() {
return deptdesc;
}
public void setDeptdesc(String deptdesc) {
this.deptdesc = deptdesc == null ? null : deptdesc.trim();
}
public String getDepttype() {
return depttype;
}
public void setDepttype(String depttype) {
this.depttype = depttype == null ? null : depttype.trim();
}
public Boolean getIsroot() {
return isroot;
}
public void setIsroot(Boolean isroot) {
this.isroot = isroot;
}
public String getCreateby() {
return createby;
}
public void setCreateby(String createby) {
this.createby = createby == null ? null : createby.trim();
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public String getUpdateby() {
return updateby;
}
public void setUpdateby(String updateby) {
this.updateby = updateby == null ? null : updateby.trim();
}
public Date getUpdatetme() {
return updatetme;
}
public void setUpdatetme(Date updatetme) {
this.updatetme = updatetme;
}
public Boolean getIsdelete() {
return isdelete;
}
public void setIsdelete(Boolean isdelete) {
this.isdelete = isdelete;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public String getRemark1() {
return remark1;
}
public void setRemark1(String remark1) {
this.remark1 = remark1 == null ? null : remark1.trim();
}
public List<SysDept> getChildren() {
return children;
}
public void setChildren(List<SysDept> children) {
this.children = children;
}
}
... ...
... ... @@ -21,7 +21,8 @@ public class UserRole {
public UserRole(){
}
public UserRole(Integer userId,Integer roleId){
public UserRole(Integer id,Integer userId,Integer roleId){
this.id = id;
this.roleId=roleId;
this.userId = userId;
}
... ...
package com.tianbo.warehouse.security;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
/**
* @author
* @time 2019-12-18 15:25
*/
public class getUserNameForSecurity {
public static String getUserName(){
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof AnonymousAuthenticationToken)) {
String currentUserName = authentication.getName();
return currentUserName;
}
return null;
}
}
... ...
... ... @@ -10,6 +10,10 @@ public interface PermissionService {
PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name);
List<PERMISSION> findByRoleId(Integer roleId);
List<PERMISSION> getPermissionList(List<PERMISSION> permissions, Integer pid);
int insertSelective(PERMISSION record);
/**
... ...
package com.tianbo.warehouse.service;
import com.tianbo.warehouse.model.SysDept;
import java.util.List;
/**
* @author
* @time 2019-12-18 11:22
*/
public interface SysDeptService {
int deleteByPrimaryKey(Integer id);
int insertSelective(SysDept sysDept);
SysDept selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SysDept sysDept);
List<SysDept> findAllDept();
}
... ...
... ... @@ -5,42 +5,61 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.dao.PERMISSIONMapper;
import com.tianbo.warehouse.model.PERMISSION;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("PermissionService")
public class PermissionServiceImp implements PermissionService{
public class PermissionServiceImp implements PermissionService {
@Autowired
PERMISSIONMapper permissionMapper;
@Override
public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name){
Page<PERMISSION> page = PageHelper.startPage(pageNum,pageSize);
public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) {
Page<PERMISSION> page = PageHelper.startPage(pageNum, pageSize);
List<PERMISSION> list = permissionMapper.findAll(name);
PageInfo<PERMISSION> result = new PageInfo<>(list);
PageInfo<PERMISSION> result = new PageInfo<>(getPermissionList(list, 0));
return result;
}
public List<PERMISSION> findByRoleId(Integer roleId) {
List<PERMISSION> list = getPermissionList(permissionMapper.findByRoleId(roleId), 0);
return list;
}
@Override
public int insertSelective(PERMISSION record){
public int insertSelective(PERMISSION record) {
return permissionMapper.insertSelective(record);
}
public List<PERMISSION> getPermissionList(List<PERMISSION> permissions, Integer pid) {
List<PERMISSION> permissionList = new ArrayList<>();
for (PERMISSION permission : permissions) {
if (permission.getParentId().equals(pid)) {
permission.setChildren(getPermissionList(permissions, permission.getPermissionId()));
permissionList.add(permission);
}
}
return permissionList;
}
@Override
public Map<String,Object> getUserMenus(Integer userId){
Map<String,Object> data = new HashMap<String,Object>();
public Map<String, Object> getUserMenus(Integer userId) {
Map<String, Object> data = new HashMap<String, Object>();
try {
//查询所有菜单
List<PERMISSION> allMenu = permissionMapper.findByUserId(userId);
//根节点
List<PERMISSION> rootMenu = new ArrayList<PERMISSION>();
for (PERMISSION nav : allMenu) {
if(nav.getParentId()==0){//父节点是0的,为根节点。
if (nav.getParentId() == 0) {//父节点是0的,为根节点。
rootMenu.add(nav);
}
}
... ... @@ -69,17 +88,18 @@ public class PermissionServiceImp implements PermissionService{
/**
* 获取子节点
*
* @param id 父节点id
* @param allMenu 所有菜单列表
* @return 每个根节点下,所有子菜单列表
*/
public List<PERMISSION> getChild(Integer id,List<PERMISSION> allMenu){
public List<PERMISSION> getChild(Integer id, List<PERMISSION> allMenu) {
//子菜单
List<PERMISSION> childList = new ArrayList<PERMISSION>();
for (PERMISSION nav : allMenu) {
// 遍历所有节点,将所有菜单的父id与传过来的根节点的id比较
//相等说明:为该根节点的子节点。
if(nav.getParentId().equals(id)){
if (nav.getParentId().equals(id)) {
childList.add(nav);
}
}
... ... @@ -89,7 +109,7 @@ public class PermissionServiceImp implements PermissionService{
}
// Collections.sort(childList,order());//排序
//如果节点下没有子节点,返回一个空List(递归退出)
if(childList.size() == 0){
if (childList.size() == 0) {
return new ArrayList<PERMISSION>();
}
return childList;
... ... @@ -103,20 +123,19 @@ public class PermissionServiceImp implements PermissionService{
@Override
public int deleteByPrimaryKey(String permissionId) {
if (permissionId.contains(",")){
if (permissionId.contains(",")) {
try {
String[] split = permissionId.split(",");
for (int i=0; i<split.length; i++){
for (int i = 0; i < split.length; i++) {
permissionMapper.deleteByPrimaryKey(Integer.valueOf(split[i]));
}
System.out.println();
return 1;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}else {
} else {
return permissionMapper.deleteByPrimaryKey(Integer.valueOf(permissionId));
}
}
... ...
... ... @@ -9,14 +9,12 @@ import com.tianbo.warehouse.dao.RolePermissionMapper;
import com.tianbo.warehouse.model.Department;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.model.RolePermission;
import com.tianbo.warehouse.service.DepartmentService;
import com.tianbo.warehouse.service.PermissionService;
import com.tianbo.warehouse.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@Service(value = "roleService")
... ... @@ -31,12 +29,17 @@ public class RoleServiceImp implements RoleService{
@Autowired
DepartmentMapper departmentMapper;
@Autowired
PermissionService permissionService;
@Override
public PageInfo<ROLE> findAll(int pageNum, int pageSize, String roleName){
Page<ROLE> page = PageHelper.startPage(pageNum,pageSize);
List<ROLE> list = roleMapper.findAll(roleName);
for (ROLE role: list){
if(role.getPermissions().size()>1){
role.setPermissions(permissionService.getPermissionList(role.getPermissions(),0));
}
Department department = departmentMapper.selectByPrimaryKey(role.getDepartmentId());
if (department == null){
role.setDepartmentName("无");
... ...
package com.tianbo.warehouse.service.imp;
import com.tianbo.warehouse.dao.SysDeptMapper;
import com.tianbo.warehouse.model.SysDept;
import com.tianbo.warehouse.security.getUserNameForSecurity;
import com.tianbo.warehouse.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author
* @time 2019-12-18 11:41
*/
@Service
public class SysDeptServiceImpl implements SysDeptService {
@Autowired
SysDeptMapper sysDeptMapper;
@Override
@Transactional
public int deleteByPrimaryKey(Integer id) {
return sysDeptMapper.deleteByPrimaryKey(id);
}
@Override
@Transactional
public int insertSelective(SysDept sysDept) {
sysDept.setUpdatetme(new Date());
sysDept.setUpdateby(getUserNameForSecurity.getUserName());
sysDept.setCreatetime(new Date());
sysDept.setCreateby(getUserNameForSecurity.getUserName());
return sysDeptMapper.insertSelective(sysDept);
}
@Override
public SysDept selectByPrimaryKey(Integer id) {
return sysDeptMapper.selectByPrimaryKey(id);
}
@Override
@Transactional
public int updateByPrimaryKeySelective(SysDept sysDept) {
sysDept.setUpdatetme(new Date());
sysDept.setCreateby(getUserNameForSecurity.getUserName());
return sysDeptMapper.updateByPrimaryKeySelective(sysDept);
}
@Override
public List<SysDept> findAllDept() {
return childrenDept(sysDeptMapper.findAllDept(),0);
}
/**
* 获取组织机构树形结构列表
* @param list
* @param pid
* @return
*/
public List<SysDept> childrenDept(List<SysDept> list,Integer pid){
List<SysDept> childrenList = new ArrayList<>();
if (list !=null && !list.isEmpty()){
for (SysDept dept: list) {
if(dept.getPid().equals(pid)){
dept.setChildren(childrenDept(list,dept.getId()));
childrenList.add(dept);
}
}
}
return childrenList;
}
}
... ...
... ... @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Random;
@Service(value = "userService")
public class UserServiceImpl implements UserService{
... ... @@ -63,10 +64,13 @@ public class UserServiceImpl implements UserService{
users.setRealname(realName);
List<USERS> list = usersMapper.selectAllUser(users);
for (USERS user: list) {
List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId());
user.setPermissions(permissionList);
// List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId());
// user.setPermissions(permissionList);
List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId());
user.setRoles(roleList);
if(user.getUserId() == 27){
System.out.println(users.getRoles());
}
}
PageInfo<USERS> result = new PageInfo<USERS>(list);
return result;
... ... @@ -115,7 +119,7 @@ public class UserServiceImpl implements UserService{
userRoleMapper.deleteByUserId(userId);
if (null!=ids && !ids.isEmpty()){
for (Integer id:ids) {
UserRole ur = new UserRole(userId,id);
UserRole ur = new UserRole(new Random().nextInt(10000000)+1,userId,id);
userRoleMapper.insertSelective(ur);
}
}
... ...
... ... @@ -35,12 +35,12 @@
ORDER BY permission_order
</select>
<select id="getRolePermisson" resultMap="BaseResultMap" parameterType="java.lang.Integer">
SELECT P.*
FROM role R
LEFT JOIN role_permission RP ON R.role_id = RP.role_id
LEFT JOIN permission P ON RP.permission_id = P.permission_id
WHERE R.role_id=#{roleId,jdbcType=INTEGER}
ORDER BY P.ismenu,P.name,P.permission_order DESC
select p.*
from permission p
left join role_permission rp on rp.permission_id = p.permission_id
left join role r on r.role_id = rp.role_id
where r.role_id=#{roleId,jdbcType=INTEGER} and r.role_id is not null
ORDER BY p.ismenu,p.name,p.permission_order DESC
</select>
<select id="getAllMenus" resultMap="BaseResultMap" >
SELECT
... ... @@ -112,6 +112,21 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order
)
) ORDER BY permission_order
</select>
<select id="findByRoleId" resultMap="BaseResultMap" parameterType="integer">
SELECT
P.*
FROM
permission P
WHERE
P.permission_id IN (
SELECT
RP.permission_id
FROM
role_permission RP
WHERE
RP.role_id= #{roleId,jdbcType=INTEGER})
ORDER BY permission_order
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from permission
where permission_id = #{permissionId,jdbcType=INTEGER}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tianbo.warehouse.dao.SysDeptMapper">
<resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.SysDept">
<id column="ID" jdbcType="INTEGER" property="id" />
<result column="PID" jdbcType="INTEGER" property="pid" />
<result column="DEPTNAME" jdbcType="VARCHAR" property="deptname" />
<result column="DEPTDESC" jdbcType="VARCHAR" property="deptdesc" />
<result column="DEPTTYPE" jdbcType="VARCHAR" property="depttype" />
<result column="ISROOT" jdbcType="BIT" property="isroot" />
<result column="CREATEBY" jdbcType="VARCHAR" property="createby" />
<result column="CREATETIME" jdbcType="TIMESTAMP" property="createtime" />
<result column="UPDATEBY" jdbcType="VARCHAR" property="updateby" />
<result column="UPDATETME" jdbcType="TIMESTAMP" property="updatetme" />
<result column="ISDELETE" jdbcType="BIT" property="isdelete" />
<result column="REMARK" jdbcType="VARCHAR" property="remark" />
<result column="REMARK1" jdbcType="VARCHAR" property="remark1" />
</resultMap>
<sql id="Base_Column_List">
ID, PID, DEPTNAME, DEPTDESC, DEPTTYPE, ISROOT, CREATEBY, CREATETIME, UPDATEBY, UPDATETME,
ISDELETE, REMARK, REMARK1
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_dept
where ID = #{id,jdbcType=INTEGER}
</select>
<select id="findAllDept" resultMap="BaseResultMap">
select <include refid="Base_Column_List"></include>
from sys_dept where ISDELETE = 0
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from sys_dept
where ID = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.SysDept">
insert into sys_dept (ID, PID, DEPTNAME,
DEPTDESC, DEPTTYPE, ISROOT,
CREATEBY, CREATETIME, UPDATEBY,
UPDATETME, ISDELETE, REMARK,
REMARK1)
values (#{id,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER}, #{deptname,jdbcType=VARCHAR},
#{deptdesc,jdbcType=VARCHAR}, #{depttype,jdbcType=VARCHAR}, #{isroot,jdbcType=BIT},
#{createby,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{updateby,jdbcType=VARCHAR},
#{updatetme,jdbcType=TIMESTAMP}, #{isdelete,jdbcType=BIT}, #{remark,jdbcType=VARCHAR},
#{remark1,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.SysDept">
insert into sys_dept
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
ID,
</if>
<if test="pid != null">
PID,
</if>
<if test="deptname != null">
DEPTNAME,
</if>
<if test="deptdesc != null">
DEPTDESC,
</if>
<if test="depttype != null">
DEPTTYPE,
</if>
<if test="isroot != null">
ISROOT,
</if>
<if test="createby != null">
CREATEBY,
</if>
<if test="createtime != null">
CREATETIME,
</if>
<if test="updateby != null">
UPDATEBY,
</if>
<if test="updatetme != null">
UPDATETME,
</if>
<if test="isdelete != null">
ISDELETE,
</if>
<if test="remark != null">
REMARK,
</if>
<if test="remark1 != null">
REMARK1,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="pid != null">
#{pid,jdbcType=INTEGER},
</if>
<if test="deptname != null">
#{deptname,jdbcType=VARCHAR},
</if>
<if test="deptdesc != null">
#{deptdesc,jdbcType=VARCHAR},
</if>
<if test="depttype != null">
#{depttype,jdbcType=VARCHAR},
</if>
<if test="isroot != null">
#{isroot,jdbcType=BIT},
</if>
<if test="createby != null">
#{createby,jdbcType=VARCHAR},
</if>
<if test="createtime != null">
#{createtime,jdbcType=TIMESTAMP},
</if>
<if test="updateby != null">
#{updateby,jdbcType=VARCHAR},
</if>
<if test="updatetme != null">
#{updatetme,jdbcType=TIMESTAMP},
</if>
<if test="isdelete != null">
#{isdelete,jdbcType=BIT},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="remark1 != null">
#{remark1,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.SysDept">
update sys_dept
<set>
<if test="pid != null">
PID = #{pid,jdbcType=INTEGER},
</if>
<if test="deptname != null">
DEPTNAME = #{deptname,jdbcType=VARCHAR},
</if>
<if test="deptdesc != null">
DEPTDESC = #{deptdesc,jdbcType=VARCHAR},
</if>
<if test="depttype != null">
DEPTTYPE = #{depttype,jdbcType=VARCHAR},
</if>
<if test="isroot != null">
ISROOT = #{isroot,jdbcType=BIT},
</if>
<if test="createby != null">
CREATEBY = #{createby,jdbcType=VARCHAR},
</if>
<if test="createtime != null">
CREATETIME = #{createtime,jdbcType=TIMESTAMP},
</if>
<if test="updateby != null">
UPDATEBY = #{updateby,jdbcType=VARCHAR},
</if>
<if test="updatetme != null">
UPDATETME = #{updatetme,jdbcType=TIMESTAMP},
</if>
<if test="isdelete != null">
ISDELETE = #{isdelete,jdbcType=BIT},
</if>
<if test="remark != null">
REMARK = #{remark,jdbcType=VARCHAR},
</if>
<if test="remark1 != null">
REMARK1 = #{remark1,jdbcType=VARCHAR},
</if>
</set>
where ID = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.SysDept">
update sys_dept
set PID = #{pid,jdbcType=INTEGER},
DEPTNAME = #{deptname,jdbcType=VARCHAR},
DEPTDESC = #{deptdesc,jdbcType=VARCHAR},
DEPTTYPE = #{depttype,jdbcType=VARCHAR},
ISROOT = #{isroot,jdbcType=BIT},
CREATEBY = #{createby,jdbcType=VARCHAR},
CREATETIME = #{createtime,jdbcType=TIMESTAMP},
UPDATEBY = #{updateby,jdbcType=VARCHAR},
UPDATETME = #{updatetme,jdbcType=TIMESTAMP},
ISDELETE = #{isdelete,jdbcType=BIT},
REMARK = #{remark,jdbcType=VARCHAR},
REMARK1 = #{remark1,jdbcType=VARCHAR}
where ID = #{id,jdbcType=INTEGER}
</update>
</mapper>
... ...
... ... @@ -24,14 +24,17 @@
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.UserRole" >
insert into user_role (user_id, role_id
insert into user_role (id,user_id, role_id
)
values (#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
values (#{id,jdbcType=INTEGER},#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.UserRole" >
insert into user_role
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="userId != null" >
user_id,
</if>
... ... @@ -40,6 +43,9 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="userId != null" >
#{userId,jdbcType=INTEGER},
</if>
... ...