Browse Source

增加上级单位。

zhengqiang 5 years ago
parent
commit
e427866a13

+ 12 - 2
common/src/main/java/com/jpsoft/smart/modules/base/dao/CompanyInfoDAO.java

@@ -9,10 +9,20 @@ import com.jpsoft.smart.modules.common.dto.Sort;
 @Repository
 public interface CompanyInfoDAO {
 	int insert(CompanyInfo entity);
+
 	int update(CompanyInfo entity);
+
 	int exist(String id);
+
 	CompanyInfo get(String id);
+
 	int delete(String id);
+
 	List<CompanyInfo> list();
-	List<CompanyInfo> search(Map<String,Object> searchParams,List<Sort> sortList);
-}
+
+	List<CompanyInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+
+	List<CompanyInfo> findByCompanyCode(String code);
+
+	long countByParentId(String parentId);
+}

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

@@ -46,10 +46,10 @@ public class CompanyInfoDTO {
     private String position4Name;
     @ApiModelProperty(value = "位置5")
     private String position5Name;
-    @ApiModelProperty(value = "上级公司")
+    @ApiModelProperty(value = "上级单位编号")
     private String parentId;
-    @ApiModelProperty(value = "上级公司名称")
-    private String parentName;
-    @ApiModelProperty(value = "企业编码")
+    @ApiModelProperty(value = "单位编码")
     private String code;
+    @ApiModelProperty(value = "上级单位")
+    private String parentName;
 }

+ 3 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/CompanyInfo.java

@@ -48,4 +48,7 @@ public class CompanyInfo {
 
 	@ApiModelProperty(value = "企业编码")
 	private String code;
+
+	@ApiModelProperty(value = "上级单位")
+	private String parentName;
 }

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

@@ -17,4 +17,6 @@ public interface CompanyInfoService {
 	int delete(String id);
 	List<CompanyInfo> list();
 	Page<CompanyInfo> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,List<Sort> sortList);
+    List<CompanyInfo> findByCompanyCode(String code);
+    long countByParentId(String parentId);
 }

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

@@ -67,4 +67,14 @@ public class CompanyInfoServiceImpl implements CompanyInfoService {
         
         return page;
 	}
+
+	@Override
+	public List<CompanyInfo> findByCompanyCode(String code) {
+		return companyInfoDAO.findByCompanyCode(code);
+	}
+
+	@Override
+	public long countByParentId(String parentId) {
+		return companyInfoDAO.countByParentId(parentId);
+	}
 }

+ 29 - 5
common/src/main/resources/mapper/base/CompanyInfo.xml

@@ -16,6 +16,7 @@
         <result property="delFlag" column="del_flag"/>
         <result property="parentId" column="parent_id"/>
         <result property="code" column="code_"/>
+        <result property="parentName" column="parent_name"/>
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.CompanyInfo">
         <!--
@@ -86,7 +87,10 @@
         where id_=#{id}
     </update>
     <select id="get" parameterType="string" resultMap="CompanyInfoMap">
-        select * from base_company_info where id_=#{0} and del_flag = 0
+        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.id_=#{0} and a.del_flag = 0
     </select>
     <select id="exist" parameterType="string" resultType="int">
         select count(*) from base_company_info where id_=#{0} and del_flag = 0
@@ -96,16 +100,36 @@
     </select>
     <select id="search" parameterType="hashmap" resultMap="CompanyInfoMap">
         <![CDATA[
-			select * from base_company_info
+            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>
-            del_flag = 0
+            a.del_flag = 0
             <if test="searchParams.id != null">
-                and ID_ like #{searchParams.id}
+                and a.id_ like #{searchParams.id}
             </if>
         </where>
         <foreach item="sort" collection="sortList" open="order by" separator=",">
-            ${sort.name} ${sort.order}
+            a.${sort.name} ${sort.order}
         </foreach>
     </select>
+    <select id="findByCompanyCode" 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.code_ like #{code} and a.del_flag=0 order by a.id_ asc
+    </select>
+    <select id="countByParentId" resultType="long">
+        select count(*) from base_company_info
+        <where>
+            del_flag=0
+            <if test="parentId!=null">
+                and parent_id=#{parentId,jdbcType=VARCHAR},
+            </if>
+            <if test="parentId==null">
+                and (parent_id is null or parent_id='')
+            </if>
+        </where>
+    </select>
 </mapper>

+ 37 - 2
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -3,7 +3,9 @@ package com.jpsoft.smart.modules.base.controller;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.base.dto.CompanyInfoDTO;
 import com.jpsoft.smart.modules.base.entity.CompanyPosition;
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.base.service.CompanyPositionService;
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
@@ -22,6 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -33,11 +37,16 @@ public class CompanyInfoController {
 
     @Autowired
     private CompanyInfoService companyInfoService;
+
     @Autowired
     private UserService userService;
+
     @Autowired
     private CompanyPositionService companyPositionService;
 
+    @Autowired
+    private PersonInfoService personInfoService;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<CompanyInfoDTO> create(){
@@ -61,6 +70,18 @@ public class CompanyInfoController {
             CompanyInfo companyInfo = new CompanyInfo();
             PojoUtils.map(companyInfoDTO, companyInfo);
             companyInfo.setId(UUID.randomUUID().toString());
+
+            DecimalFormat df = new DecimalFormat("000");
+
+            //上级单位code
+            if (StringUtils.isNotEmpty(companyInfo.getParentId())){
+                CompanyInfo parent = companyInfoService.get(companyInfo.getParentId());
+                companyInfo.setCode(parent.getCode() + "," + companyInfo.getId());
+            }
+            else{
+                companyInfo.setCode(companyInfo.getCode());
+            }
+
             companyInfo.setDelFlag(false);
             companyInfo.setCreateBy(subject);
             companyInfo.setCreateTime(new Date());
@@ -153,6 +174,16 @@ public class CompanyInfoController {
             int affectCount = 0;
             CompanyInfo companyInfo = new CompanyInfo();
             PojoUtils.map(companyInfoDTO, companyInfo);
+
+            //上级单位code
+            if (StringUtils.isNotEmpty(companyInfo.getParentId())){
+                CompanyInfo parent = companyInfoService.get(companyInfo.getParentId());
+                companyInfo.setCode(parent.getCode() + "," + companyInfo.getId());
+            }
+            else{
+                companyInfo.setCode(companyInfo.getCode());
+            }
+
             companyInfo.setUpdateBy(subject);
             companyInfo.setUpdateTime(new Date());
             companyInfoService.update(companyInfo);
@@ -325,8 +356,12 @@ public class CompanyInfoController {
         if (userService.hasRole(subject,"SYSADMIN")) {
             list = companyInfoService.list();
         }
-        if(userService.hasRole(subject,"ADMIN")){
-            list.add(companyInfoService.get(user.getCompanyId()));
+        else if(userService.hasRole(subject,"ADMIN")){
+            CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
+
+            CompanyInfo parent = companyInfoService.get(companyInfo.getParentId());
+
+            list = companyInfoService.findByCompanyCode(parent.getCode() + "%");
         }
 
         msgResult.setResult(true);

+ 5 - 1
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceLogApiController.java

@@ -299,7 +299,11 @@ public class PersonDeviceLogApiController {
         MessageResult<List> messageResult = new MessageResult<>();
 
         try {
-            List<CompanyInfo> companyList = companyInfoService.list();
+            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
+
+            CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
+
+            List<CompanyInfo> companyList = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%");
 
             messageResult.setData(companyList);
             messageResult.setResult(true);