Browse Source

组织机构管理

jz.kai 4 years ago
parent
commit
736ca6c32a

+ 18 - 0
common/src/main/java/com/jpsoft/supervision/modules/base/dao/OrganizationDAO.java

@@ -0,0 +1,18 @@
+package com.jpsoft.supervision.modules.base.dao;
+
+import java.util.List;
+import org.springframework.stereotype.Repository;
+import com.jpsoft.supervision.modules.base.entity.Organization;
+import java.util.Map;
+import com.jpsoft.supervision.modules.common.dto.Sort;
+
+@Repository
+public interface OrganizationDAO {
+	int insert(Organization entity);
+	int update(Organization entity);
+	int exist(String id);
+	Organization get(String id);
+	int delete(String id);
+	List<Organization> list();
+	List<Organization> search(Map<String,Object> searchParams,List<Sort> sortList);
+}

+ 43 - 0
common/src/main/java/com/jpsoft/supervision/modules/base/entity/Organization.java

@@ -0,0 +1,43 @@
+package com.jpsoft.supervision.modules.base.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.math.BigDecimal;
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+  描述:base_organization的实体类
+ */
+@Data
+@ApiModel(value = "base_organization的实体类")
+public class Organization {
+        @ApiModelProperty(value = "菜单编号")
+    private String id;
+        @ApiModelProperty(value = "机构名称")
+    private String name;
+        @ApiModelProperty(value = "上级机构")
+    private String parentId;
+        @ApiModelProperty(value = "上级机构")
+    private String parentName;
+        @ApiModelProperty(value = "机构代码")
+    private String code;
+        @ApiModelProperty(value = "")
+    private Boolean delFlag;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "")
+    private Date createTime;
+        @ApiModelProperty(value = "")
+    private String createBy;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "")
+    private Date updateTime;
+        @ApiModelProperty(value = "")
+    private String updateBy;
+}

+ 17 - 0
common/src/main/java/com/jpsoft/supervision/modules/base/service/OrganizationService.java

@@ -0,0 +1,17 @@
+package com.jpsoft.supervision.modules.base.service;
+
+import java.util.List;
+import java.util.Map;
+import com.jpsoft.supervision.modules.base.entity.Organization;
+import com.github.pagehelper.Page;
+import com.jpsoft.supervision.modules.common.dto.Sort;
+
+public interface OrganizationService {
+	Organization get(String id);
+	boolean exist(String id);
+	int insert(Organization model);
+	int update(Organization model);
+	int delete(String id);
+	List<Organization> list();
+	Page<Organization> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
+}

+ 70 - 0
common/src/main/java/com/jpsoft/supervision/modules/base/service/impl/OrganizationServiceImpl.java

@@ -0,0 +1,70 @@
+package com.jpsoft.supervision.modules.base.service.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.annotation.Resource;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.jpsoft.supervision.modules.base.dao.OrganizationDAO;
+import com.jpsoft.supervision.modules.base.entity.Organization;
+import com.jpsoft.supervision.modules.base.service.OrganizationService;
+import com.github.pagehelper.Page;
+import com.jpsoft.supervision.modules.common.dto.Sort;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="organizationService")
+public class OrganizationServiceImpl implements OrganizationService {
+	@Resource(name="organizationDAO")
+	private OrganizationDAO organizationDAO;
+
+	@Override
+	public Organization get(String id) {
+		// TODO Auto-generated method stub
+		return organizationDAO.get(id);
+	}
+
+	@Override
+	public int insert(Organization model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+		
+		return organizationDAO.insert(model);
+	}
+
+	@Override
+	public int update(Organization model) {
+		// TODO Auto-generated method stub
+		return organizationDAO.update(model);		
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return organizationDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = organizationDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<Organization> list() {
+		// TODO Auto-generated method stub
+		return organizationDAO.list();
+	}
+		
+	@Override
+	public Page<Organization> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+        Page<Organization> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            organizationDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+}

+ 115 - 0
common/src/main/resources/mapper/base/Organization.xml

@@ -0,0 +1,115 @@
+<?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">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.supervision.modules.base.dao.OrganizationDAO">
+	<resultMap id="OrganizationMap" type="com.jpsoft.supervision.modules.base.entity.Organization">
+		<id property="id" column="id_" />
+			<result property="name" column="name_" />
+			<result property="parentId" column="parent_id" />
+			<result property="parentName" column="parent_name"/>
+			<result property="code" column="code_" />
+			<result property="delFlag" column="del_flag" />
+			<result property="createTime" column="create_time" />
+			<result property="createBy" column="create_by" />
+			<result property="updateTime" column="update_time" />
+			<result property="updateBy" column="update_by" />
+			</resultMap>
+	<insert id="insert" parameterType="com.jpsoft.supervision.modules.base.entity.Organization">
+	<!--
+	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+		select sys_guid() from dual
+	</selectKey>
+	-->
+	<![CDATA[
+		insert into base_organization
+	    (id_,name_,parent_id,code_,del_flag,create_time,create_by,update_time,update_by)
+		values
+		(
+#{id,jdbcType=VARCHAR}
+,#{name,jdbcType=VARCHAR}
+,#{parentId,jdbcType=VARCHAR}
+,#{code,jdbcType=VARCHAR}
+,#{delFlag,jdbcType= NUMERIC }
+,#{createTime,jdbcType= TIMESTAMP }
+,#{createBy,jdbcType=VARCHAR}
+,#{updateTime,jdbcType= TIMESTAMP }
+,#{updateBy,jdbcType=VARCHAR}
+		)
+	]]>
+	</insert>
+	<delete id="delete" parameterType="string">
+		delete from base_organization where id_=#{id,jdbcType=VARCHAR}
+	</delete>
+	<update id="update" parameterType="com.jpsoft.supervision.modules.base.entity.Organization">
+		update base_organization
+		<set>
+				<if test="name!=null">
+		name_=#{name,jdbcType=VARCHAR},
+		</if>
+				<if test="parentId!=null">
+		parent_id=#{parentId,jdbcType=VARCHAR},
+		</if>
+				<if test="code!=null">
+		code_=#{code,jdbcType=VARCHAR},
+		</if>
+				<if test="delFlag!=null">
+		del_flag=#{delFlag,jdbcType= NUMERIC },
+		</if>
+				<if test="createTime!=null">
+		create_time=#{createTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="createBy!=null">
+		create_by=#{createBy,jdbcType=VARCHAR},
+		</if>
+				<if test="updateTime!=null">
+		update_time=#{updateTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="updateBy!=null">
+		update_by=#{updateBy,jdbcType=VARCHAR},
+		</if>
+		</set>
+	where id_=#{id}
+	</update>
+	<select id="get" parameterType="string" resultMap="OrganizationMap">
+		select 
+id_,name_,parent_id,code_,del_flag,create_time,create_by,update_time,update_by		from base_organization where id_=#{0}
+	</select>
+	<select id="exist" parameterType="string" resultType="int">
+		select count(*) from base_organization where id_=#{0}
+	</select>
+	<select id="list" resultMap="OrganizationMap">
+		select * from base_organization
+	</select>
+	<select id="search" parameterType="hashmap" resultMap="OrganizationMap">
+		<![CDATA[
+			SELECT
+				a.*,b.name_ AS parent_name
+			FROM
+				base_organization a
+			LEFT JOIN base_organization b ON a.parent_id = b.id_
+		]]>
+		<where>
+			a.del_flag = 0
+			<if test="searchParams.id != null">
+				and a.id_ = #{searchParams.id}
+			</if>
+			<if test="searchParams.name != null">
+				and a.name_ like #{searchParams.name}
+			</if>
+			<if test="searchParams.excludeId != null">
+				<![CDATA[
+				and a.id_ <> #{searchParams.excludeId}
+				]]>
+			</if>
+			<if test="searchParams.parentId != null">
+				<![CDATA[
+				and a.parent_id = #{searchParams.parentId}
+				]]>
+			</if>
+		</where>
+		<foreach item="sort" collection="sortList"  open="order by" separator=",">
+	        ${sort.name} ${sort.order}
+	 	</foreach>
+	</select>
+</mapper>

+ 268 - 0
web/src/main/java/com/jpsoft/supervision/modules/base/controller/OrganizationController.java

@@ -0,0 +1,268 @@
+package com.jpsoft.supervision.modules.base.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.supervision.modules.common.utils.PojoUtils;
+import com.jpsoft.supervision.modules.common.dto.Sort;
+import com.jpsoft.supervision.modules.common.dto.MessageResult;
+import com.jpsoft.supervision.modules.base.entity.Organization;
+import com.jpsoft.supervision.modules.base.service.OrganizationService;
+import com.jpsoft.supervision.modules.sys.entity.DataDictionary;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@RestController
+@RequestMapping("/base/organization")
+@Api(description = "组织机构管理")
+public class OrganizationController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private OrganizationService organizationService;
+
+    @ApiOperation(value="创建空记录")
+    @GetMapping("create")
+    public MessageResult<Organization> create(){
+        MessageResult<Organization> msgResult = new MessageResult<>();
+
+        Organization organization = new Organization();
+
+        msgResult.setData(organization);
+        msgResult.setResult(true);
+
+        return msgResult;
+    }
+    
+    @ApiOperation(value="添加信息")
+    @PostMapping("add")
+    public MessageResult<Organization> add(@RequestBody Organization organization,@RequestAttribute String subject){
+        MessageResult<Organization> msgResult = new MessageResult<>();
+
+        try {
+            organization.setId(UUID.randomUUID().toString());
+            organization.setDelFlag(false);
+            organization.setCreateBy(subject);
+            organization.setCreateTime(new Date());
+
+            Organization org = organizationService.get(organization.getParentId());
+            if(org != null){
+                organization.setCode(org.getCode() + "," + organization.getId());
+            }
+            else{
+                organization.setCode(organization.getId());
+            }
+            
+            int affectCount = organizationService.insert(organization);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(organization);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库添加失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="获取信息")
+    @GetMapping("edit/{id}")
+    public MessageResult<Organization> edit(@PathVariable("id") String id){
+        MessageResult<Organization> msgResult = new MessageResult<>();
+
+        try {
+            Organization organization = organizationService.get(id);
+
+            if (organization != null) {
+                msgResult.setResult(true);
+                msgResult.setData(organization);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库不存在该记录!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="更新用户")
+    @PostMapping("update")
+    public MessageResult<Organization> update(@RequestBody Organization organization,@RequestAttribute String subject){
+        MessageResult<Organization> msgResult = new MessageResult<>();
+
+        try {
+            organization.setUpdateBy(subject);
+            organization.setUpdateTime(new Date());
+            
+            int affectCount = organizationService.update(organization);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(organization);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库更新失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+	@ApiOperation(value="删除")
+    @PostMapping("delete/{id}")
+    public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            Organization organization = organizationService.get(id);
+            organization.setDelFlag(true);
+            organization.setUpdateBy(subject);
+            organization.setUpdateTime(new Date());
+
+            int affectCount = organizationService.update(organization);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("删除失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+
+    @ApiOperation(value="批量删除")
+    @PostMapping("batchDelete")
+    public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            int affectCount = 0;
+
+            for (String id : idList) {
+                Organization organization = organizationService.get(id);
+                organization.setDelFlag(true);
+                organization.setUpdateBy(subject);
+                organization.setUpdateTime(new Date());
+
+                affectCount += organizationService.update(organization);
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("删除失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    public MessageResult<Map> pageList(
+            String name,
+            String parentId,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestAttribute String subject){
+
+        //当前用户ID
+        System.out.println(subject);
+
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("id_","asc"));
+
+        if (!"null".equals(parentId) && StringUtils.isNotEmpty(parentId)) {
+            searchParams.put("parentId",parentId);
+        }
+
+        if (StringUtils.isNotEmpty(name)) {
+            searchParams.put("name","%" + name + "%");
+        }
+
+        Page<Organization> page = organizationService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtils.pageWrapper(page));
+
+        return msgResult;
+    }
+
+    @ApiOperation(value = "查询")
+    @RequestMapping(value = "query", method = RequestMethod.POST)
+    public MessageResult<List> query(
+            String keywords,
+            String excludeId,
+            @RequestAttribute String subject) {
+        MessageResult<List> msgResult = new MessageResult<>();
+
+        Map<String, Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("a.create_time", "asc"));
+
+        if (StringUtils.isNotEmpty(keywords)) {
+            searchParams.put("name", "%" + keywords + "%");
+        }
+
+        if (StringUtils.isNotEmpty(excludeId)) {
+            searchParams.put("excludeId", excludeId);
+        }
+
+        Page<Organization> page = organizationService.pageSearch(searchParams,1,1000,false,sortList);
+        List<Organization> organizationList = page.getResult();
+        msgResult.setResult(true);
+        msgResult.setData(organizationList);
+
+        return msgResult;
+    }
+}