Forráskód Böngészése

试验-规范管理-规范文件父子级开发

LHB 4 hónapja
szülő
commit
723dec51d3

+ 103 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/PrivateStandard.java

@@ -0,0 +1,103 @@
+package org.springblade.business.entity;
+
+import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * 规范文件夹及规范文件表
+ *
+ * @author LHB
+ * @TableName u_wbs_private_standard
+ */
+@TableName(value = "u_wbs_private_standard")
+@Data
+public class PrivateStandard {
+    /**
+     *
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 名称(规范文件夹名称及规范名称)
+     */
+    @NotBlank(message = "名称不能为空")
+    private String name;
+
+    /**
+     * 父级节点id
+     * type = 2 必传
+     */
+    private Long parentId;
+
+    /**
+     * 项目试验节点id
+     * type = 1 必传
+     */
+    private Long privateId;
+
+    /**
+     * 类型(1-规范文件夹,2-规范文件)
+     */
+    @NotNull(message = "类型不能为空")
+    private Integer type;
+
+    /**
+     * 下达日期(年月日)
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date issueDate;
+
+    /**
+     * 实施日期(年月日)
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date actualizeDate;
+
+    /**
+     * 规范文件路径
+     */
+    private String standardFileUrl;
+
+    /**
+     * 是否删除(0-正常,1-已删除)
+     */
+    private Integer isDeleted;
+
+    /**
+     * 创建时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime createTime;
+
+    /**
+     * 创建人
+     */
+    private Long createUser;
+
+    /**
+     * 修改时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime updateTime;
+
+    /**
+     * 修改人
+     */
+    private Long updateUser;
+}

+ 126 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/PrivateStandardController.java

@@ -0,0 +1,126 @@
+package org.springblade.business.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.springblade.business.entity.PrivateStandard;
+import org.springblade.business.service.PrivateStandardService;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springblade.core.tool.api.R;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * 规范文件夹及规范文件表(UWbsPrivateStandard)表控制层
+ *
+ * @author makejava
+ * @since 2025-06-10 11:09:22
+ */
+@RestController
+@RequestMapping("PrivateStandard")
+public class PrivateStandardController {
+    /**
+     * 服务对象
+     */
+    @Resource
+    private PrivateStandardService privateStandardService;
+
+    /**
+     * 分页查询所有数据
+     *
+     * @param query               分页对象
+     * @param uWbsPrivateStandard 查询实体
+     * @return 所有数据
+     */
+    @GetMapping
+    public R<IPage<PrivateStandard>> selectAll(Query query, PrivateStandard uWbsPrivateStandard) {
+        try {
+            Page page = new Page(query.getCurrent(), query.getSize());
+            IPage<PrivateStandard> resultPage = this.privateStandardService.page(page, new QueryWrapper<>(uWbsPrivateStandard));
+            return R.data(resultPage);
+        } catch (Exception e) {
+            // 可根据实际需求记录日志或返回特定错误信息
+            return R.fail("查询失败");
+        }
+    }
+
+
+    /**
+     * 通过主键查询单条数据
+     *
+     * @param id 主键
+     * @return 单条数据
+     */
+    @GetMapping("/getById")
+    public R<PrivateStandard> selectOne(Long id) {
+        PrivateStandard byId = this.privateStandardService.getById(id);
+        return R.data(byId);
+    }
+
+    /**
+     * 新增数据
+     *
+     * @param uWbsPrivateStandard 实体对象
+     * @return 新增结果
+     */
+    @PostMapping
+    public R<Boolean> insert(@RequestBody @Validated PrivateStandard uWbsPrivateStandard) {
+        uWbsPrivateStandard.setId(SnowFlakeUtil.getId());
+        if (uWbsPrivateStandard.getType() != 1 && uWbsPrivateStandard.getType() != 2) {
+            return R.fail("类型错误");
+        }
+        if (uWbsPrivateStandard.getType() == 1) {
+            uWbsPrivateStandard.setParentId(0L);
+            if (uWbsPrivateStandard.getPrivateId() == null) {
+                return R.fail("节点不能为空");
+            }
+        } else {
+            if (uWbsPrivateStandard.getParentId() == null) {
+                return R.fail("父级节点不能为空");
+            }
+            if (uWbsPrivateStandard.getIssueDate() == null) {
+                return R.fail("下达日期不能为空");
+            }
+            if (uWbsPrivateStandard.getActualizeDate() == null) {
+                return R.fail("实施日期不能为空");
+            }
+        }
+        BladeUser user = SecureUtil.getUser();
+        uWbsPrivateStandard.setCreateUser(user.getUserId());
+        boolean save = this.privateStandardService.save(uWbsPrivateStandard);
+        return R.data(save);
+    }
+
+    /**
+     * 修改数据
+     *
+     * @param uWbsPrivateStandard 实体对象
+     * @return 修改结果
+     */
+    @PutMapping
+    public R<Boolean> update(@RequestBody @Validated PrivateStandard uWbsPrivateStandard) {
+        BladeUser user = SecureUtil.getUser();
+        uWbsPrivateStandard.setUpdateUser(user.getUserId());
+        boolean b = this.privateStandardService.updateById(uWbsPrivateStandard);
+        return R.data(b);
+    }
+
+    /**
+     * 删除数据
+     *
+     * @param id 主键
+     * @return 删除结果
+     */
+    @GetMapping("/delete")
+    public R<Boolean> delete(Long id) {
+        boolean b = this.privateStandardService.delete(id);
+        return R.data(b);
+    }
+}
+

+ 18 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/PrivateStandardMapper.java

@@ -0,0 +1,18 @@
+package org.springblade.business.mapper;
+
+import org.springblade.business.entity.PrivateStandard;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author LHB
+* @description 针对表【u_wbs_private_standard(规范文件夹及规范文件表)】的数据库操作Mapper
+* @createDate 2025-06-10 10:48:37
+* @Entity generator.domain.UWbsPrivateStandard
+*/
+public interface PrivateStandardMapper extends BaseMapper<PrivateStandard> {
+
+}
+
+
+
+

+ 28 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/PrivateStandardMapper.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.business.mapper.PrivateStandardMapper">
+
+    <resultMap id="BaseResultMap" type="org.springblade.business.entity.PrivateStandard">
+            <id property="id" column="id" />
+            <result property="name" column="name" />
+            <result property="parentId" column="parent_id" />
+            <result property="privateId" column="private_id" />
+            <result property="type" column="type" />
+            <result property="issueDate" column="issue_date" />
+            <result property="actualizeDate" column="actualize_date" />
+            <result property="standardFileUrl" column="standard_file_url" />
+            <result property="isDeleted" column="is_deleted" />
+            <result property="createTime" column="create_time" />
+            <result property="createUser" column="create_user" />
+            <result property="updateTime" column="update_time" />
+            <result property="updateUser" column="update_user" />
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,name,parent_id,private_id,type,issue_date,
+        actualize_date,standard_file_url,is_deleted,create_time,create_user,
+        update_time,update_user
+    </sql>
+</mapper>

+ 14 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/PrivateStandardService.java

@@ -0,0 +1,14 @@
+package org.springblade.business.service;
+
+import org.springblade.business.entity.PrivateStandard;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author LHB
+* @description 针对表【u_wbs_private_standard(规范文件夹及规范文件表)】的数据库操作Service
+* @createDate 2025-06-10 10:48:37
+*/
+public interface PrivateStandardService extends IService<PrivateStandard> {
+
+    boolean delete(Long id);
+}

+ 42 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/PrivateStandardServiceImpl.java

@@ -0,0 +1,42 @@
+package org.springblade.business.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springblade.business.entity.PrivateStandard;
+import org.springblade.business.service.PrivateStandardService;
+import org.springblade.business.mapper.PrivateStandardMapper;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+* @author LHB
+* @description 针对表【u_wbs_private_standard(规范文件夹及规范文件表)】的数据库操作Service实现
+* @createDate 2025-06-10 10:48:37
+*/
+@Service
+public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMapper, PrivateStandard>
+    implements PrivateStandardService {
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean delete(Long id) {
+        //获取当前用户
+        BladeUser user = SecureUtil.getUser();
+        int update = baseMapper.update(null, Wrappers.<PrivateStandard>lambdaUpdate()
+                .set(PrivateStandard::getIsDeleted, 1)
+                .set(PrivateStandard::getUpdateUser, user.getUserId())
+                .eq(PrivateStandard::getId, id)
+                .or()
+                .eq(PrivateStandard::getParentId, id)
+        );
+        //TODO 后续还要删除规范详细信息
+
+        return update > 0;
+    }
+}
+
+
+
+