作者 朱兆平

卡口用户登录验证OK

正在显示 31 个修改的文件 包含 786 行增加591 行删除
... ... @@ -23,7 +23,7 @@ spring:
static-locations: classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
application:
name: cloud-user-center
name: cloud-kako-user-center
redis:
# host: 127.0.0.1
host: 192.168.1.53
... ... @@ -57,7 +57,7 @@ spring:
#username=CGOETL
#password=1q2w3e4r
#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
url: jdbc:mysql://118.31.66.166:3306/statistics?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://118.31.66.166:3306/station?useUnicode=true&characterEncoding=utf8
username: 110
password: QAHqCJf2kFYCLirM
driver-class-name: com.mysql.cj.jdbc.Driver
... ...
... ... @@ -4,7 +4,7 @@
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="10 seconds">
<configuration scan="true" scanPeriod="60 seconds">
<!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
... ... @@ -25,7 +25,7 @@
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
<level>debug</level>
</filter>
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
... ... @@ -169,7 +169,7 @@
不能设置为INHERITED或者同义词NULL。默认是DEBUG
可以包含零个或多个元素,标识这个appender将会添加到这个logger。
-->
<logger name="com.tianbo.warehouse.dao" level="info" />
<logger name="com.tianbo.warehouse.dao" level="debug" />
<!--开发环境:打印控制台-->
<springProfile name="dev">
<logger name="org.springframework.security" level="debug"/>
... ...
... ... @@ -21,6 +21,7 @@
<fastjson_version>1.2.28</fastjson_version>
<lombok_sersion>1.18.6</lombok_sersion>
<swagger2_version>2.9.2</swagger2_version>
<shiro.version>1.2.5</shiro.version>
</properties>
<dependencies>
... ... @@ -205,10 +206,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-zipkin</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>de.codecentric</groupId>
... ... @@ -220,6 +221,12 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 兼容卡口登录插件需要用shiro-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
... ...
... ... @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.annotation.RequestRequire;
import com.tianbo.warehouse.annotation.UserPasswordMd5;
import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheDelTarget;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.model.UserRole;
... ... @@ -74,6 +75,7 @@ public class UserController {
@LogAnnotation(moduleName = "用户管理",operate = "用户编辑")
@PutMapping("/edit")
public ResultJson updateUserById(@Validated(UpdateUser.class) @RequestBody USERS user){
user.setPassword(null);
int i = userService.updateByPrimaryKeySelective(user);
ResultJson resultJson = new ResultJson();
return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild");
... ... @@ -127,6 +129,7 @@ public class UserController {
* 刷新redis权限缓存
*/
@ApiOperation(value = "更新用户权限缓存", notes = "重新生成用户的信息到redis")
@RedisCacheDelTarget(cacheKey = "com.tianbo.warehouse.service.imp.PermissionServiceImp")
@PutMapping("/resetToken")
public ResultJson resetToken(HttpServletRequest request,HttpServletResponse respons) {
/**
... ...
package com.tianbo.warehouse.controller.staff;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.StaffApartmentComeCar;
import com.tianbo.warehouse.model.StaffApartmentMaintain;
import com.tianbo.warehouse.service.satff.ComeCarService;
import com.tianbo.warehouse.service.satff.MaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@RequestMapping("/come_car")
public class ComeCarController {
@Autowired
ComeCarService comeCarService;
@GetMapping("/list")
public PageInfo<StaffApartmentComeCar> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "cometovisitname", required = false)
String comeToVisitName){
return comeCarService.findAll(pageNum,pageSize,comeToVisitName);
}
@LogAnnotation(moduleName = "职工公寓人员,车辆来访登记",operate = "职工公寓人员,车辆来访登记添加")
@PostMapping("/add")
public ResultJson add(@RequestBody StaffApartmentComeCar staffApartmentComeCar){
int i =comeCarService.insertSelective(staffApartmentComeCar);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓人员,车辆来访登记",operate = "职工公寓人员,车辆来访登记修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid StaffApartmentComeCar staffApartmentComeCar){
int i =comeCarService.updateByPrimaryKeySelective(staffApartmentComeCar);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓人员,车辆来访登记",operate = "职工公寓人员,车辆来访登记删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody StaffApartmentComeCar staffApartmentComeCar, HttpServletRequest request, HttpServletResponse response){
int i =comeCarService.deleteByPrimaryKey(staffApartmentComeCar.getId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓人员,车辆来访登记",operate = "职工公寓人员,车辆来访登记删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (comeCarService.deleteByPrimaryKey(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
}
package com.tianbo.warehouse.controller.staff;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.StaffApartmentSpareKey;
import com.tianbo.warehouse.model.StaffSecurityInspection;
import com.tianbo.warehouse.service.satff.KeyService;
import com.tianbo.warehouse.service.satff.StaffSecurityInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@RequestMapping("/key")
public class KeyController {
@Autowired
KeyService keyService;
@GetMapping("/list")
public PageInfo<StaffApartmentSpareKey> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "staffname", required = false)
String staffname){
return keyService.findAll(pageNum,pageSize,staffname);
}
@LogAnnotation(moduleName = "职工公寓备用钥匙使用记录管理",operate = "职工公寓备用钥匙使用记录添加")
@PostMapping("/add")
public ResultJson add(@RequestBody StaffApartmentSpareKey staffApartmentSpareKey){
int i =keyService.insertSelective(staffApartmentSpareKey);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓备用钥匙使用记录管理",operate = "职工公寓备用钥匙使用记录修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid StaffApartmentSpareKey staffApartmentSpareKey){
int i =keyService.updateByPrimaryKeySelective(staffApartmentSpareKey);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓备用钥匙使用记录管理",operate = "职工公寓备用钥匙使用记录删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody StaffApartmentSpareKey staffApartmentSpareKey, HttpServletRequest request, HttpServletResponse response){
int i =keyService.deleteByPrimaryKey(staffApartmentSpareKey.getId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓备用钥匙使用记录管理",operate = "职工公寓备用钥匙使用记录删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (keyService.deleteByPrimaryKey(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
}
package com.tianbo.warehouse.controller.staff;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.StaffApartmentMaintain;
import com.tianbo.warehouse.model.StaffApartmentSpareKey;
import com.tianbo.warehouse.service.satff.KeyService;
import com.tianbo.warehouse.service.satff.MaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@RequestMapping("/maintain")
public class MaintainController {
@Autowired
MaintainService maintainService;
@GetMapping("/list")
public PageInfo<StaffApartmentMaintain> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "repairsname", required = false)
String repairsname){
return maintainService.findAll(pageNum,pageSize,repairsname);
}
@LogAnnotation(moduleName = "职工公寓设施设备维修记录管理",operate = "职工公寓设施设备维修记录添加")
@PostMapping("/add")
public ResultJson add(@RequestBody StaffApartmentMaintain staffApartmentMaintain){
int i =maintainService.insertSelective(staffApartmentMaintain);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓设施设备维修记录管理",operate = "职工公寓设施设备维修记录修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid StaffApartmentMaintain staffApartmentMaintain){
int i =maintainService.updateByPrimaryKeySelective(staffApartmentMaintain);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓设施设备维修记录管理",operate = "职工公寓设施设备维修记录删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody StaffApartmentMaintain staffApartmentMaintain, HttpServletRequest request, HttpServletResponse response){
int i =maintainService.deleteByPrimaryKey(staffApartmentMaintain.getId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓设施设备维修记录管理",operate = "职工公寓设施设备维修记录删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (maintainService.deleteByPrimaryKey(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
}
package com.tianbo.warehouse.controller.staff;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.StaffApartmentMaintain;
import com.tianbo.warehouse.model.StaffApartmentOnduty;
import com.tianbo.warehouse.service.satff.MaintainService;
import com.tianbo.warehouse.service.satff.OnDutyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@RequestMapping("/on_duty")
public class OnDutyController {
@Autowired
OnDutyService onDutyService;
@GetMapping("/list")
public PageInfo<StaffApartmentOnduty> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "warchkeeper", required = false)
String warchkeeper){
return onDutyService.findAll(pageNum,pageSize,warchkeeper);
}
@LogAnnotation(moduleName = "职工公寓值班巡视管理",operate = "职工公寓值班巡视添加")
@PostMapping("/add")
public ResultJson add(@RequestBody StaffApartmentOnduty staffApartmentOnduty){
int i =onDutyService.insertSelective(staffApartmentOnduty);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓值班巡视管理",operate = "职工公寓值班巡视修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid StaffApartmentOnduty staffApartmentOnduty){
int i =onDutyService.updateByPrimaryKeySelective(staffApartmentOnduty);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓值班巡视管理",operate = "职工公寓值班巡视删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody StaffApartmentOnduty staffApartmentOnduty, HttpServletRequest request, HttpServletResponse response){
int i =onDutyService.deleteByPrimaryKey(staffApartmentOnduty.getId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓值班巡视管理",operate = "职工公寓值班巡视删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (onDutyService.deleteByPrimaryKey(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
}
package com.tianbo.warehouse.controller.staff;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.StaffSecurityInspection;
import com.tianbo.warehouse.service.satff.StaffSecurityInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@RequestMapping("/inspection")
public class StaffSecurityInspectionController {
@Autowired
StaffSecurityInspectionService staffSecurityInspectionService;
@GetMapping("/list")
public PageInfo<StaffSecurityInspection> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "securityInspectionName", required = false)
String securityInspectionName){
return staffSecurityInspectionService.findAll(pageNum,pageSize,securityInspectionName);
}
@LogAnnotation(moduleName = "职工公寓安全巡视管理",operate = "职工公寓安全巡视添加")
@PostMapping("/add")
public ResultJson add(@RequestBody StaffSecurityInspection staffSecurityInspection){
int i =staffSecurityInspectionService.insertSelective(staffSecurityInspection);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓安全巡视管理",operate = "职工公寓安全巡视修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid StaffSecurityInspection staffSecurityInspection){
int i =staffSecurityInspectionService.updateByPrimaryKeySelective(staffSecurityInspection);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓安全巡视管理",operate = "职工公寓安全巡视删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody StaffSecurityInspection staffSecurityInspection, HttpServletRequest request, HttpServletResponse response){
int i =staffSecurityInspectionService.deleteByPrimaryKey(staffSecurityInspection.getSecurityInspectionId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "职工公寓安全巡视管理",operate = "职工公寓安全巡视删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (staffSecurityInspectionService.deleteByPrimaryKey(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
}
package com.tianbo.warehouse.controller.water;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.Company;
import com.tianbo.warehouse.model.WaterStationsPatrol;
import com.tianbo.warehouse.service.CompanyService;
import com.tianbo.warehouse.service.water.WaterStationsPatrolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@RequestMapping("/water_stations_patrol")
public class WaterStationsPatrolController {
@Autowired
WaterStationsPatrolService waterStationsPatrolService;
@GetMapping("/list")
public PageInfo<WaterStationsPatrol> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize){
return waterStationsPatrolService.findAll(pageNum,pageSize);
}
@LogAnnotation(moduleName = "二水厂-水站巡视记录单管理",operate = "二水厂-水站巡视记录单管理添加")
@PostMapping("/add")
public ResultJson add(@RequestBody WaterStationsPatrol waterStationsPatrol){
int i =waterStationsPatrolService.insertSelective(waterStationsPatrol);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "二水厂-水站巡视记录单管理",operate = "二水厂-水站巡视记录单管理修改")
@PutMapping("/edit")
@ResponseBody
public ResultJson edit(@RequestBody @Valid WaterStationsPatrol waterStationsPatrol){
int i =waterStationsPatrolService.updateByPrimaryKeySelective(waterStationsPatrol);
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","修改成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "二水厂-水站巡视记录单管理",operate = "二水厂-水站巡视记录单管理删除")
@DeleteMapping("/del")
public ResultJson reomve(@RequestBody WaterStationsPatrol waterStationsPatrol, HttpServletRequest request, HttpServletResponse response){
int i =waterStationsPatrolService.deleteByPrimaryKey(waterStationsPatrol.getId());
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
@LogAnnotation(moduleName = "二水厂-水站巡视记录单管理",operate = "二水厂-水站巡视记录单管理批量删除")
@GetMapping("/batchremove")
public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){
ResultJson resultJson = new ResultJson();
if (waterStationsPatrolService.deleteByPrimaryKey(ids)>0){
resultJson = new ResultJson("200","删除成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
}
... ... @@ -26,6 +26,8 @@ public interface PERMISSIONMapper {
List<PERMISSION> findByUserId(Integer userId);
List<PERMISSION> findByUserIdKako(String userId);
/**
* 登录验证成功后获取用户权限列表非树形结构
* @param userId
... ... @@ -33,6 +35,8 @@ public interface PERMISSIONMapper {
*/
List<PERMISSION> findByUserIdWithLogin(Integer userId);
List<PERMISSION> findByUserIdWithLoginKako(String userId);
List<PERMISSION> findByRoleId(Integer roleId);
List<String> findRoleListByUrl(String permissionUrl);
... ...
... ... @@ -16,6 +16,8 @@ public interface ROLEMapper {
List<ROLE> findRolesByUserId(Integer userId);
List<ROLE> findRolesByUserIdKako(String userId);
List<ROLE> selectByParentId(Integer roleId);
List<ROLE> findAll(@Param("roleName") String roleName,
... ...
... ... @@ -65,8 +65,8 @@ public class PERMISSION implements Serializable {
return ismenu;
}
public void setIsmenu(String ismenu) {
this.ismenu = "0".equals(ismenu)?false:true ;
public void setIsmenu(Boolean ismenu) {
this.ismenu = ismenu ;
}
public Integer getParentId() {
... ...
... ... @@ -24,7 +24,7 @@ public class USERS implements UserDetails {
private Integer userId;
@NotBlank(message="用户名不能为空",groups={InsertUser.class, UpdateUser.class})
@Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间",groups={InsertUser.class, UpdateUser.class})
@Length(min = 4, max = 11, message = "username 长度必须在 {min} - {max} 之间",groups={InsertUser.class, UpdateUser.class})
@CheckUserExist(message = "用户已存在",groups=InsertUser.class)
private String username;
... ...
... ... @@ -11,7 +11,6 @@ public class UserRole {
@DecimalMin("1")
private Integer id;
@DecimalMin("1")
private Integer userId;
@DecimalMin("1")
... ...
package com.tianbo.warehouse.security.config;
import com.netflix.discovery.converters.Auto;
import com.tianbo.warehouse.security.CustomUserDetailService;
import com.tianbo.warehouse.security.filter.JwtAuthenticationTokenFilter;
import com.tianbo.warehouse.security.handel.*;
import com.tianbo.warehouse.security.MyFilterSecurityInterceptor;
import com.tianbo.warehouse.security.handel.kakologin.MyKakoAuthenticationSuccessHandler;
import com.tianbo.warehouse.security.handel.kakologin.MyLoginAuthenticationProcessFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
... ... @@ -37,7 +35,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private PasswordEncoder passwordEncoder;
@Autowired
private MyAuthenticationSuccessHandler successHandler;
private MyKakoAuthenticationSuccessHandler successHandler;
@Autowired
private MyAuthenticationFailHandler failHandler;
... ... @@ -58,6 +56,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
private final MyLoginAuthenticationProcessFilter adminAuthenticationProcessingFilter;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//user Details Service验证
... ... @@ -66,6 +66,16 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
auth.eraseCredentials(false);
}
/**
* 用户密码校验过滤器
*/
public WebSecurityConfig(MyLoginAuthenticationProcessFilter adminAuthenticationProcessingFilter) {
this.adminAuthenticationProcessingFilter = adminAuthenticationProcessingFilter;
}
/**
* 在configure(HttpSecurity http)方法中,
* 通过withObjectPostProcessor将刚刚创建的UrlFilterInvocationSecurityMetadataSource和UrlAccessDecisionManager注入进来。
... ... @@ -130,6 +140,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//关闭session
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// 自定义过滤器认证用户名密码
http.addFilterAt(adminAuthenticationProcessingFilter, UsernamePasswordAuthenticationFilter.class);
//session管理
//session失效后跳转
... ...
/**
* Copyright (c) 2005-2012 springside.org.cn
*/
package com.tianbo.warehouse.security.handel.kakologin;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import java.io.UnsupportedEncodingException;
/**
* 封装各种格式的编码解码工具类.
* 1.Commons-Codec的 hex/base64 编码
* 2.自制的base62 编码
* 3.Commons-Lang的xml/html escape
* 4.JDK提供的URLEncoder
* @author calvin
* @version 2013-01-15
*/
public class Encodes {
private static final String DEFAULT_URL_ENCODING = "UTF-8";
private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
/**
* Hex编码.
*/
public static String encodeHex(byte[] input) {
return new String(Hex.encodeHex(input));
}
/**
* Hex解码.
*/
public static byte[] decodeHex(String input) {
try {
return Hex.decodeHex(input.toCharArray());
} catch (DecoderException e) {
throw Exceptions.unchecked(e);
}
}
/**
* Base64编码.
*/
public static String encodeBase64(byte[] input) {
return new String(Base64.encodeBase64(input));
}
/**
* Base64编码.
*/
public static String encodeBase64(String input) {
try {
return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
} catch (UnsupportedEncodingException e) {
return "";
}
}
// /**
// * Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548).
// */
// public static String encodeUrlSafeBase64(byte[] input) {
// return Base64.encodeBase64URLSafe(input);
// }
/**
* Base64解码.
*/
public static byte[] decodeBase64(String input) {
return Base64.decodeBase64(input.getBytes());
}
/**
* Base64解码.
*/
public static String decodeBase64String(String input) {
try {
return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
} catch (UnsupportedEncodingException e) {
return "";
}
}
/**
* Base62编码。
*/
public static String encodeBase62(byte[] input) {
char[] chars = new char[input.length];
for (int i = 0; i < input.length; i++) {
chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)];
}
return new String(chars);
}
}
... ...
/**
* Copyright (c) 2005-2012 springside.org.cn
*/
package com.tianbo.warehouse.security.handel.kakologin;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* 关于异常的工具类.
* @author calvin
* @version 2013-01-15
*/
public class Exceptions {
/**
* 将CheckedException转换为UncheckedException.
*/
public static RuntimeException unchecked(Exception e) {
if (e instanceof RuntimeException) {
return (RuntimeException) e;
} else {
return new RuntimeException(e);
}
}
/**
* 将ErrorStack转化为String.
*/
public static String getStackTraceAsString(Throwable e) {
if (e == null){
return "";
}
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
/**
* 判断异常是否由某些底层的异常引起.
*/
public static boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
Throwable cause = ex.getCause();
while (cause != null) {
for (Class<? extends Exception> causeClass : causeExceptionClasses) {
if (causeClass.isInstance(cause)) {
return true;
}
}
cause = cause.getCause();
}
return false;
}
/**
* 在request中获取异常类
* @param request
* @return
*/
public static Throwable getThrowable(HttpServletRequest request){
Throwable ex = null;
if (request.getAttribute("exception") != null) {
ex = (Throwable) request.getAttribute("exception");
} else if (request.getAttribute("javax.servlet.error.exception") != null) {
ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
}
return ex;
}
}
... ...
package com.tianbo.warehouse.security.handel.kakologin;
import com.tianbo.warehouse.model.KakoUser;
import com.tianbo.warehouse.service.kakoImp.KakoUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class KakoUserDetailService implements UserDetailsService {
@Autowired
private KakoUserService userService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserDetails user = userService.loadByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("用户名不存在");
// throw new BadCredentialsException("用户名不存在");
}
return user;
}
}
... ...
package com.tianbo.warehouse.security.handel.kakologin;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.ProviderNotFoundException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 自定义认证管理器
*/
@Component
public class MyAuthenticationManager implements AuthenticationManager {
private final MyLoginAuthenticationProvider adminAuthenticationProvider;
public MyAuthenticationManager(MyLoginAuthenticationProvider adminAuthenticationProvider) {
this.adminAuthenticationProvider = adminAuthenticationProvider;
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Authentication result = adminAuthenticationProvider.authenticate(authentication);
if (Objects.nonNull(result)) {
return result;
}
throw new ProviderNotFoundException("Authentication failed!");
}
}
... ...
package com.tianbo.warehouse.security.handel.kakologin;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tianbo.warehouse.bean.AuthSuccessResponse;
import com.tianbo.warehouse.model.KakoUser;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.security.config.SecurityProperties;
import com.tianbo.warehouse.security.filter.JwtTokenUtil;
import com.tianbo.warehouse.security.model.LoginType;
import com.tianbo.warehouse.service.PermissionService;
import com.tianbo.warehouse.util.RedisUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.SavedRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
* 登录成功后的返回处理
*/
@Component
public class MyKakoAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler{
protected final Log logger = LogFactory.getLog(this.getClass());
@Value("${jwt.max-alive}")
protected Integer jwtMaxAlive;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private PermissionService permissionService;
private RequestCache requestCache = new HttpSessionRequestCache();
@Autowired
private SecurityProperties securityProperties;
@Autowired
RedisUtils redisUtils;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
logger.info("登录成功");
if (LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){
//将 authention 信息打包成json格式返回
response.setContentType("application/json;charset=UTF-8");
// response.setHeader("Access-Control-Allow-Origin","*");
KakoUser user = (KakoUser) authentication.getPrincipal();
//返回前端登陆成功后的用户信息
KakoUser loginedUser = new KakoUser();
loginedUser.setLoginName(user.getUsername());
loginedUser.setId(user.getId());
loginedUser.setName(user.getName());
//设置用户的TOKEN的有效时间,时间配置在配置文件中设置
String jwtToken = JwtTokenUtil.generateToken(loginedUser.getUsername(), jwtMaxAlive);
loginedUser.setToken(jwtToken);
//这里将登录成功的[user]对象数据写入redis缓存,KEY为token value为user的JSON对象
String json = JSON.toJSONString(user);
redisUtils.set(jwtToken, json,3600*24*7);
Map<String,Object> menuMap = permissionService.getUserMenusKako(user.getId());
//返回用户信息和用户可访问的目录列表
response.getWriter().write(objectMapper.writeValueAsString(new AuthSuccessResponse(loginedUser,menuMap)));
}else {
//走原来的处理流程
SavedRequest savedRequest = this.requestCache.getRequest(request, response);
if (savedRequest == null) {
super.onAuthenticationSuccess(request, response, authentication);
} else {
String targetUrlParameter = this.getTargetUrlParameter();
if (!this.isAlwaysUseDefaultTargetUrl() && (targetUrlParameter == null || !StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
this.clearAuthenticationAttributes(request);
String targetUrl = savedRequest.getRedirectUrl();
this.logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
this.getRedirectStrategy().sendRedirect(request, response, targetUrl);
} else {
this.requestCache.removeRequest(request, response);
super.onAuthenticationSuccess(request, response, authentication);
}
}
}
}
}
... ...
package com.tianbo.warehouse.security.handel.kakologin;
import com.tianbo.warehouse.security.handel.MyAuthenticationFailHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 用户登录自定义校验过滤器
*/
@Slf4j
@Component
public class MyLoginAuthenticationProcessFilter extends AbstractAuthenticationProcessingFilter {
/**
* @param authenticationManager: 认证管理器
* @param adminAuthenticationSuccessHandler: 认证成功处理
* @param adminAuthenticationFailureHandler: 认证失败处理
*/
public MyLoginAuthenticationProcessFilter(MyAuthenticationManager authenticationManager, MyKakoAuthenticationSuccessHandler adminAuthenticationSuccessHandler, MyAuthenticationFailHandler adminAuthenticationFailureHandler) {
super(new AntPathRequestMatcher("/login", "POST"));
this.setAuthenticationManager(authenticationManager);
this.setAuthenticationSuccessHandler(adminAuthenticationSuccessHandler);
this.setAuthenticationFailureHandler(adminAuthenticationFailureHandler);
}
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
if (request.getContentType() == null || !request.getContentType().contains("application/x-www-form-urlencoded")) {
throw new AuthenticationServiceException("请求头类型不支持: " + request.getContentType());
}
UsernamePasswordAuthenticationToken authRequest;
try {
String loginUserName = request.getParameter("username");
String loginUserPass = request.getParameter("password");
authRequest = new UsernamePasswordAuthenticationToken(loginUserName,loginUserPass, null);
authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
} catch (Exception e) {
throw new AuthenticationServiceException(e.getMessage());
}
return this.getAuthenticationManager().authenticate(authRequest);
}
}
... ...
package com.tianbo.warehouse.security.handel.kakologin;
import com.tianbo.warehouse.dao.KakoUserMapper;
import com.tianbo.warehouse.model.KakoUser;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.security.CustomUserDetailService;
import com.tianbo.warehouse.service.UserService;
import com.tianbo.warehouse.util.RedisUtils;
import org.apache.shiro.codec.CodecException;
import org.apache.shiro.crypto.hash.Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.shiro.codec.CodecSupport;
import javax.annotation.Resource;
/**
* 自定义认证处理类
*/
@Component
public class MyLoginAuthenticationProvider extends CodecSupport implements AuthenticationProvider {
@Autowired
private KakoUserDetailService userDetailsService;
@Resource
private KakoUserMapper userMapper;
@Autowired
private RedisUtils redisUtils;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
// 获取前端表单中输入后返回的用户名、密码
String userName = (String) authentication.getPrincipal();
String password = (String) authentication.getCredentials();
UserDetails userInfo = userDetailsService.loadUserByUsername(userName);
//验证登录密码是否符合规则,如位数包含的字符等
boolean isValid = PasswordSaltUtils.isValidPassword(password, userInfo.getPassword(), "");
// 验证密码
if (!isValid) {
//todo: 登录次数超了 锁定账户
throw new BadCredentialsException("密码错误!");
}
if(!userInfo.isEnabled()){
throw new DisabledException("用户被禁用");
}
//取盐规则
byte[] salt = PasswordSaltUtils.getSalt16(userInfo.getPassword());
//真实密码
String realPass = PasswordSaltUtils.getPassword16(userInfo.getPassword());
//用户登录密码与盐运算
Object tokenHashedCredentials = this.hashProvidedCredentials(password,salt,1024);
try{
String loginUserLock = redisUtils.get(userName+"-lock");
Integer loginUserLockNO= 0;
if (loginUserLock!=null){
loginUserLockNO = Integer.valueOf(loginUserLock);
}
//判断密码是否正确
if(!equals(realPass,tokenHashedCredentials.toString())){
redisUtils.set(userName+"-lock", String.valueOf(++loginUserLockNO),120);
//两分钟内错误登录次数超过5次锁定账户
if (loginUserLockNO>5){
KakoUser kakoUser = new KakoUser();
kakoUser.setLoginName(userName);
kakoUser.setLoginFlag("0");
userMapper.lockUser(kakoUser);
}
return null;
}
}catch (Exception e){
throw new BadCredentialsException("验证失败!");
}
// 前后端分离情况下 处理逻辑...
// 更新登录令牌 - 之后访问系统其它接口直接通过token认证用户权限...
return new UsernamePasswordAuthenticationToken(userInfo, password, userInfo.getAuthorities());
}
@Override
public boolean supports(Class<?> aClass) {
return true;
}
/**
* 根据用户密码生成秘文
* @param credentials 用户登录密码
* @param salt 盐
* @param hashIterations 1024
* @return
*/
protected Hash hashProvidedCredentials(Object credentials, Object salt, int hashIterations) {
String hashAlgorithmName = "SHA-1";
hashIterations = 1024;
return new SimpleHash(hashAlgorithmName, credentials, salt, hashIterations);
}
protected boolean equals(Object tokenCredentials, Object accountCredentials) {
if (this.isByteSource(tokenCredentials) && this.isByteSource(accountCredentials)) {
byte[] tokenBytes = this.toBytes(tokenCredentials);
byte[] accountBytes = this.toBytes(accountCredentials);
return Arrays.equals(tokenBytes, accountBytes);
} else {
return accountCredentials.equals(tokenCredentials);
}
}
}
... ...
package com.tianbo.warehouse.security.handel.kakologin;
import org.springframework.stereotype.Component;
@Component
public class PasswordSaltUtils {
/**
* 密码校验
* @return true密码校验通过 false 失败
*/
public static boolean isValidPassword(String LoginPassword, String UserPassword, String Salt){
return true;
}
/**
* 加密前端传递过来的密码
* @param Salt 盐
* @param SaltFromDB 数据库中保存的盐
* @return
*/
public static String encodePassword(String Salt,String SaltFromDB){
return null;
}
/**
* 解码存储到数据库中密码密文的前16位
* @param userPasswordInDB 数据库中用户的密码
* @return
*/
public static byte[] getSalt16(String userPasswordInDB){
byte[] salt = Encodes.decodeHex(userPasswordInDB.substring(0,16));
return salt;
}
/**
* 取存储到数据库中密码密文的后16位
* @param userPasswordInDB 数据库中用户的密码
* @return
*/
public static String getPassword16(String userPasswordInDB){
return userPasswordInDB.substring(16);
}
}
... ...
... ... @@ -23,6 +23,8 @@ public interface PermissionService {
*/
Map<String,Object> getUserMenus(Integer userId);
Map<String,Object> getUserMenusKako(String userId);
int updateByPrimaryKeySelective(PERMISSION permission);
... ... @@ -35,6 +37,8 @@ public interface PermissionService {
*/
List<PERMISSION> findByUserIdWithLogin(Integer userId);
List<PERMISSION> findByUserIdWithLoginKako(String userId);
/**
* 清理跟permission相关的所有缓存
*/
... ...
... ... @@ -69,6 +69,10 @@ public class PermissionServiceImp implements PermissionService {
return permissionMapper.findByUserIdWithLogin(userId);
}
@Override
public List<PERMISSION> findByUserIdWithLoginKako(String userId){
return permissionMapper.findByUserIdWithLoginKako(userId);
}
/**
* 返回用户权限的树形列表
* @param userId
... ... @@ -111,6 +115,43 @@ public class PermissionServiceImp implements PermissionService {
}
}
@Override
public Map<String, Object> getUserMenusKako(String userId) {
Map<String, Object> data = new HashMap<String, Object>();
try {
//查询所有菜单
List<PERMISSION> allMenu = permissionMapper.findByUserIdKako(userId);
// //根节点
// List<PERMISSION> rootMenu = new ArrayList<PERMISSION>();
// for (PERMISSION nav : allMenu) {
// if (nav.getParentId() == 0) {//父节点是0的,为根节点。
// rootMenu.add(nav);
// }
// }
/* 根据Menu类的order排序 */
// Collections.sort(rootMenu, order());
//为根菜单设置子菜单,getClild是递归调用的
// for (PERMISSION nav : rootMenu) {
// /* 获取根节点下的所有子节点 使用getChild方法*/
// List<PERMISSION> childList = getChild(nav.getPermissionId(), allMenu);
// nav.setChildren(childList);//给根节点设置子节点
// }
/**
* 输出构建好的菜单数据。
*
*/
data.put("success", "true");
data.put("list", allMenu);
return data;
} catch (Exception e) {
data.put("success", "false");
data.put("list", new ArrayList());
return data;
}
}
/**
* 获取子节点
*
... ...
package com.tianbo.warehouse.service.kakoImp;
import com.tianbo.warehouse.model.KakoUser;
import org.springframework.stereotype.Service;
import java.util.List;
public interface KakoUserService {
KakoUser loadByUsername(String username);
}
... ...
package com.tianbo.warehouse.service.kakoImp;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.dao.KakoUserMapper;
import com.tianbo.warehouse.dao.ROLEMapper;
import com.tianbo.warehouse.model.*;
import com.tianbo.warehouse.service.PermissionService;
import com.tianbo.warehouse.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class KakoUserServiceImpl implements KakoUserService{
@Resource
private KakoUserMapper kakoUserMapper;
@Autowired
private PermissionService permissionService;
@Resource
private ROLEMapper roleMapper;
@Override
public KakoUser loadByUsername(String username){
List<KakoUser> userList = kakoUserMapper.selectByUsername(username);
if (userList != null && userList.size() > 0) {
KakoUser user = userList.get(0);
List<PERMISSION> permissionList = permissionService.findByUserIdWithLoginKako(user.getId());
if (permissionList!=null && permissionList.size()>0){
user.setPermissions(permissionList);
}
List<ROLE> roleList = roleMapper.findRolesByUserIdKako(user.getId());
if (roleList!=null && roleList.size()>0){
user.setRoles(roleList);
}
return user;
}
return null;
}
}
... ...
... ... @@ -14,7 +14,7 @@
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://118.31.66.166:3306/statistics"
connectionURL="jdbc:mysql://118.31.66.166:3306/station"
userId="110"
password="QAHqCJf2kFYCLirM">
</jdbcConnection>
... ... @@ -45,6 +45,6 @@
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table tableName="role" domainObjectName="ROLE" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="sys_user" domainObjectName="KakoUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
\ No newline at end of file
... ...
... ... @@ -140,6 +140,37 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order
AND P.parent_id = 0
ORDER BY permission_order
</select>
<select id="findByUserIdKako" parameterType="java.lang.String" resultMap="treeResultMap">
SELECT
P.*
FROM
permission P
WHERE
P.permission_id IN (
SELECT
RP.permission_id
FROM
role_permission RP
WHERE
RP.role_id IN (
SELECT
R.role_id
FROM
role R
WHERE
R.role_id IN (
SELECT
UR.role_id
FROM
user_role UR
WHERE
UR.user_id = #{userId,jdbcType=VARCHAR}
)
)
)
AND P.parent_id = 0
ORDER BY permission_order
</select>
<select id="findByUserIdWithLogin" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT
P.*
... ... @@ -170,6 +201,36 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order
)
ORDER BY permission_order
</select>
<select id="findByUserIdWithLoginKako" parameterType="java.lang.String" resultMap="BaseResultMap">
SELECT
P.*
FROM
permission P
WHERE
P.permission_id IN (
SELECT
RP.permission_id
FROM
role_permission RP
WHERE
RP.role_id IN (
SELECT
R.role_id
FROM
role R
WHERE
R.role_id IN (
SELECT
UR.role_id
FROM
user_role UR
WHERE
UR.user_id = #{userId,jdbcType=VARCHAR}
)
)
)
ORDER BY permission_order
</select>
<select id="findByRoleId" resultMap="BaseResultMap" parameterType="integer">
SELECT
P.*
... ...
... ... @@ -192,4 +192,14 @@
LEFT JOIN role R ON R.role_id= UR.role_id
where U.user_id = #{userId,jdbcType=INTEGER}
</select>
<select id="findRolesByUserIdKako" parameterType="java.lang.String" resultMap="BaseResultMap">
SELECT
R.*
FROM
sys_user U
LEFT JOIN user_role UR ON U.id = UR.user_id
LEFT JOIN role R ON R.role_id= UR.role_id
where U.id = #{userId,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
... ...