系统用户管理
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopPushOpenId;
|
||||
|
||||
/**
|
||||
* 用户推送信息表 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
public interface ShopPushOpenIdMapper extends BaseMapper<ShopPushOpenId> {
|
||||
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
if (sysUser == null) {
|
||||
throw new ApiNotPrintException("登录账号不存在");
|
||||
}
|
||||
if (StatusEnum.DISABLE.value() == sysUser.getStauts()) {
|
||||
if (StatusEnum.DISABLE.value() == sysUser.getStatus()) {
|
||||
throw new ApiNotPrintException("账户未启用");
|
||||
}
|
||||
|
||||
@@ -143,6 +143,9 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
if (shopStaffPromissionList != null && !shopStaffPromissionList.isEmpty()) {
|
||||
promissionList.addAll(shopStaffPromissionList);
|
||||
}
|
||||
if (user.getIsAdmin()) {
|
||||
promissionList.add("admin");
|
||||
}
|
||||
StpKit.USER.addPermissionList(promissionList);
|
||||
String platformType = ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType");
|
||||
if (PlatformTypeEnum.PC_CLIENT.getValue().equals(platformType)) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopPushOpenId;
|
||||
import com.czg.account.service.ShopPushOpenIdService;
|
||||
import com.czg.service.account.mapper.ShopPushOpenIdMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 用户推送信息表 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Service
|
||||
public class ShopPushOpenIdServiceImpl extends ServiceImpl<ShopPushOpenIdMapper, ShopPushOpenId> implements ShopPushOpenIdService{
|
||||
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.czg.account.dto.user.SysUserAddDTO;
|
||||
import com.czg.account.dto.user.SysUserEditDTO;
|
||||
import com.czg.account.entity.SysRole;
|
||||
import com.czg.account.entity.SysUser;
|
||||
import com.czg.account.entity.SysUsersRoles;
|
||||
@@ -12,11 +18,20 @@ import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.SysRoleMapper;
|
||||
import com.czg.service.account.mapper.SysUserMapper;
|
||||
import com.czg.service.account.mapper.SysUsersRolesMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.column;
|
||||
|
||||
/**
|
||||
* 系统用户 服务层实现。
|
||||
*
|
||||
@@ -42,7 +57,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
sysUser.setAccount(accountName);
|
||||
sysUser.setNickName(nickname);
|
||||
sysUser.setPhone(phone);
|
||||
sysUser.setStauts(1);
|
||||
sysUser.setStatus(1);
|
||||
sysUser.setCreateUserId(StpKit.USER.getLoginIdAsLong());
|
||||
save(sysUser);
|
||||
sysUser.setPassword(SecureUtil.md5(sysUser.getId() + accountPwd));
|
||||
@@ -68,6 +83,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
sysUser.setPassword(SecureUtil.md5(sysUser.getId() + accountPwd));
|
||||
sysUser.setUpdateUserId(sysUserId);
|
||||
sysUser.setUpdateTime(DateUtil.date().toLocalDateTime());
|
||||
sysUser.setPwdResetTime(DateUtil.date().toLocalDateTime());
|
||||
return updateById(sysUser);
|
||||
}
|
||||
|
||||
@@ -76,4 +92,99 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
sysUsersRolesMapper.deleteByQuery(new QueryWrapper().eq(SysUsersRoles::getUserId, id));
|
||||
return removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SysUser> getPage(String key, String startTime, String endTime, Integer status) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
if (StrUtil.isNotBlank(key)) {
|
||||
queryWrapper.and(column(SysUser::getAccount).like(key).or(column(SysUser::getNickName).like(key)));
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(startTime)) {
|
||||
queryWrapper.ge(SysUser::getCreateTime, DateUtil.parse(startTime));
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(endTime)) {
|
||||
queryWrapper.le(SysUser::getCreateTime, DateUtil.parse(endTime));
|
||||
}
|
||||
|
||||
if (status != null) {
|
||||
queryWrapper.eq(SysUser::getStatus, status);
|
||||
}
|
||||
return page(PageUtil.buildPage(), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(SysUserEditDTO sysUserEditDTO) {
|
||||
long count = count(new QueryWrapper().eq(SysUser::getAccount, sysUserEditDTO.getAccount()).ne(SysUser::getId, sysUserEditDTO.getId()));
|
||||
if (count > 0) {
|
||||
throw new ApiNotPrintException("账号已存在");
|
||||
}
|
||||
|
||||
SysUser sysUser = getById(sysUserEditDTO.getId());
|
||||
BeanUtil.copyProperties(sysUserEditDTO, sysUser);
|
||||
if (StrUtil.isNotBlank(sysUserEditDTO.getPassword())) {
|
||||
sysUser.setPassword(SecureUtil.md5(sysUser.getId() + sysUserEditDTO.getPassword()));
|
||||
sysUser.setPwdResetTime(DateUtil.date().toLocalDateTime());
|
||||
}
|
||||
|
||||
if (sysUserEditDTO.getRoleId() != null) {
|
||||
SysUsersRoles usersRoles = new SysUsersRoles();
|
||||
usersRoles.setRoleId(sysUserEditDTO.getRoleId());
|
||||
usersRoles.setUserId(sysUser.getId());
|
||||
sysUsersRolesMapper.updateByQuery(usersRoles, new QueryWrapper().eq(SysUsersRoles::getUserId, sysUser.getId()));
|
||||
}
|
||||
return updateById(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(Integer id) {
|
||||
SysUser sysUser = getById(id);
|
||||
if (sysUser == null) {
|
||||
throw new ApiNotPrintException("用户不存在");
|
||||
}
|
||||
int i = sysUsersRolesMapper.deleteByQuery(new QueryWrapper().eq(SysUsersRoles::getUserId, id));
|
||||
return i > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean add(SysUserAddDTO sysUserAddDTO) {
|
||||
long count = count(new QueryWrapper().eq(SysUser::getAccount, sysUserAddDTO.getAccount()));
|
||||
if (count > 0) {
|
||||
throw new ApiNotPrintException("账号已存在");
|
||||
}
|
||||
|
||||
SysUser sysUser = BeanUtil.copyProperties(sysUserAddDTO, SysUser.class);
|
||||
boolean save = save(sysUser);
|
||||
if (save) {
|
||||
sysUser.setPassword(SecureUtil.md5(sysUser.getId() + sysUserAddDTO.getPassword()));
|
||||
}
|
||||
|
||||
SysUsersRoles usersRoles = new SysUsersRoles();
|
||||
usersRoles.setRoleId(sysUserAddDTO.getRoleId());
|
||||
usersRoles.setUserId(sysUser.getId());
|
||||
sysUsersRolesMapper.insert(usersRoles);
|
||||
return updateById(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String key, String startTime, String endTime, Integer status, HttpServletResponse response) throws IOException {
|
||||
Page<SysUser> sysUserPage = getPage(key, startTime, endTime, status);
|
||||
List<SysUser> records = sysUserPage.getRecords();
|
||||
|
||||
// 1. 创建 ExcelWriter
|
||||
// true 表示使用 XLSX 格式
|
||||
ExcelWriter writer = ExcelUtil.getWriter(true);
|
||||
|
||||
// 2. 写入数据
|
||||
writer.write(records, true);
|
||||
|
||||
// 3. 设置响应头,返回 Excel
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("用户列表.xlsx", "UTF-8"));
|
||||
|
||||
// 4. 写入到响应流
|
||||
writer.flush(response.getOutputStream(), true);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?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.czg.service.account.mapper.ShopPushOpenIdMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user