|
@@ -0,0 +1,308 @@
|
|
|
+package org.jeecg.modules.deviceLesm.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
+import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.deviceLesm.entity.DeviceInformation;
|
|
|
+import org.jeecg.modules.deviceLesm.entity.DeviceRegion;
|
|
|
+import org.jeecg.modules.deviceLesm.service.IDeviceInformationService;
|
|
|
+import org.jeecg.modules.deviceLesm.service.IDeviceRegionService;
|
|
|
+import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
+import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
+import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 设备管理信息表
|
|
|
+ * @Author: jeecg-boot
|
|
|
+ * @Date: 2024-09-19
|
|
|
+ * @Version: V1.0
|
|
|
+ */
|
|
|
+@Api(tags="设备管理信息表")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/device/deviceInformation")
|
|
|
+@Slf4j
|
|
|
+public class DeviceInformationController extends JeecgController<DeviceInformation, IDeviceInformationService> {
|
|
|
+ @Autowired
|
|
|
+ private IDeviceInformationService deviceInformationService;
|
|
|
+ @Autowired
|
|
|
+ private IDeviceRegionService deviceRegionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @param deviceInformation
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "设备管理信息表-分页列表查询")
|
|
|
+ @ApiOperation(value="设备管理信息表-分页列表查询", notes="设备管理信息表-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<DeviceInformation>> queryPageList(DeviceInformation deviceInformation,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ QueryWrapper<DeviceInformation> queryWrapper = QueryGenerator.initQueryWrapper(deviceInformation, req.getParameterMap());
|
|
|
+ Page<DeviceInformation> page = new Page<DeviceInformation>(pageNo, pageSize);
|
|
|
+ IPage<DeviceInformation> pageList = deviceInformationService.page(page, queryWrapper);
|
|
|
+ return Result.OK(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param deviceInformation
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "设备管理信息表-添加")
|
|
|
+ @ApiOperation(value="设备管理信息表-添加", notes="设备管理信息表-添加")
|
|
|
+// @RequiresPermissions("device:device_information:add")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<String> add(@RequestBody DeviceInformation deviceInformation) {
|
|
|
+ deviceInformationService.save(deviceInformation);
|
|
|
+ return Result.OK("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param deviceInformation
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "设备管理信息表-编辑")
|
|
|
+ @ApiOperation(value="设备管理信息表-编辑", notes="设备管理信息表-编辑")
|
|
|
+// @RequiresPermissions("device:device_information:edit")
|
|
|
+ @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
+ public Result<String> edit(@RequestBody DeviceInformation deviceInformation) {
|
|
|
+ deviceInformationService.updateById(deviceInformation);
|
|
|
+ return Result.OK("编辑成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "设备管理信息表-通过id删除")
|
|
|
+ @ApiOperation(value="设备管理信息表-通过id删除", notes="设备管理信息表-通过id删除")
|
|
|
+// @RequiresPermissions("device:device_information:delete")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ deviceInformationService.removeById(id);
|
|
|
+ return Result.OK("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "设备管理信息表-批量删除")
|
|
|
+ @ApiOperation(value="设备管理信息表-批量删除", notes="设备管理信息表-批量删除")
|
|
|
+// @RequiresPermissions("device:device_information:deleteBatch")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+ this.deviceInformationService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "设备管理信息表-通过id查询")
|
|
|
+ @ApiOperation(value="设备管理信息表-通过id查询", notes="设备管理信息表-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<DeviceInformation> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ DeviceInformation deviceInformation = deviceInformationService.getById(id);
|
|
|
+ if(deviceInformation==null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ return Result.OK(deviceInformation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param deviceInformation
|
|
|
+ */
|
|
|
+// @RequiresPermissions("device:device_information:exportXls")
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, DeviceInformation deviceInformation) {
|
|
|
+// return super.exportXls(request, deviceInformation, DeviceInformation.class, "设备管理信息");
|
|
|
+ // Step.1 组装查询条件
|
|
|
+ QueryWrapper<DeviceInformation> queryWrapper = QueryGenerator.initQueryWrapper(deviceInformation, request.getParameterMap());
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+
|
|
|
+ // 过滤选中数据
|
|
|
+ String selections = request.getParameter("selections");
|
|
|
+ if (oConvertUtils.isNotEmpty(selections)) {
|
|
|
+ List<String> selectionList = Arrays.asList(selections.split(","));
|
|
|
+ queryWrapper.in("id",selectionList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step.2 获取导出数据
|
|
|
+ List<DeviceInformation> exportList = deviceInformationService.list(queryWrapper);
|
|
|
+
|
|
|
+ for (DeviceInformation deviceinfo : exportList) {
|
|
|
+ // 转换区域名称
|
|
|
+ String deviceregionid = deviceinfo.getDeviceRegionId();
|
|
|
+ if(StringUtils.isNotEmpty(deviceregionid)){
|
|
|
+ DeviceRegion deviceRegion = deviceRegionService.getById(deviceregionid);
|
|
|
+ if(deviceRegion == null) {
|
|
|
+ deviceinfo.setDeviceRegionId("");
|
|
|
+ }else{
|
|
|
+ deviceinfo.setDeviceRegionId(deviceRegion.getRegionTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Step.3 AutoPoi 导出Excel
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ //此处设置的filename无效 ,前端会重更新设置一下
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "设备信息列表");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, DeviceInformation.class);
|
|
|
+ ExportParams exportParams=new ExportParams("设备信息数据" + "报表", "导出人:" + sysUser.getRealname(), "设备信息");
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS,exportParams);
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
|
|
+ return mv;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * excel导入模板
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param deviceInformation
|
|
|
+ */
|
|
|
+// @RequiresPermissions("device:device_information:exportXls")
|
|
|
+ @RequestMapping(value = "/exportXlsModel/{type}")
|
|
|
+ public ModelAndView exportXlsModel(HttpServletRequest request, DeviceInformation deviceInformation,@PathVariable(name = "type")String type) {
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ List<String> exportFieldsList = new ArrayList<>();
|
|
|
+ Field[] fileds = DeviceInformation.class.getDeclaredFields();
|
|
|
+ List<Field> list = new ArrayList(Arrays.asList(fileds));
|
|
|
+ for(Field field : list){
|
|
|
+ if(field.getName().contains(type)){
|
|
|
+ exportFieldsList.add(field.getName());
|
|
|
+ }
|
|
|
+ if(!field.getName().contains("s7")&&!field.getName().contains("opc")&&!field.getName().contains("modbus")){
|
|
|
+ exportFieldsList.add(field.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "设备导入模板");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, DeviceInformation.class);
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("设备导入模板", "导出人:"+sysUser.getRealname(), "设备导入模板"));
|
|
|
+ mv.addObject(NormalExcelConstants.EXPORT_FIELDS,String.join(",", exportFieldsList));
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, new ArrayList<DeviceInformation>());
|
|
|
+ return mv;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+// @RequiresPermissions("device:device_information:importExcel")
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+// return super.importExcel(request, response, DeviceInformation.class);
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
+ for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
+ // 获取上传文件对象
|
|
|
+ MultipartFile file = entity.getValue();
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(2);
|
|
|
+ params.setHeadRows(1);
|
|
|
+ params.setNeedSave(true);
|
|
|
+ try {
|
|
|
+ List<DeviceInformation> list = ExcelImportUtil.importExcel(file.getInputStream(), DeviceInformation.class, params);
|
|
|
+ StringBuffer errorLine = new StringBuffer();
|
|
|
+ AtomicInteger line = new AtomicInteger(1);
|
|
|
+ list.forEach(deviceinfo -> {
|
|
|
+ QueryWrapper<DeviceRegion> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("region_title", deviceinfo.getDeviceRegionId());
|
|
|
+ // 设备状态处理
|
|
|
+ deviceinfo.setStatus("1");
|
|
|
+ // 设备区域处理
|
|
|
+ DeviceRegion deviceRegion = deviceRegionService.getOne(queryWrapper);
|
|
|
+ if(deviceRegion == null) {
|
|
|
+ deviceinfo.setDeviceRegionId("");
|
|
|
+ }else{
|
|
|
+ deviceinfo.setDeviceRegionId(deviceRegion.getId());
|
|
|
+ }
|
|
|
+ line.getAndIncrement();
|
|
|
+ });
|
|
|
+ if(errorLine.length()>0){
|
|
|
+ return Result.error("数据格式有误!有误行数:"+errorLine);
|
|
|
+ }
|
|
|
+ deviceInformationService.saveBatch(list);
|
|
|
+ return Result.OK("文件导入成功!数据行数:" + list.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ return Result.error("文件导入失败:"+e.getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ file.getInputStream().close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.OK("文件导入失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过区域划分获取设备
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/getByRegion")
|
|
|
+ public Result<List<DeviceInformation>> getByRegion(@RequestParam(name = "region") String region,@RequestParam(name = "region") String type) {
|
|
|
+ LambdaQueryWrapper<DeviceInformation> eq = new LambdaQueryWrapper<DeviceInformation>()
|
|
|
+ .eq(DeviceInformation::getDeviceRegionId, region)
|
|
|
+ .isNull(DeviceInformation::getFreq)
|
|
|
+ .eq(DeviceInformation::getDeviceGather,type);
|
|
|
+ return Result.OK(deviceInformationService.list(eq));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|