From ca489012f5801c66ed677a82c607b758c3e1d511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B9=85=E5=93=A5?= <787952492@qq.com> Date: Tue, 14 Jun 2022 11:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=9C=E5=9C=BA=E6=97=A5=E5=BF=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/user/AdminUserService.java | 6 + .../service/user/AdminUserServiceImpl.java | 21 +++ zsw-farm/zsw-farm-api/pom.xml | 16 ++ .../module/farm/enums/ErrorCodeConstants.java | 5 +- .../yudao/module/farm/annotation/FarmMsg.java | 17 +++ .../module/farm/annotation/FarmMsgAspect.java | 76 ++++++++++ .../admin/logMsg/LogMsgController.java | 112 ++++++++++++++ .../admin/logMsg/dto/LogMsgDTO.java | 15 ++ .../admin/logMsg/vo/LogMsgBaseVO.java | 24 +++ .../admin/logMsg/vo/LogMsgCreateReqVO.java | 14 ++ .../admin/logMsg/vo/LogMsgExcelVO.java | 32 ++++ .../admin/logMsg/vo/LogMsgExportReqVO.java | 32 ++++ .../admin/logMsg/vo/LogMsgPageReqVO.java | 34 +++++ .../admin/logMsg/vo/LogMsgRespVO.java | 19 +++ .../admin/logMsg/vo/LogMsgUpdateReqVO.java | 18 +++ .../admin/project/ProjectController.java | 4 + .../controller/admin/task/TaskController.java | 4 + .../farm/convert/logMsg/LogMsgConvert.java | 34 +++++ .../farm/dal/dataobject/logMsg/LogMsgDO.java | 40 +++++ .../farm/dal/mysql/logMsg/LogMsgMapper.java | 38 +++++ .../farm/service/logMsg/LogMsgService.java | 79 ++++++++++ .../service/logMsg/LogMsgServiceImpl.java | 137 ++++++++++++++++++ .../resources/mapper/logMsg/LogMsgMapper.xml | 12 ++ 23 files changed, 788 insertions(+), 1 deletion(-) create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/LogMsgController.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/dto/LogMsgDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgCreateReqVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgRespVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgUpdateReqVO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/logMsg/LogMsgConvert.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/logMsg/LogMsgMapper.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgService.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgServiceImpl.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/resources/mapper/logMsg/LogMsgMapper.xml diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java index 78d6a88a..da18619c 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfi import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import javax.validation.Valid; @@ -200,4 +201,9 @@ public interface AdminUserService { */ List getUsersByStatus(Integer status); + /** + * 根据系统用户id获取cpUser用户 + **/ + List getCpUserByAdminUser(List adminUserIdList); + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 2d8b0aa8..6afbb027 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.service.user; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.ServiceException; @@ -12,13 +13,16 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfi import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.*; import cn.iocoder.yudao.module.system.convert.user.UserConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; import cn.iocoder.yudao.module.system.service.dept.DeptService; import cn.iocoder.yudao.module.system.service.dept.PostService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.tenant.TenantService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -29,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.InputStream; import java.util.*; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; @@ -61,6 +66,8 @@ public class AdminUserServiceImpl implements AdminUserService { @Resource private FileApi fileApi; + @Resource + private CpUserMapper cpUserMapper; @Override @@ -398,4 +405,18 @@ public class AdminUserServiceImpl implements AdminUserService { return adminUserMapper.selectListByStatus(status); } + + public List getCpUserByAdminUser(List adminUserIdList){ + List adminUserList = adminUserMapper.selectList(Wrappers.lambdaQuery().in(AdminUserDO::getId, adminUserIdList)); + if (ObjectUtil.isEmpty(adminUserList)){ + return new ArrayList<>(); + } + List usernameList = adminUserList.stream().map(AdminUserDO::getUsername).collect(Collectors.toList()); + List cpUserList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getUserId, usernameList)); + if (ObjectUtil.isEmpty(cpUserList)){ + return new ArrayList<>(); + } + return cpUserList; + } + } diff --git a/zsw-farm/zsw-farm-api/pom.xml b/zsw-farm/zsw-farm-api/pom.xml index 036729aa..48825903 100644 --- a/zsw-farm/zsw-farm-api/pom.xml +++ b/zsw-farm/zsw-farm-api/pom.xml @@ -27,6 +27,22 @@ cn.iocoder.boot yudao-spring-boot-starter-mybatis + + + org.aspectj + aspectjweaver + + + aopalliance + aopalliance + 1.0 + compile + + + org.aspectj + aspectjrt + 1.9.5 + diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java index 85086014..7b6d010c 100644 --- a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java +++ b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java @@ -24,7 +24,10 @@ public interface ErrorCodeConstants{ ErrorCode CROP_RECORD_NOT_EXISTS = new ErrorCode(1000007009, "农场作物出入记录不存在"); ErrorCode WORK_HOUR_NOT_EXISTS = new ErrorCode(1000007010, "工时不存在"); - ErrorCode TASK_CATE_NOT_EXISTS = new ErrorCode(1000007010, "任务类型不存在"); + ErrorCode TASK_CATE_NOT_EXISTS = new ErrorCode(1000007011, "任务类型不存在"); + + + ErrorCode LOG_MSG_NOT_EXISTS = new ErrorCode(1000007012, "农场日志信息不存在"); } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java new file mode 100644 index 00000000..85c0d3fa --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.farm.annotation; + +import java.lang.annotation.*; + +/** + * @Created by jiu on 2022/6/13. + */ + +@Target({ElementType.METHOD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface FarmMsg { + + String type() default ""; + + String title() default ""; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java new file mode 100644 index 00000000..223160dd --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java @@ -0,0 +1,76 @@ +package cn.iocoder.yudao.module.farm.annotation; + +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import cn.iocoder.yudao.module.farm.dal.mysql.logMsg.LogMsgMapper; +import cn.iocoder.yudao.module.farm.service.logMsg.LogMsgService; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; + +/** + * @Created by jiu on 2022/6/13. + */ +@Aspect +@Component +@Slf4j +public class FarmMsgAspect { + + @Resource + private LogMsgMapper logMsgMapper; + + + /** + * 定义切入点 @PointCut + * 使用了@FarmMsg注解的地方切入 + * + **/ + @Pointcut("@annotation(cn.iocoder.yudao.module.farm.annotation.FarmMsg)") + public void farmMsgPointCut(){ + + } + + /** + * 拦截用户操作日志, 连接点执行完成后记录, 如果连接点异常,则不会执行 + * @param jointPoint 切入点 + * @param result 返回结果 + **/ + @AfterReturning(value = "farmMsgPointCut()", returning = "result") + public void saveFarmMsg(JoinPoint jointPoint, Object result){ + + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST); + + //从切入点通过反射获取切入点方法 + MethodSignature signature = (MethodSignature) jointPoint.getSignature(); + + //获取切入点的方法 + Method method = signature.getMethod(); + + //获取操作的type, title + FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); + + //插入农场日志信息 + LogMsgDO msg = LogMsgDO.builder() + .type(farmMsg.type()) + .title(farmMsg.title()) + .userId(getLoginUserId()) + .build(); + logMsgMapper.insert(msg); + } +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/LogMsgController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/LogMsgController.java new file mode 100644 index 00000000..91e2ea14 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/LogMsgController.java @@ -0,0 +1,112 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg; + +import cn.iocoder.yudao.framework.common.page.PageDTO; +import cn.iocoder.yudao.framework.common.page.PageVO; +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.dto.LogMsgDTO; +import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.WorkStaticDTO; +import cn.iocoder.yudao.module.farm.controller.admin.workHour.dto.WorkTotalDTO; +import com.zsw.base.R; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.annotations.*; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import cn.iocoder.yudao.module.farm.convert.logMsg.LogMsgConvert; +import cn.iocoder.yudao.module.farm.service.logMsg.LogMsgService; + +@Api(tags = "管理后台 - 农场日志信息") +@RestController +@RequestMapping("/farm/log-msg") +@Validated +public class LogMsgController { + + @Resource + private LogMsgService logMsgService; + + @PostMapping("/create") + @ApiOperation("创建") + @PreAuthorize("@ss.hasPermission('farm:log-msg:create')") + public CommonResult createLogMsg(@Valid @RequestBody LogMsgCreateReqVO createReqVO) { + return success(logMsgService.createLogMsg(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新") + @PreAuthorize("@ss.hasPermission('farm:log-msg:update')") + public CommonResult updateLogMsg(@Valid @RequestBody LogMsgUpdateReqVO updateReqVO) { + logMsgService.updateLogMsg(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('farm:log-msg:delete')") + public CommonResult deleteLogMsg(@RequestParam("id") Long id) { + logMsgService.deleteLogMsg(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('farm:log-msg:query')") + public CommonResult getLogMsg(@RequestParam("id") Long id) { + LogMsgDO logMsg = logMsgService.getLogMsg(id); + return success(LogMsgConvert.INSTANCE.convert(logMsg)); + } + + @GetMapping("/list") + @ApiOperation("获得列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('farm:log-msg:query')") + public CommonResult> getLogMsgList(@RequestParam("ids") Collection ids) { + List list = logMsgService.getLogMsgList(ids); + return success(LogMsgConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得分页") + @PreAuthorize("@ss.hasPermission('farm:log-msg:query')") + public CommonResult> getLogMsgPage(@Valid LogMsgPageReqVO pageVO) { + PageResult pageResult = logMsgService.getLogMsgPage(pageVO); + return success(LogMsgConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出 Excel") + @PreAuthorize("@ss.hasPermission('farm:log-msg:export')") + @OperateLog(type = EXPORT) + public void exportLogMsgExcel(@Valid LogMsgExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = logMsgService.getLogMsgList(exportReqVO); + // 导出 Excel + List datas = LogMsgConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, ".xls", "数据", LogMsgExcelVO.class, datas); + } + + + @PostMapping("/logMsgList") + @ApiOperation("农场日志信息") + public R> logMsgList(@RequestBody PageDTO pageDTO){ + return logMsgService.logMsgList(pageDTO); + } +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/dto/LogMsgDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/dto/LogMsgDTO.java new file mode 100644 index 00000000..1dbdfba4 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/dto/LogMsgDTO.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.dto; + +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import lombok.Data; + +/** + * @Created by jiu on 2022/6/14. + */ +@Data +public class LogMsgDTO extends LogMsgDO { + + private String userName; + + private String userIcon; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java new file mode 100644 index 00000000..638071e5 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +/** +* Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class LogMsgBaseVO { + + @ApiModelProperty(value = "类型") + private String type; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "用户id") + private Long userId; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgCreateReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgCreateReqVO.java new file mode 100644 index 00000000..4ba070f0 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class LogMsgCreateReqVO extends LogMsgBaseVO { + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java new file mode 100644 index 00000000..10ff1d12 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * Excel VO + * + * @author 尚筱璇 + */ +@Data +public class LogMsgExcelVO { + + @ExcelProperty("") + private Long id; + + @ExcelProperty("类型") + private String type; + + @ExcelProperty("标题") + private String title; + + @ExcelProperty("用户id") + private Long userId; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java new file mode 100644 index 00000000..e4ae8592 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - Excel 导出 Request VO", description = "参数和 LogMsgPageReqVO 是一致的") +@Data +public class LogMsgExportReqVO { + + @ApiModelProperty(value = "类型") + private String type; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "用户id") + private Long userId; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java new file mode 100644 index 00000000..f6637df1 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class LogMsgPageReqVO extends PageParam { + + @ApiModelProperty(value = "类型") + private String type; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "用户id") + private Long userId; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgRespVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgRespVO.java new file mode 100644 index 00000000..4e032cc4 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class LogMsgRespVO extends LogMsgBaseVO { + + @ApiModelProperty(value = "", required = true) + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgUpdateReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgUpdateReqVO.java new file mode 100644 index 00000000..7c0621e7 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class LogMsgUpdateReqVO extends LogMsgBaseVO { + + @ApiModelProperty(value = "", required = true) + @NotNull(message = "不能为空") + private Long id; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java index 5fc973bb..b5225b71 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.project; import cn.iocoder.yudao.framework.common.page.PageVO; +import cn.iocoder.yudao.module.farm.annotation.FarmMsg; import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO; import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO; import com.zsw.base.R; @@ -38,6 +39,7 @@ public class ProjectController { @Resource private ProjectService projectService; + @FarmMsg(type = "项目", title = "创建项目") @PostMapping("/create") @ApiOperation("创建农场项目") @PreAuthorize("@ss.hasPermission('farm:project:create')") @@ -45,6 +47,7 @@ public class ProjectController { return success(projectService.createProject(createReqVO)); } + @FarmMsg(type = "项目", title = "更新项目") @PutMapping("/update") @ApiOperation("更新农场项目") @PreAuthorize("@ss.hasPermission('farm:project:update')") @@ -62,6 +65,7 @@ public class ProjectController { return success(true); } + @FarmMsg(type = "项目", title = "查看项目#{id}") @GetMapping("/get") @ApiOperation("获得农场项目") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java index ec87d888..37cbe4c8 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.farm.controller.admin.task; +import cn.iocoder.yudao.module.farm.annotation.FarmMsg; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -35,6 +36,7 @@ public class TaskController { @Resource private TaskService taskService; + @FarmMsg(type = "任务", title = "创建任务") @PostMapping("/create") @ApiOperation("创建农场项目") @PreAuthorize("@ss.hasPermission('farm:task:create')") @@ -42,6 +44,7 @@ public class TaskController { return success(taskService.createTask(createReqVO)); } + @FarmMsg(type = "任务", title = "更新任务") @PutMapping("/update") @ApiOperation("更新农场项目") @PreAuthorize("@ss.hasPermission('farm:task:update')") @@ -59,6 +62,7 @@ public class TaskController { return success(true); } + @FarmMsg(type = "任务", title = "查看任务") @GetMapping("/get") @ApiOperation("获得农场项目") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/logMsg/LogMsgConvert.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/logMsg/LogMsgConvert.java new file mode 100644 index 00000000..6b49ddc3 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/convert/logMsg/LogMsgConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.farm.convert.logMsg; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; + +/** + * Convert + * + * @author 尚筱璇 + */ +@Mapper +public interface LogMsgConvert { + + LogMsgConvert INSTANCE = Mappers.getMapper(LogMsgConvert.class); + + LogMsgDO convert(LogMsgCreateReqVO bean); + + LogMsgDO convert(LogMsgUpdateReqVO bean); + + LogMsgRespVO convert(LogMsgDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java new file mode 100644 index 00000000..e390a64c --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.farm.dal.dataobject.logMsg; + +import lombok.*; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * DO + * + * @author 尚筱璇 + */ +@TableName("farm_log_msg") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class LogMsgDO extends BaseDO { + + /** + * + */ + @TableId + private Long id; + /** + * 类型 + */ + private String type; + /** + * 标题 + */ + private String title; + /** + * 用户id + */ + private Long userId; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/logMsg/LogMsgMapper.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/logMsg/LogMsgMapper.java new file mode 100644 index 00000000..9a1ccc9d --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/logMsg/LogMsgMapper.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.farm.dal.mysql.logMsg; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.*; + +/** + * Mapper + * + * @author 尚筱璇 + */ +@Mapper +public interface LogMsgMapper extends BaseMapperX { + + default PageResult selectPage(LogMsgPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(LogMsgDO::getType, reqVO.getType()) + .eqIfPresent(LogMsgDO::getTitle, reqVO.getTitle()) + .eqIfPresent(LogMsgDO::getUserId, reqVO.getUserId()) + .betweenIfPresent(LogMsgDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(LogMsgDO::getId)); + } + + default List selectList(LogMsgExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(LogMsgDO::getType, reqVO.getType()) + .eqIfPresent(LogMsgDO::getTitle, reqVO.getTitle()) + .eqIfPresent(LogMsgDO::getUserId, reqVO.getUserId()) + .betweenIfPresent(LogMsgDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(LogMsgDO::getId)); + } + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgService.java new file mode 100644 index 00000000..d5bf2d63 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgService.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.module.farm.service.logMsg; + +import java.util.*; +import javax.validation.*; + +import cn.iocoder.yudao.framework.common.page.PageDTO; +import cn.iocoder.yudao.framework.common.page.PageVO; +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.dto.LogMsgDTO; +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import com.zsw.base.R; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * Service 接口 + * + * @author 尚筱璇 + */ +public interface LogMsgService { + + /** + * 创建 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createLogMsg(@Valid LogMsgCreateReqVO createReqVO); + + /** + * 更新 + * + * @param updateReqVO 更新信息 + */ + void updateLogMsg(@Valid LogMsgUpdateReqVO updateReqVO); + + /** + * 删除 + * + * @param id 编号 + */ + void deleteLogMsg(Long id); + + /** + * 获得 + * + * @param id 编号 + * @return + */ + LogMsgDO getLogMsg(Long id); + + /** + * 获得列表 + * + * @param ids 编号 + * @return 列表 + */ + List getLogMsgList(Collection ids); + + /** + * 获得分页 + * + * @param pageReqVO 分页查询 + * @return 分页 + */ + PageResult getLogMsgPage(LogMsgPageReqVO pageReqVO); + + /** + * 获得列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 列表 + */ + List getLogMsgList(LogMsgExportReqVO exportReqVO); + + + R> logMsgList(PageDTO pageDTO); + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgServiceImpl.java new file mode 100644 index 00000000..b6cbd637 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgServiceImpl.java @@ -0,0 +1,137 @@ +package cn.iocoder.yudao.module.farm.service.logMsg; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.db.Page; +import cn.hutool.system.oshi.CpuInfo; +import cn.iocoder.yudao.framework.common.page.PageDTO; +import cn.iocoder.yudao.framework.common.page.PageUtil; +import cn.iocoder.yudao.framework.common.page.PageVO; +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.dto.LogMsgDTO; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; +import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.zsw.base.R; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import java.util.stream.Collectors; + +import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.farm.convert.logMsg.LogMsgConvert; +import cn.iocoder.yudao.module.farm.dal.mysql.logMsg.LogMsgMapper; +import org.springframework.web.bind.annotation.RequestBody; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*; + +/** + * Service 实现类 + * + * @author 尚筱璇 + */ +@Service +@Validated +public class LogMsgServiceImpl implements LogMsgService { + + @Resource + private LogMsgMapper logMsgMapper; + @Resource + private CpUserMapper cpUserMapper; + @Resource + private CpUserService cpUserService; + @Resource + private AdminUserService adminUserService; + + @Override + public Long createLogMsg(LogMsgCreateReqVO createReqVO) { + // 插入 + LogMsgDO logMsg = LogMsgConvert.INSTANCE.convert(createReqVO); + logMsgMapper.insert(logMsg); + // 返回 + return logMsg.getId(); + } + + @Override + public void updateLogMsg(LogMsgUpdateReqVO updateReqVO) { + // 校验存在 + this.validateLogMsgExists(updateReqVO.getId()); + // 更新 + LogMsgDO updateObj = LogMsgConvert.INSTANCE.convert(updateReqVO); + logMsgMapper.updateById(updateObj); + } + + @Override + public void deleteLogMsg(Long id) { + // 校验存在 + this.validateLogMsgExists(id); + // 删除 + logMsgMapper.deleteById(id); + } + + private void validateLogMsgExists(Long id) { + if (logMsgMapper.selectById(id) == null) { + throw exception(LOG_MSG_NOT_EXISTS); + } + } + + @Override + public LogMsgDO getLogMsg(Long id) { + return logMsgMapper.selectById(id); + } + + @Override + public List getLogMsgList(Collection ids) { + return logMsgMapper.selectBatchIds(ids); + } + + @Override + public PageResult getLogMsgPage(LogMsgPageReqVO pageReqVO) { + return logMsgMapper.selectPage(pageReqVO); + } + + @Override + public List getLogMsgList(LogMsgExportReqVO exportReqVO) { + return logMsgMapper.selectList(exportReqVO); + } + + public R> logMsgList(PageDTO pageDTO){ + PageUtil.startPage(pageDTO); + List list = logMsgMapper.selectList(); + + List dtoList = BeanUtil.copyToList(list, LogMsgDTO.class); + + List systemUserIdList = dtoList.stream().map(LogMsgDTO::getUserId).collect(Collectors.toList()); + List adminUserList = adminUserService.getUsers(systemUserIdList); + List cpUserList = adminUserService.getCpUserByAdminUser(systemUserIdList); + + Map map = new HashMap<>(); + adminUserList.forEach(systemUser ->{ + cpUserList.forEach(cpUser ->{ + if (systemUser.getUsername().equals(cpUser.getUserId())){ + map.put(systemUser.getId(), cpUser); + } + }); + }); + + + dtoList.forEach(msg ->{ + if (map.containsKey(msg.getUserId())){ + CpUserDO user = map.get(msg.getUserId()); + msg.setUserName(user.getName()); + msg.setUserIcon(user.getAvatar()); + } + }); + PageVO returnList = PageUtil.convertPageInfo(dtoList); + return R.success(returnList); + } + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/resources/mapper/logMsg/LogMsgMapper.xml b/zsw-farm/zsw-farm-impl/src/main/resources/mapper/logMsg/LogMsgMapper.xml new file mode 100644 index 00000000..143858b7 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/resources/mapper/logMsg/LogMsgMapper.xml @@ -0,0 +1,12 @@ + + + + + + +