Просмотр исходного кода

单位列表增加上级单位查询。

zhengqiang 5 лет назад
Родитель
Сommit
ba721a8061

+ 5 - 1
common/src/main/java/com/jpsoft/smart/modules/base/dao/CompanyInfoDAO.java

@@ -1,6 +1,8 @@
 package com.jpsoft.smart.modules.base.dao;
 
 import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import java.util.Map;
@@ -24,11 +26,13 @@ public interface CompanyInfoDAO {
 
 	List<CompanyInfo> findByCompanyCode(String code);
 
-	long countByParentId(String parentId);
+	long countByParentId(@Param("parentId") String parentId);
 
 	long countByCompanyCode(String code,Long personId);
 
 	int updateCode(String oldCode,int startIndex, String newCode);
 
     List<CompanyInfo> findByCompanyCode(String code, Long personId);
+
+    List<CompanyInfo> findByParentId(@Param("parentId") String parentId);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dto/CompanyInfoDTO.java

@@ -56,4 +56,6 @@ public class CompanyInfoDTO {
     private String type;
     @ApiModelProperty(value = "单位性质翻译")
     private String typeN;
+    @ApiModelProperty(value = "是否有子单位")
+    private Boolean hasChildren;
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/CompanyInfoService.java

@@ -18,4 +18,6 @@ public interface CompanyInfoService {
     long countByParentId(String parentId);
     long countByCompanyCode(String code,Long personId);
     int updateCode(String oldCode, String newCode);
+    Boolean hasChildren(String parentId);
+	List<CompanyInfo> findByParentId(String parentId);
 }

+ 10 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/CompanyInfoServiceImpl.java

@@ -87,4 +87,14 @@ public class CompanyInfoServiceImpl implements CompanyInfoService {
 	public int updateCode(String oldCode, String newCode) {
 		return companyInfoDAO.updateCode(oldCode + "%",oldCode.length()+1 ,newCode);
 	}
+
+	@Override
+	public Boolean hasChildren(String id) {
+		return countByParentId(id)>0;
+	}
+
+	@Override
+	public List<CompanyInfo> findByParentId(String parentId) {
+		return companyInfoDAO.findByParentId(parentId);
+	}
 }

+ 10 - 6
common/src/main/resources/mapper/base/CompanyInfo.xml

@@ -122,11 +122,8 @@
             <if test="searchParams.parentCode != null">
                 and b.code_ like #{searchParams.parentCode}
             </if>
-            <if test="searchParams.bindCompanyId != null">
-                and (
-                a.id_ = #{searchParams.bindCompanyId} or
-                a.parent_id = #{searchParams.bindCompanyId}
-                )
+            <if test="searchParams.bindCompanyCode != null">
+                and b.code_ like #{searchParams.bindCompanyCode}
             </if>
         </where>
         <foreach item="sort" collection="sortList" open="order by" separator=",">
@@ -153,7 +150,7 @@
         <where>
             del_flag=0
             <if test="parentId!=null">
-                and parent_id=#{parentId,jdbcType=VARCHAR},
+                and parent_id=#{parentId,jdbcType=VARCHAR}
             </if>
             <if test="parentId==null">
                 and (parent_id is null or parent_id='')
@@ -173,4 +170,11 @@
         </if>
         )
     </select>
+    <select id="findByParentId" resultMap="CompanyInfoMap">
+        select a.*,b.name_ as parent_name
+        from base_company_info a
+        left join base_company_info b on a.parent_id = b.id_
+        where a.parent_id=#{parentId} and a.del_flag=0
+        order by a.sort_no asc,a.name_ asc
+    </select>
 </mapper>

+ 53 - 6
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -13,6 +13,7 @@ import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
 import com.jpsoft.smart.modules.sys.service.UserService;
 import com.rabbitmq.client.AMQP;
+import com.sun.rmi.rmid.ExecOptionPermission;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -348,6 +349,8 @@ public class CompanyInfoController {
         return msgResult;
     }
 
+
+
     @ApiOperation(value="列表")
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
@@ -362,11 +365,6 @@ public class CompanyInfoController {
 
         Map<String,Object> searchParams = new HashMap<>();
 
-        User user = userService.get(subject);
-        if(!userService.hasRole(user.getId(),"SYSADMIN")) {
-            searchParams.put("bindCompanyId",user.getCompanyId());
-        }
-
         List<Sort> sortList = new ArrayList<>();
         sortList.add(new Sort("sort_no","asc"));
         sortList.add(new Sort("name_","asc"));
@@ -388,8 +386,22 @@ public class CompanyInfoController {
             }
         }
 
+        User user = userService.get(subject);
+
+        if(!userService.hasRole(user.getId(),"SYSADMIN")) {
+            CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
+            searchParams.put("bindCompanyCode",companyInfo.getCode()  + "%");
+        }
+        else {
+            if (StringUtils.isEmpty(name) && StringUtils.isEmpty(parentId)) {
+                //系统管理员,如果查询条件为空则只查根目录
+                searchParams.put("root", true);
+            }
+        }
+
         Page<CompanyInfo> page = companyInfoService.pageSearch(searchParams,pageIndex,pageSize,sortList);
         Page<CompanyInfoDTO> pageDTO = PojoUtils.convertPage(page, CompanyInfoDTO.class);
+
         for(CompanyInfoDTO li : pageDTO.getResult()){
             Map<String,Object> searchParams1 = new HashMap<>();
             searchParams1.put("companyId",li.getId());
@@ -405,10 +417,13 @@ public class CompanyInfoController {
                 li.setPosition5Name(page1.get(0).getPosition5Name());
             }
 
-
             String typeN = dataDictionaryService.findNameByCatalogNameAndValue("单位性质",li.getType());
             li.setTypeN(typeN);
 
+            //查询是否有子单位
+            Boolean hasChildren = companyInfoService.hasChildren(li.getId());
+
+            li.setHasChildren(hasChildren);
         }
 
         msgResult.setResult(true);
@@ -417,6 +432,38 @@ public class CompanyInfoController {
         return msgResult;
     }
 
+    @ApiOperation(value="查询子单位")
+    @RequestMapping(value = "children",method = RequestMethod.POST)
+    public MessageResult<List<CompanyInfoDTO>> children(String parentId){
+        MessageResult<List<CompanyInfoDTO>> msgResult = new MessageResult<>();
+
+        try {
+            List<CompanyInfo> list = companyInfoService.findByParentId(parentId);
+
+            List<CompanyInfoDTO> dtoList = new ArrayList<>();
+
+            for (CompanyInfo companyInfo : list) {
+                CompanyInfoDTO dto = new CompanyInfoDTO();
+
+                PojoUtils.map(companyInfo,dto);
+
+//                Boolean hasChildren = companyInfoService.hasChildren(companyInfo.getId());
+//                dto.setHasChildren(hasChildren);
+
+                dtoList.add(dto);
+            }
+
+            msgResult.setResult(true);
+            msgResult.setData(dtoList);
+        }
+        catch (Exception ex){
+            msgResult.setResult(false);
+            logger.error(ex.getMessage(),ex);
+        }
+
+        return msgResult;
+    }
+
     @ApiOperation(value="所有单位列表")
     @RequestMapping(value = "list",method = RequestMethod.POST)
     @ApiImplicitParams({