完成票据分页查询,用户管理

This commit is contained in:
Ftz123456 2024-01-15 12:10:47 +08:00
parent 4c1c168be7
commit d5105a870c
27 changed files with 912 additions and 42 deletions

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM openjdk:18
LABEL authors="fantianzhi"
ADD target/bill-0.0.1-SNAPSHOT.jar /usr/src/bill/
WORKDIR /usr/src/bill
EXPOSE 8081
CMD ["java", "-jar", "bill-0.0.1-SNAPSHOT.jar"]

View File

@ -0,0 +1,30 @@
package com.zsc.edu.bill.common.enums;
import org.springframework.security.core.GrantedAuthority;
/**
* @author ftz
* 创建时间:11/1/2024 下午1:54
* 描述: 审核员权限
*/
public enum Auditor implements GrantedAuthority {
/**
* 用户管理
*/
USER_QUERY,
USER_CREATE,
/**
* 审核票据
*/
AUDIT_TICKET_QUERY,
AUDIT_TICKET_UPDATE;
@Override
public String getAuthority() {
return name();
}
}

View File

@ -0,0 +1,29 @@
package com.zsc.edu.bill.common.enums;
import org.springframework.security.core.GrantedAuthority;
/**
* @author ftz
* 创建时间:11/1/2024 下午2:04
* 描述: TODO
*/
public enum RegularUsers implements GrantedAuthority {
/**
* 用户管理
*/
USER_QUERY,
USER_CREATE,
USER_UPDATE,
/**
* 票据管理
*/
TICKET_QUERY,
TICKET_CREATE,
TICKET_UPDATE,
TICKET_DELETE;
@Override
public String getAuthority() {
return name();
}
}

View File

@ -17,6 +17,8 @@ import org.springframework.security.web.authentication.rememberme.JdbcTokenRepos
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository; import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import javax.sql.DataSource; import javax.sql.DataSource;
/** /**
@ -59,6 +61,7 @@ public class SpringSecurityConfig {
filter.setAuthenticationFailureHandler(customAuthenticationFailureHandler); filter.setAuthenticationFailureHandler(customAuthenticationFailureHandler);
filter.setFilterProcessesUrl("/api/rest/user/login"); filter.setFilterProcessesUrl("/api/rest/user/login");
filter.setAuthenticationManager(authenticationManager()); filter.setAuthenticationManager(authenticationManager());
filter.setSecurityContextRepository(new HttpSessionSecurityContextRepository());
return filter; return filter;
} }
@ -67,7 +70,8 @@ public class SpringSecurityConfig {
return http return http
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
.requestMatchers(HttpMethod.GET, "/api/rest/user/me").permitAll() .requestMatchers(HttpMethod.GET, "/api/rest/user/me","/api/rest/user/register").permitAll()
.requestMatchers(HttpMethod.POST, "/api/rest/user/login","/api/rest/user/register").permitAll()
.requestMatchers("/api/**").authenticated()) .requestMatchers("/api/**").authenticated())
.addFilterAt(jsonAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterAt(jsonAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.formLogin(form -> form .formLogin(form -> form
@ -86,7 +90,7 @@ public class SpringSecurityConfig {
.rememberMe(rememberMe -> rememberMe .rememberMe(rememberMe -> rememberMe
.userDetailsService(userDetailsService) .userDetailsService(userDetailsService)
.tokenRepository(persistentTokenRepository())) .tokenRepository(persistentTokenRepository()))
.csrf(csrf -> csrf.ignoringRequestMatchers("/api/internal/**", "/api/rest/user/logout")) .csrf(csrf -> csrf.ignoringRequestMatchers("/api/internal/**", "/api/rest/user/logout","/api/rest/user/register"))
.sessionManagement(session -> session .sessionManagement(session -> session
.maximumSessions(3) .maximumSessions(3)
.sessionRegistry(sessionRegistry) .sessionRegistry(sessionRegistry)

View File

@ -0,0 +1,64 @@
package com.zsc.edu.bill.modules.system.controller;
/**
* @author ftz
* 票据Controller
* 创建时间:11/1/2024 上午10:57
* 描述: 针对表ticket(票据表)的数据库操作Controller
*/
@AllArgsConstructor
@RestController
@RequestMapping("api/rest/ticket")
public class TicketController {
private final TicketService service;
/**
* 分页查询票据列表
* @return 票据列表
*/
@GetMapping("list")
public PageDto<TicketVo> list(TicketQuery query){
return service.tickePage(query);
}
/**
* 创建票据
* @return ture/false
*/
@PostMapping("create")
public Boolean create(Ticket ticket){
return service.save(ticket);
}
/**
* 更新票据
* @return ture/false
*/
@PostMapping("update")
public Boolean update(Ticket ticket){
return service.updateById(ticket);
}
/**
* 删除票据
* @return ture/false
*/
@PostMapping("delete")
public Boolean delete(Long id){
return service.removeById(id);
}
/**
* 批量删除票据
* @return ture/false
*/
@PostMapping("deleteBatch")
public Boolean deleteBatch(List<Long> ids){
return service.removeByIds(ids);
}
/**
* 获取票据详情
* @return 票据详情
*/
@GetMapping("detail")
public Ticket detail(Long id){
return service.getById(id);
}
}

View File

@ -2,10 +2,7 @@ package com.zsc.edu.bill.modules.system.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zsc.edu.bill.framework.security.UserDetailsImpl; import com.zsc.edu.bill.framework.security.UserDetailsImpl;
import com.zsc.edu.bill.modules.system.dto.UserCreateDto; import com.zsc.edu.bill.modules.system.dto.*;
import com.zsc.edu.bill.modules.system.dto.UserSelfUpdateDto;
import com.zsc.edu.bill.modules.system.dto.UserSelfUpdatePasswordDto;
import com.zsc.edu.bill.modules.system.dto.UserUpdateDto;
import com.zsc.edu.bill.modules.system.entity.User; import com.zsc.edu.bill.modules.system.entity.User;
import com.zsc.edu.bill.modules.system.query.UserQuery; import com.zsc.edu.bill.modules.system.query.UserQuery;
import com.zsc.edu.bill.modules.system.service.DeptService; import com.zsc.edu.bill.modules.system.service.DeptService;
@ -105,6 +102,18 @@ public class UserController {
public Page<UserVo> query(UserQuery query, PageDTO<User> page) { public Page<UserVo> query(UserQuery query, PageDTO<User> page) {
return service.page(query, page); return service.page(query, page);
} }
/**
* 分页查询用户信息2 hasAuthority('USER_QUERY')
*
* @param query 查询表单
* @return 分页用户信息
*/
@GetMapping("query")
@PreAuthorize("hasAuthority('USER_QUERY')")
public PageDto<UserVo> query2(UserQuery query) {
return service.queryUserPage(query);
}
/** /**
* 新建用户 hasAuthority('USER_CREATE') * 新建用户 hasAuthority('USER_CREATE')
@ -117,6 +126,15 @@ public class UserController {
public Boolean create(@RequestBody UserCreateDto dto) { public Boolean create(@RequestBody UserCreateDto dto) {
return service.create(dto); return service.create(dto);
} }
/**
* 注册用户
* @param dto 表单数据
* @return Boolean
*/
@PostMapping("register")
public Boolean register(@RequestBody UserCreateDto dto) {
return service.register(dto);
}
/** /**
* 更新用户 hasAuthority('USER_UPDATE') * 更新用户 hasAuthority('USER_UPDATE')

View File

@ -0,0 +1,26 @@
package com.zsc.edu.bill.modules.system.dto;
import lombok.Data;
import java.util.List;
/**
* @author ftz
* 创建时间:12/1/2024 下午1:55
* 描述: 分页查询
*/
@Data
public class PageDto<T> {
/**
* 总条数
*/
private Long total;
/**
* 总页数
*/
private Integer pages;
/**
* 集合
*/
private List<T> list;
}

View File

@ -0,0 +1,67 @@
package com.zsc.edu.bill.modules.system.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @author ftz
* 创建时间:11/1/2024 上午10:25
* 描述: TODO
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TicketDto {
/**
* 票据uuid 提供给前端显示用
*/
private String uuid;
/**
* 用户id 票据创建者id
*/
private Long userId;
/**
* 票据标题
*/
private String title;
/**
* 主体内容 票据详细内容
*/
private String body;
/**
* 金额 票据金额
*/
private BigDecimal money;
/**
* 状态 0:未提交草稿;1:未审核2:审核通过3:退回审核未通过
*/
private Integer status;
/**
* 票据类型
*/
private Integer ticketType;
/**
* 联系方式email邮箱
*/
private String contactEmail;
/**
* 客户公司名称 票据对应的企业名称
*/
private String companyName;
}

View File

@ -56,7 +56,7 @@ public class UserCreateDto {
/** /**
* 用户身份集合 * 用户身份集合
*/ */
@NotEmpty(message = "角色不能为空") //@NotEmpty(message = "角色不能为空")
public Set<Long> roleIds; public Set<Long> roleIds;
/** /**

View File

@ -28,6 +28,18 @@ public class UserSelfUpdateDto {
*/ */
@Email(message = "电子邮箱格式不对") @Email(message = "电子邮箱格式不对")
public String email; public String email;
/**
* 昵称
* */
public String nickName;
/**
* 头像
* */
public String avatar;
/**
* 地址
* */
public String address;
} }

View File

@ -0,0 +1,169 @@
package com.zsc.edu.bill.modules.system.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
/**
* 票据表
* @TableName ticket
*/
@TableName(value ="ticket")
@Data
public class Ticket extends BaseEntity implements Serializable{
/**
* 票据id 主键id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 票据uuid 提供给前端显示用
*/
private String uuid;
/**
* 用户id 票据创建者id
*/
private Long userId;
/**
* 票据标题
*/
private String title;
/**
* 主体内容 票据详细内容
*/
private String body;
/**
* 金额 票据金额
*/
private BigDecimal money;
/**
* 状态 0:未提交草稿;1:未审核2:审核通过3:退回审核未通过
*/
private Integer status;
/**
* 票据类型
*/
private Integer ticketType;
/**
* 联系方式email邮箱
*/
private String contactEmail;
/**
* 客户公司名称 票据对应的企业名称
*/
private String companyName;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Ticket other = (Ticket) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUuid() == null ? other.getUuid() == null : this.getUuid().equals(other.getUuid()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()))
&& (this.getBody() == null ? other.getBody() == null : this.getBody().equals(other.getBody()))
&& (this.getMoney() == null ? other.getMoney() == null : this.getMoney().equals(other.getMoney()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getTicketType() == null ? other.getTicketType() == null : this.getTicketType().equals(other.getTicketType()))
&& (this.getContactEmail() == null ? other.getContactEmail() == null : this.getContactEmail().equals(other.getContactEmail()))
&& (this.getCompanyName() == null ? other.getCompanyName() == null : this.getCompanyName().equals(other.getCompanyName()))
&& (this.getCreatedBy() == null ? other.getCreatedBy() == null : this.getCreatedBy().equals(other.getCreatedBy()))
&& (this.getCreatedTime() == null ? other.getCreatedTime() == null : this.getCreatedTime().equals(other.getCreatedTime()))
&& (this.getUpdatedBy() == null ? other.getUpdatedBy() == null : this.getUpdatedBy().equals(other.getUpdatedBy()))
&& (this.getUpdatedTime() == null ? other.getUpdatedTime() == null : this.getUpdatedTime().equals(other.getUpdatedTime()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getUuid() == null) ? 0 : getUuid().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
result = prime * result + ((getBody() == null) ? 0 : getBody().hashCode());
result = prime * result + ((getMoney() == null) ? 0 : getMoney().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getTicketType() == null) ? 0 : getTicketType().hashCode());
result = prime * result + ((getContactEmail() == null) ? 0 : getContactEmail().hashCode());
result = prime * result + ((getCompanyName() == null) ? 0 : getCompanyName().hashCode());
result = prime * result + ((getCreatedBy() == null) ? 0 : getCreatedBy().hashCode());
result = prime * result + ((getCreatedTime() == null) ? 0 : getCreatedTime().hashCode());
result = prime * result + ((getUpdatedBy() == null) ? 0 : getUpdatedBy().hashCode());
result = prime * result + ((getUpdatedTime() == null) ? 0 : getUpdatedTime().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", uuid=").append(uuid);
sb.append(", userId=").append(userId);
sb.append(", title=").append(title);
sb.append(", body=").append(body);
sb.append(", money=").append(money);
sb.append(", status=").append(status);
sb.append(", ticketType=").append(ticketType);
sb.append(", contactEmail=").append(contactEmail);
sb.append(", companyName=").append(companyName);
sb.append(", createdBy=").append(createdBy);
sb.append(", createdTime=").append(createdTime);
sb.append(", updatedBy=").append(updatedBy);
sb.append(", updatedTime=").append(updatedTime);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*; import lombok.*;
import java.util.Set;
/** /**
* 用户 * 用户
* *
@ -45,7 +43,11 @@ public class User extends BaseEntity {
* 启用状态 * 启用状态
*/ */
public Boolean enabled = true; public Boolean enabled = true;
/**
*
*昵称
* */
public String nickName;
/** /**
* 所属部门ID * 所属部门ID
@ -56,6 +58,14 @@ public class User extends BaseEntity {
* 角色ID * 角色ID
*/ */
public Long roleId; public Long roleId;
/**
* 头像
*/
public String avatar;
/**
* 地址
*/
public String address;
/** /**
* 所属部门 * 所属部门

View File

@ -0,0 +1,24 @@
package com.zsc.edu.bill.modules.system.mapper;
import com.zsc.edu.bill.common.mapstruct.BaseMapper;
import com.zsc.edu.bill.modules.system.dto.TicketDto;
import com.zsc.edu.bill.modules.system.entity.Ticket;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author fantianzhi
* @description 针对表ticket(票据表)的数据库操作Mapper
* @createDate 2024-01-11 10:13:22
* @Entity com.zsc.edu.bill.modules.system.entity.Ticket
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TicketMapper extends BaseMapper<TicketDto,Ticket> {
}

View File

@ -0,0 +1,28 @@
package com.zsc.edu.bill.modules.system.query;
import lombok.Data;
/**
* @author ftz
* 创建时间:12/1/2024 下午1:49
* 描述: 分页查询
*/
@Data
public class PageQuery {
/**
* 页码
*/
private Integer page;
/**
* 每页大小
*/
private Integer size;
/**
* 排序字段
*/
private String orderBy;
/**
* 是否升序
*/
private Boolean asc;
}

View File

@ -0,0 +1,80 @@
package com.zsc.edu.bill.modules.system.query;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.bill.modules.system.entity.Ticket;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
/**
* @author ftz
* 创建时间:11/1/2024 上午11:04
* 描述: 前端传递的查询参数
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TicketQuery extends PageQuery {
/**
* 票据uuid 提供给前端显示用
*/
private String uuid;
/**
* 用户id 票据创建者id
*/
private Long userId;
/**
* 票据标题
*/
private String title;
/**
* 主体内容 票据详细内容
*/
private String body;
/**
* 金额 票据金额
*/
private BigDecimal money;
/**
* 状态 0:未提交草稿;1:未审核2:审核通过3:退回审核未通过
*/
private Integer status;
/**
* 票据类型
*/
private Integer ticketType;
/**
* 联系方式email邮箱
*/
private String contactEmail;
/**
* 客户公司名称 票据对应的企业名称
*/
private String companyName;
public LambdaQueryWrapper<Ticket> wrapper() {
LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.hasText(this.uuid), Ticket::getUuid, this.uuid);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.userId)), Ticket::getUserId, this.userId);
queryWrapper.eq(StringUtils.hasText(this.title), Ticket::getTitle, this.title);
queryWrapper.eq(StringUtils.hasText(this.body), Ticket::getBody, this.body);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.money)), Ticket::getMoney, this.money);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.status)), Ticket::getStatus, this.status);
queryWrapper.eq(StringUtils.hasText(String.valueOf(this.ticketType)), Ticket::getTicketType, this.ticketType);
queryWrapper.eq(StringUtils.hasText(this.contactEmail), Ticket::getContactEmail, this.contactEmail);
queryWrapper.eq(StringUtils.hasText(this.companyName), Ticket::getCompanyName, this.companyName);
return queryWrapper;
}
}

View File

@ -1,13 +1,10 @@
package com.zsc.edu.bill.modules.system.query; package com.zsc.edu.bill.modules.system.query;
import com.zsc.edu.bill.modules.system.entity.User;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
import java.util.Objects;
import java.util.Set; import java.util.Set;
/** /**
@ -15,10 +12,11 @@ import java.util.Set;
* *
* @author harry yao * @author harry yao
*/ */
@EqualsAndHashCode(callSuper = true)
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class UserQuery { public class UserQuery extends PageQuery{
/** /**
* 用户名 * 用户名
@ -43,20 +41,21 @@ public class UserQuery {
/** /**
* 角色集合 * 角色集合
*/ */
public Set<Long> roleIds; public Long roleId;
/** /**
* 部门集合 * 部门集合
*/ */
public Set<Long> deptIds; public Set<Long> deptIds;
public LambdaQueryWrapper<User> wrapper() { // public LambdaQueryWrapper<User> wrapper() {
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StringUtils.hasText(this.username), User::getUsername, this.username); // queryWrapper.eq(StringUtils.hasText(this.username), User::getUsername, this.username);
queryWrapper.eq(StringUtils.hasText(this.phone), User::getPhone, this.phone); // queryWrapper.eq(StringUtils.hasText(this.phone), User::getPhone, this.phone);
queryWrapper.eq(StringUtils.hasText(this.email), User::getEmail, this.email); // queryWrapper.eq(StringUtils.hasText(this.email), User::getEmail, this.email);
queryWrapper.eq(Objects.nonNull(this.enable), User::getEnabled, this.enable); // queryWrapper.eq(Objects.nonNull(this.enable), User::getEnabled, this.enable);
return queryWrapper; // return queryWrapper;
} // }
} }

View File

@ -0,0 +1,13 @@
package com.zsc.edu.bill.modules.system.repo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsc.edu.bill.modules.system.entity.Ticket;
/**
* @author ftz
* 创建时间:11/1/2024 上午10:41
* 描述: TODO
*/
public interface TicketRepository extends BaseMapper<Ticket> {
}

View File

@ -1,5 +1,7 @@
package com.zsc.edu.bill.modules.system.repo; package com.zsc.edu.bill.modules.system.repo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.zsc.edu.bill.modules.system.entity.User; import com.zsc.edu.bill.modules.system.entity.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -31,4 +33,5 @@ public interface UserRepository extends BaseMapper<User> {
// User findByUsername(String username); // User findByUsername(String username);
User selectByUsername(String username); User selectByUsername(String username);
Page<UserVo> page2(PageDTO<User> page, LambdaQueryWrapper<User> wrapper);
} }

View File

@ -0,0 +1,19 @@
package com.zsc.edu.bill.modules.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zsc.edu.bill.modules.system.dto.PageDto;
import com.zsc.edu.bill.modules.system.entity.Ticket;
import com.zsc.edu.bill.modules.system.query.TicketQuery;
import com.zsc.edu.bill.modules.system.query.UserQuery;
import com.zsc.edu.bill.modules.system.vo.TicketVo;
/**
* @author fantianzhi
* @description 针对表ticket(票据表)的数据库操作Service
* @createDate 2024-01-11 10:13:22
*/
public interface TicketService extends IService<Ticket> {
PageDto<TicketVo> tickePage(TicketQuery query);
}

View File

@ -2,10 +2,7 @@ package com.zsc.edu.bill.modules.system.service;
import com.zsc.edu.bill.framework.security.UserDetailsImpl; import com.zsc.edu.bill.framework.security.UserDetailsImpl;
import com.zsc.edu.bill.modules.system.dto.UserCreateDto; import com.zsc.edu.bill.modules.system.dto.*;
import com.zsc.edu.bill.modules.system.dto.UserSelfUpdateDto;
import com.zsc.edu.bill.modules.system.dto.UserSelfUpdatePasswordDto;
import com.zsc.edu.bill.modules.system.dto.UserUpdateDto;
import com.zsc.edu.bill.modules.system.entity.User; import com.zsc.edu.bill.modules.system.entity.User;
import com.zsc.edu.bill.modules.system.query.UserQuery; import com.zsc.edu.bill.modules.system.query.UserQuery;
import com.zsc.edu.bill.modules.system.vo.UserVo; import com.zsc.edu.bill.modules.system.vo.UserVo;
@ -38,4 +35,10 @@ public interface UserService extends IService<User> {
Boolean toggle(Long id); Boolean toggle(Long id);
Page<UserVo> page(UserQuery query, PageDTO pageDTO); Page<UserVo> page(UserQuery query, PageDTO pageDTO);
Boolean register(UserCreateDto dto);
Page<UserVo> page2(UserQuery query, PageDTO<User> page);
PageDto<UserVo> queryUserPage(UserQuery query);
} }

View File

@ -0,0 +1,62 @@
package com.zsc.edu.bill.modules.system.service.impl;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.bill.modules.system.dto.PageDto;
import com.zsc.edu.bill.modules.system.entity.Ticket;
import com.zsc.edu.bill.modules.system.query.TicketQuery;
import com.zsc.edu.bill.modules.system.repo.TicketRepository;
import com.zsc.edu.bill.modules.system.service.TicketService;
import com.zsc.edu.bill.modules.system.vo.TicketVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author fantianzhi
* @description 针对表ticket(票据表)的数据库操作Service实现
* @createDate 2024-01-11 10:13:22
*/
@AllArgsConstructor
@Service
public class TicketServiceImpl extends ServiceImpl<TicketRepository, Ticket>
implements TicketService {
@Override
public PageDto<TicketVo> tickePage(TicketQuery query) {
Page<Ticket> page = Page.of(query.getPage(), query.getSize());
if (query.getOrderBy()!=null) {
page.addOrder(new OrderItem().setColumn(query.getOrderBy()).setAsc(query.getAsc()));
} else {
page.addOrder(new OrderItem().setColumn("id").setAsc(false));
}
Page<Ticket> ticketPage = lambdaQuery()
.eq(query.getUuid()!=null, Ticket::getUuid, query.getUuid())
.eq(query.getUserId()!=null, Ticket::getUserId, query.getUserId())
.eq(query.getTitle()!=null, Ticket::getTitle, query.getTitle())
.eq(query.getBody()!=null, Ticket::getBody, query.getBody())
.eq(query.getMoney()!=null, Ticket::getMoney, query.getMoney())
.eq(query.getStatus()!=null, Ticket::getStatus, query.getStatus())
.eq(query.getTicketType()!=null, Ticket::getTicketType, query.getTicketType())
.page(page);
PageDto<TicketVo> pageDto = new PageDto<>();
pageDto.setTotal(ticketPage.getTotal());
pageDto.setPages(Math.toIntExact(ticketPage.getPages()));
List<TicketVo> ticketVoList = ticketPage.getRecords().stream().map(ticket -> {
TicketVo ticketVo = new TicketVo();
BeanUtils.copyProperties(ticket, ticketVo);
return ticketVo;
}).toList();
pageDto.setList(ticketVoList);
return pageDto;
}
}

View File

@ -1,12 +1,11 @@
package com.zsc.edu.bill.modules.system.service.impl; package com.zsc.edu.bill.modules.system.service.impl;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.bill.exception.ConstraintException; import com.zsc.edu.bill.exception.ConstraintException;
import com.zsc.edu.bill.framework.security.UserDetailsImpl; import com.zsc.edu.bill.framework.security.UserDetailsImpl;
import com.zsc.edu.bill.modules.system.dto.UserCreateDto; import com.zsc.edu.bill.modules.system.dto.*;
import com.zsc.edu.bill.modules.system.dto.UserSelfUpdateDto; import com.zsc.edu.bill.modules.system.entity.Role;
import com.zsc.edu.bill.modules.system.dto.UserSelfUpdatePasswordDto;
import com.zsc.edu.bill.modules.system.dto.UserUpdateDto;
import com.zsc.edu.bill.modules.system.entity.User; import com.zsc.edu.bill.modules.system.entity.User;
import com.zsc.edu.bill.modules.system.query.UserQuery; import com.zsc.edu.bill.modules.system.query.UserQuery;
import com.zsc.edu.bill.modules.system.repo.UserRepository; import com.zsc.edu.bill.modules.system.repo.UserRepository;
@ -21,6 +20,8 @@ import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* <p> * <p>
* 服务实现类 * 服务实现类
@ -34,6 +35,7 @@ import org.springframework.stereotype.Service;
public class UserServiceImpl extends ServiceImpl<UserRepository, User> implements UserService { public class UserServiceImpl extends ServiceImpl<UserRepository, User> implements UserService {
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final RoleServiceImpl roleService;
@Override @Override
@ -76,13 +78,64 @@ public class UserServiceImpl extends ServiceImpl<UserRepository, User> implement
public Page<UserVo> page(UserQuery query, PageDTO pageDTO) { public Page<UserVo> page(UserQuery query, PageDTO pageDTO) {
//2.构造连表查询的动态SQL代码 //2.构造连表查询的动态SQL代码
QueryWrapper<User> wrapper = new QueryWrapper<>(); QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.like(!query.getUsername().isBlank(), "u.username", query.getUsername()) // wrapper.like(!query.getUsername().isBlank(), "u.username", query.getUsername())
.in(query.deptIds != null && !query.deptIds.isEmpty(), "d.id", query.getDeptIds()) // wrapper
.in(query.roleIds != null && !query.roleIds.isEmpty(), "r.id", query.getRoleIds()); // .in(query.deptIds != null && !query.deptIds.isEmpty(), "d.id", query.getDeptIds())
// .in(query.roleId != null && !query.roleId.isEmpty(), "r.id", query.getRoleId());
//3.Mapper层连表查询SQL语句并把动态查询的代码段传递给Mapper接 //3.Mapper层连表查询SQL语句并把动态查询的代码段传递给Mapper接
return this.baseMapper.page(pageDTO, wrapper); return this.baseMapper.page(pageDTO, wrapper);
} }
@Override
public Boolean register(UserCreateDto dto) {
User user = new User();
BeanUtils.copyProperties(dto, user);
if (count(new LambdaQueryWrapper<User>().eq(User::getPhone, dto.getPhone())) > 0) {
throw new ConstraintException("phone", dto.phone, "手机号已存在");
}
if (count(new LambdaQueryWrapper<User>().eq(User::getEmail, dto.getEmail())) > 0) {
throw new ConstraintException("email", dto.email, "邮箱地址已存在");
}
user.setPassword(passwordEncoder.encode(dto.password));
user.setRoleId(roleService.getOne(new LambdaQueryWrapper<Role>().eq(Role::getName, "普通用户")).getId());
return save(user);
}
@Override
public Page<UserVo> page2(UserQuery query, PageDTO<User> page) {
QueryWrapper<User> wrapper = new QueryWrapper<>();
return this.baseMapper.page(page, wrapper);
}
@Override
public PageDto<UserVo> queryUserPage(UserQuery query) {
String username = query.getUsername();
String phone = query.getPhone();
String email = query.getEmail();
Page<User> page = Page.of(query.getPage(), query.getSize());
if (query.getOrderBy()!=null) {
page.addOrder(new OrderItem().setColumn(query.getOrderBy()).setAsc(query.getAsc()));
} else {
page.addOrder(new OrderItem().setColumn("id").setAsc(false));
}
Page<User> p = lambdaQuery()
.like(username != null && !username.isBlank(), User::getUsername, username)
.like(phone != null && !phone.isBlank(), User::getPhone, phone)
.like(email != null && !email.isBlank(), User::getEmail, email)
.page(page);
PageDto<UserVo> dto = new PageDto<>();
dto.setTotal(p.getTotal());
dto.setPages((int) p.getPages());
List<UserVo> list = p.getRecords().stream().map(user -> {
UserVo vo = new UserVo();
BeanUtils.copyProperties(user, vo);
return vo;
}).toList();
dto.setList(list);
return dto;
}
@Override @Override
public User selfDetail(UserDetailsImpl userDetails) { public User selfDetail(UserDetailsImpl userDetails) {
return getById(userDetails.getId()); return getById(userDetails.getId());

View File

@ -0,0 +1,76 @@
package com.zsc.edu.bill.modules.system.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author ftz
* 创建时间:13/1/2024 下午3:00
* 描述: 票据vo
*/
@Data
public class TicketVo {
private String uuid;
/**
* 用户id 票据创建者id
*/
private Long userId;
/**
* 票据标题
*/
private String title;
/**
* 主体内容 票据详细内容
*/
private String body;
/**
* 金额 票据金额
*/
private BigDecimal money;
/**
* 状态 0:未提交草稿;1:未审核2:审核通过3:退回审核未通过
*/
private Integer status;
/**
* 票据类型
*/
private Integer ticketType;
/**
* 联系方式email邮箱
*/
private String contactEmail;
/**
* 客户公司名称 票据对应的企业名称
*/
private String companyName;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
}

View File

@ -6,10 +6,49 @@ import java.time.LocalDateTime;
@Data @Data
public class UserVo { public class UserVo {
String username; /**
String phone; * 用户名
String email; */
Boolean enabled; public String username;
/**
* 手机号码
*/
public String phone;
/**
* 电子邮件
*/
public String email;
/**
* 启用状态
*/
public Boolean enabled;
/**
*
*昵称
* */
public String nickName;
/**
* 所属部门ID
*/
public Long deptId;
/**
* 角色ID
*/
public Long roleId;
/**
* 头像
*/
public String avatar;
/**
* 地址
*/
public String address;
LocalDateTime createTime; LocalDateTime createTime;
LocalDateTime updateTime; LocalDateTime updateTime;
} }

View File

@ -1,5 +1,5 @@
server: server:
port: 8080 port: 8081
mybatis-plus: mybatis-plus:
type-aliases-package: com.zsc.edu.bill.modules.*.entity type-aliases-package: com.zsc.edu.bill.modules.*.entity
@ -9,7 +9,7 @@ mybatis-plus:
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/study?useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true&characterEncoding=utf8&serverTimezone=Hongkong url: jdbc:mysql://59.110.238.182:3306/study?useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true&characterEncoding=utf8&serverTimezone=Hongkong
username: root username: root
password: 123123 password: 2002
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver

View File

@ -0,0 +1,31 @@
<?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.zsc.edu.bill.modules.system.mapper.TicketMapper">
<resultMap id="BaseResultMap" type="com.zsc.edu.bill.modules.system.entity.Ticket">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="uuid" column="uuid" jdbcType="VARCHAR"/>
<result property="userId" column="user_id" jdbcType="BIGINT"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="body" column="body" jdbcType="VARCHAR"/>
<result property="money" column="money" jdbcType="DECIMAL"/>
<result property="status" column="status" jdbcType="TINYINT"/>
<result property="ticketType" column="ticket_type" jdbcType="TINYINT"/>
<result property="contactEmail" column="contact_email" jdbcType="VARCHAR"/>
<result property="companyName" column="company_name" jdbcType="VARCHAR"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="updatedBy" column="updated_by" jdbcType="VARCHAR"/>
<result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,uuid,user_id,
title,body,money,
status,ticket_type,contact_email,
company_name,created_by,created_time,
updated_by,updated_time
</sql>
</mapper>

View File

@ -9,6 +9,9 @@
<result column="dept_id" jdbcType="BIGINT" property="deptId"/> <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
<result column="email" jdbcType="VARCHAR" property="email"/> <result column="email" jdbcType="VARCHAR" property="email"/>
<result column="phone" jdbcType="VARCHAR" property="phone"/> <result column="phone" jdbcType="VARCHAR" property="phone"/>
<result column="nick_name" jdbcType="INTEGER" property="nickName"/>
<result column="avatar" jdbcType="VARCHAR" property="avatar"/>
<result column="address" jdbcType="VARCHAR" property="address"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<collection property="role" ofType="com.zsc.edu.bill.modules.system.entity.Role"> <collection property="role" ofType="com.zsc.edu.bill.modules.system.entity.Role">
<id column="id" jdbcType="BIGINT" property="id"/> <id column="id" jdbcType="BIGINT" property="id"/>