xiao547607 5 anni fa
parent
commit
9f94e775e6

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/CompanyDeviceRelationDAO.java

@@ -20,6 +20,8 @@ public interface CompanyDeviceRelationDAO {
     List<DeviceInfo> findDeviceByCompanyId(String companyId);
 	CompanyDeviceRelation findByCompanyIdAndDeviceId(String companyId, String deviceId);
 	List<CompanyDeviceRelation> findByCompanyId(String companyId);
+	List<CompanyDeviceRelation> findByDeviceId(String deviceId);
 	int deleteByCompanyId(String companyId);
+	int deleteByDeviceId(String deviceId);
     int deleteByCompanyIdAndDeviceId(String companyId, String deviceId);
 }

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

@@ -52,4 +52,8 @@ public class CompanyInfoDTO {
     private String code;
     @ApiModelProperty(value = "上级单位")
     private String parentName;
+    @ApiModelProperty(value = "单位性质")
+    private String type;
+    @ApiModelProperty(value = "单位性质翻译")
+    private String typeN;
 }

+ 4 - 5
common/src/main/java/com/jpsoft/smart/modules/base/entity/CompanyInfo.java

@@ -28,27 +28,26 @@ public class CompanyInfo {
 	private String remark;
     @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 createTime;
     @ApiModelProperty(value = "更新人")
 	private String updateBy;
-
 	@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 Boolean delFlag;
-
 	@ApiModelProperty(value = "上级公司")
 	private String parentId;
-
 	@ApiModelProperty(value = "企业编码")
 	private String code;
-
 	@ApiModelProperty(value = "上级单位")
 	private String parentName;
+	@ApiModelProperty(value = "单位性质")
+	private String type;
+	@ApiModelProperty(value = "单位性质翻译")
+	private String typeN;
 }

+ 2 - 1
common/src/main/java/com/jpsoft/smart/modules/base/entity/DeviceInfo.java

@@ -179,5 +179,6 @@ public class DeviceInfo {
 		return isAutoUpdateN;
 	}
 
-
+	@ApiModelProperty(value = "异常原因")
+	private String isBind;
 }

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

@@ -18,6 +18,8 @@ public interface CompanyDeviceRelationService {
 	List<DeviceInfo> findDeviceByCompanyId(String companyId);
 	CompanyDeviceRelation findByCompanyIdAndDeviceId(String companyId, String deviceId);
 	List<CompanyDeviceRelation> findByCompanyId(String companyId);
+	List<CompanyDeviceRelation> findByDeviceId(String deviceId);
 	int deleteByCompanyId(String companyId);
+	int deleteByDeviceId(String deviceId);
     int deleteByCompanyIdAndDeviceId(String companyId, String deviceId);
 }

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

@@ -84,11 +84,21 @@ public class CompanyDeviceRelationServiceImpl implements CompanyDeviceRelationSe
 		return companyDeviceRelationDAO.findByCompanyId(companyId);
 	}
 
+	@Override
+	public List<CompanyDeviceRelation> findByDeviceId(String deviceId){
+		return companyDeviceRelationDAO.findByDeviceId(deviceId);
+	}
+
 	@Override
 	public int deleteByCompanyId(String companyId) {
 		return companyDeviceRelationDAO.deleteByCompanyId(companyId);
 	}
 
+	@Override
+	public int deleteByDeviceId(String deviceId) {
+		return companyDeviceRelationDAO.deleteByDeviceId(deviceId);
+	}
+
 	@Override
 	public int deleteByCompanyIdAndDeviceId(String companyId, String deviceId) {
 		return companyDeviceRelationDAO.deleteByCompanyIdAndDeviceId(companyId,deviceId);

+ 7 - 0
common/src/main/resources/mapper/base/CompanyDeviceRelation.xml

@@ -43,6 +43,9 @@
     <delete id="deleteByCompanyId" parameterType="string">
         delete from base_company_device_relation where company_id=#{0}
     </delete>
+    <delete id="deleteByDeviceId" parameterType="string">
+        delete from base_company_device_relation where device_id=#{0}
+    </delete>
     <delete id="deleteByCompanyIdAndDeviceId" parameterType="string">
         delete from base_company_device_relation
         where company_id=#{companyId} and device_id=#{deviceId}
@@ -116,4 +119,8 @@
         where company_id=#{companyId}
     </select>
 
+    <select id="findByDeviceId" parameterType="string" resultMap="CompanyDeviceRelationMap">
+        select * from base_company_device_relation
+        where device_id=#{deviceId}
+    </select>
 </mapper>

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

@@ -17,6 +17,7 @@
         <result property="parentId" column="parent_id"/>
         <result property="code" column="code_"/>
         <result property="parentName" column="parent_name"/>
+        <result property="type" column="type_"/>
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.CompanyInfo">
         <!--
@@ -26,7 +27,7 @@
         -->
         <![CDATA[
 		insert into base_company_info
-	    (id_,sort_no,name_,logo_,remark_,create_by,create_time,update_by,update_time,del_flag,parent_id,code_)
+	    (id_,sort_no,name_,logo_,remark_,create_by,create_time,update_by,update_time,del_flag,parent_id,code_,type_)
 		values
 		(
 			#{id,jdbcType=VARCHAR}
@@ -41,6 +42,7 @@
 			,#{delFlag,jdbcType= NUMERIC }
 			,#{parentId,jdbcType=VARCHAR}
 			,#{code,jdbcType=VARCHAR}
+			,#{type,jdbcType=VARCHAR}
 		)
 	]]>
     </insert>
@@ -83,6 +85,9 @@
             <if test="code!=null">
                 code_=#{code,jdbcType=VARCHAR},
             </if>
+            <if test="type!=null">
+                type_=#{type,jdbcType=VARCHAR},
+            </if>
         </set>
         where id_=#{id}
     </update>

+ 7 - 2
common/src/main/resources/mapper/base/DeviceInfo.xml

@@ -26,6 +26,7 @@
 		    <result property="defaultFaceLibraryId" column="default_face_library_id" />
 		    <result property="heartbeatUpdateTime" column="heartbeat_update_time" />
 		    <result property="abnormalReason" column="abnormal_reason" />
+			<result property="isBind" column="is_bind" />
 			</resultMap>
 	<insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.DeviceInfo">
 	<!--
@@ -155,13 +156,17 @@ id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,
 		</foreach>
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="DeviceInfoMap">
-		<![CDATA[
 			select
 				a.*,
 				b.name_ AS company_name
+				<if test="searchParams.isBoundCompanyId != null" >
+				,( SELECT count(c.id_) FROM base_company_device_relation c WHERE c.device_id = a.id_ AND c.company_id = #{searchParams.isBoundCompanyId} and c.del_flag = 0) AS is_bind
+				</if>
+				<if test="searchParams.isBoundPersonId != null" >
+					,( SELECT count(c.id_) FROM base_person_device_relation c WHERE c.device_id = a.id_ AND c.person_id = #{searchParams.isBoundPersonId} and c.del_flag = 0) AS is_bind
+				</if>
 				from base_device_info a
 				LEFT JOIN base_company_info b ON a.company_id = b.id_
-		]]>
 		<where>
 				and a.del_flag=false
 			<if test="searchParams.deviceIdList != null">

+ 7 - 5
common/src/main/resources/mapper/base/PersonDeviceRelation.xml

@@ -102,19 +102,21 @@ id_,device_id,person_id,del_flag,create_by,create_time,update_by,update_time		fr
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="PersonDeviceRelationMap">
 		<![CDATA[
-			select * from base_person_device_relation
+			select * from base_person_device_relation a
+			LEFT JOIN base_device_info b ON a.device_id = b.id_
 		]]>
 		<where>
-			and del_flag = false
+			and a.del_flag = false
+			and b.del_flag = false
 			<if test="searchParams.deviceId != null">
-			and device_id = #{searchParams.deviceId}
+			and a.device_id = #{searchParams.deviceId}
 		</if>
 			<if test="searchParams.personId != null">
-				and person_id = #{searchParams.personId}
+				and a.person_id = #{searchParams.personId}
 			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
-	        ${sort.name} ${sort.order}
+	        a.${sort.name} ${sort.order}
 	 	</foreach>
 	</select>
     <select id="findDeviceByPersonId" resultMap="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO.DeviceInfoMap">

+ 52 - 25
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -10,6 +10,7 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
 import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 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 io.swagger.annotations.Api;
@@ -57,6 +58,9 @@ public class CompanyInfoController {
     @Autowired
     private ILapiService lapiService;
 
+    @Autowired
+    private DataDictionaryService dataDictionaryService;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<CompanyInfoDTO> create(){
@@ -386,6 +390,11 @@ public class CompanyInfoController {
                 li.setPosition4Name(page1.get(0).getPosition4Name());
                 li.setPosition5Name(page1.get(0).getPosition5Name());
             }
+
+
+            String typeN = dataDictionaryService.findNameByCatalogNameAndValue("单位性质",li.getType());
+            li.setTypeN(typeN);
+
         }
 
         msgResult.setResult(true);
@@ -422,9 +431,11 @@ public class CompanyInfoController {
 
     @GetMapping("queryBindDeviceList")
     public MessageResult<Map> queryBindDeviceList(String companyId,
-                                                   @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
-                                                   @RequestParam(value="pageSize",defaultValue="20") int pageSize,
-                                                   @RequestAttribute String subject){
+                       @RequestParam(value="deviceNo",defaultValue="") String deviceNo,
+                       @RequestParam(value="deviceName",defaultValue="") String deviceName,
+                       @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+                       @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+                       @RequestAttribute String subject){
         MessageResult<Map> messageResult = new MessageResult<>();
 
         try {
@@ -436,39 +447,55 @@ public class CompanyInfoController {
                 searchParams.put("bindCompanyId",user.getCompanyId());
             }
 
-            List<Sort> sorts = new ArrayList<>();
-            sorts.add(new Sort("create_time","asc"));
 
-            //设备列表
-            Page<DeviceInfo> deviceInfoPage = deviceInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sorts);
 
-            //查询已绑定设备
-            List<DeviceInfo> bindDeviceList = companyDeviceRelationService.findDeviceByCompanyId(companyId);
+            if(StringUtils.isNotEmpty(deviceNo)){
+                searchParams.put("deviceNo","%" + deviceNo + "%");
+            }
 
-            List<Map> mapList = new ArrayList<>();
+            if(StringUtils.isNotEmpty(deviceName)){
+                searchParams.put("aliasName","%" + deviceName + "%");
+            }
 
-            for (DeviceInfo deviceInfo : deviceInfoPage) {
-                Map<String,Object> map = new HashMap<>();
+            List<Sort> sorts = new ArrayList<>();
 
-                map.put("device",deviceInfo);
 
-                long count = bindDeviceList.stream().filter((d)->d.getId().equals(deviceInfo.getId())).count();
+            if(StringUtils.isNotEmpty(companyId)){
+                searchParams.put("isBoundCompanyId",companyId);
+                sorts.add(new Sort("is_bind","desc"));
+            }
+            sorts.add(new Sort("create_time","asc"));
 
-                if (count>0){
-                    map.put("bound",true);
-                }
-                else{
-                    map.put("bound",false);
-                }
+            //设备列表
+            Page<DeviceInfo> deviceInfoPage = deviceInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sorts);
 
-                mapList.add(map);
-            }
+//            //查询已绑定设备
+//            List<DeviceInfo> bindDeviceList = companyDeviceRelationService.findDeviceByCompanyId(companyId);
+//
+//            List<Map> mapList = new ArrayList<>();
+//
+//            for (DeviceInfo deviceInfo : deviceInfoPage) {
+//                Map<String,Object> map = new HashMap<>();
+//
+//                map.put("device",deviceInfo);
+//
+//                long count = bindDeviceList.stream().filter((d)->d.getId().equals(deviceInfo.getId())).count();
+//
+//                if (count>0){
+//                    map.put("bound",true);
+//                }
+//                else{
+//                    map.put("bound",false);
+//                }
+//
+//                mapList.add(map);
+//            }
 
-            Map<String,Object> dataMap = PojoUtils.pageWrapper(deviceInfoPage);
+            //Map<String,Object> dataMap = PojoUtils.pageWrapper(deviceInfoPage);
 
-            dataMap.put("data",mapList);
+            //dataMap.put("data",mapList);
 
-            messageResult.setData(dataMap);
+            messageResult.setData(PojoUtils.pageWrapper(deviceInfoPage));
             messageResult.setResult(true);
         }
         catch (Exception ex){

+ 3 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -264,6 +264,7 @@ public class DeviceInfoController {
             int affectCount = deviceInfoService.update(deviceInfo);
 
             if (affectCount > 0) {
+                companyDeviceRelationService.deleteByCompanyIdAndDeviceId(deviceInfo.getCompanyId(),deviceInfo.getId());
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);
             } else {
@@ -297,6 +298,8 @@ public class DeviceInfoController {
                 deviceInfo.setUpdateTime(new Date());
 
                 affectCount += deviceInfoService.update(deviceInfo);
+
+                companyDeviceRelationService.deleteByCompanyIdAndDeviceId(deviceInfo.getCompanyId(),deviceInfo.getId());
             }
 
             if (affectCount > 0) {

+ 18 - 9
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -721,8 +721,7 @@ public class PersonDeviceRelationController {
 
         Map<String,Object> searchParams = new HashMap<>();
 
-        List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("create_time","desc"));
+
 
         //为公司管理员
         boolean is_admin = userService.hasRole(subject,"ADMIN");
@@ -750,16 +749,26 @@ public class PersonDeviceRelationController {
         if(StringUtils.isNotEmpty(deviceName)){
             searchParams.put("aliasName","%" + deviceName + "%");
         }
+
+        List<Sort> sortList = new ArrayList<>();
+
+        if(personId != null){
+            searchParams.put("isBoundPersonId",personId);
+            sortList.add(new Sort("is_bind","desc"));
+        }
+        sortList.add(new Sort("is_online","desc"));
+        sortList.add(new Sort("create_time","desc"));
+
         Page<DeviceInfo> page = deviceInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
 
         for (DeviceInfo deviceInfo:page) {
-            PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(deviceInfo.getId(),personId);
-            if(item == null){
-                deviceInfo.setIsBindPerson(false);
-            }
-            else{
-                deviceInfo.setIsBindPerson(true);
-            }
+//            PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(deviceInfo.getId(),personId);
+//            if(item == null){
+//                deviceInfo.setIsBindPerson(false);
+//            }
+//            else{
+//                deviceInfo.setIsBindPerson(true);
+//            }
             String typeN = dataDictionaryService.findNameByCatalogNameAndValue("设备类型",deviceInfo.getType());
             deviceInfo.setTypeN(typeN);
         }