package com.newfiber.led.business.controller; import com.newfiber.led.business.entity.LedInformation; import com.newfiber.led.business.entity.LedSiteGrouping; import com.newfiber.led.business.entity.LedState; import com.newfiber.led.business.service.LedService; import com.newfiber.led.business.util.PageUtils; import com.newfiber.led.business.util.R; import com.newfiber.led.business.util.interceptor.DisableAuth; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; /** * Created by Xy on 2019/12/16. */ @Slf4j @RestController @RequestMapping("/led") public class LedController { @Autowired private LedService ledService; /** * 登录 */ @RequestMapping("/login") public R login(String userName, String password) { Map<String, Object> result = ledService.login(userName, password); if (result == null) { return R.error("账号或密码错误."); } return R.ok(result); } /** * 查询未于站点进行关联过的led编号 */ @RequestMapping("/queryLedNo") public R queryLedNo() { List<String> result = ledService.queryLedNo(); return R.ok(result); } /** * 查询led设备于关联站点的信息 */ @RequestMapping("/query") public R query(@RequestBody LedInformation ledInformation) { List<LedInformation> result = null; try { result = ledService.query(ledInformation.getSiteNo()); } catch (Exception e) { e.printStackTrace(); return R.error(); } return R.ok(result); } @RequestMapping("/queryLed") public R queryLed(String ledNo) { List<LedInformation> result = null; try { result = ledService.queryLed(ledNo); } catch (Exception e) { e.printStackTrace(); return R.error(); } return R.ok(result); } /** * 新增设备于站点信息的关联 */ @DisableAuth @RequestMapping("/save") public R save(@RequestBody LedInformation ledInformation) { try { ledService.save(ledInformation); } catch (Exception e) { e.printStackTrace(); return R.error("新增失败."); } return R.ok("新增成功."); } /** * 更新led设备于站点信息的关联 */ @RequestMapping("/update") public R update(@RequestBody LedInformation ledInformation) { try { ledService.update(ledInformation); } catch (Exception e) { e.printStackTrace(); return R.error("更新失败,请重试"); } return R.ok("更新成功"); } /** * 删除led设备于站点信息的关联 */ @DisableAuth @RequestMapping("/delete") public R delete(@RequestBody LedInformation ledInformation) { try { ledService.delete(ledInformation); } catch (Exception e) { e.printStackTrace(); return R.error("清空失败,请重试"); } return R.ok("清空成功"); } /** * 手动提交一次任务 */ @RequestMapping("/send") public R send(String idsDev, String value) { try { ledService.sendNew(idsDev, value); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(); } /** * 清屏 */ @RequestMapping("/clean") public R clean(String idsDev) { try { ledService.clean(idsDev); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(); } /** * 开屏 */ @RequestMapping("/open") public R open(String idsDev) { try { ledService.open(idsDev); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(); } /** * 关屏 */ @RequestMapping("/close") public R close(String idsDev) { try { ledService.close(idsDev); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(); } /** * 查询站点分组信息 */ @RequestMapping("/querySiteGroup") public R querySiteGroup(@RequestBody LedSiteGrouping ledSiteGrouping, HttpServletRequest request) { PageUtils result; try { /**从请求头获取用户名*/ String userno = request.getHeader("userno"); if (!userno.equalsIgnoreCase("Admin")) { ledSiteGrouping.setUserNo(request.getHeader("userno")); } result = ledService.querySiteGroup(ledSiteGrouping); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(result); } /** * 添加站点分组信息 */ @RequestMapping("/addSiteGroup") public R addSiteGroup(@RequestBody List<LedSiteGrouping> ledSiteGrouping) { try { ledService.addSiteGroup(ledSiteGrouping); } catch (Exception e) { e.printStackTrace(); return R.error("新增失败"); } return R.ok("新增成功"); } /** * 修改站点分组信息 */ @RequestMapping("/updateSiteGroup") public R updateSiteGroup(@RequestBody LedSiteGrouping ledSiteGrouping) { try { ledService.updateSiteGroup(ledSiteGrouping); } catch (Exception e) { e.printStackTrace(); return R.error("修改失败"); } return R.ok("修改成功"); } /** * 删除站点分组信息 */ @RequestMapping("/deleteSiteGroup") public R deleteSiteGroup(@RequestBody List<Integer> ids) { try { ledService.deleteSiteGroup(ids); } catch (Exception e) { e.printStackTrace(); return R.error("删除失败"); } return R.ok("删除成功"); } /** * 查询未关联的站点详细信息 */ @RequestMapping("/querySiteMes") public R querySiteMes(@RequestBody LedSiteGrouping ledSiteGrouping, HttpServletRequest request) { PageUtils result; try { /**从请求头获取用户名*/ String userno = request.getHeader("USERNO"); if (!userno.equalsIgnoreCase("admin")) { ledSiteGrouping.setUserNo(userno); } result = ledService.querySiteMes(ledSiteGrouping); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(result); } /** * 查询led设备的离线日志 */ @RequestMapping("/queryLogs") public R queryLogs(@RequestBody LedState ledState) { PageUtils result; try { result = ledService.queryLogs(ledState); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(result); } /**配置克隆*/ @RequestMapping("/configureClone") public R configureClone(@RequestBody LedState ledState) { PageUtils result; try { result = ledService.queryLogs(ledState); } catch (Exception e) { e.printStackTrace(); return R.error("网络异常,请重试"); } return R.ok(result); } }