Преглед изворни кода

设备管理,设备和人员绑定,基础增删改查

yanliming пре 5 година
родитељ
комит
b8d3b7c7e3

+ 24 - 24
src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -7,6 +7,8 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -20,27 +22,14 @@ import java.util.*;
 
 @RestController
 @RequestMapping("/deviceInfo")
-@Api(description = "deviceInfo")
+@Api(description = "设备信息")
 public class DeviceInfoController {
     private Logger logger = LoggerFactory.getLogger(getClass());
 
     @Autowired
     private DeviceInfoService deviceInfoService;
 
-    @ApiOperation(value="创建空记录")
-    @GetMapping("create")
-    public MessageResult<DeviceInfo> create(){
-        MessageResult<DeviceInfo> msgResult = new MessageResult<>();
-
-        DeviceInfo deviceInfo = new DeviceInfo();
-
-        msgResult.setData(deviceInfo);
-        msgResult.setResult(true);
-
-        return msgResult;
-    }
-    
-    @ApiOperation(value="添加信息")
+    @ApiOperation(value="添加设备")
     @PostMapping("add")
     public MessageResult<DeviceInfo> add(@RequestBody DeviceInfo deviceInfo,@RequestAttribute String subject){
         MessageResult<DeviceInfo> msgResult = new MessageResult<>();
@@ -71,7 +60,7 @@ public class DeviceInfoController {
         return msgResult;
     }
 
-    @ApiOperation(value="获取信息")
+    @ApiOperation(value="获取设备信息")
     @GetMapping("edit/{id}")
     public MessageResult<DeviceInfo> edit(@PathVariable("id") String id){
         MessageResult<DeviceInfo> msgResult = new MessageResult<>();
@@ -97,7 +86,7 @@ public class DeviceInfoController {
         return msgResult;
     }
 
-    @ApiOperation(value="更新用户")
+    @ApiOperation(value="更新设备信息")
     @PostMapping("update")
     public MessageResult<DeviceInfo> update(@RequestBody DeviceInfo deviceInfo,@RequestAttribute String subject){
         MessageResult<DeviceInfo> msgResult = new MessageResult<>();
@@ -126,7 +115,7 @@ public class DeviceInfoController {
         return msgResult;
     }
 
-	@ApiOperation(value="删除")
+	@ApiOperation(value="删除设备")
     @PostMapping("delete/{id}")
     public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
         MessageResult<Integer> msgResult = new MessageResult<>();
@@ -158,7 +147,7 @@ public class DeviceInfoController {
     }
 
 
-    @ApiOperation(value="批量删除")
+    @ApiOperation(value="批量删除设备")
     @PostMapping("batchDelete")
     public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
         MessageResult<Integer> msgResult = new MessageResult<>();
@@ -193,10 +182,15 @@ public class DeviceInfoController {
         return msgResult;
     }
 
-    @ApiOperation(value="列表")
+    @ApiOperation(value="设备列表")
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "aliasName",value = "设备别名",  paramType = "query"),
+            @ApiImplicitParam(name = "deviceNo",value = "编号",  paramType = "query"),
+            @ApiImplicitParam(name = "address",value = "位置",  paramType = "query")
+    })
     public MessageResult<Map> pageList(
-            String id,
+            String aliasName,String deviceNo,String address,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             @RequestAttribute String subject){
@@ -209,10 +203,16 @@ public class DeviceInfoController {
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("id_","asc"));
+        sortList.add(new Sort("create_time","desc"));
 
-        if (StringUtils.isNotEmpty(id)) {
-            searchParams.put("id","%" + id + "%");
+        if (StringUtils.isNotEmpty(aliasName)) {
+            searchParams.put("aliasName","%" + aliasName + "%");
+        }
+        if (StringUtils.isNotEmpty(deviceNo)) {
+            searchParams.put("deviceNo","%" + deviceNo + "%");
+        }
+        if (StringUtils.isNotEmpty(address)) {
+            searchParams.put("address","%" + address + "%");
         }
 
         Page<DeviceInfo> page = deviceInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);

+ 19 - 21
src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -7,6 +7,8 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.base.entity.PersonDeviceRelation;
 import com.jpsoft.smart.modules.base.service.PersonDeviceRelationService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -20,27 +22,15 @@ import java.util.*;
 
 @RestController
 @RequestMapping("/personDeviceRelation")
-@Api(description = "personDeviceRelation")
+@Api(description = "设备和人员绑定")
 public class PersonDeviceRelationController {
     private Logger logger = LoggerFactory.getLogger(getClass());
 
     @Autowired
     private PersonDeviceRelationService personDeviceRelationService;
 
-    @ApiOperation(value="创建空记录")
-    @GetMapping("create")
-    public MessageResult<PersonDeviceRelation> create(){
-        MessageResult<PersonDeviceRelation> msgResult = new MessageResult<>();
-
-        PersonDeviceRelation personDeviceRelation = new PersonDeviceRelation();
-
-        msgResult.setData(personDeviceRelation);
-        msgResult.setResult(true);
-
-        return msgResult;
-    }
     
-    @ApiOperation(value="添加信息")
+    @ApiOperation(value="添加设备和人员绑定")
     @PostMapping("add")
     public MessageResult<PersonDeviceRelation> add(@RequestBody PersonDeviceRelation personDeviceRelation,@RequestAttribute String subject){
         MessageResult<PersonDeviceRelation> msgResult = new MessageResult<>();
@@ -71,7 +61,7 @@ public class PersonDeviceRelationController {
         return msgResult;
     }
 
-    @ApiOperation(value="获取信息")
+    @ApiOperation(value="获取人员和设备绑定信息")
     @GetMapping("edit/{id}")
     public MessageResult<PersonDeviceRelation> edit(@PathVariable("id") String id){
         MessageResult<PersonDeviceRelation> msgResult = new MessageResult<>();
@@ -97,7 +87,7 @@ public class PersonDeviceRelationController {
         return msgResult;
     }
 
-    @ApiOperation(value="更新用户")
+    @ApiOperation(value="更新设备和人员绑定")
     @PostMapping("update")
     public MessageResult<PersonDeviceRelation> update(@RequestBody PersonDeviceRelation personDeviceRelation,@RequestAttribute String subject){
         MessageResult<PersonDeviceRelation> msgResult = new MessageResult<>();
@@ -126,7 +116,7 @@ public class PersonDeviceRelationController {
         return msgResult;
     }
 
-	@ApiOperation(value="删除")
+	@ApiOperation(value="删除设备和人员绑定")
     @PostMapping("delete/{id}")
     public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
         MessageResult<Integer> msgResult = new MessageResult<>();
@@ -195,8 +185,12 @@ public class PersonDeviceRelationController {
 
     @ApiOperation(value="列表")
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "deviceId",value = "设备ID",  paramType = "query"),
+            @ApiImplicitParam(name = "personId",value = "人员ID",  paramType = "query")
+    })
     public MessageResult<Map> pageList(
-            String id,
+            String deviceId,String personId,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             @RequestAttribute String subject){
@@ -209,10 +203,14 @@ public class PersonDeviceRelationController {
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("id_","asc"));
+        sortList.add(new Sort("create_time","desc"));
+
+        if (StringUtils.isNotEmpty(deviceId)) {
+            searchParams.put("deviceId",deviceId);
+        }
 
-        if (StringUtils.isNotEmpty(id)) {
-            searchParams.put("id","%" + id + "%");
+        if (StringUtils.isNotEmpty(personId)) {
+            searchParams.put("personId",personId);
         }
 
         Page<PersonDeviceRelation> page = personDeviceRelationService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);

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

@@ -25,8 +25,7 @@ public class DeviceInfo {
 	 *表头
 	 */
         @ApiModelProperty(value = "表头")
-	private String 
-header;
+	private String header;
 	/**
 	 *设备编号
 	 */

+ 22 - 0
src/main/java/com/jpsoft/smart/modules/base/entity/PersonDeviceRelation.java

@@ -26,11 +26,17 @@ public class PersonDeviceRelation {
 	 */
         @ApiModelProperty(value = "设备ID")
 	private String deviceId;
+
+	@ApiModelProperty(value = "设备信息")
+	private DeviceInfo deviceInfo;
 	/**
 	 *人员ID
 	 */
         @ApiModelProperty(value = "人员ID")
 	private String personId;
+
+	@ApiModelProperty(value = "人员信息")
+	private PersonInfo personInfo;
 	/**
 	 *是否删除
 	 */
@@ -60,4 +66,20 @@ public class PersonDeviceRelation {
 	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
 	    @ApiModelProperty(value = "更新时间")
 	private Date updateTime;
+
+	public DeviceInfo getDeviceInfo() {
+		return deviceInfo;
+	}
+
+	public void setDeviceInfo(DeviceInfo deviceInfo) {
+		this.deviceInfo = deviceInfo;
+	}
+
+	public PersonInfo getPersonInfo() {
+		return personInfo;
+	}
+
+	public void setPersonInfo(PersonInfo personInfo) {
+		this.personInfo = personInfo;
+	}
 }

+ 14 - 16
src/main/resources/mapper/base/DeviceInfo.xml

@@ -5,9 +5,7 @@
 <mapper namespace="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO">
 	<resultMap id="DeviceInfoMap" type="com.jpsoft.smart.modules.base.entity.DeviceInfo">
 		<id property="id" column="id_" />
-			<result property="
-header" column="
-header_" />
+			<result property="header" column="header_" />
 			<result property="deviceNo" column="device_no" />
 			<result property="aliasName" column="alias_name" />
 			<result property="address" column="address_" />
@@ -31,13 +29,11 @@ header_" />
 	-->
 	<![CDATA[
 		insert into base_device_info
-	    (id_,
-header_,device_no,alias_name,address_,is_online,unlock_password,code_address,ip_address,port_,type_,del_flag,create_by,create_time,update_by,update_time)
+	    (id_,header_,device_no,alias_name,address_,is_online,unlock_password,code_address,ip_address,port_,type_,del_flag,create_by,create_time,update_by,update_time)
 		values
 		(
 #{id,jdbcType=VARCHAR}
-,#{
-header,jdbcType=VARCHAR}
+,#{header,jdbcType=VARCHAR}
 ,#{deviceNo,jdbcType=VARCHAR}
 ,#{aliasName,jdbcType=VARCHAR}
 ,#{address,jdbcType=VARCHAR}
@@ -61,11 +57,8 @@ header,jdbcType=VARCHAR}
 	<update id="update" parameterType="com.jpsoft.smart.modules.base.entity.DeviceInfo">
 		update base_device_info
 		<set>
-				<if test="
-header!=null">
-		
-header_=#{
-header,jdbcType=VARCHAR},
+				<if test="header!=null">
+			header_=#{header,jdbcType=VARCHAR},
 		</if>
 				<if test="deviceNo!=null">
 		device_no=#{deviceNo,jdbcType=VARCHAR},
@@ -114,8 +107,7 @@ header,jdbcType=VARCHAR},
 	</update>
 	<select id="get" parameterType="string" resultMap="DeviceInfoMap">
 		select 
-id_,
-header_,device_no,alias_name,address_,is_online,unlock_password,code_address,ip_address,port_,type_,del_flag,create_by,create_time,update_by,update_time		from base_device_info where id_=#{0}
+id_, header_,device_no,alias_name,address_,is_online,unlock_password,code_address,ip_address,port_,type_,del_flag,create_by,create_time,update_by,update_time		from base_device_info where id_=#{0}
 	</select>
 	<select id="exist" parameterType="string" resultType="int">
 		select count(*) from base_device_info where id_=#{0}
@@ -128,8 +120,14 @@ header_,device_no,alias_name,address_,is_online,unlock_password,code_address,ip_
 			select * from base_device_info
 		]]>
 		<where>
-			<if test="searchParams.id != null">
-				and ID_ like #{searchParams.id}
+			<if test="searchParams.aliasName != null">
+				and alias_name like #{searchParams.aliasName}
+			</if>
+			<if test="searchParams.deviceNo != null">
+				and device_no like #{searchParams.deviceNo}
+			</if>
+			<if test="searchParams.address != null">
+				and address_ like #{searchParams.address}
 			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">

+ 9 - 2
src/main/resources/mapper/base/PersonDeviceRelation.xml

@@ -12,6 +12,10 @@
 			<result property="createTime" column="create_time" />
 			<result property="updateBy" column="update_by" />
 			<result property="updateTime" column="update_time" />
+			<association property="deviceInfo" column="device_id"
+					 select="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO.get"></association>
+			<association property="personInfo" column="person_id"
+					 select="com.jpsoft.smart.modules.base.dao.PersonInfoDAO.get"></association>
 			</resultMap>
 	<insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.PersonDeviceRelation">
 	<!--
@@ -80,8 +84,11 @@ id_,device_id,person_id,del_flag,create_by,create_time,update_by,update_time		fr
 			select * from base_person_device_relation
 		]]>
 		<where>
-			<if test="searchParams.id != null">
-				and ID_ like #{searchParams.id}
+			<if test="searchParams.deviceId != null">
+			and device_id = #{searchParams.deviceId}
+		</if>
+			<if test="searchParams.personId != null">
+				and person_id = #{searchParams.personId}
 			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">