diff --git a/common/common-framework/pom.xml b/common/common-framework/pom.xml index 0aa12f44d..76937f96f 100644 --- a/common/common-framework/pom.xml +++ b/common/common-framework/pom.xml @@ -32,6 +32,11 @@ mybatis + + com.baomidou + mybatis-plus-annotation + + org.apache.dubbo diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/dataobject/DeletableDO.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/dataobject/DeletableDO.java index ce006b925..3e70485ce 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/dataobject/DeletableDO.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/dataobject/DeletableDO.java @@ -1,5 +1,7 @@ package cn.iocoder.common.framework.dataobject; +import com.baomidou.mybatisplus.annotation.TableLogic; + /** * extends BaseDO 扩展 delete 操作 * @@ -11,6 +13,7 @@ public class DeletableDO extends BaseDO { /** * 是否删除 */ + @TableLogic private Integer deleted; @Override diff --git a/docs/guides/功能列表/功能列表-管理后台.md b/docs/guides/功能列表/功能列表-管理后台.md index 59f2f6b65..9b79f4d35 100644 --- a/docs/guides/功能列表/功能列表-管理后台.md +++ b/docs/guides/功能列表/功能列表-管理后台.md @@ -37,7 +37,6 @@ - [ ] 短信管理 - [ ] 短信模板 - [ ] 发送日志 - - [ ] 用户访问日志 - - [ ] 员工访问日志 - [ ] 员工操作日志 + - [ ] 访问日志 - [ ] 异常日志 diff --git a/pom.xml b/pom.xml index 373f2a96b..85b32e69e 100644 --- a/pom.xml +++ b/pom.xml @@ -138,6 +138,11 @@ mybatis-spring-boot-starter ${mybatis-spring-boot-starter.version} + + com.baomidou + mybatis-plus-annotation + ${mybatis-plus.version} + com.baomidou mybatis-plus-boot-starter diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index 0b3b46ff4..b7bcb0b23 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -1,24 +1,24 @@ package cn.iocoder.mall.admin.application.controller.admins; +import cn.iocoder.common.framework.constant.MallConstants; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.AdminService; import cn.iocoder.mall.admin.api.ResourceService; import cn.iocoder.mall.admin.api.RoleService; -import cn.iocoder.mall.admin.api.bo.AdminPageBO; import cn.iocoder.mall.admin.api.bo.ResourceBO; import cn.iocoder.mall.admin.api.bo.RoleBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; import cn.iocoder.mall.admin.api.constant.ResourceConstants; -import cn.iocoder.mall.admin.api.dto.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.AdminPageDTO; -import cn.iocoder.mall.admin.api.dto.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; import cn.iocoder.mall.admin.application.convert.AdminConvert; import cn.iocoder.mall.admin.application.convert.ResourceConvert; import cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO; import cn.iocoder.mall.admin.application.vo.AdminPageVO; import cn.iocoder.mall.admin.application.vo.AdminRoleVO; -import cn.iocoder.mall.admin.application.vo.AdminVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; -import cn.iocoder.common.framework.constant.MallConstants; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.*; import java.util.*; import java.util.stream.Collectors; +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/admin") @Api("管理员模块") @@ -70,7 +72,7 @@ public class AdminController { .filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT)) // .sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort)) .collect(Collectors.toList()); - return CommonResult.success(rootNodes); + return success(rootNodes); } @GetMapping("/url_resource_list") @@ -78,7 +80,7 @@ public class AdminController { // @ApiModelProperty(value = "data", example = "['/admin/role/add', '/admin/role/update']") 没效果 public CommonResult> urlResourceList() { List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_URL, AdminSecurityContextHolder.getContext().getRoleIds()); - return CommonResult.success(resources.stream().map(ResourceBO::getHandler).collect(Collectors.toSet())); + return success(resources.stream().map(ResourceBO::getHandler).collect(Collectors.toSet())); } // =========== 管理员管理 API =========== @@ -90,25 +92,16 @@ public class AdminController { @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) - public CommonResult page(@RequestParam(value = "nickname", required = false) String nickname, - @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { - CommonResult result = adminService.getAdminPage(new AdminPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize)); + public CommonResult page(AdminPageDTO adminPageDTO) { +// CommonResult result = adminService.getAdminPage(new AdminPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize)); + CommonResult result = adminService.getAdminPage(adminPageDTO); return AdminConvert.INSTANCE.convert(result); } @PostMapping("/add") @ApiOperation(value = "创建管理员") - @ApiImplicitParams({ - @ApiImplicitParam(name = "username", value = "账号", required = true, example = "15601691300"), - @ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"), - @ApiImplicitParam(name = "password", value = "密码", required = true, example = "buzhidao"), - }) - public CommonResult add(@RequestParam("username") String username, - @RequestParam("nickname") String nickname, - @RequestParam("password") String password) { - AdminAddDTO adminAddDTO = new AdminAddDTO().setUsername(username).setNickname(nickname).setPassword(password); - return AdminConvert.INSTANCE.convert2(adminService.addAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminAddDTO)); + public CommonResult add(AdminAddDTO adminAddDTO) { + return success(adminService.addAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminAddDTO)); } @PostMapping("/update") @@ -157,7 +150,7 @@ public class AdminController { List result = AdminConvert.INSTANCE.convert(allRoleList); // 设置每个角色是否赋予给改管理员 result.forEach(adminRoleVO -> adminRoleVO.setAssigned(adminRoleIdSet.contains(adminRoleVO.getId()))); - return CommonResult.success(result); + return success(result); } @PostMapping("/assign_role") diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java index 4a06d9022..42b4e57a6 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java @@ -1,8 +1,8 @@ package cn.iocoder.mall.admin.application.convert; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.AdminBO; -import cn.iocoder.mall.admin.api.bo.AdminPageBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; import cn.iocoder.mall.admin.api.bo.RoleBO; import cn.iocoder.mall.admin.application.vo.AdminInfoVO; import cn.iocoder.mall.admin.application.vo.AdminPageVO; @@ -35,4 +35,4 @@ public interface AdminConvert { @Mappings({}) List convert(List roleList); -} \ No newline at end of file +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java index 4a9df5b4c..4090bbfe9 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminVO.java @@ -14,12 +14,16 @@ public class AdminVO { @ApiModelProperty(value = "管理员编号", required = true, example = "1") private Integer id; + @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") private String username; + @ApiModelProperty(value = "昵称", required = true, example = "小王") private String nickname; + @ApiModelProperty(value = "账号状态", required = true, example = "1") private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") private Date createTime; diff --git a/system/system-application/src/main/resources/application-test.yaml b/system/system-application/src/main/resources/application-test.yaml index 96d1cacc3..c7ab7fb7c 100644 --- a/system/system-application/src/main/resources/application-test.yaml +++ b/system/system-application/src/main/resources/application-test.yaml @@ -16,7 +16,3 @@ management: swagger: enable: true # 暂时不去掉 - title: 管理员子系统 - description: 管理员子系统 - version: 1.0.0 - base-package: cn.iocoder.mall.admin.application.controller diff --git a/system/system-application/src/main/resources/application.yaml b/system/system-application/src/main/resources/application.yaml index 160cae4a2..f47d1b7f3 100644 --- a/system/system-application/src/main/resources/application.yaml +++ b/system/system-application/src/main/resources/application.yaml @@ -19,4 +19,8 @@ qiniu: bucket: onemall swagger: - enable: false # 暂时不去掉 + enable: true # 暂时不去掉 + title: 管理员子系统 + description: 管理员子系统 + version: 1.0.0 + base-package: cn.iocoder.mall.admin.application.controller diff --git a/system/system-service-api/pom.xml b/system/system-service-api/pom.xml index 8fc8754ce..644cc079e 100644 --- a/system/system-service-api/pom.xml +++ b/system/system-service-api/pom.xml @@ -19,6 +19,12 @@ 1.0-SNAPSHOT + + + io.springfox + springfox-swagger2 + + org.mapstruct 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 462016d06..cce2eebc7 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 @@ -3,11 +3,11 @@ package cn.iocoder.mall.admin.api; import cn.iocoder.common.framework.constant.CommonStatusEnum; import cn.iocoder.common.framework.validator.InEnum; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.admin.api.bo.AdminBO; -import cn.iocoder.mall.admin.api.bo.AdminPageBO; -import cn.iocoder.mall.admin.api.dto.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.AdminPageDTO; -import cn.iocoder.mall.admin.api.dto.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; +import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; import java.util.Set; @@ -18,7 +18,7 @@ public interface AdminService { CommonResult getAdminPage(AdminPageDTO adminPageDTO); - CommonResult addAdmin(Integer adminId, AdminAddDTO adminAddDTO); + AdminBO addAdmin(Integer adminId, AdminAddDTO adminAddDTO); CommonResult updateAdmin(Integer adminId, AdminUpdateDTO adminUpdateDTO); diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminBO.java deleted file mode 100644 index c85823ed2..000000000 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminBO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.mall.admin.api.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * 管理员 BO - */ -@Data -@Accessors(chain = true) -public class AdminBO implements Serializable { - - /** - * 管理员编号 - */ - private Integer id; - /** - * 登陆账号 - */ - private String username; - /** - * 昵称 - */ - private String nickname; - /** - * 账号状态 - */ - private Integer status; - /** - * 创建时间 - */ - private Date createTime; - -} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java new file mode 100644 index 000000000..65673e18f --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.admin.api.bo.admin; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +@ApiModel("管理员 BO") +@Data +@Accessors(chain = true) +public class AdminBO implements Serializable { + + @ApiModelProperty(value = "管理员编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") + private String username; + + @ApiModelProperty(value = "昵称", required = true, example = "小王") + private String nickname; + + @ApiModelProperty(value = "账号状态", required = true, example = "1", dataType= "CommonStatusEnum") + private Integer status; + + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminPageBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminPageBO.java similarity index 89% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminPageBO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminPageBO.java index ad82042ae..a93a69e78 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/AdminPageBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminPageBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.bo; +package cn.iocoder.mall.admin.api.bo.admin; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java similarity index 67% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminAddDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java index 822fcb005..ee9e73648 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java @@ -1,5 +1,7 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.admin; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -8,29 +10,23 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Pattern; import java.io.Serializable; -/** - * 管理员添加 DTO - */ +@ApiModel("管理员添加 DTO") @Data @Accessors(chain = true) public class AdminAddDTO implements Serializable { - /** - * 登陆账号 - */ + @ApiModelProperty(value = "登陆账号", required = true, example = "15601691300") @NotEmpty(message = "登陆账号不能为空") @Length(min = 6, max = 16, message = "账号长度为 6-16 位") @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") private String username; - /** - * 昵称 - */ + + @ApiModelProperty(value = "昵称", required = true, example = "小王") @NotEmpty(message = "昵称不能为空") @Length(max = 10, message = "昵称长度最大为 10 位") private String nickname; - /** - * 密码 - */ + + @ApiModelProperty(value = "密码", required = true, example = "buzhidao") @NotEmpty(message = "密码不能为空") @Length(min = 6, max = 16, message = "密码长度为 6-16 位") private String password; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java similarity index 91% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java index 8a347793d..953ec6edb 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.admin; import lombok.Data; import lombok.experimental.Accessors; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java similarity index 66% rename from system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminUpdateDTO.java rename to system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java index 8399faeb3..13c6ccecc 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java @@ -1,5 +1,7 @@ -package cn.iocoder.mall.admin.api.dto; +package cn.iocoder.mall.admin.api.dto.admin; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -14,6 +16,12 @@ import java.io.Serializable; */ @Data @Accessors(chain = true) +@ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1"), + @ApiImplicitParam(name = "username", value = "账号", required = true, example = "15601691300"), + @ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"), + @ApiImplicitParam(name = "password", value = "密码", example = "buzhidao"), +}) public class AdminUpdateDTO implements Serializable { /** diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java index 0d68d1b89..fef005762 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/config/DatabaseConfiguration.java @@ -1,6 +1,9 @@ package cn.iocoder.mall.admin.config; +import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; +import com.baomidou.mybatisplus.core.injector.ISqlInjector; import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -11,4 +14,9 @@ public class DatabaseConfiguration { // 数据库连接池 Druid + @Bean + public ISqlInjector sqlInjector() { + return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除 + } + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java index b50774a63..ce27ed781 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/AdminConvert.java @@ -1,8 +1,8 @@ package cn.iocoder.mall.admin.convert; -import cn.iocoder.mall.admin.api.bo.AdminBO; -import cn.iocoder.mall.admin.api.dto.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; import cn.iocoder.mall.admin.dataobject.AdminDO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -27,4 +27,4 @@ public interface AdminConvert { @Mappings({}) List convert(List adminBOs); -} \ No newline at end of file +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java index 9c2c2b695..b8d04138c 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java @@ -1,17 +1,19 @@ package cn.iocoder.mall.admin.dao; import cn.iocoder.mall.admin.dataobject.AdminDO; +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; import java.util.List; @Repository -public interface AdminMapper { +public interface AdminMapper extends BaseMapper { - AdminDO selectById(@Param("id") Integer id); - - AdminDO selectByUsername(@Param("username") String username); + default AdminDO selectByUsername(@Param("username") String username) { + return selectOne(new QueryWrapper().eq("username", username)); + } List selectListByNicknameLike(@Param("nickname") String nickname, @Param("offset") Integer offset, @@ -19,8 +21,6 @@ public interface AdminMapper { Integer selectCountByNicknameLike(@Param("nickname") String nickname); - void insert(AdminDO admin); - int update(AdminDO admin); -} \ No newline at end of file +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java index 77a0231b3..08b030628 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java @@ -1,12 +1,14 @@ 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; /** * 管理员实体 */ +@TableName(value = "admin") @Data @Accessors(chain = true) public class AdminDO extends DeletableDO { diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java index f5c56fb4b..5ba6c61f7 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java @@ -5,13 +5,13 @@ import cn.iocoder.common.framework.constant.DeletedStatusEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.AdminService; -import cn.iocoder.mall.admin.api.bo.AdminBO; -import cn.iocoder.mall.admin.api.bo.AdminPageBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminBO; +import cn.iocoder.mall.admin.api.bo.admin.AdminPageBO; import cn.iocoder.mall.admin.api.constant.AdminConstants; import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; -import cn.iocoder.mall.admin.api.dto.AdminAddDTO; -import cn.iocoder.mall.admin.api.dto.AdminPageDTO; -import cn.iocoder.mall.admin.api.dto.AdminUpdateDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminAddDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminPageDTO; +import cn.iocoder.mall.admin.api.dto.admin.AdminUpdateDTO; import cn.iocoder.mall.admin.convert.AdminConvert; import cn.iocoder.mall.admin.dao.AdminMapper; import cn.iocoder.mall.admin.dao.AdminRoleMapper; @@ -79,10 +79,10 @@ public class AdminServiceImpl implements AdminService { } @Override - public CommonResult addAdmin(Integer adminId, AdminAddDTO adminAddDTO) { + public AdminBO addAdmin(Integer adminId, AdminAddDTO adminAddDTO) { // 校验账号唯一 if (adminMapper.selectByUsername(adminAddDTO.getUsername()) != null) { - return ServiceExceptionUtil.error(AdminErrorCodeEnum.ADMIN_USERNAME_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_EXISTS.getCode()); } // 保存到数据库 AdminDO admin = AdminConvert.INSTANCE.convert(adminAddDTO) @@ -93,7 +93,7 @@ public class AdminServiceImpl implements AdminService { adminMapper.insert(admin); // TODO 插入操作日志 // 返回成功 - return CommonResult.success(AdminConvert.INSTANCE.convert(admin)); + return AdminConvert.INSTANCE.convert(admin); } @Override 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 2cf22d7ee..0bb439c57 100644 --- a/system/system-service-impl/src/main/resources/config/application.yaml +++ b/system/system-service-impl/src/main/resources/config/application.yaml @@ -19,6 +19,8 @@ mybatis-plus: global-config: db-config: id-type: auto + logic-delete-value: 1 # 逻辑已删除值(默认为 1) + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) mapper-locations: classpath*:mapper/*.xml type-aliases-package: cn.iocoder.mall.admin.dataobject diff --git a/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml b/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml index 6a4ecbc7d..13272d4be 100644 --- a/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml +++ b/system/system-service-impl/src/main/resources/mapper/AdminMapper.xml @@ -7,14 +7,6 @@ create_time - - - - INSERT INTO admin ( - username, nickname, password, status, - create_time, deleted - ) VALUES ( - #{username}, #{nickname}, #{password}, #{status}, - #{createTime}, #{deleted} - ) - -