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); } } 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)); 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); } 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); } 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); 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); } 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); } 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); } } 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; } } 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> 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>