From 53d37173a4393caf1de249041ac4929ca5ea63cf Mon Sep 17 00:00:00 2001 From: xins Date: Sun, 8 Oct 2023 08:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?4.0=201=E3=80=81=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E5=90=AF=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E7=BD=91=E5=85=B3=E5=92=8C=E7=9B=B4=E8=BF=9E=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=8F=AF=E4=BB=A5=E6=8E=A7=E5=88=B6=202=E3=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E5=AE=8C=E5=96=84=E5=AF=B9?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9A=84=E5=A4=84=E7=90=86=203=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E6=9C=BA=E7=AB=AF=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=204=E3=80=81tenantId=E5=86=99=E5=88=B0header=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E4=BE=BF=E5=9C=A8=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E8=8E=B7=E5=8F=96=205=E3=80=81=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=AE=A1=E7=90=86=E7=A7=9F=E6=88=B7=E5=8F=AF=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/controller/HwTenantController.java | 123 ++++++++++++++++++ .../ruoyi/business/domain/HwFenceArea.java | 79 +++++++++++ .../business/mapper/HwFenceAreaMapper.java | 61 +++++++++ .../business/service/IHwCommonService.java | 10 ++ .../mapper/business/HwFenceAreaMapper.xml | 66 ++++++++++ .../ruoyi/dataprocess/common/ImageUtils.java | 72 +++++++++- 6 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwFenceArea.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwFenceAreaMapper.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwCommonService.java create mode 100644 ruoyi-modules/hw-business/src/main/resources/mapper/business/HwFenceAreaMapper.xml diff --git a/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java b/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java new file mode 100644 index 0000000..e54738d --- /dev/null +++ b/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java @@ -0,0 +1,123 @@ +package com.ruoyi.basic.controller; + + +import com.ruoyi.basic.api.domain.HwTenant; +import com.ruoyi.basic.service.IHwTenantService; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.utils.poi.ExcelUtil; +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.common.core.web.page.TableDataInfo; +import com.ruoyi.common.log.annotation.Log; +import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.annotation.RequiresPermissions; +import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.model.LoginUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +/** + * 租户信息Controller + * + * @author xins + * @date 2023-09-04 + */ +@RestController +@RequestMapping("/tenant") +public class HwTenantController extends BaseController +{ + @Autowired + private IHwTenantService hwTenantService; + + /** + * 分页查询租户信息列表 + */ + @RequiresPermissions("business:tenant:list") + @GetMapping("/list") + public TableDataInfo list(HwTenant hwTenant) + { + List list = new ArrayList(); + startPage(); + //todo 放到add中 + + list = hwTenantService.selectHwTenantList(hwTenant); + return getDataTable(list); + } + + /** + * 导出租户信息列表 + */ + @RequiresPermissions("business:tenant:export") + @Log(title = "租户信息", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, HwTenant hwTenant) + { + List list = hwTenantService.selectHwTenantList(hwTenant); + ExcelUtil util = new ExcelUtil(HwTenant.class); + util.exportExcel(response, list, "租户信息数据"); + } + + /** + * 获取租户信息详细信息 + */ + @RequiresPermissions("business:tenant:query") + @GetMapping(value = "/{tenantId}") + public AjaxResult getInfo(@PathVariable("tenantId") Long tenantId) + { + return success(hwTenantService.selectHwTenantByTenantId(tenantId)); + } + + /** + * 新增租户信息 + */ + @RequiresPermissions("business:tenant:add") + @Log(title = "租户信息", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody HwTenant hwTenant) + { + LoginUser loginUser = SecurityUtils.getLoginUser(); + SysUser sysUser = loginUser.getSysUser(); + hwTenant.setIsRegister("0"); + hwTenant.setCreateBy(sysUser.getNickName()); + return toAjax(hwTenantService.insertHwTenant(hwTenant)); + } + + /** + * 修改租户信息 + */ + @RequiresPermissions("business:tenant:edit") + @Log(title = "租户信息", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody HwTenant hwTenant) + {LoginUser loginUser = SecurityUtils.getLoginUser(); + SysUser sysUser = loginUser.getSysUser(); + + hwTenant.setUpdateBy(sysUser.getNickName()); + return toAjax(hwTenantService.updateHwTenant(hwTenant)); + } + + /** + * 删除租户信息 + */ + @RequiresPermissions("business:tenant:remove") + @Log(title = "租户信息", businessType = BusinessType.DELETE) + @DeleteMapping("/{tenantIds}") + public AjaxResult remove(@PathVariable Long[] tenantIds) + { + return toAjax(hwTenantService.deleteHwTenantByTenantIds(tenantIds)); + } + + /** + * 查询租户信息列表 + */ + @GetMapping("/getTenants") + public R> getTenants(HwTenant hwTenant) + { + return R.ok(hwTenantService.selectHwTenantList(hwTenant)); + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwFenceArea.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwFenceArea.java new file mode 100644 index 0000000..9462866 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwFenceArea.java @@ -0,0 +1,79 @@ +package com.ruoyi.business.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.core.annotation.Excel; +import com.ruoyi.common.core.web.domain.BaseEntity; + +/** + * 电子围栏区域对象 hw_fence_area + * + * @author xins + * @date 2023-09-19 + */ +public class HwFenceArea extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 电子围栏区域ID */ + private Long fenceAreaId; + + /** 电子围栏ID */ + @Excel(name = "电子围栏ID") + private Long electronicFenceId; + + /** 区域形状(1、多边形,2、圆形) */ + @Excel(name = "区域形状", readConverterExp = "1=、多边形,2、圆形") + private String areaShapeFlag; + + /** 区域范围:为多边形时保存格式,经度,纬度,多个以_隔开;为圆形时的中心点和半径,,隔开 */ + @Excel(name = "区域范围:为多边形时保存格式,经度,纬度,多个以_隔开;为圆形时的中心点和半径,,隔开") + private String areaRange; + + public void setFenceAreaId(Long fenceAreaId) + { + this.fenceAreaId = fenceAreaId; + } + + public Long getFenceAreaId() + { + return fenceAreaId; + } + public void setElectronicFenceId(Long electronicFenceId) + { + this.electronicFenceId = electronicFenceId; + } + + public Long getElectronicFenceId() + { + return electronicFenceId; + } + public void setAreaShapeFlag(String areaShapeFlag) + { + this.areaShapeFlag = areaShapeFlag; + } + + public String getAreaShapeFlag() + { + return areaShapeFlag; + } + public void setAreaRange(String areaRange) + { + this.areaRange = areaRange; + } + + public String getAreaRange() + { + return areaRange; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("fenceAreaId", getFenceAreaId()) + .append("electronicFenceId", getElectronicFenceId()) + .append("areaShapeFlag", getAreaShapeFlag()) + .append("areaRange", getAreaRange()) + .toString(); + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwFenceAreaMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwFenceAreaMapper.java new file mode 100644 index 0000000..9c868dd --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwFenceAreaMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.business.mapper; + +import java.util.List; +import com.ruoyi.business.domain.HwFenceArea; + +/** + * 电子围栏区域Mapper接口 + * + * @author xins + * @date 2023-09-19 + */ +public interface HwFenceAreaMapper +{ + /** + * 查询电子围栏区域 + * + * @param fenceAreaId 电子围栏区域主键 + * @return 电子围栏区域 + */ + public HwFenceArea selectHwFenceAreaByFenceAreaId(Long fenceAreaId); + + /** + * 查询电子围栏区域列表 + * + * @param hwFenceArea 电子围栏区域 + * @return 电子围栏区域集合 + */ + public List selectHwFenceAreaList(HwFenceArea hwFenceArea); + + /** + * 新增电子围栏区域 + * + * @param hwFenceArea 电子围栏区域 + * @return 结果 + */ + public int insertHwFenceArea(HwFenceArea hwFenceArea); + + /** + * 修改电子围栏区域 + * + * @param hwFenceArea 电子围栏区域 + * @return 结果 + */ + public int updateHwFenceArea(HwFenceArea hwFenceArea); + + /** + * 删除电子围栏区域 + * + * @param fenceAreaId 电子围栏区域主键 + * @return 结果 + */ + public int deleteHwFenceAreaByFenceAreaId(Long fenceAreaId); + + /** + * 批量删除电子围栏区域 + * + * @param fenceAreaIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteHwFenceAreaByFenceAreaIds(Long[] fenceAreaIds); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwCommonService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwCommonService.java new file mode 100644 index 0000000..0b09bb5 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwCommonService.java @@ -0,0 +1,10 @@ +package com.ruoyi.business.service; + +import com.ruoyi.business.domain.HwDevice; + +public interface IHwCommonService { + + public void createTdTable(HwDevice hwDevice); + + public void updateMqttAut(HwDevice hwDevice); +} diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwFenceAreaMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwFenceAreaMapper.xml new file mode 100644 index 0000000..5695ef1 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwFenceAreaMapper.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + select fence_area_id, electronic_fence_id, area_shape_flag, area_range from hw_fence_area + + + + + + + + insert into hw_fence_area + + electronic_fence_id, + area_shape_flag, + area_range, + + + #{electronicFenceId}, + #{areaShapeFlag}, + #{areaRange}, + + + + + update hw_fence_area + + electronic_fence_id = #{electronicFenceId}, + area_shape_flag = #{areaShapeFlag}, + area_range = #{areaRange}, + + where fence_area_id = #{fenceAreaId} + + + + delete from hw_fence_area where fence_area_id = #{fenceAreaId} + + + + delete from hw_fence_area where fence_area_id in + + #{fenceAreaId} + + + \ No newline at end of file diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java index 457f2b7..523fd65 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java @@ -1,7 +1,10 @@ package com.ruoyi.dataprocess.common; +import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.core.utils.uuid.Seq; import com.ruoyi.common.core.utils.uuid.UUID; +import org.apache.commons.io.FilenameUtils; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -86,7 +89,7 @@ public class ImageUtils { * @author xins * @date 2023-09-04 15:59 */ - public static String convertBase64ToImage(String base64Str, String imagePath, String imageType, Long deviceId) { + /*public static String convertBase64ToImage(String base64Str, String imagePath, String imageType, Long deviceId) { // 解密 try { String fileName = UUID.randomUUID().toString().concat(".").concat(imageType); @@ -124,7 +127,7 @@ public class ImageUtils { return null; } - } + }*/ public static String getFileContent(FileInputStream fis, String encoding) throws IOException { @@ -139,13 +142,76 @@ public class ImageUtils { } + + private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException { + File desc = new File(uploadDir + File.separator + fileName); + + if (!desc.exists()) { + if (!desc.getParentFile().exists()) { + desc.getParentFile().mkdirs(); + } + } + return desc.isAbsolute() ? desc : desc.getAbsoluteFile(); + } + + private static final String getPathFileName(String fileName) throws IOException { + String pathFileName = "/" + fileName; + return pathFileName; + } + + + public static final String extractFilename(String originalFileName, String imagePath, String extension) { + return StringUtils.format("{}/{}/{}_{}.{}", imagePath, DateUtils.datePath(), + FilenameUtils.getBaseName(originalFileName), Seq.getId(Seq.uploadSeqType), extension); + } + + + /** + * @param: base64 + * @param: imageFileName + * @description base64字符串转图片 + * @author xins + * @date 2023-09-04 15:59 + */ + public static String convertBase64ToImage(String baseDir, String base64Str, String imagePath, String extension) throws IOException { + // 解密 + try { + String originalFileName = UUID.randomUUID().toString(); + String fileName = extractFilename(originalFileName, imagePath, extension); + String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); + + // 去掉base64前缀 data:image/jpeg;base64, + base64Str = base64Str.substring(base64Str.indexOf(",", 1) + 1); + // 解密,解密的结果是一个byte数组 + Base64.Decoder decoder = Base64.getDecoder(); + byte[] imgbytes = decoder.decode(base64Str); + for (int i = 0; i < imgbytes.length; ++i) { + if (imgbytes[i] < 0) { + imgbytes[i] += 256; + } + } + + // 保存图片 + OutputStream out = new FileOutputStream(absPath); + out.write(imgbytes); + out.flush(); + out.close(); + // 返回图片的相对路径 = 图片分类路径+图片名+图片后缀 + return getPathFileName(fileName); + } catch (IOException e) { + throw new IOException(e.getMessage(), e); + } + } + + + public static void main(String[] args) throws IOException { // 从txt文件中读取base64字符串 FileInputStream fis = new FileInputStream("e://base64test/base64test5.txt"); String base64Str = getFileContent(fis, "UTF-8"); String[] imagePatternArr = {"png", "jpg", "jpeg"}; String imageType = ImageUtils.getImageType(base64Str, imagePatternArr); - ImageUtils.convertBase64ToImage(base64Str,"images",imageType,2L); +// ImageUtils.convertBase64ToImage(base64Str,"images",imageType,2L); // 将base64字符串翻译成图片