xiangpei
2024-08-15 d67583aafee4044aa1c5313939da3fe3cc5aec13
平台管理代码
9个文件已添加
532 ■■■■■ 已修改文件
ycl-pojo/src/main/java/com/ycl/platform/domain/entity/Platform.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/form/PlatformForm.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/query/PlatformQuery.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/vo/PlatformVO.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/controller/PlatformController.java 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/mapper/PlatformMapper.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/PlatformService.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/impl/PlatformServiceImpl.java 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/resources/mapper/zgyw/PlatformMapper.xml 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/entity/Platform.java
New file
@@ -0,0 +1,42 @@
package com.ycl.platform.domain.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ycl.platform.base.AbsEntity;
import lombok.Data;
/**
 * 平台运行监控
 *
 * @author xp
 * @since 2024-08-15
 */
@Data
@TableName("t_platform")
public class Platform extends AbsEntity {
    private static final long serialVersionUID = 1L;
    @TableField("platform_name")
    /** 平台名称 */
    private String platformName;
    @TableField("platform_contact")
    /** 平台联系人 */
    private String platformIP;
    @TableField("status")
    /** 状态:1正常 2异常 */
    private Integer status;
    @TableField("remark")
    /** 备注 */
    private String remark;
    @TableField("parent_id")
    /** 主平台ID */
    private Integer parentId;
}
ycl-pojo/src/main/java/com/ycl/platform/domain/form/PlatformForm.java
New file
@@ -0,0 +1,57 @@
package com.ycl.platform.domain.form;
import com.ycl.platform.base.AbsForm;
import com.ycl.platform.domain.entity.Platform;
import com.ycl.system.domain.group.Add;
import com.ycl.system.domain.group.Update;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.BeanUtils;
import javax.validation.constraints.NotNull;
import org.springframework.lang.NonNull;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
 * 平台运行监控表单
 *
 * @author xp
 * @since 2024-08-15
 */
@Data
@ApiModel(value = "Platform表单", description = "平台运行监控表单")
public class PlatformForm extends AbsForm {
    @NotBlank(message = "平台名称不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("平台名称")
    private String platformName;
    @NotBlank(message = "平台IP不能为空", groups = {Add.class, Update.class})
    @ApiModelProperty("平台IP")
    private String platformIP;
//    @NotBlank(message = "平台联系人不能为空", groups = {Add.class, Update.class})
//    @ApiModelProperty("平台联系人")
//    private String platformContact;
//
//    @NotBlank(message = "平台联系人电话不能为空", groups = {Add.class, Update.class})
//    @ApiModelProperty("平台联系人电话")
//    private String platformContactPhone;
    @ApiModelProperty("备注")
    private String remark;
    @ApiModelProperty("部署平台列表,一个平台可部署到多个区县")
    private List<Platform> deployList;
    public static Platform getEntityByForm(@NonNull PlatformForm form, Platform entity) {
        if(entity == null) {
          entity = new Platform();
        }
        BeanUtils.copyProperties(form, entity);
        return entity;
    }
}
ycl-pojo/src/main/java/com/ycl/platform/domain/query/PlatformQuery.java
New file
@@ -0,0 +1,17 @@
package com.ycl.platform.domain.query;
import com.ycl.platform.base.AbsQuery;
import io.swagger.annotations.ApiModel;
import lombok.Data;
/**
 * 平台运行监控查询
 *
 * @author xp
 * @since 2024-08-15
 */
@Data
@ApiModel(value = "Platform查询", description = "平台运行监控查询")
public class PlatformQuery extends AbsQuery {
}
ycl-pojo/src/main/java/com/ycl/platform/domain/vo/PlatformVO.java
New file
@@ -0,0 +1,48 @@
package com.ycl.platform.domain.vo;
import com.ycl.platform.base.AbsVo;
import com.ycl.platform.domain.entity.Platform;
import org.springframework.lang.NonNull;
import org.springframework.beans.BeanUtils;
import lombok.Data;
import java.util.Date;
/**
 * 平台运行监控展示
 *
 * @author xp
 * @since 2024-08-15
 */
@Data
public class PlatformVO extends AbsVo {
    /** 平台名称 */
    private String platformName;
    /** 平台联系人 */
    private String platformContact;
    /** 平台联系人电话 */
    private String platformContactPhone;
    /** 状态:1正常 2异常 */
    private Integer status;
    /** 备注 */
    private String remark;
    /** 创建时间 */
    private Date createTime;
    /** 修改时间 */
    private Date updateTime;
    public static PlatformVO getVoByEntity(@NonNull Platform entity, PlatformVO vo) {
        if(vo == null) {
            vo = new PlatformVO();
        }
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
}
ycl-server/src/main/java/com/ycl/platform/controller/PlatformController.java
New file
@@ -0,0 +1,81 @@
package com.ycl.platform.controller;
import com.ycl.platform.domain.form.PlatformForm;
import com.ycl.platform.domain.query.PlatformQuery;
import com.ycl.platform.service.PlatformService;
import com.ycl.system.Result;
import com.ycl.system.domain.group.Add;
import com.ycl.system.domain.group.Update;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import lombok.RequiredArgsConstructor;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
/**
 * 平台运行监控 前端控制器
 *
 * @author xp
 * @since 2024-08-15
 */
@Validated
@RequiredArgsConstructor
@Api(value = "平台运行监控", tags = "平台运行监控管理")
@RestController
@RequestMapping("/platform")
public class PlatformController {
    private final PlatformService platformService;
    @PostMapping
    @ApiOperation(value = "添加", notes = "添加")
    @PreAuthorize("@ss.hasPermi('platform:add')")
    public Result add(@RequestBody @Validated(Add.class) PlatformForm form) {
        return platformService.add(form);
    }
    @PutMapping
    @ApiOperation(value = "修改", notes = "修改")
    @PreAuthorize("@ss.hasPermi('platform:edit')")
    public Result update(@RequestBody @Validated(Update.class) PlatformForm form) {
        return platformService.update(form);
    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "ID删除", notes = "ID删除")
    @PreAuthorize("@ss.hasPermi('platform:del')")
    public Result removeById(@PathVariable("id") String id) {
        return platformService.removeById(id);
    }
    @DeleteMapping("/batch")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PreAuthorize("@ss.hasPermi('platform:del:batch')")
    public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List<String> ids) {
        return platformService.remove(ids);
    }
    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "分页")
    @PreAuthorize("@ss.hasPermi('platform:page')")
    public Result page(PlatformQuery query) {
        return platformService.page(query);
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "详情", notes = "详情")
    @PreAuthorize("@ss.hasPermi('platform:detail')")
    public Result detail(@PathVariable("id") Integer id) {
        return platformService.detail(id);
    }
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('platform:list')")
    @ApiOperation(value = "列表", notes = "列表")
    public Result list() {
        return platformService.all();
    }
}
ycl-server/src/main/java/com/ycl/platform/mapper/PlatformMapper.java
New file
@@ -0,0 +1,33 @@
package com.ycl.platform.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ycl.platform.domain.entity.Platform;
import com.ycl.platform.domain.query.PlatformQuery;
import com.ycl.platform.domain.vo.PlatformVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
 * 平台运行监控 Mapper 接口
 *
 * @author xp
 * @since 2024-08-15
 */
@Mapper
public interface PlatformMapper extends BaseMapper<Platform> {
    /**
     * id查找平台运行监控
     * @param id
     * @return
     */
    PlatformVO getById(Integer id);
    /**
    *  分页
    */
    IPage getPage(IPage page, @Param("query") PlatformQuery query);
}
ycl-server/src/main/java/com/ycl/platform/service/PlatformService.java
New file
@@ -0,0 +1,66 @@
package com.ycl.platform.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ycl.platform.domain.entity.Platform;
import com.ycl.platform.domain.form.PlatformForm;
import com.ycl.platform.domain.query.PlatformQuery;
import com.ycl.system.Result;
import java.util.List;
/**
 * 平台运行监控 服务类
 *
 * @author xp
 * @since 2024-08-15
 */
public interface PlatformService extends IService<Platform> {
    /**
     * 添加
     * @param form
     * @return
     */
    Result add(PlatformForm form);
    /**
     * 修改
     * @param form
     * @return
     */
    Result update(PlatformForm form);
    /**
     * 批量删除
     * @param ids
     * @return
     */
    Result remove(List<String> ids);
    /**
     * id删除
     * @param id
     * @return
     */
    Result removeById(String id);
    /**
     * 分页查询
     * @param query
     * @return
     */
    Result page(PlatformQuery query);
    /**
     * 根据id查找
     * @param id
     * @return
     */
    Result detail(Integer id);
    /**
     * 列表
     * @return
     */
    Result all();
}
ycl-server/src/main/java/com/ycl/platform/service/impl/PlatformServiceImpl.java
New file
@@ -0,0 +1,133 @@
package com.ycl.platform.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.platform.domain.entity.Platform;
import com.ycl.platform.domain.form.PlatformForm;
import com.ycl.platform.domain.query.PlatformQuery;
import com.ycl.platform.domain.vo.PlatformVO;
import com.ycl.platform.mapper.PlatformMapper;
import com.ycl.platform.service.PlatformService;
import com.ycl.system.Result;
import com.ycl.system.page.PageUtil;
import org.ehcache.core.util.CollectionUtil;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 平台运行监控 服务实现类
 *
 * @author xp
 * @since 2024-08-15
 */
@Service
@RequiredArgsConstructor
public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, Platform> implements PlatformService {
    private final PlatformMapper platformMapper;
    /**
     * 添加
     * @param form
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result add(PlatformForm form) {
        Platform entity = PlatformForm.getEntityByForm(form, null);
        entity.setParentId(0);
        baseMapper.insert(entity);
        if (! CollectionUtils.isEmpty(form.getDeployList())) {
            List<Platform> childList = form.getDeployList().stream().map(deploy -> {
                Platform child = new Platform();
                BeanUtils.copyProperties(deploy, child);
                child.setParentId(entity.getId());
                return child;
            }).collect(Collectors.toList());
            this.saveBatch(childList);
        }
        return Result.ok("添加成功");
    }
    /**
     * 修改
     * @param form
     * @return
     */
    @Override
    public Result update(PlatformForm form) {
        Platform entity = baseMapper.selectById(form.getId());
        // 为空抛IllegalArgumentException,做全局异常处理
        Assert.notNull(entity, "记录不存在");
        BeanUtils.copyProperties(form, entity);
        baseMapper.updateById(entity);
        return Result.ok("修改成功");
    }
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public Result remove(List<String> ids) {
        baseMapper.deleteBatchIds(ids);
        return Result.ok("删除成功");
    }
    /**
     * id删除
     * @param id
     * @return
     */
    @Override
    public Result removeById(String id) {
        baseMapper.deleteById(id);
        return Result.ok("删除成功");
    }
    /**
     * 分页查询
     * @param query
     * @return
     */
    @Override
    public Result page(PlatformQuery query) {
        IPage<PlatformVO> page = PageUtil.getPage(query, PlatformVO.class);
        baseMapper.getPage(page, query);
        return Result.ok().data(page.getRecords()).total(page.getTotal());
    }
    /**
     * 根据id查找
     * @param id
     * @return
     */
    @Override
    public Result detail(Integer id) {
        PlatformVO vo = baseMapper.getById(id);
        Assert.notNull(vo, "记录不存在");
        return Result.ok().data(vo);
    }
    /**
     * 列表
     * @return
     */
    @Override
    public Result all() {
        List<Platform> entities = baseMapper.selectList(null);
        List<PlatformVO> vos = entities.stream()
                .map(entity -> PlatformVO.getVoByEntity(entity, null))
                .collect(Collectors.toList());
        return Result.ok().data(vos);
    }
}
ycl-server/src/main/resources/mapper/zgyw/PlatformMapper.xml
New file
@@ -0,0 +1,55 @@
<?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="com.ycl.platform.mapper.PlatformMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.platform.domain.vo.PlatformVO">
        <result column="platform_name" property="platformName" />
        <result column="platform_contact" property="platformContact" />
        <result column="platform_contact_phone" property="platformContactPhone" />
        <result column="status" property="status" />
        <result column="remark" property="remark" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>
    <select id="getById" resultMap="BaseResultMap">
        SELECT
            TP.platform_name,
            TP.platform_contact,
            TP.platform_contact_phone,
            TP.status,
            TP.remark,
            TP.create_time,
            TP.update_time,
            TP.id
        FROM
            t_platform TP
        WHERE
            TP.id = #{id} AND TP.deleted = 0
    </select>
    <select id="getPage" resultMap="BaseResultMap">
        SELECT
            TP.platform_name,
            TP.platform_contact,
            TP.platform_contact_phone,
            TP.status,
            TP.remark,
            TP.create_time,
            TP.update_time,
            TP.id
        FROM
            t_platform TP
        WHERE
            TP.deleted = 0
    </select>
</mapper>