diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java new file mode 100644 index 0000000..cda6e09 --- /dev/null +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java @@ -0,0 +1,55 @@ +package com.shxy.xymanager_admin.controller; + +import com.github.pagehelper.PageInfo; +import com.shxy.xymanager_common.base.BaseController; +import com.shxy.xymanager_common.base.ResponseReult; +import com.shxy.xymanager_common.entity.MntnCmdHistory; +import com.shxy.xymanager_common.entity.MntnCmds; +import com.shxy.xymanager_common.model.CmdModel; +import com.shxy.xymanager_service.service.CmdService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +@RestController +@Api(tags = {"命令相关接口"}) +@RequestMapping("cmd") +@Slf4j +public class CmdController extends BaseController { + + @Resource + CmdService cmdsService; + + @PostMapping("send") + @ApiOperation("下达命令") + public ResponseReult send(@RequestBody CmdModel model) throws Exception { + cmdsService.send(model); + return ResponseReult.success("OK"); + } + + @GetMapping("list") + @ApiOperation("查询") + public ResponseReult> list(String cmdid, String action, + Integer pageNum, Integer pageSize) { + pageNum = this.initPageNum(pageNum); + pageSize = this.initPageSize(pageSize); + PageInfo result = cmdsService.list(cmdid, action, + pageNum, pageSize); + return ResponseReult.success(result); + } + + @GetMapping("listHistory") + @ApiOperation("查询历史") + public ResponseReult> listHistory(String cmdid, String action, + Integer pageNum, Integer pageSize) { + pageNum = this.initPageNum(pageNum); + pageSize = this.initPageSize(pageSize); + PageInfo result = cmdsService.listHistory(cmdid, action, + pageNum, pageSize); + return ResponseReult.success(result); + } + +} diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MntnController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MntnController.java deleted file mode 100644 index 5cfb48b..0000000 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MntnController.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.shxy.xymanager_admin.controller; - -import com.shxy.xymanager_common.base.BaseController; -import com.shxy.xymanager_common.base.ResponseReult; -import com.shxy.xymanager_common.model.CmdModel; -import com.shxy.xymanager_service.service.MntnCmdsService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -@RestController -@Api(tags = {"命令相关接口"}) -@RequestMapping("cmd") -@Slf4j -public class MntnController extends BaseController { - - @Resource - MntnCmdsService cmdsService; - - @PostMapping("send") - @ApiOperation("下达命令") - public ResponseReult send(@RequestBody CmdModel model) throws Exception { - cmdsService.send(model); - return ResponseReult.success("OK"); - } - -} diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdHistory.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdHistory.java index 6555388..0215d72 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdHistory.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdHistory.java @@ -266,4 +266,14 @@ public class MntnCmdHistory { public void setPublishTime(Date publishTime) { this.publishTime = publishTime; } + + private Terminals terminal; + + public Terminals getTerminal() { + return terminal; + } + + public void setTerminal(Terminals terminal) { + this.terminal = terminal; + } } \ No newline at end of file diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmds.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmds.java index 8530283..12bd21e 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmds.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmds.java @@ -200,4 +200,14 @@ public class MntnCmds { public void setCreateTime(Date createTime) { this.createTime = createTime; } + + private Terminals terminal; + + public Terminals getTerminal() { + return terminal; + } + + public void setTerminal(Terminals terminal) { + this.terminal = terminal; + } } \ No newline at end of file diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/MntnCmdsServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/CmdServiceImpl.java similarity index 79% rename from xymanager_service/src/main/java/com/shxy/xymanager_service/impl/MntnCmdsServiceImpl.java rename to xymanager_service/src/main/java/com/shxy/xymanager_service/impl/CmdServiceImpl.java index 1edb75c..8db280e 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/MntnCmdsServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/CmdServiceImpl.java @@ -1,13 +1,22 @@ package com.shxy.xymanager_service.impl; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.shxy.xymanager_common.bean.PermissionDetail; import com.shxy.xymanager_common.entity.*; +import com.shxy.xymanager_common.enums.CommonStatus; import com.shxy.xymanager_common.exception.ApiException; import com.shxy.xymanager_common.model.CmdModel; +import com.shxy.xymanager_common.page.TableDataInfo; import com.shxy.xymanager_common.util.JSONUtil; +import com.shxy.xymanager_common.vo.TerminalSelectVo; import com.shxy.xymanager_dao.dao.MntnCmdHistoryMapper; import com.shxy.xymanager_dao.dao.MntnCmdsMapper; import com.shxy.xymanager_dao.dao.MntnStatusMapper; -import com.shxy.xymanager_service.service.MntnCmdsService; +import com.shxy.xymanager_dao.dao.TerminalsDao; +import com.shxy.xymanager_service.service.CmdService; +import com.shxy.xymanager_service.service.TerminalService; +import com.shxy.xymanager_service.service.UserService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -15,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -22,7 +32,7 @@ import java.util.List; @Service @Slf4j @Transactional(rollbackFor = Exception.class) -public class MntnCmdsServiceImpl implements MntnCmdsService { +public class CmdServiceImpl implements CmdService { @Resource MntnCmdsMapper cmdsMapper; @@ -30,14 +40,109 @@ public class MntnCmdsServiceImpl implements MntnCmdsService { MntnCmdHistoryMapper historyMapper; @Resource MntnStatusMapper statusMapper; + @Resource + UserService userService; + @Resource + TerminalService terminalService; + @Resource + TerminalsDao terminalsDao; + + private List getTerminalLit(String cmdid) { + TerminalSelectVo vo = new TerminalSelectVo(); + vo.setSearch(cmdid); + vo.setPageindex(1); + vo.setPagesize(10000); + TableDataInfo result = terminalService.getTerminalList(vo).getData(); + + List termIdList = new ArrayList<>(); + for (View_Dy_Line_Tower_Terminals item : result.getList()) { + termIdList.add(item.getId()); + } + if (termIdList.size() < 1) { + termIdList.add(-1); + } + return termIdList; + } @Override - public List listAll() { + public PageInfo list(String cmdid, String action, + Integer pageNum, Integer pageSize) { MntnCmdsExample example = new MntnCmdsExample(); MntnCmdsExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(cmdid)) { + List termIdList = this.getTerminalLit(cmdid); + criteria.andTermIdIn(termIdList); + } else { + PermissionDetail permit = userService.getPermissionListFull(); + if (permit.getIsSuper().equals(CommonStatus.DELETE.value())) { + criteria.andTermIdIn(permit.getTermpList()); + } + } + + if (StringUtils.isNotBlank(action)) { + criteria.andNameEqualTo(action); + } + example.setOrderByClause("id desc"); + PageHelper.startPage(pageNum, pageSize); + List list = cmdsMapper.selectByExample(example); - return list; + this.fillTerm(list); + + return new PageInfo<>(list); + } + + private void fillTerm(List list) { + HashMap map = new HashMap<>(); + for (MntnCmds item : list) { + Terminals terminal = map.get(item.getTermId()); + if (terminal == null) { + terminal = terminalsDao.selectByPrimaryKey(item.getTermId()); + map.put(item.getTermId(), terminal); + } + item.setTerminal(terminal); + } + } + + @Override + public PageInfo listHistory(String cmdid, String action, + Integer pageNum, Integer pageSize) { + + + MntnCmdHistoryExample example = new MntnCmdHistoryExample(); + MntnCmdHistoryExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(cmdid)) { + List termIdList = this.getTerminalLit(cmdid); + criteria.andTermIdIn(termIdList); + } else { + PermissionDetail permit = userService.getPermissionListFull(); + if (permit.getIsSuper().equals(CommonStatus.DELETE.value())) { + criteria.andTermIdIn(permit.getTermpList()); + } + } + + if (StringUtils.isNotBlank(action)) { + criteria.andNameEqualTo(action); + } + example.setOrderByClause("id desc"); + PageHelper.startPage(pageNum, pageSize); + + List list = historyMapper.selectByExample(example); + this.fillHisTerm(list); + + return new PageInfo<>(list); + } + + private void fillHisTerm(List list) { + HashMap map = new HashMap<>(); + for (MntnCmdHistory item : list) { + Terminals terminal = map.get(item.getTermId()); + if (terminal == null) { + terminal = terminalsDao.selectByPrimaryKey(item.getTermId()); + map.put(item.getTermId(), terminal); + } + item.setTerminal(terminal); + } } @Override diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/CmdService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/CmdService.java new file mode 100644 index 0000000..d79406e --- /dev/null +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/CmdService.java @@ -0,0 +1,19 @@ +package com.shxy.xymanager_service.service; + + +import com.github.pagehelper.PageInfo; +import com.shxy.xymanager_common.entity.MntnCmdHistory; +import com.shxy.xymanager_common.entity.MntnCmds; +import com.shxy.xymanager_common.model.CmdModel; + + +public interface CmdService { + + PageInfo list(String cmdid, String action, + Integer pageNum, Integer pageSize); + + PageInfo listHistory(String cmdid, String action, + Integer pageNum, Integer pageSize); + + void send(CmdModel model) throws Exception; +} diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/MntnCmdsService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/MntnCmdsService.java deleted file mode 100644 index a1eec6b..0000000 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/MntnCmdsService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.shxy.xymanager_service.service; - - -import com.shxy.xymanager_common.entity.MntnCmds; -import com.shxy.xymanager_common.model.CmdModel; - -import java.util.List; - -public interface MntnCmdsService { - - List listAll(); - - void send(CmdModel model) throws Exception; -}