From 1bae32285fa0d8b47aca71edb961b7882a306888 Mon Sep 17 00:00:00 2001 From: guo Date: Sat, 12 Aug 2023 14:08:09 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PoisonousGasDevCurrentDataController.java | 3 ++- .../IPoisonousGasDevCurrentDataService.java | 2 ++ ...PoisonousGasDevCurrentDataServiceImpl.java | 13 ++++++++++++ .../DangerTypeRecordController.java | 20 +++++++++++++++++-- .../zhgd/xmgl/security/WebSecurityConfig.java | 1 + .../java/com/zhgd/xmgl/util/ExcelUtils.java | 11 ---------- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java b/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java index 4d12bb097..ff0d9f717 100644 --- a/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java @@ -104,9 +104,10 @@ public class PoisonousGasDevCurrentDataController { @ApiOperation(value = " 添加有毒气体-数据信息", notes = "添加有毒气体-数据信息", httpMethod = "POST") @PostMapping(value = "/add") public Result add(@RequestBody PoisonousGasDevCurrentData poisonousGasDevCurrentData) { + log.info("添加有毒气体-数据信息:{}", JSON.toJSONString(poisonousGasDevCurrentData)); Result result = new Result(); try { - poisonousGasDevCurrentDataService.save(poisonousGasDevCurrentData); + poisonousGasDevCurrentDataService.add(poisonousGasDevCurrentData); result.success("添加成功!"); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/zhgd/xmgl/modules/poisonous/service/IPoisonousGasDevCurrentDataService.java b/src/main/java/com/zhgd/xmgl/modules/poisonous/service/IPoisonousGasDevCurrentDataService.java index 81b865c3d..6011eac33 100644 --- a/src/main/java/com/zhgd/xmgl/modules/poisonous/service/IPoisonousGasDevCurrentDataService.java +++ b/src/main/java/com/zhgd/xmgl/modules/poisonous/service/IPoisonousGasDevCurrentDataService.java @@ -24,4 +24,6 @@ public interface IPoisonousGasDevCurrentDataService extends IService queryPageList(PoisonousGasDevCurrentData poisonousGasDevCurrentData, Integer pageNo, Integer pageSize, HttpServletRequest req); + + void add(PoisonousGasDevCurrentData poisonousGasDevCurrentData); } diff --git a/src/main/java/com/zhgd/xmgl/modules/poisonous/service/impl/PoisonousGasDevCurrentDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/poisonous/service/impl/PoisonousGasDevCurrentDataServiceImpl.java index b4ce0d6c8..3728f17d8 100644 --- a/src/main/java/com/zhgd/xmgl/modules/poisonous/service/impl/PoisonousGasDevCurrentDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/poisonous/service/impl/PoisonousGasDevCurrentDataServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.xmgl.modules.poisonous.entity.PoisonousGasDev; import com.zhgd.xmgl.modules.poisonous.entity.PoisonousGasDevAlarm; @@ -178,6 +179,18 @@ public class PoisonousGasDevCurrentDataServiceImpl extends ServiceImpl().eq(PoisonousGasDev::getDevSn, poisonousGasDevCurrentData.getDevSn())); + if (poisonousGasDev == null) { + throw new OpenAlertException("设备sn不存在"); + } + poisonousGasDevCurrentData.setDevName(poisonousGasDev.getDevName()); + poisonousGasDevCurrentData.setProjectSn(poisonousGasDev.getProjectSn()); + poisonousGasDevCurrentData.setLocation(poisonousGasDev.getLocation()); + save(poisonousGasDevCurrentData); + } + @NotNull private QueryWrapper getPoisonousGasDevCurrentDataQueryWrapper(PoisonousGasDevCurrentData poisonousGasDevCurrentData, HttpServletRequest req) { String defaultAlias = "pgdcd."; diff --git a/src/main/java/com/zhgd/xmgl/modules/quality/controller/DangerTypeRecordController.java b/src/main/java/com/zhgd/xmgl/modules/quality/controller/DangerTypeRecordController.java index 25d904beb..0a5e79ec4 100644 --- a/src/main/java/com/zhgd/xmgl/modules/quality/controller/DangerTypeRecordController.java +++ b/src/main/java/com/zhgd/xmgl/modules/quality/controller/DangerTypeRecordController.java @@ -6,18 +6,23 @@ import com.zhgd.jeecg.common.mybatis.EntityMap; import com.zhgd.xmgl.modules.quality.entity.DangerTypeRecord; import com.zhgd.xmgl.modules.quality.service.IDangerItemRecordService; import com.zhgd.xmgl.modules.quality.service.IDangerTypeRecordService; -import com.zhgd.xmgl.util.ExcelUtils; import com.zhgd.xmgl.util.MessageUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.util.IOUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLEncoder; import java.util.List; import java.util.Map; @@ -167,7 +172,18 @@ public class DangerTypeRecordController { @ApiOperation(value = "质量检查模板导入下载", notes = "质量检查模板导入下载") @GetMapping("/downloadDangerTypeRecordExcelTemplate") public void downloadDangerTypeRecordExcelTemplate(HttpServletResponse response) { - ExcelUtils.downloadDangerTypeRecordExcelTemplate(response); + try { + OutputStream out = response.getOutputStream(); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/vnd.ms-excel;charset=gb2312"); + response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("质量检查模板_导入模板.xlsx", "UTF-8")); + InputStream fis = new ClassPathResource("excel/质量检查模板_导入模板.xlsx").getInputStream(); + IOUtils.copy(fis, out); + out.flush(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } } diff --git a/src/main/java/com/zhgd/xmgl/security/WebSecurityConfig.java b/src/main/java/com/zhgd/xmgl/security/WebSecurityConfig.java index dee4d6ccf..2951ab64b 100644 --- a/src/main/java/com/zhgd/xmgl/security/WebSecurityConfig.java +++ b/src/main/java/com/zhgd/xmgl/security/WebSecurityConfig.java @@ -236,6 +236,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/xmgl/callback/ammeter/status").permitAll() .antMatchers("/xmgl/electricalData/add").permitAll() .antMatchers("/xmgl/upload/getRenameFile").permitAll() + .antMatchers("/xmgl/poisonousGasDevCurrentData/add").permitAll() .antMatchers(HttpMethod.OPTIONS, "/**").anonymous() .anyRequest().authenticated() // 剩下所有的验证都需要验证 .and() diff --git a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java index 605ed5a33..411208f73 100644 --- a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java @@ -221,17 +221,6 @@ public class ExcelUtils { } } - public static void downloadDangerTypeRecordExcelTemplate(HttpServletResponse response) { - try { - ClassPathResource classPathResource = new ClassPathResource("excel/质量检查模板_导入模板.xlsx"); - InputStream inputStream = classPathResource.getInputStream(); - XSSFWorkbook workbook = new XSSFWorkbook(inputStream); - downLoadExcel("质量检查模板_导入模板.xlsx", response, workbook); - } catch (IOException e) { - e.printStackTrace(); - } - } - public static void exporExcelWorkerTemplate(HttpServletResponse response, List teamList, List departmentList) { try { ClassPathResource classPathResource = new ClassPathResource("excel/人员导入模板.xlsx");