Commit 98bb98a91f3e85050214fadb85b28c82c05061d5
1 parent
0c1344e2
feat: 新增装修垃圾独立模块,新增用户控制层,修改单点登录
Showing
16 changed files
with
208 additions
and
61 deletions
trash-garbage/src/main/java/com/trash/garbage/controller/GarbageUserController.java
| 1 | 1 | package com.trash.garbage.controller; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -import com.aliyuncs.exceptions.ClientException; | |
| 5 | 4 | import com.trash.garbage.global.Result; |
| 6 | -import com.trash.garbage.pojo.vo.LoginVo; | |
| 5 | +import com.trash.garbage.pojo.domain.GarAddress; | |
| 6 | +import com.trash.garbage.pojo.dto.AddressDto; | |
| 7 | +import com.trash.garbage.pojo.dto.LoginDto; | |
| 7 | 8 | import com.trash.garbage.service.GarUserService; |
| 8 | -import com.trash.garbage.utils.SMSUtils; | |
| 9 | -import com.trash.garbage.utils.ValidateCodeUtil; | |
| 10 | 9 | import io.swagger.annotations.Api; |
| 11 | 10 | import io.swagger.annotations.ApiOperation; |
| 12 | -import io.swagger.annotations.Tag; | |
| 13 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | 12 | import org.springframework.web.bind.annotation.*; |
| 15 | 13 | |
| 16 | -import java.util.Random; | |
| 14 | +import java.util.List; | |
| 17 | 15 | |
| 18 | 16 | /** |
| 19 | 17 | * @author 20412 |
| ... | ... | @@ -34,7 +32,7 @@ public class GarbageUserController { |
| 34 | 32 | */ |
| 35 | 33 | @ApiOperation("用户接口-用户登录") |
| 36 | 34 | @PostMapping("/login") |
| 37 | - public Result<String> login(@RequestBody LoginVo user) { | |
| 35 | + public Result<String> login(@RequestBody LoginDto user) { | |
| 38 | 36 | return Result.OK(garUserService.login(user)); |
| 39 | 37 | } |
| 40 | 38 | |
| ... | ... | @@ -48,6 +46,17 @@ public class GarbageUserController { |
| 48 | 46 | e.printStackTrace(); |
| 49 | 47 | return Result.ERROR(); |
| 50 | 48 | } |
| 49 | + } | |
| 50 | + | |
| 51 | + @ApiOperation("用户接口-获取用户地址") | |
| 52 | + @GetMapping("/query/address/{type}") | |
| 53 | + public Result<List<GarAddress>> queryAddress(@PathVariable("type") String type){ | |
| 54 | + return Result.OK(garUserService.queryAddress(type)); | |
| 55 | + } | |
| 51 | 56 | |
| 57 | + @ApiOperation("用户接口-新增地址") | |
| 58 | + @PostMapping("/save/address") | |
| 59 | + public Result<String> saveAddress(@RequestBody AddressDto dto){ | |
| 60 | + return Result.OK(garUserService.saveAddress(dto)); | |
| 52 | 61 | } |
| 53 | 62 | } | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/custom/BizException.java
0 → 100644
| 1 | +package com.trash.garbage.custom; | |
| 2 | + | |
| 3 | +import com.trash.garbage.global.ResultCode; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * @author 20412 | |
| 8 | + */ | |
| 9 | +@Data | |
| 10 | +public class BizException extends RuntimeException{ | |
| 11 | + private String msg; | |
| 12 | + private ResultCode code; | |
| 13 | + | |
| 14 | + public BizException(ResultCode code, String msg){ | |
| 15 | + this.msg = msg; | |
| 16 | + this.code = code; | |
| 17 | + } | |
| 18 | +} | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/global/GlobalStatus.java
| ... | ... | @@ -15,6 +15,15 @@ public class GlobalStatus { |
| 15 | 15 | public static final int DEL_FLAG_YES = 1; |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | + * 地址查询类型 当前地址 | |
| 19 | + */ | |
| 20 | + public static final String QUERY_ADDRESS_TYPE_CURRENT = "CURRENT"; | |
| 21 | + /** | |
| 22 | + * 地址查询类型 所有 | |
| 23 | + */ | |
| 24 | + public static final String QUERY_ADDRESS_TYPE_ALL = "ALL"; | |
| 25 | + | |
| 26 | + /** | |
| 18 | 27 | * 用户状态管理 |
| 19 | 28 | */ |
| 20 | 29 | public enum UserStatusEnum{ |
| ... | ... | @@ -40,15 +49,22 @@ public class GlobalStatus { |
| 40 | 49 | /** |
| 41 | 50 | * 字典 |
| 42 | 51 | */ |
| 43 | - public enum DicEnum{ | |
| 44 | - MODE("MODE"), | |
| 45 | - CUSTOM("CUSTOM"); | |
| 46 | - DicEnum(String type){ | |
| 47 | - this.type = type; | |
| 52 | + public enum GarAddressStatus { | |
| 53 | + NORMAL_ADDRESS(0,"地址"), | |
| 54 | + DEFAULT_ADDRESS(1,"默认地址"), | |
| 55 | + CURRENT_ADDRESS(2,"当前选中地址"); | |
| 56 | + GarAddressStatus(Integer status,String description){ | |
| 57 | + this.status = status; | |
| 58 | + this.description = description; | |
| 59 | + } | |
| 60 | + private String description; | |
| 61 | + private Integer status; | |
| 62 | + public Integer getValue(){ | |
| 63 | + return this.status; | |
| 48 | 64 | } |
| 49 | - private String type; | |
| 50 | - public String getValue(){ | |
| 51 | - return this.type; | |
| 65 | + public String getDescription(){ | |
| 66 | + return this.description; | |
| 52 | 67 | } |
| 68 | + | |
| 53 | 69 | } |
| 54 | 70 | } | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/handle/HandleException.java
0 → 100644
| 1 | +package com.trash.garbage.handle; | |
| 2 | + | |
| 3 | +import com.trash.garbage.custom.BizException; | |
| 4 | +import com.trash.garbage.global.Result; | |
| 5 | +import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 6 | +import org.springframework.web.bind.annotation.RestControllerAdvice; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * @author 20412 | |
| 10 | + */ | |
| 11 | +@RestControllerAdvice | |
| 12 | +public class HandleException { | |
| 13 | + | |
| 14 | + @ExceptionHandler(BizException.class) | |
| 15 | + public Result<?> handleBizException(BizException e) { | |
| 16 | + return Result.ERROR(e.getCode(), e.getMsg()); | |
| 17 | + } | |
| 18 | +} | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/interceptor/MyMetaObjectHandler.java
| 1 | 1 | package com.trash.garbage.interceptor; |
| 2 | 2 | |
| 3 | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| 4 | -import com.trash.garbage.global.GlobalStatus; | |
| 5 | 4 | import com.trash.garbage.utils.SecurityUtil; |
| 6 | 5 | import lombok.extern.slf4j.Slf4j; |
| 7 | 6 | import org.apache.ibatis.reflection.MetaObject; |
| ... | ... | @@ -27,7 +26,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { |
| 27 | 26 | |
| 28 | 27 | if (metaObject.hasGetter("garCreateBy")){ |
| 29 | 28 | if (!Objects.isNull(SecurityUtil.getUserCustom())){ |
| 30 | - this.strictInsertFill(metaObject, "garCreateBy", String.class, SecurityUtil.getUserCustom().getUser().getUserId()); | |
| 29 | + this.strictInsertFill(metaObject, "garCreateBy", String.class, SecurityUtil.getUserCustom().getUser().getGarUserId()); | |
| 31 | 30 | } |
| 32 | 31 | } |
| 33 | 32 | |
| ... | ... | @@ -36,12 +35,12 @@ public class MyMetaObjectHandler implements MetaObjectHandler { |
| 36 | 35 | } |
| 37 | 36 | if (metaObject.hasGetter("garUserId")){ |
| 38 | 37 | if (!Objects.isNull(SecurityUtil.getUserCustom())) { |
| 39 | - this.strictInsertFill(metaObject, "garUserId", String.class, SecurityUtil.getUserCustom().getUser().getUserId()); | |
| 38 | + this.strictInsertFill(metaObject, "garUserId", String.class, SecurityUtil.getUserCustom().getUser().getGarUserId()); | |
| 40 | 39 | } |
| 41 | 40 | } |
| 42 | 41 | if (metaObject.hasGetter("garUpdateBy")){ |
| 43 | 42 | if (!Objects.isNull(SecurityUtil.getUserCustom())){ |
| 44 | - this.strictInsertFill(metaObject, "garUpdateBy", String.class, SecurityUtil.getUserCustom().getUser().getUserId()); | |
| 43 | + this.strictInsertFill(metaObject, "garUpdateBy", String.class, SecurityUtil.getUserCustom().getUser().getGarUserId()); | |
| 45 | 44 | } |
| 46 | 45 | } |
| 47 | 46 | } |
| ... | ... | @@ -53,7 +52,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { |
| 53 | 52 | this.strictUpdateFill(metaObject, "garUpdateTime", Date.class, new Date()); |
| 54 | 53 | } |
| 55 | 54 | if (metaObject.hasGetter("garUpdateBy")){ |
| 56 | - this.strictUpdateFill(metaObject,"garUpdateBy",String.class,SecurityUtil.getUserCustom().getUser().getUserId()); | |
| 55 | + this.strictUpdateFill(metaObject,"garUpdateBy",String.class,SecurityUtil.getUserCustom().getUser().getGarUserId()); | |
| 57 | 56 | } |
| 58 | 57 | } |
| 59 | 58 | } |
| 60 | 59 | \ No newline at end of file | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/pojo/domain/GarAddress.java
| 1 | 1 | package com.trash.garbage.pojo.domain; |
| 2 | 2 | |
| 3 | +import com.baomidou.mybatisplus.annotation.FieldFill; | |
| 3 | 4 | import com.baomidou.mybatisplus.annotation.TableField; |
| 4 | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 5 | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | + | |
| 6 | 8 | import java.io.Serializable; |
| 7 | 9 | import java.util.Date; |
| 10 | + | |
| 8 | 11 | import lombok.Data; |
| 9 | 12 | |
| 13 | + | |
| 10 | 14 | /** |
| 11 | 15 | * 建筑垃圾-用户地址 |
| 16 | + * | |
| 12 | 17 | * @author 20412 |
| 13 | 18 | * @TableName gar_address |
| 14 | 19 | */ |
| 15 | -@TableName(value ="gar_address") | |
| 20 | +@TableName(value = "gar_address") | |
| 16 | 21 | @Data |
| 17 | 22 | public class GarAddress implements Serializable { |
| 18 | 23 | /** |
| ... | ... | @@ -24,7 +29,7 @@ public class GarAddress implements Serializable { |
| 24 | 29 | /** |
| 25 | 30 | * 用户id |
| 26 | 31 | */ |
| 27 | - private Long garUserId; | |
| 32 | + private String garUserId; | |
| 28 | 33 | |
| 29 | 34 | /** |
| 30 | 35 | * 用户地址 |
| ... | ... | @@ -39,14 +44,26 @@ public class GarAddress implements Serializable { |
| 39 | 44 | /** |
| 40 | 45 | * 创建时间 |
| 41 | 46 | */ |
| 47 | + @TableField(fill = FieldFill.INSERT) | |
| 42 | 48 | private Date garCreateTime; |
| 43 | 49 | |
| 44 | 50 | /** |
| 45 | 51 | * 修改时间 |
| 46 | 52 | */ |
| 53 | + @TableField(fill = FieldFill.INSERT_UPDATE) | |
| 47 | 54 | private Date garUpdateTime; |
| 48 | 55 | |
| 49 | 56 | /** |
| 57 | + * 联系人名 | |
| 58 | + */ | |
| 59 | + private String garUserContactName; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * 联系电话 | |
| 63 | + */ | |
| 64 | + private String garUserContactTel; | |
| 65 | + | |
| 66 | + /** | |
| 50 | 67 | * 备注 |
| 51 | 68 | */ |
| 52 | 69 | private String garRemark; |
| ... | ... | @@ -67,12 +84,14 @@ public class GarAddress implements Serializable { |
| 67 | 84 | } |
| 68 | 85 | GarAddress other = (GarAddress) that; |
| 69 | 86 | return (this.getGarAddressId() == null ? other.getGarAddressId() == null : this.getGarAddressId().equals(other.getGarAddressId())) |
| 70 | - && (this.getGarUserId() == null ? other.getGarUserId() == null : this.getGarUserId().equals(other.getGarUserId())) | |
| 71 | - && (this.getGarUserAddress() == null ? other.getGarUserAddress() == null : this.getGarUserAddress().equals(other.getGarUserAddress())) | |
| 72 | - && (this.getGarUserDefault() == null ? other.getGarUserDefault() == null : this.getGarUserDefault().equals(other.getGarUserDefault())) | |
| 73 | - && (this.getGarCreateTime() == null ? other.getGarCreateTime() == null : this.getGarCreateTime().equals(other.getGarCreateTime())) | |
| 74 | - && (this.getGarUpdateTime() == null ? other.getGarUpdateTime() == null : this.getGarUpdateTime().equals(other.getGarUpdateTime())) | |
| 75 | - && (this.getGarRemark() == null ? other.getGarRemark() == null : this.getGarRemark().equals(other.getGarRemark())); | |
| 87 | + && (this.getGarUserId() == null ? other.getGarUserId() == null : this.getGarUserId().equals(other.getGarUserId())) | |
| 88 | + && (this.getGarUserAddress() == null ? other.getGarUserAddress() == null : this.getGarUserAddress().equals(other.getGarUserAddress())) | |
| 89 | + && (this.getGarUserDefault() == null ? other.getGarUserDefault() == null : this.getGarUserDefault().equals(other.getGarUserDefault())) | |
| 90 | + && (this.getGarCreateTime() == null ? other.getGarCreateTime() == null : this.getGarCreateTime().equals(other.getGarCreateTime())) | |
| 91 | + && (this.getGarUpdateTime() == null ? other.getGarUpdateTime() == null : this.getGarUpdateTime().equals(other.getGarUpdateTime())) | |
| 92 | + && (this.getGarUserContactName() == null ? other.getGarUserContactName() == null : this.getGarUserContactName().equals(other.getGarUserContactName())) | |
| 93 | + && (this.getGarUserContactTel() == null ? other.getGarUserContactTel() == null : this.getGarUserContactTel().equals(other.getGarUserContactTel())) | |
| 94 | + && (this.getGarRemark() == null ? other.getGarRemark() == null : this.getGarRemark().equals(other.getGarRemark())); | |
| 76 | 95 | } |
| 77 | 96 | |
| 78 | 97 | @Override |
| ... | ... | @@ -85,6 +104,8 @@ public class GarAddress implements Serializable { |
| 85 | 104 | result = prime * result + ((getGarUserDefault() == null) ? 0 : getGarUserDefault().hashCode()); |
| 86 | 105 | result = prime * result + ((getGarCreateTime() == null) ? 0 : getGarCreateTime().hashCode()); |
| 87 | 106 | result = prime * result + ((getGarUpdateTime() == null) ? 0 : getGarUpdateTime().hashCode()); |
| 107 | + result = prime * result + ((getGarUserContactName() == null) ? 0 : getGarUserContactName().hashCode()); | |
| 108 | + result = prime * result + ((getGarUserContactTel() == null) ? 0 : getGarUserContactTel().hashCode()); | |
| 88 | 109 | result = prime * result + ((getGarRemark() == null) ? 0 : getGarRemark().hashCode()); |
| 89 | 110 | return result; |
| 90 | 111 | } |
| ... | ... | @@ -101,9 +122,11 @@ public class GarAddress implements Serializable { |
| 101 | 122 | sb.append(", garUserDefault=").append(garUserDefault); |
| 102 | 123 | sb.append(", garCreateTime=").append(garCreateTime); |
| 103 | 124 | sb.append(", garUpdateTime=").append(garUpdateTime); |
| 125 | + sb.append(", garUserContactName=").append(garUserContactName); | |
| 126 | + sb.append(", garUserContactTel=").append(garUserContactTel); | |
| 104 | 127 | sb.append(", garRemark=").append(garRemark); |
| 105 | 128 | sb.append(", serialVersionUID=").append(serialVersionUID); |
| 106 | 129 | sb.append("]"); |
| 107 | 130 | return sb.toString(); |
| 108 | 131 | } |
| 109 | -} | |
| 110 | 132 | \ No newline at end of file |
| 133 | +} | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/pojo/dto/AddressDto.java
0 → 100644
| 1 | +package com.trash.garbage.pojo.dto; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @author 20412 | |
| 7 | + */ | |
| 8 | +@Data | |
| 9 | +public class AddressDto { | |
| 10 | + private String address; | |
| 11 | + private String details; | |
| 12 | + private String contactName; | |
| 13 | + private String contactTel; | |
| 14 | + private Integer defaultFlag; | |
| 15 | +} | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/pojo/vo/LoginVo.java renamed to trash-garbage/src/main/java/com/trash/garbage/pojo/dto/LoginDto.java
| 1 | -package com.trash.garbage.pojo.vo; | |
| 1 | +package com.trash.garbage.pojo.dto; | |
| 2 | 2 | |
| 3 | 3 | import io.swagger.annotations.ApiModel; |
| 4 | 4 | import io.swagger.annotations.ApiModelProperty; |
| 5 | 5 | import lombok.Data; |
| 6 | 6 | |
| 7 | -import javax.validation.constraints.NotBlank; | |
| 8 | - | |
| 9 | 7 | /** |
| 10 | 8 | * @author 20412 |
| 11 | 9 | */ |
| 12 | 10 | @Data |
| 13 | 11 | @ApiModel(value = "登录vo") |
| 14 | -public class LoginVo { | |
| 12 | +public class LoginDto { | |
| 15 | 13 | @ApiModelProperty(value = "登录vo-手机号") |
| 16 | 14 | private String tel; |
| 17 | 15 | @ApiModelProperty(value = "登录vo-验证码") | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/security/UserAbstract.java
trash-garbage/src/main/java/com/trash/garbage/service/GarAddressService.java
| 1 | 1 | package com.trash.garbage.service; |
| 2 | 2 | |
| 3 | -import com.trash.garbage.pojo.domain.GarAddress; | |
| 4 | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
| 4 | +import com.trash.garbage.pojo.domain.GarAddress; | |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @author 20412 |
| 8 | 8 | * @description 针对表【gar_address(建筑垃圾-用户地址)】的数据库操作Service |
| 9 | -* @createDate 2023-11-20 16:03:15 | |
| 9 | +* @createDate 2023-11-22 09:48:43 | |
| 10 | 10 | */ |
| 11 | 11 | public interface GarAddressService extends IService<GarAddress> { |
| 12 | 12 | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/service/GarUserService.java
| 1 | 1 | package com.trash.garbage.service; |
| 2 | 2 | |
| 3 | 3 | import com.aliyuncs.exceptions.ClientException; |
| 4 | +import com.trash.garbage.pojo.domain.GarAddress; | |
| 4 | 5 | import com.trash.garbage.pojo.domain.GarUser; |
| 5 | 6 | import com.baomidou.mybatisplus.extension.service.IService; |
| 6 | -import com.trash.garbage.pojo.vo.LoginVo; | |
| 7 | +import com.trash.garbage.pojo.dto.AddressDto; | |
| 8 | +import com.trash.garbage.pojo.dto.LoginDto; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 7 | 11 | |
| 8 | 12 | /** |
| 9 | 13 | * @author 20412 |
| ... | ... | @@ -12,7 +16,11 @@ import com.trash.garbage.pojo.vo.LoginVo; |
| 12 | 16 | */ |
| 13 | 17 | public interface GarUserService extends IService<GarUser> { |
| 14 | 18 | |
| 15 | - String login(LoginVo user); | |
| 19 | + String login(LoginDto user); | |
| 16 | 20 | |
| 17 | 21 | void sendVerify(String tel) throws ClientException; |
| 22 | + | |
| 23 | + List<GarAddress> queryAddress(String type); | |
| 24 | + | |
| 25 | + String saveAddress(AddressDto dto); | |
| 18 | 26 | } | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/service/impl/GarAddressServiceImpl.java
| 1 | 1 | package com.trash.garbage.service.impl; |
| 2 | 2 | |
| 3 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 4 | +import com.trash.garbage.mapper.GarAddressMapper; | |
| 4 | 5 | import com.trash.garbage.pojo.domain.GarAddress; |
| 5 | 6 | import com.trash.garbage.service.GarAddressService; |
| 6 | -import com.trash.garbage.mapper.GarAddressMapper; | |
| 7 | 7 | import org.springframework.stereotype.Service; |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * @author 20412 |
| 11 | 11 | * @description 针对表【gar_address(建筑垃圾-用户地址)】的数据库操作Service实现 |
| 12 | -* @createDate 2023-11-20 16:03:15 | |
| 12 | +* @createDate 2023-11-22 09:48:43 | |
| 13 | 13 | */ |
| 14 | 14 | @Service |
| 15 | 15 | public class GarAddressServiceImpl extends ServiceImpl<GarAddressMapper, GarAddress> |
| 16 | - implements GarAddressService{ | |
| 16 | + implements GarAddressService { | |
| 17 | 17 | |
| 18 | 18 | } |
| 19 | 19 | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/service/impl/GarUserServiceImpl.java
| ... | ... | @@ -3,22 +3,23 @@ package com.trash.garbage.service.impl; |
| 3 | 3 | import cn.hutool.http.HttpUtil; |
| 4 | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | 5 | import com.aliyuncs.exceptions.ClientException; |
| 6 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 6 | 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 7 | 8 | import com.trash.garbage.config.WxConfig; |
| 9 | +import com.trash.garbage.custom.BizException; | |
| 8 | 10 | import com.trash.garbage.global.GlobalRedisProperties; |
| 9 | 11 | import com.trash.garbage.global.GlobalStatus; |
| 10 | -import com.trash.garbage.global.Result; | |
| 12 | +import com.trash.garbage.global.ResultCode; | |
| 13 | +import com.trash.garbage.pojo.domain.GarAddress; | |
| 11 | 14 | import com.trash.garbage.pojo.domain.GarUser; |
| 12 | -import com.trash.garbage.pojo.vo.LoginVo; | |
| 15 | +import com.trash.garbage.pojo.dto.AddressDto; | |
| 16 | +import com.trash.garbage.pojo.dto.LoginDto; | |
| 13 | 17 | import com.trash.garbage.security.UserCustom; |
| 18 | +import com.trash.garbage.service.GarAddressService; | |
| 14 | 19 | import com.trash.garbage.service.GarUserService; |
| 15 | 20 | import com.trash.garbage.mapper.GarUserMapper; |
| 16 | -import com.trash.garbage.utils.JwtUtils; | |
| 17 | -import com.trash.garbage.utils.RedisUtils; | |
| 18 | -import com.trash.garbage.utils.SMSUtils; | |
| 19 | -import com.trash.garbage.utils.ValidateCodeUtil; | |
| 21 | +import com.trash.garbage.utils.*; | |
| 20 | 22 | import org.apache.commons.codec.binary.Base64; |
| 21 | -import org.apache.commons.lang3.StringUtils; | |
| 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| 23 | 24 | import org.springframework.security.authentication.AuthenticationManager; |
| 24 | 25 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| ... | ... | @@ -32,6 +33,8 @@ import javax.crypto.Cipher; |
| 32 | 33 | import javax.crypto.spec.IvParameterSpec; |
| 33 | 34 | import javax.crypto.spec.SecretKeySpec; |
| 34 | 35 | import java.security.spec.AlgorithmParameterSpec; |
| 36 | +import java.util.Arrays; | |
| 37 | +import java.util.List; | |
| 35 | 38 | import java.util.Objects; |
| 36 | 39 | import java.util.concurrent.TimeUnit; |
| 37 | 40 | |
| ... | ... | @@ -49,12 +52,15 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> |
| 49 | 52 | @Autowired |
| 50 | 53 | private AuthenticationManager authenticationManager; |
| 51 | 54 | |
| 55 | + @Autowired | |
| 56 | + private GarAddressService garAddressService; | |
| 57 | + | |
| 52 | 58 | @Resource |
| 53 | 59 | private RedisUtils redisUtils; |
| 54 | 60 | |
| 55 | 61 | |
| 56 | 62 | @Override |
| 57 | - public String login(LoginVo user) { | |
| 63 | + public String login(LoginDto user) { | |
| 58 | 64 | if (Objects.isNull(user)) { |
| 59 | 65 | throw new UsernameNotFoundException("当前用户不存在"); |
| 60 | 66 | } |
| ... | ... | @@ -73,7 +79,7 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> |
| 73 | 79 | // 验证码验证 |
| 74 | 80 | Integer code = (Integer) redisUtils.get(GlobalRedisProperties.REDIS_USER_CODE.getValue() + user.getTel()); |
| 75 | 81 | if (!code.equals(user.getCode())) { |
| 76 | - throw new RuntimeException("验证码错误!!"); | |
| 82 | + throw new BizException(ResultCode.CODE_400, "验证码错误!!"); | |
| 77 | 83 | } |
| 78 | 84 | // 封装成authentication对象 |
| 79 | 85 | Authentication authentication = new UsernamePasswordAuthenticationToken(user.getTel(), ""); |
| ... | ... | @@ -84,9 +90,9 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> |
| 84 | 90 | } |
| 85 | 91 | UserCustom userCustom = (UserCustom) authenticate.getPrincipal(); |
| 86 | 92 | // 存入redis |
| 87 | - redisUtils.set(GlobalRedisProperties.REDIS_USER_HEADER.getValue() + userCustom.getUser().getUserId(), userCustom); | |
| 93 | + redisUtils.set(GlobalRedisProperties.REDIS_USER_HEADER.getValue() + userCustom.getUser().getGarUserId(), userCustom); | |
| 88 | 94 | // 修改在线状态 |
| 89 | - return JwtUtils.createToken(userCustom.getUser().getTel(), userCustom.getUser().getUserId()); | |
| 95 | + return JwtUtils.createToken(userCustom.getUser().getTel(), userCustom.getUser().getGarUserId()); | |
| 90 | 96 | } |
| 91 | 97 | |
| 92 | 98 | @Override |
| ... | ... | @@ -96,10 +102,44 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> |
| 96 | 102 | //给用户发送验证码 |
| 97 | 103 | // SMSUtils.sendMessage("", tel, validateCode.toString(), ""); |
| 98 | 104 | // 保存redis |
| 99 | - System.out.println("code:"+ validateCode); | |
| 105 | + System.out.println("code:" + validateCode); | |
| 100 | 106 | redisUtils.setEx(GlobalRedisProperties.REDIS_USER_CODE.getValue() + tel, validateCode, 60, TimeUnit.SECONDS); |
| 101 | 107 | } |
| 102 | 108 | |
| 109 | + @Override | |
| 110 | + public List<GarAddress> queryAddress(String type) { | |
| 111 | + UserCustom userCustom = SecurityUtil.getUserCustom(); | |
| 112 | + if (Objects.isNull(userCustom)) { | |
| 113 | + throw new BizException(ResultCode.CODE_401, ResultCode.CODE_401.getMsg()); | |
| 114 | + } | |
| 115 | + String garUserId = userCustom.getUser().getGarUserId(); | |
| 116 | + LambdaQueryWrapper<GarAddress> qw = new LambdaQueryWrapper<>(); | |
| 117 | + qw.eq(GarAddress::getGarUserId, garUserId); | |
| 118 | + List<GarAddress> addressList = garAddressService.list(qw); | |
| 119 | + if (GlobalStatus.QUERY_ADDRESS_TYPE_CURRENT.equals(type)) { | |
| 120 | + for (GarAddress garAddress : addressList) { | |
| 121 | + if (GlobalStatus.GarAddressStatus.CURRENT_ADDRESS.getValue().equals(garAddress.getGarUserDefault())) { | |
| 122 | + return Arrays.asList(garAddress); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + } | |
| 126 | + return addressList; | |
| 127 | + } | |
| 128 | + | |
| 129 | + @Override | |
| 130 | + public String saveAddress(AddressDto dto) { | |
| 131 | + UserCustom userCustom = SecurityUtil.getUserCustom(); | |
| 132 | + GarAddress garAddress = new GarAddress(); | |
| 133 | + garAddress.setGarUserId(userCustom.getUser().getGarUserId()); | |
| 134 | + garAddress.setGarUserAddress(dto.getAddress()); | |
| 135 | + garAddress.setGarUserDefault(dto.getDefaultFlag()); | |
| 136 | + garAddress.setGarUserContactName(dto.getContactName()); | |
| 137 | + garAddress.setGarUserContactTel(dto.getContactTel()); | |
| 138 | + garAddress.setGarRemark(dto.getDetails()); | |
| 139 | + garAddressService.save(garAddress); | |
| 140 | + return "新增地址成功"; | |
| 141 | + } | |
| 142 | + | |
| 103 | 143 | |
| 104 | 144 | /** |
| 105 | 145 | * 微信小程序解密 | ... | ... |
trash-garbage/src/main/java/com/trash/garbage/utils/SecurityUtil.java
| 1 | 1 | package com.trash.garbage.utils; |
| 2 | 2 | |
| 3 | +import com.trash.garbage.custom.BizException; | |
| 4 | +import com.trash.garbage.global.ResultCode; | |
| 3 | 5 | import com.trash.garbage.security.UserCustom; |
| 4 | 6 | import org.springframework.security.core.context.SecurityContextHolder; |
| 5 | 7 | |
| ... | ... | @@ -11,8 +13,7 @@ public class SecurityUtil { |
| 11 | 13 | |
| 12 | 14 | public static UserCustom getUserCustom() { |
| 13 | 15 | if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof UserCustom) |
| 14 | - return (UserCustom) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | |
| 15 | - return null; | |
| 16 | + return (UserCustom) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | |
| 17 | + throw new BizException(ResultCode.CODE_401, ResultCode.CODE_401.getMsg()); | |
| 16 | 18 | } |
| 17 | - | |
| 18 | 19 | } | ... | ... |
trash-garbage/src/main/resources/application-dev.yml
| ... | ... | @@ -53,10 +53,11 @@ spring: |
| 53 | 53 | redis: |
| 54 | 54 | # 地址 |
| 55 | 55 | # host: 121.41.83.61 |
| 56 | - host: 192.168.172.221 | |
| 56 | +# host: 192.168.172.221 | |
| 57 | + host: 127.0.0.1 | |
| 57 | 58 | database: 0 |
| 58 | 59 | # password: "guzijian" |
| 59 | - port: 6378 | |
| 60 | + port: 6379 | |
| 60 | 61 | # 连接超时时间 |
| 61 | 62 | timeout: 10s |
| 62 | 63 | lettuce: |
| ... | ... | @@ -79,7 +80,6 @@ mybatis-plus: |
| 79 | 80 | global-config: |
| 80 | 81 | # 指定逻辑删除含义 |
| 81 | 82 | db-config: |
| 82 | - logic-delete-field: delFlag | |
| 83 | 83 | logic-delete-value: 1 |
| 84 | 84 | logic-not-delete-value: 0 |
| 85 | 85 | configuration: | ... | ... |
trash-garbage/src/main/resources/mapper/GarAddressMapper.xml
| ... | ... | @@ -6,17 +6,19 @@ |
| 6 | 6 | |
| 7 | 7 | <resultMap id="BaseResultMap" type="com.trash.garbage.pojo.domain.GarAddress"> |
| 8 | 8 | <id property="garAddressId" column="gar_address_id" jdbcType="BIGINT"/> |
| 9 | - <result property="garUserId" column="gar_user_id" jdbcType="BIGINT"/> | |
| 9 | + <result property="garUserId" column="gar_user_id" jdbcType="VARCHAR"/> | |
| 10 | 10 | <result property="garUserAddress" column="gar_user_address" jdbcType="VARCHAR"/> |
| 11 | 11 | <result property="garUserDefault" column="gar_user_default" jdbcType="TINYINT"/> |
| 12 | 12 | <result property="garCreateTime" column="gar_create_time" jdbcType="TIMESTAMP"/> |
| 13 | 13 | <result property="garUpdateTime" column="gar_update_time" jdbcType="TIMESTAMP"/> |
| 14 | + <result property="garUserContactName" column="gar_user_contact_name" jdbcType="VARCHAR"/> | |
| 15 | + <result property="garUserContactTel" column="gar_user_contact_tel" jdbcType="VARCHAR"/> | |
| 14 | 16 | <result property="garRemark" column="gar_remark" jdbcType="VARCHAR"/> |
| 15 | 17 | </resultMap> |
| 16 | 18 | |
| 17 | 19 | <sql id="Base_Column_List"> |
| 18 | 20 | gar_address_id,gar_user_id,gar_user_address, |
| 19 | 21 | gar_user_default,gar_create_time,gar_update_time, |
| 20 | - gar_remark | |
| 22 | + gar_user_contact_name,gar_user_contact_tel,gar_remark | |
| 21 | 23 | </sql> |
| 22 | 24 | </mapper> | ... | ... |