ソースを参照

添加自定义列宽后端接口文件

阿伏兔 4 年 前
コミット
904bf1798b

+ 94 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysTableSetController.java

@@ -0,0 +1,94 @@
+package com.ruoyi.web.controller.system;
+
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.system.domain.SysTableSet;
+import com.ruoyi.system.domain.SysTableSetQuery;
+import com.ruoyi.system.service.ISysTableSetService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 列宽修改Controller
+ *
+ * @author ruoyi
+ * @date 2021-01-30
+ */
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/system/set")
+public class SysTableSetController extends BaseController {
+
+    private final ISysTableSetService iSysTableSetService;
+
+    /**
+     * 查询列宽修改列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:set:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(SysTableSet sysTableSet) {
+        startPage();
+        List<SysTableSet> list = iSysTableSetService.queryList(sysTableSet);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出列宽修改列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:set:export')")
+    @Log(title = "列宽修改", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    public AjaxResult export(SysTableSet sysTableSet) {
+        List<SysTableSet> list = iSysTableSetService.queryList(sysTableSet);
+        ExcelUtil<SysTableSet> util = new ExcelUtil<SysTableSet>(SysTableSet.class);
+        return util.exportExcel(list, "set");
+    }
+
+    /**
+     * 新增列宽修改
+     */
+    @PreAuthorize("@ss.hasPermi('system:set:add')")
+    @Log(title = "列宽修改", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody SysTableSetQuery sysTableSetQuery) {
+        if (sysTableSetQuery.getUserId() == null || StringUtils.isEmpty(sysTableSetQuery.getTableName())) {
+            return AjaxResult.error("参数缺失");
+        }
+        return iSysTableSetService.saveTableSet(sysTableSetQuery);
+    }
+
+    /**
+     * 修改列宽修改
+     */
+    @PreAuthorize("@ss.hasPermi('system:set:edit')")
+    @Log(title = "列宽修改", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody SysTableSet sysTableSet) {
+        return toAjax(iSysTableSetService.updateTableSetMessage(sysTableSet) ? 1 : 0);
+    }
+
+    /**
+     * 查询列宽修改列表
+     *
+     * @return
+     */
+    @PreAuthorize("@ss.hasPermi('system:set:select')")
+    @GetMapping("/select")
+    public AjaxResult select(SysTableSet sysTableSet) {
+        if (sysTableSet.getUserId() == null || StringUtils.isEmpty(sysTableSet.getTableName())) {
+            return AjaxResult.error("参数缺失");
+        }
+        List<SysTableSet> list = iSysTableSetService.selectTableSet(sysTableSet);
+        return AjaxResult.success(list);
+    }
+}

+ 59 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTableSet.java

@@ -0,0 +1,59 @@
+package com.ruoyi.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.annotation.Excel;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 列宽修改对象 sys_table_set
+ * 
+ * @author ruoyi
+ * @date 2021-01-30
+ */
+@Data
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("sys_table_set")
+public class SysTableSet implements Serializable {
+
+private static final long serialVersionUID=1L;
+
+
+    /** 主键 */
+    @TableId(value = "id")
+    private Long id;
+
+    /** 表名 */
+    @Excel(name = "表名")
+    private String tableName;
+
+    /** 用户ID */
+    @Excel(name = "用户ID")
+    private Long userId;
+    /**列名ID*/
+    @Excel(name = "列名ID")
+    private Long surface;
+    /**英文列名*/
+    @Excel(name = "英文列名")
+    private String label;
+    /**中文列名*/
+    @Excel(name = "中文列名")
+    private String name;
+    /**选中状态*/
+    @Excel(name = "选中状态"  , readConverterExp = "0=选中,1=未选中")
+    private Long checked;
+    /**宽度*/
+    @Excel(name = "宽度")
+    private Long width;
+
+    @TableField(exist = false)
+    private Map<String, Object> params = new HashMap<>();
+}

+ 24 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTableSetQuery.java

@@ -0,0 +1,24 @@
+package com.ruoyi.system.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class SysTableSetQuery implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    /**
+     * 表名
+     */
+    private String tableName;
+    /**
+     * 用户ID
+     */
+    private Long userId;
+    /**
+     * 列显示信息
+     */
+    private List<SysTableSet> sysTableSetList;
+}

+ 82 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysTableSetMapper.java

@@ -0,0 +1,82 @@
+package com.ruoyi.system.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.system.domain.SysTableSet;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 列宽修改Mapper接口
+ *
+ * @author ruoyi
+ * @date 2021-01-30
+ */
+public interface SysTableSetMapper {
+    /**
+     * 获取最大的表ID
+     *
+     * @return
+     */
+    Long selectMaxId();
+
+    List<SysTableSet> selectMessage(@Param("tableName") String tableName,
+                                    @Param("userId") Long userId);
+
+    Integer updateTableSetMessage(@Param("table") SysTableSet sysTableSet);
+
+    /**
+     * 查询列宽修改
+     *
+     * @param id 列宽修改ID
+     * @return 列宽修改
+     */
+    public SysTableSet selectSysTableSetById(Long id);
+
+    /**
+     * 查询列宽修改列表
+     *
+     * @param sysTableSet 列宽修改
+     * @return 列宽修改集合
+     */
+    public List<SysTableSet> selectSysTableSetList(SysTableSet sysTableSet);
+
+    /**
+     * 新增列宽修改
+     *
+     * @param sysTableSet 列宽修改
+     * @return 结果
+     */
+    public int insertSysTableSet(SysTableSet sysTableSet);
+
+    /**
+     * 修改列宽修改
+     *
+     * @param sysTableSet 列宽修改
+     * @return 结果
+     */
+    public int updateSysTableSet(SysTableSet sysTableSet);
+
+    /**
+     * 删除列宽修改
+     *
+     * @param id 列宽修改ID
+     * @return 结果
+     */
+    public int deleteSysTableSetById(Long id);
+
+    /**
+     * 批量删除列宽修改
+     *
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+    public int deleteSysTableSetByIds(Long[] ids);
+
+    /**
+     *  根据条件删除对应数据
+     * @param stableSet
+     * @return
+     */
+    public int deleteSysTableSet(SysTableSet stableSet);
+}

+ 40 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTableSetService.java

@@ -0,0 +1,40 @@
+package com.ruoyi.system.service;
+
+
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.system.domain.SysTableSet;
+import com.ruoyi.system.domain.SysTableSetQuery;
+
+import java.util.List;
+
+/**
+ * 列宽修改Service接口
+ *
+ * @author ruoyi
+ * @date 2021-01-30
+ */
+public interface ISysTableSetService {
+
+    /**
+     * 查询列表
+     */
+    List<SysTableSet> queryList(SysTableSet sysTableSet);
+
+    /**
+     * 保存表信息
+     *
+     * @param sysTableSet
+     * @return
+     */
+    AjaxResult saveTableSet(SysTableSetQuery sysTableSet);
+
+    /**
+     * 查询表信息
+     *
+     * @param sysTableSet
+     * @return
+     */
+    List<SysTableSet> selectTableSet(SysTableSet sysTableSet);
+
+    boolean updateTableSetMessage(SysTableSet sysTableSet);
+}

+ 106 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTableSetServiceImpl.java

@@ -0,0 +1,106 @@
+package com.ruoyi.system.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.system.domain.SysTableSet;
+import com.ruoyi.system.domain.SysTableSetQuery;
+import com.ruoyi.system.mapper.SysTableSetMapper;
+import com.ruoyi.system.service.ISysTableSetService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 列宽修改Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2021-01-30
+ */
+@Service
+public class SysTableSetServiceImpl implements ISysTableSetService {
+    @Autowired
+    private SysTableSetMapper sysTableSetMapper;
+
+    @Override
+    public List<SysTableSet> queryList(SysTableSet sysTableSet) {
+        return sysTableSetMapper.selectSysTableSetList(sysTableSet);
+    }
+
+    @Override
+    @Transactional
+    public AjaxResult saveTableSet(SysTableSetQuery sysTableSetQuery) {
+        boolean flag = false;
+        //查询用户对应的表信息是否存在
+        SysTableSet stableSet = new SysTableSet();
+        stableSet.setUserId(sysTableSetQuery.getUserId());
+        stableSet.setTableName(sysTableSetQuery.getTableName());
+        List<SysTableSet> sysTableSetList = sysTableSetMapper.selectSysTableSetList(stableSet);
+        if (CollectionUtils.isNotEmpty(sysTableSetList)) {
+            if (sysTableSetMapper.deleteSysTableSet(stableSet) <= 0) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("删除数据失败");
+            }
+        }
+        for (SysTableSet tableSet : sysTableSetQuery.getSysTableSetList()) {
+            tableSet.setTableName(sysTableSetQuery.getTableName());
+            tableSet.setUserId(sysTableSetQuery.getUserId());
+            if (sysTableSetMapper.insertSysTableSet(tableSet) <= 0) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("新增数据失败");
+            }
+        }
+        /*if (CollectionUtils.isNotEmpty(sysTableSetList)){
+            //不为空修改原有信息
+            for (SysTableSet tableSet : sysTableSetQuery.getSysTableSetList()) {
+                flag = this.updateById(tableSet);
+            }
+        }else {
+            //为空新增数据信息
+           *//* Long aLong = this.selectMaxId();//获取最大的表ID
+            if (aLong ==0 || aLong ==null){
+                aLong = 1L;
+            }else if (aLong != null && aLong>0){
+                aLong = aLong+1;
+            }*//*
+            for (SysTableSet tableSet : sysTableSetQuery.getSysTableSetList()) {
+                tableSet.setTableName(sysTableSetQuery.getTableName());
+                tableSet.setUserId(sysTableSetQuery.getUserId());
+                flag = this.save(tableSet);
+            }
+        }*/
+        return AjaxResult.success();
+    }
+
+    @Override
+    public List<SysTableSet> selectTableSet(SysTableSet sysTableSet) {
+        List<SysTableSet> list = new ArrayList<>();
+        if (sysTableSet.getUserId() != null && StringUtils.isNoneEmpty(sysTableSet.getTableName())) {
+            SysTableSet stableSet = new SysTableSet();
+            stableSet.setUserId(sysTableSet.getUserId());
+            stableSet.setTableName(sysTableSet.getTableName());
+            list = sysTableSetMapper.selectSysTableSetList(stableSet);
+        }
+        return list;
+    }
+
+    @Override
+    @Transactional
+    public boolean updateTableSetMessage(SysTableSet sysTableSet) {
+        Integer integer = sysTableSetMapper.updateSysTableSet(sysTableSet);
+        if (Objects.equals(integer, 0) || integer < 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+}

+ 124 - 0
ruoyi-system/src/main/resources/mapper/system/SysTableSetMapper.xml

@@ -0,0 +1,124 @@
+<?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.ruoyi.system.mapper.SysTableSetMapper">
+
+    <resultMap type="SysTableSet" id="SysTableSetResult">
+        <result property="id" column="id"/>
+        <result property="tableName" column="table_name"/>
+        <result property="userId" column="user_id"/>
+        <result property="surface" column="surface"/>
+        <result property="label" column="label"/>
+        <result property="name" column="name"/>
+        <result property="checked" column="checked"/>
+        <result property="width" column="width"/>
+    </resultMap>
+
+    <sql id="selectSysTableSetVo">
+        select id, table_name, user_id, surface, label, name, checked, width from sys_table_set
+    </sql>
+
+    <select id="selectSysTableSetList" parameterType="SysTableSet" resultMap="SysTableSetResult">
+        <include refid="selectSysTableSetVo"/>
+        <where>
+            <if test="tableName != null  and tableName != ''">and table_name like concat('%', #{tableName}, '%')</if>
+            <if test="userId != null ">and user_id = #{userId}</if>
+            <if test="surface != null ">and surface = #{surface}</if>
+            <if test="label != null  and label != ''">and label = #{label}</if>
+            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
+            <if test="checked != null ">and checked = #{checked}</if>
+            <if test="width != null ">and width = #{width}</if>
+        </where>
+    </select>
+
+    <select id="selectSysTableSetById" parameterType="Long" resultMap="SysTableSetResult">
+        <include refid="selectSysTableSetVo"/>
+        where id = #{id}
+    </select>
+
+    <select id="selectMaxId" resultType="long">
+        SELECT if(MAX(table_id) IS NULL,0,table_id)  AS a FROM sys_table_set
+    </select>
+    <select id="selectMessage" resultType="com.ruoyi.system.domain.SysTableSet">
+        SELECT
+	        id,surface,label,name,checked,width
+        FROM
+	        `sys_table_set`
+        WHERE
+	        user_id = #{userId}
+	    AND table_name = #{tableName}
+    </select>
+
+    <insert id="insertSysTableSet" parameterType="SysTableSet" useGeneratedKeys="true" keyProperty="id">
+        insert into sys_table_set
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="tableName != null">table_name,</if>
+            <if test="userId != null">user_id,</if>
+            <if test="surface != null">surface,</if>
+            <if test="label != null">label,</if>
+            <if test="name != null">name,</if>
+            <if test="checked != null">checked,</if>
+            <if test="width != null">width,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="tableName != null">#{tableName},</if>
+            <if test="userId != null">#{userId},</if>
+            <if test="surface != null">#{surface},</if>
+            <if test="label != null">#{label},</if>
+            <if test="name != null">#{name},</if>
+            <if test="checked != null">#{checked},</if>
+            <if test="width != null">#{width},</if>
+        </trim>
+    </insert>
+
+    <update id="updateSysTableSet" parameterType="SysTableSet">
+        update sys_table_set
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="tableName != null">table_name = #{tableName},</if>
+            <if test="userId != null">user_id = #{userId},</if>
+            <if test="surface != null">surface = #{surface},</if>
+            <if test="label != null">label = #{label},</if>
+            <if test="name != null">name = #{name},</if>
+            <if test="checked != null">checked = #{checked},</if>
+            <if test="width != null">width = #{width},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <update id="updateTableSetMessage" parameterType="object">
+        UPDATE sys_table_set
+        <set>
+            <if test="table.surface != null">
+                surface = #{table.surface},
+            </if>
+            <if test="table.label != '' || table.label != null">
+                label = #{table.label},
+            </if>
+            <if test="table.name != '' || table.name != null">
+                name = #{table.name},
+            </if>
+            <if test="table.checked != null">
+                checked = #{table.checked},
+            </if>
+            <if test="table.width != null">
+                width = #{table.width},
+            </if>
+        </set>
+        WHERE
+        user_id = #{table.userId}
+        AND table_name = #{table.tableName}
+    </update>
+
+    <delete id="deleteSysTableSetById" parameterType="Long">
+        delete from sys_table_set where id = #{id}
+    </delete>
+
+    <delete id="deleteSysTableSetByIds" parameterType="String">
+        delete from sys_table_set where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+</mapper>