merge
This commit is contained in:
@@ -111,6 +111,8 @@ TO_CHAR
|
||||
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
|
||||
SELECT TO_DATE('1992-9-1 23:22:11','RR-mm-dd hh24:mi:ss') FROM dual;
|
||||
SELECT TO_CHAR(TO_DATE('99-09-01','RR-MM-DD'),'YYYY-MM-DD') FROM DUAL;
|
||||
SELECT date_format(now(),'%Y-%m-%d %h:%i:%s');//mysql--------------------------------------
|
||||
SELECT str_to_date('2016-01-02 11:11:11','%Y-%m-%d %h:%i:%s');//mysql--------------------------------------
|
||||
|
||||
LAST_DAY(date) 该函数返回给定日期所在月的最后一天
|
||||
查看当月月底?
|
||||
@@ -169,5 +171,4 @@ SELECT ENAME,SAL,NVL2(BOUNS,'有奖金','无奖金') FROM EMP_XWBING;
|
||||
ISNULL(字段) true返回1
|
||||
IF(p1,p2,p3):如果p1是true,返回值为p2;否则返回值则为p3
|
||||
IF(ISNULL(p1),p2,p3) 若p1为null值为p2,p1不为null值为p3
|
||||
SELECT ENAME,SAL,IF(ISNULL(BOUNS),'无奖金','有奖金') FROM EMP_XWBING;
|
||||
|
||||
SELECT ENAME,SAL,IF(ISNULL(BOUNS),'无奖金','有奖金') FROM EMP_XWBING;
|
||||
@@ -59,7 +59,7 @@ SELECT * FROM emp_xwbing ORDER BY field(字段名,'','');//MYSQL----------------
|
||||
|
||||
|
||||
聚合函数又称多行函数:用来统计结果的
|
||||
MAX,MIN 统计最大值,最小值
|
||||
MAX,MIN 统计最大值,最小值,无值为null
|
||||
查看最高工资?
|
||||
SELECT MAX(sal),MIN(sal) FROM emp_xwbing;
|
||||
|
||||
@@ -149,3 +149,4 @@ SELECT d.loc FROM EMP_XWBING E,EMP_XWBING M , dept_xwbing d WHERE E.MGR=M.EMPN
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SysUser extends BaseEntity {
|
||||
private String isAdmin;
|
||||
//临时字段
|
||||
@ApiModelProperty(hidden = true)
|
||||
private transient String create;
|
||||
private transient String created;
|
||||
@ApiModelProperty(hidden = true)
|
||||
private transient String modified;
|
||||
@ApiModelProperty(hidden = true)
|
||||
|
||||
@@ -23,6 +23,6 @@ public class SysUserLoginInOut extends BaseEntity {
|
||||
private transient String userIdName;
|
||||
private transient String recordTime;
|
||||
private transient String inoutTypeName;
|
||||
// private transient String startDate;
|
||||
// private transient String endDate;
|
||||
private transient String startDate;
|
||||
private transient String endDate;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xwbing.domain.mapper.sys;
|
||||
|
||||
import com.xwbing.domain.entity.sys.SysAuthority;
|
||||
import com.xwbing.domain.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2018/6/1 21:50
|
||||
* 作者: xiangwb
|
||||
* 说明:
|
||||
*/
|
||||
public interface SysAuthorityMapper extends BaseMapper<SysAuthority> {
|
||||
int getMaxSort();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xwbing.domain.mapper.sys;
|
||||
|
||||
import com.xwbing.domain.entity.sys.SysUserLoginInOut;
|
||||
import com.xwbing.domain.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2018/6/1 21:50
|
||||
* 作者: xiangwb
|
||||
* 说明:
|
||||
*/
|
||||
public interface SysUserLoginInOutMapper extends BaseMapper<SysUserLoginInOut> {
|
||||
List<SysUserLoginInOut> findByInoutType(Map<String, Object> map);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xwbing.domain.mapper.sys;
|
||||
|
||||
import com.xwbing.domain.entity.sys.SysUser;
|
||||
import com.xwbing.domain.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2018/6/1 21:50
|
||||
* 作者: xiangwb
|
||||
* 说明:
|
||||
*/
|
||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
SysUser findByUserName(String userName);
|
||||
}
|
||||
@@ -4,19 +4,16 @@ import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.domain.entity.sys.SysAuthority;
|
||||
import com.xwbing.domain.entity.sys.SysRoleAuthority;
|
||||
import com.xwbing.domain.entity.vo.SysAuthVo;
|
||||
import com.xwbing.domain.mapper.sys.SysAuthorityMapper;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.domain.repository.sys.SysAuthorityRepository;
|
||||
import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -28,9 +25,9 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class SysAuthorityService {
|
||||
@Resource
|
||||
private SysAuthorityRepository sysAuthorityRepository;
|
||||
private SysAuthorityMapper authorityMapper;
|
||||
@Resource
|
||||
private SysRoleAuthorityService sysRoleAuthorityService;
|
||||
private SysRoleAuthorityService roleAuthorityService;
|
||||
|
||||
/**
|
||||
* 保存权限
|
||||
@@ -41,13 +38,13 @@ public class SysAuthorityService {
|
||||
public RestMessage save(SysAuthority sysAuthority) {
|
||||
RestMessage result = new RestMessage();
|
||||
//检查编码
|
||||
boolean b = uniqueCode(sysAuthority.getCode(), null);
|
||||
boolean b = uniqueCode(sysAuthority.getCode());
|
||||
if (!b) {
|
||||
throw new BusinessException("该编码已存在");
|
||||
}
|
||||
//排序处理
|
||||
if (sysAuthority.getSort() == null) {
|
||||
int sort = getSort() + 1;
|
||||
int sort = authorityMapper.getMaxSort() + 1;
|
||||
sysAuthority.setSort(sort);
|
||||
} else {
|
||||
boolean sorted = uniqueSort(sysAuthority.getSort(), null);
|
||||
@@ -55,18 +52,12 @@ public class SysAuthorityService {
|
||||
throw new BusinessException("该排序编号已存在");
|
||||
}
|
||||
}
|
||||
//添加必要参数
|
||||
String id = PassWordUtil.createId();
|
||||
sysAuthority.setId(id);
|
||||
sysAuthority.setCreateTime(new Date());
|
||||
if (StringUtils.isEmpty(sysAuthority.getParentId())) {
|
||||
sysAuthority.setParentId(CommonConstant.ROOT);
|
||||
}
|
||||
//保存
|
||||
SysAuthority save = sysAuthorityRepository.save(sysAuthority);
|
||||
if (save != null) {
|
||||
int save = authorityMapper.insert(sysAuthority);
|
||||
if (save == 1) {
|
||||
result.setSuccess(true);
|
||||
result.setId(id);
|
||||
result.setMessage("保存权限成功");
|
||||
} else {
|
||||
result.setMessage("保存权限失败");
|
||||
@@ -80,6 +71,7 @@ public class SysAuthorityService {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public RestMessage removeById(String id) {
|
||||
RestMessage result = new RestMessage();
|
||||
//判断该权限是否存在
|
||||
@@ -88,11 +80,12 @@ public class SysAuthorityService {
|
||||
throw new BusinessException("该权限不存在");
|
||||
}
|
||||
//删除自身
|
||||
sysAuthorityRepository.delete(id);
|
||||
authorityMapper.deleteById(id);
|
||||
//如果有子节点,递归删除子节点
|
||||
List<SysAuthority> list = listChildrenForRemove(id);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
sysAuthorityRepository.deleteInBatch(list);
|
||||
List<String> ids = list.stream().map(SysAuthority::getId).collect(Collectors.toList());
|
||||
authorityMapper.deleteByIds(ids);
|
||||
}
|
||||
result.setMessage("删除成功");
|
||||
result.setSuccess(true);
|
||||
@@ -125,8 +118,8 @@ public class SysAuthorityService {
|
||||
old.setUrl(sysAuthority.getUrl());
|
||||
// old.setCode(sysAuthority.getCode());编码不能修改
|
||||
old.setType(sysAuthority.getType());
|
||||
SysAuthority save = sysAuthorityRepository.save(old);
|
||||
if (save != null) {
|
||||
int update = authorityMapper.update(old);
|
||||
if (update == 1) {
|
||||
result.setSuccess(true);
|
||||
result.setId(id);
|
||||
result.setMessage("修改权限成功");
|
||||
@@ -143,7 +136,11 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public SysAuthority getById(String id) {
|
||||
return sysAuthorityRepository.findOne(id);
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return null;
|
||||
} else {
|
||||
return authorityMapper.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,11 +150,11 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysAuthority> listByEnable(String enable) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StringUtils.isNotEmpty(enable)) {
|
||||
return sysAuthorityRepository.getByEnableOrderBySort(enable);
|
||||
} else {
|
||||
return sysAuthorityRepository.findAll(new Sort(Sort.Direction.ASC, "sort"));
|
||||
map.put("enable", enable);
|
||||
}
|
||||
return authorityMapper.find(map);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,11 +165,12 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysAuthority> listByParentEnable(String parentId, String enable) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("parentId", parentId);
|
||||
if (StringUtils.isNotEmpty(enable)) {
|
||||
return sysAuthorityRepository.getByParentIdAndEnableOrderBySort(parentId, enable);
|
||||
} else {
|
||||
return sysAuthorityRepository.getByParentIdOrderBySort(parentId);
|
||||
map.put("enable", enable);
|
||||
}
|
||||
return authorityMapper.find(map);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,18 +183,19 @@ public class SysAuthorityService {
|
||||
public List<SysAuthority> listByRoleIdEnable(String roleId, String enable) {
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
// 从角色权限表中获取所有该角色id的权限
|
||||
List<SysRoleAuthority> roleAuthorities = sysRoleAuthorityService.listByRoleId(roleId);
|
||||
List<SysRoleAuthority> roleAuthorities = roleAuthorityService.listByRoleId(roleId);
|
||||
if (CollectionUtils.isEmpty(roleAuthorities)) {
|
||||
return list;
|
||||
}
|
||||
//根据权限id获取对应权限列表
|
||||
List<String> authorityIds = roleAuthorities.stream().map(SysRoleAuthority::getAuthorityId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(authorityIds)) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("authorityIds", authorityIds);
|
||||
if (StringUtils.isNotEmpty(enable)) {
|
||||
list = sysAuthorityRepository.getByEnableAndIdInOrderBySort(enable, authorityIds);
|
||||
} else {
|
||||
list = sysAuthorityRepository.getByIdInOrderBySort(authorityIds);
|
||||
map.put("enable", enable);
|
||||
}
|
||||
list = authorityMapper.find(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -213,8 +212,8 @@ public class SysAuthorityService {
|
||||
List<SysAuthority> sysAuthorities = disableChildren(parentId);
|
||||
//批量修改权限
|
||||
if (CollectionUtils.isNotEmpty(sysAuthorities)) {
|
||||
List<SysAuthority> save = sysAuthorityRepository.save(sysAuthorities);
|
||||
return CollectionUtils.isNotEmpty(save);
|
||||
int updateBatch = authorityMapper.updateBatch(sysAuthorities);
|
||||
return updateBatch != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -227,18 +226,18 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysAuthVo> listChildren(String parentId, String enable) {
|
||||
List<SysAuthVo> list = new ArrayList<>();
|
||||
List<SysAuthority> authoritys;
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("parentId", parentId);
|
||||
if (StringUtils.isNotEmpty(enable)) {
|
||||
authoritys = sysAuthorityRepository.getByParentIdAndEnableOrderBySort(parentId, enable);
|
||||
} else {
|
||||
authoritys = sysAuthorityRepository.getByParentIdOrderBySort(parentId);
|
||||
map.put("enable", enable);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(authoritys)) {
|
||||
return list;
|
||||
List<SysAuthority> authorities = authorityMapper.find(map);
|
||||
if (CollectionUtils.isEmpty(authorities)) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
SysAuthVo vo;
|
||||
for (SysAuthority authority : authoritys) {
|
||||
List<SysAuthVo> list = new ArrayList<>();
|
||||
for (SysAuthority authority : authorities) {
|
||||
vo = new SysAuthVo(authority);
|
||||
vo.setChildren(listChildren(vo.getId(), enable));
|
||||
list.add(vo);
|
||||
@@ -246,21 +245,6 @@ public class SysAuthorityService {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最大顺序
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private int getSort() {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "sort");
|
||||
List<SysAuthority> all = sysAuthorityRepository.findAll(sort);
|
||||
if (CollectionUtils.isNotEmpty(all)) {
|
||||
return all.get(0).getSort();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询父节点下所有权限的id集合,并将状态设置为禁用(禁用权限时用)
|
||||
*
|
||||
@@ -269,13 +253,12 @@ public class SysAuthorityService {
|
||||
*/
|
||||
private List<SysAuthority> disableChildren(String parentId) {
|
||||
//根据状态查询所有子节点
|
||||
List<SysAuthority> sysAuthoritys = listByParentEnable(parentId, CommonConstant.IS_ENABLE);
|
||||
List<SysAuthority> authorities = listByParentEnable(parentId, CommonConstant.IS_ENABLE);
|
||||
//遍历子集
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(sysAuthoritys)) {
|
||||
sysAuthoritys.forEach(sysAuthority -> {
|
||||
if (CollectionUtils.isNotEmpty(authorities)) {
|
||||
authorities.forEach(sysAuthority -> {
|
||||
sysAuthority.setEnable(CommonConstant.IS_NOT_ENABLE);
|
||||
sysAuthority.setModifiedTime(new Date());
|
||||
list.add(sysAuthority);
|
||||
list.addAll(disableChildren(sysAuthority.getId()));
|
||||
});
|
||||
@@ -291,11 +274,11 @@ public class SysAuthorityService {
|
||||
*/
|
||||
private List<SysAuthority> listChildrenForRemove(String parentId) {
|
||||
//根据状态查询所有子节点
|
||||
List<SysAuthority> sysAuthoritys = listByParentEnable(parentId, null);
|
||||
List<SysAuthority> authorities = listByParentEnable(parentId, null);
|
||||
//遍历子集
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(sysAuthoritys)) {
|
||||
sysAuthoritys.forEach(sysAuthority -> {
|
||||
if (CollectionUtils.isNotEmpty(authorities)) {
|
||||
authorities.forEach(sysAuthority -> {
|
||||
list.add(sysAuthority);
|
||||
list.addAll(listChildrenForRemove(sysAuthority.getId()));
|
||||
});
|
||||
@@ -307,19 +290,20 @@ public class SysAuthorityService {
|
||||
* 检查code是否唯一 true唯一
|
||||
*
|
||||
* @param code
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private boolean uniqueCode(String code, String id) {
|
||||
private boolean uniqueCode(String code) {
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
throw new BusinessException("code不能为空");
|
||||
}
|
||||
SysAuthority one = sysAuthorityRepository.getByCode(code);
|
||||
return one == null || StringUtils.isNotEmpty(id) && id.equals(one.getId());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", code);
|
||||
List<SysAuthority> authorities = authorityMapper.find(map);
|
||||
return authorities.size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查排序是否存在
|
||||
* 检查排序是否存在 true不存在
|
||||
*
|
||||
* @param sort
|
||||
* @param id
|
||||
@@ -329,7 +313,13 @@ public class SysAuthorityService {
|
||||
if (sort == null) {
|
||||
throw new BusinessException("sort不能为空");
|
||||
}
|
||||
SysAuthority one = sysAuthorityRepository.getBySort(sort);
|
||||
return one == null || StringUtils.isNotEmpty(id) && id.equals(one.getId());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("sort", sort);
|
||||
if (StringUtils.isNotEmpty(id)) {
|
||||
map.put("id", id);
|
||||
}
|
||||
List<SysAuthority> authorities = authorityMapper.find(map);
|
||||
return authorities.size() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.xwbing.domain.entity.sys.SysRoleAuthority;
|
||||
import com.xwbing.domain.repository.sys.SysRoleAuthorityRepository;
|
||||
import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.domain.mapper.sys.SysRoleAuthorityMapper;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -20,7 +22,7 @@ import java.util.List;
|
||||
@Service
|
||||
public class SysRoleAuthorityService {
|
||||
@Resource
|
||||
private SysRoleAuthorityRepository sysRoleAuthorityRepository;
|
||||
private SysRoleAuthorityMapper sysRoleAuthorityMapper;
|
||||
|
||||
/**
|
||||
* 执行用户角色权限保存操作,保存之前先判断是否存在,存在删除
|
||||
@@ -29,21 +31,19 @@ public class SysRoleAuthorityService {
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public RestMessage saveBatch(List<SysRoleAuthority> list, String roleId) {
|
||||
RestMessage result = new RestMessage();
|
||||
//获取角色原有权限
|
||||
List<SysRoleAuthority> roleAuthorities = listByRoleId(roleId);
|
||||
//删除原有权限
|
||||
if (CollectionUtils.isNotEmpty(roleAuthorities)) {
|
||||
sysRoleAuthorityRepository.deleteInBatch(roleAuthorities);
|
||||
List<String> ids = roleAuthorities.stream().map(SysRoleAuthority::getId).collect(Collectors.toList());
|
||||
sysRoleAuthorityMapper.deleteByIds(ids);
|
||||
}
|
||||
//新增角色权限
|
||||
list.forEach(roleAuthority -> {
|
||||
roleAuthority.setId(PassWordUtil.createId());
|
||||
roleAuthority.setModifiedTime(new Date());
|
||||
});
|
||||
List<SysRoleAuthority> save = sysRoleAuthorityRepository.save(list);
|
||||
if (CollectionUtils.isNotEmpty(save)) {
|
||||
int save = sysRoleAuthorityMapper.insertBatch(list);
|
||||
if (save != 0) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("保存角色权限成功");
|
||||
} else {
|
||||
@@ -60,20 +60,29 @@ public class SysRoleAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysRoleAuthority> listByRoleId(String roleId) {
|
||||
return sysRoleAuthorityRepository.getByRoleId(roleId);
|
||||
if (StringUtils.isEmpty(roleId)) {
|
||||
return Collections.EMPTY_LIST;
|
||||
} else {
|
||||
return sysRoleAuthorityMapper.findByRoleId(roleId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param roleAuthorities
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public RestMessage removeBatch(List<SysRoleAuthority> roleAuthorities) {
|
||||
public RestMessage removeBatch(List<String> ids) {
|
||||
RestMessage result = new RestMessage();
|
||||
sysRoleAuthorityRepository.deleteInBatch(roleAuthorities);
|
||||
result.setSuccess(true);
|
||||
result.setMessage("批量删除成功");
|
||||
int deleteByIds = sysRoleAuthorityMapper.deleteByIds(ids);
|
||||
if (deleteByIds != 0) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("批量删除成功");
|
||||
}else {
|
||||
result.setMessage("批量删除失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.domain.entity.sys.SysRole;
|
||||
import com.xwbing.domain.entity.sys.SysRoleAuthority;
|
||||
import com.xwbing.domain.entity.sys.SysUserRole;
|
||||
import com.xwbing.domain.mapper.sys.SysRoleMapper;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.domain.repository.sys.SysRoleRepository;
|
||||
import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -26,11 +28,11 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class SysRoleService {
|
||||
@Resource
|
||||
private SysRoleRepository sysRoleRepository;
|
||||
private SysRoleAuthorityService roleAuthorityService;
|
||||
@Resource
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
private SysUserRoleService userRoleService;
|
||||
@Resource
|
||||
private SysRoleAuthorityService sysRoleAuthorityService;
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
/**
|
||||
* 保存角色
|
||||
@@ -45,13 +47,9 @@ public class SysRoleService {
|
||||
if (!b) {
|
||||
throw new BusinessException("该编码已存在");
|
||||
}
|
||||
String id = PassWordUtil.createId();
|
||||
sysRole.setId(id);
|
||||
sysRole.setCreateTime(new Date());
|
||||
SysRole save = sysRoleRepository.save(sysRole);
|
||||
if (save != null) {
|
||||
int save = roleMapper.insert(sysRole);
|
||||
if (save == 1) {
|
||||
result.setSuccess(true);
|
||||
result.setId(id);
|
||||
result.setMessage("保存角色成功");
|
||||
} else {
|
||||
result.setMessage("保存角色失败");
|
||||
@@ -65,6 +63,7 @@ public class SysRoleService {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public RestMessage removeById(String id) {
|
||||
RestMessage result = new RestMessage();
|
||||
SysRole one = getById(id);
|
||||
@@ -72,11 +71,12 @@ public class SysRoleService {
|
||||
throw new BusinessException("该角色不存在");
|
||||
}
|
||||
//删除角色
|
||||
sysRoleRepository.delete(id);
|
||||
roleMapper.deleteById(id);
|
||||
//删除角色权限
|
||||
List<SysRoleAuthority> roleAuthorities = sysRoleAuthorityService.listByRoleId(id);
|
||||
List<SysRoleAuthority> roleAuthorities = roleAuthorityService.listByRoleId(id);
|
||||
if (CollectionUtils.isNotEmpty(roleAuthorities)) {
|
||||
sysRoleAuthorityService.removeBatch(roleAuthorities);
|
||||
List<String> ids = roleAuthorities.stream().map(SysRoleAuthority::getId).collect(Collectors.toList());
|
||||
roleAuthorityService.removeBatch(ids);
|
||||
}
|
||||
result.setMessage("删除成功");
|
||||
result.setSuccess(true);
|
||||
@@ -101,13 +101,12 @@ public class SysRoleService {
|
||||
if (!b) {
|
||||
throw new BusinessException("该编码已存在");
|
||||
}
|
||||
old.setModifiedTime(new Date());
|
||||
old.setName(sysRole.getName());
|
||||
old.setCode(sysRole.getCode());
|
||||
old.setEnable(sysRole.getEnable());
|
||||
old.setRemark(sysRole.getRemark());
|
||||
SysRole save = sysRoleRepository.save(old);
|
||||
if (save != null) {
|
||||
int update = roleMapper.update(old);
|
||||
if (update == 1) {
|
||||
result.setSuccess(true);
|
||||
result.setId(id);
|
||||
result.setMessage("修改角色成功");
|
||||
@@ -124,7 +123,11 @@ public class SysRoleService {
|
||||
* @return
|
||||
*/
|
||||
public SysRole getById(String id) {
|
||||
return sysRoleRepository.findOne(id);
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return null;
|
||||
} else {
|
||||
return roleMapper.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,11 +137,9 @@ public class SysRoleService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysRole> listAllByEnable(String enable) {
|
||||
if (StringUtils.isNotEmpty(enable)) {
|
||||
return sysRoleRepository.getByEnable(enable);
|
||||
} else {
|
||||
return sysRoleRepository.findAll();
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("enable", enable);
|
||||
return roleMapper.find(map);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,18 +152,19 @@ public class SysRoleService {
|
||||
public List<SysRole> listByUserIdEnable(String userId, String enable) {
|
||||
List<SysRole> list = new ArrayList<>();
|
||||
//从用户角色表中获取所有该用户id的角色
|
||||
List<SysUserRole> sysUserRoles = sysUserRoleService.listByUserId(userId);
|
||||
List<SysUserRole> sysUserRoles = userRoleService.listByUserId(userId);
|
||||
if (sysUserRoles == null) {
|
||||
return list;
|
||||
}
|
||||
//根据角色id获取对应角色列表
|
||||
List<String> roleIds = sysUserRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(roleIds)) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("ids", roleIds);
|
||||
if (StringUtils.isNotEmpty(enable)) {
|
||||
list = sysRoleRepository.getByEnableAndIdIn(enable, roleIds);
|
||||
} else {
|
||||
list = sysRoleRepository.getByIdIn(roleIds);
|
||||
map.put("enable", CommonConstant.IS_ENABLE);
|
||||
}
|
||||
list = roleMapper.find(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -178,7 +180,13 @@ public class SysRoleService {
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
throw new BusinessException("code不能为空");
|
||||
}
|
||||
SysRole one = sysRoleRepository.getByCode(code);
|
||||
return one == null || StringUtils.isNotEmpty(id) && id.equals(one.getId());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", code);
|
||||
if (StringUtils.isNotEmpty(id)) {
|
||||
map.put("id", id);
|
||||
}
|
||||
List<SysRole> sysRoles = roleMapper.find(map);
|
||||
return sysRoles.size() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.domain.entity.sys.SysUser;
|
||||
import com.xwbing.domain.entity.sys.SysUserLoginInOut;
|
||||
import com.xwbing.domain.repository.sys.SysUserLoginInOutRepository;
|
||||
import com.xwbing.util.DateUtil2;
|
||||
import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.domain.mapper.sys.SysUserLoginInOutMapper;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -27,9 +23,7 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class SysUserLoginInOutService {
|
||||
@Resource
|
||||
private SysUserLoginInOutRepository loginInOutRepository;
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
private SysUserLoginInOutMapper loginInOutMapper;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
@@ -39,9 +33,8 @@ public class SysUserLoginInOutService {
|
||||
*/
|
||||
public RestMessage save(SysUserLoginInOut inOut) {
|
||||
RestMessage result = new RestMessage();
|
||||
inOut.setId(PassWordUtil.createId());
|
||||
SysUserLoginInOut save = loginInOutRepository.save(inOut);
|
||||
if (save != null) {
|
||||
int save = loginInOutMapper.insert(inOut);
|
||||
if (save == 1) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("保存登录登出信息成功");
|
||||
} else {
|
||||
@@ -56,19 +49,24 @@ public class SysUserLoginInOutService {
|
||||
* @param inout
|
||||
* @return
|
||||
*/
|
||||
public List<SysUserLoginInOut> listByType(int inout) {
|
||||
Map<String, SysUser> userMap = sysUserService.listAll().stream().collect(Collectors.toMap(SysUser::getId, Function.identity()));
|
||||
List<SysUserLoginInOut> list = loginInOutRepository.getByInoutType(inout);
|
||||
public List<SysUserLoginInOut> listByType(int inout, String startDate, String endDate) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("inout", inout);
|
||||
if (StringUtils.isNotEmpty(startDate)) {
|
||||
map.put("startDate", startDate + " 00:00:00");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(endDate)) {
|
||||
map.put("endDate", endDate + " 23:59:59");
|
||||
}
|
||||
List<SysUserLoginInOut> list = loginInOutMapper.findByInoutType(map);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
if (MapUtils.isNotEmpty(userMap)) {
|
||||
list=list.stream().sorted((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())).peek(inOut -> {
|
||||
inOut.setUserIdName(userMap.get(inOut.getUserId()).getName());//用户姓名
|
||||
inOut.setRecordTime(DateUtil2.dateToStr(inOut.getCreateTime(), DateUtil2.YYYY_MM_DD_HH_MM_SS));//记录时间
|
||||
CommonEnum.LoginInOutEnum inOutEnum = Arrays.stream(CommonEnum.LoginInOutEnum.values()).filter(obj -> obj.getValue() == inout).findFirst().get();//登录登出
|
||||
inOut.setInoutTypeName(inOutEnum.getName());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
list.forEach(inOut -> {
|
||||
//登录登出
|
||||
CommonEnum.LoginInOutEnum inOutEnum = Arrays.stream(CommonEnum.LoginInOutEnum.values()).filter(obj -> obj.getValue() == inout).findFirst().get();
|
||||
inOut.setInoutTypeName(inOutEnum.getName());
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.xwbing.domain.entity.sys.SysUserRole;
|
||||
import com.xwbing.domain.repository.sys.SysUserRoleRepository;
|
||||
import com.xwbing.util.PassWordUtil;
|
||||
import com.xwbing.domain.mapper.sys.SysUserRoleMapper;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -20,7 +22,7 @@ import java.util.List;
|
||||
@Service
|
||||
public class SysUserRoleService {
|
||||
@Resource
|
||||
private SysUserRoleRepository sysUserRoleRepository;
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
/**
|
||||
* 执行用户角色权限保存操作,保存之前先判断是否存在,存在删除
|
||||
@@ -29,21 +31,19 @@ public class SysUserRoleService {
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public RestMessage saveBatch(List<SysUserRole> list, String userId) {
|
||||
RestMessage result = new RestMessage();
|
||||
//获取用户原有角色
|
||||
List<SysUserRole> sysUserRoles = listByUserId(userId);
|
||||
//删除原有角色
|
||||
if (CollectionUtils.isNotEmpty(sysUserRoles)) {
|
||||
sysUserRoleRepository.deleteInBatch(sysUserRoles);
|
||||
List<String> ids = sysUserRoles.stream().map(SysUserRole::getId).collect(Collectors.toList());
|
||||
sysUserRoleMapper.deleteByIds(ids);
|
||||
}
|
||||
//新增用户角色
|
||||
list.forEach(sysUserRole -> {
|
||||
sysUserRole.setId(PassWordUtil.createId());
|
||||
sysUserRole.setCreateTime(new Date());
|
||||
});
|
||||
List<SysUserRole> save = sysUserRoleRepository.save(list);
|
||||
if (CollectionUtils.isNotEmpty(save)) {
|
||||
int save = sysUserRoleMapper.insertBatch(list);
|
||||
if (save != 0) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("保存用户角色成功");
|
||||
} else {
|
||||
@@ -59,20 +59,29 @@ public class SysUserRoleService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysUserRole> listByUserId(String userId) {
|
||||
return sysUserRoleRepository.getByUserId(userId);
|
||||
if (StringUtils.isEmpty(userId)) {
|
||||
return Collections.EMPTY_LIST;
|
||||
} else {
|
||||
return sysUserRoleMapper.findByUserId(userId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param userRoles
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public RestMessage removeBatch(List<SysUserRole> userRoles) {
|
||||
public RestMessage removeBatch(List<String> ids) {
|
||||
RestMessage result = new RestMessage();
|
||||
sysUserRoleRepository.deleteInBatch(userRoles);
|
||||
result.setSuccess(true);
|
||||
result.setMessage("批量删除成功");
|
||||
int deleteByIds = sysUserRoleMapper.deleteByIds(ids);
|
||||
if (deleteByIds != 0) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage("批量删除成功");
|
||||
}else {
|
||||
result.setMessage("批量删除失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,15 @@ import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.domain.entity.dto.UserDto;
|
||||
import com.xwbing.domain.entity.model.EmailModel;
|
||||
import com.xwbing.domain.entity.sys.*;
|
||||
import com.xwbing.domain.repository.sys.SysUserRepository;
|
||||
import com.xwbing.domain.mapper.sys.SysUserMapper;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.rabbit.Sender;
|
||||
import com.xwbing.util.*;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
@@ -20,7 +22,10 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 说明: 用户服务层
|
||||
@@ -30,8 +35,6 @@ import java.util.*;
|
||||
*/
|
||||
@Service
|
||||
public class SysUserService {
|
||||
@Resource
|
||||
private SysUserRepository sysUserRepository;
|
||||
@Resource
|
||||
private SysConfigService sysConfigService;
|
||||
@Resource
|
||||
@@ -43,6 +46,8 @@ public class SysUserService {
|
||||
@Resource
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Resource
|
||||
private SysUserMapper userMapper;
|
||||
@Resource
|
||||
private Sender sender;
|
||||
|
||||
/**
|
||||
@@ -59,24 +64,20 @@ public class SysUserService {
|
||||
if (old != null) {
|
||||
throw new BusinessException("已经存在此用户名");
|
||||
}
|
||||
String id = PassWordUtil.createId();
|
||||
sysUser.setId(id);
|
||||
sysUser.setCreateTime(new Date());
|
||||
// 获取初始密码
|
||||
String[] res = PassWordUtil.getUserSecret(null, null);
|
||||
sysUser.setSalt(res[1]);
|
||||
sysUser.setPassword(res[2]);
|
||||
// 设置为非管理员
|
||||
sysUser.setIsAdmin(CommonEnum.YesOrNoEnum.NO.getCode());
|
||||
SysUser one = sysUserRepository.save(sysUser);
|
||||
if (one == null) {
|
||||
int save = userMapper.insert(sysUser);
|
||||
if (save == 0) {
|
||||
throw new BusinessException("新增用户失败");
|
||||
}
|
||||
String[] msg = {sysUser.getMail(), userName, res[0]};
|
||||
//使用mq发送邮件
|
||||
sender.sendEmail(msg);
|
||||
result.setSuccess(true);
|
||||
result.setId(id);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -86,6 +87,7 @@ public class SysUserService {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public RestMessage removeById(String id) {
|
||||
RestMessage result = new RestMessage();
|
||||
//检查该用户是否存在
|
||||
@@ -102,11 +104,12 @@ public class SysUserService {
|
||||
throw new BusinessException("不能对管理员进行删除操作");
|
||||
}
|
||||
//删除用户
|
||||
sysUserRepository.delete(id);
|
||||
userMapper.deleteById(id);
|
||||
//删除用户角色
|
||||
List<SysUserRole> sysUserRoles = sysUserRoleService.listByUserId(id);
|
||||
if (CollectionUtils.isNotEmpty(sysUserRoles)) {
|
||||
sysUserRoleService.removeBatch(sysUserRoles);
|
||||
List<String> ids = sysUserRoles.stream().map(SysUserRole::getId).collect(Collectors.toList());
|
||||
sysUserRoleService.removeBatch(ids);
|
||||
}
|
||||
result.setMessage("删除成功");
|
||||
result.setSuccess(true);
|
||||
@@ -138,10 +141,9 @@ public class SysUserService {
|
||||
old.setName(sysUser.getName());
|
||||
old.setMail(sysUser.getMail());
|
||||
old.setSex(sysUser.getSex());
|
||||
old.setModifiedTime(new Date());
|
||||
// old.setUserName(sysUser.getUserName());//用户名不能修改
|
||||
SysUser one = sysUserRepository.save(old);
|
||||
if (one != null) {
|
||||
int update = userMapper.update(old);
|
||||
if (update == 1) {
|
||||
result.setMessage("更新成功");
|
||||
result.setId(sysUser.getId());
|
||||
result.setSuccess(true);
|
||||
@@ -158,7 +160,11 @@ public class SysUserService {
|
||||
* @return
|
||||
*/
|
||||
public SysUser getById(String id) {
|
||||
return sysUserRepository.findOne(id);
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return null;
|
||||
} else {
|
||||
return userMapper.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +174,11 @@ public class SysUserService {
|
||||
* @return
|
||||
*/
|
||||
public SysUser getByUserName(String userName) {
|
||||
return sysUserRepository.getByUserName(userName);
|
||||
if (StringUtils.isEmpty(userName)) {
|
||||
return null;
|
||||
} else {
|
||||
return userMapper.findByUserName(userName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,16 +187,12 @@ public class SysUserService {
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> listAll() {
|
||||
List<SysUser> all = sysUserRepository.findAll();
|
||||
List<SysUser> all = userMapper.findAll();
|
||||
if (CollectionUtils.isNotEmpty(all)) {
|
||||
all.forEach(sysUser -> {
|
||||
//性别
|
||||
CommonEnum.SexEnum sexEnum = Arrays.stream(CommonEnum.SexEnum.values()).filter(obj -> obj.getCode().equals(sysUser.getSex())).findFirst().get();
|
||||
sysUser.setSexName(sexEnum.getName());
|
||||
sysUser.setCreate(DateUtil2.dateToStr(sysUser.getCreateTime(), DateUtil2.YYYY_MM_DD_HH_MM_SS));
|
||||
Date modifiedTime = sysUser.getModifiedTime();
|
||||
if (modifiedTime != null) {
|
||||
sysUser.setModified(DateUtil2.dateToStr(sysUser.getModifiedTime(), DateUtil2.YYYY_MM_DD_HH_MM_SS));
|
||||
}
|
||||
});
|
||||
}
|
||||
return all;
|
||||
@@ -216,9 +222,8 @@ public class SysUserService {
|
||||
String[] str = PassWordUtil.getUserSecret(null, null);
|
||||
old.setSalt(str[1]);
|
||||
old.setPassword(str[2]);
|
||||
old.setModifiedTime(new Date());
|
||||
SysUser save = sysUserRepository.save(old);
|
||||
if (save == null) {
|
||||
int update = userMapper.update(old);
|
||||
if (update == 0) {
|
||||
throw new BusinessException("重置密码失败");
|
||||
}
|
||||
//使用mq发送邮件
|
||||
@@ -250,9 +255,8 @@ public class SysUserService {
|
||||
String[] str = PassWordUtil.getUserSecret(newPassWord, null);
|
||||
sysUser.setSalt(str[1]);
|
||||
sysUser.setPassword(str[2]);
|
||||
sysUser.setModifiedTime(new Date());
|
||||
SysUser save = sysUserRepository.save(sysUser);
|
||||
if (save != null) {
|
||||
int update = userMapper.update(sysUser);
|
||||
if (update == 1) {
|
||||
result.setMessage("修改密码成功");
|
||||
result.setSuccess(true);
|
||||
} else {
|
||||
@@ -288,7 +292,6 @@ public class SysUserService {
|
||||
}
|
||||
//保存登录信息
|
||||
SysUserLoginInOut loginInOut = new SysUserLoginInOut();
|
||||
loginInOut.setCreateTime(new Date());
|
||||
loginInOut.setUserId(user.getId());
|
||||
loginInOut.setInoutType(CommonEnum.LoginInOutEnum.IN.getValue());
|
||||
String ip = IpUtil.getIpAddr(request);
|
||||
@@ -322,7 +325,6 @@ public class SysUserService {
|
||||
CommonDataUtil.clearData(token);
|
||||
//保存登出信息
|
||||
SysUserLoginInOut loginInOut = new SysUserLoginInOut();
|
||||
loginInOut.setCreateTime(new Date());
|
||||
loginInOut.setUserId(user.getId());
|
||||
loginInOut.setInoutType(CommonEnum.LoginInOutEnum.OUT.getValue());
|
||||
loginInOut.setIp(IpUtil.getIpAddr(request));
|
||||
@@ -406,7 +408,7 @@ public class SysUserService {
|
||||
*/
|
||||
private List<UserDto> listReport() {
|
||||
List<UserDto> listDto = new ArrayList<>();
|
||||
List<SysUser> list = sysUserRepository.findAll();
|
||||
List<SysUser> list = userMapper.findAll();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
UserDto temp;
|
||||
for (SysUser info : list) {
|
||||
@@ -461,3 +463,4 @@ public class SysUserService {
|
||||
return EmailUtil.sendTextEmail(emailModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
<?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.xwbing.domain.mapper.sys.SysAuthorityMapper">
|
||||
<resultMap id="resultMap" type="sysAuthority">
|
||||
<id column="id" property="id"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="modified_time" property="modifiedTime"/>
|
||||
<result column="parent_id" property="parentId"/>
|
||||
</resultMap>
|
||||
<sql id="table">
|
||||
sys_authority
|
||||
</sql>
|
||||
<sql id="columns">
|
||||
id,
|
||||
creator,
|
||||
modifier,
|
||||
create_time,
|
||||
modified_time,
|
||||
name,
|
||||
code,
|
||||
enable,
|
||||
url,
|
||||
parent_id,
|
||||
type,
|
||||
sort
|
||||
</sql>
|
||||
<sql id="condition">
|
||||
<where>
|
||||
<if test="code!=null">
|
||||
code=#{code}
|
||||
</if>
|
||||
<if test="id!=null">
|
||||
and id!=#{id}
|
||||
</if>
|
||||
<if test="sort!=null">
|
||||
and sort=#{sort}
|
||||
</if>
|
||||
<if test="parentId!=null">
|
||||
and parent_id=#{parentId}
|
||||
</if>
|
||||
<if test="enable!=null">
|
||||
and enable=#{enable}
|
||||
</if>
|
||||
<if test="authorityIds!=null">
|
||||
and id in
|
||||
<foreach collection="authorityIds" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
<!-- 插入 -->
|
||||
<insert id="insert">
|
||||
<selectKey keyProperty="id" resultType="string" order="BEFORE">
|
||||
SELECT REPLACE(UUID(), '-', '')
|
||||
</selectKey>
|
||||
INSERT INTO
|
||||
<include refid="table"/>(
|
||||
id,
|
||||
creator,
|
||||
create_time,
|
||||
name,
|
||||
code,
|
||||
enable,
|
||||
url,
|
||||
parent_id,
|
||||
type,
|
||||
sort
|
||||
)
|
||||
VALUES(
|
||||
#{id},
|
||||
#{creator},
|
||||
now(),
|
||||
#{name},
|
||||
#{code},
|
||||
#{enable},
|
||||
#{url},
|
||||
#{parentId},
|
||||
#{type},
|
||||
#{sort}
|
||||
)
|
||||
</insert>
|
||||
<!-- 批量插入 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO
|
||||
<include refid="table"/>(
|
||||
id,
|
||||
creator,
|
||||
create_time,
|
||||
name,
|
||||
code,
|
||||
enable,
|
||||
url,
|
||||
parent_id,
|
||||
type,
|
||||
sort
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="obj" separator=",">(
|
||||
(SELECT REPLACE(UUID(), '-', '') AS id),
|
||||
#{obj.creator},
|
||||
now(),
|
||||
#{obj.name},
|
||||
#{obj.code},
|
||||
#{obj.enable},
|
||||
#{obj.url},
|
||||
#{obj.parentId},
|
||||
#{obj.type},
|
||||
#{obj.sort}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<!-- 删除 -->
|
||||
<delete id="deleteById">
|
||||
DELETE FROM
|
||||
<include refid="table"/>
|
||||
WHERE id=#{id}
|
||||
</delete>
|
||||
<!-- 批量删除 -->
|
||||
<delete id="deleteByIds">
|
||||
DELETE FROM
|
||||
<include refid="table"/>
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<!-- 条件删除 -->
|
||||
<delete id="delete">
|
||||
DELETE FROM
|
||||
<include refid="table"/>
|
||||
<include refid="condition"/>
|
||||
</delete>
|
||||
<!-- 更新 -->
|
||||
<update id="update">
|
||||
UPDATE
|
||||
<include refid="table"/>
|
||||
<set>
|
||||
modified_time=now(),
|
||||
<if test="modifier!=null">modifier=#{modifier},</if>
|
||||
<if test="name!=null">name=#{name},</if>
|
||||
<if test="enable!=null">enable=#{enable},</if>
|
||||
<if test="url!=null">url=#{url},</if>
|
||||
<if test="parentId!=null">parent_id=#{parentId},</if>
|
||||
<if test="type!=null">type=#{type},</if>
|
||||
<if test="sort!=null">sort=#{sort},</if>
|
||||
</set>
|
||||
WHERE id=#{id}
|
||||
</update>
|
||||
<!-- 批量更新 -->
|
||||
<update id="updateBatch">
|
||||
UPDATE
|
||||
<include refid="table"/>
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<trim prefix="modified_time=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
when id=#{obj.id} then now()
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="modifier=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.modifier!=null">
|
||||
when id=#{obj.id} then #{obj.modifier}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="name=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.name!=null">
|
||||
when id=#{obj.id} then #{obj.name}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="enable=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.enable!=null">
|
||||
when id=#{obj.id} then #{obj.enable}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="url=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.url!=null">
|
||||
when id=#{obj.id} then #{obj.url}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="parent_id=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.parentId!=null">
|
||||
when id=#{obj.id} then #{obj.parentId}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="type=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.type!=null">
|
||||
when id=#{obj.id} then #{obj.type}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="sort=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.sort!=null">
|
||||
when id=#{obj.id} then #{obj.sort}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
</trim>
|
||||
<where>
|
||||
<foreach collection="list" separator="or" item="obj">
|
||||
id=#{obj.id}
|
||||
</foreach>
|
||||
</where>
|
||||
</update>
|
||||
<!-- 查找 -->
|
||||
<select id="findById" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
WHERE id=#{id}
|
||||
</select>
|
||||
<!-- 根据ids查找 -->
|
||||
<select id="findByIds" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<!-- 条件查询 -->
|
||||
<select id="find" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
<include refid="condition"/>
|
||||
ORDER BY sort
|
||||
</select>
|
||||
<!-- 查询所有 -->
|
||||
<select id="findAll" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
ORDER BY sort
|
||||
</select>
|
||||
<!-- 获取最大排序号 -->
|
||||
<select id="getMaxSort" resultType="int">
|
||||
SELECT IFNULL(MAX(sort),0)
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,238 @@
|
||||
<?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.xwbing.domain.mapper.sys.SysUserMapper">
|
||||
<resultMap id="resultMap" type="sysUser">
|
||||
<id column="id" property="id"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="modified_time" property="modifiedTime"/>
|
||||
<result column="user_name" property="userName"/>
|
||||
<result column="is_admin" property="isAdmin"/>
|
||||
</resultMap>
|
||||
<sql id="table">
|
||||
sys_user_info
|
||||
</sql>
|
||||
<sql id="columns">
|
||||
id,
|
||||
creator,
|
||||
modifier,
|
||||
date_format(create_time,'%Y-%m-%d %h:%i:%s') created,
|
||||
date_format(modified_time,'%Y-%m-%d %h:%i:%s') modified,
|
||||
user_name,
|
||||
name,
|
||||
sex,
|
||||
mail,
|
||||
salt,
|
||||
password,
|
||||
is_admin
|
||||
</sql>
|
||||
<sql id="condition">
|
||||
<where>
|
||||
</where>
|
||||
</sql>
|
||||
<!-- 插入 -->
|
||||
<insert id="insert">
|
||||
<selectKey keyProperty="id" resultType="string" order="BEFORE">
|
||||
SELECT REPLACE(UUID(), '-', '')
|
||||
</selectKey>
|
||||
INSERT INTO
|
||||
<include refid="table"/>(
|
||||
id,
|
||||
creator,
|
||||
create_time,
|
||||
user_name,
|
||||
name,
|
||||
sex,
|
||||
mail,
|
||||
salt,
|
||||
password,
|
||||
is_admin
|
||||
)
|
||||
VALUES(
|
||||
#{id},
|
||||
#{creator},
|
||||
now(),
|
||||
#{userName},
|
||||
#{name},
|
||||
#{sex},
|
||||
#{mail},
|
||||
#{salt},
|
||||
#{password},
|
||||
#{isAdmin}
|
||||
)
|
||||
</insert>
|
||||
<!-- 批量插入 -->
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO
|
||||
<include refid="table"/>(
|
||||
id,
|
||||
creator,
|
||||
create_time,
|
||||
user_name,
|
||||
name,
|
||||
sex,
|
||||
mail,
|
||||
salt,
|
||||
password,
|
||||
is_admin
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="obj" separator=",">(
|
||||
(SELECT REPLACE(UUID(), '-', '') AS id),
|
||||
#{obj.creator},
|
||||
now(),
|
||||
#{obj.userName},
|
||||
#{obj.name},
|
||||
#{obj.sex},
|
||||
#{obj.mail},
|
||||
#{obj.salt},
|
||||
#{obj.password},
|
||||
#{obj.isAdmin}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<!-- 删除 -->
|
||||
<delete id="deleteById">
|
||||
DELETE FROM
|
||||
<include refid="table"/>
|
||||
WHERE id=#{id}
|
||||
</delete>
|
||||
<!-- 批量删除 -->
|
||||
<delete id="deleteByIds">
|
||||
DELETE FROM
|
||||
<include refid="table"/>
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<!-- 条件删除 -->
|
||||
<delete id="delete">
|
||||
DELETE FROM
|
||||
<include refid="table"/>
|
||||
<include refid="condition"/>
|
||||
</delete>
|
||||
<!-- 更新 -->
|
||||
<update id="update">
|
||||
UPDATE
|
||||
<include refid="table"/>
|
||||
<set>
|
||||
modified_time=now(),
|
||||
<if test="modifier!=null">modifier=#{modifier},</if>
|
||||
<if test="name!=null">name=#{name},</if>
|
||||
<if test="sex!=null">sex=#{sex},</if>
|
||||
<if test="mail!=null">mail=#{mail},</if>
|
||||
<if test="salt!=null">salt=#{salt},</if>
|
||||
<if test="password!=null">password=#{password},</if>
|
||||
<if test="isAdmin!=null">is_admin=#{isAdmin},</if>
|
||||
</set>
|
||||
WHERE id=#{id}
|
||||
</update>
|
||||
<!-- 批量更新 -->
|
||||
<update id="updateBatch">
|
||||
UPDATE
|
||||
<include refid="table"/>
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<trim prefix="modified_time=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
when id=#{obj.id} then now()
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="modifier=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.modifier!=null">
|
||||
when id=#{obj.id} then #{obj.modifier}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="name=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.name!=null">
|
||||
when id=#{obj.id} then #{obj.name}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="sex=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.sex!=null">
|
||||
when id=#{obj.id} then #{obj.sex}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="mail=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.mail!=null">
|
||||
when id=#{obj.id} then #{obj.mail}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="salt=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.salt!=null">
|
||||
when id=#{obj.id} then #{obj.salt}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="password=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.password!=null">
|
||||
when id=#{obj.id} then #{obj.password}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_admin=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.isAdmin!=null">
|
||||
when id=#{obj.id} then #{obj.isAdmin}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
</trim>
|
||||
<where>
|
||||
<foreach collection="list" separator="or" item="obj">
|
||||
id=#{obj.id}
|
||||
</foreach>
|
||||
</where>
|
||||
</update>
|
||||
<!-- 查找 -->
|
||||
<select id="findById" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
WHERE id=#{id}
|
||||
</select>
|
||||
<!-- 根据ids查找 -->
|
||||
<select id="findByIds" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<!-- 条件查询 -->
|
||||
<select id="find" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
<include refid="condition"/>
|
||||
</select>
|
||||
<!-- 查询所有 -->
|
||||
<select id="findAll" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
<select id="findByUserName" resultMap="resultMap">
|
||||
SELECT
|
||||
<include refid="columns"/>
|
||||
FROM
|
||||
<include refid="table"/>
|
||||
where user_name=#{userName}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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.xwbing.domain.mapper.sys.SysUserLoginInOutMapper">
|
||||
<resultMap id="resultMap" type="sysUserLoginInOut">
|
||||
<id column="id" property="id"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="modified_time" property="modifiedTime"/>
|
||||
<result column="inout_type" property="inoutType"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
</resultMap>
|
||||
<sql id="table">
|
||||
sys_user_login_in_out
|
||||
</sql>
|
||||
<sql id="columns">
|
||||
id,
|
||||
creator,
|
||||
modifier,
|
||||
create_time,
|
||||
modified_time,
|
||||
ip,
|
||||
inout_type,
|
||||
user_id
|
||||
</sql>
|
||||
<sql id="condition">
|
||||
<where>
|
||||
</where>
|
||||
</sql>
|
||||
<!-- 插入 -->
|
||||
<insert id="insert">
|
||||
<selectKey keyProperty="id" resultType="string" order="BEFORE">
|
||||
SELECT REPLACE(UUID(), '-', '')
|
||||
</selectKey>
|
||||
INSERT INTO
|
||||
<include refid="table"/>(
|
||||
id,
|
||||
creator,
|
||||
create_time,
|
||||
ip,
|
||||
inout_type,
|
||||
user_id
|
||||
)
|
||||
VALUES(
|
||||
#{id},
|
||||
#{creator},
|
||||
now(),
|
||||
#{ip},
|
||||
#{inoutType},
|
||||
#{userId}
|
||||
)
|
||||
</insert>
|
||||
<select id="findByInoutType" resultMap="resultMap">
|
||||
SELECT a.inout_type,a.ip,date_format(a.create_time,'%Y-%m-%d %h:%i:%s') recordTime,b.name userIdName
|
||||
FROM sys_user_login_in_out a left join sys_user_info b on
|
||||
(a.user_id=b.id)
|
||||
where a.inout_type=#{inout}
|
||||
<if test="startDate!=null">
|
||||
and a.create_time>=#{startDate}
|
||||
</if>
|
||||
<if test="endDate!=null">
|
||||
and a.create_time <![CDATA[ <= ]]> #{endDate}
|
||||
</if>
|
||||
ORDER BY a.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -128,6 +128,11 @@
|
||||
UPDATE
|
||||
<include refid="table"/>
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<trim prefix="modified_time=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
when id=#{obj.id} then now()
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="modifier=case" suffix="end,">
|
||||
<foreach collection="list" item="obj">
|
||||
<if test="obj.modifier!=null">
|
||||
|
||||
@@ -32,8 +32,8 @@ public class SysUserLoginInOutControl {
|
||||
@LogInfo("获取登录或登出信息")
|
||||
@ApiOperation(value = "获取登录或登出信息", response = ListSysUserLoginInOutVo.class)
|
||||
@GetMapping("listByType")
|
||||
public JSONObject listByType(@RequestParam int inout) {
|
||||
List<SysUserLoginInOut> sysUserLoginInOuts = inOutService.listByType(inout);
|
||||
public JSONObject listByType(@RequestParam int inout,@RequestParam String startDate,@RequestParam String endDate) {
|
||||
List<SysUserLoginInOut> sysUserLoginInOuts = inOutService.listByType(inout,startDate,endDate);
|
||||
return JsonResult.toJSONObj(sysUserLoginInOuts, "获取列表成功");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user