Compare commits

..
10 Commits
12 changed files with 239 additions and 85 deletions
@@ -230,7 +230,12 @@ public class SysUserController {
user.setCreateTime(new Date());//设置创建时间
String salt = RandomUtil.randomString(8);
user.setSalt(salt);
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), password, salt);
String passwordEncode = "";
if ("admin".equals(user.getUserType())) {
passwordEncode = PasswordUtil.encrypt(user.getUsername(), "admin888", salt);
} else {
passwordEncode = PasswordUtil.encrypt(user.getUsername(), password, salt);
}
user.setPassword(passwordEncode);
user.setStatus(1);
user.setDelFlag(CommonConstant.DEL_FLAG_0);
@@ -267,10 +272,6 @@ public class SysUserController {
@NotNull
private SysUser getSysUser(@RequestBody JSONObject jsonObject, String rsaPrivateKey, SysUser sysUser) {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
String email = null;
String phone = null;
user.setEmail(email);
user.setPhone(phone);
user.setUpdateTime(new Date());
user.setPassword(sysUser.getPassword());
return user;
@@ -533,6 +533,10 @@ public class LoginServiceImpl implements ILoginService {
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
// 手机号解密
String phone = sysUser.getPhone();
phone = sysUserService.proceedPhoneDecrypt(phone);
sysUser.setPhone(phone);
obj.put("token", token);
obj.put(USER_INFO, sysUser);
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
@@ -474,7 +474,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
throw new JeroBootException("手机号已存在,请重新输入");
}
}
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUser::getUsername, user.getUsername());
int count = userMapper.selectCount(queryWrapper);
if (count > 0) {
throw new JeroBootException("用户名已存在,请重新输入");
}
//step.1 保存用户
// 对手机号、邮箱进行加密处理
this.proceedUserInfoEncrypt(user);
@@ -640,8 +645,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
this.updateById(user);
//step.2 修改角色
//处理用户角色 先删后加
sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, user.getId()));
if(oConvertUtils.isNotEmpty(roles)) {
sysUserRoleMapper.delete(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, user.getId()));
String[] arr = roles.split(",");
for (String roleId : arr) {
SysUserRole userRole = new SysUserRole(user.getId(), roleId);
+5
View File
@@ -31,5 +31,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
</project>
@@ -4,8 +4,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jero.common.api.vo.Results;
import com.jero.common.aspect.annotation.Translation;
import com.jero.modules.entity.KhDevice;
import com.jero.modules.service.IKhDeviceService;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -16,7 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.jero.common.aspect.annotation.AutoLog;
@@ -82,6 +81,7 @@ public class KhDeviceController extends JeroController<KhDevice, IKhDeviceServic
@AutoLog(value = "设备-列表查询")
@ApiOperation(value = "设备-列表查询", notes = "设备-列表查询")
@GetMapping(value = "/list")
@Translation
public Results<List<KhDevice>> queryList(KhDevice khDevice, HttpServletRequest req) {
List<KhDevice> list = khDeviceService.queryList(khDevice, req);
return Results.OK(list);
@@ -49,18 +49,13 @@ public class KhNgRealtimeDataController extends JeroController<KhNgRealtimeData,
/**
* 返回动态数据
*
* @param id
* @return
*/
@AutoLog(value = "天然气数据远传终端实时数据-返回动态数据")
@ApiOperation(value = "天然气数据远传终端实时数据-返回动态数据", notes = "油井实时数据-返回动态数据")
@GetMapping(value = "/realtimeDataResults")
public Results<Map<String, List<KhNgRealtimeData>>> realtimeDataResults(@RequestParam(name = "id", required = true) String id) {
if (!id.equals("default")) {
return Results.error("未找到对应数据");
}
Map<String, List<KhNgRealtimeData>> khOilRealtimeData = khNgRealtimeDataService.realtimeDataResults(id);
return Results.OK(khOilRealtimeData);
public Results<List<KhNgRealtimeData>> realtimeDataResults() {
return Results.OK(khNgRealtimeDataService.mockKhNgRealtimeRedisData());
}
}
@@ -1,7 +1,8 @@
package com.jero.modules.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.*;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -57,41 +58,34 @@ public class KhNgRealtimeData implements Serializable {
@Excel(name = "设备编号", width = 15)
@ApiModelProperty(value = "设备编号")
private String deviceNo;
/**设备编号*/
@Excel(name = "通道编号", width = 15)
@ApiModelProperty(value = "通道编号")
private String channelNo;
/**实时温度*/
@Excel(name = "实时温度", width = 15)
@ApiModelProperty(value = "实时温度")
private Double realTimeTemp;
private String realTimeTemp;
/**累计流量*/
@Excel(name = "累计流量", width = 15)
@ApiModelProperty(value = "累计流量")
private Double cumulativeFlow;
private String cumulativeFlow;
/**实时压力*/
@Excel(name = "实时压力", width = 15)
@ApiModelProperty(value = "实时压力")
private Double realTimePressure;
private String realTimePressure;
/**标况瞬时*/
@Excel(name = "标况瞬时", width = 15)
@ApiModelProperty(value = "标况瞬时")
private Double stdInstant;
private String stdInstant;
/**工况瞬时*/
@Excel(name = "工况瞬时", width = 15)
@ApiModelProperty(value = "工况瞬时")
private Double operationalInstant;
private String operationalInstant;
/**同步时间*/
@Excel(name = "同步时间", width = 15, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
@ApiModelProperty(value = "同步时间")
private Date syncDate;
public void mockKhOilRealtimeData() {
this.setId("default");
this.setDeviceNo("default");
this.setRealTimeTemp(RandomNumberUtil.getRandomDouble());
this.setRealTimePressure(RandomNumberUtil.getRandomDouble());
this.setCumulativeFlow(RandomNumberUtil.getRandomDouble());
this.setRealTimePressure(RandomNumberUtil.getRandomDouble());
this.setStdInstant(RandomNumberUtil.getRandomDouble());
this.setOperationalInstant(RandomNumberUtil.getRandomDouble());
}
}
@@ -1,12 +1,15 @@
package com.jero.modules.entity;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.github.javafaker.Faker;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.modules.utils.RandomNumberUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -14,9 +17,11 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import redis.clients.jedis.Jedis;
import java.io.Serializable;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author: Mzaxd
@@ -27,7 +32,7 @@ import java.util.Date;
@TableName("kh_oil_realtime_data")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="kh_oil_realTime_data对象", description="油井实时数据")
@ApiModel(value = "kh_oil_realTime_data对象", description = "油井实时数据")
public class KhOilRealtimeData implements Serializable {
private static final long serialVersionUID = 1L;
@@ -38,27 +43,37 @@ public class KhOilRealtimeData implements Serializable {
@ApiModelProperty(value = "id")
private String id;
/**创建人*/
/**
* 创建人
*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private Date createTime;
/**更新人*/
/**
* 更新人
*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
/**所属部门*/
/**
* 所属部门
*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
@@ -185,5 +200,103 @@ public class KhOilRealtimeData implements Serializable {
this.id = "default";
}
private static int dbIndex = 0;
private static boolean db1Select = true;
private static ObjectMapper mapper = new ObjectMapper();
public void mockKhOilRealtimeRedisData(Map<String, Object> result) throws JsonProcessingException {
Map<String, List<Double>> map = new HashMap<>();
List<List<Double>> ShangChongCheng = new ArrayList<>();
List<List<Double>> XiaChongCheng = new ArrayList<>();
List<List<Double>> ZuiDaZaiHe = new ArrayList<>();
List<List<Double>> ZuiXiaoZaiHe = new ArrayList<>();
JSONArray data = new JSONArray();
// 连接到Redis服务器
try (Jedis jedis = new Jedis("1.15.107.30", 6379)) {
jedis.auth("kld4....");
if (db1Select) {
// 去db1取数据
jedis.select(1);
} else {
jedis.select(2);
}
// 获取名为 runtime_data 的 JSON 字符串
String jsonData = jedis.get("runtime_data");
// 使用 Fastjson 反序列化 JSON 字符串
data = JSON.parseArray(jsonData);
}
ObjectMapper mapper = new ObjectMapper();
for (Object item : data) {
JSONObject jsonObject = (JSONObject) item;
String name = jsonObject.getString("Name");
if (!name.equals("ShiShiShiGongTu") && !name.equals("ZaiHeFenBuTu")) {
List<Double> values = jsonObject.getJSONArray("Values").toJavaList(Double.class);
map.put(name, values);
}
switch (name) {
case "ShiShiShiGongTu":
ShangChongCheng = mapper.readValue(jsonObject.getString("ShangChongCheng"), new TypeReference<List<List<Double>>>(){});
XiaChongCheng = mapper.readValue(jsonObject.getString("XiaChongCheng"), new TypeReference<List<List<Double>>>(){});
break;
case "ZaiHeFenBuTu":
ZuiDaZaiHe = mapper.readValue(jsonObject.getString("ZuiDaZaiHe"), new TypeReference<List<List<Double>>>(){});
ZuiXiaoZaiHe = mapper.readValue(jsonObject.getString("ZuiXiaoZaiHe"), new TypeReference<List<List<Double>>>(){});
break;
}
}
int size = map.get("YouYa").size();
this.oilPressure = map.get("YouYa").get(dbIndex);
this.currentA = map.get("DianLiu_A").get(dbIndex);
this.currentB = map.get("DianLiu_B").get(dbIndex);
this.currentC = map.get("DianLiu_C").get(dbIndex);
this.activePower = map.get("YouGongGongLv").get(dbIndex);
this.powerFactor = map.get("GongLvYinShu").get(dbIndex);
this.casingPressure = map.get("TaoYa").get(dbIndex);
this.voltageA = map.get("DianYa_A").get(dbIndex);
this.voltageB = map.get("DianYa_B").get(dbIndex);
this.voltageC = map.get("DianYa_C").get(dbIndex);
this.reactivePower = map.get("WuGongGongLv").get(dbIndex);
this.outputFrequency = (int) Double.parseDouble(String.valueOf(map.get("ShuChuPinLv").get(dbIndex)));
this.strokeCount = (int) Double.parseDouble(String.valueOf(map.get("ChongCi").get(dbIndex)));
this.stroke = map.get("ChongCheng").get(dbIndex);
this.minLoad = 0;
this.maxLoad = 0;
this.deviceId = "default";
this.id = "default";
Map<String, Object> chartTwo = new HashMap<>();
Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250};
List<Integer> chartTwoX = Arrays.asList(arr);
List<Double> chartTwoUp = ShangChongCheng != null ? ShangChongCheng.get(dbIndex) : null;
List<Double> chartTwoDown = XiaChongCheng != null ? XiaChongCheng.get(dbIndex) : null;
chartTwo.put("X轴", chartTwoX);
chartTwo.put("上冲程", chartTwoUp);
chartTwo.put("下冲程", chartTwoDown);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
chartTwo.put("时间", sdf.format(new Date()));
chartTwo.put("冲程", chartTwoUp.get(0));
chartTwo.put("冲次", chartTwoDown.get(0));
result.put("实时示功图", chartTwo);
Map<String, List<?>> chartThree = new HashMap<>();
List<String> chartThreeX = RandomNumberUtil.getLast30DaysFormattedDatesAscending();
List<Double> chartThreeMax = ZuiDaZaiHe != null ? ZuiDaZaiHe.get(dbIndex) : null;
List<Double> chartThreeMin = ZuiXiaoZaiHe != null ? ZuiXiaoZaiHe.get(dbIndex) : null;
chartThree.put("X轴", chartThreeX);
chartThree.put("最大载荷", chartThreeMax);
chartThree.put("最小载荷", chartThreeMin);
result.put("载荷分布图", chartThree);
dbIndex += 1;
if (dbIndex >= size) {
dbIndex = 0;
db1Select = !db1Select;
}
}
}
@@ -0,0 +1,22 @@
package com.jero.modules.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OilRealTimeRedisData {
private List<List<Double>> ShangChongCheng;
private List<List<Double>> XiaCongCheng;
private List<List<Double>> ChanYouLiang;
private List<List<Double>> ChanQiLiang;
private List<List<Double>> ZuiDaZaiHe;
private List<List<Double>> ZuiXiaoZaiHe;
}
@@ -37,4 +37,13 @@ public interface IKhNgRealtimeDataService extends IService<KhNgRealtimeData> {
* @return
*/
Map<String, List<KhNgRealtimeData>> realtimeDataResults(String id);
/**
* 实时数据
* @param
* @return
*/
List<KhNgRealtimeData> mockKhNgRealtimeRedisData();
}
@@ -1,5 +1,8 @@
package com.jero.modules.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jero.modules.entity.KhNgRealtimeData;
import com.jero.modules.entity.KhOilRealtimeData;
@@ -17,6 +20,7 @@ import com.jero.common.system.query.QueryGenerator;
import javax.servlet.http.HttpServletRequest;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import redis.clients.jedis.Jedis;
/**
@@ -57,9 +61,39 @@ public class KhNgRealtimeDataServiceImpl extends ServiceImpl<KhNgRealtimeDataMap
Map<String, List<KhNgRealtimeData>> result = new HashMap<>();
List<KhNgRealtimeData> dataList = new ArrayList<>();
KhNgRealtimeData khNgRealtimeData = new KhNgRealtimeData();
khNgRealtimeData.mockKhOilRealtimeData();
dataList.add(khNgRealtimeData);
result.put("实时运行参数", dataList);
return result;
}
@Override
public List<KhNgRealtimeData> mockKhNgRealtimeRedisData() {
Map<String, List<Double>> map = new HashMap<>();
JSONArray data = new JSONArray();
List<KhNgRealtimeData> resultList = new ArrayList<>();
// 连接到Redis服务器
try (Jedis jedis = new Jedis("1.15.107.30", 6379)) {
jedis.auth("kld4....");
jedis.select(3);
// 获取名为 flowmeter 的 JSON 字符串
String jsonData = jedis.get("flowmeter");
// 使用 Fastjson 反序列化 JSON 字符串
data = JSON.parseArray(jsonData);
}
for (Object item : data) {
KhNgRealtimeData realData = new KhNgRealtimeData();
JSONObject jsonObject = (JSONObject) item;
realData.setChannelNo(jsonObject.getString("name"));
realData.setRealTimeTemp(jsonObject.getString("temperature"));
realData.setCumulativeFlow(jsonObject.getString("totalflow"));
realData.setRealTimePressure(jsonObject.getString("pressure"));
realData.setStdInstant(jsonObject.getString("standard"));
realData.setOperationalInstant(jsonObject.getString("acture"));
resultList.add(realData);
}
return resultList;
}
}
@@ -1,25 +1,24 @@
package com.jero.modules.service.impl;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.modules.entity.KhOilRealtimeData;
import com.jero.modules.entity.OilRealTimeRedisData;
import com.jero.modules.mapper.KhOilRealtimeDataMapper;
import com.jero.modules.service.IKhOilRealtimeDataService;
import com.jero.modules.utils.RandomNumberUtil;
import io.swagger.models.auth.In;
import javafx.beans.property.SimpleListProperty;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jero.common.exception.JeroBootException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import com.github.javafaker.Faker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.system.query.QueryGenerator;
import redis.clients.jedis.Jedis;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -74,39 +73,12 @@ public class KhOilRealtimeDataServiceImpl extends ServiceImpl<KhOilRealtimeDataM
public Map<String, Object> realtimeDataResults(String id) {
KhOilRealtimeData khOilRealtimeData = new KhOilRealtimeData();
Map<String, Object> result = new HashMap<>();
khOilRealtimeData.mockKhOilRealtimeData();
try {
khOilRealtimeData.mockKhOilRealtimeRedisData(result);
} catch (Exception e) {
log.error("从redis获取数据错误", e);
}
result.put("油井实时参数", khOilRealtimeData);
Map<String, Object> chartTwo = new HashMap<>();
Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250};
List<Integer> chartTwoX = Arrays.asList(arr);
List<Integer> chartTwoUp = RandomNumberUtil.generateFakeDataList(arr.length, Integer.class);
List<Integer> chartTwoDown = this.getRandomMinusDataList(chartTwoUp);
chartTwo.put("X轴", chartTwoX);
chartTwo.put("上冲程", chartTwoUp);
chartTwo.put("下冲程", chartTwoDown);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
chartTwo.put("时间", sdf.format(new Date()));
chartTwo.put("冲程", RandomNumberUtil.getRandomDouble());
chartTwo.put("冲次", RandomNumberUtil.getRandomDouble());
result.put("实时示功图", chartTwo);
Map<String, List<?>> chartThree = new HashMap<>();
List<String> chartThreeX = RandomNumberUtil.getLast30DaysFormattedDatesAscending();
List<Integer> chartThreeMax = RandomNumberUtil.generateFakeDataList(chartThreeX.size(), Integer.class);
List<Integer> chartThreeMin = this.getRandomMinusDataList(chartThreeMax);
chartThree.put("X轴", chartThreeX);
chartThree.put("最大载荷", chartThreeMax);
chartThree.put("最小载荷", chartThreeMin);
result.put("载荷分布图", chartThree);
return result;
}
private List<Integer> getRandomMinusDataList(List<Integer> originList) {
List<Integer> data = new ArrayList<>();
for (Integer originData : originList) {
data.add(originData - RandomNumberUtil.getRandomIntBetween(5, 40));
}
return data;
}
}