Kaynağa Gözat

场景类型模块

wangyangyang 4 yıl önce
ebeveyn
işleme
28c2b25b77

+ 109 - 0
sms_water/src/main/java/com/huaxu/controller/SceneTypeController.java

@@ -0,0 +1,109 @@
+package com.huaxu.controller;
+
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.LoginUser;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.util.UserUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Date;
+import org.springframework.web.bind.annotation.*;
+import com.huaxu.entity.SceneTypeEntity;
+import com.huaxu.service.SceneTypeService;
+
+/**
+ * 场景类型页面控制器
+ * @author WYY
+ * @date 2020-11-17 19:31
+ */
+@Controller
+@RequestMapping("/scenetype/scenetype")
+@Api(tags = "场景类型管理")
+public class SceneTypeController {
+
+    @Autowired
+    private SceneTypeService sceneTypeService;
+
+    @ApiOperation(value = "按父级节点查询子节点信息")
+    @RequestMapping(value = "/selectListByParentId", method = RequestMethod.GET)
+    @ResponseBody
+    public AjaxMessage<List<SceneTypeEntity>> list(@ApiParam(value = "父级ID", required = true) @RequestParam Long id) {
+        SceneTypeEntity sceneType = new SceneTypeEntity();
+        sceneType.setParentScenetypeId(id);
+        List<SceneTypeEntity> page = sceneTypeService.findListByParentID(sceneType);
+        return new AjaxMessage<>(ResultStatus.OK, page);
+    }
+
+    @ApiOperation(value = "查询所有场景类型")
+    @RequestMapping(value = "/selectList", method = RequestMethod.GET)
+    @ResponseBody
+    public AjaxMessage<List<SceneTypeEntity>> selectAllList(@ApiParam(value = "名称", required = false) @RequestParam(required = false) String name) {
+        SceneTypeEntity sceneType = new SceneTypeEntity();
+        sceneType.setSceneTypeName(name);
+        List<SceneTypeEntity> page = sceneTypeService.findList(sceneType);
+        return new AjaxMessage<>(ResultStatus.OK, page);
+    }
+
+    /**
+     * 新增
+     */
+    @ApiOperation(value = "新增")
+    @RequestMapping(value = "/add", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<Integer> addSceneType(@ApiParam(value = "场景类型", required = true) @RequestBody SceneTypeEntity sceneType) {
+        int result = sceneTypeService.addSceneType(sceneType) ? 1 : 0;
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+    /**
+     * 批量新增
+     */
+    @RequestMapping(value = "/batchAdd", method = RequestMethod.POST)
+    @ResponseBody
+    @ApiOperation(value = "批量新增或修改")
+    public AjaxMessage<Integer> addSceneType(@ApiParam(value = "场景类型", required = true) @RequestBody ArrayList<SceneTypeEntity> sceneTypes) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        for (SceneTypeEntity item : sceneTypes) {
+            item.setTenantId(currentUser.getTenantId());
+            item.setStatus(1);
+        }
+        int result = sceneTypeService.saveOrUpdateBatch(sceneTypes) ? 1 : 0;
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+    /**
+     * 修改保存场景类型
+     */
+    @RequestMapping(value = "/edit", method = RequestMethod.POST)
+    @ResponseBody
+    @ApiOperation(value = "修改")
+    public AjaxMessage<Integer> editSceneType(@ApiParam(value = "场景类型", required = true) @RequestBody SceneTypeEntity sceneType) {
+        int result = sceneTypeService.updateSceneTypeById(sceneType) ? 1 : 0;
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+    /**
+     * 删除
+     */
+    @ApiOperation(value = "批量删除")
+    @RequestMapping(value = "/deleteByIds", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<Integer> del(@ApiParam(value = "场景类型ID", required = true) @RequestBody Long[] ids) {
+        int result = sceneTypeService.delSceneTypeByIds(ids) ? 1 : 0;
+        return new AjaxMessage<>(ResultStatus.OK, result);
+    }
+
+    @ApiOperation(value = "按ID查询场景类型")
+    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
+    @ResponseBody
+    public AjaxMessage<SceneTypeEntity> selectById(@ApiParam(value = "ID", required = true) @RequestParam Long id) {
+        SceneTypeEntity sceneTypeEntity = sceneTypeService.findSceneTypeById(id);
+        return new AjaxMessage<>(ResultStatus.OK, sceneTypeEntity);
+    }
+}

+ 33 - 0
sms_water/src/main/java/com/huaxu/dao/SceneTypeMapper.java

@@ -0,0 +1,33 @@
+package com.huaxu.dao;
+
+import com.huaxu.entity.SceneTypeEntity;
+import java.io.Serializable;
+import java.util.List;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+/**
+ *
+ * sms_scene_typeDAO接口
+ * @author: WYY
+ * @date 2020-11-17 19:31
+ */
+@Mapper
+public interface SceneTypeMapper extends BaseMapper<SceneTypeEntity> {
+
+	/**
+     * 自定义分页查询
+     * @param  page 
+     * @param  sceneTypeEntity 实体类
+     */
+     Page<SceneTypeEntity> findPage(IPage<SceneTypeEntity> page, @Param("sceneType") SceneTypeEntity sceneTypeEntity);
+
+     SceneTypeEntity findSceneTypeById(Serializable id);
+
+
+     List<SceneTypeEntity> findList(SceneTypeEntity sceneTypeEntity);
+
+     /**删除相关方法  使用mybatis-plus集成的 **/
+}

+ 83 - 0
sms_water/src/main/java/com/huaxu/entity/SceneTypeEntity.java

@@ -0,0 +1,83 @@
+package com.huaxu.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.huaxu.model.ProgramItem;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * sms_scene_type
+ * @author: WYY
+ * @date 2020-11-17 19:31
+ */
+@Data
+@TableName("sms_scene_type")
+public class SceneTypeEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    @ApiModelProperty(value = "主键")
+	@TableId(type = IdType.AUTO)
+    private Long id;
+
+    /** 租户标识 */
+    @ApiModelProperty(value = "租户标识")
+    private String tenantId;
+
+    /** 上级场景类型 */
+    @ApiModelProperty(value = "上级场景类型")
+    private Long parentScenetypeId;
+
+    /** 场景类型名称 */
+    @ApiModelProperty(value = "场景类型名称")
+    private String sceneTypeName;
+
+    /** 数据删除标记 */
+    @ApiModelProperty(value = "数据删除标记")
+    @TableLogic
+    private Integer status;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "2020-12-12 12:12:12")
+    @ApiModelProperty(value = "创建时间",example = "2020-12-12 12:12:12")
+    private Date dateCreate;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    /** 更新时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "2020-12-12 12:12:12")
+    @ApiModelProperty(value = "更新时间")
+    private Date dateUpdate;
+
+    @ApiModelProperty(value ="权限",hidden = true)
+    @TableField(exist = false)
+    @JsonIgnore
+    private List<ProgramItem> programItems;
+
+    @ApiModelProperty(value="用户权限类型")
+    @TableField(exist = false)
+    @JsonIgnore
+    private Integer permissonType;
+
+    /** 用户类型 */
+    @ApiModelProperty(value = "用户类型(-9999 超管 -999普通用户 2普通用户)")
+    @TableField(exist = false)
+    @JsonIgnore
+    private String userType;
+
+
+    @ApiModelProperty(value = "子类", position = 100)
+    @TableField(exist = false)
+    private List<SceneTypeEntity> children;
+
+}

+ 115 - 0
sms_water/src/main/java/com/huaxu/service/SceneTypeService.java

@@ -0,0 +1,115 @@
+package com.huaxu.service;
+
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dao.SceneTypeMapper;
+import com.huaxu.entity.SceneTypeEntity;
+import com.huaxu.model.LoginUser;
+import com.huaxu.util.UserUtil;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+
+import javax.annotation.Resource;
+
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Arrays;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+/**
+ * 场景类型Service接口
+ *
+ * @author: WYY
+ * @date 2020-11-17 19:31
+ */
+@Service
+public class SceneTypeService extends ServiceImpl<SceneTypeMapper, SceneTypeEntity> {
+
+    @Resource
+    private SceneTypeMapper sceneTypeMapper;
+
+    /**
+     * 查列表
+     */
+    public List<SceneTypeEntity> findListByParentID(SceneTypeEntity sceneTypeEntity) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        sceneTypeEntity.setTenantId(currentUser.getTenantId());
+        List<SceneTypeEntity> sceneTypeEntities = sceneTypeMapper.findList(sceneTypeEntity);
+        return sceneTypeEntities;
+    }
+    /**
+     * 查列表
+     */
+    public List<SceneTypeEntity> findList(SceneTypeEntity sceneTypeEntity) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        sceneTypeEntity.setTenantId(currentUser.getTenantId());
+        List<SceneTypeEntity> sceneTypeEntities = sceneTypeMapper.findList(sceneTypeEntity);
+        List<SceneTypeEntity> sceneTypeTree = getSceneTypeTree(sceneTypeEntities, Long.valueOf(0), 1);
+        return sceneTypeTree;
+    }
+
+    public static List<SceneTypeEntity> getSceneTypeTree(List<SceneTypeEntity> list, Long id, Integer leve) {
+        List<SceneTypeEntity> temList = newArrayList();
+        if (list != null) {
+            for (SceneTypeEntity sceneTypeEntity : list) {
+                if (id.equals(sceneTypeEntity.getParentScenetypeId())) {
+                    List<SceneTypeEntity> chidren = getSceneTypeTree(list, sceneTypeEntity.getId(), ++leve);
+                    SceneTypeEntity temMeanu = new SceneTypeEntity();
+                    BeanUtils.copyProperties(sceneTypeEntity, temMeanu);
+                    temMeanu.setChildren(chidren);
+                    temList.add(temMeanu);
+                    leve--;
+                }
+
+            }
+        }
+        if (temList.size() > 0) {
+            return temList;
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * 批量删除
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public boolean delSceneTypeByIds(Long[] ids) {
+        return this.removeByIds(Arrays.asList(ids));
+    }
+    /**
+     * 保存
+     */
+    public boolean addSceneType(SceneTypeEntity sceneType) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        sceneType.setTenantId(currentUser.getTenantId());
+        sceneType.setStatus(1);
+        if (this.save(sceneType)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 修改根据ID
+     */
+    public boolean updateSceneTypeById(SceneTypeEntity sceneType) {
+        if (this.updateById(sceneType)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 根居ID获取对象
+     */
+    public SceneTypeEntity findSceneTypeById(Long id) {
+        return sceneTypeMapper.findSceneTypeById(id);
+    }
+}

+ 71 - 0
sms_water/src/main/resources/mapper/SceneTypeMapper.xml

@@ -0,0 +1,71 @@
+<?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.huaxu.dao.SceneTypeMapper">
+    <resultMap type="SceneTypeEntity" id="SceneTypeResult">
+        <result property="id" column="id"/>
+        <result property="tenantId" column="tenant_id"/>
+        <result property="parentScenetypeId" column="parent_scenetype_id"/>
+        <result property="sceneTypeName" column="scene_type_name"/>
+        <result property="remark" column="remark"/>
+        <result property="status" column="status"/>
+        <result property="dateCreate" column="date_create"/>
+        <result property="createBy" column="create_by"/>
+        <result property="dateUpdate" column="date_update"/>
+        <result property="updateBy" column="update_by"/>
+    </resultMap>
+    <!--  实体栏位  -->
+    <sql id="sceneTypeColumns">
+         a.id as "id" ,
+         a.tenant_id as "tenantId" ,
+         a.parent_scenetype_id as "parentScenetypeId" ,
+         a.scene_type_name as "sceneTypeName" ,
+         a.remark as "remark" ,
+         a.status as "status" ,
+         a.date_create as "dateCreate" ,
+         a.create_by as "createBy" ,
+         a.date_update as "dateUpdate" ,
+         a.update_by as "updateBy" 
+     </sql>
+    <!--  根据主键获取实体   -->
+    <select id="findSceneTypeById" resultType="com.huaxu.entity.SceneTypeEntity">
+        SELECT
+        <include refid="sceneTypeColumns"/>
+        FROM sms_scene_type a
+        WHERE a.id = #{id} and  a.status = 1
+    </select>
+
+    <!--  根据获取实体List   -->
+    <select id="findList" resultType="com.huaxu.entity.SceneTypeEntity">
+        SELECT
+        <include refid="sceneTypeColumns"/>
+        FROM sms_scene_type a
+        <where>
+            a.status = 1
+            <if test="tenantId != null  and tenantId != ''">and a.tenant_id = #{tenantId}</if>
+            <if test="parentScenetypeId != null ">and a.parent_scenetype_id = #{parentScenetypeId}</if>
+            <if test="sceneTypeName != null  and sceneTypeName != ''">
+                and a.scene_type_name LIKE concat('%',#{sceneTypeName},'%')
+            </if>
+        </where>
+        order  by a.date_create
+    </select>
+
+    <!--  根据获取实体 page   -->
+    <select id="findPage" resultType="com.huaxu.entity.SceneTypeEntity">
+        SELECT
+        <include refid="sceneTypeColumns"/>
+        FROM sms_scene_type a
+        <where>
+            a.status = 1
+            <if test="sceneType.tenantId != null  and sceneType.tenantId != ''">
+            and a.tenant_id = #{sceneType.tenantId}
+            </if>
+            <if test="sceneType.sceneTypeName != null  and sceneType.sceneTypeName != ''">
+                and a.scene_type_name LIKE concat('%',#{sceneType.sceneTypeName},'%')
+            </if>
+        </where>
+        order  by a.date_create
+    </select>
+</mapper>