系统用户管理
This commit is contained in:
parent
2af118bb57
commit
f81a4a8cbf
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.controller.admin;
|
||||||
|
|
||||||
|
import com.czg.resp.CzgResult;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺消息推送相关
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/shopMsgPush")
|
||||||
|
public class ShopMsgPushController {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
package com.czg.controller.admin;
|
||||||
|
|
||||||
|
import com.czg.account.dto.user.SysUserAddDTO;
|
||||||
|
import com.czg.account.dto.user.SysUserEditDTO;
|
||||||
|
import com.czg.account.entity.SysUser;
|
||||||
|
import com.czg.account.entity.SysUsersRoles;
|
||||||
|
import com.czg.account.service.SysUserService;
|
||||||
|
import com.czg.annotation.SaAdminCheckPermission;
|
||||||
|
import com.czg.annotation.SaAdminCheckRole;
|
||||||
|
import com.czg.resp.CzgResult;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统用户管理
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/sysUser")
|
||||||
|
public class SysController {
|
||||||
|
@Resource
|
||||||
|
private SysUserService sysUserService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统用户列表
|
||||||
|
* @param key 名称或邮箱搜索
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @param endTime 结束时间
|
||||||
|
* @param status 状态:1启用、0禁用
|
||||||
|
* @return 分页数据
|
||||||
|
*/
|
||||||
|
// @SaAdminCheckPermission("sysUser:list")
|
||||||
|
@SaAdminCheckRole("admin")
|
||||||
|
@GetMapping
|
||||||
|
public CzgResult<Page<SysUser>> list(String key, String startTime, String endTime, Integer status) {
|
||||||
|
return CzgResult.success(sysUserService.getPage(key, startTime, endTime, status));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统账号修改
|
||||||
|
* @param sysUserEditDTO 修改信息
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
// @SaAdminCheckPermission("sysUser:edit")
|
||||||
|
@SaAdminCheckRole("admin")
|
||||||
|
@PutMapping
|
||||||
|
public CzgResult<Boolean> edit(@RequestBody @Validated SysUserEditDTO sysUserEditDTO) {
|
||||||
|
return CzgResult.success(sysUserService.edit(sysUserEditDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统用户删除
|
||||||
|
* @param id 用户id
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
// @SaAdminCheckPermission("sysUser:del")
|
||||||
|
@SaAdminCheckRole("admin")
|
||||||
|
@DeleteMapping
|
||||||
|
public CzgResult<Boolean> del(@RequestParam Integer id) {
|
||||||
|
return CzgResult.success(sysUserService.delete(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统用户添加
|
||||||
|
* @param sysUserAddDTO 添加信息
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@SaAdminCheckRole("admin")
|
||||||
|
@PostMapping
|
||||||
|
public CzgResult<Boolean> add(@RequestBody @Validated SysUserAddDTO sysUserAddDTO) {
|
||||||
|
return CzgResult.success(sysUserService.add(sysUserAddDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统用户导出
|
||||||
|
* @param key 名称或邮箱搜索
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @param endTime 结束时间
|
||||||
|
* @param status 状态:1启用、0禁用
|
||||||
|
* @throws IOException IO异常
|
||||||
|
*/
|
||||||
|
@SaAdminCheckRole("admin")
|
||||||
|
@GetMapping("/download")
|
||||||
|
public void download(String key, String startTime, String endTime, Integer status, HttpServletResponse response) throws IOException {
|
||||||
|
sysUserService.download(key, startTime, endTime, status, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
|
||||||
|
package com.czg.account.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import java.io.Serial;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户推送信息表 实体类。
|
||||||
|
*
|
||||||
|
* @author zs
|
||||||
|
* @since 2025-03-03
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ShopPushOpenIdDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信openid
|
||||||
|
*/
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态 1 正常 0 禁用
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.czg.account.dto.user;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysUserAddDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "账号不为空")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "昵称不为空")
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "性别不为空")
|
||||||
|
private String gender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "手机号不为空")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "邮箱不为空")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "头像不为空")
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "密码不为空")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为admin账号
|
||||||
|
*/
|
||||||
|
@NotNull(message = "是否为admin账号不为空")
|
||||||
|
private Boolean isAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:1启用、0禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色id
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
package com.czg.account.dto.user;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysUserEditDTO {
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "ID不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@Size(min = 1, message = "账号不为空")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
@Size(min = 1, message = "昵称不为空")
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
private String gender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号码
|
||||||
|
*/
|
||||||
|
@Size(min = 1, message = "手机号不为空")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
@Size(min = 1, message = "邮箱不为空")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
@Size(min = 1, message = "头像不为空")
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@Size(min = 1, message = "密码不为空")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为admin账号
|
||||||
|
*/
|
||||||
|
private Boolean isAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:1启用、0禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
*/
|
||||||
|
private Long createUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新者
|
||||||
|
*/
|
||||||
|
private Long updateUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码的时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime pwdResetTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色id
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.czg.account.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户推送信息表 实体类。
|
||||||
|
*
|
||||||
|
* @author zs
|
||||||
|
* @since 2025-03-03
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table("tb_shop_push_open_id")
|
||||||
|
public class ShopPushOpenId implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信openid
|
||||||
|
*/
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态 1 正常 0 禁用
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ public class SysUser implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 状态:1启用、0禁用
|
* 状态:1启用、0禁用
|
||||||
*/
|
*/
|
||||||
private Integer stauts;
|
private Integer status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建者
|
* 创建者
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.account.service;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
import com.czg.account.entity.ShopPushOpenId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户推送信息表 服务层。
|
||||||
|
*
|
||||||
|
* @author zs
|
||||||
|
* @since 2025-03-03
|
||||||
|
*/
|
||||||
|
public interface ShopPushOpenIdService extends IService<ShopPushOpenId> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
package com.czg.account.service;
|
package com.czg.account.service;
|
||||||
|
|
||||||
|
import com.czg.account.dto.user.SysUserAddDTO;
|
||||||
|
import com.czg.account.dto.user.SysUserEditDTO;
|
||||||
import com.czg.account.entity.SysUser;
|
import com.czg.account.entity.SysUser;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户 服务层。
|
* 系统用户 服务层。
|
||||||
|
|
@ -16,4 +22,14 @@ public interface SysUserService extends IService<SysUser> {
|
||||||
Boolean updateSysUserPwd(long sysUserId, String accountPwd);
|
Boolean updateSysUserPwd(long sysUserId, String accountPwd);
|
||||||
|
|
||||||
Boolean removeUserAndRole(Long id);
|
Boolean removeUserAndRole(Long id);
|
||||||
|
|
||||||
|
Page<SysUser> getPage(String key, String startTime, String endTime, Integer status);
|
||||||
|
|
||||||
|
Boolean edit(SysUserEditDTO sysUserEditDTO);
|
||||||
|
|
||||||
|
Boolean delete(Integer id);
|
||||||
|
|
||||||
|
Boolean add(SysUserAddDTO sysUserAddDTO);
|
||||||
|
|
||||||
|
void download(String key, String startTime, String endTime, Integer status, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
if (sysUser == null) {
|
||||||
throw new ApiNotPrintException("登录账号不存在");
|
throw new ApiNotPrintException("登录账号不存在");
|
||||||
}
|
}
|
||||||
if (StatusEnum.DISABLE.value() == sysUser.getStauts()) {
|
if (StatusEnum.DISABLE.value() == sysUser.getStatus()) {
|
||||||
throw new ApiNotPrintException("账户未启用");
|
throw new ApiNotPrintException("账户未启用");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,6 +143,9 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||||
if (shopStaffPromissionList != null && !shopStaffPromissionList.isEmpty()) {
|
if (shopStaffPromissionList != null && !shopStaffPromissionList.isEmpty()) {
|
||||||
promissionList.addAll(shopStaffPromissionList);
|
promissionList.addAll(shopStaffPromissionList);
|
||||||
}
|
}
|
||||||
|
if (user.getIsAdmin()) {
|
||||||
|
promissionList.add("admin");
|
||||||
|
}
|
||||||
StpKit.USER.addPermissionList(promissionList);
|
StpKit.USER.addPermissionList(promissionList);
|
||||||
String platformType = ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType");
|
String platformType = ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType");
|
||||||
if (PlatformTypeEnum.PC_CLIENT.getValue().equals(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;
|
package com.czg.service.account.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
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.SysRole;
|
||||||
import com.czg.account.entity.SysUser;
|
import com.czg.account.entity.SysUser;
|
||||||
import com.czg.account.entity.SysUsersRoles;
|
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.SysRoleMapper;
|
||||||
import com.czg.service.account.mapper.SysUserMapper;
|
import com.czg.service.account.mapper.SysUserMapper;
|
||||||
import com.czg.service.account.mapper.SysUsersRolesMapper;
|
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.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.stereotype.Service;
|
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.setAccount(accountName);
|
||||||
sysUser.setNickName(nickname);
|
sysUser.setNickName(nickname);
|
||||||
sysUser.setPhone(phone);
|
sysUser.setPhone(phone);
|
||||||
sysUser.setStauts(1);
|
sysUser.setStatus(1);
|
||||||
sysUser.setCreateUserId(StpKit.USER.getLoginIdAsLong());
|
sysUser.setCreateUserId(StpKit.USER.getLoginIdAsLong());
|
||||||
save(sysUser);
|
save(sysUser);
|
||||||
sysUser.setPassword(SecureUtil.md5(sysUser.getId() + accountPwd));
|
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.setPassword(SecureUtil.md5(sysUser.getId() + accountPwd));
|
||||||
sysUser.setUpdateUserId(sysUserId);
|
sysUser.setUpdateUserId(sysUserId);
|
||||||
sysUser.setUpdateTime(DateUtil.date().toLocalDateTime());
|
sysUser.setUpdateTime(DateUtil.date().toLocalDateTime());
|
||||||
|
sysUser.setPwdResetTime(DateUtil.date().toLocalDateTime());
|
||||||
return updateById(sysUser);
|
return updateById(sysUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,4 +92,99 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||||
sysUsersRolesMapper.deleteByQuery(new QueryWrapper().eq(SysUsersRoles::getUserId, id));
|
sysUsersRolesMapper.deleteByQuery(new QueryWrapper().eq(SysUsersRoles::getUserId, id));
|
||||||
return removeById(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>
|
||||||
Loading…
Reference in New Issue