From d6a0ac523af2db9216d30fabf1063c095c5b41e1 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Fri, 06 Jul 2018 15:52:39 +0800 Subject: [PATCH] app接口 --- src/main/java/com/moral/service/DeviceService.java | 2 src/main/java/com/moral/service/HistoryService.java | 5 + src/main/resources/mapper/DeviceMapper.xml | 30 +++++++ src/main/java/com/moral/service/impl/HistoryServiceImpl.java | 29 +++++++ src/main/java/com/moral/controller/MobileController.java | 91 +++++++++++++++++++++- src/main/java/com/moral/mapper/HistoryMapper.java | 2 src/main/java/com/moral/mapper/DeviceMapper.java | 2 src/main/java/com/moral/mapper/SensorMapper.java | 2 src/main/resources/mapper/HistoryMapper.xml | 13 +++ src/main/java/com/moral/controller/ScreenController.java | 9 + src/main/java/com/moral/service/impl/DeviceServiceImpl.java | 5 + 11 files changed, 180 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/moral/controller/MobileController.java b/src/main/java/com/moral/controller/MobileController.java index b9f1174..7319f8a 100644 --- a/src/main/java/com/moral/controller/MobileController.java +++ b/src/main/java/com/moral/controller/MobileController.java @@ -9,17 +9,38 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import com.moral.common.util.Crypto; -import com.moral.entity.*; -import com.moral.entity.adapter.EquDeviceAdapter; -import com.moral.service.*; -import com.moral.util.MessageUtils; -import com.taobao.api.ApiException; import org.apache.commons.lang3.StringUtils; import org.springframework.cglib.beans.BeanMap; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import com.moral.common.bean.AppData; +import com.moral.common.bean.ResultBean; +import com.moral.common.util.Crypto; +import com.moral.entity.Account; +import com.moral.entity.Device; +import com.moral.entity.MonitorPoint; +import com.moral.entity.OperateUser; +import com.moral.entity.Organization; +import com.moral.entity.Profession; +import com.moral.entity.adapter.EquDeviceAdapter; +import com.moral.service.AccountService; +import com.moral.service.DeviceService; +import com.moral.service.HistoryService; +import com.moral.service.MonitorPointService; +import com.moral.service.OperateUserService; +import com.moral.service.OrganizationService; +import com.moral.service.ProfessionService; +import com.moral.util.MessageUtils; +import com.taobao.api.ApiException; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; /** * The Class MobileController. @@ -27,6 +48,7 @@ @RestController @RequestMapping("mobile") @CrossOrigin(origins = "*", maxAge = 3600) +@Api(tags = "Mobile", description = "APP������") public class MobileController { /** The operate user service. */ @@ -47,6 +69,12 @@ @Resource private ProfessionService professionService; + + @Resource + private AccountService accountService; + + @Resource + private HistoryService historyService; /** * Mobile login.������ @@ -250,4 +278,53 @@ List<Profession> professions = professionService.getProfessiontList(); return new AppData<List<Profession>>(professions); } + + @GetMapping("login") + @ApiOperation(value = "������������������", notes = "������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "account", value = "������", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "password", value = "������", required = true, paramType = "query", dataType = "String") + }) + public ResultBean<Account> companyLogin(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + Account account = accountService.companyLogin(parameters); + return new ResultBean<Account>(account); + } + + @GetMapping("devices") + @ApiOperation(value = "������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "organizationId", value = "������Id", required = true, paramType = "query", dataType = "String"), + }) + public ResultBean<List<Device>> getDevicesByOrganizationId(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + List<Device> devices = deviceService.getDevicesByOrganizationId(parameters); + return new ResultBean<List<Device>>(devices); + } + + @GetMapping("sensors") + @ApiOperation(value = "���������������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "deviceVersionId", value = "������������Id", required = true, paramType = "query", dataType = "Integer"), + @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "deviceId", value = "������id", required = true, paramType = "query", dataType = "Integer"), + }) + public ResultBean<List<Map<String, Object>>> getSensorsDataByDevice(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + List<Map<String, Object>> sensors = historyService.getSensorsDataByDevice(parameters); + return new ResultBean<List<Map<String, Object>>>(sensors); + } + + @GetMapping("sensor") + @ApiOperation(value = "���������������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "sensorKey", value = "���������key", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "size", value = "������������������", required = true, paramType = "query", dataType = "Integer"), + }) + public ResultBean<List<Map<String, Object>>> getSensorDataBySensorKey(HttpServletRequest request){ + Map<String, Object> parameters = getParametersStartingWith(request, null); + List<Map<String, Object>> sensors = historyService.getSensorDataBySensorKey(parameters); + return new ResultBean<List<Map<String, Object>>>(sensors); + } } diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java index 6a86664..064270e 100644 --- a/src/main/java/com/moral/controller/ScreenController.java +++ b/src/main/java/com/moral/controller/ScreenController.java @@ -60,7 +60,7 @@ @RequestMapping("/screen") //@CrossOrigin(origins = "*", maxAge = 3600) @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) -@Api(tags = "Screen", description = "������������") +@Api(tags = "Screen", description = "������������") public class ScreenController { public static Logger log = Logger.getLogger(ScreenController.class); @Resource @@ -626,7 +626,12 @@ }) public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgDataBySensorKey(HttpServletRequest request) throws Exception { Map<String, Object> parameters = getParametersStartingWith(request, null); - parameters.put("type", "month"); + int length = ((String)parameters.get("time")).split("-").length; + if (length == 2) { + parameters.put("type", "month"); + } else if (length == 3){ + parameters.put("type", "day"); + } parameters.put("monitorPointId", parameters.remove("monitorPoint")); String[] sensorKeys = parameters.remove("sensorKey").toString().split(","); parameters.put("sensors", Arrays.asList(sensorKeys)); diff --git a/src/main/java/com/moral/mapper/DeviceMapper.java b/src/main/java/com/moral/mapper/DeviceMapper.java index 0a934e1..3ba6f22 100644 --- a/src/main/java/com/moral/mapper/DeviceMapper.java +++ b/src/main/java/com/moral/mapper/DeviceMapper.java @@ -35,4 +35,6 @@ List<Map> countByTimes(@Param("start")Date start,@Param("end")Date end,@Param("format")String format); List<Device> getDevicesByProfession(Map<String, Object> parameters); + + List<Device> getDevicesByOrganizationId(Map<String, Object> parameters); } \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/HistoryMapper.java b/src/main/java/com/moral/mapper/HistoryMapper.java index 5f81619..4b5a131 100644 --- a/src/main/java/com/moral/mapper/HistoryMapper.java +++ b/src/main/java/com/moral/mapper/HistoryMapper.java @@ -15,5 +15,7 @@ List<String> selectNextLevelRegion(Map<String, Object> parameters); List<Map<String, Object>> getDischargeByRegion(Map<String, Object> parameters); + + List<Map<String, Object>> getValueByMacAndSize(Map<String, Object> parameters); } \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/SensorMapper.java b/src/main/java/com/moral/mapper/SensorMapper.java index fa1d9b8..be79476 100644 --- a/src/main/java/com/moral/mapper/SensorMapper.java +++ b/src/main/java/com/moral/mapper/SensorMapper.java @@ -16,7 +16,7 @@ List<Sensor> selectByOrgId(Integer organizationId); - List<Map<String, Object>> getSensorsByDeviceVersionId(Integer deviceVersionId); + List<Map<String, Object>> getSensorsByDeviceVersionId(Map<String, Object> parameters); List<Sensor> getSensorsByCriteria(Map<String, Object> parameters); diff --git a/src/main/java/com/moral/service/DeviceService.java b/src/main/java/com/moral/service/DeviceService.java index e05acea..e76912f 100644 --- a/src/main/java/com/moral/service/DeviceService.java +++ b/src/main/java/com/moral/service/DeviceService.java @@ -42,4 +42,6 @@ Device queryById(Integer id); List<Device> getDevicesByProfessionId(Map<String, Object> parameters); + + List<Device> getDevicesByOrganizationId(Map<String, Object> parameters); } diff --git a/src/main/java/com/moral/service/HistoryService.java b/src/main/java/com/moral/service/HistoryService.java index dec4d08..1a28271 100644 --- a/src/main/java/com/moral/service/HistoryService.java +++ b/src/main/java/com/moral/service/HistoryService.java @@ -14,4 +14,9 @@ String queryValueByMacAndTime(String mac, Date time); List<Map<String, Object>> getRegionRankingData(Map<String, Object> parameters); + + List<Map<String, Object>> getSensorsDataByDevice(Map<String, Object> parameters); + + List<Map<String, Object>> getSensorDataBySensorKey(Map<String, Object> parameters); + } diff --git a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java index 2094ad5..8aa95dc 100644 --- a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java @@ -474,4 +474,9 @@ return deviceMapper.getDevicesByProfession(parameters); } + @Override + public List<Device> getDevicesByOrganizationId(Map<String, Object> parameters) { + return deviceMapper.getDevicesByOrganizationId(parameters); + } + } diff --git a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java index fa11e80..c45cb88 100644 --- a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java +++ b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java @@ -18,7 +18,10 @@ import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.moral.common.util.ValidateUtil; +import com.moral.entity.Device; import com.moral.entity.Profession; import com.moral.entity.Sensor; import com.moral.mapper.DeviceMapper; @@ -215,4 +218,30 @@ } return result; } + + @Override + public List<Map<String, Object>> getSensorsDataByDevice(Map<String, Object> parameters) { + List<Map<String, Object>> sensors = sensorMapper.getSensorsByDeviceVersionId(parameters); + parameters.put("size", 1); + List<Map<String, Object>> values = historyMapper.getValueByMacAndSize(parameters); + JSONObject map = JSON.parseObject(values.get(0).get("value").toString()); + Device device = deviceMapper.selectByPrimaryKey(Integer.valueOf((String) parameters.get("deviceId"))); + for (Map<String, Object> sensor : sensors) { + sensor.put("value", map.remove(sensor.get("sensor_key"))); + sensor.put("state", device.getState()); + } + return sensors; + } + + @Override + public List<Map<String, Object>> getSensorDataBySensorKey(Map<String, Object> parameters) { + parameters.put("size", Integer.valueOf(parameters.remove("size").toString())); + List<Map<String, Object>> values = historyMapper.getValueByMacAndSize(parameters); + for (Map<String, Object> value : values) { + JSONObject json = JSON.parseObject(value.remove("value").toString()); + value.put("value", json.get(parameters.get("sensorKey"))); + } + return values; + } + } diff --git a/src/main/resources/mapper/DeviceMapper.xml b/src/main/resources/mapper/DeviceMapper.xml index 4d483d0..16521ec 100644 --- a/src/main/resources/mapper/DeviceMapper.xml +++ b/src/main/resources/mapper/DeviceMapper.xml @@ -332,4 +332,34 @@ AND d.profession_id = #{professionId} </if> </select> + + <resultMap id="ResultMap" type="com.moral.entity.Device"> + <id column="id" jdbcType="INTEGER" property="id" /> + <result column="name" jdbcType="VARCHAR" property="name" /> + <result column="address" jdbcType="VARCHAR" property="address" /> + <result column="longitude" jdbcType="DOUBLE" property="longitude" /> + <result column="latitude" jdbcType="DOUBLE" property="latitude" /> + <result column="mac" jdbcType="VARCHAR" property="mac" /> + <result column="operate_user_id" jdbcType="INTEGER" property="operateUserId" /> + <result column="state" jdbcType="CHAR" property="state" /> + <result column="is_delete" jdbcType="CHAR" property="isDelete" /> + <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> + <result column="install_time" jdbcType="TIMESTAMP" property="installTime" /> + <result column="monitor_point_id" jdbcType="INTEGER" property="monitorPointId" /> + <result column="device_version_id" jdbcType="INTEGER" property="deviceVersionId" /> + <result column="profession_id" jdbcType="INTEGER" property="professionId" /> + </resultMap> + + <select id="getDevicesByOrganizationId" resultMap="ResultMap"> + SELECT + d.* + FROM + device d, + monitor_point mp + WHERE + d.monitor_point_id = mp.id + AND d.is_delete = 0 + AND mp.is_delete = 0 + AND mp.organization_id = #{organizationId} + </select> </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml index e19db1a..bef36f5 100644 --- a/src/main/resources/mapper/HistoryMapper.xml +++ b/src/main/resources/mapper/HistoryMapper.xml @@ -115,4 +115,17 @@ AND mp.${regionType}_code = #{regionCode} AND dis.`year` = #{year} </select> + + <select id="getValueByMacAndSize" resultType="java.util.Map"> + SELECT + value, + time + FROM + history + WHERE + mac = #{mac} + ORDER BY + time DESC + LIMIT #{size} + </select> </mapper> \ No newline at end of file -- Gitblit v1.8.0