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字符串翻译成图片