22 changed files with 550 additions and 22 deletions
			
			
		@ -0,0 +1,68 @@ | 
				
			|||||||
 | 
					package com.mh.common.core.domain.dto; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonFormat; | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonInclude; | 
				
			||||||
 | 
					import org.apache.commons.lang3.builder.ToStringBuilder; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Date; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@JsonInclude(JsonInclude.Include.NON_NULL) | 
				
			||||||
 | 
					class DeviceDTO { | 
				
			||||||
 | 
					    private String otherName; | 
				
			||||||
 | 
					    private String curValue; | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 时间格式化 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | 
				
			||||||
 | 
					    private Date curTime; | 
				
			||||||
 | 
					    private Integer status; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    DeviceDTO(TempHumidityDTO data) { | 
				
			||||||
 | 
					        this.otherName = data.getOtherName(); | 
				
			||||||
 | 
					        this.curValue = data.getCurValue().stripTrailingZeros().toPlainString(); | 
				
			||||||
 | 
					        this.curTime = data.getCurTime(); | 
				
			||||||
 | 
					        this.status = data.getStatus(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getOtherName() { | 
				
			||||||
 | 
					        return otherName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setOtherName(String otherName) { | 
				
			||||||
 | 
					        this.otherName = otherName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getCurValue() { | 
				
			||||||
 | 
					        return curValue; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setCurValue(String curValue) { | 
				
			||||||
 | 
					        this.curValue = curValue; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Date getCurTime() { | 
				
			||||||
 | 
					        return curTime; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setCurTime(Date curTime) { | 
				
			||||||
 | 
					        this.curTime = curTime; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Integer getStatus() { | 
				
			||||||
 | 
					        return status; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setStatus(Integer status) { | 
				
			||||||
 | 
					        this.status = status; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String toString() { | 
				
			||||||
 | 
					        return new ToStringBuilder(this) | 
				
			||||||
 | 
					                .append("otherName", otherName) | 
				
			||||||
 | 
					                .append("curValue", curValue) | 
				
			||||||
 | 
					                .append("curTime", curTime) | 
				
			||||||
 | 
					                .append("status", status) | 
				
			||||||
 | 
					                .toString(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,64 @@ | 
				
			|||||||
 | 
					package com.mh.common.core.domain.dto; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonInclude; | 
				
			||||||
 | 
					import org.apache.commons.lang3.builder.ToStringBuilder; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList; | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 最终JSON结构类(优化分组逻辑)
 | 
				
			||||||
 | 
					@JsonInclude(JsonInclude.Include.NON_NULL) | 
				
			||||||
 | 
					public class HouseGroupDTO { | 
				
			||||||
 | 
					    private String houseId; | 
				
			||||||
 | 
					    private String houseName; | 
				
			||||||
 | 
					    private List<DeviceDTO> deviceList = new ArrayList<>(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 分组构造器
 | 
				
			||||||
 | 
					    public HouseGroupDTO(TempHumidityDTO data) { | 
				
			||||||
 | 
					        this.houseId = data.getHouseId(); | 
				
			||||||
 | 
					        this.houseName = data.getHouseName(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 合并设备的方法
 | 
				
			||||||
 | 
					    public void merge(HouseGroupDTO other) { | 
				
			||||||
 | 
					        this.deviceList.addAll(other.deviceList); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 添加单个设备
 | 
				
			||||||
 | 
					    public void addDevice(TempHumidityDTO data) { | 
				
			||||||
 | 
					        this.deviceList.add(new DeviceDTO(data)); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getHouseId() { | 
				
			||||||
 | 
					        return houseId; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setHouseId(String houseId) { | 
				
			||||||
 | 
					        this.houseId = houseId; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getHouseName() { | 
				
			||||||
 | 
					        return houseName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setHouseName(String houseName) { | 
				
			||||||
 | 
					        this.houseName = houseName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<DeviceDTO> getDeviceList() { | 
				
			||||||
 | 
					        return deviceList; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setDeviceList(List<DeviceDTO> deviceList) { | 
				
			||||||
 | 
					        this.deviceList = deviceList; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String toString() { | 
				
			||||||
 | 
					        return new ToStringBuilder(this) | 
				
			||||||
 | 
					                .append("houseId", houseId) | 
				
			||||||
 | 
					                .append("houseName", houseName) | 
				
			||||||
 | 
					                .append("deviceList", deviceList) | 
				
			||||||
 | 
					                .toString(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,93 @@ | 
				
			|||||||
 | 
					package com.mh.common.core.domain.dto; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonFormat; | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonInclude; | 
				
			||||||
 | 
					import org.apache.commons.lang3.builder.ToStringBuilder; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.math.BigDecimal; | 
				
			||||||
 | 
					import java.util.ArrayList; | 
				
			||||||
 | 
					import java.util.Date; | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author LJF | 
				
			||||||
 | 
					 * @version 1.0 | 
				
			||||||
 | 
					 * @project EEMCS | 
				
			||||||
 | 
					 * @description 温湿度DTO管理 | 
				
			||||||
 | 
					 * @date 2025-02-24 16:55:22 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class TempHumidityDTO { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String houseId; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String houseName; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String otherName; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private BigDecimal curValue; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | 
				
			||||||
 | 
					    private Date curTime; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Integer status; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getOtherName() { | 
				
			||||||
 | 
					        return otherName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setOtherName(String otherName) { | 
				
			||||||
 | 
					        this.otherName = otherName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getHouseId() { | 
				
			||||||
 | 
					        return houseId; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setHouseId(String houseId) { | 
				
			||||||
 | 
					        this.houseId = houseId; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getHouseName() { | 
				
			||||||
 | 
					        return houseName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setHouseName(String houseName) { | 
				
			||||||
 | 
					        this.houseName = houseName; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public BigDecimal getCurValue() { | 
				
			||||||
 | 
					        return curValue; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setCurValue(BigDecimal curValue) { | 
				
			||||||
 | 
					        this.curValue = curValue; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Date getCurTime() { | 
				
			||||||
 | 
					        return curTime; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setCurTime(Date curTime) { | 
				
			||||||
 | 
					        this.curTime = curTime; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Integer getStatus() { | 
				
			||||||
 | 
					        return status; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setStatus(Integer status) { | 
				
			||||||
 | 
					        this.status = status; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String toString() { | 
				
			||||||
 | 
					        return new ToStringBuilder(this) | 
				
			||||||
 | 
					                .append("houseId", houseId) | 
				
			||||||
 | 
					                .append("houseName", houseName) | 
				
			||||||
 | 
					                .append("otherName", otherName) | 
				
			||||||
 | 
					                .append("curValue", curValue) | 
				
			||||||
 | 
					                .append("curTime", curTime) | 
				
			||||||
 | 
					                .append("status", status) | 
				
			||||||
 | 
					                .toString(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,73 @@ | 
				
			|||||||
 | 
					package com.mh.common.utils.file; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.springframework.web.multipart.MultipartFile; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.*; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * @author LJF | 
				
			||||||
 | 
					 * @version 1.0 | 
				
			||||||
 | 
					 * @project EEMCS | 
				
			||||||
 | 
					 * @description file转换 | 
				
			||||||
 | 
					 * @date 2025-02-25 17:38:11 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class FileToMultipartConverter implements MultipartFile { | 
				
			||||||
 | 
					    private final File file; | 
				
			||||||
 | 
					    private final String contentType; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public FileToMultipartConverter(File file, String contentType) { | 
				
			||||||
 | 
					        this.file = file; | 
				
			||||||
 | 
					        this.contentType = contentType; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String getName() { | 
				
			||||||
 | 
					        return file.getName(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String getOriginalFilename() { | 
				
			||||||
 | 
					        return file.getName(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public String getContentType() { | 
				
			||||||
 | 
					        return contentType; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public boolean isEmpty() { | 
				
			||||||
 | 
					        return file.length() == 0; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public long getSize() { | 
				
			||||||
 | 
					        return file.length(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public byte[] getBytes() throws IOException { | 
				
			||||||
 | 
					        FileInputStream inputStream = new FileInputStream(file); | 
				
			||||||
 | 
					        byte[] bytes = new byte[(int) file.length()]; | 
				
			||||||
 | 
					        inputStream.read(bytes); | 
				
			||||||
 | 
					        inputStream.close(); | 
				
			||||||
 | 
					        return bytes; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public InputStream getInputStream() throws IOException { | 
				
			||||||
 | 
					        return new FileInputStream(file); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override | 
				
			||||||
 | 
					    public void transferTo(File dest) throws IOException, IllegalStateException { | 
				
			||||||
 | 
					        try (InputStream in = new FileInputStream(this.file); | 
				
			||||||
 | 
					             OutputStream out = new FileOutputStream(dest)) { | 
				
			||||||
 | 
					            byte[] buffer = new byte[1024]; | 
				
			||||||
 | 
					            int bytesRead; | 
				
			||||||
 | 
					            while ((bytesRead = in.read(buffer)) != -1) { | 
				
			||||||
 | 
					                out.write(buffer, 0, bytesRead); | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue