فهرست منبع

应用分类与算法平台保持一致

Huhu 2 سال پیش
والد
کامیت
44b63976a9

+ 81 - 0
src/main/java/io/renren/modules/generator/controller/CategoryController.java

@@ -0,0 +1,81 @@
+package io.renren.modules.generator.controller;
+
+import io.renren.common.annotation.SysLog;
+import io.renren.common.utils.PageUtils;
+import io.renren.common.utils.R;
+import io.renren.common.validator.ValidatorUtils;
+import io.renren.datasource.annotation.DataSource;
+import io.renren.modules.generator.entity.CategoryEntity;
+import io.renren.modules.generator.service.CategoryService;
+import io.renren.modules.sys.controller.AbstractController;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/category")
+@DataSource("slave2")
+public class CategoryController extends AbstractController {
+    @Autowired
+    private CategoryService categoryService;
+
+    /**
+     * 类别列表
+     * 不返回完全,返回一页的数据
+     */
+    @GetMapping("/list")
+    @RequiresPermissions("sys:category:list")
+    public R list(@RequestParam Map<String, Object> params){
+
+        PageUtils page = categoryService.queryPage(params);
+
+        return R.ok().put("page", page);
+    }
+
+    /**
+     * 类别列表
+     * 用于其他数据页面中对,所有类别的获取.
+     * 如果想要设置权限,打开@RequiresPermissions
+     */
+    @GetMapping("/select")
+//    @RequiresPermissions("sys:category:select")
+    public R select(){
+        List<CategoryEntity> list = (List<CategoryEntity>) categoryService.list();
+        System.out.println("所有类别");
+        for (CategoryEntity categoryEntity:list){
+            System.out.println(categoryEntity.getCategoryName());
+        }
+        return R.ok().put("list", list);
+    }
+
+    /**
+     * 删除类别
+     */
+    @SysLog("删除类别")
+    @PostMapping("/delete")
+    @RequiresPermissions("sys:category:delete")
+    public R delete(@RequestBody Long[] categoryIds){
+        categoryService.deleteBatch(categoryIds);
+
+        return R.ok();
+    }
+
+    /**
+     * 保存类别
+     */
+    @SysLog("保存类别")
+    @PostMapping("/save")
+    @RequiresPermissions("sys:category:save")
+    public R save(@RequestBody CategoryEntity category){
+        ValidatorUtils.validateEntity(category);
+        List<CategoryEntity> list = (List<CategoryEntity>) categoryService.list();
+        for(CategoryEntity categoryEntity : list){
+            if(categoryEntity.getCategoryName().equals(category.getCategoryName())) return R.error("已存在重复类别");
+        }
+        categoryService.save(category);
+        return R.ok();
+    }
+}

+ 13 - 0
src/main/java/io/renren/modules/generator/dao/CategoryMapper.java

@@ -0,0 +1,13 @@
+package io.renren.modules.generator.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import io.renren.modules.generator.entity.CategoryEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface CategoryMapper extends BaseMapper<CategoryEntity> {
+    @Select("SELECT id FROM classification WHERE name = #{name,jdbcType=VARCHAR}")
+    Long getByName(@Param("name") String classificationtag);
+}

+ 16 - 0
src/main/java/io/renren/modules/generator/entity/CategoryEntity.java

@@ -0,0 +1,16 @@
+package io.renren.modules.generator.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("classification")
+public class CategoryEntity {
+    @TableId(value = "id")
+    private Long categoryId;
+
+    @TableField("name")
+    private String categoryName;
+}

+ 15 - 0
src/main/java/io/renren/modules/generator/service/CategoryService.java

@@ -0,0 +1,15 @@
+package io.renren.modules.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import io.renren.common.utils.PageUtils;
+import io.renren.modules.generator.entity.CategoryEntity;
+
+import java.util.Map;
+
+public interface CategoryService extends IService<CategoryEntity> {
+    PageUtils queryPage(Map<String, Object> params);
+
+    void deleteBatch(Long[] categoryIds);
+
+    Long getByName(String classificationtag);
+}

+ 47 - 0
src/main/java/io/renren/modules/generator/service/impl/CategoryServiceImpl.java

@@ -0,0 +1,47 @@
+package io.renren.modules.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import io.renren.common.utils.PageUtils;
+import io.renren.common.utils.Query;
+import io.renren.datasource.annotation.DataSource;
+import io.renren.modules.generator.dao.CategoryMapper;
+import io.renren.modules.generator.entity.CategoryEntity;
+import io.renren.modules.generator.service.CategoryService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.Map;
+
+@Service
+@DataSource("slave2")
+public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService {
+    @Autowired
+    CategoryMapper categoryMapper;
+
+    @Override
+    public PageUtils queryPage(Map<String, Object> params) {
+        String categoryName = (String)params.get("categoryName");
+        IPage<CategoryEntity> page = this.page(
+                new Query<CategoryEntity>().getPage(params),
+                new QueryWrapper<CategoryEntity>()
+                        .like(StringUtils.isNotBlank(categoryName),"name", categoryName)
+        );
+        return new PageUtils(page);
+
+    }
+
+    @Override
+    public void deleteBatch(Long[] categoryIds) {
+        this.removeByIds(Arrays.asList(categoryIds));
+    }
+
+    @Override
+    public Long getByName(String classificationtag) {
+
+        return categoryMapper.getByName(classificationtag);
+    }
+}

+ 1 - 1
src/main/java/io/renren/modules/kubesphere/config/KubeSphereConfig.java

@@ -22,7 +22,7 @@ public class KubeSphereConfig {
 
     public static class URL {
 
-        private static final String host = KubeSphereConfig.kubesphereUrl;
+        private static final String host = "http://42.192.195.253:30881";
         // s2i相关url
         public static final String S2I_BUILDER_URL = host + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2ibuilders";
         public static final String S2I_CREATE_BINARY_QUERY_URL = host + "/apis/devops.kubesphere.io/v1alpha1/namespaces/mkcloud/s2ibinaries";

+ 60 - 0
src/main/resources/mapper/generator/CategoryMapper.xml

@@ -0,0 +1,60 @@
+<?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="io.renren.modules.generator.dao.CategoryMapper">
+    <resultMap id="BaseResultMap" type="io.renren.modules.generator.entity.CategoryEntity">
+        <id column="id" jdbcType="INTEGER" property="categoryId" />
+        <result column="name" jdbcType="VARCHAR" property="categoryName" />
+    </resultMap>
+    <sql id="Base_Column_List">
+      id, name
+    </sql>
+    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List" />
+        from classification
+        where id = #{categoryId,jdbcType=INTEGER}
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+    delete from classification
+    where id = #{categoryId,jdbcType=INTEGER}
+  </delete>
+    <insert id="insert" parameterType="io.renren.modules.generator.entity.CategoryEntity">
+    insert into classification (id, name)
+    values (#{categoryId,jdbcType=INTEGER}, #{categoryName,jdbcType=VARCHAR})
+  </insert>
+    <insert id="insertSelective" parameterType="io.renren.modules.generator.entity.CategoryEntity">
+        insert into classification
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="categoryId != null">
+                id,
+            </if>
+            <if test="categoryName != null">
+                name,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="categoryId != null">
+                #{id,jdbcType=INTEGER},
+            </if>
+            <if test="categoryName != null">
+                #{name,jdbcType=VARCHAR},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="io.renren.modules.generator.entity.CategoryEntity">
+        update classification
+        <set>
+            <if test="categoryName != null">
+                name = #{categoryName,jdbcType=VARCHAR},
+            </if>
+        </set>
+        where id = #{categoryId,jdbcType=INTEGER}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="io.renren.modules.generator.entity.CategoryEntity">
+    update classification
+    set name = #{categoryName,jdbcType=VARCHAR}
+    where id = #{categoryId,jdbcType=INTEGER}
+  </update>
+</mapper>