resList = BeanUtil.copyToList(list, cls);
51 | return resList;
52 | }
53 |
54 |
55 | /**
56 | * 设置请求降序排序
57 | */
58 | protected PageInfo startOrderByDesc(int pageNumb, int pageSize, String filed, ISelect select)
59 | {
60 | return PageUtil.orderByDesc(pageNumb, pageSize, filed, select);
61 | }
62 |
63 |
64 | /**
65 | * 设置请求升序排序
66 | */
67 | protected PageInfo startOrderByAsc(int pageNumb, int pageSize, String filed, ISelect select)
68 | {
69 | return PageUtil.orderByAsc(pageNumb, pageSize, filed, select);
70 | }
71 |
72 |
73 | /**
74 | * 清理线程变量
75 | */
76 | protected void cleanPage()
77 | {
78 | PageUtil.clearPage();
79 | }
80 |
81 |
82 | protected PageResult success(Object data,long total){
83 | return PageResult.success(data,total);
84 | }
85 |
86 |
87 | /**
88 | * 返回成功响应结果
89 | *
90 | * @return 成功响应
91 | */
92 | protected AjaxResult success()
93 | {
94 | return AjaxResult.success();
95 |
96 | }
97 |
98 | /**
99 | * 返回成功响应结果
100 | *
101 | * @param mes 成功消息
102 | * @return 成功响应
103 | */
104 | protected AjaxResult success(String mes)
105 | {
106 | return AjaxResult.success(mes);
107 | }
108 |
109 | /**
110 | * 返回成功响应
111 | *
112 | * @param data 成功内容
113 | * @return 成功响应
114 | */
115 | protected AjaxResult success(Object data)
116 | {
117 | return AjaxResult.success(data);
118 | }
119 |
120 | /**
121 | * 返回警告响应
122 | *
123 | * @param mes 警告信息
124 | * @return 警告响应
125 | */
126 | protected AjaxResult warn(String mes)
127 | {
128 | return AjaxResult.warn(mes);
129 | }
130 |
131 | /**
132 | * 返回警告响应
133 | *
134 | * @param data 警告内容
135 | * @param mes 警告信息
136 | * @return 警告响应
137 | */
138 | protected AjaxResult warn(Object data, String mes)
139 | {
140 | return AjaxResult.warn(data, mes);
141 | }
142 |
143 |
144 | /**
145 | * 返回失败响应结果
146 | *
147 | * @return 失败响应
148 | */
149 | protected AjaxResult error()
150 | {
151 | return AjaxResult.error();
152 | }
153 |
154 | /**
155 | * 返回失败响应结果
156 | *
157 | * @param mes
158 | * @return 失败响应
159 | */
160 | protected AjaxResult error(String mes)
161 | {
162 | return AjaxResult.error(mes);
163 | }
164 |
165 | /**
166 | * 最后返回响应结果
167 | *
168 | * @param data 响应数据
169 | * @return 响应结果
170 | */
171 | protected AjaxResult toAjax(Object data)
172 | {
173 | return success(data);
174 | }
175 |
176 | protected PageResult toAjax(PageInfo pageInfo){
177 | return PageResult.success(pageInfo.getList(),pageInfo.getTotal());
178 | }
179 |
180 | /**
181 | * 最后返回响应结果
182 | *
183 | * @param results 增、删、改...等修改行为的响应结果
184 | * @return 响应结果
185 | */
186 | protected AjaxResult toAjax(boolean results)
187 | {
188 | return results ? success() : error();
189 | }
190 |
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/Contract.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableName;
6 | import java.io.Serializable;
7 | import java.time.LocalDateTime;
8 |
9 | import com.jzm.backme.annotation.NotEmpty;
10 | import com.jzm.backme.controller.base.BaseBaseEntity;
11 | import com.jzm.backme.domain.base.BaseEntity;
12 | import com.jzm.backme.util.user.UserUtil;
13 | import io.swagger.annotations.ApiModel;
14 | import io.swagger.annotations.ApiModelProperty;
15 | import lombok.Getter;
16 | import lombok.Setter;
17 |
18 | /**
19 | *
20 | * 合同表 -- 存储合同信息
21 | *
22 | *
23 | * @author qhx2004
24 | * @since 2024-04-15
25 | */
26 | @Getter
27 | @Setter
28 | @TableName("contract")
29 | @ApiModel(value = "Contract对象", description = "合同表 -- 存储合同信息")
30 | public class Contract extends BaseBaseEntity implements Serializable {
31 |
32 | private static final long serialVersionUID = 1L;
33 |
34 | @ApiModelProperty("合同id")
35 | @TableId(value = "contract_id", type = IdType.AUTO)
36 | private Long contractId;
37 |
38 | @NotEmpty(extra = "房屋编号")
39 | private Long houseId;
40 |
41 | private Long landlordId;
42 |
43 | @ApiModelProperty("0 未签署 1签署")
44 | private String sign;
45 |
46 | @ApiModelProperty("合同编号")
47 | private String contractNum;
48 |
49 | @ApiModelProperty("签署日期")
50 | private LocalDateTime signTime;
51 |
52 | @ApiModelProperty("停止日期")
53 | private LocalDateTime stopTime;
54 |
55 |
56 | public static void main(String[] args)
57 | {
58 | System.out.println(UserUtil.cryptPass("123458"));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/House.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableName;
6 | import java.io.Serializable;
7 | import java.time.LocalDateTime;
8 |
9 | import com.jzm.backme.annotation.NotEmpty;
10 | import com.jzm.backme.domain.base.BaseEntity;
11 | import io.swagger.annotations.ApiModel;
12 | import io.swagger.annotations.ApiModelProperty;
13 | import lombok.Getter;
14 | import lombok.Setter;
15 |
16 | /**
17 | *
18 | * 房屋表 -- 存储房屋信息
19 | *
20 | *
21 | * @author qhx2004
22 | * @since 2024-04-15
23 | */
24 | @Getter
25 | @Setter
26 | @TableName("house")
27 | @ApiModel(value = "House对象", description = "房屋表 -- 存储房屋信息")
28 | public class House extends BaseEntity implements Serializable {
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | @TableId(value = "house_id", type = IdType.AUTO)
33 | private Long houseId;
34 |
35 | @ApiModelProperty("房屋地址")
36 | @NotEmpty(extra = "房屋地址")
37 | private String address;
38 |
39 | @ApiModelProperty("房东id")
40 | private Long landlordId;
41 |
42 | @ApiModelProperty("联系人")
43 | @NotEmpty(extra = "联系人")
44 | private String linkMan;
45 |
46 | @ApiModelProperty("联系电话")
47 | @NotEmpty(extra = "联系电话")
48 | private String linkPhone;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/Payment.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableName;
6 | import java.io.Serializable;
7 | import java.time.LocalDateTime;
8 |
9 | import com.jzm.backme.controller.base.BaseBaseEntity;
10 | import com.jzm.backme.domain.base.BaseEntity;
11 | import io.swagger.annotations.ApiModel;
12 | import io.swagger.annotations.ApiModelProperty;
13 | import lombok.Getter;
14 | import lombok.Setter;
15 |
16 | /**
17 | *
18 | * 缴纳记录表 -- 记录租金缴纳信息
19 | *
20 | *
21 | * @author qhx2004
22 | * @since 2024-04-15
23 | */
24 | @Getter
25 | @Setter
26 | @TableName("payment")
27 | @ApiModel(value = "Payment对象", description = "缴纳记录表 -- 记录租金缴纳信息")
28 | public class Payment extends BaseBaseEntity implements Serializable {
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | @ApiModelProperty("缴纳记录id")
33 | @TableId(value = "payment_id", type = IdType.AUTO)
34 | private Long paymentId;
35 |
36 | @ApiModelProperty("缴纳人账户地址")
37 | private String payer;
38 |
39 | @ApiModelProperty("缴纳人用户id")
40 | private Long payerId;
41 |
42 | @ApiModelProperty("合同序列码")
43 | private String contractNum;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/Role.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableName;
4 | import java.io.Serializable;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.AllArgsConstructor;
8 | import lombok.Data;
9 | import lombok.Getter;
10 | import lombok.Setter;
11 |
12 | /**
13 | *
14 | * 角色表
15 | *
16 | *
17 | * @author qhx2004
18 | * @since 2024-04-14
19 | */
20 | @Getter
21 | @Setter
22 | @TableName("role")
23 | @ApiModel(value = "Role对象", description = " 角色表")
24 | @AllArgsConstructor
25 | public class Role implements Serializable {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | private Long roleId;
30 |
31 | private String roleName;
32 | }
33 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.baomidou.mybatisplus.annotation.TableName;
6 | import java.io.Serializable;
7 | import java.time.LocalDateTime;
8 |
9 | import com.jzm.backme.annotation.NotEmpty;
10 | import com.jzm.backme.domain.base.BaseEntity;
11 | import io.swagger.annotations.ApiModel;
12 | import io.swagger.annotations.ApiModelProperty;
13 | import lombok.Getter;
14 | import lombok.Setter;
15 |
16 | /**
17 | *
18 | * 用户表 -- 存储用户信息
19 | *
20 | *
21 | * @author qhx2004
22 | * @since 2024-04-15
23 | */
24 | @Getter
25 | @Setter
26 | @TableName("user")
27 | @ApiModel(value = "User对象", description = "用户表 -- 存储用户信息")
28 | public class User extends BaseEntity implements Serializable {
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | @TableId(value = "user_id", type = IdType.AUTO)
33 | private Long userId;
34 |
35 | private String username;
36 |
37 | @ApiModelProperty("用户区块链账户地址")
38 | @NotEmpty(extra = "区块链账户地址")
39 | private String user;
40 |
41 | @NotEmpty(extra = "用户电话")
42 | private String phone;
43 |
44 | @ApiModelProperty("用户密码")
45 | @NotEmpty(extra = "密码")
46 | private String password;
47 |
48 | private String sex;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/UserRole.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableName;
4 | import java.io.Serializable;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Getter;
8 | import lombok.Setter;
9 |
10 | /**
11 | *
12 | * 用户 - 角色表
13 | *
14 | *
15 | * @author qhx2004
16 | * @since 2024-04-15
17 | */
18 | @Getter
19 | @Setter
20 | @TableName("user_role")
21 | @ApiModel(value = "UserRole对象", description = "用户 - 角色表")
22 | public class UserRole implements Serializable {
23 |
24 | private static final long serialVersionUID = 1L;
25 |
26 | private Long userId;
27 |
28 | private Long roleId;
29 | }
30 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/domain/base/BaseEntity.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.domain.base;
2 |
3 | import com.jzm.backme.controller.base.BaseBaseEntity;
4 | import io.swagger.annotations.ApiModelProperty;
5 | import lombok.Data;
6 |
7 | @Data
8 | public abstract class BaseEntity extends BaseBaseEntity
9 | {
10 |
11 | @ApiModelProperty("状态")
12 | private String status;
13 |
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/exception/CustomException.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.exception;
2 |
3 | import com.jzm.backme.exception.base.BaseException;
4 |
5 | /**
6 | * @author: jzm
7 | * @date: 2024-04-14 20:47
8 | **/
9 |
10 | public class CustomException extends BaseException
11 | {
12 |
13 | public CustomException(String message)
14 | {
15 | super(message,400);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/exception/PermissionException.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.exception;
2 |
3 |
4 | import com.jzm.backme.exception.base.BaseException;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-03-07 20:34
9 | **/
10 |
11 | public class PermissionException extends BaseException
12 | {
13 | public PermissionException(String message, int code)
14 | {
15 | super(message, code);
16 | }
17 |
18 | public PermissionException(String message)
19 | {
20 | super(message);
21 | }
22 |
23 | public PermissionException(){
24 | this("操作者权限不足");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/exception/base/BaseException.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.exception.base;
2 |
3 |
4 | import lombok.Data;
5 |
6 | /**
7 | * 基础异常
8 | *
9 | * @author jzm
10 | */
11 | @Data
12 | public class BaseException extends RuntimeException
13 | {
14 | private static final long serialVersionUID = 1L;
15 |
16 | private String mes;
17 | private int code;
18 |
19 | public BaseException(String message, int code){
20 | super(message);
21 | this.mes = message;
22 | this.code = code;
23 | }
24 |
25 | public BaseException(String message){
26 | super(message);
27 | this.mes = message;
28 | this.code = 400;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/handler/GlobalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.handler;
2 |
3 | import com.jzm.backme.exception.base.BaseException;
4 | import com.jzm.backme.model.AjaxResult;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.springframework.web.bind.annotation.ControllerAdvice;
7 | import org.springframework.web.bind.annotation.ExceptionHandler;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 |
10 | /**
11 | * @author: jzm
12 | * @date: 2024-04-18 21:27
13 | **/
14 |
15 | @ControllerAdvice
16 | @ResponseBody
17 | @Slf4j
18 | public class GlobalExceptionHandler
19 | {
20 | @ExceptionHandler(BaseException.class)
21 | public AjaxResult handlerBaseException(BaseException ex)
22 | {
23 | ex.printStackTrace();
24 | return AjaxResult.error(ex.getCode(), ex.getMessage());
25 | }
26 |
27 | @ExceptionHandler(Exception.class)
28 | public AjaxResult handlerException(Exception ex)
29 | {
30 | ex.printStackTrace();
31 | return AjaxResult.error(400, ex.getMessage());
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/interceptor/TokenInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.interceptor;
2 |
3 | import cn.hutool.Hutool;
4 | import cn.hutool.json.JSONUtil;
5 | import com.jzm.backme.constant.*;
6 | import com.jzm.backme.context.UserContext;
7 | import com.jzm.backme.domain.User;
8 | import com.jzm.backme.model.AjaxResult;
9 | import com.jzm.backme.model.vo.UserVo;
10 | import com.jzm.backme.util.ServletUtil;
11 | import com.jzm.backme.util.StringUtil;
12 | import com.jzm.backme.util.TokenUtil;
13 | import com.jzm.backme.util.redis.RedisCache;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.stereotype.Component;
16 | import org.springframework.web.servlet.HandlerInterceptor;
17 |
18 | import javax.servlet.http.HttpServletRequest;
19 | import javax.servlet.http.HttpServletResponse;
20 | import java.security.MessageDigest;
21 |
22 | /**
23 | * @author: jzm
24 | * @date: 2024-04-14 16:58
25 | **/
26 |
27 | @Component
28 | public class TokenInterceptor implements HandlerInterceptor
29 | {
30 |
31 | @Autowired
32 | private RedisCache redisCache;
33 |
34 | @Override
35 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
36 | {
37 | // 设置跨域
38 | response.setHeader("Access-Control-Allow-Origin", "*"); // 修改携带cookie,PS
39 | response.setHeader("Access-Control-Allow-Methods", "*");
40 | response.setHeader("Access-Control-Allow-Headers", "*");
41 | // 预检请求缓存时间(秒),即在这个时间内相同的预检请求不再发送,直接使用缓存结果。
42 | response.setHeader("Access-Control-Max-Age", "3600");
43 |
44 | if (request.getMethod().equalsIgnoreCase("options"))
45 | { // 设置预请求直接通过
46 | return true;
47 | }
48 | String path = request.getRequestURI();
49 | // 排除不过滤列表
50 | if (isExclusionList(path, UserConstant.ExclusionList))
51 | {
52 | return true;
53 | }
54 | // token拿取和校验
55 | String authorization = request.getHeader(HeaderConstant.AUTHORIZATION);
56 | if (StringUtil.isEmpty(authorization))
57 | {
58 | ServletUtil.renderString(response, JSONUtil.toJsonStr(HttpStatus.USER_NOT_LOGIN));
59 | return false;
60 | }
61 | if (!authorization.startsWith(Constant.TOKEN_PREFIX))
62 | {
63 | ServletUtil.renderString(response, JSONUtil.toJsonStr(HttpStatus.USER_TOKEN_ILLICIT));
64 | return false;
65 | }
66 | String token = authorization.substring(Constant.TOKEN_PREFIX.length());
67 | String userId = TokenUtil.parseTokenGetUserId(token);
68 | String loginKey = CacheConstant.LOGIN_USER_KEY + userId;
69 | User user = redisCache.getCacheObject(loginKey);
70 | if (StringUtil.isEmpty(user))
71 | {
72 | ServletUtil.renderString(response, JSONUtil.toJsonStr(HttpStatus.USER_LOGIN_EXPIRED));
73 | return false;
74 | }
75 | UserContext.set(user);
76 | return true;
77 | }
78 |
79 | // 排除不拦截列表(其实mvc配置就行,但是我这里面懒写了)。
80 | private boolean isExclusionList(String path, String... exclusionList)
81 | {
82 | for (String ep : exclusionList)
83 | {
84 | if (ep.equals(path))
85 | {
86 | return true;
87 | }
88 | // 这是 /path/qhx => /path/**
89 | if (ep.contains("/**"))
90 | {
91 | int len = ep.length();
92 | ep = ep.substring(0, len - "/**".length());
93 | if (path.contains(ep))
94 | {
95 | return true;
96 | }
97 | }
98 | }
99 | return false;
100 | }
101 |
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/mapper/ContractMapper.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.mapper;
2 |
3 | import com.jzm.backme.domain.Contract;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 合同表 -- 存储合同信息 Mapper 接口
10 | *
11 | *
12 | * @author qhx2004
13 | * @since 2024-04-14
14 | */
15 | @Mapper
16 | public interface ContractMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/mapper/HouseMapper.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.mapper;
2 |
3 | import com.jzm.backme.domain.House;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 房屋表 -- 存储房屋信息 Mapper 接口
10 | *
11 | *
12 | * @author qhx2004
13 | * @since 2024-04-14
14 | */
15 | @Mapper
16 | public interface HouseMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/mapper/PaymentMapper.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.mapper;
2 |
3 | import com.jzm.backme.domain.Payment;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 缴纳记录表 -- 记录租金缴纳信息 Mapper 接口
10 | *
11 | *
12 | * @author qhx2004
13 | * @since 2024-04-14
14 | */
15 | @Mapper
16 | public interface PaymentMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/mapper/RoleMapper.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.mapper;
2 |
3 | import com.jzm.backme.domain.Role;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 角色表 Mapper 接口
10 | *
11 | *
12 | * @author qhx2004
13 | * @since 2024-04-14
14 | */
15 | @Mapper
16 | public interface RoleMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.mapper;
2 |
3 | import com.jzm.backme.domain.Role;
4 | import com.jzm.backme.domain.User;
5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | /**
9 | *
10 | * 用户表 -- 存储用户信息 Mapper 接口
11 | *
12 | *
13 | * @author qhx2004
14 | * @since 2024-04-14
15 | */
16 | @Mapper
17 | public interface UserMapper extends BaseMapper {
18 |
19 | Role selectRole(Long userId);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/mapper/UserRoleMapper.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.mapper;
2 |
3 | import com.jzm.backme.domain.UserRole;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 用户 - 角色表 Mapper 接口
10 | *
11 | *
12 | * @author qhx2004
13 | * @since 2024-04-14
14 | */
15 | @Mapper
16 | public interface UserRoleMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/AjaxResult.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model;
2 |
3 |
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import com.jzm.backme.constant.Constant;
6 | import lombok.Getter;
7 | import lombok.Setter;
8 |
9 | import java.io.Serializable;
10 |
11 | /**
12 | * 公共响应类
13 | *
14 | * @author: jzm
15 | * @date: 2024-01-08 20:29
16 | **/
17 |
18 | @Setter
19 | @Getter
20 | @JsonInclude(value = JsonInclude.Include.NON_EMPTY) // 排除值为空字段的序列化
21 | public class AjaxResult implements Serializable
22 | {
23 | private static final long serialVersionUID = 1L;
24 |
25 | private Object data;
26 | private int code;
27 | private String mes;
28 |
29 |
30 | protected AjaxResult(Object data, int code, String mes)
31 | {
32 | this.data = data;
33 | this.code = code;
34 | this.mes = mes;
35 | }
36 |
37 | /**
38 | * 返回默认成功响应
39 | *
40 | * @return 成功响应
41 | */
42 | public static AjaxResult success()
43 | {
44 | return AjaxResult.success(Constant.OK_MES);
45 | }
46 |
47 |
48 | /**
49 | * 返回成功响应
50 | *
51 | * @param mes 成功信息
52 | * @return 成功响应
53 | */
54 | public static AjaxResult success(String mes)
55 | {
56 | return AjaxResult.common(null,200, mes);
57 | }
58 |
59 | /**
60 | * 返回成功响应
61 | *
62 | * @param data 成功内容
63 | * @return 成功响应
64 | */
65 | public static AjaxResult success(Object data)
66 | {
67 | return AjaxResult.common(data,Constant.OK_CODE, Constant.OK_MES);
68 | }
69 |
70 |
71 | /**
72 | * 返回警告响应
73 | *
74 | * @param data 警告内容
75 | * @param mes 警告信息
76 | * @return 警告响应
77 | */
78 | public static AjaxResult warn(Object data, String mes)
79 | {
80 | return AjaxResult.common(data,Constant.WARN_CODE, mes);
81 | }
82 |
83 |
84 | /**
85 | * 返回警告响应
86 | *
87 | * @param mes 警告信息
88 | * @return 警告响应
89 | */
90 | public static AjaxResult warn(String mes)
91 | {
92 | return AjaxResult.warn(null, mes);
93 | }
94 |
95 | /**
96 | * 返回失败响应
97 | *
98 | * @return 失败响应
99 | */
100 | public static AjaxResult error()
101 | {
102 | return AjaxResult.error(Constant.FAIL_MES);
103 | }
104 |
105 | /**
106 | * 返回失败响应
107 | *
108 | * @param mes 失败信息
109 | * @return 失败响应
110 | */
111 | public static AjaxResult error(String mes)
112 | {
113 | return AjaxResult.common(null,Constant.ERROR_CODE, mes);
114 | }
115 |
116 | /**
117 | * 返回失败响应
118 | *
119 | * @param code 失败编码
120 | * @param mes 失败信息
121 | * @return 失败响应
122 | */
123 | public static AjaxResult error(int code, String mes)
124 | {
125 | return AjaxResult.common(null, code, mes);
126 | }
127 |
128 |
129 | /**
130 | * 返回响应
131 | *
132 | * @param data 响应内容
133 | * @param code 响应编码
134 | * @param mes 响应消息
135 | * @return 响应
136 | */
137 | private static AjaxResult common(Object data, int code, String mes)
138 | {
139 | return new AjaxResult(data, code, mes);
140 | }
141 |
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/PageResult.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model;
2 |
3 | import com.jzm.backme.constant.Constant;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 |
7 | /**
8 | * @author: jzm
9 | * @date: 2024-03-08 18:04
10 | **/
11 |
12 | @Setter
13 | @Getter
14 | public class PageResult extends AjaxResult
15 | {
16 | private long total;
17 |
18 | protected PageResult(Object data, int code, String mes,long total)
19 | {
20 | super(data, code, mes);
21 | this.total = total;
22 | }
23 |
24 | private static PageResult common(Object data, int code, String mes,long total){
25 | return new PageResult(data,code,mes,total);
26 | }
27 | public static PageResult success(Object data,long total){
28 | return common(data, Constant.OK_CODE,Constant.OK_MES,total);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/LoginTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to;
2 |
3 | import com.jzm.backme.annotation.NotEmpty;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-14 16:17
9 | **/
10 |
11 | @Data
12 | public class LoginTo
13 | {
14 | @NotEmpty(extra = "密码")
15 | private String password;
16 |
17 | @NotEmpty(extra = "电话")
18 | private String phone;
19 | }
20 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/base/BasePageQueryTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.base;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author: jzm
7 | * @date: 2024-04-14 20:07
8 | **/
9 |
10 | @Data
11 | public class BasePageQueryTo
12 | {
13 | private int page;
14 | private int pageSize;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/contract/ContractQueryTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.contract;
2 |
3 | import com.jzm.backme.model.to.base.BasePageQueryTo;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-16 22:12
9 | **/
10 |
11 | @Data
12 | public class ContractQueryTo extends BasePageQueryTo
13 | {
14 | private Long landlordId;
15 | private String type;
16 | // 预发布
17 | // 签署未生效
18 | // 签署已经生效
19 | // 签署-过期
20 | // 签署-停止
21 | }
22 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/house/HouseAddTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.house;
2 |
3 | import com.jzm.backme.annotation.NotEmpty;
4 | import com.jzm.backme.domain.House;
5 | import lombok.Data;
6 |
7 | /**
8 | * @author: jzm
9 | * @date: 2024-04-16 20:44
10 | **/
11 |
12 | @Data
13 | public class HouseAddTo extends House
14 | {
15 | @NotEmpty(extra = "房屋密码")
16 | private String password;
17 | }
18 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/house/HouseDeleteTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.house;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author: jzm
9 | * @date: 2024-04-14 20:02
10 | **/
11 |
12 | @Data
13 | public class HouseDeleteTo
14 | {
15 | private List houseIds;
16 | }
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/house/HousePassTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.house;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author: jzm
7 | * @date: 2024-04-16 21:06
8 | **/
9 |
10 | @Data
11 | public class HousePassTo
12 | {
13 | private Long houseId;
14 | private String oldPass;
15 | private String newPass;
16 | }
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/house/HouseQueryTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.house;
2 |
3 | import com.jzm.backme.model.to.base.BasePageQueryTo;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-16 20:51
9 | **/
10 |
11 | @Data
12 | public class HouseQueryTo extends BasePageQueryTo
13 | {
14 | private String linkPhone;
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/payment/PaymentAddTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.payment;
2 |
3 | import com.jzm.backme.domain.Payment;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-17 14:38
9 | **/
10 |
11 | @Data
12 | public class PaymentAddTo extends Payment
13 | {
14 | private int money;
15 | private Long contractId;
16 | }
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/payment/PaymentQueryTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.payment;
2 |
3 | import com.jzm.backme.model.to.base.BasePageQueryTo;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-17 14:57
9 | **/
10 |
11 | @Data
12 | public class PaymentQueryTo extends BasePageQueryTo
13 | {
14 | private String payer; // 缴纳账户地址
15 | private String contractNum; // 合同序列号
16 | }
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/PassTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author: jzm
7 | * @date: 2024-04-20 21:26
8 | **/
9 |
10 | @Data
11 | public class PassTo
12 | {
13 | private String oldPassword;
14 | private String newPassword;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/UserAddTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import com.jzm.backme.domain.User;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-14 20:29
9 | **/
10 |
11 | @Data
12 | public class UserAddTo extends User
13 | {
14 | private Long roleId;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/UserDeleteTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @author: jzm
9 | * @date: 2024-04-14 19:24
10 | **/
11 |
12 | @Data
13 | public class UserDeleteTo
14 | {
15 | private List userIds;
16 | }
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/UserPassTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-18 10:46
9 | **/
10 |
11 | @Data
12 | @AllArgsConstructor
13 | public class UserPassTo
14 | {
15 | private String password;
16 | private String newPassword;
17 | }
18 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/UserPayMoneyTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author: jzm
7 | * @date: 2024-04-16 19:49
8 | **/
9 |
10 | @Data
11 | public class UserPayMoneyTo
12 | {
13 | private String user;
14 | private int amount;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/UserQueryTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import com.jzm.backme.model.to.base.BasePageQueryTo;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-14 20:05
9 | **/
10 |
11 | @Data
12 | public class UserQueryTo extends BasePageQueryTo
13 | {
14 | private String phone;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/to/user/UserResTo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.to.user;
2 |
3 | import com.jzm.backme.domain.User;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-16 19:58
9 | **/
10 |
11 | @Data
12 | public class UserResTo extends User
13 | {
14 | private int balance;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/vo/ContractVo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.vo;
2 |
3 | import com.jzm.backme.annotation.NotEmpty;
4 | import com.jzm.backme.domain.Contract;
5 | import lombok.Data;
6 |
7 | import java.time.LocalDateTime;
8 |
9 | /**
10 | * @author: jzm
11 | * @date: 2024-04-16 22:19
12 | **/
13 |
14 | @Data
15 | public class ContractVo extends Contract
16 | {
17 | // 签署结束时间
18 | private LocalDateTime signEndTime;
19 | // 生效
20 | private String begin;
21 | private LocalDateTime beginStartTime;
22 | private LocalDateTime beginEndTime;
23 | private String stop;
24 |
25 | @NotEmpty(extra = "规定每月租金")
26 | private Integer rent;
27 |
28 | @NotEmpty(extra = "规定每月保证金")
29 | private Integer earnest;
30 |
31 | // 签署是否缴纳
32 | String isTenEarnest; // 租客是否缴纳保证金
33 | String isTenRent; // 租客是否缴纳租金
34 | String isLanEarnest; // 房东是否缴纳保证金
35 |
36 | String tenant; // 租客地址
37 |
38 | String landlord; // 房东地址
39 | }
40 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/vo/HouseVo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.vo;
2 |
3 | import com.jzm.backme.domain.House;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-16 21:25
9 | **/
10 |
11 | @Data
12 | public class HouseVo extends House
13 | {
14 | private String password;
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/vo/PaymentVo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.vo;
2 |
3 | import com.jzm.backme.domain.Payment;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-17 15:01
9 | **/
10 |
11 | @Data
12 | public class PaymentVo extends Payment
13 | {
14 | private int money; // 缴纳金额
15 | }
16 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/model/vo/UserVo.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.model.vo;
2 |
3 | import com.jzm.backme.domain.User;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: jzm
8 | * @date: 2024-04-14 19:07
9 | **/
10 |
11 | @Data
12 | public class UserVo extends User
13 | {
14 | private Long roleId;
15 | private String roleName;
16 | private int balance;
17 | }
18 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/CaptchaService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import cn.hutool.captcha.CaptchaUtil;
4 | import cn.hutool.captcha.LineCaptcha;
5 | import cn.hutool.core.util.IdUtil;
6 | import com.jzm.backme.constant.CacheConstant;
7 | import com.jzm.backme.model.AjaxResult;
8 | import com.jzm.backme.util.redis.RedisCache;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.util.HashMap;
13 | import java.util.concurrent.TimeUnit;
14 |
15 | /**
16 | * 验证码业务类
17 | *
18 | * @author: jzm
19 | * @date: 2024-02-28 12:12
20 | **/
21 |
22 | @Component
23 | public class CaptchaService
24 | {
25 |
26 | @Autowired
27 | RedisCache redisCache;
28 |
29 | public AjaxResult getCaptcha(){
30 | LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(128, 50);
31 | String uuid = IdUtil.randomUUID();
32 | // 验证码缓存到redis
33 | String codeKey = CacheConstant.CAPTCHA_CODE_KEY + uuid;
34 | redisCache.setCacheObject(codeKey,lineCaptcha.getCode(),60, TimeUnit.SECONDS);
35 | HashMap result = new HashMap<>();
36 | result.put("codeUrl",lineCaptcha.getImageBase64Data());
37 | result.put("codeKey",uuid);
38 | return AjaxResult.success(result);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/ContractService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
4 | import com.jzm.backme.domain.Contract;
5 | import com.baomidou.mybatisplus.extension.service.IService;
6 | import com.jzm.backme.model.to.contract.ContractQueryTo;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 合同表 -- 存储合同信息 服务类
13 | *
14 | *
15 | * @author qhx2004
16 | * @since 2024-04-14
17 | */
18 | public interface ContractService extends IService {
19 |
20 | List getAll(ContractQueryTo contractQueryTo);
21 |
22 | Contract getOne(SFunction column,Object val);
23 |
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/HouseService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.jzm.backme.model.to.house.HouseQueryTo;
4 | import com.jzm.backme.model.to.user.UserQueryTo;
5 | import com.jzm.backme.domain.House;
6 | import com.baomidou.mybatisplus.extension.service.IService;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * 房屋表 -- 存储房屋信息 服务类
13 | *
14 | *
15 | * @author qhx2004
16 | * @since 2024-04-14
17 | */
18 | public interface HouseService extends IService {
19 |
20 | List getAll(HouseQueryTo houseQueryTo);
21 |
22 | boolean updateStatus(House house);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/LoginService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.jzm.backme.constant.CacheConstant;
4 | import com.jzm.backme.constant.HeaderConstant;
5 | import com.jzm.backme.constant.HttpStatus;
6 | import com.jzm.backme.context.UserContext;
7 | import com.jzm.backme.domain.User;
8 | import com.jzm.backme.exception.PermissionException;
9 | import com.jzm.backme.model.vo.UserVo;
10 | import com.jzm.backme.util.ServletUtil;
11 | import com.jzm.backme.util.StringUtil;
12 | import com.jzm.backme.util.redis.RedisCache;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.stereotype.Service;
15 |
16 | /**
17 | * @author: jzm
18 | * @date: 2024-04-14 16:39
19 | **/
20 |
21 | @Service
22 | public class LoginService
23 | {
24 |
25 | @Autowired
26 | private RedisCache redisCache;
27 |
28 | /**
29 | * 获取userId
30 | * @return
31 | */
32 | public final Long getUserId(){
33 | User user = getUser();
34 | if(StringUtil.isEmpty(user)){
35 | return null;
36 | }
37 | return user.getUserId();
38 | }
39 |
40 | public final String getAccountAddress(){
41 | return getUser().getUser();
42 | }
43 |
44 | public final User getUser(){
45 | return UserContext.get();
46 | }
47 |
48 | public final boolean isRole(Long roleId){
49 | User user = getUser();
50 | if(user instanceof UserVo){
51 | UserVo userVo = (UserVo) user;
52 | if(userVo.getRoleId() == roleId){
53 | return true;
54 | }
55 | }
56 | return false;
57 | }
58 |
59 | public final boolean isAdmin(){
60 | return isRole(1L);
61 | }
62 |
63 | public final boolean isLandlord(){
64 | return isRole(2L);
65 | }
66 |
67 | public final boolean isTenant(){
68 | return isRole(3L);
69 | }
70 |
71 |
72 | public final boolean isNotAdmin(){
73 | return !isAdmin();
74 | }
75 |
76 | public final void checkAdmin(){
77 | if(!isAdmin()){
78 | throw new PermissionException();
79 | }
80 | }
81 |
82 | public final void checkLandlord(){
83 | if(!isLandlord()){
84 | throw new PermissionException("操作者必须是房东");
85 | }
86 | }
87 |
88 | public final void checkTenant(){
89 | if(!isTenant()){
90 | throw new PermissionException("操作者必须是租客");
91 | }
92 | }
93 |
94 |
95 | /**
96 | * 校验验证码
97 | */
98 | public final HttpStatus verifyCaptcha(){
99 | String codeVal = ServletUtil.getHeader(HeaderConstant.CAPTCHA_VAL);
100 | String codeKey = ServletUtil.getHeader(HeaderConstant.CAPTCHA_KEY);
101 |
102 | if(codeVal != null){
103 | codeKey = CacheConstant.CAPTCHA_CODE_KEY + codeKey;
104 | String val = redisCache.getCacheObject(codeKey);
105 | if(val == null) { // 验证码过期
106 | return HttpStatus.CAPTCHA_EXPIRED;
107 | }
108 | if(!StringUtil.equals(val,codeVal)){ // 验证码不一致
109 | return HttpStatus.CAPTCHA_CHECK_FAILED;
110 | }
111 | return null;
112 | }
113 | return HttpStatus.CAPTCHA_CHECK_FAILED;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/MainContractService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import cn.hutool.json.JSONArray;
4 | import com.jzm.backme.config.fisco.contract.ContractResponse;
5 | import com.jzm.backme.config.fisco.service.WeFrontService;
6 | import com.jzm.backme.model.to.payment.PaymentAddTo;
7 | import com.jzm.backme.model.vo.ContractVo;
8 | import com.jzm.backme.model.vo.PaymentVo;
9 | import com.jzm.backme.util.Convert;
10 | import com.jzm.backme.util.DateUtil;
11 | import io.swagger.models.auth.In;
12 | import org.fisco.bcos.sdk.abi.datatypes.Int;
13 | import org.fisco.bcos.sdk.client.Client;
14 | import org.fisco.bcos.sdk.client.protocol.response.BcosBlock;
15 | import org.fisco.bcos.sdk.client.protocol.response.BlockNumber;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.stereotype.Component;
18 |
19 | import javax.annotation.Resource;
20 | import java.math.BigInteger;
21 | import java.util.ArrayList;
22 | import java.util.Arrays;
23 | import java.util.List;
24 |
25 | /**
26 | * 主合约交互类
27 | *
28 | * @author: jzm
29 | * @date: 2024-04-15 22:14
30 | **/
31 |
32 | @Component
33 | public class MainContractService
34 | {
35 |
36 | @Resource
37 | private WeFrontService weFrontService;
38 |
39 | public void addPerson(String account, Long role)
40 | {
41 | weFrontService.commonWrite("addPerson", Arrays.asList(account, role));
42 | }
43 |
44 | public void addBalance(String account, int amount)
45 | {
46 | weFrontService.commonWrite("addBalance", Arrays.asList(account, amount));
47 | }
48 |
49 | public int getBalance(String account)
50 | {
51 | ContractResponse response = weFrontService.commonRead("getPerson", Arrays.asList(account));
52 | String hex = response.getVals().getStr(0);
53 | return Convert.hexToInt(hex);
54 | }
55 |
56 | public void addHouse(String address, Long houseId, String password)
57 | {
58 | weFrontService.commonWrite(address, "addHouse", Arrays.asList(houseId, password));
59 | }
60 |
61 | public void changeHousePass(Long houseId, String password)
62 | {
63 | weFrontService.commonWrite("changeHousePass", Arrays.asList(houseId, password));
64 | }
65 |
66 | public String getHouseAdmin(Long houseId)
67 | {
68 | ContractResponse response = weFrontService.commonRead("getHouseAdmin", Arrays.asList(houseId));
69 | return response.getVals().getStr(1);
70 | }
71 |
72 | // 租客获取
73 | public String getHouse(Long houseId, Long contractId)
74 | {
75 | ContractResponse response = weFrontService.commonRead("getHouse", Arrays.asList(houseId, contractId));
76 | return response.getVals().getStr(1);
77 | }
78 |
79 | public void getContract(Long contractId, ContractVo contractVo)
80 | {
81 | ContractResponse response = weFrontService.commonRead("getContract", Arrays.asList(contractId));
82 | JSONArray vals = response.getVals();
83 | contractVo.setLandlord(vals.getStr(1));
84 | contractVo.setTenant(vals.getStr(2));
85 | contractVo.setEarnest(Convert.hexToInt(vals.getStr(3)));
86 | contractVo.setRent(Convert.hexToInt(vals.getStr(4)));
87 | contractVo.setBeginStartTime(DateUtil.parseLDT(vals.getStr(5)));
88 | contractVo.setBeginEndTime(DateUtil.parseLDT(vals.getStr(6)));
89 | contractVo.setIsTenEarnest(Convert.boolConv(vals.getBool(7)));
90 | contractVo.setIsTenRent(Convert.boolConv(vals.getBool(8)));
91 | contractVo.setIsLanEarnest(Convert.boolConv(vals.getBool(9)));
92 | contractVo.setBegin(Convert.boolConv(vals.getBool(10)));
93 | contractVo.setStop(Convert.boolConv(vals.getBool(11)));
94 | contractVo.setSignEndTime(DateUtil.parseLDT(vals.getStr(12)));
95 | }
96 |
97 | public void signContract(ContractVo contractVo)
98 | {
99 | Long contractId = contractVo.getContractId();
100 | String landlord = contractVo.getLandlord();
101 | String tenant = contractVo.getTenant();
102 | Integer earnest = contractVo.getEarnest();
103 | Long beginEndTime = DateUtil.datetimeToTimestamp(contractVo.getBeginEndTime()) / DateUtil.S;
104 |
105 | weFrontService.commonWrite("signContract", Arrays.asList(
106 | contractId, landlord, tenant, earnest, beginEndTime
107 | ));
108 | }
109 |
110 | public void tenantPrestore(String address, Long contractId)
111 | {
112 | weFrontService.commonWrite(address, "tenantPrestore", Arrays.asList(address, contractId));
113 | }
114 |
115 | public void landlordPrestore(String address, Long contractId)
116 | {
117 | weFrontService.commonWrite(address, "landlordPrestore", Arrays.asList(address, contractId));
118 | }
119 |
120 | public void backPrestoreMoney(String address, Long contractId)
121 | {
122 | weFrontService.commonWrite(address, "backPrestoreMoney", Arrays.asList(contractId, address));
123 | }
124 |
125 | public void stopContractTenant(String address, Long contractId)
126 | {
127 | weFrontService.commonWrite(address, "stopContractTenant", Arrays.asList(
128 | contractId, address
129 | ));
130 | }
131 |
132 | public void payRent(String address, PaymentAddTo pt)
133 | {
134 | weFrontService.commonWrite(address, "payRent", Arrays.asList(
135 | pt.getPayerId(),
136 | pt.getContractId(),
137 | pt.getMoney()
138 | ));
139 | }
140 |
141 | public void getPayRent(Long paymentId, PaymentVo paymentVo)
142 | {
143 | ContractResponse response = weFrontService.commonRead("getPayRent", Arrays.asList(paymentId));
144 | JSONArray vals = response.getVals();
145 | paymentVo.setMoney(Convert.hexToInt(vals.getStr(2)));
146 | }
147 |
148 | public void stopContractLandlord(String address, Long contractId)
149 | {
150 | weFrontService.commonWrite(address, "stopContractLandlord", Arrays.asList(
151 | contractId, address
152 | ));
153 | }
154 |
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/PaymentService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.jzm.backme.domain.Payment;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 | import com.jzm.backme.model.to.payment.PaymentQueryTo;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | *
11 | * 缴纳记录表 -- 记录租金缴纳信息 服务类
12 | *
13 | *
14 | * @author qhx2004
15 | * @since 2024-04-14
16 | */
17 | public interface PaymentService extends IService {
18 |
19 | List getAll(PaymentQueryTo qt);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/RoleService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.jzm.backme.domain.Role;
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 |
6 | /**
7 | *
8 | * 角色表 服务类
9 | *
10 | *
11 | * @author qhx2004
12 | * @since 2024-04-14
13 | */
14 | public interface RoleService extends IService {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/UserRoleService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.jzm.backme.domain.Role;
4 | import com.jzm.backme.domain.UserRole;
5 | import com.baomidou.mybatisplus.extension.service.IService;
6 |
7 | /**
8 | *
9 | * 用户 - 角色表 服务类
10 | *
11 | *
12 | * @author qhx2004
13 | * @since 2024-04-14
14 | */
15 | public interface UserRoleService extends IService {
16 |
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service;
2 |
3 | import com.jzm.backme.domain.Role;
4 | import com.jzm.backme.domain.User;
5 | import com.baomidou.mybatisplus.extension.service.IService;
6 | import com.jzm.backme.model.to.user.PassTo;
7 | import com.jzm.backme.model.to.user.UserPassTo;
8 | import com.jzm.backme.model.to.user.UserQueryTo;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | *
14 | * 用户表 -- 存储用户信息 服务类
15 | *
16 | *
17 | * @author qhx2004
18 | * @since 2024-04-14
19 | */
20 | public interface UserService extends IService {
21 |
22 | User getOne(String phone, String password);
23 |
24 | List getAll(UserQueryTo queryTo);
25 |
26 | boolean checkPhoneUnique(String phone);
27 | boolean checkPhoneUpUnique(String phone);
28 |
29 | boolean checkPassUnique(String password);
30 | boolean isPasswordExists(String oldPassword);
31 |
32 | boolean checkMd5PassUnique(String password);
33 |
34 | boolean checkUserUnique(String user);
35 |
36 | Role getRole(Long userId);
37 |
38 | boolean updateStatus(User user);
39 | boolean updatePass(UserPassTo upt);
40 |
41 | boolean updatePass(PassTo passTo);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/impl/ContractServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 | import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
5 | import com.jzm.backme.constant.Constant;
6 | import com.jzm.backme.domain.Contract;
7 | import com.jzm.backme.mapper.ContractMapper;
8 | import com.jzm.backme.model.to.contract.ContractQueryTo;
9 | import com.jzm.backme.service.ContractService;
10 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11 | import com.jzm.backme.util.StringUtil;
12 | import org.springframework.stereotype.Service;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | *
18 | * 合同表 -- 存储合同信息 服务实现类
19 | *
20 | *
21 | * @author qhx2004
22 | * @since 2024-04-14
23 | */
24 | @Service
25 | public class ContractServiceImpl extends ServiceImpl implements ContractService {
26 |
27 | @Override
28 | public List getAll(ContractQueryTo contractQueryTo)
29 | {
30 | Long landlordId = contractQueryTo.getLandlordId();
31 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
32 | .eq(StringUtil.isNotEmpty(landlordId), Contract::getLandlordId, landlordId);
33 |
34 | return this.list(queryWrapper);
35 | }
36 |
37 | @Override
38 | public Contract getOne(SFunction column, Object val)
39 | {
40 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
41 | .eq(column, val);
42 | return this.getOne(queryWrapper);
43 | }
44 |
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/impl/HouseServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 | import com.jzm.backme.model.to.house.HouseQueryTo;
5 | import com.jzm.backme.model.to.user.UserQueryTo;
6 | import com.jzm.backme.domain.House;
7 | import com.jzm.backme.mapper.HouseMapper;
8 | import com.jzm.backme.service.HouseService;
9 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10 | import com.jzm.backme.util.StringUtil;
11 | import org.springframework.stereotype.Service;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | *
17 | * 房屋表 -- 存储房屋信息 服务实现类
18 | *
19 | *
20 | * @author qhx2004
21 | * @since 2024-04-14
22 | */
23 | @Service
24 | public class HouseServiceImpl extends ServiceImpl implements HouseService {
25 |
26 | @Override
27 | public List getAll(HouseQueryTo houseQueryTo)
28 | {
29 | String linkPhone = houseQueryTo.getLinkPhone();
30 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
31 | .eq(StringUtil.isNotEmpty(linkPhone),House::getLinkPhone,linkPhone);
32 |
33 | return this.list(queryWrapper);
34 | }
35 |
36 | @Override
37 | public boolean updateStatus(House house)
38 | {
39 | Long houseId = house.getHouseId();
40 | House newHouse = new House();
41 |
42 | newHouse.setHouseId(houseId);
43 | newHouse.setStatus(house.getStatus());
44 | LambdaQueryWrapper updateWrapper = new LambdaQueryWrapper()
45 | .eq(House::getHouseId, houseId);
46 |
47 | return this.update(newHouse,updateWrapper);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/impl/PaymentServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 | import com.jzm.backme.domain.Payment;
5 | import com.jzm.backme.mapper.PaymentMapper;
6 | import com.jzm.backme.model.to.payment.PaymentQueryTo;
7 | import com.jzm.backme.service.PaymentService;
8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9 | import com.jzm.backme.util.StringUtil;
10 | import org.springframework.stereotype.Service;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | *
16 | * 缴纳记录表 -- 记录租金缴纳信息 服务实现类
17 | *
18 | *
19 | * @author qhx2004
20 | * @since 2024-04-14
21 | */
22 | @Service
23 | public class PaymentServiceImpl extends ServiceImpl implements PaymentService {
24 |
25 | @Override
26 | public List getAll(PaymentQueryTo qt)
27 | {
28 | String payer = qt.getPayer();
29 | String contractNum = qt.getContractNum();
30 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
31 | .eq(StringUtil.isNotEmpty(payer), Payment::getPayer, payer)
32 | .eq(StringUtil.isNotEmpty(contractNum),Payment::getContractNum,contractNum);
33 |
34 |
35 | return this.list(queryWrapper);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/impl/RoleServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service.impl;
2 |
3 | import com.jzm.backme.domain.Role;
4 | import com.jzm.backme.mapper.RoleMapper;
5 | import com.jzm.backme.service.RoleService;
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 角色表 服务实现类
12 | *
13 | *
14 | * @author qhx2004
15 | * @since 2024-04-14
16 | */
17 | @Service
18 | public class RoleServiceImpl extends ServiceImpl implements RoleService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/impl/UserRoleServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service.impl;
2 |
3 | import com.jzm.backme.domain.UserRole;
4 | import com.jzm.backme.mapper.UserRoleMapper;
5 | import com.jzm.backme.service.UserRoleService;
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 用户 - 角色表 服务实现类
12 | *
13 | *
14 | * @author qhx2004
15 | * @since 2024-04-14
16 | */
17 | @Service
18 | public class UserRoleServiceImpl extends ServiceImpl implements UserRoleService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/service/impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 | import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
5 | import com.jzm.backme.domain.Role;
6 | import com.jzm.backme.domain.User;
7 | import com.jzm.backme.mapper.UserMapper;
8 | import com.jzm.backme.model.to.user.PassTo;
9 | import com.jzm.backme.model.to.user.UserPassTo;
10 | import com.jzm.backme.model.to.user.UserQueryTo;
11 | import com.jzm.backme.service.UserService;
12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
13 | import com.jzm.backme.util.StringUtil;
14 | import com.jzm.backme.util.user.UserUtil;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.stereotype.Service;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | *
22 | * 用户表 -- 存储用户信息 服务实现类
23 | *
24 | *
25 | * @author qhx2004
26 | * @since 2024-04-14
27 | */
28 | @Service
29 | public class UserServiceImpl extends ServiceImpl implements UserService {
30 |
31 | @Autowired
32 | private UserMapper userMapper;
33 |
34 | @Override
35 | public User getOne(String phone, String password)
36 | {
37 | password = UserUtil.cryptPass(password);
38 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
39 | .eq(User::getPhone, phone).eq(User::getPassword, password);
40 |
41 | return this.getOne(queryWrapper);
42 | }
43 |
44 | @Override
45 | public List getAll(UserQueryTo queryTo)
46 | {
47 | String phone = queryTo.getPhone();
48 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
49 | .eq(StringUtil.isNotEmpty(phone), User::getPhone, phone);
50 | return this.list(queryWrapper);
51 | }
52 |
53 | @Override
54 | public boolean checkPhoneUnique(String phone)
55 | {
56 | return checkFieldUnique(User::getPhone,phone);
57 | }
58 |
59 | @Override
60 | public boolean checkPhoneUpUnique(String phone)
61 | {
62 | User one = getOne(User::getPhone, phone);
63 | if( StringUtil.isEmpty(one) || one.getPhone().equals(phone)){
64 | return true;
65 | }
66 | return false;
67 | }
68 |
69 | @Override
70 | public boolean checkPassUnique(String password)
71 | {
72 | password = UserUtil.cryptPass(password);
73 | return checkMd5PassUnique(password);
74 | }
75 |
76 | @Override
77 | public boolean isPasswordExists(String oldPassword)
78 | {
79 | return !checkPassUnique(oldPassword);
80 | }
81 |
82 | @Override
83 | public boolean checkMd5PassUnique(String password)
84 | {
85 | return checkFieldUnique(User::getPassword,password);
86 | }
87 |
88 | @Override
89 | public boolean checkUserUnique(String user)
90 | {
91 | return checkFieldUnique(User::getUser,user);
92 | }
93 |
94 | private boolean checkFieldUnique(SFunction column,Object val){
95 | User one = getOne(column,val);
96 | if(StringUtil.isEmpty(one)){
97 | return true;
98 | }
99 | return false;
100 | }
101 |
102 | private User getOne(SFunction column,Object val){
103 | LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
104 | .eq(column, val);
105 | return this.getOne(queryWrapper);
106 | }
107 |
108 | @Override
109 | public Role getRole(Long userId)
110 | {
111 | return userMapper.selectRole(userId);
112 | }
113 |
114 | @Override
115 | public boolean updateStatus(User user)
116 | {
117 | Long userId = user.getUserId();
118 | LambdaQueryWrapper updateWrapper = new LambdaQueryWrapper()
119 | .eq(User::getUserId, userId);
120 | User newUser = new User();
121 | newUser.setUserId(userId);
122 | newUser.setStatus(user.getStatus());
123 | return this.update(newUser,updateWrapper);
124 | }
125 |
126 | @Override
127 | public boolean updatePass(UserPassTo upt)
128 | {
129 | String password = upt.getPassword();
130 | String newPassword = upt.getNewPassword();
131 | LambdaQueryWrapper updateWrapper = new LambdaQueryWrapper()
132 | .eq(User::getPassword, password);
133 | User newUser = new User();
134 | newUser.setPassword(newPassword);
135 | return this.update(newUser,updateWrapper);
136 | }
137 |
138 | @Override
139 | public boolean updatePass(PassTo passTo)
140 | {
141 | String oldPassword = passTo.getOldPassword();
142 | oldPassword = UserUtil.cryptPass(oldPassword);
143 |
144 | String newPassword = passTo.getNewPassword();
145 | newPassword = UserUtil.cryptPass(newPassword);
146 |
147 | UserPassTo userPassTo = new UserPassTo(oldPassword, newPassword);
148 | return updatePass(userPassTo);
149 | }
150 |
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/Convert.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | /**
4 | * @author: jzm
5 | * @date: 2024-04-17 08:44
6 | **/
7 |
8 | public class Convert
9 | {
10 | /**
11 | * 16进制字符串(0x开头的)-数字
12 | * @return
13 | */
14 | public static Integer hexToInt(String val){
15 | if(val.startsWith("0x")){
16 | val = val.substring("0x".length());
17 | }else{
18 | return Integer.parseInt(val);
19 | }
20 | return Integer.parseInt(val, 16);
21 | }
22 |
23 | public static Long hexToLong(String val)
24 | {
25 | return Long.parseLong(hexToInt(val).toString());
26 | }
27 |
28 |
29 | public static String boolConv(Boolean bool){
30 | if(!bool){
31 | return "0";
32 | }else{
33 | return "1";
34 | }
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/DateUtil.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | import java.time.LocalDateTime;
4 | import java.time.ZoneId;
5 | import java.time.ZoneOffset;
6 | import java.time.ZonedDateTime;
7 | import java.util.Date;
8 |
9 | /**
10 | * @author: jzm
11 | * @date: 2024-04-17 09:11
12 | **/
13 |
14 | public class DateUtil extends cn.hutool.core.date.DateUtil
15 | {
16 |
17 |
18 | public static final long S = 1000L;
19 | public static final long M = S * 60;
20 | public static final long H = M * 60;
21 | public static final long D = H * 24;
22 |
23 | public static LocalDateTime parseLDTs(String s_timestamp){
24 | // 是否为16进制数字
25 | if(s_timestamp.startsWith("0x")){
26 | s_timestamp = s_timestamp.substring("0x".length());
27 | }
28 | return parseLDTms(String.valueOf(Long.parseLong(s_timestamp) * 1000));
29 | }
30 |
31 | public static LocalDateTime parseLDT(String s_timestamp){
32 | return parseLDTs(s_timestamp);
33 | }
34 |
35 | public static LocalDateTime parseLDTms(String ms_timestamp){
36 | if(ms_timestamp.startsWith("0x")){
37 | ms_timestamp = ms_timestamp.substring("0x".length());
38 | }
39 | Date date = new Date(Long.parseLong(ms_timestamp));
40 | String dateTime = formatDateTime(date);
41 | return DateUtil.parseLocalDateTime(dateTime);
42 | }
43 |
44 | public static int compare(LocalDateTime d1,LocalDateTime d2){
45 | Date date1 = localToDate(d1);
46 | Date date2 = localToDate(d2);
47 | return DateUtil.compare(date1,date2);
48 | }
49 |
50 |
51 | public static LocalDateTime addTime(LocalDateTime source,int day){
52 | Long end = datetimeToTimestamp(source);
53 | end = end + day * D;
54 | return parseLDTms(String.valueOf(end));
55 | }
56 |
57 | public static Date localToDate(LocalDateTime localDateTime){
58 | ZonedDateTime l1 = localDateTime.atZone(ZoneId.systemDefault());
59 | return Date.from(l1.toInstant());
60 | }
61 |
62 |
63 | public static Long datetimeToTimestamp(LocalDateTime beginEndTime)
64 | {
65 | return beginEndTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/NotEmptyUtil.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | import com.jzm.backme.annotation.NotEmpty;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | import java.lang.reflect.Field;
7 |
8 | /**
9 | * 自定义字段检验工具类
10 | *
11 | * 配合 @NotEmpty + 反射:实现被该注解注释字段,校验空值。如果该注解没元数据
12 | * 则: 字段名 + 不能为空
13 | *
14 | *
15 | * @author: jzm
16 | * @date: 2024-03-08 10:56
17 | **/
18 |
19 | @Slf4j
20 | public class NotEmptyUtil
21 | {
22 |
23 |
24 | public static String checkEmptyFiled(Object obj,String ...fileNames)
25 | {
26 | return checkEmptyFiled(obj,obj.getClass(),fileNames);
27 | }
28 |
29 | /**
30 | * 检验字段是否空
31 | *
32 | * @param obj 检验对象
33 | * @param fileNames 忽略字段列表
34 | * @return 第一个空字段
35 | */
36 | public static String checkEmptyFiled(Object obj,Class> cls,String ...fileNames)
37 | {
38 | NotEmpty notEmptyCls = cls.getAnnotation(NotEmpty.class); // 类获取的空
39 | Field[] fields = cls.getDeclaredFields();
40 | for (Field field : fields)
41 | {
42 | field.setAccessible(true);
43 | try
44 | {
45 | // 忽略字段
46 | String fileName = field.getName();
47 | if(StringUtil.equalsAny(fileName,fileNames))
48 | {
49 | continue;
50 | }
51 | // 获取字段值
52 | Object value = field.get(obj);
53 | // 其他类型(不校验非引用类型)
54 | if(StringUtil.isEmpty(value))
55 | {
56 | String end = checkFileIsAn(field); // 检查字段是否注解
57 | if(end != null)
58 | {
59 | return end;
60 | }
61 | if(notEmptyCls != null && notEmptyCls.required()){ // 检查是否类标记注解
62 | return fileName + "不能为空";
63 | }
64 | }
65 | // 字符串类型: "" 值
66 | if(value instanceof String){
67 | if(StringUtil.isEmpty(value.toString()))
68 | {
69 | String end = checkFileIsAn(field); // 检查字段是否注解
70 | if(end != null)
71 | {
72 | return end;
73 | }
74 | if(notEmptyCls != null && notEmptyCls.required()){ // 检查是否类标记注解
75 | return fileName + "不能为空";
76 | }
77 | }
78 | }
79 | // 是对象类型校验对象
80 | //if(value != null && value.getClass().isInstance(value)){
81 | // Class> fieldType = value.getClass();
82 | // String res = checkEmptyFiled(value, fieldType, fileNames);
83 | // if(StringUtil.isNotEmpty(res)){
84 | // return res;
85 | // }
86 | //}
87 |
88 | } catch (IllegalAccessException e)
89 | {
90 | log.error("读取字段异常:"+e.getMessage());
91 | return null;
92 | } catch (Exception e)
93 | {
94 | log.error(e.getMessage());
95 | }
96 | }
97 | if( cls.getSuperclass() == Object.class) // 到这结束递归
98 | {
99 | return null;
100 | }
101 | return checkEmptyFiled(obj,cls.getSuperclass(),fileNames);
102 | }
103 |
104 |
105 | private static String checkFileIsAn(Field field)
106 | {
107 | NotEmpty verifyField = field.getAnnotation(NotEmpty.class);
108 | if (verifyField != null && verifyField.required()){
109 | if(StringUtil.isEmpty(verifyField.extra()))
110 | {
111 | return field.getName() + "不能为空!";
112 | }
113 | return verifyField.extra() + "不能为空!" ;
114 | }
115 | return null;
116 | }
117 |
118 |
119 |
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/PageUtil.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | import com.github.pagehelper.ISelect;
4 | import com.github.pagehelper.Page;
5 | import com.github.pagehelper.PageHelper;
6 | import com.github.pagehelper.PageInfo;
7 |
8 |
9 | /**
10 | * 分页工具类
11 | */
12 | public class PageUtil
13 | {
14 | private static Page _startPage(int pageNum, int pageSize, ISelect select, String orderBy)
15 | {
16 | clearPage();
17 | Page page = PageHelper.startPage(pageNum, pageSize).doSelectPage(select);
18 | if (orderBy == null)
19 | {
20 | return page;
21 | }
22 | page.setOrderBy(orderBy);
23 | return page;
24 | }
25 |
26 | /**
27 | * 分页
28 | *
29 | * page 起始页
30 | * pageSize 页大小
31 | *
32 | * @param select : () -> userMapper.list()
33 | */
34 | public static PageInfo startPage(int pageNum, int pageSize, ISelect select)
35 | {
36 | return new PageInfo<>(_startPage(pageNum, pageSize, select, null));
37 | }
38 |
39 | /**
40 | * 降序 + 分页
41 | */
42 | public static PageInfo orderByDesc(int pageNum, int pageSize, String filed, ISelect select)
43 | {
44 | return new PageInfo<>(_startPage(pageNum, pageSize, select, filed + " desc"));
45 | }
46 |
47 |
48 | /**
49 | * 升序 + 分页
50 | */
51 | public static PageInfo orderByAsc(int pageNum, int pageSize, String filed, ISelect select)
52 | {
53 | return new PageInfo<>(_startPage(pageNum, pageSize, select, filed + " asc"));
54 | }
55 |
56 | /**
57 | * 清理分页的线程变量(清除分页数据)
58 | */
59 | public static void clearPage()
60 | {
61 | PageHelper.clearPage();
62 | }
63 |
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/ServletUtil.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | import cn.hutool.core.convert.Convert;
4 | import com.jzm.backme.constant.Constant;
5 | import org.springframework.web.context.request.RequestAttributes;
6 | import org.springframework.web.context.request.RequestContextHolder;
7 | import org.springframework.web.context.request.ServletRequestAttributes;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import javax.servlet.http.HttpSession;
12 | import java.io.IOException;
13 | import java.io.UnsupportedEncodingException;
14 | import java.net.URLDecoder;
15 | import java.net.URLEncoder;
16 | import java.util.Enumeration;
17 | import java.util.List;
18 |
19 | /**
20 | * 客户端工具类
21 | *
22 | * @author ruoyi
23 | */
24 | public class ServletUtil
25 | {
26 | /**
27 | * 定义移动端请求的所有可能类型
28 | */
29 | private final static String[] agent = { "Android", "iPhone", "iPod", "iPad", "Windows Phone", "MQQBrowser" };
30 |
31 | /**
32 | * 获取String参数
33 | */
34 | public static String getParameter(String name)
35 | {
36 | return getRequest().getParameter(name);
37 | }
38 |
39 | /**
40 | * 获取String参数
41 | */
42 | public static String getParameter(String name, String defaultValue)
43 | {
44 | return Convert.toStr(getRequest().getParameter(name), defaultValue);
45 | }
46 |
47 | /**
48 | * 获取Integer参数
49 | */
50 | public static Integer getParameterToInt(String name)
51 | {
52 | return Convert.toInt(getRequest().getParameter(name));
53 | }
54 |
55 | /**
56 | * 获取Integer参数
57 | */
58 | public static Integer getParameterToInt(String name, Integer defaultValue)
59 | {
60 | return Convert.toInt(getRequest().getParameter(name), defaultValue);
61 | }
62 |
63 | /**
64 | * 获取Boolean参数
65 | */
66 | public static Boolean getParameterToBool(String name)
67 | {
68 | return Convert.toBool(getRequest().getParameter(name));
69 | }
70 |
71 | /**
72 | * 获取Boolean参数
73 | */
74 | public static Boolean getParameterToBool(String name, Boolean defaultValue)
75 | {
76 | return Convert.toBool(getRequest().getParameter(name), defaultValue);
77 | }
78 |
79 | /**
80 | * 获取request
81 | */
82 | public static HttpServletRequest getRequest()
83 | {
84 | return getRequestAttributes().getRequest();
85 | }
86 |
87 | /**
88 | * 获取Header
89 | */
90 |
91 | public static String getHeader(String name){
92 | return getRequest().getHeader(name);
93 | }
94 |
95 | public static Enumeration getHeaders(String name){
96 | return getRequest().getHeaders(name);
97 | }
98 |
99 |
100 |
101 | /**
102 | * 获取response
103 | */
104 | public static HttpServletResponse getResponse()
105 | {
106 | return getRequestAttributes().getResponse();
107 | }
108 |
109 | /**
110 | * 获取session
111 | */
112 | public static HttpSession getSession()
113 | {
114 | return getRequest().getSession();
115 | }
116 |
117 | public static ServletRequestAttributes getRequestAttributes()
118 | {
119 | RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
120 | return (ServletRequestAttributes) attributes;
121 | }
122 |
123 | /**
124 | * 将字符串渲染到客户端
125 | *
126 | * @param response 渲染对象
127 | * @param string 待渲染的字符串
128 | * @return null
129 | */
130 | public static String renderString(HttpServletResponse response, String string)
131 | {
132 | try
133 | {
134 | response.setContentType("application/json");
135 | response.setCharacterEncoding("utf-8");
136 | response.getWriter().print(string);
137 | }
138 | catch (IOException e)
139 | {
140 | e.printStackTrace();
141 | }
142 | return null;
143 | }
144 |
145 | /**
146 | * 是否是Ajax异步请求
147 | *
148 | * @param request
149 | */
150 | public static boolean isAjaxRequest(HttpServletRequest request)
151 | {
152 | String accept = request.getHeader("accept");
153 | if (accept != null && accept.contains("application/json"))
154 | {
155 | return true;
156 | }
157 |
158 | String xRequestedWith = request.getHeader("X-Requested-With");
159 | if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
160 | {
161 | return true;
162 | }
163 |
164 | String uri = request.getRequestURI();
165 | if (StringUtil.inStringIgnoreCase(uri, ".json", ".xml"))
166 | {
167 | return true;
168 | }
169 |
170 | String ajax = request.getParameter("__ajax");
171 | return StringUtil.inStringIgnoreCase(ajax, "json", "xml");
172 | }
173 |
174 | /**
175 | * 判断User-Agent 是不是来自于手机
176 | */
177 | public static boolean checkAgentIsMobile(String ua)
178 | {
179 | boolean flag = false;
180 | if (!ua.contains("Windows NT") || (ua.contains("Windows NT") && ua.contains("compatible; MSIE 9.0;")))
181 | {
182 | // 排除 苹果桌面系统
183 | if (!ua.contains("Windows NT") && !ua.contains("Macintosh"))
184 | {
185 | for (String item : agent)
186 | {
187 | if (ua.contains(item))
188 | {
189 | flag = true;
190 | break;
191 | }
192 | }
193 | }
194 | }
195 | return flag;
196 | }
197 |
198 | /**
199 | * 内容编码
200 | *
201 | * @param str 内容
202 | * @return 编码后的内容
203 | */
204 | public static String urlEncode(String str)
205 | {
206 | try
207 | {
208 | return URLEncoder.encode(str, Constant.UTF_8);
209 | }
210 | catch (UnsupportedEncodingException e)
211 | {
212 | return StringUtil.EMPTY;
213 | }
214 | }
215 |
216 | /**
217 | * 内容解码(utf-8解码)
218 | *
219 | * @param str 内容
220 | * @return 解码后的内容
221 | */
222 | public static String urlDecode(String str)
223 | {
224 | try
225 | {
226 | return URLDecoder.decode(str, Constant.UTF_8);
227 | }
228 | catch (UnsupportedEncodingException e)
229 | {
230 | return StringUtil.EMPTY;
231 | }
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/StringUtil.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | import cn.hutool.core.util.StrUtil;
4 |
5 | import java.util.Objects;
6 |
7 | /**
8 | * String 工具类
9 | *
10 | * @author: jzm
11 | * @date: 2024-01-08 19:44
12 | **/
13 |
14 | public class StringUtil extends StrUtil
15 | {
16 |
17 | public static boolean equals(Object a,Object b){
18 | return Objects.equals(a, b) || StringUtil.equals(a.toString(),b.toString());
19 | }
20 |
21 | /**
22 | * 是空字符串?
23 | *
24 | * @param str
25 | * @return true:为空 false:非空
26 | */
27 | public static boolean isEmpty(CharSequence str)
28 | {
29 | if (StrUtil.isEmpty(str))
30 | {
31 | return true;
32 | }
33 | if (str instanceof String)
34 | {
35 | if (((String) str).trim().equals(""))
36 | {
37 | return true;
38 | }
39 | }
40 | return false;
41 | }
42 |
43 | /**
44 | * 是空?
45 | *
46 | * @param obj 对象
47 | * @return true:为空 false:非空
48 | */
49 | public static boolean isEmpty(Object obj)
50 | {
51 | return obj == null;
52 | }
53 |
54 | /**
55 | * 不是空?
56 | *
57 | * @param str
58 | * @return true:非空 false:为空
59 | */
60 | public static boolean isNotEmpty(CharSequence str)
61 | {
62 | return !isEmpty(str);
63 | }
64 |
65 | public static boolean isNotEmpty(Object obj)
66 | {
67 | return !isEmpty(obj);
68 | }
69 |
70 | /**
71 | * 判断字符串列表是否包含被包含字符串
72 | *
73 | * @param str 被包含字符串
74 | * @param strs 字符串列表
75 | * @return 包含返回true
76 | */
77 | public static boolean inStringIgnoreCase(String str, String... strs)
78 | {
79 | if (str != null && strs != null)
80 | {
81 | for (String s : strs)
82 | {
83 | if (s.equalsIgnoreCase(str))
84 | {
85 | return true;
86 | }
87 | }
88 | return false;
89 | }
90 | return false;
91 | }
92 |
93 | public static boolean isNull(Object obj)
94 | {
95 | return obj == null;
96 | }
97 |
98 | public static boolean isNotNull(Object obj)
99 | {
100 | return !isNull(obj);
101 | }
102 |
103 |
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/TokenUtil.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util;
2 |
3 | import cn.hutool.crypto.digest.MD5;
4 | import cn.hutool.jwt.JWTUtil;
5 | import com.jzm.backme.constant.Constant;
6 | import java.io.UnsupportedEncodingException;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | /**
11 | * token工具类
12 | *
13 | * @author: jzm
14 | * @date: 2024-02-26 21:31
15 | **/
16 |
17 | public class TokenUtil extends JWTUtil
18 | {
19 | private static String CREATE_TIME = "create_time";
20 |
21 | private static String EXPIRE_TIME = "expire_time";
22 |
23 |
24 | private static final String SECRET = "abcdefghijklmnopqrstuvwxyz";
25 |
26 | protected static final long MILLIS_SECOND = 1000; // 单位 1s
27 |
28 | protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; // 单位 1 min
29 |
30 | protected static final Long MILLIS_HOUR = 60 * MILLIS_MINUTE; // 单位 1 hour
31 | protected static final Long MILLIS_DAY = 24 * MILLIS_HOUR; // 单位 1 day
32 |
33 |
34 |
35 | // 默认一天后过期
36 | public static String createToken(Long userId) {
37 | return createToken(userId,MILLIS_DAY);
38 | }
39 |
40 | public static String createTokenByPassWord(String password,long expireTime) {
41 | return createToken(Constant.PASSWORD,password,expireTime);
42 | }
43 |
44 | public static String createToken(Long userId, long expireTime)
45 | {
46 | return createToken(Constant.USER_ID,userId,expireTime);
47 | }
48 |
49 | // 创建令牌
50 | public static String createToken(String key,Object val, long expireTime){
51 | Map claims = new HashMap<>();
52 | claims.put(key,val);
53 | claims.put(CREATE_TIME, System.currentTimeMillis());
54 | claims.put(EXPIRE_TIME, expireTime * MILLIS_MINUTE + System.currentTimeMillis());
55 | return createToken(claims,SECRET);
56 | }
57 |
58 |
59 | private static String createToken(Map claims,String key)
60 | {
61 | try
62 | {
63 | return TokenUtil.createToken(claims,key.getBytes(Constant.UTF_8));
64 | } catch (UnsupportedEncodingException e)
65 | {
66 | return null;
67 | }
68 | }
69 |
70 | public static String parseTokenGetUserId(String token) {
71 | return parseTokenGetClaims(token, Constant.USER_ID).toString();
72 | }
73 |
74 | public static Object parseTokenGetClaims(String token,String name) {
75 | return parseToken(token).getPayload(name);
76 | }
77 |
78 | /** 校验token是否过期
79 | *
80 | * @param token
81 | * @return
82 | */
83 | public static boolean verify(String token){
84 | long currentTime = System.currentTimeMillis();
85 | return Long.parseLong(parseTokenGetClaims(token,EXPIRE_TIME).toString()) > currentTime;
86 | }
87 |
88 | /**
89 | * 校验token从创建时间 - 到现在超过time分钟否
90 | *
91 | * @param token
92 | * @param time 单位 min
93 | * @return
94 | */
95 | // 按照我们的设计,用户每次携带token,校验,
96 | // 都会去更新这个token创建时间,那么直到我们有很长一次才被校验时,说明我们用户已经长期未登录了。
97 | public static boolean verify(String token,Long time)
98 | {
99 | Long creteTime = Long.valueOf(parseTokenGetClaims(token, CREATE_TIME).toString());
100 | Long currentTime = System.currentTimeMillis();
101 | return time > (currentTime - creteTime )/MILLIS_MINUTE;
102 | }
103 |
104 | public static String verifyRefresh(String token)
105 | {
106 | if(verify(token,20L)) // 离线没超过20min
107 | {
108 | Long userId = Long.valueOf(parseTokenGetUserId(token));
109 | return createToken(userId);
110 | }
111 | return null;
112 | }
113 |
114 |
115 | public static void main(String[] args)
116 | {
117 | System.out.println(MD5.create().digestHex("12345"));
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/back-me/src/main/java/com/jzm/backme/util/redis/RedisCache.java:
--------------------------------------------------------------------------------
1 | package com.jzm.backme.util.redis;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.redis.core.BoundSetOperations;
5 | import org.springframework.data.redis.core.HashOperations;
6 | import org.springframework.data.redis.core.RedisTemplate;
7 | import org.springframework.data.redis.core.ValueOperations;
8 | import org.springframework.stereotype.Component;
9 | import org.springframework.stereotype.Service;
10 |
11 | import java.util.*;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | /**
15 | * spring redis 工具类
16 | *
17 | * @author jzm
18 | **/
19 | @SuppressWarnings(value = {"unchecked", "rawtypes"})
20 | @Component
21 | @Service
22 | public class RedisCache
23 | {
24 | @Autowired
25 | public RedisTemplate redisTemplate;
26 | /**
27 | * 缓存基本的对象,Integer、String、实体类等
28 | *
29 | * @param key 缓存的键值
30 | * @param value 缓存的值
31 | */
32 | public void setCacheObject(final String key, final T value)
33 | {
34 | redisTemplate.opsForValue().set(key, value);
35 | }
36 |
37 | /**
38 | * 缓存基本的对象,Integer、String、实体类等
39 | *
40 | * @param key 缓存的键值
41 | * @param value 缓存的值
42 | * @param timeout 时间
43 | * @param timeUnit 时间颗粒度
44 | */
45 | public void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
46 | {
47 | redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
48 | }
49 |
50 | /**
51 | * 设置有效时间
52 | *
53 | * @param key Redis键
54 | * @param timeout 超时时间
55 | * @return true=设置成功;false=设置失败
56 | */
57 | public boolean expire(final String key, final long timeout)
58 | {
59 | return expire(key, timeout, TimeUnit.SECONDS);
60 | }
61 |
62 | /**
63 | * 设置有效时间
64 | *
65 | * @param key Redis键
66 | * @param timeout 超时时间
67 | * @param unit 时间单位
68 | * @return true=设置成功;false=设置失败
69 | */
70 | public boolean expire(final String key, final long timeout, final TimeUnit unit)
71 | {
72 | return redisTemplate.expire(key, timeout, unit);
73 | }
74 |
75 | /**
76 | * 获取有效时间
77 | *
78 | * @param key Redis键
79 | * @return 有效时间
80 | */
81 | public long getExpire(final String key)
82 | {
83 | return redisTemplate.getExpire(key);
84 | }
85 |
86 | /**
87 | * 判断 key是否存在
88 | *
89 | * @param key 键
90 | * @return true 存在 false不存在
91 | */
92 | public Boolean hasKey(String key)
93 | {
94 | return redisTemplate.hasKey(key);
95 | }
96 |
97 | /**
98 | * 获得缓存的基本对象。
99 | *
100 | * @param key 缓存键值
101 | * @return 缓存键值对应的数据
102 | */
103 | public T getCacheObject(final String key)
104 | {
105 | ValueOperations operation = redisTemplate.opsForValue();
106 | return operation.get(key);
107 | }
108 |
109 | /**
110 | * 删除单个对象
111 | *
112 | * @param key
113 | */
114 | public boolean deleteObject(final String key)
115 | {
116 | return redisTemplate.delete(key);
117 | }
118 |
119 | /**
120 | * 删除集合对象
121 | *
122 | * @param collection 多个对象
123 | * @return
124 | */
125 | public boolean deleteObject(final Collection collection)
126 | {
127 | return redisTemplate.delete(collection) > 0;
128 | }
129 |
130 | /**
131 | * 缓存List数据
132 | *
133 | * @param key 缓存的键值
134 | * @param dataList 待缓存的List数据
135 | * @return 缓存的对象
136 | */
137 | public long setCacheList(final String key, final List dataList)
138 | {
139 | Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
140 | return count == null ? 0 : count;
141 | }
142 |
143 | /**
144 | * 获得缓存的list对象
145 | *
146 | * @param key 缓存的键值
147 | * @return 缓存键值对应的数据
148 | */
149 | public List getCacheList(final String key)
150 | {
151 | return redisTemplate.opsForList().range(key, 0, -1);
152 | }
153 |
154 | /**
155 | * 缓存Set
156 | *
157 | * @param key 缓存键值
158 | * @param dataSet 缓存的数据
159 | * @return 缓存数据的对象
160 | */
161 | public BoundSetOperations setCacheSet(final String key, final Set dataSet)
162 | {
163 | BoundSetOperations setOperation = redisTemplate.boundSetOps(key);
164 | for (T t : dataSet)
165 | {
166 | setOperation.add(t);
167 | }
168 | return setOperation;
169 | }
170 |
171 | /**
172 | * 获得缓存的set
173 | *
174 | * @param key
175 | * @return
176 | */
177 | public Set getCacheSet(final String key)
178 | {
179 | return redisTemplate.opsForSet().members(key);
180 | }
181 |
182 | /**
183 | * 缓存Map
184 | *
185 | * @param key
186 | * @param dataMap
187 | */
188 | public void setCacheMap(final String key, final Map dataMap)
189 | {
190 | if (dataMap != null)
191 | {
192 | redisTemplate.opsForHash().putAll(key, dataMap);
193 | }
194 | }
195 |
196 | /**
197 | * 获得缓存的Map
198 | *
199 | * @param key
200 | * @return
201 | */
202 | public Map getCacheMap(final String key)
203 | {
204 | return redisTemplate.opsForHash().entries(key);
205 | }
206 |
207 | /**
208 | * 往Hash中存入数据
209 | *
210 | * @param key Redis键
211 | * @param hKey Hash键
212 | * @param value 值
213 | */
214 | public void setCacheMapValue(final String key, final String hKey, final T value)
215 | {
216 | redisTemplate.opsForHash().put(key, hKey, value);
217 | }
218 |
219 | /**
220 | * 获取Hash中的数据
221 | *
222 | * @param key Redis键
223 | * @param hKey Hash键
224 | * @return Hash中的对象
225 | */
226 | public T getCacheMapValue(final String key, final String hKey)
227 | {
228 | HashOperations opsForHash = redisTemplate.opsForHash();
229 | return opsForHash.get(key, hKey);
230 | }
231 |
232 | /**
233 | * 获取多个Hash中的数据
234 | *
235 | * @param key Redis键
236 | * @param hKeys Hash键集合
237 | * @return Hash对象集合
238 | */
239 | public List getMultiCacheMapValue(final String key, final Collection