From 3e8480c3907113969e403fda5bc692c07a83b291 Mon Sep 17 00:00:00 2001 From: PQZ Date: Thu, 16 Jan 2025 21:44:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E7=BB=83=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/DlDriveSchoolCoachController.java | 29 +++--- .../base/entity/DlDriveSchoolCoach.java | 2 +- .../base/mapper/DlDriveSchoolCoachMapper.java | 1 - .../service/DlDriveSchoolCoachService.java | 22 ++--- .../impl/DlDriveSchoolCoachServiceImpl.java | 95 +++++++++++++++---- 5 files changed, 105 insertions(+), 44 deletions(-) diff --git a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/controller/admin/DlDriveSchoolCoachController.java b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/controller/admin/DlDriveSchoolCoachController.java index 8db4bae1..b80c0fa8 100644 --- a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/controller/admin/DlDriveSchoolCoachController.java +++ b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/controller/admin/DlDriveSchoolCoachController.java @@ -12,7 +12,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -50,7 +49,7 @@ public class DlDriveSchoolCoachController { } /** - * 新增驾校教练 + * 保存驾校教练 * * @param createReqVO {@link DlDriveSchoolCoachSaveReqVO} * @return cn.iocoder.yudao.framework.common.pojo.CommonResult @@ -59,18 +58,19 @@ public class DlDriveSchoolCoachController { **/ @PostMapping("/create") @Operation(summary = "创建驾校教练") - public CommonResult createDlDriveSchoolCoach(@Valid @RequestBody DlDriveSchoolCoachSaveReqVO createReqVO) { - dlDriveSchoolCoachService.createDlDriveSchoolCoach(createReqVO); - return success(true); - } - - @PutMapping("/update") - @Operation(summary = "更新驾校教练") - public CommonResult updateDlDriveSchoolCoach(@Valid @RequestBody DlDriveSchoolCoachSaveReqVO updateReqVO) { - dlDriveSchoolCoachService.updateDlDriveSchoolCoach(updateReqVO); + public CommonResult saveSchoolCoach(@Valid @RequestBody DlDriveSchoolCoachSaveReqVO createReqVO) { + dlDriveSchoolCoachService.saveSchoolCoach(createReqVO); return success(true); } + /** + * 通过id删除驾校教练 + * + * @param id 教练id + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + * @author PQZ + * @date 21:40 2025/1/16 + **/ @DeleteMapping("/delete") @Operation(summary = "删除驾校教练") @Parameter(name = "id", description = "编号", required = true) @@ -79,6 +79,13 @@ public class DlDriveSchoolCoachController { return success(true); } + /** + * 通过教练id获取驾校教练 + * @author PQZ + * @date 21:41 2025/1/16 + * @param id 教练id + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + **/ @GetMapping("/get") @Operation(summary = "获得驾校教练") @Parameter(name = "id", description = "编号", required = true, example = "1024") diff --git a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/entity/DlDriveSchoolCoach.java b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/entity/DlDriveSchoolCoach.java index 63cdfe3a..0175136d 100644 --- a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/entity/DlDriveSchoolCoach.java +++ b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/entity/DlDriveSchoolCoach.java @@ -77,7 +77,7 @@ public class DlDriveSchoolCoach extends TenantBaseDO { /** * 用户id */ - private Integer userId; + private Long userId; /** * 身份证 */ diff --git a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/mapper/DlDriveSchoolCoachMapper.java b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/mapper/DlDriveSchoolCoachMapper.java index 124b8cbf..06595b84 100644 --- a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/mapper/DlDriveSchoolCoachMapper.java +++ b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/mapper/DlDriveSchoolCoachMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.base.mapper; import cn.iocoder.yudao.module.base.entity.DlDriveSchoolCoach; import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachPageReqVO; import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachRespVO; -import cn.iocoder.yudao.module.member.vo.MemberLevelRespVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; diff --git a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/DlDriveSchoolCoachService.java b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/DlDriveSchoolCoachService.java index ed2a318e..983d61c7 100644 --- a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/DlDriveSchoolCoachService.java +++ b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/DlDriveSchoolCoachService.java @@ -29,26 +29,20 @@ public interface DlDriveSchoolCoachService extends IService IPage queryListPage(DlDriveSchoolCoachPageReqVO pageReqVO, Page page); /** - * 创建驾校教练 + * 保存驾校教练 * * @param createReqVO {@link DlDriveSchoolCoachSaveReqVO} - * @author PQZ - * @date 2025/1/16 + * @author PQZ @date 2025/1/16 **/ - void createDlDriveSchoolCoach(@Valid DlDriveSchoolCoachSaveReqVO createReqVO); - - /** - * 更新驾校教练 - * - * @param updateReqVO 更新信息 - */ - void updateDlDriveSchoolCoach(@Valid DlDriveSchoolCoachSaveReqVO updateReqVO); + void saveSchoolCoach(@Valid DlDriveSchoolCoachSaveReqVO createReqVO); /** * 删除驾校教练 * - * @param id 编号 - */ + * @param id 教练id + * @author PQZ + * @date 21:39 2025/1/16 + **/ void deleteDlDriveSchoolCoach(String id); /** @@ -57,7 +51,7 @@ public interface DlDriveSchoolCoachService extends IService * @param id 编号 * @return 驾校教练 */ - DlDriveSchoolCoach getDlDriveSchoolCoach(String id); + DlDriveSchoolCoachRespVO getDlDriveSchoolCoach(String id); } \ No newline at end of file diff --git a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/impl/DlDriveSchoolCoachServiceImpl.java b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/impl/DlDriveSchoolCoachServiceImpl.java index e748884b..1e8a9462 100644 --- a/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/impl/DlDriveSchoolCoachServiceImpl.java +++ b/dl-module-jx/src/main/java/cn/iocoder/yudao/module/base/service/impl/DlDriveSchoolCoachServiceImpl.java @@ -7,13 +7,24 @@ import cn.iocoder.yudao.module.base.service.DlDriveSchoolCoachService; import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachPageReqVO; import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachRespVO; import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachSaveReqVO; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.HashSet; +import java.util.Set; + +import static cn.iocoder.yudao.common.BaseConstants.PASSWORD_DEFAULT; +import static cn.iocoder.yudao.framework.common.config.CommonStr.USER_TYPE_STAFF; /** * 驾校教练 Service 实现类 @@ -26,6 +37,11 @@ public class DlDriveSchoolCoachServiceImpl extends ServiceImpl queryListPage(DlDriveSchoolCoachPageReqVO pageReqVO, Page page) { - return dlDriveSchoolCoachMapper.queryListPage(pageReqVO,page); + return dlDriveSchoolCoachMapper.queryListPage(pageReqVO, page); } + /** + * 保存驾校教练 + * + * @param createReqVO {@link DlDriveSchoolCoachSaveReqVO} + * @author PQZ + * @date 21:07 2025/1/16 + **/ @Override - public void createDlDriveSchoolCoach(DlDriveSchoolCoachSaveReqVO createReqVO) { - // 插入 + @Transactional(rollbackFor = Exception.class) + public void saveSchoolCoach(DlDriveSchoolCoachSaveReqVO createReqVO) { + /*1、数据类型转换*/ DlDriveSchoolCoach dlDriveSchoolCoach = BeanUtils.toBean(createReqVO, DlDriveSchoolCoach.class); - dlDriveSchoolCoachMapper.insert(dlDriveSchoolCoach); - - } - - @Override - public void updateDlDriveSchoolCoach(DlDriveSchoolCoachSaveReqVO updateReqVO) { - // 校验存在 - DlDriveSchoolCoach updateObj = BeanUtils.toBean(updateReqVO, DlDriveSchoolCoach.class); - dlDriveSchoolCoachMapper.updateById(updateObj); + if (null == createReqVO.getUserId()) { + /*2、新增教练或编辑教练无用户id时,同时插入一条用户数据*/ + //通过手机号查询用户 + AdminUserRespDTO userDTO = adminUserApi.getUserByUsername(createReqVO.getPhone()); + Long userId; + //存在两种情况,1、用户存在,2、用户不存在 + if (null == userDTO) { + UserDTO user = new UserDTO(); + //如果不存在创建用户; + user.setUsername(createReqVO.getPhone()); + user.setNickname(createReqVO.getName()); + //默认密码 + user.setPassword(PASSWORD_DEFAULT); + user.setMobile(createReqVO.getPhone()); + //用户类型员工 + user.setUserType(USER_TYPE_STAFF); + //创建客户 + userId = adminUserApi.createUser(user); + //创建客户后为客户绑定角色 + Set roleCodes = new HashSet<>(); + // TODO: 2025/1/16 枚举值问老马(保存角色方法不对) + permissionApi.assignUserRole(userId, roleCodes); + } else { + userId = userDTO.getId(); + } + dlDriveSchoolCoach.setUserId(userId); + } + /*3、保存教练信息*/ + saveOrUpdate(dlDriveSchoolCoach); } + /** + * 删除驾校教练 + * + * @param id 教练id + * @author PQZ + * @date 21:39 2025/1/16 + **/ @Override public void deleteDlDriveSchoolCoach(String id) { - // 删除 - dlDriveSchoolCoachMapper.deleteById(id); + removeById(id); } - + /** + * 通过id查询教练信息 + * + * @param id 教练id + * @return cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachRespVO + * @author PQZ + * @date 21:43 2025/1/16 + **/ @Override - public DlDriveSchoolCoach getDlDriveSchoolCoach(String id) { - return dlDriveSchoolCoachMapper.selectById(id); + public DlDriveSchoolCoachRespVO getDlDriveSchoolCoach(String id) { + //通过id查询教练信息 + DlDriveSchoolCoach schoolCoach = getById(id); + //数据类型转换 + DlDriveSchoolCoachRespVO result = BeanUtils.toBean(schoolCoach, DlDriveSchoolCoachRespVO.class); + return result; }