From aa8917f69ac3994c14173ad2495734678e2cc9d6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 16 May 2019 20:24:31 +0800 Subject: [PATCH 01/13] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20oauth2=20=E6=A8=A1=E5=9D=97=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E5=90=8E=E7=BB=AD=20User=20=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E3=80=82=20-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E9=87=8D=E5=86=99?= =?UTF-8?q?=20Admin=20=E5=AE=89=E5=85=A8=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E7=8E=B0=E7=B1=BB=E4=BC=BC=20Shiro=20?= =?UTF-8?q?=E7=9A=84=E6=95=88=E6=9E=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/application/SystemApplication.java | 10 +--- .../controller/admins/DataDictController.java | 60 ++++--------------- .../application/convert/DataDictConvert.java | 18 +----- .../vo/datadict/DataDictEnumVO.java | 16 ++++- .../application/vo/datadict/DataDictVO.java | 26 -------- .../vo/datadict/DataDictValueVO.java | 18 ------ .../mall/admin/api/DataDictService.java | 9 +-- .../api/dto/datadict/DataDictAddDTO.java | 30 ++++------ .../api/dto/datadict/DataDictUpdateDTO.java | 31 +++++----- .../mall/admin/dao/DataDictMapper.java | 13 ++-- .../admin/dao/OAuth2AccessTokenMapper.java | 8 ++- .../admin/dao/OAuth2RefreshTokenMapper.java | 8 ++- .../mall/admin/dao/ResourceMapper.java | 2 +- .../mall/admin/dataobject/DataDictDO.java | 2 + .../admin/service/DataDictServiceImpl.java | 34 +++++------ .../main/resources/mapper/DataDictMapper.xml | 52 +--------------- .../mapper/OAuth2AccessTokenMapper.xml | 12 ---- .../mapper/OAuth2RefreshTokenMapper.xml | 12 ---- 18 files changed, 100 insertions(+), 261 deletions(-) delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java delete mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java delete mode 100644 system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml delete mode 100644 system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java index d4b1b995..9792b390 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/SystemApplication.java @@ -2,7 +2,6 @@ package cn.iocoder.mall.admin.application; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.admin"}) @@ -10,14 +9,7 @@ import org.springframework.scheduling.annotation.EnableAsync; public class SystemApplication { public static void main(String[] args) { - ConfigurableApplicationContext ctx = SpringApplication.run(SystemApplication.class, args); -// Object bean = ctx.getBean("test"); -// System.out.println(AopUtils.getTargetClass(bean)); - -// System.out.println(bean); - -// ConfigurableApplicationContext ctx = -// System.out.println(); // TODO 后面去掉,这里是临时的 + SpringApplication.run(SystemApplication.class, args); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java index 1af446e6..59b64fa4 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java @@ -7,14 +7,12 @@ import cn.iocoder.mall.admin.api.dto.datadict.DataDictAddDTO; import cn.iocoder.mall.admin.api.dto.datadict.DataDictUpdateDTO; import cn.iocoder.mall.admin.application.convert.DataDictConvert; import cn.iocoder.mall.admin.application.vo.datadict.DataDictEnumVO; -import cn.iocoder.mall.admin.application.vo.datadict.DataDictVO; import cn.iocoder.mall.admin.sdk.annotation.RequiresPermissions; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Multimaps; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; import org.springframework.web.bind.annotation.*; @@ -22,6 +20,8 @@ import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping("admins/data_dict") @Api("数据字典模块") @@ -33,9 +33,8 @@ public class DataDictController { @GetMapping("/list") @ApiOperation(value = "数据字典全列表") @RequiresPermissions("system.dataDict.list") - public CommonResult> list() { - CommonResult> result = dataDictService.selectDataDictList(); - return DataDictConvert.INSTANCE.convert(result); + public CommonResult> list() { + return success( dataDictService.selectDataDictList()); } @GetMapping("/tree") @@ -43,12 +42,9 @@ public class DataDictController { @ApiOperation(value = "数据字典树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。") public CommonResult> tree() { // 查询数据字典全列表 - CommonResult> result = dataDictService.selectDataDictList(); - if (result.isError()) { - return CommonResult.error(result); - } + List dataDicts = dataDictService.selectDataDictList(); // 构建基于 enumValue 聚合的 Multimap - ImmutableListMultimap dataDictMap = Multimaps.index(result.getData(), DataDictBO::getEnumValue); // KEY 是 enumValue ,VALUE 是 DataDictBO 数组 + ImmutableListMultimap dataDictMap = Multimaps.index(dataDicts, DataDictBO::getEnumValue); // KEY 是 enumValue ,VALUE 是 DataDictBO 数组 // 构建返回结果 List dataDictEnumVOs = new ArrayList<>(dataDictMap.size()); dataDictMap.keys().forEach(enumValue -> { @@ -56,53 +52,21 @@ public class DataDictController { .setValues(DataDictConvert.INSTANCE.convert2(dataDictMap.get(enumValue))); dataDictEnumVOs.add(dataDictEnumVO); }); - return CommonResult.success(dataDictEnumVOs); + return success(dataDictEnumVOs); } @PostMapping("/add") @RequiresPermissions("system.dataDict.add") @ApiOperation(value = "创建数据字典") - @ApiImplicitParams({ - @ApiImplicitParam(name = "enumValue", value = "大类枚举值", required = true, example = "gender"), - @ApiImplicitParam(name = "value", value = "小类数值", required = true, example = "1"), - @ApiImplicitParam(name = "displayName", value = "展示名", required = true, example = "男"), - @ApiImplicitParam(name = "sort", required = true, value = "排序值", defaultValue = "10"), - @ApiImplicitParam(name = "memo", value = "备注", example = "你猜我猜不猜"), - }) - public CommonResult add(@RequestParam("enumValue") String enumValue, - @RequestParam("value") String value, - @RequestParam("displayName") String displayName, - @RequestParam("sort") Integer sort, - @RequestParam(value = "memo", required = false) String memo) { - // 创建 DataDictAddDTO 对象 - DataDictAddDTO dataDictAddDTO = new DataDictAddDTO().setEnumValue(enumValue).setValue(value).setDisplayName(displayName) - .setSort(sort).setMemo(memo); - // 保存数据字典 - CommonResult result = dataDictService.addDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictAddDTO); - // 返回结果 - return DataDictConvert.INSTANCE.convert2(result); + public CommonResult add(DataDictAddDTO dataDictAddDTO) { + return success(dataDictService.addDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictAddDTO)); } @PostMapping("/update") @RequiresPermissions("system.dataDict.update") @ApiOperation(value = "更新数据字典") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "100"), - @ApiImplicitParam(name = "value", value = "小类数值", required = true, example = "1"), - @ApiImplicitParam(name = "displayName", value = "展示名", required = true, example = "男"), - @ApiImplicitParam(name = "sort", required = true, value = "排序值", defaultValue = "10"), - @ApiImplicitParam(name = "memo", value = "备注", example = "你猜我猜不猜"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("value") String value, - @RequestParam("displayName") String displayName, - @RequestParam("sort") Integer sort, - @RequestParam(value = "memo", required = false) String memo) { - // 创建 DataDictAddDTO 对象 - DataDictUpdateDTO dataDictUpdateDTO = new DataDictUpdateDTO().setId(id).setValue(value).setDisplayName(displayName) - .setSort(sort).setMemo(memo); - // 更新数据字典 - return dataDictService.updateDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictUpdateDTO); + public CommonResult update(DataDictUpdateDTO dataDictUpdateDTO) { + return success(dataDictService.updateDataDict(AdminSecurityContextHolder.getContext().getAdminId(), dataDictUpdateDTO)); } @PostMapping("/delete") @@ -110,7 +74,7 @@ public class DataDictController { @ApiOperation(value = "删除数据字典") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "100") public CommonResult delete(@RequestParam("id") Integer id) { - return dataDictService.deleteDataDict(AdminSecurityContextHolder.getContext().getAdminId(), id); + return success(dataDictService.deleteDataDict(AdminSecurityContextHolder.getContext().getAdminId(), id)); } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java index 8d875c4d..c9b8a867 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java @@ -1,9 +1,7 @@ package cn.iocoder.mall.admin.application.convert; -import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.bo.datadict.DataDictBO; -import cn.iocoder.mall.admin.application.vo.datadict.DataDictVO; -import cn.iocoder.mall.admin.application.vo.datadict.DataDictValueVO; +import cn.iocoder.mall.admin.application.vo.datadict.DataDictEnumVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -16,18 +14,6 @@ public interface DataDictConvert { DataDictConvert INSTANCE = Mappers.getMapper(DataDictConvert.class); @Mappings({}) - DataDictVO convert(DataDictBO dataDictBO); - - @Mappings({}) - List convert(List dataDictBOs); - - @Mappings({}) - CommonResult> convert(CommonResult> result); - - @Mappings({}) - CommonResult convert2(CommonResult result); - - @Mappings({}) - List convert2(List dataDictBOs); + List convert2(List dataDictBOs); } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java index d9814747..936b0496 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictEnumVO.java @@ -14,7 +14,21 @@ public class DataDictEnumVO { @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") private String enumValue; + @ApiModelProperty(value = "小类数值数组", required = true) - private List values; + private List values; + + @ApiModel("数据字典枚举值 VO") + @Data + @Accessors(chain = true) + public static class Value { + + @ApiModelProperty(value = "小类数值", required = true, example = "1") + private String value; + + @ApiModelProperty(value = "展示名", required = true, example = "男") + private String displayName; + + } } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java deleted file mode 100644 index 1524ce4c..00000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictVO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.admin.application.vo.datadict; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -@ApiModel("数据字典 VO") -@Data -@Accessors(chain = true) -public class DataDictVO { - - @ApiModelProperty(value = "编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") - private String enumValue; - @ApiModelProperty(value = "小类数值", required = true, example = "1") - private String value; - @ApiModelProperty(value = "展示名", required = true, example = "男") - private String displayName; - @ApiModelProperty(value = "排序值", required = true, example = "10") - private Integer sort; - @ApiModelProperty(value = "备注", example = "你猜") - private String memo; - -} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java deleted file mode 100644 index 7ed6eeff..00000000 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/datadict/DataDictValueVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.mall.admin.application.vo.datadict; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -@ApiModel("数据字典枚举值 VO") -@Data -@Accessors(chain = true) -public class DataDictValueVO { - - @ApiModelProperty(value = "小类数值", required = true, example = "1") - private String value; - @ApiModelProperty(value = "展示名", required = true, example = "男") - private String displayName; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java index 7d92b8be..2d3da6bd 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java @@ -10,13 +10,13 @@ import java.util.List; public interface DataDictService { - CommonResult> selectDataDictList(); + List selectDataDictList(); - CommonResult addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO); + DataDictBO addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO); - CommonResult updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO); + Boolean updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO); - CommonResult deleteDataDict(Integer adminId, Integer dataDictId); + Boolean deleteDataDict(Integer adminId, Integer dataDictId); /** * 获取字典值 - 单个 @@ -28,6 +28,7 @@ public interface DataDictService { * @return */ CommonResult getDataDict(String dictKey, Object dictValue); + CommonResult> getDataDict(String dictKey); /** diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java index 574a66ae..378dc5bc 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictAddDTO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.admin.api.dto.datadict; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -7,36 +9,28 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.Serializable; -/** - * 数据字典添加 DTO - */ +@ApiModel("数据字典添加 DTO") @Data @Accessors(chain = true) public class DataDictAddDTO implements Serializable { - /** - * 大类枚举值 - */ + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") @NotEmpty(message = "大类枚举值不能为空") private String enumValue; - /** - * 小类数值 - */ + + @ApiModelProperty(value = "小类数值", required = true, example = "1") @NotEmpty(message = "小类数值不能为空") private String value; - /** - * 展示名 - */ + + @ApiModelProperty(value = "展示名", required = true, example = "男") @NotEmpty(message = "展示名不能为空") private String displayName; - /** - * 排序值 - */ + + @ApiModelProperty(required = true, value = "排序值", example = "123") @NotNull(message = "排序值不能为空") private Integer sort; - /** - * 备注 - */ + + @ApiModelProperty(value = "备注", example = "你猜我猜不猜") private String memo; } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java index 9653beb2..bfaa8b74 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/datadict/DataDictUpdateDTO.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.admin.api.dto.datadict; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -14,29 +15,27 @@ import java.io.Serializable; @Accessors(chain = true) public class DataDictUpdateDTO implements Serializable { - /** - * 编号 - */ - @NotNull(message = "编号不能为空") + @ApiModelProperty(value = "数据字典编号", required = true, example = "1") + @NotNull(message = "数据字典编号不能为空") private Integer id; - /** - * 小类数值 - */ + + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + @NotEmpty(message = "大类枚举值不能为空") + private String enumValue; + + @ApiModelProperty(value = "小类数值", required = true, example = "1") @NotEmpty(message = "小类数值不能为空") private String value; - /** - * 展示名 - */ + + @ApiModelProperty(value = "展示名", required = true, example = "男") @NotEmpty(message = "展示名不能为空") private String displayName; - /** - * 排序值 - */ + + @ApiModelProperty(required = true, value = "排序值", example = "123") @NotNull(message = "排序值不能为空") private Integer sort; - /** - * 备注 - */ + + @ApiModelProperty(value = "备注", example = "你猜我猜不猜") private String memo; } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java index 5b6e5e5f..90bb43f1 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java @@ -1,6 +1,8 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.DataDictDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -8,9 +10,7 @@ import java.util.Collection; import java.util.List; @Repository -public interface DataDictMapper { - - DataDictDO selectById(@Param("id") Integer id); +public interface DataDictMapper extends BaseMapper { DataDictDO selectByEnumValueAndValue( @Param("enumValue") String enumValue, @@ -26,10 +26,9 @@ public interface DataDictMapper { @Param("enumValue") String enumValue ); - List selectList(); + default List selectList() { + return selectList(new QueryWrapper<>()); + } - void insert(DataDictDO dataDict); - - int update(DataDictDO dataDict); } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java index e5ad899b..9f113ac3 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2AccessTokenMapper.java @@ -1,13 +1,17 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.OAuth2AccessTokenDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @Repository public interface OAuth2AccessTokenMapper extends BaseMapper { - int updateToInvalidByAdminId(@Param("adminId") Integer adminId); + default int updateToInvalidByAdminId(Integer adminId) { + QueryWrapper query = new QueryWrapper() + .eq("admin_id", adminId).eq("valid", true); + return update(new OAuth2AccessTokenDO().setValid(false), query); + } } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java index a96b3545..9d9caec7 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/OAuth2RefreshTokenMapper.java @@ -1,13 +1,17 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.OAuth2RefreshTokenDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @Repository public interface OAuth2RefreshTokenMapper extends BaseMapper { - int updateToInvalidByAdminId(@Param("adminId") Integer adminId); + default int updateToInvalidByAdminId(Integer adminId) { + QueryWrapper query = new QueryWrapper() + .eq("admin_id", adminId).eq("valid", true); + return update(new OAuth2RefreshTokenDO().setValid(false), query); + } } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java index e054abc3..47306567 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/ResourceMapper.java @@ -13,7 +13,7 @@ import java.util.Set; @Repository public interface ResourceMapper extends BaseMapper { - @Deprecated + // TODO 芋艿,后续改造。 List selectListByTypeAndRoleIds(@Param("type") Integer type, @Param("roleIds") Set roleIds); diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java index b65a853c..091ed72a 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DataDictDO.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.admin.dataobject; import cn.iocoder.common.framework.dataobject.DeletableDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; @@ -13,6 +14,7 @@ import lombok.experimental.Accessors; * value:1 男 * value:2 女 */ +@TableName("data_dict") @Data @Accessors(chain = true) public class DataDictDO extends DeletableDO { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java index 348d7bbf..f0f566d2 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -31,16 +31,16 @@ public class DataDictServiceImpl implements DataDictService { private DataDictMapper dataDictMapper; @Override - public CommonResult> selectDataDictList() { + public List selectDataDictList() { List dataDicts = dataDictMapper.selectList(); - return CommonResult.success(DataDictConvert.INSTANCE.convert(dataDicts)); + return DataDictConvert.INSTANCE.convert(dataDicts); } @Override - public CommonResult addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO) { + public DataDictBO addDataDict(Integer adminId, DataDictAddDTO dataDictAddDTO) { // 校验数据字典重复 if (dataDictMapper.selectByEnumValueAndValue(dataDictAddDTO.getEnumValue(), dataDictAddDTO.getValue()) != null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); } // 保存到数据库 DataDictDO dataDict = DataDictConvert.INSTANCE.convert(dataDictAddDTO); @@ -49,45 +49,43 @@ public class DataDictServiceImpl implements DataDictService { dataDictMapper.insert(dataDict); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(DataDictConvert.INSTANCE.convert(dataDict)); + return DataDictConvert.INSTANCE.convert(dataDict); } @Override - public CommonResult updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO) { + public Boolean updateDataDict(Integer adminId, DataDictUpdateDTO dataDictUpdateDTO) { // 校验数据字典不存在 DataDictDO existsDataDict = dataDictMapper.selectById(dataDictUpdateDTO.getId()); if (existsDataDict == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); } // 校验数据字典重复 DataDictDO duplicateDataDict = dataDictMapper.selectByEnumValueAndValue(existsDataDict.getEnumValue(), dataDictUpdateDTO.getValue()); if (duplicateDataDict != null && !duplicateDataDict.getId().equals(dataDictUpdateDTO.getId())) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_EXISTS.getCode()); } // 更新到数据库 DataDictDO updateDataDict = DataDictConvert.INSTANCE.convert(dataDictUpdateDTO); - dataDictMapper.update(updateDataDict); + dataDictMapper.updateById(updateDataDict); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } // 一般情况下,不要删除数据字典。 // 因为,业务数据正在使用该数据字典,删除后,可能有不可预知的问题。 @Override - public CommonResult deleteDataDict(Integer adminId, Integer dataDictId) { + public Boolean deleteDataDict(Integer adminId, Integer dataDictId) { // 校验数据字典不存在 DataDictDO existsDataDict = dataDictMapper.selectById(dataDictId); if (existsDataDict == null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DATA_DICT_NOT_EXISTS.getCode()); } - // 更新到数据库 - DataDictDO updateDataDict = new DataDictDO().setId(dataDictId); - updateDataDict.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - dataDictMapper.update(updateDataDict); + // 标记删除 + dataDictMapper.deleteById(dataDictId); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(true); + return true; } @Override @@ -106,7 +104,7 @@ public class DataDictServiceImpl implements DataDictService { @Override public CommonResult> getDataDictList(String dictKey, Collection dictValueList) { - Set convertDictValueList = dictValueList.stream().map(o -> String.valueOf(o)).collect(Collectors.toSet()); + Set convertDictValueList = dictValueList.stream().map(String::valueOf).collect(Collectors.toSet()); List dataDictDOList = dataDictMapper.selectByEnumValueAndValues(dictKey, convertDictValueList); List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); return CommonResult.success(dataDictBOList); diff --git a/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml b/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml index e5b588a4..546d268c 100644 --- a/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml +++ b/system/system-service-impl/src/main/resources/mapper/DataDictMapper.xml @@ -29,21 +29,6 @@ - - - - - - INSERT INTO data_dict ( - id, enum_value, value, display_name, sort, - memo, create_time, deleted - ) VALUES ( - #{id}, #{enumValue}, #{value}, #{displayName}, #{sort}, - #{memo}, #{createTime}, #{deleted} - ) - - - - UPDATE data_dict - - - enum_value = #{enumValue}, - - - value = #{value}, - - - display_name = #{displayName}, - - - sort = #{sort}, - - - memo = #{memo}, - - - deleted = #{deleted} - - - WHERE id = #{id} - - - \ No newline at end of file + diff --git a/system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml b/system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml deleted file mode 100644 index 1497e457..00000000 --- a/system/system-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - UPDATE oauth2_access_token - SET valid = 0 - WHERE admin_id = #{adminId} - AND valid = 1 - - - diff --git a/system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml b/system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml deleted file mode 100644 index 1b7a70cd..00000000 --- a/system/system-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - UPDATE oauth2_refresh_token - SET valid = 0 - WHERE admin_id = #{adminId} - AND valid = 1 - - - From 453235bb6abeb92211c7fe479bf1f738b14bbdb8 Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Thu, 16 May 2019 21:50:22 +0800 Subject: [PATCH 02/13] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=20SmsPlatform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iocoder/mall/admin/api/SmsPlatform.java | 80 ++++++ .../cn/iocoder/mall/admin/api/SmsService.java | 60 ++++ .../mall/admin/api/bo/sms/SmsSignBO.java | 40 +++ .../mall/admin/api/bo/sms/SmsTemplateBO.java | 44 +++ .../api/constant/AdminErrorCodeEnum.java | 9 + .../api/constant/SmsApplyStatusEnum.java | 31 ++ .../admin/api/exception/SmsFailException.java | 14 + system/system-service-impl/pom.xml | 10 + .../mall/admin/convert/SmsSignConvert.java | 22 ++ .../admin/convert/SmsTemplateConvert.java | 22 ++ .../iocoder/mall/admin/dao/SmsSignMapper.java | 15 + .../mall/admin/dao/SmsTemplateMapper.java | 16 ++ .../mall/admin/dataobject/SmsSignDO.java | 45 +++ .../mall/admin/dataobject/SmsTemplateDO.java | 45 +++ .../mall/admin/service/SmsServiceImpl.java | 172 +++++++++++ .../admin/service/SmsYunPianPlatform.java | 272 ++++++++++++++++++ .../main/resources/config/application.yaml | 6 + .../mall/admin/SystemApplicationTest.java | 20 ++ .../cn/iocoder/mall/admin/package-info.java | 5 + .../admin/service/SmsServiceImplTest.java | 29 ++ 20 files changed, 957 insertions(+) create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsPlatform.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsService.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsSignBO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsTemplateBO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsApplyStatusEnum.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsSignMapper.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsTemplateMapper.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsSignDO.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsTemplateDO.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java create mode 100644 system/system-service-impl/src/test/java/cn/iocoder/mall/admin/SystemApplicationTest.java create mode 100644 system/system-service-impl/src/test/java/cn/iocoder/mall/admin/package-info.java create mode 100644 system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SmsServiceImplTest.java diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsPlatform.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsPlatform.java new file mode 100644 index 00000000..597db312 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsPlatform.java @@ -0,0 +1,80 @@ +package cn.iocoder.mall.admin.api; + +import cn.iocoder.mall.admin.api.bo.sms.SmsSignBO; +import lombok.Data; +import lombok.experimental.Accessors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 短信平台 + * + * @author Sin + * @time 2019/5/16 6:33 PM + */ +public interface SmsPlatform { + + @Data + @Accessors(chain = true) + class Result { + /** + * 编号 + */ + private String id; + /** + * 审核状态 + */ + private Integer applyStatus; + /** + * 审核内容 + */ + private String applyMessage; + } + + /** + * 签名 - 创建 + * + * @param sign + */ + Result createSign(String sign); + + /** + * 签名 - 获取 + * + * @param sign + */ + Result getSign(String sign); + + /** + * 签名 - 更新 + * + * @param oldSign + * @param sign + */ + Result updateSign(String oldSign, String sign); + + /** + * 模板 - 创建 + * + * @param sign 选用的哪个签名 + * @param template 模板内容 + * @param tplType 1 为验证码类型,其他为 null + */ + Result createTemplate(String sign, String template, Integer tplType); + + /** + * 获取模板信息 + * + * @param tipId + */ + Result getTemplate(String tipId); + + /** + * 更新模板内容 + * + * @param tipId 选用的哪个签名 + * @param template 模板内容 + * @param tplType 1 为验证码类型,其他为 null + */ + Result updateTemplate(String tipId, String template, Integer tplType); +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsService.java new file mode 100644 index 00000000..a3d36139 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/SmsService.java @@ -0,0 +1,60 @@ +package cn.iocoder.mall.admin.api; + +import cn.iocoder.mall.admin.api.bo.sms.SmsSignBO; +import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO; + +/** + * 短信服务 + * + * @author Sin + * @time 2019/5/16 9:54 AM + */ +public interface SmsService { + + /** + * 签名 - 创建 + * + * @param sign + */ + void createSign(String sign); + + /** + * 签名 - 获取 + * + * @param sign + */ + SmsSignBO getSign(String sign); + + /** + * 签名 - 更新 + * + * @param oldSign + * @param sign + */ + void updateSign(String oldSign, String sign); + + /** + * 模板 - 创建 + * + * @param smsSignId 选用的哪个签名 + * @param template 模板内容 + * @param tplType 1 为验证码类型,其他为 null + */ + void createTemplate(Integer smsSignId, String template, Integer tplType); + + /** + * 获取模板信息 + * + * @param id + */ + SmsTemplateBO getTemplate(String id); + + /** + * 更新模板内容 + * + * @param id 模板id + * @param template 模板内容 + * @param tplType 1 为验证码类型,其他为 null + */ + void updateTemplate(String id, String template, Integer tplType); +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsSignBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsSignBO.java new file mode 100644 index 00000000..220b0185 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsSignBO.java @@ -0,0 +1,40 @@ +package cn.iocoder.mall.admin.api.bo.sms; + +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 短信签名 + * + * @author Sin + * @time 2019/5/16 6:30 PM + */ +@Data +@Accessors(chain = true) +public class SmsSignBO { + + /** + * 编号 + */ + private Integer id; + /** + * 签名id 这个是第三方的 + */ + private Integer signId; + /** + * 签名名称 + */ + private String sign; + /** + * 审核状态 + * + * - 1、审核中 + * - 2、审核成功 + * - 3、审核失败 + */ + private Integer applyStatus; + /** + * 审核信息 + */ + private String applyMessage; +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsTemplateBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsTemplateBO.java new file mode 100644 index 00000000..e2094eee --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/SmsTemplateBO.java @@ -0,0 +1,44 @@ +package cn.iocoder.mall.admin.api.bo.sms; + +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 短信 template + * + * @author Sin + * @time 2019/5/16 7:41 PM + */ +@Data +@Accessors(chain = true) +public class SmsTemplateBO { + + /** + * 编号 + */ + private Integer id; + /** + * 模板编号 (第三方的) + */ + private Integer smsSignId; + /** + * 短信签名 id + */ + private String platformId; + /** + * 短信模板 + */ + private String template; + /** + * 审核状态 + * + * 1、审核中 + * 2、审核成功 + * 3、审核失败 + */ + private Integer applyStatus; + /** + * 审核信息 + */ + private String applyMessage; +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java index 61f4dfd1..3764d63a 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java @@ -46,6 +46,15 @@ public enum AdminErrorCodeEnum { DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), DATA_DICT_NOT_EXISTS(1002005001, "该数据字典不存在"), + // ========== 短信模板 1002006000 ========== + SMS_SIGN_ADD_FAIL(1002006000, "短信签名添加失败"), + SMS_SIGN_NOT_EXISTENT(1002006001, "短信签名不存在"), + SMS_SIGN_IS_EXISTENT(1002006002, "短信签名已存在"), + SMS_SIGN_UPDATE_FAIL(1002006003, "短信更新失败"), + + SMS_TEMPLATE_ADD_FAIL(1002006020, "短信签名不存在"), + SMS_TEMPLATE_NOT_EXISTENT(1002006021, "短信签名不存在"), + SMS_TEMPLATE_IS_EXISTENT(1002006022, "短信签名不存在"), ; private final int code; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsApplyStatusEnum.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsApplyStatusEnum.java new file mode 100644 index 00000000..eaf68568 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsApplyStatusEnum.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.admin.api.constant; + +/** + * 短信审核状态 + * + * @author Sin + * @time 2019/5/16 12:48 PM + */ +public enum SmsApplyStatusEnum { + + CHECKING(1, "审核中"), + SUCCESS(2, "审核成功"), + FAIL(3, "审核失败"), + ; + + private final int code; + private final String message; + + SmsApplyStatusEnum(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java new file mode 100644 index 00000000..631d8513 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java @@ -0,0 +1,14 @@ +package cn.iocoder.mall.admin.api.exception; + +import cn.iocoder.common.framework.exception.ServiceException; + +/** + * @author Sin + * @time 2019/5/16 11:17 AM + */ +public class SmsFailException extends ServiceException { + + public SmsFailException(Integer code, String message) { + super(code, message); + } +} diff --git a/system/system-service-impl/pom.xml b/system/system-service-impl/pom.xml index 3360a821..344d9344 100644 --- a/system/system-service-impl/pom.xml +++ b/system/system-service-impl/pom.xml @@ -67,7 +67,17 @@ com.google.guava guava + + com.yunpian.sdk + yunpian-java-sdk + 1.2.7 + + + + org.springframework.boot + spring-boot-starter-test + diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java new file mode 100644 index 00000000..0173e30c --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.admin.convert; + +import cn.iocoder.mall.admin.api.bo.sms.SmsSignBO; +import cn.iocoder.mall.admin.dataobject.SmsSignDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * 短信 签名 + * + * @author Sin + * @time 2019/5/16 6:31 PM + */ +@Mapper +public interface SmsSignConvert { + + SmsSignConvert INSTANCE = Mappers.getMapper(SmsSignConvert.class); + + @Mappings({}) + SmsSignBO convert(SmsSignDO smsSignDO); +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java new file mode 100644 index 00000000..d76c694b --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.admin.convert; + +import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO; +import cn.iocoder.mall.admin.dataobject.SmsTemplateDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * 短信 template + * + * @author Sin + * @time 2019/5/16 7:43 PM + */ +@Mapper +public interface SmsTemplateConvert { + + SmsTemplateConvert INSTANCE = Mappers.getMapper(SmsTemplateConvert.class); + + @Mappings({}) + SmsTemplateBO convert(SmsTemplateDO smsTemplateDO); +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsSignMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsSignMapper.java new file mode 100644 index 00000000..351e0326 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsSignMapper.java @@ -0,0 +1,15 @@ +package cn.iocoder.mall.admin.dao; + +import cn.iocoder.mall.admin.dataobject.SmsSignDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +/** + * 短信 + * + * @author Sin + * @time 2019/5/16 6:18 PM + */ +@Repository +public interface SmsSignMapper extends BaseMapper { +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsTemplateMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsTemplateMapper.java new file mode 100644 index 00000000..91fa0405 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/SmsTemplateMapper.java @@ -0,0 +1,16 @@ +package cn.iocoder.mall.admin.dao; + +import cn.iocoder.common.framework.dataobject.BaseDO; +import cn.iocoder.mall.admin.dataobject.SmsTemplateDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +/** + * 短信 template + * + * @author Sin + * @time 2019/5/16 6:18 PM + */ +@Repository +public interface SmsTemplateMapper extends BaseMapper { +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsSignDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsSignDO.java new file mode 100644 index 00000000..f25afcd1 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsSignDO.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.admin.dataobject; + +import cn.iocoder.common.framework.dataobject.DeletableDO; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 短信签名 + * + * 签名是短信发送前缀 如:【阿里云】、【小红书】 + * + * @author Sin + * @time 2019/5/16 12:28 PM + */ +@Data +@Accessors(chain = true) +public class SmsSignDO extends DeletableDO { + + /** + * 编号 + */ + @TableId("id") + private Integer id; + /** + * 签名id 这个是第三方的 + */ + private String platformId; + /** + * 签名名称 + */ + private String sign; + /** + * 审核状态 + * + * - 1、审核中 + * - 2、审核成功 + * - 3、审核失败 + */ + private Integer applyStatus; + /** + * 审核信息 + */ + private String applyMessage; +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsTemplateDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsTemplateDO.java new file mode 100644 index 00000000..00e7f18f --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/SmsTemplateDO.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.admin.dataobject; + +import cn.iocoder.common.framework.dataobject.DeletableDO; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 短信 模板 + * + * @author Sin + * @time 2019/5/16 12:31 PM + */ +@Data +@Accessors(chain = true) +public class SmsTemplateDO extends DeletableDO { + + /** + * 编号 + */ + private Integer id; + /** + * 模板编号 (第三方的) + */ + private Integer smsSignId; + /** + * 短信签名 id + */ + private String platformId; + /** + * 短信模板 + */ + private String template; + /** + * 审核状态 + * + * 1、审核中 + * 2、审核成功 + * 3、审核失败 + */ + private Integer applyStatus; + /** + * 审核信息 + */ + private String applyMessage; +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java new file mode 100644 index 00000000..c6518402 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java @@ -0,0 +1,172 @@ +package cn.iocoder.mall.admin.service; + +import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.mall.admin.api.SmsPlatform; +import cn.iocoder.mall.admin.api.SmsService; +import cn.iocoder.mall.admin.api.bo.sms.SmsSignBO; +import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO; +import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; +import cn.iocoder.mall.admin.api.exception.SmsFailException; +import cn.iocoder.mall.admin.convert.SmsSignConvert; +import cn.iocoder.mall.admin.convert.SmsTemplateConvert; +import cn.iocoder.mall.admin.dao.SmsSignMapper; +import cn.iocoder.mall.admin.dao.SmsTemplateMapper; +import cn.iocoder.mall.admin.dataobject.SmsSignDO; +import cn.iocoder.mall.admin.dataobject.SmsTemplateDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; + +/** + * 短信 + * + * @author Sin + * @time 2019/5/16 10:30 AM + */ +@Service +@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.SmsService.version}") +public class SmsServiceImpl implements SmsService { + + @Autowired + private SmsSignMapper smsSignMapper; + @Autowired + private SmsTemplateMapper smsTemplateMapper; + + @Autowired + @Qualifier("smsYunPianPlatform") + private SmsPlatform smsPlatform; + + @Override + @Transactional + public void createSign(String sign) { + + // 避免重复 + SmsSignDO smsSignDO = smsSignMapper.selectOne( + new QueryWrapper().eq("sign", sign)); + + if (smsSignDO != null) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getMessage()); + } + + // 创建平台 sign + SmsPlatform.Result result = smsPlatform.createSign(sign); + + // 保存数据库 + smsSignMapper.insert( + (SmsSignDO) new SmsSignDO() + .setSign(sign) + .setPlatformId(result.getId()) + .setApplyStatus(result.getApplyStatus()) + .setDeleted(DeletedStatusEnum.DELETED_NO.getValue()) + .setUpdateTime(new Date()) + ); + } + + @Override + public SmsSignBO getSign(String sign) { + SmsSignDO smsSignDO = smsSignMapper.selectOne( + new QueryWrapper().eq("sign", sign)); + + if (smsSignDO == null) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); + } + + return SmsSignConvert.INSTANCE.convert(smsSignDO); + } + + @Override + @Transactional + public void updateSign(String oldSign, String sign) { + // 避免重复 + SmsSignDO smsSignDO = smsSignMapper.selectOne( + new QueryWrapper().eq("sign", oldSign)); + + if (smsSignDO == null) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); + } + + // 更新平台 + SmsPlatform.Result result = smsPlatform.updateSign(oldSign, sign); + + // 更新 + smsSignMapper.updateById( + (SmsSignDO) new SmsSignDO() + .setId(smsSignDO.getId()) + .setPlatformId(result.getId()) + .setSign(sign) + .setApplyStatus(result.getApplyStatus()) + .setUpdateTime(new Date()) + ); + } + + @Override + public void createTemplate(Integer smsSignId, String template, Integer tplType) { + + SmsSignDO smsSignDO = smsSignMapper.selectOne( + new QueryWrapper().eq("id", smsSignId)); + + if (smsSignDO == null) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); + } + + // 调用平台 + SmsPlatform.Result result = smsPlatform + .createTemplate(smsSignDO.getSign(), template, tplType); + + // 保存数据库 + smsTemplateMapper.insert( + (SmsTemplateDO) new SmsTemplateDO() + .setId(null) + .setSmsSignId(smsSignId) + .setPlatformId(result.getId()) + .setTemplate(template) + .setApplyStatus(result.getApplyStatus()) + .setApplyMessage(result.getApplyMessage()) + .setDeleted(DeletedStatusEnum.DELETED_NO.getValue()) + .setCreateTime(new Date()) + ); + } + + @Override + public SmsTemplateBO getTemplate(String id) { + SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne( + new QueryWrapper().eq("id", id)); + + if (smsTemplateDO == null) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage()); + } + + return SmsTemplateConvert.INSTANCE.convert(smsTemplateDO); + } + + @Override + public void updateTemplate(String id, String template, Integer tplType) { + SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne( + new QueryWrapper().eq("id", id)); + + if (smsTemplateDO == null) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage()); + } + + SmsPlatform.Result result = smsPlatform.updateTemplate( + smsTemplateDO.getPlatformId(), template, tplType); + + smsTemplateMapper.update( + (SmsTemplateDO) new SmsTemplateDO() + .setApplyStatus(result.getApplyStatus()) + .setApplyMessage(result.getApplyMessage()) + .setUpdateTime(new Date()), + new QueryWrapper().eq("id", id) + ); + } +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java new file mode 100644 index 00000000..8d852a9d --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java @@ -0,0 +1,272 @@ +package cn.iocoder.mall.admin.service; + +import cn.iocoder.mall.admin.api.SmsPlatform; +import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; +import cn.iocoder.mall.admin.api.constant.SmsApplyStatusEnum; +import cn.iocoder.mall.admin.api.exception.SmsFailException; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 云片 短信平台 + * + * @author Sin + * @time 2019/5/16 6:34 PM + */ +@Service +public class SmsYunPianPlatform implements SmsPlatform { + + protected static final Logger LOGGER = LoggerFactory.getLogger(SmsPlatform.class); + + private static final int SUCCESS_CODE = 0; + + //查账户信息的http地址 + private static final String URI_GET_USER_INFO = + "https://sms.yunpian.com/v2/user/get.json"; + + //智能匹配模板发送接口的http地址 + private static final String URI_SEND_SMS = + "https://sms.yunpian.com/v2/sms/single_send.json"; + + //模板发送接口的http地址 + private static final String URI_TPL_SEND_SMS = + "https://sms.yunpian.com/v2/sms/tpl_single_send.json"; + + //发送语音验证码接口的http地址 + private static final String URI_SEND_VOICE = + "https://voice.yunpian.com/v2/voice/send.json"; + + //绑定主叫、被叫关系的接口http地址 + private static final String URI_SEND_BIND = + "https://call.yunpian.com/v2/call/bind.json"; + + //解绑主叫、被叫关系的接口http地址 + private static final String URI_SEND_UNBIND = + "https://call.yunpian.com/v2/call/unbind.json"; + + /** + * 签名 - 添加 + */ + private static final String URL_SIGN_ADD = "https://sms.yunpian.com/v2/sign/add.json"; + /** + * 签名 - 获取 + */ + private static final String URL_SIGN_GET = "https://sms.yunpian.com/v2/sign/get.json"; + /** + * 签名 - 更新 + */ + private static final String URL_SIGN_UPDATE = "https://sms.yunpian.com/v2/sign/update.json"; + /** + * 模板 - 添加 + */ + private static final String URL_TEMPLATE_ADD = "https://sms.yunpian.com/v2/tpl/add.json"; + /** + * 模板 - 获取 + */ + private static final String URL_TEMPLATE_GET = "https://sms.yunpian.com/v2/tpl/get.json"; + /** + * 模板 - 更新 + */ + private static final String URL_TEMPLATE_UPDATE = "https://sms.yunpian.com/v2/tpl/update.json"; + + //编码格式。发送编码格式统一用UTF-8 + private static String ENCODING = "UTF-8"; + + @Value("${sms.apiKey}") + private String apiKey; + + @Override + public Result createSign(String sign) { + // 调用 短信平台 + Map params = new LinkedHashMap<>(); + params.put("apikey", apiKey); + params.put("sign", sign); + params.put("notify", "true"); + String result = post(URL_SIGN_ADD, params); + JSONObject jsonObject = JSON.parseObject(result); + if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(), + AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getMessage()); + } + + JSONObject signJSONObject = (JSONObject) jsonObject.get("sign"); + Integer applyState = smsStatusMapping(signJSONObject.getString("apply_state")); + return new Result().setId(null).setApplyStatus(applyState).setApplyMessage(null); + } + + @Override + public Result getSign(String sign) { + Map params = new LinkedHashMap<>(); + params.put("apikey", apiKey); + params.put("sign", sign); + params.put("page_num", "1"); + params.put("page_size", "20"); + String result = post(URL_SIGN_GET, params); + JSONObject jsonObject = JSON.parseObject(result); + + if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(), + AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getMessage()); + } + + JSONArray jsonArray = jsonObject.getJSONArray("sign"); + if (jsonArray.size() <= 0) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); + } + + JSONObject signJSONObject = (JSONObject) jsonArray.get(0); + String checkStatus = signJSONObject.getString("check_status"); + String applyMessage = signJSONObject.getString("remark"); + Integer applyStatus = smsStatusMapping(checkStatus); + return new Result().setId(null).setApplyStatus(applyStatus).setApplyMessage(applyMessage); + } + + @Override + public Result updateSign(String oldSign, String sign) { + Map params = new LinkedHashMap<>(); + params.put("apikey", apiKey); + params.put("old_sign", oldSign); + params.put("sign", sign); + String result = post(URL_SIGN_UPDATE, params); + JSONObject jsonObject = JSON.parseObject(result); + + if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) { + throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getCode(), + AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getMessage()); + } + + JSONObject signJSONObject = (JSONObject) jsonObject.get("sign"); + Integer applyState = smsStatusMapping(signJSONObject.getString("apply_state")); + return new Result().setId(null).setApplyStatus(applyState).setApplyMessage(null); + } + + @Override + public Result createTemplate(String sign, String template, Integer tplType) { + Map params = new LinkedHashMap<>(); + params.put("apikey", apiKey); + params.put("tpl_content", sign + template); + if (tplType != null) { + params.put("tplType", String.valueOf(tplType)); + } + String result = post(URL_TEMPLATE_ADD, params); + JSONObject jsonObject = JSON.parseObject(result); + String tipId = jsonObject.getString("tpl_id"); + String checkStatus = jsonObject.getString("check_status"); + String reason = jsonObject.getString("reason"); + Integer applyStatus = smsStatusMapping(checkStatus); + return new Result().setId(tipId).setApplyStatus(applyStatus).setApplyMessage(reason); + } + + @Override + public Result getTemplate(String tipId) { + Map params = new LinkedHashMap<>(); + params.put("apikey", apiKey); + params.put("tipId", tipId); + String result = post(URL_TEMPLATE_GET, params); + JSONObject jsonObject = JSON.parseObject(result); + + String checkStatus = jsonObject.getString("check_status"); + Integer applyStatus = smsStatusMapping(checkStatus); + String reason = jsonObject.getString("reason"); + return new Result().setId(tipId).setApplyStatus(applyStatus).setApplyMessage(reason); + } + + @Override + public Result updateTemplate(String tipId, String template, Integer tplType) { + Map params = new LinkedHashMap<>(); + params.put("apikey", apiKey); + params.put("tipId", tipId); + params.put("template", template); + String result = post(URL_TEMPLATE_UPDATE, params); + JSONObject jsonObject = JSON.parseObject(result); + + String checkStatus = jsonObject.getString("check_status"); + Integer applyStatus = smsStatusMapping(checkStatus); + String reason = jsonObject.getString("reason"); + return new Result().setId(tipId).setApplyStatus(applyStatus).setApplyMessage(reason); + } + + /** + * 短信 status 和 云片状态 映射关系 + * + * @param checkStatus + * @return + */ + private Integer smsStatusMapping(String checkStatus) { + Integer applyStatus; + switch (checkStatus) { + case "SUCCESS": + applyStatus = SmsApplyStatusEnum.SUCCESS.getCode(); + break; + case "FAIL": + applyStatus = SmsApplyStatusEnum.FAIL.getCode(); + break; + default: + applyStatus = SmsApplyStatusEnum.CHECKING.getCode(); + break; + } + return applyStatus; + } + + /** + * 基于HttpClient 4.3的通用POST方法 + * + * @param url 提交的URL + * @param paramsMap 提交<参数,值>Map + * @return 提交响应 + */ + + public static String post(String url, Map paramsMap) { + CloseableHttpClient client = HttpClients.createDefault(); + String responseText = ""; + CloseableHttpResponse response = null; + try { + HttpPost method = new HttpPost(url); + if (paramsMap != null) { + List paramList = new ArrayList<>(); + for (Map.Entry param : paramsMap.entrySet()) { + NameValuePair pair = new BasicNameValuePair(param.getKey(), + param.getValue()); + paramList.add(pair); + } + method.setEntity(new UrlEncodedFormEntity(paramList, ENCODING)); + } + response = client.execute(method); + HttpEntity entity = response.getEntity(); + if (entity != null) { + responseText = EntityUtils.toString(entity, ENCODING); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + LOGGER.debug("云片短信平台 res: {}", responseText); + return responseText; + } +} diff --git a/system/system-service-impl/src/main/resources/config/application.yaml b/system/system-service-impl/src/main/resources/config/application.yaml index 2030b157..7b8f80fb 100644 --- a/system/system-service-impl/src/main/resources/config/application.yaml +++ b/system/system-service-impl/src/main/resources/config/application.yaml @@ -24,6 +24,10 @@ mybatis-plus: mapper-locations: classpath*:mapper/*.xml type-aliases-package: cn.iocoder.mall.admin.dataobject +# sms +sms: + apiKey: d4705399e71e822fe3a90f801ed95bd9 + # dubbo dubbo: application: @@ -49,6 +53,8 @@ dubbo: version: 1.0.0 RoleService: version: 1.0.0 + SmsService: + version: 1.0.0 # logging logging: diff --git a/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/SystemApplicationTest.java b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/SystemApplicationTest.java new file mode 100644 index 00000000..d0acf0f3 --- /dev/null +++ b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/SystemApplicationTest.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.admin; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; + +/** + * 短信 application (test) + * + * @author Sin + * @time 2019/5/16 10:53 AM + */ +@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.admin"}) +@EnableAsync(proxyTargetClass = true) +public class SystemApplicationTest { + + public static void main(String[] args) { + SpringApplication.run(SystemApplicationTest.class); + } +} diff --git a/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/package-info.java b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/package-info.java new file mode 100644 index 00000000..1a1304b6 --- /dev/null +++ b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/package-info.java @@ -0,0 +1,5 @@ +/** + * @author Sin + * @time 2019/5/16 10:52 AM + */ +package cn.iocoder.mall.admin; \ No newline at end of file diff --git a/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SmsServiceImplTest.java b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SmsServiceImplTest.java new file mode 100644 index 00000000..07c1e6cc --- /dev/null +++ b/system/system-service-impl/src/test/java/cn/iocoder/mall/admin/service/SmsServiceImplTest.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.admin.service; + +import cn.iocoder.mall.admin.SystemApplicationTest; +import cn.iocoder.mall.admin.service.SmsServiceImpl; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * 短信 test + * + * @author Sin + * @time 2019/5/16 10:52 AM + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SystemApplicationTest.class) +public class SmsServiceImplTest { + + @Autowired + private SmsServiceImpl smsService; + + @Test + public void createSignTest() { +// smsService.createSign("测试签名1"); + smsService.getSign("测试签名1"); + } +} From 5f91289c889a22d2b8aa5bbe93d7e8576d2c8615 Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Thu, 16 May 2019 21:52:26 +0800 Subject: [PATCH 03/13] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/iocoder/mall/order/biz/mapper/OrderMapperTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/mapper/OrderMapperTest.java b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/mapper/OrderMapperTest.java index 0a57e40e..d30fdaa9 100644 --- a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/mapper/OrderMapperTest.java +++ b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/mapper/OrderMapperTest.java @@ -3,8 +3,6 @@ package cn.iocoder.mall.order.biz.mapper; import cn.iocoder.mall.order.biz.OrderApplicationTest; import cn.iocoder.mall.order.biz.dao.OrderMapper; import cn.iocoder.mall.order.biz.dataobject.OrderDO; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; From be94f2979163600b3a5f719ea2cc09471b06a88b Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Thu, 16 May 2019 22:05:21 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=20SmsFailException?= =?UTF-8?q?=EF=BC=8CServiceException=20=E8=A2=AB=20final=20=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/admin/api/exception/SmsFailException.java | 14 -------------- .../iocoder/mall/admin/service/SmsServiceImpl.java | 14 +++++++------- 2 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java deleted file mode 100644 index 631d8513..00000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/exception/SmsFailException.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.mall.admin.api.exception; - -import cn.iocoder.common.framework.exception.ServiceException; - -/** - * @author Sin - * @time 2019/5/16 11:17 AM - */ -public class SmsFailException extends ServiceException { - - public SmsFailException(Integer code, String message) { - super(code, message); - } -} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java index c6518402..836ee9eb 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java @@ -1,12 +1,12 @@ package cn.iocoder.mall.admin.service; import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.common.framework.exception.ServiceException; import cn.iocoder.mall.admin.api.SmsPlatform; import cn.iocoder.mall.admin.api.SmsService; import cn.iocoder.mall.admin.api.bo.sms.SmsSignBO; import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.admin.api.exception.SmsFailException; import cn.iocoder.mall.admin.convert.SmsSignConvert; import cn.iocoder.mall.admin.convert.SmsTemplateConvert; import cn.iocoder.mall.admin.dao.SmsSignMapper; @@ -49,7 +49,7 @@ public class SmsServiceImpl implements SmsService { new QueryWrapper().eq("sign", sign)); if (smsSignDO != null) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getMessage()); } @@ -73,7 +73,7 @@ public class SmsServiceImpl implements SmsService { new QueryWrapper().eq("sign", sign)); if (smsSignDO == null) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); } @@ -88,7 +88,7 @@ public class SmsServiceImpl implements SmsService { new QueryWrapper().eq("sign", oldSign)); if (smsSignDO == null) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); } @@ -113,7 +113,7 @@ public class SmsServiceImpl implements SmsService { new QueryWrapper().eq("id", smsSignId)); if (smsSignDO == null) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); } @@ -141,7 +141,7 @@ public class SmsServiceImpl implements SmsService { new QueryWrapper().eq("id", id)); if (smsTemplateDO == null) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage()); } @@ -154,7 +154,7 @@ public class SmsServiceImpl implements SmsService { new QueryWrapper().eq("id", id)); if (smsTemplateDO == null) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage()); } From 68027b9f16d48bfe58bdc28cebd450a0eabe6731 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 17 May 2019 00:35:42 +0800 Subject: [PATCH 05/13] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9AUser=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E6=8E=A5=E5=85=A5=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=9A=84=20OAuth2=20=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../功能列表/功能列表-管理后台.md | 10 ++-- mobile-web/src/page/account/phonelogin.vue | 2 +- .../iocoder/mall/admin/api/AdminService.java | 2 +- .../iocoder/mall/admin/api/OAuth2Service.java | 2 + .../api/bo/oauth2/OAuth2AuthenticationBO.java | 4 +- .../api/dto/oauth2/OAuth2CreateTokenDTO.java | 3 +- .../api/dto/oauth2/OAuth2GetTokenDTO.java | 3 +- .../mall/admin/service/OAuth2ServiceImpl.java | 1 + .../admin/service/SmsYunPianPlatform.java | 10 ++-- .../controller/users/PassportController.java | 14 ++--- .../user/sdk/context/UserSecurityContext.java | 20 +++---- .../context/UserSecurityContextHolder.java | 2 +- .../interceptor/UserSecurityInterceptor.java | 60 ++++++++++++------- user/user-service-api/pom.xml | 5 ++ .../iocoder/mall/user/api/OAuth2Service.java | 3 +- .../mall/user/api/UserAccessLogService.java | 1 + .../cn/iocoder/mall/user/api/UserService.java | 4 ++ .../api/bo/user/UserAuthenticationBO.java | 22 +++++++ .../UserAuthenticationByMobileCodeDTO.java | 29 +++++++++ .../mall/user/biz/convert/UserConvert.java | 8 ++- .../mall/user/biz/dao/MobileCodeMapper.java | 23 ++++--- .../user/biz/dataobject/MobileCodeDO.java | 9 ++- .../biz/service/MobileCodeServiceImpl.java | 35 +++++------ .../user/biz/service/OAuth2ServiceImpl.java | 21 ------- .../user/biz/service/UserServiceImpl.java | 43 ++++++++++++- .../main/resources/config/application.yaml | 17 +++--- .../resources/mapper/MobileCodeMapper.xml | 35 ----------- .../src/main/resources/mybatis-config.xml | 19 ------ 28 files changed, 229 insertions(+), 178 deletions(-) create mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/user/UserAuthenticationBO.java create mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/user/UserAuthenticationByMobileCodeDTO.java delete mode 100644 user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml delete mode 100644 user/user-service-impl/src/main/resources/mybatis-config.xml diff --git a/docs/guides/功能列表/功能列表-管理后台.md b/docs/guides/功能列表/功能列表-管理后台.md index bb534edf..be9b5190 100644 --- a/docs/guides/功能列表/功能列表-管理后台.md +++ b/docs/guides/功能列表/功能列表-管理后台.md @@ -14,11 +14,11 @@ - [x] 发布商品 - [x] 商品列表 - [x] 展示类目 - - [ ] 品牌管理【待认领】 + - [ ] 品牌管理【开发中 @黑子】 - [ ] 订单管理 - [ ] 销售单 开发中 - [ ] 售后单 开发中 - - [ ] 订单评价【开发中】 + - [ ] 订单评价【开发中 @wang171776704】 - [ ] 会员管理 - [ ] 会员资料 20%【待认领】 - TODO 需要补充 @@ -33,8 +33,10 @@ - [ ] 系统管理 - [x] 员工管理 - [x] 角色管理 - - [ ] 权限管理 - - [ ] 短信管理 + - [x] 权限管理 + - [ ] 部门管理【待认领】 + - [x] 数据字典 + - [ ] 短信管理【开发中 @小范】 - [ ] 短信模板 - [ ] 发送日志 - [ ] 员工操作日志 diff --git a/mobile-web/src/page/account/phonelogin.vue b/mobile-web/src/page/account/phonelogin.vue index 66bf1921..a17b071f 100644 --- a/mobile-web/src/page/account/phonelogin.vue +++ b/mobile-web/src/page/account/phonelogin.vue @@ -69,7 +69,7 @@ export default { let that = this; let response = doPassportMobileRegister(this.mobile, this.code); response.then(data => { - setLoginToken(data.accessToken, data.refreshToken); + setLoginToken(data.token.accessToken, data.token.refreshToken); Dialog.alert({ title: '系统提示', message: '登陆成功', diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java index da12818b..dac695c5 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/AdminService.java @@ -17,7 +17,7 @@ import java.util.Map; public interface AdminService { /** - * 用户认证。认证成功后,返回认证信息 + * 管理员认证。认证成功后,返回认证信息 * * 实际上,就是用户名 + 密码登陆 * diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java index ccc78681..eadf0d37 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/OAuth2Service.java @@ -20,6 +20,8 @@ public interface OAuth2Service { // TODO @see 刷新 token + void removeToken(Integer userId); // TODO 需要优化 + /** * 通过 accessToken 获得身份信息 * diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java index dfd6abb1..2e514653 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationBO.java @@ -5,10 +5,12 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; +import java.io.Serializable; + @ApiModel("OAUTH2 认证 BO") @Data @Accessors(chain = true) -public class OAuth2AuthenticationBO { +public class OAuth2AuthenticationBO implements Serializable { @ApiModelProperty(value = "用户编号", required = true, example = "1") private Integer userId; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2CreateTokenDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2CreateTokenDTO.java index a70e2298..fbd46456 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2CreateTokenDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2CreateTokenDTO.java @@ -8,11 +8,12 @@ import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotNull; +import java.io.Serializable; @ApiModel("OAuth2 创建 Token DTO") @Data @Accessors(chain = true) -public class OAuth2CreateTokenDTO { +public class OAuth2CreateTokenDTO implements Serializable { @ApiModelProperty(value = "用户编号", required = true, example = "1") @NotNull(message = "用户编号不能为空") diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2GetTokenDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2GetTokenDTO.java index 0b0d4862..b2d2b602 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2GetTokenDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2GetTokenDTO.java @@ -9,11 +9,12 @@ import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.io.Serializable; @ApiModel("OAuth2 身份验证 DTO") @Data @Accessors(chain = true) -public class OAuth2GetTokenDTO { +public class OAuth2GetTokenDTO implements Serializable { @ApiModelProperty(value = "accessToken", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") @NotEmpty(message = "accessToken 不能为空") diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java index 5db47a9c..035cf4ed 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/OAuth2ServiceImpl.java @@ -64,6 +64,7 @@ public class OAuth2ServiceImpl implements OAuth2Service { * * @param adminId 管理员编号 */ + @Override @Transactional public void removeToken(Integer adminId) { // 设置 access token 失效 diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java index 8d852a9d..80f4b385 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsYunPianPlatform.java @@ -1,9 +1,9 @@ package cn.iocoder.mall.admin.service; +import cn.iocoder.common.framework.exception.ServiceException; import cn.iocoder.mall.admin.api.SmsPlatform; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; import cn.iocoder.mall.admin.api.constant.SmsApplyStatusEnum; -import cn.iocoder.mall.admin.api.exception.SmsFailException; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -104,7 +104,7 @@ public class SmsYunPianPlatform implements SmsPlatform { String result = post(URL_SIGN_ADD, params); JSONObject jsonObject = JSON.parseObject(result); if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(), AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getMessage()); } @@ -124,13 +124,13 @@ public class SmsYunPianPlatform implements SmsPlatform { JSONObject jsonObject = JSON.parseObject(result); if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(), AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getMessage()); } JSONArray jsonArray = jsonObject.getJSONArray("sign"); if (jsonArray.size() <= 0) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(), AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage()); } @@ -151,7 +151,7 @@ public class SmsYunPianPlatform implements SmsPlatform { JSONObject jsonObject = JSON.parseObject(result); if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) { - throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getCode(), + throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getCode(), AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getMessage()); } diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java index 80db85f1..c51c64ad 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java @@ -5,13 +5,13 @@ import cn.iocoder.mall.user.api.MobileCodeService; import cn.iocoder.mall.user.api.OAuth2Service; import cn.iocoder.mall.user.api.UserService; import cn.iocoder.mall.user.api.bo.OAuth2AccessTokenBO; +import cn.iocoder.mall.user.api.bo.user.UserAuthenticationBO; +import cn.iocoder.mall.user.api.dto.user.UserAuthenticationByMobileCodeDTO; import cn.iocoder.mall.user.application.convert.PassportConvert; import cn.iocoder.mall.user.application.vo.users.UsersAccessTokenVO; -import cn.iocoder.mall.user.application.vo.users.UsersMobileRegisterVO; import cn.iocoder.mall.user.sdk.annotation.PermitAll; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; import org.springframework.web.bind.annotation.PostMapping; @@ -43,14 +43,8 @@ public class PassportController { @PermitAll @PostMapping("/mobile/register") @ApiOperation(value = "手机号 + 验证码登陆(注册)", notes = "如果手机对应的账号不存在,则会自动创建") - @ApiImplicitParams({ - @ApiImplicitParam(name = "mobile", value = "手机号", required = true, example = "15601691300"), - @ApiImplicitParam(name = "code", value = "验证码", required = true, example = "9999") - }) - public CommonResult mobileRegister(@RequestParam("mobile") String mobile, - @RequestParam("code") String code) { - OAuth2AccessTokenBO result = oauth2Service.getAccessToken(mobile, code); - return success(PassportConvert.INSTANCE.convert(result)); + public CommonResult mobileRegister(UserAuthenticationByMobileCodeDTO userAuthenticationByMobileCodeDTO) { + return success(userService.authenticationByMobileCode(userAuthenticationByMobileCodeDTO)); } @PermitAll diff --git a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java index c4332830..c6ab1a70 100644 --- a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java +++ b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java @@ -1,18 +1,18 @@ package cn.iocoder.mall.user.sdk.context; +import lombok.Data; +import lombok.experimental.Accessors; + /** * User Security 上下文 */ +@Data +@Accessors(chain = true) public class UserSecurityContext { - private final Integer userId; + /** + * 用户编号 + */ + private Integer userId; - public UserSecurityContext(Integer userId) { - this.userId = userId; - } - - public Integer getUserId() { - return userId; - } - -} \ No newline at end of file +} diff --git a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContextHolder.java b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContextHolder.java index 09ca1bcd..c63c1a43 100644 --- a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContextHolder.java +++ b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContextHolder.java @@ -17,7 +17,7 @@ public class UserSecurityContextHolder { UserSecurityContext ctx = SECURITY_CONTEXT.get(); // 为空时,设置一个空的进去 if (ctx == null) { - ctx = new UserSecurityContext(null); + ctx = new UserSecurityContext(); SECURITY_CONTEXT.set(ctx); } return ctx; diff --git a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java index 9404aa9b..f559222f 100644 --- a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java +++ b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java @@ -1,11 +1,14 @@ package cn.iocoder.mall.user.sdk.interceptor; -import cn.iocoder.common.framework.constant.MallConstants; +import cn.iocoder.common.framework.constant.UserTypeEnum; import cn.iocoder.common.framework.exception.ServiceException; import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.MallUtil; -import cn.iocoder.mall.user.api.OAuth2Service; -import cn.iocoder.mall.user.api.bo.OAuth2AuthenticationBO; +import cn.iocoder.common.framework.util.StringUtil; +import cn.iocoder.mall.admin.api.OAuth2Service; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AuthenticationBO; +import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; +import cn.iocoder.mall.admin.api.dto.oauth2.OAuth2GetTokenDTO; import cn.iocoder.mall.user.sdk.annotation.PermitAll; import cn.iocoder.mall.user.sdk.context.UserSecurityContext; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; @@ -18,40 +21,55 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** - * 安全拦截器 + * User 安全拦截器 */ @Component public class UserSecurityInterceptor extends HandlerInterceptorAdapter { - @Reference(validation = "true", version = "${dubbo.provider.OAuth2Service.version:1.0.0}") + @Reference(validation = "true", version = "${dubbo.consumer.OAuth2Service.version:1.0.0}") private OAuth2Service oauth2Service; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // 设置当前访问的用户类型。注意,即使未登陆,我们也认为是用户 - MallUtil.setUserType(request, MallConstants.USER_TYPE_USER); - // 校验访问令牌是否正确。若正确,返回授权信息 + MallUtil.setUserType(request, UserTypeEnum.USER.getValue()); + + // 根据 accessToken 获得认证信息,判断是谁 String accessToken = HttpUtil.obtainAuthorization(request); OAuth2AuthenticationBO authentication = null; - if (accessToken != null) { - authentication = oauth2Service.checkToken(accessToken); // TODO 芋艿,如果访问的地址无需登录,这里也不用抛异常 - // 添加到 SecurityContext - UserSecurityContext context = new UserSecurityContext(authentication.getUserId()); - UserSecurityContextHolder.setContext(context); - // 同时也记录管理员编号到 AdminAccessLogInterceptor 中。因为: - // AdminAccessLogInterceptor 需要在 AdminSecurityInterceptor 之前执行,这样记录的访问日志才健全 - // AdminSecurityInterceptor 执行后,会移除 AdminSecurityContext 信息,这就导致 AdminAccessLogInterceptor 无法获得管理员编号 - // 因此,这里需要进行记录 - if (authentication.getUserId() != null) { - MallUtil.setUserId(request, authentication.getUserId()); + ServiceException serviceException = null; + if (StringUtil.hasText(accessToken)) { + try { + authentication = oauth2Service.getAuthentication(new OAuth2GetTokenDTO().setAccessToken(accessToken) + .setUserType(UserTypeEnum.USER.getValue())); + } catch (ServiceException e) { + serviceException = e; } } - // 校验是否需要已授权 + + // 进行鉴权 HandlerMethod method = (HandlerMethod) handler; boolean isPermitAll = method.hasMethodAnnotation(PermitAll.class); - if (!isPermitAll && authentication == null) { - throw new ServiceException(-1, "未授权"); // TODO 这里要改下 + if (!isPermitAll) { // 如果需要鉴权 + if (serviceException != null) { // 认证失败,抛出上面认证失败的 ServiceException 异常 + throw serviceException; + } + if (authentication == null) { // 无认证信息,抛出未登陆 ServiceException 异常 + throw new ServiceException(AdminErrorCodeEnum.OAUTH2_NOT_LOGIN.getCode(), AdminErrorCodeEnum.OAUTH2_NOT_LOGIN.getMessage()); + } + // TODO 芋艿,后续拓展读取用户信息 } + + // 鉴权完成,初始化 AdminSecurityContext 上下文 + UserSecurityContext context = new UserSecurityContext(); + UserSecurityContextHolder.setContext(context); + if (authentication != null) { + context.setUserId(authentication.getUserId()); + MallUtil.setUserId(request, authentication.getUserId()); // 记录到 request 中,避免 AdminSecurityContext 后续清理掉后,其它地方需要用到 userId + // TODO 芋艿,后续拓展读取用户信息 + } + + // 返回成功 return super.preHandle(request, response, handler); } diff --git a/user/user-service-api/pom.xml b/user/user-service-api/pom.xml index 8054f41c..92eade7a 100644 --- a/user/user-service-api/pom.xml +++ b/user/user-service-api/pom.xml @@ -17,6 +17,11 @@ common-framework 1.0-SNAPSHOT + + cn.iocoder.mall + system-service-api + 1.0-SNAPSHOT + diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/OAuth2Service.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/OAuth2Service.java index 2a3ae387..b6cbb6f2 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/OAuth2Service.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/OAuth2Service.java @@ -4,10 +4,9 @@ package cn.iocoder.mall.user.api; import cn.iocoder.mall.user.api.bo.OAuth2AccessTokenBO; import cn.iocoder.mall.user.api.bo.OAuth2AuthenticationBO; +@Deprecated public interface OAuth2Service { - OAuth2AccessTokenBO getAccessToken(String mobile, String code); - /** * 校验访问令牌,获取身份信息( 不包括 accessToken 等等 ) * diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAccessLogService.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAccessLogService.java index 972d6e19..8e5fcaa6 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAccessLogService.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAccessLogService.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.user.api; import cn.iocoder.mall.user.api.dto.UserAccessLogAddDTO; +@Deprecated public interface UserAccessLogService { void addUserAccessLog(UserAccessLogAddDTO userAccessLogAddDTO); diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserService.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserService.java index b97c94ae..94b3d603 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserService.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserService.java @@ -2,13 +2,17 @@ package cn.iocoder.mall.user.api; import cn.iocoder.common.framework.constant.CommonStatusEnum; import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.user.api.bo.user.UserAuthenticationBO; import cn.iocoder.mall.user.api.bo.UserBO; import cn.iocoder.mall.user.api.bo.UserPageBO; import cn.iocoder.mall.user.api.dto.UserPageDTO; import cn.iocoder.mall.user.api.dto.UserUpdateDTO; +import cn.iocoder.mall.user.api.dto.user.UserAuthenticationByMobileCodeDTO; public interface UserService { + UserAuthenticationBO authenticationByMobileCode(UserAuthenticationByMobileCodeDTO userAuthenticationByMobileCodeDTO); + UserPageBO getUserPage(UserPageDTO userPageDTO); UserBO getUser(Integer userId); diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/user/UserAuthenticationBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/user/UserAuthenticationBO.java new file mode 100644 index 00000000..06e40101 --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/user/UserAuthenticationBO.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.user.api.bo.user; + +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +@ApiModel("用户认证 BO") +@Data +@Accessors(chain = true) +public class UserAuthenticationBO { + + @ApiModelProperty(value = "用户编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "昵称", required = true, example = "小王") + private String nickname; + + private OAuth2AccessTokenBO token; + +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/user/UserAuthenticationByMobileCodeDTO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/user/UserAuthenticationByMobileCodeDTO.java new file mode 100644 index 00000000..c63ca07e --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/user/UserAuthenticationByMobileCodeDTO.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.user.api.dto.user; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; + +@ApiModel("用户认证 DTO") +@Data +@Accessors(chain = true) +public class UserAuthenticationByMobileCodeDTO { + + @ApiModelProperty(value = "手机号", required = true, example = "15601691300") + @NotEmpty(message = "手机号不能为空") + @Length(min = 11, max = 11, message = "账号长度为 11 位") + @Pattern(regexp = "^[0-9]+$", message = "手机号必须都是数字") + private String mobile; + + @ApiModelProperty(value = "手机验证码", required = true, example = "1024") + @NotEmpty(message = "手机验证码不能为空") + @Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位") + @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") + private String code; + +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserConvert.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserConvert.java index 3b7a37a2..ea9bb8df 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserConvert.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserConvert.java @@ -1,8 +1,9 @@ package cn.iocoder.mall.user.biz.convert; -import cn.iocoder.mall.user.biz.dataobject.UserDO; +import cn.iocoder.mall.user.api.bo.user.UserAuthenticationBO; import cn.iocoder.mall.user.api.bo.UserBO; import cn.iocoder.mall.user.api.dto.UserUpdateDTO; +import cn.iocoder.mall.user.biz.dataobject.UserDO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -17,10 +18,13 @@ public interface UserConvert { @Mappings({}) UserBO convert(UserDO userDO); + @Mappings({}) + UserAuthenticationBO convert2(UserDO userDO); + @Mappings({}) UserDO convert(UserUpdateDTO userUpdateDTO); @Mappings({}) List convert(List userDOs); -} \ No newline at end of file +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/MobileCodeMapper.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/MobileCodeMapper.java index 6691a75c..1e68c74b 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/MobileCodeMapper.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/MobileCodeMapper.java @@ -1,19 +1,12 @@ package cn.iocoder.mall.user.biz.dao; import cn.iocoder.mall.user.biz.dataobject.MobileCodeDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.springframework.stereotype.Repository; @Repository // 实际不加也没问entity,就是不想 IDEA 那看到有个报错 -public interface MobileCodeMapper { - - void insert(MobileCodeDO entity); - - /** - * 更新手机验证码 - * - * @param entity 更新信息 - */ - void update(MobileCodeDO entity); +public interface MobileCodeMapper extends BaseMapper { /** * 获得手机号的最后一个手机验证码 @@ -21,6 +14,12 @@ public interface MobileCodeMapper { * @param mobile 手机号 * @return 手机验证码 */ - MobileCodeDO selectLast1ByMobile(String mobile); + default MobileCodeDO selectLast1ByMobile(String mobile) { + QueryWrapper query = new QueryWrapper() + .eq("mobile", mobile) + .orderByDesc("id") + .last("limit 1"); + return selectOne(query); + } -} \ No newline at end of file +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/MobileCodeDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/MobileCodeDO.java index aec91c67..0963e41f 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/MobileCodeDO.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/MobileCodeDO.java @@ -1,14 +1,17 @@ package cn.iocoder.mall.user.biz.dataobject; +import cn.iocoder.common.framework.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; import java.util.Date; // TODO 优化,IP +@TableName("mobile_code") @Data @Accessors(chain = true) -public class MobileCodeDO { +public class MobileCodeDO extends BaseDO { /** * 编号 @@ -34,10 +37,6 @@ public class MobileCodeDO { * 注册的用户编号 */ private Integer usedUserId; - /** - * 创建时间 - */ - private Date createTime; /** * 使用时间 */ diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/MobileCodeServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/MobileCodeServiceImpl.java index 11e78ae9..eba7226c 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/MobileCodeServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/MobileCodeServiceImpl.java @@ -50,21 +50,21 @@ public class MobileCodeServiceImpl implements MobileCodeService { */ public MobileCodeDO validLastMobileCode(String mobile, String code) { // TODO: 2019-04-09 Sin 暂时先忽略掉验证码校验 - return new MobileCodeDO().setCode(code).setCreateTime(new Date()).setId(1); -// MobileCodeDO mobileCodePO = mobileCodeMapper.selectLast1ByMobile(mobile); -// if (mobileCodePO == null) { // 若验证码不存在,抛出异常 -// throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_NOT_FOUND.getCode()); -// } -// if (System.currentTimeMillis() - mobileCodePO.getCreateTime().getTime() >= codeExpireTimes) { // 验证码已过期 -// throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_EXPIRED.getCode()); -// } -// if (mobileCodePO.getUsed()) { // 验证码已使用 -// throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_USED.getCode()); -// } -// if (!mobileCodePO.getCode().equals(code)) { -// throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_NOT_CORRECT.getCode()); -// } -// return mobileCodePO; +// return new MobileCodeDO().setCode(code).setCreateTime(new Date()).setId(1); + MobileCodeDO mobileCodePO = mobileCodeMapper.selectLast1ByMobile(mobile); + if (mobileCodePO == null) { // 若验证码不存在,抛出异常 + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_NOT_FOUND.getCode()); + } + if (System.currentTimeMillis() - mobileCodePO.getCreateTime().getTime() >= codeExpireTimes) { // 验证码已过期 + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_EXPIRED.getCode()); + } + if (mobileCodePO.getUsed()) { // 验证码已使用 + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_USED.getCode()); + } + if (!mobileCodePO.getCode().equals(code)) { + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.MOBILE_CODE_NOT_CORRECT.getCode()); + } + return mobileCodePO; } /** @@ -75,7 +75,7 @@ public class MobileCodeServiceImpl implements MobileCodeService { */ public void useMobileCode(Integer id, Integer userId) { MobileCodeDO update = new MobileCodeDO().setId(id).setUsed(true).setUsedUserId(userId).setUsedTime(new Date()); - mobileCodeMapper.update(update); + mobileCodeMapper.updateById(update); } // TODO 芋艿,后面要返回有效时间 @@ -99,7 +99,8 @@ public class MobileCodeServiceImpl implements MobileCodeService { MobileCodeDO newMobileCodePO = new MobileCodeDO().setMobile(mobile) .setCode("9999") // TODO 芋艿,随机 4 位验证码 or 6 位验证码 .setTodayIndex(lastMobileCodePO != null ? lastMobileCodePO.getTodayIndex() : 1) - .setUsed(false).setCreateTime(new Date()); + .setUsed(false); + newMobileCodePO.setCreateTime(new Date()); mobileCodeMapper.insert(newMobileCodePO); // TODO 发送验证码短信 } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/OAuth2ServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/OAuth2ServiceImpl.java index b4880370..a568d052 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/OAuth2ServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/OAuth2ServiceImpl.java @@ -49,27 +49,6 @@ public class OAuth2ServiceImpl implements OAuth2Service { @Autowired private OAuth2RefreshTokenMapper oauth2RefreshTokenMapper; - @Override - @Transactional - public OAuth2AccessTokenBO getAccessToken(String mobile, String code) { - // 校验传入的 mobile 和 code 是否合法 - MobileCodeDO mobileCodeDO = mobileCodeService.validLastMobileCode(mobile, code); - // 获取用户 - UserDO userDO = userService.getUser(mobile); - if (userDO == null) { // 用户不存在,则进行创建用户 - userDO = userService.createUser(mobile); - Assert.notNull(userDO, "创建用户必然成功"); - } - // 创建刷新令牌 - OAuth2RefreshTokenDO oauth2RefreshTokenDO = createOAuth2RefreshToken(userDO.getId()); - // 创建访问令牌 - OAuth2AccessTokenDO oauth2AccessTokenDO = createOAuth2AccessToken(userDO.getId(), oauth2RefreshTokenDO.getId()); - // 标记已使用 - mobileCodeService.useMobileCode(mobileCodeDO.getId(), userDO.getId()); - // 转换返回 - return OAuth2Convert.INSTANCE.convertToAccessTokenWithExpiresIn(oauth2AccessTokenDO); - } - @Override public OAuth2AuthenticationBO checkToken(String accessToken) throws ServiceException { OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenMapper.selectByTokenId(accessToken); diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java index f9fd61ac..874a48eb 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java @@ -3,20 +3,28 @@ package cn.iocoder.mall.user.biz.service; import cn.iocoder.common.framework.constant.CommonStatusEnum; import cn.iocoder.common.framework.constant.DeletedStatusEnum; import cn.iocoder.common.framework.constant.SysErrorCodeEnum; +import cn.iocoder.common.framework.constant.UserTypeEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.util.ValidationUtil; +import cn.iocoder.mall.admin.api.OAuth2Service; +import cn.iocoder.mall.admin.api.bo.oauth2.OAuth2AccessTokenBO; +import cn.iocoder.mall.admin.api.dto.oauth2.OAuth2CreateTokenDTO; import cn.iocoder.mall.user.api.UserService; +import cn.iocoder.mall.user.api.bo.user.UserAuthenticationBO; import cn.iocoder.mall.user.api.bo.UserBO; import cn.iocoder.mall.user.api.bo.UserPageBO; import cn.iocoder.mall.user.api.constant.UserConstants; import cn.iocoder.mall.user.api.constant.UserErrorCodeEnum; import cn.iocoder.mall.user.api.dto.UserPageDTO; import cn.iocoder.mall.user.api.dto.UserUpdateDTO; +import cn.iocoder.mall.user.api.dto.user.UserAuthenticationByMobileCodeDTO; import cn.iocoder.mall.user.biz.convert.UserConvert; import cn.iocoder.mall.user.biz.dao.UserMapper; import cn.iocoder.mall.user.biz.dao.UserRegisterMapper; +import cn.iocoder.mall.user.biz.dataobject.MobileCodeDO; import cn.iocoder.mall.user.biz.dataobject.UserDO; import cn.iocoder.mall.user.biz.dataobject.UserRegisterDO; +import org.apache.dubbo.config.annotation.Reference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,7 +43,10 @@ public class UserServiceImpl implements UserService { @Autowired private UserRegisterMapper userRegisterMapper; @Autowired - private OAuth2ServiceImpl oAuth2Service; + private MobileCodeServiceImpl mobileCodeService; + + @Reference(validation = "true", version = "${dubbo.consumer.OAuth2Service.version}") + private OAuth2Service oAuth2Service; public UserDO getUser(String mobile) { return userMapper.selectByMobile(mobile); @@ -67,6 +78,36 @@ public class UserServiceImpl implements UserService { userRegisterMapper.insert(userRegisterDO); } + @Override + @Transactional + public UserAuthenticationBO authenticationByMobileCode(UserAuthenticationByMobileCodeDTO userAuthenticationByMobileCodeDTO) { + String mobile = userAuthenticationByMobileCodeDTO.getMobile(); + String code = userAuthenticationByMobileCodeDTO.getCode(); + // 校验手机格式 + if (!ValidationUtil.isMobile(mobile)) { + throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓 + } + // 校验验证码是否正确 + MobileCodeDO mobileCodeDO = mobileCodeService.validLastMobileCode(mobile, code); + // 获得用户 + UserDO user = userMapper.selectByMobile(mobile); + if (user == null) { // 用户不存在,则进行创建 + user = new UserDO().setMobile(mobile).setStatus(UserConstants.STATUS_ENABLE); + user.setCreateTime(new Date()); + user.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); + userMapper.insert(user); + // 插入注册信息 TODO 芋艿 后续完善,记录 ip、ua 等等 + createUserRegister(user); + } + // 更新验证码已使用 + mobileCodeService.useMobileCode(mobileCodeDO.getId(), user.getId()); + // 创建 accessToken + OAuth2AccessTokenBO accessTokenBO = oAuth2Service.createToken(new OAuth2CreateTokenDTO().setUserId(user.getId()) + .setUserType(UserTypeEnum.USER.getValue())); + // 转换返回 + return UserConvert.INSTANCE.convert2(user).setToken(accessTokenBO); + } + @Override public UserPageBO getUserPage(UserPageDTO userPageDTO) { UserPageBO userPageBO = new UserPageBO(); diff --git a/user/user-service-impl/src/main/resources/config/application.yaml b/user/user-service-impl/src/main/resources/config/application.yaml index 51578545..105bfc29 100644 --- a/user/user-service-impl/src/main/resources/config/application.yaml +++ b/user/user-service-impl/src/main/resources/config/application.yaml @@ -6,19 +6,17 @@ spring: username: root password: ${MALL_MYSQL_PASSWORD} -# mybatis -#mybatis: -# config-location: classpath:mybatis-config.xml -# mapper-locations: classpath:mapper/*.xml -# type-aliases-package: cn.iocoder.mall.user.biz.dataobject - # mybatis-plus mybatis-plus: configuration: - mapUnderscoreToCamelCase: true # 虽然默认为 true ,但是还是显示去指定下。 + map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 + global-config: + db-config: + id-type: auto + logic-delete-value: 1 # 逻辑已删除值(默认为 1) + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) mapperLocations: classpath*:mapper/*.xml typeAliasesPackage: cn.iocoder.mall.user.biz.dataobject - config-location: classpath:mybatis-config.xml # dubbo dubbo: @@ -43,3 +41,6 @@ dubbo: version: 1.0.0 UserService: version: 1.0.0 + consumer: + OAuth2Service: + version: 1.0.0 diff --git a/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml b/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml deleted file mode 100644 index a5599ef9..00000000 --- a/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - INSERT INTO mobile_code ( - id, mobile, code, today_index, used, - userd_user_id, used_time, create_time - ) VALUES ( - #{id}, #{mobile}, #{code}, #{todayIndex}, #{used}, - #{usedUserId}, #{usedTime}, #{createTime} - ) - - - - UPDATE mobile_code - - used = #{used}, - userd_user_id = #{usedUserId}, - used_time = #{usedTime}, - - WHERE id = #{id} - - - - - \ No newline at end of file diff --git a/user/user-service-impl/src/main/resources/mybatis-config.xml b/user/user-service-impl/src/main/resources/mybatis-config.xml deleted file mode 100644 index 7f604cc7..00000000 --- a/user/user-service-impl/src/main/resources/mybatis-config.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file From dbf2a4392408c8389ca87bc3688dcf205e3ffb04 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 17 May 2019 19:23:26 +0800 Subject: [PATCH 06/13] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20README=20-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 +- .../common/framework/util/StringUtil.java | 4 + .../mall/spring/boot/package-info.java | 1 - .../boot/web/AdminMVCAutoConfiguration.java | 8 ++ .../功能列表/功能列表-H5 商城.md | 4 +- .../功能列表/功能列表-管理后台.md | 19 ++- mobile-web/src/config/request.js | 12 +- mobile-web/src/page/category/index.vue | 15 -- mobile-web/src/page/user/info/detail.vue | 8 +- .../admins/AdminOrderReturnController.java | 4 +- .../admins/AdminsOrderController.java | 9 +- .../controller/users/OrderController.java | 14 +- .../users/OrderLogisticsController.java | 3 +- .../users/OrderReturnController.java | 3 +- .../controller/users/UsersCartController.java | 6 +- .../iocoder/mall/order/api/OrderService.java | 2 +- .../mall/order/api/bo/OrderRecipientBO.java | 2 +- .../mall/order/api/dto/CalcOrderPriceDTO.java | 2 + .../iocoder/mall/order/api/package-info.java | 7 - .../config/ServiceExceptionConfiguration.java | 4 +- .../order/biz/constants/package-info.java | 7 - .../order/biz/dataobject/OrderReturnDO.java | 5 +- .../biz/service/OrderReturnServiceImpl.java | 2 +- .../order/biz/service/OrderServiceImpl.java | 33 ++--- .../main/resources/config/application.yaml | 1 - .../src/main/resources/mybatis-config.xml | 19 --- .../admins/AdminsPayRefundController.java | 8 +- .../AdminsPayTransactionController.java | 4 +- .../users/UsersPayTransactionController.java | 42 +++--- .../application/convert/PayRefundConvert.java | 2 +- .../vo/admins/AdminsPayRefundDetailVO.java | 4 +- .../mall/pay/api/PayRefundService.java | 8 +- .../mall/pay/api/PayTransactionService.java | 21 +-- .../pay/api/bo/PayTransactionSubmitBO.java | 24 ---- .../pay/api/bo/{ => refund}/PayRefundBO.java | 2 +- .../api/bo/{ => refund}/PayRefundPageBO.java | 2 +- .../bo/{ => refund}/PayRefundSubmitBO.java | 2 +- .../{ => transaction}/PayTransactionBO.java | 63 ++++----- .../PayTransactionPageBO.java | 2 +- .../transaction/PayTransactionSubmitBO.java | 21 +++ .../mall/pay/api/constant/PayChannelEnum.java | 13 +- .../pay/api/dto/PayTransactionSubmitDTO.java | 37 ----- .../dto/{ => refund}/PayRefundPageDTO.java | 2 +- .../dto/{ => refund}/PayRefundSubmitDTO.java | 2 +- .../PayTransactionCreateDTO.java | 49 +++---- .../dto/transaction/PayTransactionGetDTO.java | 28 ++++ .../PayTransactionPageDTO.java | 2 +- .../transaction/PayTransactionSubmitDTO.java | 35 +++++ .../pay/biz/component/DubboReferencePool.java | 20 +-- .../pay/biz/convert/PayRefundConvert.java | 4 +- .../biz/convert/PayTransactionConvert.java | 6 +- .../pay/biz/mq/PayRefundSuccessConsumer.java | 1 + .../pay/biz/service/PayAppServiceImpl.java | 11 +- .../pay/biz/service/PayNotifyServiceImpl.java | 1 + .../pay/biz/service/PayRefundServiceImpl.java | 16 +-- .../service/PayTransactionServiceImpl.java | 67 +++++---- .../biz/service/PayRefundServiceImplTest.java | 2 +- .../PayTransactionServiceImplTest.java | 4 - .../users/UsersProductCategoryController.java | 4 +- .../users/UsersProductSpuController.java | 3 - .../users/UsersBannerController.java | 2 - .../users/UsersCouponController.java | 2 - .../UsersProductRecommendController.java | 2 - .../main/resources/config/application.yaml | 7 +- .../src/main/resources/mybatis-config.xml | 19 --- sessionStore/root.data | Bin 0 -> 9710 bytes .../sdk/context/AdminSecurityContext.java | 10 ++ .../sdk/interceptor/AdminDemoInterceptor.java | 31 +++++ .../interceptor/AdminSecurityInterceptor.java | 5 +- .../iocoder/mall/admin/sdk/package-info.java | 4 +- .../iocoder/mall/admin/api/OAuth2Service.java | 17 ++- .../api/bo/admin/AdminAuthorizationBO.java | 6 +- .../bo/oauth2/OAuth2AuthenticationOldBO.java | 27 ---- .../admin/api/constant/AdminConstants.java | 10 +- .../api/constant/AdminErrorCodeEnum.java | 7 +- .../api/dto/oauth2/OAuth2RefreshTokenDTO.java | 28 ++++ .../oauth2/OAuth2RemoveTokenByUserDTO.java | 27 ++++ .../mall/admin/convert/OAuth2Convert.java | 12 -- .../admin/dao/OAuth2AccessTokenMapper.java | 11 +- .../admin/dao/OAuth2RefreshTokenMapper.java | 5 +- .../mall/admin/service/AdminServiceImpl.java | 18 ++- .../mall/admin/service/OAuth2ServiceImpl.java | 37 +++-- .../cn/iocoder/mall/admin/package-info.java | 5 - .../controller/users/PassportController.java | 22 ++- .../controller/users/UserController.java | 4 + .../application/convert/PassportConvert.java | 21 --- .../user/application/po/UserAddressAddPO.java | 8 +- .../mall/user/sdk/annotation/PermitAll.java | 14 -- .../user/sdk/annotation/RequiresLogin.java | 16 +++ .../interceptor/UserSecurityInterceptor.java | 6 +- .../iocoder/mall/user/api/OAuth2Service.java | 22 --- .../mall/user/api/UserAccessLogService.java | 10 -- .../mall/user/api/bo/OAuth2AccessTokenBO.java | 25 ---- .../user/api/bo/OAuth2AuthenticationBO.java | 17 --- .../user/api/dto/UserAccessLogAddDTO.java | 65 --------- .../mall/user/biz/convert/OAuth2Convert.java | 29 ---- .../biz/convert/UserAccessLogConvert.java | 17 --- .../user/biz/dao/OAuth2AccessTokenMapper.java | 18 --- .../biz/dao/OAuth2RefreshTokenMapper.java | 16 --- .../user/biz/dao/UserAccessLogMapper.java | 11 -- .../user/biz/service/OAuth2ServiceImpl.java | 129 ------------------ .../biz/service/UserAccessLogServiceImpl.java | 54 -------- .../user/biz/service/UserServiceImpl.java | 3 +- .../resources/config/application.properties | 3 - .../main/resources/config/application.yaml | 2 - .../mapper/OAuth2AccessTokenMapper.xml | 36 ----- .../mapper/OAuth2RefreshTokenMapper.xml | 27 ---- .../resources/mapper/UserAccessLogMapper.xml | 20 --- 108 files changed, 589 insertions(+), 1017 deletions(-) delete mode 100644 common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/package-info.java delete mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/package-info.java delete mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/constants/package-info.java delete mode 100644 order/order-service-impl/src/main/resources/mybatis-config.xml delete mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/PayTransactionSubmitBO.java rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/{ => refund}/PayRefundBO.java (97%) rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/{ => refund}/PayRefundPageBO.java (89%) rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/{ => refund}/PayRefundSubmitBO.java (83%) rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/{ => transaction}/PayTransactionBO.java (54%) rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/{ => transaction}/PayTransactionPageBO.java (88%) create mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/transaction/PayTransactionSubmitBO.java delete mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/PayTransactionSubmitDTO.java rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/{ => refund}/PayRefundPageDTO.java (95%) rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/{ => refund}/PayRefundSubmitDTO.java (96%) rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/{ => transaction}/PayTransactionCreateDTO.java (56%) create mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/transaction/PayTransactionGetDTO.java rename pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/{ => transaction}/PayTransactionPageDTO.java (95%) create mode 100644 pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/transaction/PayTransactionSubmitDTO.java delete mode 100644 promotion/promotion-service-impl/src/main/resources/mybatis-config.xml create mode 100644 sessionStore/root.data create mode 100644 system/system-sdk/src/main/java/cn/iocoder/mall/admin/sdk/interceptor/AdminDemoInterceptor.java delete mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/oauth2/OAuth2AuthenticationOldBO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2RefreshTokenDTO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/oauth2/OAuth2RemoveTokenByUserDTO.java delete mode 100644 system/system-service-impl/src/test/java/cn/iocoder/mall/admin/package-info.java delete mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/PassportConvert.java delete mode 100644 user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/annotation/PermitAll.java create mode 100644 user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/annotation/RequiresLogin.java delete mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/OAuth2Service.java delete mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAccessLogService.java delete mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/OAuth2AccessTokenBO.java delete mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/OAuth2AuthenticationBO.java delete mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAccessLogAddDTO.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/OAuth2Convert.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAccessLogConvert.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/OAuth2AccessTokenMapper.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/OAuth2RefreshTokenMapper.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/UserAccessLogMapper.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/OAuth2ServiceImpl.java delete mode 100644 user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAccessLogServiceImpl.java delete mode 100644 user/user-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml delete mode 100644 user/user-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml delete mode 100644 user/user-service-impl/src/main/resources/mapper/UserAccessLogMapper.xml diff --git a/README.md b/README.md index d6dff6e1..b6f38bcc 100644 --- a/README.md +++ b/README.md @@ -30,19 +30,26 @@ # 演示 +> 艿艿:目前的开发者,都是后端出身。所以,一帮没有审美自觉的人,撸出来的前端界面,可能是东半球倒数第二难看。 +> +> 迫切希望,有前端能力不错的小伙伴,加入我们,一起来完善「一个商城」。 +> +> 啊啊啊!我好像做店铺装修功能。 + ## H5 商城 [体验传送门](http://h5.shop.iocoder.cn:18099) -TODO 此处应有一个演示的装逼 GIF 图。 +![手残艿艿的 GIF 图](https://cdn.sinaimg.cn.52ecy.cn/large/005BYqpgly1g34hgm6fyhg31hc0u0nph.jpg) ## 管理后台 [体验传送门](http://admin.shop.iocoder.cn:18099) -TODO 暂时不提供管理后台的账号密码,等后面提供。 +* 账号:yudaoyuanma +* 密码:yudaoyuanma -TODO 此处应有一个演示的装逼 GIF 图。 +![](http://ww1.sinaimg.cn/large/98a7a01cgy1g34j9b2ktqg21hc0u01lf.gif) ## 其它演示 diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/StringUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/StringUtil.java index c947894d..61ebff37 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/StringUtil.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/StringUtil.java @@ -35,4 +35,8 @@ public class StringUtil { return org.apache.commons.lang3.StringUtils.substring(str, start); } + public static void main(String[] args) { + System.out.println(StringUtil.split("cn.iocoder.mall.order.api.OrderService#updatePaySuccess#1.0.0", "#").size()); + } + } diff --git a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/package-info.java b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/package-info.java deleted file mode 100644 index e8b0e471..00000000 --- a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package cn.iocoder.mall.spring.boot; diff --git a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/AdminMVCAutoConfiguration.java b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/AdminMVCAutoConfiguration.java index f2c947b5..b83ecbdd 100644 --- a/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/AdminMVCAutoConfiguration.java +++ b/common/mall-spring-boot/src/main/java/cn/iocoder/mall/spring/boot/web/AdminMVCAutoConfiguration.java @@ -2,6 +2,7 @@ package cn.iocoder.mall.spring.boot.web; import cn.iocoder.common.framework.constant.MallConstants; import cn.iocoder.common.framework.servlet.CorsFilter; +import cn.iocoder.mall.admin.sdk.interceptor.AdminDemoInterceptor; import cn.iocoder.mall.spring.boot.web.interceptor.AccessLogInterceptor; import cn.iocoder.mall.admin.sdk.interceptor.AdminSecurityInterceptor; import cn.iocoder.mall.spring.boot.web.handler.GlobalExceptionHandler; @@ -34,6 +35,12 @@ public class AdminMVCAutoConfiguration implements WebMvcConfigurer { return new AdminSecurityInterceptor(); } + @Bean + @ConditionalOnMissingBean(AdminDemoInterceptor.class) + public AdminDemoInterceptor adminDemoInterceptor() { + return new AdminDemoInterceptor(); + } + @Bean @ConditionalOnMissingBean(GlobalResponseBodyHandler.class) public GlobalResponseBodyHandler globalReturnValueHandler() { @@ -50,6 +57,7 @@ public class AdminMVCAutoConfiguration implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(adminAccessLogInterceptor()).addPathPatterns(MallConstants.ROOT_PATH_ADMIN + "/**"); registry.addInterceptor(adminSecurityInterceptor()).addPathPatterns(MallConstants.ROOT_PATH_ADMIN + "/**"); + registry.addInterceptor(adminDemoInterceptor()).addPathPatterns(MallConstants.ROOT_PATH_ADMIN + "/**"); } @Bean diff --git a/docs/guides/功能列表/功能列表-H5 商城.md b/docs/guides/功能列表/功能列表-H5 商城.md index 56f33d3e..1cd19aa1 100644 --- a/docs/guides/功能列表/功能列表-H5 商城.md +++ b/docs/guides/功能列表/功能列表-H5 商城.md @@ -29,4 +29,6 @@ - 用户相关 - [x] 登陆 - [x] 注册 - - [ ] 个人信息 + - [x] 个人信息 + - [ ] 手机改绑 + - [ ] 微信登陆 diff --git a/docs/guides/功能列表/功能列表-管理后台.md b/docs/guides/功能列表/功能列表-管理后台.md index be9b5190..d8bb63a8 100644 --- a/docs/guides/功能列表/功能列表-管理后台.md +++ b/docs/guides/功能列表/功能列表-管理后台.md @@ -10,17 +10,25 @@ - [ ] 支付单 20% 【待认领】 - [ ] 退款单 20% 【待认领】 - TODO 需要补充 +- [ ] 店铺装修【迫切需要靠谱前端一起做】 + - [ ] H5 装修 + - [ ] 小程序装修 + - [ ] 自定义页面 - [ ] 商品管理 - [x] 发布商品 - [x] 商品列表 - [x] 展示类目 - [ ] 品牌管理【开发中 @黑子】 + - [ ] 商品标签 - [ ] 订单管理 - - [ ] 销售单 开发中 - - [ ] 售后单 开发中 + - [x] 销售单 + - [x] 售后单 - [ ] 订单评价【开发中 @wang171776704】 - [ ] 会员管理 - [ ] 会员资料 20%【待认领】 + - [ ] 会员等级 + - [ ] 会员积分 + - [ ] 用户标签 - TODO 需要补充 - [ ] 营销管理 - [x] 首页广告 @@ -30,6 +38,13 @@ - [ ] 满减送 20% 【待认领】 - [ ] 限制折扣 20% 【待认领】 - [ ] 多人拼团【待认领】 + - [ ] 积分商城 + - [ ] 问卷调查 + - [ ] 幸运大转盘 +- [ ] 分销管理 + - [ ] 分销设置 + - [ ] 分销员管理 + - [ ] 提现管理 - [ ] 系统管理 - [x] 员工管理 - [x] 角色管理 diff --git a/mobile-web/src/config/request.js b/mobile-web/src/config/request.js index 90183546..9d92692e 100644 --- a/mobile-web/src/config/request.js +++ b/mobile-web/src/config/request.js @@ -229,11 +229,11 @@ service.interceptors.response.use( // TODO token 过期 // TODO 需要拿 refresh token 置换 - if (code === 1001001011 // 访问令牌不存在 - || code === 1001001013 // 访问令牌已失效 - || code === 1001001021 // 刷新令牌不存在 - || code === 1001001022 // 刷新令牌已过期 - || code === 1001001023) { // 刷新令牌已失效 + if (code === 1002001011 // 访问令牌不存在 + || code === 1002001013 // 访问令牌已失效 + || code === 1002001017 // 刷新令牌不存在 + || code === 1002001018 // 刷新令牌已过期 + || code === 1002001019) { // 刷新令牌已失效 Dialog.confirm({ title: '系统提示', message: res.message, @@ -249,7 +249,7 @@ service.interceptors.response.use( } } }); - } else if (code === 1001001012) { // 访问令牌已过期 + } else if (code === 1002001012) { // 访问令牌已过期 return refreshToken(response); } else { Dialog.alert({ diff --git a/mobile-web/src/page/category/index.vue b/mobile-web/src/page/category/index.vue index 2f7cd5da..5baa9837 100644 --- a/mobile-web/src/page/category/index.vue +++ b/mobile-web/src/page/category/index.vue @@ -50,21 +50,6 @@
    - - - - - - - - - - - - - - -
  • diff --git a/mobile-web/src/page/user/info/detail.vue b/mobile-web/src/page/user/info/detail.vue index 155a303b..be4913e8 100644 --- a/mobile-web/src/page/user/info/detail.vue +++ b/mobile-web/src/page/user/info/detail.vue @@ -1,7 +1,7 @@