From 568e0da097ea94d97ba09f6f252845640884da1f Mon Sep 17 00:00:00 2001 From: lijiaqi Date: Mon, 15 Aug 2022 13:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E7=BB=8F=E6=B7=BB=E5=8A=A0=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiAddUserLogController.java | 58 +++++++++++++++++++ .../boot/modules/rddb/entity/AddUserLog.java | 58 +++++++++++++++++++ .../boot/modules/rddb/gen/MyGenerator.java | 4 +- .../modules/rddb/mapper/AddUserLogMapper.java | 16 +++++ .../rddb/mapper/xml/AddUserLogMapper.xml | 5 ++ .../rddb/service/AddUserLogService.java | 49 ++++++++++++++++ .../service/inter/IAddUserLogService.java | 16 +++++ .../rddb/web/AddUserLogController.java | 21 +++++++ 8 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/ydool/boot/api/controller/ApiAddUserLogController.java create mode 100644 src/main/java/com/ydool/boot/modules/rddb/entity/AddUserLog.java create mode 100644 src/main/java/com/ydool/boot/modules/rddb/mapper/AddUserLogMapper.java create mode 100644 src/main/java/com/ydool/boot/modules/rddb/mapper/xml/AddUserLogMapper.xml create mode 100644 src/main/java/com/ydool/boot/modules/rddb/service/AddUserLogService.java create mode 100644 src/main/java/com/ydool/boot/modules/rddb/service/inter/IAddUserLogService.java create mode 100644 src/main/java/com/ydool/boot/modules/rddb/web/AddUserLogController.java diff --git a/src/main/java/com/ydool/boot/api/controller/ApiAddUserLogController.java b/src/main/java/com/ydool/boot/api/controller/ApiAddUserLogController.java new file mode 100644 index 0000000..f45514f --- /dev/null +++ b/src/main/java/com/ydool/boot/api/controller/ApiAddUserLogController.java @@ -0,0 +1,58 @@ +package com.ydool.boot.api.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.github.xiaoymin.knife4j.annotations.DynamicParameter; +import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters; +import com.ydool.boot.common.result.Ret; +import com.ydool.boot.modules.rddb.entity.AddUserLog; +import com.ydool.boot.modules.rddb.entity.AuditUser; +import com.ydool.boot.modules.rddb.service.AddUserLogService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.List; + +@Controller +@RequestMapping("/api/addUser") +@Api(value = "最近添加人", tags = "最近添加人") +public class ApiAddUserLogController extends ApiBaseController { + @Autowired + private AddUserLogService addUserLogService; + + @ApiOperation("最近添加人列表") + @GetMapping("") + @ResponseBody + @ApiImplicitParams({ + @ApiImplicitParam(name = "type", value = "类型(zjspr:最近审批人)", required = true), + }) + @DynamicResponseParameters(properties = { + @DynamicParameter(name = "data", value = "最近添加人", dataTypeClass = AddUserLog.class) + }) + public void addUserList(String type) { + //当前用户ID + String userId = getApiUserId(); + List addUserLogList = addUserLogService.list(new LambdaQueryWrapper().eq(AddUserLog::getType, type).eq(AddUserLog::getCreatedId, userId)); + render(Ret.ok().data(addUserLogList)); + } + + @ApiOperation("最近添加人保存") + @GetMapping("/save") + @ResponseBody + @ApiImplicitParams({ + @ApiImplicitParam(name = "addUserIds", value = "最近添加人ID,多个以英文逗号间隔", required = true), + @ApiImplicitParam(name = "addUserNames", value = "最近添加人姓名,多个以英文逗号间隔", required = true), + @ApiImplicitParam(name = "type", value = "类型(zjspr:最近审批人)", required = true), + }) + public void insertAddUser(String addUserIds, String addUserNames, String type) { + String userId = getApiUserId(); + boolean flag = addUserLogService.saveOrUpdate(addUserIds, addUserNames, type, userId); + render(!flag ? Ret.fail("操作失败") : Ret.ok()); + } +} diff --git a/src/main/java/com/ydool/boot/modules/rddb/entity/AddUserLog.java b/src/main/java/com/ydool/boot/modules/rddb/entity/AddUserLog.java new file mode 100644 index 0000000..be6e443 --- /dev/null +++ b/src/main/java/com/ydool/boot/modules/rddb/entity/AddUserLog.java @@ -0,0 +1,58 @@ +package com.ydool.boot.modules.rddb.entity; +import com.baomidou.mybatisplus.annotation.TableName; +import com.ydool.boot.core.entity.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; + +/** + *

+ * 最近添加人 + *

+ * + * @author zhouyuan + * @since 2022-08-15 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("t_add_user_log") +@ApiModel(value = "最近添加人") +public class AddUserLog extends BaseEntity{ + + private static final long serialVersionUID = 1L; + + /** + * 创建者 + */ + private String createdId; + + /** + * 更新者 + */ + private String updatedId; + + /** + * 最经添加人id + */ + @ApiModelProperty(value = "最经添加人id") + @NotBlank(message = "最经添加人id不能为空") + private String addUserId; + + /** + * 最近添加人姓名 + */ + @ApiModelProperty(value = "最近添加人姓名") + @NotBlank(message = "最近添加人姓名不能为空") + private String addUserName; + + /** + * 类型(zjspr:最近审批人) + */ + @ApiModelProperty(value = "类型(zjspr:最近审批人)") + @NotBlank(message = "类型不能为空") + private String type; + +} diff --git a/src/main/java/com/ydool/boot/modules/rddb/gen/MyGenerator.java b/src/main/java/com/ydool/boot/modules/rddb/gen/MyGenerator.java index d231740..5b2f9ec 100644 --- a/src/main/java/com/ydool/boot/modules/rddb/gen/MyGenerator.java +++ b/src/main/java/com/ydool/boot/modules/rddb/gen/MyGenerator.java @@ -20,7 +20,7 @@ public class MyGenerator { public static void main(String[] args) { //表名 - String tableName = "t_rd_notice_attachment"; + String tableName = "t_add_user_log"; //表前缀 String tablePrefix = "t_"; @@ -47,7 +47,7 @@ public class MyGenerator { dsc.setUrl("jdbc:mysql://127.0.0.1:3306/ydool_rd?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8"); dsc.setDriverName("com.mysql.cj.jdbc.Driver"); dsc.setUsername("root"); - dsc.setPassword("123456"); + dsc.setPassword("Wang09211108"); dsc.setDbType(DbType.MYSQL); mpg.setDataSource(dsc); diff --git a/src/main/java/com/ydool/boot/modules/rddb/mapper/AddUserLogMapper.java b/src/main/java/com/ydool/boot/modules/rddb/mapper/AddUserLogMapper.java new file mode 100644 index 0000000..7675e12 --- /dev/null +++ b/src/main/java/com/ydool/boot/modules/rddb/mapper/AddUserLogMapper.java @@ -0,0 +1,16 @@ +package com.ydool.boot.modules.rddb.mapper; + +import com.ydool.boot.modules.rddb.entity.AddUserLog; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 最近添加人 Mapper 接口 + *

+ * + * @author zhouyuan + * @since 2022-08-15 + */ +public interface AddUserLogMapper extends BaseMapper { + +} diff --git a/src/main/java/com/ydool/boot/modules/rddb/mapper/xml/AddUserLogMapper.xml b/src/main/java/com/ydool/boot/modules/rddb/mapper/xml/AddUserLogMapper.xml new file mode 100644 index 0000000..b48c74f --- /dev/null +++ b/src/main/java/com/ydool/boot/modules/rddb/mapper/xml/AddUserLogMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/ydool/boot/modules/rddb/service/AddUserLogService.java b/src/main/java/com/ydool/boot/modules/rddb/service/AddUserLogService.java new file mode 100644 index 0000000..454eb30 --- /dev/null +++ b/src/main/java/com/ydool/boot/modules/rddb/service/AddUserLogService.java @@ -0,0 +1,49 @@ +package com.ydool.boot.modules.rddb.service; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ydool.boot.modules.rddb.entity.AddUserLog; +import com.ydool.boot.modules.rddb.mapper.AddUserLogMapper; +import com.ydool.boot.modules.rddb.service.inter.IAddUserLogService; +import com.ydool.boot.core.service.BaseService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + *

+ * 最近添加人 服务实现类 + *

+ * + * @author zhouyuan + * @since 2022-08-15 + */ +@Service +public class AddUserLogService extends BaseService { + + @Transactional + public boolean saveOrUpdate(String addUserIds, String addUserNames, String type, String userId) { + boolean flag; + List addUserLogList = new ArrayList<>(); + + remove(new LambdaQueryWrapper().eq(AddUserLog::getCreatedId, userId)); + String[] addUserIdArr = addUserIds.split(","); + String[] addUserNameArr = addUserNames.split(","); + for (int i = 0; i < addUserNameArr.length; i++) { + AddUserLog addUserLog = new AddUserLog(); + addUserLog.setAddUserId(addUserIdArr[i]); + addUserLog.setAddUserName(addUserNameArr[i]); + addUserLog.setCreatedId(userId); + addUserLog.setType(type); + addUserLog.setUpdatedId(userId); + addUserLog.setCreatedAt(LocalDateTime.now()); + addUserLog.setUpdatedAt(LocalDateTime.now()); + addUserLogList.add(addUserLog); + } + flag = this.saveBatch(addUserLogList); + return flag; + } +} diff --git a/src/main/java/com/ydool/boot/modules/rddb/service/inter/IAddUserLogService.java b/src/main/java/com/ydool/boot/modules/rddb/service/inter/IAddUserLogService.java new file mode 100644 index 0000000..8bf3efc --- /dev/null +++ b/src/main/java/com/ydool/boot/modules/rddb/service/inter/IAddUserLogService.java @@ -0,0 +1,16 @@ +package com.ydool.boot.modules.rddb.service.inter; + +import com.ydool.boot.modules.rddb.entity.AddUserLog; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 最近添加人 服务类 + *

+ * + * @author zhouyuan + * @since 2022-08-15 + */ +public interface IAddUserLogService extends IService { + +} diff --git a/src/main/java/com/ydool/boot/modules/rddb/web/AddUserLogController.java b/src/main/java/com/ydool/boot/modules/rddb/web/AddUserLogController.java new file mode 100644 index 0000000..ee1bc3c --- /dev/null +++ b/src/main/java/com/ydool/boot/modules/rddb/web/AddUserLogController.java @@ -0,0 +1,21 @@ +package com.ydool.boot.modules.rddb.web; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.stereotype.Controller; +import com.ydool.boot.core.web.BaseController; + +/** + *

+ * 最近添加人 前端控制器 + *

+ * + * @author zhouyuan + * @since 2022-08-15 + */ +@Controller +@RequestMapping("${ydool.path}/rddb/addUserLog") +public class AddUserLogController extends BaseController { + +}