Ver Fonte

提交代码(新增参数配置功能)

cxd há 7 meses atrás
pai
commit
0eba777bf1

+ 4 - 3
gqy-admin/src/main/java/com/gqy/web/controller/document/DocumentCategoryController.java

@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
 
 
 @RestController
@@ -86,13 +87,13 @@ public class DocumentCategoryController extends BaseController {
     /**
      * 获取模板分类信息
      *
-     * @param id 模板分类ID
      * @return 返回结果对象,成功则包含模板分类信息
      */
     @PostMapping("/info")
-    public AjaxResultCQY info(@RequestParam Long id)
+    public AjaxResultCQY info(@RequestBody Map maps)
     {
-        return AjaxResultCQY.success("查询成功",documentCategoryService.info(id));
+        String id = maps.get("id").toString();
+        return AjaxResultCQY.success("查询成功",documentCategoryService.info(Long.valueOf(id)));
     }
 
 }

+ 61 - 8
gqy-admin/src/main/java/com/gqy/web/controller/document/ParamsController.java

@@ -1,19 +1,23 @@
 package com.gqy.web.controller.document;
 
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.gqy.common.core.domain.AjaxResult;
 import com.gqy.common.core.domain.AjaxResultCQY;
 import com.gqy.common.core.page.TableDataInfo;
+import com.gqy.common.utils.StringUtils;
 import com.gqy.common.utils.bean.BeanUtils;
 import com.gqy.document.domain.DcParams;
+import com.gqy.document.domain.DcTemplate;
+import com.gqy.document.domain.vo.PageResult;
 import com.gqy.document.service.IDcParamsService;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import springfox.documentation.schema.Maps;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -31,12 +35,61 @@ public class ParamsController {
      * 查询参数列表
      */
     @PostMapping("/search")
-    public AjaxResultCQY search(@RequestBody Maps params)
+    public AjaxResultCQY search(@RequestBody Map<String, Object> params)
     {
-        DcParams paramsReq =  BeanUtils.mapToBean((Map<String, Object>) params, DcParams.class);
+        DcParams dcParamsReq =  BeanUtils.mapToBean((Map<String, Object>) params, DcParams.class);
 
-//        return paramsService.search(params);
-        return null;
+        String page = params.get("page").toString();
+        String pageSizeStr = params.get("pageSize").toString();
+        Integer pageNum = StringUtils.isNotEmpty(page) ? Integer.valueOf(page) : 1;
+        Integer pageSize = StringUtils.isNotEmpty(pageSizeStr) ? Integer.valueOf(pageSizeStr) : 10;
+        PageHelper.startPage(pageNum, pageSize);
+
+        List<DcParams> listDcParams =  iDcParamsService.search(dcParamsReq);
+
+        // 3. 获取分页信息
+        PageInfo<DcParams> pageInfo = new PageInfo<>(listDcParams);
+
+        // 4. 封装并返回结果
+        PageResult PageResult=  new PageResult(
+                pageInfo.getPageNum(),
+                pageInfo.getPageSize(),
+                pageInfo.getPages(),
+                pageInfo.getTotal(),
+                pageInfo.getList());
+
+        return AjaxResultCQY.success("查询成功", PageResult);
+    }
+
+
+    /**
+     * 新增参数配置
+     */
+    @PostMapping("/create")
+//    @PreAuthorize("@ss.hasPermi('system:params:add')")
+    public AjaxResultCQY create(@RequestBody DcParams params)
+    {
+        return iDcParamsService.create(params);
     }
 
+    @PostMapping("/info")
+//    @PreAuthorize("@ss.hasPermi('system:params:query')")
+    public AjaxResultCQY info(@RequestBody Map id)
+    {
+        String idStr = id.get("id").toString();
+        return iDcParamsService.info(new Long(idStr));
+    }
+
+
+    /**
+     * 修改参数配置
+     */
+    @PostMapping("/update")
+//    @PreAuthorize("@ss.hasPermi('system:params:edit')")
+    public AjaxResultCQY update(@RequestBody DcParams params)
+    {
+        return iDcParamsService.update(params);
+    }
+
+
 }

+ 4 - 3
gqy-admin/src/main/java/com/gqy/web/controller/document/TemplateCategoryController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 文档目录代码
@@ -111,14 +112,14 @@ public class TemplateCategoryController {
     /**
      * 获取模板分类信息
      *
-     * @param id 模板分类ID
      * @return 返回结果对象,成功则包含模板分类信息
      */
     @PostMapping("/info")
 //    @PreAuthorize("@ss.hasPermi('system:category:query')")
-    public AjaxResultCQY info(@RequestParam Long id)
+    public AjaxResultCQY info(@RequestBody Map maps)
     {
-        return templateCategoryService.selectTemplateCategoryById(id);
+        String id = maps.get("id").toString();
+        return templateCategoryService.selectTemplateCategoryById(Long.valueOf(id));
     }
 
 }

+ 25 - 6
gqy-common/src/main/java/com/gqy/common/utils/bean/BeanUtils.java

@@ -1,6 +1,7 @@
 package com.gqy.common.utils.bean;
 
 import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.lang.reflect.Method;
 import java.text.SimpleDateFormat;
@@ -182,12 +183,30 @@ public class BeanUtils extends org.springframework.beans.BeanUtils
      * 设置Bean属性值
      */
     private static void setProperty(Object bean, String propertyName, Object value) throws Exception {
-        PropertyDescriptor property = new PropertyDescriptor(propertyName, bean.getClass());
-        Method setter = property.getWriteMethod();
-        if (setter != null) {
-            Class<?> paramType = setter.getParameterTypes()[0];
-            Object convertedValue = convertValue(value, paramType);
-            setter.invoke(bean, convertedValue);
+        // ... existing code ...
+        try {
+            PropertyDescriptor property = new PropertyDescriptor(propertyName, bean.getClass());
+            Method setter = property.getWriteMethod();
+            if (setter != null) {
+                Class<?> paramType = setter.getParameterTypes()[0];
+                Object convertedValue = convertValue(value, paramType);
+                setter.invoke(bean, convertedValue);
+            }
+        } catch (IntrospectionException e) {
+            // 尝试使用另一种方式获取属性描述符
+            BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
+            PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
+            for (PropertyDescriptor pd : properties) {
+                if (pd.getName().equals(propertyName)) {
+                    Method setter = pd.getWriteMethod();
+                    if (setter != null) {
+                        Class<?> paramType = setter.getParameterTypes()[0];
+                        Object convertedValue = convertValue(value, paramType);
+                        setter.invoke(bean, convertedValue);
+                    }
+                    break;
+                }
+            }
         }
     }
 

+ 29 - 0
gqy-system/src/main/java/com/gqy/document/service/IDcParamsService.java

@@ -1,5 +1,7 @@
 package com.gqy.document.service;
 
+import com.gqy.common.core.domain.AjaxResult;
+import com.gqy.common.core.domain.AjaxResultCQY;
 import com.gqy.document.domain.DcParams;
 
 import java.util.List;
@@ -18,4 +20,31 @@ public interface IDcParamsService
      * @return 分页结果
      */
     public List<DcParams> search(DcParams params);
+
+
+    /**
+     * 新增参数配置
+     *
+     * @param params 参数配置信息
+     * @return 结果
+     */
+    public AjaxResultCQY create(DcParams params);
+
+
+    /**
+     * 获取参数配置详细信息
+     *
+     * @param id 参数ID
+     * @return 结果
+     */
+    public AjaxResultCQY info(Long id);
+
+    /**
+     * 修改参数配置
+     *
+     * @param params 参数配置信息
+     * @return 结果
+     */
+    public AjaxResultCQY update(DcParams params);
+
 }

+ 99 - 1
gqy-system/src/main/java/com/gqy/document/service/impl/DcParamsServiceImpl.java

@@ -1,10 +1,13 @@
 package com.gqy.document.service.impl;
 
+import com.gqy.common.core.domain.AjaxResult;
+import com.gqy.common.core.domain.AjaxResultCQY;
 import com.gqy.document.domain.DcParams;
 import com.gqy.document.service.IDcParamsService;
 import com.gqy.system.mapper.DcParamsMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -19,8 +22,103 @@ public class DcParamsServiceImpl implements IDcParamsService {
     @Autowired
     private DcParamsMapper dcParamsMapper;
 
-    @Override
+
+
+    /**
+     * 查询参数列表
+     *
+     * @param params 查询参数
+     * @return 分页结果
+     */
     public List<DcParams> search(DcParams params) {
         return dcParamsMapper.selectParamsList(params);
     }
+
+    /**
+     * 新增参数配置
+     *
+     * @param params 参数配置信息
+     * @return 结果
+     */
+    public AjaxResultCQY create(DcParams params) {
+
+        // 校验参数名称是否唯一
+        if (dcParamsMapper.checkNameUnique(params.getName()) != null)
+        {
+            return AjaxResultCQY.error("参数名称'" + params.getName() + "'已存在");
+        }
+
+        try {
+            // 设置默认值
+            if (params.getStatus() == null)
+            {
+                params.setStatus(5); // 默认使用中
+            }
+            if (params.getValue_type() == null)
+            {
+                params.setValue_type(1); // 默认输入框类型
+            }
+            if (params.getType() == null)
+            {
+                params.setType(1); // 默认变量类型
+            }
+
+            // 插入数据
+            int rows = dcParamsMapper.insertParams(params);
+            return rows > 0 ? AjaxResultCQY.success("新增成功") : AjaxResultCQY.error("新增失败");
+        }
+        catch (Exception e)
+        {
+            return AjaxResultCQY.error("新增参数失败:" + e.getMessage());
+        }
+
+    }
+
+    /**
+     * 根据ID查询参数配置
+     *
+     * @param id 参数ID
+     * @return 参数配置信息
+     */
+    public AjaxResultCQY info(Long id) {
+        return AjaxResultCQY.success("查询成功",dcParamsMapper.selectParamsById(id)) ;
+    }
+
+
+    /**
+     * 修改参数配置
+     *
+     * @param params 参数配置信息
+     * @return 结果
+     */
+    @Transactional
+    public AjaxResultCQY update(DcParams params)
+    {
+        try {
+            // 校验是否存在
+            if (params.getId() == null)
+            {
+                return AjaxResultCQY.error("参数ID不能为空");
+            }
+
+            // 校验参数名称是否唯一
+            if (dcParamsMapper.checkNameUnique(params.getName()) != null)
+            {
+                return AjaxResultCQY.error("参数名称'" + params.getName() + "'已存在");
+            }
+
+            // 更新数据
+            int rows = dcParamsMapper.updateParams(params);
+            if (rows > 0)
+            {
+                return AjaxResultCQY.success("修改成功");
+            }
+            return AjaxResultCQY.error("修改参数配置失败,请联系管理员");
+        }
+        catch (Exception e)
+        {
+            return AjaxResultCQY.error("修改参数配置失败:" + e.getMessage());
+        }
+    }
+
 }

+ 32 - 0
gqy-system/src/main/java/com/gqy/system/mapper/DcParamsMapper.java

@@ -20,4 +20,36 @@ public interface DcParamsMapper {
      */
     public List<DcParams> selectParamsList(DcParams params);
 
+
+    /**
+     * 新增参数配置
+     *
+     * @param params 参数配置信息
+     * @return 结果
+     */
+    public int insertParams(DcParams params);
+
+    /**
+     * 校验参数名称是否唯一
+     *
+     * @param name 参数名称
+     * @return 结果
+     */
+    public DcParams checkNameUnique(String name);
+
+    /**
+     * 根据ID查询参数配置
+     *
+     * @param id 参数ID
+     * @return 参数配置信息
+     */
+    public DcParams selectParamsById(Long id);
+
+    /**
+     * 修改参数配置
+     *
+     * @param params 参数配置信息
+     * @return 结果
+     */
+    public int updateParams(DcParams params);
 }

+ 58 - 0
gqy-system/src/main/resources/mapper/document/DcParamsMapper.xml

@@ -40,4 +40,62 @@
         order by id desc
     </select>
 
+
+    <!-- 新增参数配置 -->
+    <insert id="insertParams" parameterType="DcParams" useGeneratedKeys="true" keyProperty="id">
+        insert into dc_params (
+            code,
+            name,
+            value,
+            value_type,
+            value_item,
+            intro,
+            create_time,
+            type,
+            status
+        ) values (
+                     #{code},
+                     #{name},
+                     #{value},
+                     #{value_type},
+                     #{value_item},
+                     #{intro},
+                     sysdate(),
+                     #{type},
+                     #{status}
+                 )
+    </insert>
+
+    <!-- 校验参数名称是否唯一 -->
+    <select id="checkNameUnique" parameterType="String" resultMap="ParamsResult">
+        select id, name from dc_params
+        where name = #{name} and status != 4
+        limit 1
+    </select>
+
+
+    <!-- 根据ID查询参数配置 -->
+    <select id="selectParamsById" parameterType="Long" resultMap="ParamsResult">
+        select id, code, type, name, intro, value_type, value_item, value, create_time, status
+        from dc_params
+        where id = #{id}
+    </select>
+
+    <!-- 修改参数配置 -->
+    <update id="updateParams" parameterType="DcParams">
+        update dc_params
+        <set>
+            <if test="code != null">code = #{code},</if>
+            <if test="type != null">type = #{type},</if>
+            <if test="intro != null">intro = #{intro},</if>
+            <if test="name != null">name = #{name},</if>
+            <if test="value_type != null">value_type = #{value_type},</if>
+            <if test="value_item != null">value_item = #{value_item},</if>
+            <if test="value != null">value = #{value},</if>
+            <if test="status != null">status = #{status},</if>
+        </set>
+        where id = #{id}
+    </update>
+
+
 </mapper>