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 | package com.trash.garbage.controller; | 1 | package com.trash.garbage.controller; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import com.aliyuncs.exceptions.ClientException; | ||
| 5 | import com.trash.garbage.global.Result; | 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 | import com.trash.garbage.service.GarUserService; | 8 | import com.trash.garbage.service.GarUserService; |
| 8 | -import com.trash.garbage.utils.SMSUtils; | ||
| 9 | -import com.trash.garbage.utils.ValidateCodeUtil; | ||
| 10 | import io.swagger.annotations.Api; | 9 | import io.swagger.annotations.Api; |
| 11 | import io.swagger.annotations.ApiOperation; | 10 | import io.swagger.annotations.ApiOperation; |
| 12 | -import io.swagger.annotations.Tag; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.web.bind.annotation.*; | 12 | import org.springframework.web.bind.annotation.*; |
| 15 | 13 | ||
| 16 | -import java.util.Random; | 14 | +import java.util.List; |
| 17 | 15 | ||
| 18 | /** | 16 | /** |
| 19 | * @author 20412 | 17 | * @author 20412 |
| @@ -34,7 +32,7 @@ public class GarbageUserController { | @@ -34,7 +32,7 @@ public class GarbageUserController { | ||
| 34 | */ | 32 | */ |
| 35 | @ApiOperation("用户接口-用户登录") | 33 | @ApiOperation("用户接口-用户登录") |
| 36 | @PostMapping("/login") | 34 | @PostMapping("/login") |
| 37 | - public Result<String> login(@RequestBody LoginVo user) { | 35 | + public Result<String> login(@RequestBody LoginDto user) { |
| 38 | return Result.OK(garUserService.login(user)); | 36 | return Result.OK(garUserService.login(user)); |
| 39 | } | 37 | } |
| 40 | 38 | ||
| @@ -48,6 +46,17 @@ public class GarbageUserController { | @@ -48,6 +46,17 @@ public class GarbageUserController { | ||
| 48 | e.printStackTrace(); | 46 | e.printStackTrace(); |
| 49 | return Result.ERROR(); | 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,6 +15,15 @@ public class GlobalStatus { | ||
| 15 | public static final int DEL_FLAG_YES = 1; | 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 | public enum UserStatusEnum{ | 29 | public enum UserStatusEnum{ |
| @@ -40,15 +49,22 @@ public class GlobalStatus { | @@ -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 | package com.trash.garbage.interceptor; | 1 | package com.trash.garbage.interceptor; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| 4 | -import com.trash.garbage.global.GlobalStatus; | ||
| 5 | import com.trash.garbage.utils.SecurityUtil; | 4 | import com.trash.garbage.utils.SecurityUtil; |
| 6 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 7 | import org.apache.ibatis.reflection.MetaObject; | 6 | import org.apache.ibatis.reflection.MetaObject; |
| @@ -27,7 +26,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { | @@ -27,7 +26,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { | ||
| 27 | 26 | ||
| 28 | if (metaObject.hasGetter("garCreateBy")){ | 27 | if (metaObject.hasGetter("garCreateBy")){ |
| 29 | if (!Objects.isNull(SecurityUtil.getUserCustom())){ | 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,12 +35,12 @@ public class MyMetaObjectHandler implements MetaObjectHandler { | ||
| 36 | } | 35 | } |
| 37 | if (metaObject.hasGetter("garUserId")){ | 36 | if (metaObject.hasGetter("garUserId")){ |
| 38 | if (!Objects.isNull(SecurityUtil.getUserCustom())) { | 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 | if (metaObject.hasGetter("garUpdateBy")){ | 41 | if (metaObject.hasGetter("garUpdateBy")){ |
| 43 | if (!Objects.isNull(SecurityUtil.getUserCustom())){ | 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,7 +52,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { | ||
| 53 | this.strictUpdateFill(metaObject, "garUpdateTime", Date.class, new Date()); | 52 | this.strictUpdateFill(metaObject, "garUpdateTime", Date.class, new Date()); |
| 54 | } | 53 | } |
| 55 | if (metaObject.hasGetter("garUpdateBy")){ | 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 | \ No newline at end of file | 59 | \ No newline at end of file |
trash-garbage/src/main/java/com/trash/garbage/pojo/domain/GarAddress.java
| 1 | package com.trash.garbage.pojo.domain; | 1 | package com.trash.garbage.pojo.domain; |
| 2 | 2 | ||
| 3 | +import com.baomidou.mybatisplus.annotation.FieldFill; | ||
| 3 | import com.baomidou.mybatisplus.annotation.TableField; | 4 | import com.baomidou.mybatisplus.annotation.TableField; |
| 4 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 5 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 7 | + | ||
| 6 | import java.io.Serializable; | 8 | import java.io.Serializable; |
| 7 | import java.util.Date; | 9 | import java.util.Date; |
| 10 | + | ||
| 8 | import lombok.Data; | 11 | import lombok.Data; |
| 9 | 12 | ||
| 13 | + | ||
| 10 | /** | 14 | /** |
| 11 | * 建筑垃圾-用户地址 | 15 | * 建筑垃圾-用户地址 |
| 16 | + * | ||
| 12 | * @author 20412 | 17 | * @author 20412 |
| 13 | * @TableName gar_address | 18 | * @TableName gar_address |
| 14 | */ | 19 | */ |
| 15 | -@TableName(value ="gar_address") | 20 | +@TableName(value = "gar_address") |
| 16 | @Data | 21 | @Data |
| 17 | public class GarAddress implements Serializable { | 22 | public class GarAddress implements Serializable { |
| 18 | /** | 23 | /** |
| @@ -24,7 +29,7 @@ public class GarAddress implements Serializable { | @@ -24,7 +29,7 @@ public class GarAddress implements Serializable { | ||
| 24 | /** | 29 | /** |
| 25 | * 用户id | 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,14 +44,26 @@ public class GarAddress implements Serializable { | ||
| 39 | /** | 44 | /** |
| 40 | * 创建时间 | 45 | * 创建时间 |
| 41 | */ | 46 | */ |
| 47 | + @TableField(fill = FieldFill.INSERT) | ||
| 42 | private Date garCreateTime; | 48 | private Date garCreateTime; |
| 43 | 49 | ||
| 44 | /** | 50 | /** |
| 45 | * 修改时间 | 51 | * 修改时间 |
| 46 | */ | 52 | */ |
| 53 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 47 | private Date garUpdateTime; | 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 | private String garRemark; | 69 | private String garRemark; |
| @@ -67,12 +84,14 @@ public class GarAddress implements Serializable { | @@ -67,12 +84,14 @@ public class GarAddress implements Serializable { | ||
| 67 | } | 84 | } |
| 68 | GarAddress other = (GarAddress) that; | 85 | GarAddress other = (GarAddress) that; |
| 69 | return (this.getGarAddressId() == null ? other.getGarAddressId() == null : this.getGarAddressId().equals(other.getGarAddressId())) | 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 | @Override | 97 | @Override |
| @@ -85,6 +104,8 @@ public class GarAddress implements Serializable { | @@ -85,6 +104,8 @@ public class GarAddress implements Serializable { | ||
| 85 | result = prime * result + ((getGarUserDefault() == null) ? 0 : getGarUserDefault().hashCode()); | 104 | result = prime * result + ((getGarUserDefault() == null) ? 0 : getGarUserDefault().hashCode()); |
| 86 | result = prime * result + ((getGarCreateTime() == null) ? 0 : getGarCreateTime().hashCode()); | 105 | result = prime * result + ((getGarCreateTime() == null) ? 0 : getGarCreateTime().hashCode()); |
| 87 | result = prime * result + ((getGarUpdateTime() == null) ? 0 : getGarUpdateTime().hashCode()); | 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 | result = prime * result + ((getGarRemark() == null) ? 0 : getGarRemark().hashCode()); | 109 | result = prime * result + ((getGarRemark() == null) ? 0 : getGarRemark().hashCode()); |
| 89 | return result; | 110 | return result; |
| 90 | } | 111 | } |
| @@ -101,9 +122,11 @@ public class GarAddress implements Serializable { | @@ -101,9 +122,11 @@ public class GarAddress implements Serializable { | ||
| 101 | sb.append(", garUserDefault=").append(garUserDefault); | 122 | sb.append(", garUserDefault=").append(garUserDefault); |
| 102 | sb.append(", garCreateTime=").append(garCreateTime); | 123 | sb.append(", garCreateTime=").append(garCreateTime); |
| 103 | sb.append(", garUpdateTime=").append(garUpdateTime); | 124 | sb.append(", garUpdateTime=").append(garUpdateTime); |
| 125 | + sb.append(", garUserContactName=").append(garUserContactName); | ||
| 126 | + sb.append(", garUserContactTel=").append(garUserContactTel); | ||
| 104 | sb.append(", garRemark=").append(garRemark); | 127 | sb.append(", garRemark=").append(garRemark); |
| 105 | sb.append(", serialVersionUID=").append(serialVersionUID); | 128 | sb.append(", serialVersionUID=").append(serialVersionUID); |
| 106 | sb.append("]"); | 129 | sb.append("]"); |
| 107 | return sb.toString(); | 130 | return sb.toString(); |
| 108 | } | 131 | } |
| 109 | -} | ||
| 110 | \ No newline at end of file | 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 | import io.swagger.annotations.ApiModel; | 3 | import io.swagger.annotations.ApiModel; |
| 4 | import io.swagger.annotations.ApiModelProperty; | 4 | import io.swagger.annotations.ApiModelProperty; |
| 5 | import lombok.Data; | 5 | import lombok.Data; |
| 6 | 6 | ||
| 7 | -import javax.validation.constraints.NotBlank; | ||
| 8 | - | ||
| 9 | /** | 7 | /** |
| 10 | * @author 20412 | 8 | * @author 20412 |
| 11 | */ | 9 | */ |
| 12 | @Data | 10 | @Data |
| 13 | @ApiModel(value = "登录vo") | 11 | @ApiModel(value = "登录vo") |
| 14 | -public class LoginVo { | 12 | +public class LoginDto { |
| 15 | @ApiModelProperty(value = "登录vo-手机号") | 13 | @ApiModelProperty(value = "登录vo-手机号") |
| 16 | private String tel; | 14 | private String tel; |
| 17 | @ApiModelProperty(value = "登录vo-验证码") | 15 | @ApiModelProperty(value = "登录vo-验证码") |
trash-garbage/src/main/java/com/trash/garbage/security/UserAbstract.java
| @@ -17,7 +17,7 @@ public abstract class UserAbstract { | @@ -17,7 +17,7 @@ public abstract class UserAbstract { | ||
| 17 | */ | 17 | */ |
| 18 | public abstract String getTel(); | 18 | public abstract String getTel(); |
| 19 | 19 | ||
| 20 | - public String getUserId(){ | 20 | + public String getGarUserId(){ |
| 21 | return this.garUserId; | 21 | return this.garUserId; |
| 22 | } | 22 | } |
| 23 | 23 |
trash-garbage/src/main/java/com/trash/garbage/service/GarAddressService.java
| 1 | package com.trash.garbage.service; | 1 | package com.trash.garbage.service; |
| 2 | 2 | ||
| 3 | -import com.trash.garbage.pojo.domain.GarAddress; | ||
| 4 | import com.baomidou.mybatisplus.extension.service.IService; | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
| 4 | +import com.trash.garbage.pojo.domain.GarAddress; | ||
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | * @author 20412 | 7 | * @author 20412 |
| 8 | * @description 针对表【gar_address(建筑垃圾-用户地址)】的数据库操作Service | 8 | * @description 针对表【gar_address(建筑垃圾-用户地址)】的数据库操作Service |
| 9 | -* @createDate 2023-11-20 16:03:15 | 9 | +* @createDate 2023-11-22 09:48:43 |
| 10 | */ | 10 | */ |
| 11 | public interface GarAddressService extends IService<GarAddress> { | 11 | public interface GarAddressService extends IService<GarAddress> { |
| 12 | 12 |
trash-garbage/src/main/java/com/trash/garbage/service/GarUserService.java
| 1 | package com.trash.garbage.service; | 1 | package com.trash.garbage.service; |
| 2 | 2 | ||
| 3 | import com.aliyuncs.exceptions.ClientException; | 3 | import com.aliyuncs.exceptions.ClientException; |
| 4 | +import com.trash.garbage.pojo.domain.GarAddress; | ||
| 4 | import com.trash.garbage.pojo.domain.GarUser; | 5 | import com.trash.garbage.pojo.domain.GarUser; |
| 5 | import com.baomidou.mybatisplus.extension.service.IService; | 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 | * @author 20412 | 13 | * @author 20412 |
| @@ -12,7 +16,11 @@ import com.trash.garbage.pojo.vo.LoginVo; | @@ -12,7 +16,11 @@ import com.trash.garbage.pojo.vo.LoginVo; | ||
| 12 | */ | 16 | */ |
| 13 | public interface GarUserService extends IService<GarUser> { | 17 | public interface GarUserService extends IService<GarUser> { |
| 14 | 18 | ||
| 15 | - String login(LoginVo user); | 19 | + String login(LoginDto user); |
| 16 | 20 | ||
| 17 | void sendVerify(String tel) throws ClientException; | 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 | package com.trash.garbage.service.impl; | 1 | package com.trash.garbage.service.impl; |
| 2 | 2 | ||
| 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 4 | +import com.trash.garbage.mapper.GarAddressMapper; | ||
| 4 | import com.trash.garbage.pojo.domain.GarAddress; | 5 | import com.trash.garbage.pojo.domain.GarAddress; |
| 5 | import com.trash.garbage.service.GarAddressService; | 6 | import com.trash.garbage.service.GarAddressService; |
| 6 | -import com.trash.garbage.mapper.GarAddressMapper; | ||
| 7 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | * @author 20412 | 10 | * @author 20412 |
| 11 | * @description 针对表【gar_address(建筑垃圾-用户地址)】的数据库操作Service实现 | 11 | * @description 针对表【gar_address(建筑垃圾-用户地址)】的数据库操作Service实现 |
| 12 | -* @createDate 2023-11-20 16:03:15 | 12 | +* @createDate 2023-11-22 09:48:43 |
| 13 | */ | 13 | */ |
| 14 | @Service | 14 | @Service |
| 15 | public class GarAddressServiceImpl extends ServiceImpl<GarAddressMapper, GarAddress> | 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,22 +3,23 @@ package com.trash.garbage.service.impl; | ||
| 3 | import cn.hutool.http.HttpUtil; | 3 | import cn.hutool.http.HttpUtil; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.aliyuncs.exceptions.ClientException; | 5 | import com.aliyuncs.exceptions.ClientException; |
| 6 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 7 | import com.trash.garbage.config.WxConfig; | 8 | import com.trash.garbage.config.WxConfig; |
| 9 | +import com.trash.garbage.custom.BizException; | ||
| 8 | import com.trash.garbage.global.GlobalRedisProperties; | 10 | import com.trash.garbage.global.GlobalRedisProperties; |
| 9 | import com.trash.garbage.global.GlobalStatus; | 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 | import com.trash.garbage.pojo.domain.GarUser; | 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 | import com.trash.garbage.security.UserCustom; | 17 | import com.trash.garbage.security.UserCustom; |
| 18 | +import com.trash.garbage.service.GarAddressService; | ||
| 14 | import com.trash.garbage.service.GarUserService; | 19 | import com.trash.garbage.service.GarUserService; |
| 15 | import com.trash.garbage.mapper.GarUserMapper; | 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 | import org.apache.commons.codec.binary.Base64; | 22 | import org.apache.commons.codec.binary.Base64; |
| 21 | -import org.apache.commons.lang3.StringUtils; | ||
| 22 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| 23 | import org.springframework.security.authentication.AuthenticationManager; | 24 | import org.springframework.security.authentication.AuthenticationManager; |
| 24 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | 25 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| @@ -32,6 +33,8 @@ import javax.crypto.Cipher; | @@ -32,6 +33,8 @@ import javax.crypto.Cipher; | ||
| 32 | import javax.crypto.spec.IvParameterSpec; | 33 | import javax.crypto.spec.IvParameterSpec; |
| 33 | import javax.crypto.spec.SecretKeySpec; | 34 | import javax.crypto.spec.SecretKeySpec; |
| 34 | import java.security.spec.AlgorithmParameterSpec; | 35 | import java.security.spec.AlgorithmParameterSpec; |
| 36 | +import java.util.Arrays; | ||
| 37 | +import java.util.List; | ||
| 35 | import java.util.Objects; | 38 | import java.util.Objects; |
| 36 | import java.util.concurrent.TimeUnit; | 39 | import java.util.concurrent.TimeUnit; |
| 37 | 40 | ||
| @@ -49,12 +52,15 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | @@ -49,12 +52,15 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | ||
| 49 | @Autowired | 52 | @Autowired |
| 50 | private AuthenticationManager authenticationManager; | 53 | private AuthenticationManager authenticationManager; |
| 51 | 54 | ||
| 55 | + @Autowired | ||
| 56 | + private GarAddressService garAddressService; | ||
| 57 | + | ||
| 52 | @Resource | 58 | @Resource |
| 53 | private RedisUtils redisUtils; | 59 | private RedisUtils redisUtils; |
| 54 | 60 | ||
| 55 | 61 | ||
| 56 | @Override | 62 | @Override |
| 57 | - public String login(LoginVo user) { | 63 | + public String login(LoginDto user) { |
| 58 | if (Objects.isNull(user)) { | 64 | if (Objects.isNull(user)) { |
| 59 | throw new UsernameNotFoundException("当前用户不存在"); | 65 | throw new UsernameNotFoundException("当前用户不存在"); |
| 60 | } | 66 | } |
| @@ -73,7 +79,7 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | @@ -73,7 +79,7 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | ||
| 73 | // 验证码验证 | 79 | // 验证码验证 |
| 74 | Integer code = (Integer) redisUtils.get(GlobalRedisProperties.REDIS_USER_CODE.getValue() + user.getTel()); | 80 | Integer code = (Integer) redisUtils.get(GlobalRedisProperties.REDIS_USER_CODE.getValue() + user.getTel()); |
| 75 | if (!code.equals(user.getCode())) { | 81 | if (!code.equals(user.getCode())) { |
| 76 | - throw new RuntimeException("验证码错误!!"); | 82 | + throw new BizException(ResultCode.CODE_400, "验证码错误!!"); |
| 77 | } | 83 | } |
| 78 | // 封装成authentication对象 | 84 | // 封装成authentication对象 |
| 79 | Authentication authentication = new UsernamePasswordAuthenticationToken(user.getTel(), ""); | 85 | Authentication authentication = new UsernamePasswordAuthenticationToken(user.getTel(), ""); |
| @@ -84,9 +90,9 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | @@ -84,9 +90,9 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | ||
| 84 | } | 90 | } |
| 85 | UserCustom userCustom = (UserCustom) authenticate.getPrincipal(); | 91 | UserCustom userCustom = (UserCustom) authenticate.getPrincipal(); |
| 86 | // 存入redis | 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 | @Override | 98 | @Override |
| @@ -96,10 +102,44 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | @@ -96,10 +102,44 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> | ||
| 96 | //给用户发送验证码 | 102 | //给用户发送验证码 |
| 97 | // SMSUtils.sendMessage("", tel, validateCode.toString(), ""); | 103 | // SMSUtils.sendMessage("", tel, validateCode.toString(), ""); |
| 98 | // 保存redis | 104 | // 保存redis |
| 99 | - System.out.println("code:"+ validateCode); | 105 | + System.out.println("code:" + validateCode); |
| 100 | redisUtils.setEx(GlobalRedisProperties.REDIS_USER_CODE.getValue() + tel, validateCode, 60, TimeUnit.SECONDS); | 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 | package com.trash.garbage.utils; | 1 | package com.trash.garbage.utils; |
| 2 | 2 | ||
| 3 | +import com.trash.garbage.custom.BizException; | ||
| 4 | +import com.trash.garbage.global.ResultCode; | ||
| 3 | import com.trash.garbage.security.UserCustom; | 5 | import com.trash.garbage.security.UserCustom; |
| 4 | import org.springframework.security.core.context.SecurityContextHolder; | 6 | import org.springframework.security.core.context.SecurityContextHolder; |
| 5 | 7 | ||
| @@ -11,8 +13,7 @@ public class SecurityUtil { | @@ -11,8 +13,7 @@ public class SecurityUtil { | ||
| 11 | 13 | ||
| 12 | public static UserCustom getUserCustom() { | 14 | public static UserCustom getUserCustom() { |
| 13 | if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof UserCustom) | 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,10 +53,11 @@ spring: | ||
| 53 | redis: | 53 | redis: |
| 54 | # 地址 | 54 | # 地址 |
| 55 | # host: 121.41.83.61 | 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 | database: 0 | 58 | database: 0 |
| 58 | # password: "guzijian" | 59 | # password: "guzijian" |
| 59 | - port: 6378 | 60 | + port: 6379 |
| 60 | # 连接超时时间 | 61 | # 连接超时时间 |
| 61 | timeout: 10s | 62 | timeout: 10s |
| 62 | lettuce: | 63 | lettuce: |
| @@ -79,7 +80,6 @@ mybatis-plus: | @@ -79,7 +80,6 @@ mybatis-plus: | ||
| 79 | global-config: | 80 | global-config: |
| 80 | # 指定逻辑删除含义 | 81 | # 指定逻辑删除含义 |
| 81 | db-config: | 82 | db-config: |
| 82 | - logic-delete-field: delFlag | ||
| 83 | logic-delete-value: 1 | 83 | logic-delete-value: 1 |
| 84 | logic-not-delete-value: 0 | 84 | logic-not-delete-value: 0 |
| 85 | configuration: | 85 | configuration: |
trash-garbage/src/main/resources/mapper/GarAddressMapper.xml
| @@ -6,17 +6,19 @@ | @@ -6,17 +6,19 @@ | ||
| 6 | 6 | ||
| 7 | <resultMap id="BaseResultMap" type="com.trash.garbage.pojo.domain.GarAddress"> | 7 | <resultMap id="BaseResultMap" type="com.trash.garbage.pojo.domain.GarAddress"> |
| 8 | <id property="garAddressId" column="gar_address_id" jdbcType="BIGINT"/> | 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 | <result property="garUserAddress" column="gar_user_address" jdbcType="VARCHAR"/> | 10 | <result property="garUserAddress" column="gar_user_address" jdbcType="VARCHAR"/> |
| 11 | <result property="garUserDefault" column="gar_user_default" jdbcType="TINYINT"/> | 11 | <result property="garUserDefault" column="gar_user_default" jdbcType="TINYINT"/> |
| 12 | <result property="garCreateTime" column="gar_create_time" jdbcType="TIMESTAMP"/> | 12 | <result property="garCreateTime" column="gar_create_time" jdbcType="TIMESTAMP"/> |
| 13 | <result property="garUpdateTime" column="gar_update_time" jdbcType="TIMESTAMP"/> | 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 | <result property="garRemark" column="gar_remark" jdbcType="VARCHAR"/> | 16 | <result property="garRemark" column="gar_remark" jdbcType="VARCHAR"/> |
| 15 | </resultMap> | 17 | </resultMap> |
| 16 | 18 | ||
| 17 | <sql id="Base_Column_List"> | 19 | <sql id="Base_Column_List"> |
| 18 | gar_address_id,gar_user_id,gar_user_address, | 20 | gar_address_id,gar_user_id,gar_user_address, |
| 19 | gar_user_default,gar_create_time,gar_update_time, | 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 | </sql> | 23 | </sql> |
| 22 | </mapper> | 24 | </mapper> |