Jay
2024-11-08 f21253fe4bdd742acf546472fddf99d2fa06fecb
提交 | 用户 | 时间
a6de49 1 package com.iailab.module.data.channel.modbus.controller.admin;
H 2
03e8ac 3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
c7f709 4 import com.iailab.framework.common.pojo.CommonResult;
03e8ac 5 import com.iailab.framework.common.pojo.PageParam;
c7f709 6 import com.iailab.framework.common.pojo.PageResult;
L 7 import com.iailab.framework.common.util.object.BeanUtils;
03e8ac 8 import com.iailab.framework.common.util.object.ConvertUtils;
J 9 import com.iailab.framework.excel.core.util.ExcelUtils;
a6de49 10 import com.iailab.module.data.channel.modbus.entity.ChannelModBusTagEntity;
H 11 import com.iailab.module.data.channel.modbus.service.ChannelModbusTagService;
03e8ac 12 import com.iailab.module.data.channel.modbus.vo.ModBusTagExportExcelVO;
J 13 import com.iailab.module.data.channel.modbus.vo.ModBusTagImportExcelVO;
c7f709 14 import com.iailab.module.data.channel.modbus.vo.ModBusTagPageReqVO;
L 15 import com.iailab.module.data.channel.modbus.vo.ModBusTagRespVO;
03e8ac 16 import com.iailab.module.data.channel.tag.vo.TagImportRespVO;
f21253 17 import com.iailab.module.data.common.enums.IsEnableEnum;
03e8ac 18 import io.swagger.v3.oas.annotations.Operation;
J 19 import io.swagger.v3.oas.annotations.Parameter;
20 import io.swagger.v3.oas.annotations.Parameters;
21 import org.springframework.security.access.prepost.PreAuthorize;
22 import org.springframework.validation.annotation.Validated;
a6de49 23 import org.springframework.web.bind.annotation.*;
03e8ac 24 import org.springframework.web.multipart.MultipartFile;
a6de49 25
c7f709 26 import javax.annotation.Resource;
03e8ac 27 import javax.servlet.http.HttpServletResponse;
c7f709 28 import javax.validation.Valid;
03e8ac 29 import java.io.IOException;
J 30 import java.util.Collections;
c7f709 31 import java.util.Date;
03e8ac 32 import java.util.List;
a6de49 33 import java.util.UUID;
H 34
03e8ac 35 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
c7f709 36 import static com.iailab.framework.common.pojo.CommonResult.success;
L 37
a6de49 38 /**
c7f709 39  * @author lirm
L 40  * @Description
41  * @createTime 2024年08月27日
a6de49 42  */
H 43 @RestController
44 @RequestMapping("/data/channel/modbus/tag")
45 public class ChannelModbusTagController {
46     @Resource
47     private ChannelModbusTagService channelModbusTagService;
48
c7f709 49     @GetMapping("/page")
L 50     public CommonResult<PageResult<ModBusTagRespVO>> list(@Valid ModBusTagPageReqVO reqVO) {
51         PageResult<ChannelModBusTagEntity> page = channelModbusTagService.queryPage(reqVO);
52         return success(BeanUtils.toBean(page, ModBusTagRespVO.class));
a6de49 53     }
c7f709 54
a6de49 55     /**
c7f709 56      * 根据id查询设备详情
a6de49 57      *
H 58      * @param id
59      */
60     @GetMapping("/info/{id}")
c7f709 61     public CommonResult<ChannelModBusTagEntity> info(@PathVariable("id") String id) {
L 62         ChannelModBusTagEntity info = channelModbusTagService.info(id);
63         return success(info);
a6de49 64     }
H 65
66     /**
c7f709 67      * 添加设备
a6de49 68      *
H 69      * @param channelModBusTagEntity
70      */
a477ef 71     @PostMapping("/create")
72     public CommonResult<Boolean> create(@RequestBody ChannelModBusTagEntity channelModBusTagEntity) {
c7f709 73         String id = UUID.randomUUID().toString();
L 74         channelModBusTagEntity.setId(id);
75         channelModBusTagEntity.setCreateTime(new Date());
76         channelModbusTagService.add(channelModBusTagEntity);
77         return success(true);
a6de49 78     }
H 79
80     /**
c7f709 81      * 修改设备
a6de49 82      *
c7f709 83      * @param channelModBusTagEntity
a6de49 84      */
c7f709 85     @PutMapping("/update")
L 86     public CommonResult<Boolean> update(@RequestBody ChannelModBusTagEntity channelModBusTagEntity) {
87         channelModBusTagEntity.setUpdateTime(new Date());
88         channelModbusTagService.update(channelModBusTagEntity);
89         return success(true);
a6de49 90     }
H 91
c7f709 92     /**
L 93      * 删除设备
94      *
95      * @param id
96      */
97     @DeleteMapping("/delete")
98     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
99         channelModbusTagService.delete(id);
100         return success(true);
101     }
03e8ac 102
J 103     @GetMapping("/export")
104     @Operation(summary = "导出modbus tag列表")
105     @PreAuthorize("@ss.hasPermission('data:channel-modbus-tag:export')")
106     @ApiAccessLog(operateType = EXPORT)
107     public void exportPointList(@Validated ModBusTagPageReqVO reqVO, HttpServletResponse response) throws IOException {
108         reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
109         PageResult<ChannelModBusTagEntity> page = channelModbusTagService.queryPage(reqVO);
110
111         List<ModBusTagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), ModBusTagExportExcelVO.class);
112         ExcelUtils.write(response, "tag列表.xls", "数据", ModBusTagExportExcelVO.class, list, true);
113     }
114
115
116     @GetMapping("/get-import-template")
117     @Operation(summary = "获得tag导入模板")
118     public void importTemplate(HttpServletResponse response) throws IOException {
119         // 手动创建导出 demo
120         List<ModBusTagImportExcelVO> list = Collections.singletonList(
121                 ModBusTagImportExcelVO.builder().tagName("Tag名称").tagDesc("Tag描述").dataType("String").
f21253 122                         address("123").format("1").samplingRate(1000).enabled(IsEnableEnum.ENABLE.getCode())
03e8ac 123                         .build()
J 124         );
125         // 输出
126         ExcelUtils.write(response, "tag导入模板.xls", "tag列表", ModBusTagImportExcelVO.class, list,true);
127     }
128
129     @PostMapping("/import")
130     @Operation(summary = "导入tag")
131     @Parameters({
132             @Parameter(name = "file", description = "Excel 文件", required = true),
133             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
134     })
135     @PreAuthorize("@ss.hasPermission('data:channel-modbus-tag:import')")
136     public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
137                                                      @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
138                                                      @RequestParam("device") String device) throws Exception {
139         List<ModBusTagImportExcelVO> list = ExcelUtils.read(file, ModBusTagImportExcelVO.class);
140         return success(channelModbusTagService.importModBusTagList(list, updateSupport,device));
141     }
a6de49 142 }