| | |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.service.GroupService; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.api.service.DeviceService; |
| | | import com.moral.api.service.HistoryDailyService; |
| | | import com.moral.api.service.HistoryFiveMinutelyService; |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.redis.RedisUtil; |
| | | import com.moral.util.WebUtils; |
| | | |
| | | /** |
| | | * web端接口 |
| | | * @author moral |
| | | * @version v1.0 |
| | | * */ |
| | | @Slf4j |
| | | @Api(tags = {"大屏"}) |
| | | @Api(tags = {"web端接口"}) |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | @RequestMapping("/web") |
| | | public class WebController { |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | private HistoryHourlyService historyHourlyService; |
| | | |
| | | @Autowired |
| | | private GroupService groupService; |
| | | private HistoryDailyService historyDailyService; |
| | | |
| | | @Autowired |
| | | private HistoryFiveMinutelyService historyFiveMinutelyService; |
| | | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | |
| | | @Autowired |
| | | private SysAreaService sysAreaService; |
| | | |
| | | /** |
| | | * @param account 账户 |
| | | * @param password 密码 |
| | | * @Auther jinpengyong |
| | | * @Description web登陆 |
| | | */ |
| | | @ApiOperation(value = "登陆", notes = "登陆") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户", required = true, paramType = "path", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "path", dataType = "String") |
| | | * @param request 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | * */ |
| | | @GetMapping("getHourlyAqi") |
| | | @ApiOperation(value = "获取一小时AQI", notes = "获取一小时AQI") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "login/{account}/{password}", method = RequestMethod.GET) |
| | | public ResultMessage login(@PathVariable("account") String account, @PathVariable("password") String password) { |
| | | if (account == null || password == null) { |
| | | return ResultMessage.fail("账户和密码不能为空"); |
| | | public ResultMessage getHourlyAqi(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | Map<String, Object> map = userService.login(account, password); |
| | | if (map.get("token") == null) { |
| | | return ResultMessage.fail(map.get("msg").toString()); |
| | | } |
| | | return ResultMessage.ok(map.get("token")); |
| | | Map<String, Object> response = historyHourlyService.getHourlyAqiByMac(params.get("mac").toString()); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @ApiOperation(value = "注销", notes = "注销") |
| | | @RequestMapping(value = "logout", method = RequestMethod.POST) |
| | | public ResultMessage logout(HttpServletRequest request) { |
| | | String token = request.getHeader("token"); |
| | | if (token == null) { |
| | | return ResultMessage.fail("未登陆"); |
| | | /** |
| | | * @param request 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | * */ |
| | | @GetMapping("getMonthAvg") |
| | | @ApiOperation(value = "获取某设备某因子本月均值", notes = "获取某设备某因子本月均值") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "sensorCode", value = "因子code", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | public ResultMessage getMonthAvg(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac") || !params.containsKey("sensorCode")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | RedisUtil.del(token); |
| | | return ResultMessage.ok(); |
| | | Map<String, Object> response = historyDailyService.getMonthAvg(params); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @ApiOperation(value = "添加账户", notes = "添加账户") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "userName", value = "账户名称", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "email", value = "邮箱", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "mobile", value = "手机号", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "wechat", value = "微信", required = false, paramType = "query", dataType = "String") |
| | | /** |
| | | * @param request 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | * */ |
| | | @GetMapping("getWindData") |
| | | @ApiOperation(value = "获取风场数据", notes = "获取风场数据") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "addUser", method = RequestMethod.POST) |
| | | public ResultMessage addUser(User user, HttpServletRequest request) { |
| | | Integer currentUserId = Integer.parseInt(request.getHeader("uid")); |
| | | Map<String, Object> map = userService.addUser(user, currentUserId); |
| | | String msg = map.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(map.get("flag").toString()); |
| | | if (flag) { |
| | | return ResultMessage.ok(msg); |
| | | public ResultMessage getWindData(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("monitorPointIds")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | String[] monitorPointIds = params.remove("monitorPointIds").toString().split(","); |
| | | params.put("monitorPointIds", monitorPointIds); |
| | | List<Object> response = historyFiveMinutelyService.getAreaWindData(params); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除账户", notes = "删除账户") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "path", dataType = "String") |
| | | /** |
| | | * @param request 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | * */ |
| | | @GetMapping("getMacSensors") |
| | | @ApiOperation(value = "根据mac获取对应所有因子", notes = "根据mac获取对应所有因子") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "deleteUser/{userId}", method = RequestMethod.GET) |
| | | public ResultMessage deleteUser(@PathVariable("userId") String userId, HttpServletRequest request) { |
| | | Integer currentUserId = Integer.parseInt(request.getHeader("uid")); |
| | | Map<String, Object> map = userService.deleteUser(Integer.parseInt(userId), currentUserId); |
| | | String msg = map.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(map.get("flag").toString()); |
| | | if (flag) { |
| | | return ResultMessage.ok(msg); |
| | | public ResultMessage getMacSensors(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | Map<String, Object> response = deviceService.getSensorsByMac(params.get("mac").toString()); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @ApiOperation(value = "修改用户信息", notes = "修改用户信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "userName", value = "账户名称", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "email", value = "邮箱", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "mobile", value = "手机号", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "wechat", value = "微信", required = false, paramType = "query", dataType = "String") |
| | | /** |
| | | * @param request 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | * */ |
| | | @GetMapping("getTrendChartData") |
| | | @ApiOperation(value = "获取监测因子趋势图数据", notes = "获取监测因子趋势图数据") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "sensorCode", value = "因子code", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "type", value = "数据类型,日(day),月(month),年(year)", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time", value = "数据时间", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "updateUser", method = RequestMethod.POST) |
| | | public ResultMessage updateUser(User user, HttpServletRequest request) { |
| | | Integer currentUserId = Integer.parseInt(request.getHeader("uid")); |
| | | Map<String, Object> map = userService.updateUser(user, currentUserId); |
| | | String msg = map.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(map.get("flag").toString()); |
| | | if (flag) { |
| | | return ResultMessage.ok(msg); |
| | | public ResultMessage getTrendChartData(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac") || !params.containsKey("sensorCode") || !params.containsKey("type") || !params.containsKey("time")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | List<Map<String, Object>> response = deviceService.getTrendChartData(params); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @ApiOperation(value = "查询用户信息", notes = "查询用户信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "userId", value = "用户id", required = false, paramType = "path", dataType = "String") |
| | | /** |
| | | * @param request 请求信息 |
| | | * @return 返回请求成功后的对象信息 |
| | | * */ |
| | | @GetMapping("getMapPath") |
| | | @ApiOperation(value = "获取当前用户地图权限", notes = "获取当前用户地图权限") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "getUserInfo/{userId}", method = RequestMethod.GET) |
| | | public ResultMessage getUserInfo(@PathVariable("userId") String userId, HttpServletRequest request) { |
| | | Integer currentUserId = Integer.parseInt(request.getHeader("uid")); |
| | | if (userId == null) { |
| | | List<User> users = userService.getUsersByOrgId(currentUserId); |
| | | return ResultMessage.ok(users); |
| | | public ResultMessage getMapPath(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("organizationId")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | User user = userService.getUserById(Integer.parseInt(userId), currentUserId); |
| | | return ResultMessage.ok(user); |
| | | } |
| | | |
| | | @ApiOperation(value = "添加组", notes = "添加组") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "groupName", value = "组名", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "addGroup", method = RequestMethod.POST) |
| | | private ResultMessage addGroup(Group group, HttpServletRequest request) { |
| | | String currentUserId = request.getHeader("uid"); |
| | | Map<String, Object> map = groupService.addGroup(group, currentUserId); |
| | | String msg = map.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(map.get("flag").toString()); |
| | | if (flag) { |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | List<Map<String, Object>> response = sysAreaService.getMapPath(Integer.parseInt(params.get("organizationId").toString())); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | } |