zouxuan 5 年之前
父节点
当前提交
325cdf85be

+ 17 - 21
mec-web/src/main/java/com/ym/mec/web/controller/OrganizationController.java

@@ -13,49 +13,45 @@ import org.springframework.web.bind.annotation.*;
 import java.util.Date;
 
 @RequestMapping("organization")
-@Api(tags = "组织机构服务")
+@Api(tags = "分部服务")
 @RestController
 public class OrganizationController extends BaseController {
 
     @Autowired
     private OrganizationService organizationService;
 
-    @ApiOperation(value = "分页查询组织机构树状列表")
-    @PostMapping("/queryPage")
-    public Object queryPage(OrganizationQueryInfo queryInfo){
-        return succeed(organizationService.queryTreePage(queryInfo));
+    @ApiOperation(value = "分页查询分部列表")
+    @GetMapping("/queryPage")
+    public Object queryPage(@RequestBody(required = false) OrganizationQueryInfo queryInfo){
+        if(queryInfo == null){
+            queryInfo = new OrganizationQueryInfo();
+        }
+        return succeed(organizationService.queryPage(queryInfo));
     }
 
-    @ApiOperation(value = "新增机构")
+    @ApiOperation(value = "新增分部")
     @PostMapping("/add")
     public Object add(@RequestBody Organization organization){
-        Organization organizationByCode = organizationService.findByCode(organization.getCode());
-        if(organizationByCode != null){
-            return failed("组织机构代码已经存在,请更改");
-        }
         return succeed(organizationService.insert(organization));
     }
 
-    @ApiOperation(value = "根据机构编号删除机构")
-    @DeleteMapping("/del/{id}")
-    public Object del(@ApiParam(value = "组织编号", required = true) @PathVariable("id") Integer id){
+    @ApiOperation(value = "根据分部编号删除分部")
+    @PostMapping("/del/{id}")
+    public Object del(@ApiParam(value = "分部编号", required = true) @PathVariable("id") Integer id){
         return succeed(organizationService.delete(id));
     }
 
-    @ApiOperation(value = "修改机构信息")
-    @PutMapping("/update")
+    @ApiOperation(value = "修改分部信息")
+    @PostMapping("/update")
     public Object update(@RequestBody Organization organization){
-        Organization organizationByCode = organizationService.findByCode(organization.getCode());
-        if(organizationByCode != null && !organizationByCode.getId().equals(organization.getId())){
-            return failed("组织机构代码已存在,请更改");
-        }
         organization.setUpdateTime(new Date());
         return succeed(organizationService.update(organization));
     }
 
-    @ApiOperation(value = "根据机构编号查询机构详情")
+    @ApiOperation(value = "根据分部编号查询分部详情")
     @GetMapping("/get/{id}")
-    public Object get(@ApiParam(value = "组织编号", required = true) @PathVariable("id") Integer id){
+    @ApiParam(value = "分部编号", required = true)
+    public Object get( @PathVariable("id") Integer id){
         return succeed(organizationService.get(id));
     }
 }

+ 61 - 0
mec-web/src/main/java/com/ym/mec/web/controller/SysAreaController.java

@@ -0,0 +1,61 @@
+package com.ym.mec.web.controller;
+
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.web.dal.dto.TreeDto;
+import com.ym.mec.web.service.SysAreaService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("area")
+@Api(tags = "区域服务")
+@RestController
+public class SysAreaController extends BaseController {
+
+    @Autowired
+    private SysAreaService sysAreaService;
+
+    @ApiOperation(value = "根据父节点查询区域树状列表(递归)")
+    @GetMapping("/queryTree")
+    public Object queryPage(TreeDto treeDto){
+        if(treeDto.getParentId() == 0){
+            return failed("非法参数");
+        }
+        return succeed(sysAreaService.queryTreePage(treeDto));
+    }
+
+    @ApiOperation(value = "根据父节点查询下一级子节点列表(不递归)")
+    @GetMapping("/queryChild")
+    public Object queryChild(TreeDto treeDto){
+        return succeed(sysAreaService.queryChild(treeDto));
+    }
+/*
+    @ApiOperation(value = "新增区域")
+    @PostMapping("/add")
+    public Object add(SysArea area){
+        return succeed(sysAreaService.insert(area));
+    }
+
+    @ApiOperation(value = "根据区域编号删除区域")
+    @PostMapping("/del/{id}")
+    public Object del(@ApiParam(value = "区域编号", required = true) @PathVariable("id") Integer id){
+        return succeed(sysAreaService.delete(id));
+    }
+
+    @ApiOperation(value = "修改区域信息")
+    @PostMapping("/update")
+    public Object update(SysArea area){
+        area.setUpdateTime(new Date());
+        return succeed(sysAreaService.update(area));
+    }
+
+    @ApiOperation(value = "根据区域编号查询区域详情")
+    @GetMapping("/get/{id}")
+    @ApiParam(value = "区域编号", required = true)
+    public Object get( @PathVariable("id") Integer id){
+        return succeed(sysAreaService.get(id));
+    }*/
+}

+ 0 - 7
mec-web/src/main/java/com/ym/mec/web/dal/dao/OrganizationDao.java

@@ -15,11 +15,4 @@ public interface OrganizationDao extends BaseDAO<Integer, Organization> {
      * @return
      */
     List<Organization> findByParentId(@Param("parentId") Integer parentId, @Param("delFlag") String delFlag);
-
-    /**
-     * 根据机构编码查机构
-     * @param code
-     * @return
-     */
-    Organization findByCode(@Param("code") int code);
 }

+ 12 - 1
mec-web/src/main/java/com/ym/mec/web/dal/dao/SysAreaDao.java

@@ -1,9 +1,20 @@
 package com.ym.mec.web.dal.dao;
 
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.web.dal.dto.TreeDto;
 import com.ym.mec.web.dal.entity.SysArea;
+import com.ym.mec.web.dal.enums.YesOrNoEnum;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface SysAreaDao extends BaseDAO<Integer, SysArea> {
 
-	
+    /**
+     * 根据父节点获取子节点列表
+     * @param parentId
+     * @param delFlag
+     * @return
+     */
+    List<SysArea> findRootList(@Param("parentId") Integer parentId, @Param("delFlag") YesOrNoEnum delFlag);
 }

+ 28 - 0
mec-web/src/main/java/com/ym/mec/web/dal/dto/TreeDto.java

@@ -0,0 +1,28 @@
+package com.ym.mec.web.dal.dto;
+
+import com.ym.mec.web.dal.enums.YesOrNoEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+public class TreeDto {
+    @ApiModelProperty(value = "父节点编号,默认0",required = false)
+    private Integer parentId = 0;
+
+    @ApiModelProperty(value = "节点状态,默认0未删除,1删除",required = false)
+    private YesOrNoEnum delFlag = YesOrNoEnum.NO;
+
+    public Integer getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Integer parentId) {
+        this.parentId = parentId;
+    }
+
+    public YesOrNoEnum getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(YesOrNoEnum delFlag) {
+        this.delFlag = delFlag;
+    }
+}

+ 8 - 20
mec-web/src/main/java/com/ym/mec/web/dal/entity/Organization.java

@@ -19,9 +19,9 @@ public class Organization {
 	@ApiModelProperty(value = "机构名称",required = false)
 	private String name;
 	
-	/** 机构编码 */
-	@ApiModelProperty(value = "机构编码",required = false)
-	private Integer code;
+	/** 区域编码 */
+	@ApiModelProperty(value = "区域编码",required = false)
+	private Integer areaId;
 	
 	/** 创建时间 */
 	private Date createTime;
@@ -32,10 +32,6 @@ public class Organization {
 	/** 是否删除  -1:已删除  0:正常 */
 	@ApiModelProperty(value = "是否删除  1:已删除  0:正常",required = false)
 	private YesOrNoEnum delFlag;
-	
-	/** 父节点编号 */
-	@ApiModelProperty(value = "父节点编号",required = false)
-	private Integer parentOrganId;
 
 	@ApiModelProperty(value = "成立日期",required = false)
 	private Date registerDate;
@@ -76,14 +72,6 @@ public class Organization {
 		return this.name;
 	}
 			
-	public void setCode(Integer code){
-		this.code = code;
-	}
-	
-	public Integer getCode(){
-		return this.code;
-	}
-			
 	public void setCreateTime(java.util.Date createTime){
 		this.createTime = createTime;
 	}
@@ -108,12 +96,12 @@ public class Organization {
 		this.delFlag = delFlag;
 	}
 
-	public void setParentOrganId(Integer parentOrganId){
-		this.parentOrganId = parentOrganId;
+	public Integer getAreaId() {
+		return areaId;
 	}
-	
-	public Integer getParentOrganId(){
-		return this.parentOrganId;
+
+	public void setAreaId(Integer areaId) {
+		this.areaId = areaId;
 	}
 
 	public Date getRegisterDate() {

+ 15 - 1
mec-web/src/main/java/com/ym/mec/web/dal/entity/SysArea.java

@@ -2,8 +2,11 @@ package com.ym.mec.web.dal.entity;
 
 import com.ym.mec.web.dal.enums.YesOrNoEnum;
 import io.swagger.annotations.ApiModelProperty;
+import org.apache.catalina.LifecycleState;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
+import java.util.List;
+
 /**
  * 对应数据库表(sys_area):
  */
@@ -33,7 +36,18 @@ public class SysArea {
 	/** 父节点编号 */
 	@ApiModelProperty(value = "父节点编号",required = false)
 	private Integer parentOrganId;
-	
+
+	@ApiModelProperty(value = "子节点列表",required = false)
+	private List<SysArea> areas;
+
+	public List<SysArea> getAreas() {
+		return areas;
+	}
+
+	public void setAreas(List<SysArea> areas) {
+		this.areas = areas;
+	}
+
 	public void setId(Integer id){
 		this.id = id;
 	}

+ 0 - 11
mec-web/src/main/java/com/ym/mec/web/service/OrganizationService.java

@@ -1,7 +1,5 @@
 package com.ym.mec.web.service;
 
-import org.apache.ibatis.annotations.Param;
-
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.web.dal.entity.Organization;
@@ -15,13 +13,4 @@ public interface OrganizationService extends BaseService<Integer, Organization>
      * @return
      */
     PageInfo<Organization> queryTreePage(OrganizationQueryInfo queryInfo);
-
-    /**
-     * 根据机构编码查机构
-     * @param code
-     * @return
-     */
-    Organization findByCode(@Param("code") int code);
-
-
 }

+ 17 - 0
mec-web/src/main/java/com/ym/mec/web/service/SysAreaService.java

@@ -1,8 +1,25 @@
 package com.ym.mec.web.service;
 
 import com.ym.mec.common.service.BaseService;
+import com.ym.mec.web.dal.dto.TreeDto;
 import com.ym.mec.web.dal.entity.SysArea;
+import com.ym.mec.web.dal.page.OrganizationQueryInfo;
+
+import java.util.List;
 
 public interface SysAreaService extends BaseService<Integer, SysArea> {
 
+    /**
+     * 获取区域列表
+     * @param treeDto
+     * @return
+     */
+    List<SysArea> queryTreePage(TreeDto treeDto);
+
+    /**
+     * 根据父节点查询下一级子节点列表(不递归)
+     * @param treeDto
+     * @return
+     */
+    List<SysArea> queryChild(TreeDto treeDto);
 }

+ 0 - 6
mec-web/src/main/java/com/ym/mec/web/service/impl/OrganizationServiceImpl.java

@@ -50,10 +50,4 @@ public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organizati
 		}
 			return org;
 	}
-
-	@Override
-	public Organization findByCode(int code){
-		return organizationDao.findByCode(code);
-	}
-	
 }

+ 35 - 1
mec-web/src/main/java/com/ym/mec/web/service/impl/SysAreaServiceImpl.java

@@ -3,11 +3,16 @@ package com.ym.mec.web.service.impl;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.web.dal.dao.SysAreaDao;
+import com.ym.mec.web.dal.dto.TreeDto;
+import com.ym.mec.web.dal.entity.Organization;
 import com.ym.mec.web.dal.entity.SysArea;
+import com.ym.mec.web.dal.page.OrganizationQueryInfo;
 import com.ym.mec.web.service.SysAreaService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class SysAreaServiceImpl extends BaseServiceImpl<Integer, SysArea> implements SysAreaService {
 	
@@ -18,5 +23,34 @@ public class SysAreaServiceImpl extends BaseServiceImpl<Integer, SysArea> implem
 	public BaseDAO<Integer, SysArea> getDAO() {
 		return sysAreaDao;
 	}
-	
+
+	@Override
+	public List<SysArea> queryTreePage(TreeDto treeDto) {
+		List<SysArea> sysAreas = sysAreaDao.findRootList(treeDto.getParentId(),treeDto.getDelFlag());
+		for (SysArea sysArea : sysAreas) {
+			sysArea = getTree(sysArea);
+		}
+		return sysAreas;
+	}
+
+	@Override
+	public List<SysArea> queryChild(TreeDto treeDto) {
+		return sysAreaDao.findRootList(treeDto.getParentId(),treeDto.getDelFlag());
+	}
+
+	private SysArea getTree(SysArea area){
+		//得到根节点对象
+		//获取子节点list
+		List<SysArea> sysAreas = sysAreaDao.findRootList(area.getId(), area.getDelFlag());
+		//如果存在子节点
+		if(sysAreas != null && sysAreas.size() > 0) {
+			//将子节点list放入父节点对象
+			area.setAreas(sysAreas);
+			//遍历子节点....
+			for (SysArea sysArea : sysAreas) {
+				getTree(sysArea);
+			}
+		}
+		return area;
+	}
 }

+ 6 - 22
mec-web/src/main/resources/config/mybatis/OrganizationMapper.xml

@@ -9,11 +9,10 @@
     <resultMap type="com.ym.mec.web.dal.entity.Organization" id="Organization">
         <result column="id_" property="id"/>
         <result column="name_" property="name"/>
-        <result column="code_" property="code"/>
+        <result column="area_id_" property="areaId"/>
         <result column="create_time_" property="createTime"/>
         <result column="update_time_" property="updateTime"/>
         <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
-        <result column="parent_organ_id_" property="parentOrganId"/>
         <result column="register_date_" property="registerDate"/>
         <result column="linkman_" property="linkman"/>
         <result column="mobile_" property="mobile"/>
@@ -33,13 +32,8 @@
     <!-- 向数据库增加一条记录 -->
     <insert id="insert" parameterType="com.ym.mec.web.dal.entity.Organization" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
-        <!--
-        <selectKey resultClass="int" keyProperty="id" >
-        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
-        </selectKey>
-        -->
-        INSERT INTO organization (id_,name_,code_,create_time_,update_time_,parent_organ_id_,register_date_,linkman_,mobile_,address_)
-        VALUES(#{id},#{name},#{code},now(),now(),#{parentOrganId},#{registerDate},#{linkman},#{mobile},#{address})
+        INSERT INTO organization (id_,name_,area_id_,create_time_,update_time_,register_date_,linkman_,mobile_,address_)
+        VALUES(#{id},#{name},#{areaId},now(),now(),#{registerDate},#{linkman},#{mobile},#{address})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -49,11 +43,8 @@
             <if test="delFlag != null">
                 del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
             </if>
-            <if test="parentOrganId != null">
-                parent_organ_id_ = #{parentOrganId},
-            </if>
-            <if test="code != null">
-                code_ = #{code},
+            <if test="areaId != null">
+                area_id_ = #{areaId},
             </if>
             <if test="updateTime != null">
                 update_time_ = #{updateTime},
@@ -84,11 +75,8 @@
 
     <sql id="queryPageSql">
         <where>
-            <if test="parentId != null">
-                parent_organ_id_ = #{parentId}
-            </if>
             <if test="delFlag != null">
-                AND del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+                del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
             </if>
         </where>
     </sql>
@@ -109,8 +97,4 @@
     <select id="findByParentId" resultMap="Organization">
         SELECT * FROM organization <include refid="queryPageSql"/>
     </select>
-
-    <select id="findByCode" resultMap="Organization">
-        SELECT * FROM organization WHERE code = #{code}
-    </select>
 </mapper>

+ 4 - 0
mec-web/src/main/resources/config/mybatis/SysAreaMapper.xml

@@ -76,4 +76,8 @@
     <select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM sys_area
 	</select>
+    <select id="findRootList" resultMap="SysArea">
+        SELECT * FROM sys_area WHERE parent_organ_id_ = #{parentId}
+        AND del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+    </select>
 </mapper>