| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import com.sandu.common.domain.CommonPage; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.security.annotation.AnonymousAccess; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.param.LightControlParam; |
| | | import com.sandu.ximon.admin.param.LightRemarkParam; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.param.*; |
| | | import com.sandu.ximon.admin.schedule.LightTimeSynchronizationSchedule; |
| | | import com.sandu.ximon.admin.security.PermissionConfig; |
| | | import com.sandu.ximon.admin.service.LightEnergyDataService; |
| | | import com.sandu.ximon.admin.service.LightReportDataService; |
| | | import com.sandu.ximon.admin.service.LightReportErrorService; |
| | | import com.sandu.ximon.admin.service.LightService; |
| | | import com.sandu.ximon.dao.bo.LightBo; |
| | | import com.sandu.ximon.dao.bo.LightReportDataBo; |
| | | import com.sandu.ximon.dao.bo.LightReportErrorBo; |
| | | import com.sandu.ximon.dao.domain.LightReportData; |
| | | import com.sandu.ximon.dao.enums.MenuEnum; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 路灯相关控制类 |
| | |
| | | @RequestMapping("/v1/light") |
| | | public class LightController { |
| | | |
| | | private final LightEnergyDataService lightEnergyDataService; |
| | | private final LightService lightService; |
| | | private final LightReportDataService lightReportDataService; |
| | | private final LightReportErrorService lightReportErrorService; |
| | | private PermissionConfig permissionConfig; |
| | | |
| | | |
| | | @GetMapping("/list") |
| | | public ResponseVO<Object> listLight(BaseConditionVO conditionVO, @RequestParam(required = false) String keyword) { |
| | | List<LightBo> list = lightService.listLight(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword); |
| | | public ResponseVO<Object> listLight(BaseConditionVO conditionVO, |
| | | @RequestParam(value = "keyword", required = false) String keyword, |
| | | @RequestParam(value = "order", required = false) Integer order, |
| | | @RequestParam(value = "seq", required = false) Integer seq) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | List<LightBo> list = lightService.listLight(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword, order, seq); |
| | | return ResponseUtil.successPage(list); |
| | | } |
| | | |
| | | @PostMapping("/remark") |
| | | public ResponseVO<Object> addRemark(@RequestBody @Validated LightRemarkParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_REMARK.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean result = lightService.addRemark(param); |
| | | if (result) { |
| | | return ResponseUtil.success("添加成功"); |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping("/report/list") |
| | | public ResponseVO<Object> listReportData(BaseConditionVO conditionVO, @RequestParam(required = false) String keyword, @RequestParam(required = false) String deviceCode) { |
| | | List<LightReportDataBo> list = lightReportDataService.listReportData(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword, deviceCode); |
| | | return ResponseUtil.successPage(list); |
| | | public ResponseVO<Object> listReportData(BaseConditionVO conditionVO |
| | | , @RequestParam(value = "keyword", required = false) String keyword |
| | | , @RequestParam(value = "deviceCode", required = false) String deviceCode |
| | | , @RequestParam(value = "order", required = false) Integer order |
| | | ,@RequestParam(value = "seq", required = false) Integer seq) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_DATA.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | CommonPage commonPage = lightReportDataService.listReportData(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword, deviceCode,order,seq); |
| | | List<LightReportDataBo> lightReportDataBos = (List<LightReportDataBo>) commonPage.getList(); |
| | | |
| | | if (lightReportDataBos == null) { |
| | | return ResponseUtil.success(CommonPage.restPage(new ArrayList<>())); |
| | | } |
| | | CommonPage commonPage1 = CommonPage.restPage(lightReportDataBos); |
| | | commonPage1.setTotal(commonPage.getTotal()); |
| | | commonPage1.setTotalPage(commonPage.getTotalPage()); |
| | | |
| | | return ResponseUtil.success(commonPage1); |
| | | } |
| | | |
| | | /** |
| | | * 导出Excel |
| | | * |
| | | * @param deviceCode |
| | | * @return |
| | | */ |
| | | @GetMapping("/report/exportList") |
| | | public ResponseVO<Object> exportList(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "deviceCode", required = false) String deviceCode) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_EXPORT_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (deviceCode.isEmpty()) { |
| | | return ResponseUtil.fail("设备编号不能为空"); |
| | | } |
| | | int length = deviceCode.length(); |
| | | if (length != 24) { |
| | | return ResponseUtil.fail("设备编号长度不正确"); |
| | | } |
| | | lightReportDataService.exportList(request, response, deviceCode); |
| | | |
| | | return ResponseUtil.success("导出成功"); |
| | | } |
| | | |
| | | @GetMapping("/error/list") |
| | | public ResponseVO<Object> listReportError(BaseConditionVO conditionVO, @RequestParam(required = false) String keyword) { |
| | | List<LightReportErrorBo> list = lightReportErrorService.listReportError(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword); |
| | | return ResponseUtil.successPage(list); |
| | | public ResponseVO<Object> listReportError(BaseConditionVO conditionVO, @RequestParam(value = "keyword", required = false) String keyword |
| | | , @RequestParam(value = "errorCode", required = false) Integer errorCode) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_ERROR_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | List<LightReportErrorBo> list = lightReportErrorService.listReportError(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword, errorCode); |
| | | return ResponseUtil.success(list); |
| | | } |
| | | |
| | | |
| | | // 亮度控制 |
| | | @PostMapping("/control") |
| | | public ResponseVO<Object> controlBrightness(@RequestBody @Validated LightControlParam param) { |
| | | Integer status = lightService.controlBrightness(param); |
| | | return ResponseUtil.success(status); |
| | | public ResponseVO<Object> controlBrightness(@RequestBody @Validated List<LightControlParam> paramList) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_CONTROL.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | List<Map<String, Object>> list = lightService.controlBrightness(paramList); |
| | | return ResponseUtil.success(list); |
| | | } |
| | | |
| | | @PostMapping("/Energy") |
| | | public ResponseVO<Object> Energy() { |
| | | return ResponseUtil.success(lightEnergyDataService.energy(0)); |
| | | // return ResponseUtil.success(lightService.controlEnergy()); |
| | | } |
| | | |
| | | @PostMapping("/EnergySaving") |
| | | public ResponseVO<Object> controlEnergySaving() { |
| | | return ResponseUtil.success(lightEnergyDataService.energy(1)); |
| | | // return ResponseUtil.success(lightService.controlEnergySaving()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置功率 |
| | | */ |
| | | @PostMapping("/setPower") |
| | | public ResponseVO<Object> setPower(@RequestBody LightPowerSettingParam lightPowerSettingParam) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_SET_POWER.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean resule = lightService.setPower(lightPowerSettingParam); |
| | | return ResponseUtil.success(resule); |
| | | } |
| | | |
| | | /** |
| | | * 单灯数据列表 |
| | | */ |
| | | @GetMapping("/data/list") |
| | | public ResponseVO<Object> listData(BaseConditionVO conditionVO, @RequestParam(value = "deviceCode", required = false) String deviceCode) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_DATA.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | List<LightReportData> reportDataList = lightReportDataService.getReportDataList(conditionVO, deviceCode); |
| | | |
| | | return ResponseUtil.success(reportDataList); |
| | | } |
| | | |
| | | /** |
| | | * 设置日历(同心跳包中的6字节日期时间) |
| | | */ |
| | | @PostMapping("/SetCalendar") |
| | | public ResponseVO<Object> SetCalendar(@RequestBody @Validated LightSetCalendarParam lightSetCalendarParam) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_SETCALENDAR.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | |
| | | return ResponseUtil.success(lightService.SetCalendar(lightSetCalendarParam.getLightId(), lightSetCalendarParam.getAddress())); |
| | | } |
| | | |
| | | @AnonymousAccess |
| | | @GetMapping("/test") |
| | | public ResponseVO<Object> test() { |
| | | SpringContextHolder.getBean(LightTimeSynchronizationSchedule.class).UserSubjectRefund(); |
| | | |
| | | return ResponseUtil.success(null); |
| | | } |
| | | } |