21 changed files with 1484 additions and 8 deletions
@ -0,0 +1,98 @@ |
|||||
|
package com.xr.device_car.modules.analysis.controller; |
||||
|
|
||||
|
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.xr.device_car.config.common.Result; |
||||
|
import com.xr.device_car.config.utils.StringFormatterUtil; |
||||
|
import com.xr.device_car.config.utils.StringUtils; |
||||
|
import com.xr.device_car.config.utils.UserUtils; |
||||
|
import com.xr.device_car.modules.analysis.entity.DeviceCamera; |
||||
|
import com.xr.device_car.modules.analysis.entity.MeterConfig; |
||||
|
import com.xr.device_car.modules.analysis.entity.Substation; |
||||
|
import com.xr.device_car.modules.analysis.service.DeviceCameraService; |
||||
|
import com.xr.device_car.modules.analysis.service.MeterConfigService; |
||||
|
import com.xr.device_car.modules.analysis.service.SubstationService; |
||||
|
import com.xr.device_car.modules.system.entity.UserInfo; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("analysis/substation") |
||||
|
@RequiredArgsConstructor |
||||
|
public class SubstationController { |
||||
|
|
||||
|
private final SubstationService substationService; |
||||
|
private final MeterConfigService meterConfigService; |
||||
|
private final DeviceCameraService deviceCameraService; |
||||
|
|
||||
|
|
||||
|
@RequestMapping("/pageList") |
||||
|
public IPage<Substation> pageList(Substation substation, HttpServletRequest req){ |
||||
|
Page<Substation> page= StringFormatterUtil.returnPage(req); |
||||
|
QueryWrapper<Substation> query=new QueryWrapper<>(); |
||||
|
if(StringUtils.isNotEmpty(substation.getSubstationName())){ |
||||
|
query.like("substation_name",substation.getSubstationName()); |
||||
|
} |
||||
|
IPage<Substation> substationIPage= substationService.page(page,query); |
||||
|
return substationIPage; |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("/getStationList") |
||||
|
public Result<?> getStationList(){ |
||||
|
List<Substation> list1 = substationService.list(); |
||||
|
return Result.OK(list1); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("/getStation") |
||||
|
public Result<?> getStation(Integer id){ |
||||
|
Substation substation = substationService.getById(id); |
||||
|
return Result.OK(substation); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("/saveData") |
||||
|
public Result<?> saveData(Substation substation){ |
||||
|
UserInfo userInfo = UserUtils.currentUser(); |
||||
|
substation.setUpdateTime(new Date()); |
||||
|
substation.setUpdateUser(userInfo.getUserName()); |
||||
|
if(!StringUtils.isNotEmpty(substation.getId())){ |
||||
|
substation.setCreateUser(userInfo.getUserName()); |
||||
|
substation.setCreateTime(new Date()); |
||||
|
} |
||||
|
substationService.saveOrUpdate(substation); |
||||
|
return Result.OK("保存成功。"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("/delData") |
||||
|
public Result<?> delData(Integer id){ |
||||
|
QueryWrapper<DeviceCamera> query1=new QueryWrapper<>(); |
||||
|
query1.eq("station_id",id); |
||||
|
List<DeviceCamera> list1=deviceCameraService.list(query1); |
||||
|
if(!list1.isEmpty()){ |
||||
|
String str = String.join(",",list1.stream().map(n->n.getDeviceIp()).collect(Collectors.toList())); |
||||
|
if(str.length()>100){ |
||||
|
str=str.substring(0,100)+"·······"; |
||||
|
} |
||||
|
return Result.error(str+"。摄像头已绑定该变电站请先解绑",list1); |
||||
|
} |
||||
|
|
||||
|
QueryWrapper<MeterConfig> query2 = new QueryWrapper<>(); |
||||
|
query2.eq("station_id",id); |
||||
|
List<MeterConfig> list2 = meterConfigService.list(query2); |
||||
|
if(!list2.isEmpty()){ |
||||
|
String str = String.join(",",list1.stream().map(n->n.getId()+"").collect(Collectors.toList())); |
||||
|
if(str.length()>100){ |
||||
|
str=str.substring(0,100)+"·······"; |
||||
|
} |
||||
|
return Result.error(str+"。表计已绑定该变电站请先解绑",list1); |
||||
|
} |
||||
|
|
||||
|
substationService.removeById(id); |
||||
|
return Result.OK("删除成功!"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
package com.xr.device_car.modules.analysis.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* 变电站表 |
||||
|
* @TableName substation |
||||
|
*/ |
||||
|
@TableName(value ="substation") |
||||
|
@Data |
||||
|
public class Substation implements Serializable { |
||||
|
/** |
||||
|
* 主键 |
||||
|
*/ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Integer id; |
||||
|
|
||||
|
/** |
||||
|
* 变电站名称 |
||||
|
*/ |
||||
|
private String substationName; |
||||
|
|
||||
|
/** |
||||
|
* 电压等级 |
||||
|
*/ |
||||
|
private String voltageClasses; |
||||
|
|
||||
|
/** |
||||
|
* 详细地址 |
||||
|
*/ |
||||
|
private String location; |
||||
|
|
||||
|
/** |
||||
|
* 经度 |
||||
|
*/ |
||||
|
private String longitude; |
||||
|
|
||||
|
/** |
||||
|
* 纬度 |
||||
|
*/ |
||||
|
private String latitude; |
||||
|
|
||||
|
/** |
||||
|
* 联系人 |
||||
|
*/ |
||||
|
private String linkman; |
||||
|
|
||||
|
/** |
||||
|
* 联系人电话 |
||||
|
*/ |
||||
|
private String contactNumber; |
||||
|
|
||||
|
/** |
||||
|
* 创建人 |
||||
|
*/ |
||||
|
private String createUser; |
||||
|
|
||||
|
/** |
||||
|
* 创建时间 |
||||
|
*/ |
||||
|
private Date createTime; |
||||
|
|
||||
|
/** |
||||
|
* 修改人 |
||||
|
*/ |
||||
|
private String updateUser; |
||||
|
|
||||
|
/** |
||||
|
* 修改时间 |
||||
|
*/ |
||||
|
private Date updateTime; |
||||
|
|
||||
|
@TableField(exist = false) |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.xr.device_car.modules.analysis.mapper; |
||||
|
|
||||
|
import com.xr.device_car.modules.analysis.entity.Substation; |
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
|
||||
|
/** |
||||
|
* @author 范亚杰 |
||||
|
* @description 针对表【substation(变电站表)】的数据库操作Mapper |
||||
|
* @createDate 2024-06-27 16:39:33 |
||||
|
* @Entity com.xr.device_car.modules.analysis.entity.Substation |
||||
|
*/ |
||||
|
public interface SubstationMapper extends BaseMapper<Substation> { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
@ -0,0 +1,13 @@ |
|||||
|
package com.xr.device_car.modules.analysis.service; |
||||
|
|
||||
|
import com.xr.device_car.modules.analysis.entity.Substation; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
|
||||
|
/** |
||||
|
* @author 范亚杰 |
||||
|
* @description 针对表【substation(变电站表)】的数据库操作Service |
||||
|
* @createDate 2024-06-27 16:39:33 |
||||
|
*/ |
||||
|
public interface SubstationService extends IService<Substation> { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.xr.device_car.modules.analysis.service.impl; |
||||
|
|
||||
|
import com.baomidou.dynamic.datasource.annotation.DS; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.xr.device_car.modules.analysis.entity.Substation; |
||||
|
import com.xr.device_car.modules.analysis.service.SubstationService; |
||||
|
import com.xr.device_car.modules.analysis.mapper.SubstationMapper; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
/** |
||||
|
* @author 范亚杰 |
||||
|
* @description 针对表【substation(变电站表)】的数据库操作Service实现 |
||||
|
* @createDate 2024-06-27 16:39:33 |
||||
|
*/ |
||||
|
@Service |
||||
|
@DS("db2") |
||||
|
public class SubstationServiceImpl extends ServiceImpl<SubstationMapper, Substation> |
||||
|
implements SubstationService{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
@ -0,0 +1,28 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper |
||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.xr.device_car.modules.analysis.mapper.SubstationMapper"> |
||||
|
|
||||
|
<resultMap id="BaseResultMap" type="com.xr.device_car.modules.analysis.entity.Substation"> |
||||
|
<id property="id" column="id" jdbcType="INTEGER"/> |
||||
|
<result property="substationName" column="substation_name" jdbcType="VARCHAR"/> |
||||
|
<result property="voltageClasses" column="voltage_classes" jdbcType="VARCHAR"/> |
||||
|
<result property="location" column="location" jdbcType="VARCHAR"/> |
||||
|
<result property="longitude" column="longitude" jdbcType="VARCHAR"/> |
||||
|
<result property="latitude" column="latitude" jdbcType="VARCHAR"/> |
||||
|
<result property="linkman" column="linkman" jdbcType="VARCHAR"/> |
||||
|
<result property="contactNumber" column="contact_number" jdbcType="VARCHAR"/> |
||||
|
<result property="createUser" column="create_user" jdbcType="VARCHAR"/> |
||||
|
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> |
||||
|
<result property="updateUser" column="update_user" jdbcType="VARCHAR"/> |
||||
|
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<sql id="Base_Column_List"> |
||||
|
id,substation_name,voltage_classes, |
||||
|
location,longitude,latitude, |
||||
|
linkman,contact_number,create_user, |
||||
|
create_time,update_user,update_time |
||||
|
</sql> |
||||
|
</mapper> |
||||
@ -0,0 +1,85 @@ |
|||||
|
package com.xr.device.common.utils; |
||||
|
|
||||
|
import java.nio.charset.Charset; |
||||
|
import java.nio.charset.StandardCharsets; |
||||
|
|
||||
|
/** |
||||
|
* 字符集工具类 |
||||
|
* |
||||
|
* @author |
||||
|
*/ |
||||
|
public class CharsetKit |
||||
|
{ |
||||
|
/** ISO-8859-1 */ |
||||
|
public static final String ISO_8859_1 = "ISO-8859-1"; |
||||
|
/** UTF-8 */ |
||||
|
public static final String UTF_8 = "UTF-8"; |
||||
|
/** GBK */ |
||||
|
public static final String GBK = "GBK"; |
||||
|
|
||||
|
/** ISO-8859-1 */ |
||||
|
public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); |
||||
|
/** UTF-8 */ |
||||
|
public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); |
||||
|
/** GBK */ |
||||
|
public static final Charset CHARSET_GBK = Charset.forName(GBK); |
||||
|
|
||||
|
/** |
||||
|
* 转换为Charset对象 |
||||
|
* |
||||
|
* @param charset 字符集,为空则返回默认字符集 |
||||
|
* @return Charset |
||||
|
*/ |
||||
|
public static Charset charset(String charset) |
||||
|
{ |
||||
|
return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 转换字符串的字符集编码 |
||||
|
* |
||||
|
* @param source 字符串 |
||||
|
* @param srcCharset 源字符集,默认ISO-8859-1 |
||||
|
* @param destCharset 目标字符集,默认UTF-8 |
||||
|
* @return 转换后的字符集 |
||||
|
*/ |
||||
|
public static String convert(String source, String srcCharset, String destCharset) |
||||
|
{ |
||||
|
return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 转换字符串的字符集编码 |
||||
|
* |
||||
|
* @param source 字符串 |
||||
|
* @param srcCharset 源字符集,默认ISO-8859-1 |
||||
|
* @param destCharset 目标字符集,默认UTF-8 |
||||
|
* @return 转换后的字符集 |
||||
|
*/ |
||||
|
public static String convert(String source, Charset srcCharset, Charset destCharset) |
||||
|
{ |
||||
|
if (null == srcCharset) |
||||
|
{ |
||||
|
srcCharset = StandardCharsets.ISO_8859_1; |
||||
|
} |
||||
|
|
||||
|
if (null == destCharset) |
||||
|
{ |
||||
|
destCharset = StandardCharsets.UTF_8; |
||||
|
} |
||||
|
|
||||
|
if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) |
||||
|
{ |
||||
|
return source; |
||||
|
} |
||||
|
return new String(source.getBytes(srcCharset), destCharset); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return 系统字符集编码 |
||||
|
*/ |
||||
|
public static String systemCharset() |
||||
|
{ |
||||
|
return Charset.defaultCharset().name(); |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,90 @@ |
|||||
|
package com.xr.device.common.utils; |
||||
|
|
||||
|
/** |
||||
|
* 字符串格式化 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
public class StrFormatter |
||||
|
{ |
||||
|
public static final String EMPTY_JSON = "{}"; |
||||
|
public static final char C_BACKSLASH = '\\'; |
||||
|
public static final char C_DELIM_START = '{'; |
||||
|
public static final char C_DELIM_END = '}'; |
||||
|
|
||||
|
/** |
||||
|
* 格式化字符串<br> |
||||
|
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br> |
||||
|
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> |
||||
|
* 例:<br> |
||||
|
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> |
||||
|
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> |
||||
|
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> |
||||
|
* |
||||
|
* @param strPattern 字符串模板 |
||||
|
* @param argArray 参数列表 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public static String format(final String strPattern, final Object... argArray) |
||||
|
{ |
||||
|
if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) |
||||
|
{ |
||||
|
return strPattern; |
||||
|
} |
||||
|
final int strPatternLength = strPattern.length(); |
||||
|
|
||||
|
// 初始化定义好的长度以获得更好的性能
|
||||
|
StringBuilder sbuf = new StringBuilder(strPatternLength + 50); |
||||
|
|
||||
|
int handledPosition = 0; |
||||
|
int delimIndex;// 占位符所在位置
|
||||
|
for (int argIndex = 0; argIndex < argArray.length; argIndex++) |
||||
|
{ |
||||
|
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); |
||||
|
if (delimIndex == -1) |
||||
|
{ |
||||
|
if (handledPosition == 0) |
||||
|
{ |
||||
|
return strPattern; |
||||
|
} |
||||
|
else |
||||
|
{ // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
|
||||
|
sbuf.append(strPattern, handledPosition, strPatternLength); |
||||
|
return sbuf.toString(); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) |
||||
|
{ |
||||
|
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) |
||||
|
{ |
||||
|
// 转义符之前还有一个转义符,占位符依旧有效
|
||||
|
sbuf.append(strPattern, handledPosition, delimIndex - 1); |
||||
|
sbuf.append(Convert.utf8Str(argArray[argIndex])); |
||||
|
handledPosition = delimIndex + 2; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
// 占位符被转义
|
||||
|
argIndex--; |
||||
|
sbuf.append(strPattern, handledPosition, delimIndex - 1); |
||||
|
sbuf.append(C_DELIM_START); |
||||
|
handledPosition = delimIndex + 1; |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
// 正常占位符
|
||||
|
sbuf.append(strPattern, handledPosition, delimIndex); |
||||
|
sbuf.append(Convert.utf8Str(argArray[argIndex])); |
||||
|
handledPosition = delimIndex + 2; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// 加入最后一个占位符后所有的字符
|
||||
|
sbuf.append(strPattern, handledPosition, strPattern.length()); |
||||
|
|
||||
|
return sbuf.toString(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue