内网代码拷贝后修改

This commit is contained in:
wangshilong 2024-12-07 14:50:35 +08:00
parent 7dfdf48309
commit 5e286b3ea3
38 changed files with 609 additions and 576 deletions

View File

@ -15,7 +15,6 @@ import com.isu.gaswellwatch.vo.MenuVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -43,15 +42,15 @@ public class SaTokenConfigure {
.setAuth(obj -> {
// 登录校验 -- 拦截所有路由并排除/user/doLogin 用于开放登录
SaRouter.match("/**")
.notMatch( "/user/doLogin","/user/file/files")
.notMatch("/user/doLogin", "/user/file/files")
.check(r -> {
StpUtil.checkLogin();
checkPermission();
this.checkPermission();
});
})
// 异常处理方法每次setAuth函数出现异常时进入
.setError(e -> {
if(e instanceof NotLoginException){
if (e instanceof NotLoginException) {
return SaResult.error(UserConstant.NOT_LOGIN_MSG).setCode(UserConstant.NOT_LOGIN_CODE);
}
return SaResult.error(e.getMessage());
@ -76,34 +75,34 @@ public class SaTokenConfigure {
private void checkPermission() {
//先判断接口是否为限制接口
HashMap<String, List<String>> identifier = settings.getIdentifier();
String res= "";
HashMap<String, List<String>> identifier = this.settings.getIdentifier();
String res = "";
String requestPath = SaHolder.getRequest().getRequestPath();
if(identifier == null) return;
if (identifier == null) return;
for (Map.Entry<String, List<String>> entry : identifier.entrySet()) {
if(entry.getValue().contains(requestPath)){
if (entry.getValue().contains(requestPath)) {
res = entry.getKey();
}
}
//是限制接口才校验不是直接放行
if(StringUtils.isNotBlank(res)){
if (StringUtils.isNotBlank(res)) {
//获取token对应的菜单列表
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession().get(UserConstant.TOKEN_SESSION);
List<MenuVO> menuList = userService.getMenuList(userLoginInfoVO.getUserVO().getUsername());
if(CollectionUtil.isEmpty(menuList)) throw new BusinessException("未获取到用户菜单");
List<MenuVO> menuList = this.userService.getMenuList(userLoginInfoVO.getUserVO().getUsername());
if (CollectionUtil.isEmpty(menuList)) throw new BusinessException("未获取到用户菜单");
//判断菜单和标识是否合法
String menuId = SaHolder.getRequest().getHeader(UserConstant.HEADER_MENU_ID);
if(StringUtils.isBlank(menuId)) throw new BusinessException("未获取到请求发出所在菜单");
if (StringUtils.isBlank(menuId)) throw new BusinessException("未获取到请求发出所在菜单");
boolean flag = false;
for (MenuVO menuVO : menuList) {
if(menuId.equals(menuVO.getId().toString())) {
if(res.equals(menuVO.getIdentifier())){
if (menuId.equals(menuVO.getId().toString())) {
if (res.equals(menuVO.getIdentifier())) {
flag = true;
break;
}
}
}
if(!flag) throw new BusinessException("该用户没有接口" + requestPath +"的权限");
if (!flag) throw new BusinessException("该用户没有接口" + requestPath + "的权限");
}
}
}

View File

@ -1,32 +1,19 @@
package com.isu.gaswellwatch.controller;
import java.util.Collection;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isu.gaswellwatch.service.BlockService;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.vo.BlockPageQuery;
import com.isu.gaswellwatch.vo.BlockVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.annotation.OperationLog;
import jakarta.annotation.Resource;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.BlockService;
import com.isu.gaswellwatch.vo.BlockVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 区块管理
*
@ -47,7 +34,7 @@ public class BlockController {
public Response<Page<BlockVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name) {
return Response.succeed(blockService.pageForQuery(currentPage, pageSize, name));
return Response.succeed(this.blockService.pageForQuery(currentPage, pageSize, name));
}
/**
@ -55,7 +42,7 @@ public class BlockController {
*/
@GetMapping(value = "/getBlock")
public Response<BlockVO> getInfo(@RequestParam Long id) {
return Response.succeed(blockService.selectBlockById(id));
return Response.succeed(this.blockService.selectBlockById(id));
}
/**
@ -64,7 +51,7 @@ public class BlockController {
@PostMapping(value = "/add")
@OperationLog(description = "新增区块", type = LogType.ADD)
public Response<String> add(@RequestBody @Valid BlockCreateRequest blockCreateRequest) {
blockService.insertBlock(blockCreateRequest);
this.blockService.insertBlock(blockCreateRequest);
return Response.succeed();
}
@ -74,7 +61,7 @@ public class BlockController {
@PostMapping(value = "/edit")
@OperationLog(description = "修改区块", type = LogType.UPDATE)
public Response<String> edit(@RequestBody BlockEditRequest blockEditRequest) {
blockService.updateBlock(blockEditRequest);
this.blockService.updateBlock(blockEditRequest);
return Response.succeed();
}
@ -84,7 +71,7 @@ public class BlockController {
@GetMapping("/delete")
@OperationLog(description = "删除区块", type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id) {
blockService.deleteBlockById(id);
this.blockService.deleteBlockById(id);
return Response.succeed();
}
@ -93,7 +80,7 @@ public class BlockController {
*/
@GetMapping("/list")
public Response<List<BlockVO>> list() {
return Response.succeed(blockService.selectBlockList());
return Response.succeed(this.blockService.selectBlockList());
}
}

View File

@ -1,20 +1,15 @@
package com.isu.gaswellwatch.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.annotation.OperationLog;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.vo.GasWellVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
@ -38,7 +33,7 @@ public class GasWellController {
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name,
@RequestParam Long blockId) {
return Response.succeed(gasWellService.pageForQuery(currentPage, pageSize, name,blockId));
return Response.succeed(this.gasWellService.pageForQuery(currentPage, pageSize, name, blockId));
}
/**
@ -46,7 +41,7 @@ public class GasWellController {
*/
@GetMapping(value = "/getGasWell")
public Response<GasWellVO> getGasWell(@RequestParam Long id) {
return Response.succeed(gasWellService.selectGasWellById(id));
return Response.succeed(this.gasWellService.selectGasWellById(id));
}
/**
@ -55,7 +50,7 @@ public class GasWellController {
@PostMapping(value = "/add")
@OperationLog(description = "新增气井", type = LogType.ADD)
public Response<String> add(@RequestBody @Valid GasWellCreateRequest gasWellCreateRequest) {
gasWellService.insertGasWell(gasWellCreateRequest);
this.gasWellService.insertGasWell(gasWellCreateRequest);
return Response.succeed();
}
@ -65,7 +60,7 @@ public class GasWellController {
@PostMapping("/edit")
@OperationLog(description = "修改气井", type = LogType.UPDATE)
public Response<String> edit(@RequestBody GasWellEditRequest gasWellEditRequest) {
gasWellService.updateGasWell(gasWellEditRequest);
this.gasWellService.updateGasWell(gasWellEditRequest);
return Response.succeed();
}
@ -75,7 +70,7 @@ public class GasWellController {
@GetMapping("/delete")
@OperationLog(description = "删除气井", type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id) {
gasWellService.deleteGasWellById(id);
this.gasWellService.deleteGasWellById(id);
return Response.succeed();
}

View File

@ -1,16 +1,13 @@
package com.isu.gaswellwatch.controller;
import com.isu.gaswellwatch.annotation.OperationLog;
import com.isu.gaswellwatch.dto.LoginDTO;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.SummaryService;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import com.isu.gaswellwatch.vo.summary.PieSummaryVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@ -24,8 +21,8 @@ public class SummaryController {
private SummaryService summaryService;
@GetMapping("/getIndexPieSummary")
public Response<List<PieSummaryVO>> getIndexPieSummary(){
return Response.succeed(summaryService.getIndexPieSummary());
public Response<List<PieSummaryVO>> getIndexPieSummary() {
return Response.succeed(this.summaryService.getIndexPieSummary());
}
}

View File

@ -7,7 +7,6 @@ import com.isu.gaswellwatch.dto.ModifyPasswordDTO;
import com.isu.gaswellwatch.dto.UserDTO;
import com.isu.gaswellwatch.dto.UserEditDTO;
import com.isu.gaswellwatch.entity.Response;
import com.isu.gaswellwatch.entity.User;
import com.isu.gaswellwatch.enums.LogType;
import com.isu.gaswellwatch.service.UserService;
import com.isu.gaswellwatch.vo.MenuTreeVO;
@ -16,7 +15,6 @@ import com.isu.gaswellwatch.vo.UserVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -31,76 +29,77 @@ public class UserController {
private UserService userService;
@PostMapping("/doLogin")
@OperationLog(description = "用户登录",type = LogType.LOGIN)
public Response<UserLoginInfoVO> doLogin(@RequestBody @Valid LoginDTO loginDTO){
return Response.succeed(userService.doLogin(loginDTO));
@OperationLog(description = "用户登录", type = LogType.LOGIN)
public Response<UserLoginInfoVO> doLogin(@RequestBody @Valid LoginDTO loginDTO) {
return Response.succeed(this.userService.doLogin(loginDTO));
}
@GetMapping("/getMenuTreeByToken")
public Response<List<MenuTreeVO>> getMenuTreeByToken(){
return Response.succeed(userService.getMenuTreeByToken());
public Response<List<MenuTreeVO>> getMenuTreeByToken() {
return Response.succeed(this.userService.getMenuTreeByToken());
}
@GetMapping("/logout")
@OperationLog(description = "用户注销",type = LogType.LOGOUT)
public Response<String> logout(){
userService.logout();
@OperationLog(description = "用户注销", type = LogType.LOGOUT)
public Response<String> logout() {
this.userService.logout();
return Response.succeed();
}
@GetMapping("/getUser")
public Response<UserVO> getUser(@RequestParam Long id){
return Response.succeed(userService.getUser(id));
public Response<UserVO> getUser(@RequestParam Long id) {
return Response.succeed(this.userService.getUser(id));
}
@PostMapping("/modifyPassword")
public Response<String> modifyPassword(@RequestBody @Valid ModifyPasswordDTO modifyPasswordDTO){
userService.modifyPassword(modifyPasswordDTO);
public Response<String> modifyPassword(@RequestBody @Valid ModifyPasswordDTO modifyPasswordDTO) {
this.userService.modifyPassword(modifyPasswordDTO);
return Response.succeed();
}
@GetMapping("/page")
public Response<Page<UserVO>> page(@RequestParam(defaultValue = "1") Integer currentPage ,
public Response<Page<UserVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String username,
@RequestParam(required = false) String name,
@RequestParam(required = false) Long roleId,
@RequestParam(required = false) String isEnable){
return Response.succeed(userService.page(currentPage,pageSize,username,name,roleId,isEnable));
@RequestParam(required = false) String isEnable) {
return Response.succeed(this.userService.page(currentPage, pageSize, username, name, roleId, isEnable));
}
@PostMapping("/add")
@OperationLog(description = "新增用户",type = LogType.ADD)
public Response<String> add(@RequestBody @Valid UserDTO userDTO){
userService.add(userDTO);
@OperationLog(description = "新增用户", type = LogType.ADD)
public Response<String> add(@RequestBody @Valid UserDTO userDTO) {
this.userService.add(userDTO);
return Response.succeed();
}
@GetMapping("/setEnable")
public Response<String> setEnable(@RequestParam Long userId, @RequestParam String isEnable){
userService.setEnable(userId,isEnable);
public Response<String> setEnable(@RequestParam Long userId, @RequestParam String isEnable) {
this.userService.setEnable(userId, isEnable);
return Response.succeed();
}
@PostMapping("/edit")
@OperationLog(description = "编辑用户",type = LogType.UPDATE)
public Response<String> edit(@RequestBody @Valid UserEditDTO userEditDTO){
userService.edit(userEditDTO);
@OperationLog(description = "编辑用户", type = LogType.UPDATE)
public Response<String> edit(@RequestBody @Valid UserEditDTO userEditDTO) {
this.userService.edit(userEditDTO);
return Response.succeed();
}
@GetMapping("/delete")
@OperationLog(description = "删除用户",type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id){
userService.delete(id);
@OperationLog(description = "删除用户", type = LogType.DELETE)
public Response<String> delete(@RequestParam Long id) {
this.userService.delete(id);
return Response.succeed();
}
@OperationLog(description = "重置密码",type = LogType.UPDATE)
@OperationLog(description = "重置密码", type = LogType.UPDATE)
@GetMapping("/reset")
public Response<String> reset(@RequestParam Long id){
userService.reset(id);
public Response<String> reset(@RequestParam Long id) {
this.userService.reset(id);
return Response.succeed("重置密码成功重置为123456");
}
@ -110,11 +109,9 @@ public class UserController {
@RequestParam(required = false) String name,
@RequestParam(required = false) Long roleId,
@RequestParam(required = false) String isEnable) {
userService.export(response,username, name, roleId,isEnable);
this.userService.export(response, username, name, roleId, isEnable);
}
}

View File

@ -1,13 +1,14 @@
package com.isu.gaswellwatch.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.entity.Block;
import com.isu.gaswellwatch.vo.BlockVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.vo.BlockVO;
import com.isu.gaswellwatch.entity.Block;
/**
* 区块Mapper接口
@ -35,6 +36,7 @@ public interface BlockDao extends BaseMapper<Block> {
/**
* 分页查询区块列表
*
* @param page 分页信息
* @param name 区块名称
* @return 区块

View File

@ -2,7 +2,6 @@ package com.isu.gaswellwatch.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isu.gaswellwatch.entity.DeviceOptLog;
import com.isu.gaswellwatch.entity.UserDepartment;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

View File

@ -1,14 +1,15 @@
package com.isu.gaswellwatch.dao;
import java.util.Collection;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.entity.GasWell;
import com.isu.gaswellwatch.vo.GasWellVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.entity.GasWell;
import java.util.Collection;
import java.util.List;
/**
* 气井Mapper接口
@ -75,7 +76,7 @@ public interface GasWellDao extends BaseMapper<GasWell> {
*/
int deleteGasWellByIds(Collection<Long> ids);
void bindDevice(@Param("gasWellId")Long gasWellId,@Param("deviceId") Long deviceId);
void bindDevice(@Param("gasWellId") Long gasWellId, @Param("deviceId") Long deviceId);
void unbindDevice(Long id);
}

View File

@ -1,18 +1,13 @@
package com.isu.gaswellwatch.dto;
import jakarta.validation.constraints.NotBlank;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.io.Serial;
import java.time.LocalDateTime;
import java.io.Serializable;
/**
* 创建区块对象 blocks
@ -29,17 +24,23 @@ public class BlockCreateRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** id */
/**
* id
*/
private Long id;
@NotBlank(message = "名称不能为空!")
/** 名称 */
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 部门id */
/**
* 部门id
*/
private Long departmentId;

View File

@ -2,18 +2,13 @@ package com.isu.gaswellwatch.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.io.Serial;
import java.time.LocalDateTime;
import java.io.Serializable;
/**
* 修改区块对象 blocks
@ -30,18 +25,26 @@ public class BlockEditRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
@NotNull(message = "ID不能为空")
private Long id;
/** 名称 */
/**
* 名称
*/
@NotBlank(message = "名称不能为空!")
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 部门id */
/**
* 部门id
*/
private Long departmentId;
}

View File

@ -2,18 +2,13 @@ package com.isu.gaswellwatch.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.io.Serial;
import java.time.LocalDateTime;
import java.io.Serializable;
/**
* 创建气井对象 gas_wells
@ -31,17 +26,25 @@ public class GasWellCreateRequest implements Serializable {
private static final long serialVersionUID = 1L;
/** 气井ID */
/**
* 气井ID
*/
private Long id;
/** 气井名称 */
/**
* 气井名称
*/
@NotBlank(message = "气井名称不能为空")
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 所属区块 */
/**
* 所属区块
*/
@NotNull(message = "所属区块不能为空")
private Long blockId;

View File

@ -1,17 +1,12 @@
package com.isu.gaswellwatch.dto;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.io.Serial;
import java.time.LocalDateTime;
import java.io.Serializable;
/**
* 修改气井对象 gas_wells
@ -28,13 +23,19 @@ public class GasWellEditRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
private Long id;
/** 气井名称 */
/**
* 气井名称
*/
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
}

View File

@ -1,9 +1,11 @@
package com.isu.gaswellwatch.entity;
import com.isu.gaswellwatch.vo.DepartmentVO;
import lombok.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.time.LocalDateTime;
import com.isu.gaswellwatch.vo.DepartmentVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 区块对象 blocks
@ -19,22 +21,34 @@ public class Block extends Model<Block> {
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
private Long id;
/** 名称 */
/**
* 名称
*/
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 创建时间 */
/**
* 创建时间
*/
private String createTime;
/** 更新时间 */
/**
* 更新时间
*/
private String updateTime;
/** 关联部门 */
/**
* 关联部门
*/
private DepartmentVO department;

View File

@ -1,7 +1,6 @@
package com.isu.gaswellwatch.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.isu.gaswellwatch.vo.DepartmentVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -21,36 +20,55 @@ public class Device extends Model<Device> {
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
private Long id;
/** 设备类型 */
/**
* 设备类型
*/
private Long deviceType;
/** 设备编号 */
/**
* 设备编号
*/
private String code;
/** 集气站 */
/**
* 集气站
*/
private String gasStation;
/** 设备品牌 */
/**
* 设备品牌
*/
private Long product;
/** 网关通讯地址 */
/**
* 网关通讯地址
*/
private String gatewaySn;
/** 描述 */
/**
* 描述
*/
private String details;
/** 所属气井 */
/**
* 所属气井
*/
private Long gasWell;
/** 创建时间 */
/**
* 创建时间
*/
private String createTime;
/** 更新时间 */
/**
* 更新时间
*/
private String updateTime;
}

View File

@ -1,13 +1,12 @@
package com.isu.gaswellwatch.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.io.Serial;
@Data
@Builder
@ -15,6 +14,8 @@ import java.util.Date;
@NoArgsConstructor
public class DeviceOptLog extends Model<DeviceOptLog> {
@Serial
private static final long serialVersionUID = 1687383207806889137L;
private Long id;
//设备id
private Long deviceId;

View File

@ -1,13 +1,8 @@
package com.isu.gaswellwatch.entity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.time.LocalDateTime;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.*;
/**
* 气井对象 gas_wells
@ -20,32 +15,45 @@ import java.time.LocalDateTime;
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class GasWell extends Model<GasWell> {
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
private Long id;
/** 气井名称 */
/**
* 气井名称
*/
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 设备ID */
/**
* 设备ID
*/
private Long deviceId;
/** 区块ID */
/**
* 区块ID
*/
private Long blockId;
/** 创建时间 */
/**
* 创建时间
*/
private String createTime;
/** 更新时间 */
/**
* 更新时间
*/
private String updateTime;
}

View File

@ -1,21 +1,14 @@
package com.isu.gaswellwatch.mapper;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.entity.Block;
import com.isu.gaswellwatch.vo.BlockVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import com.isu.gaswellwatch.entity.Block;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.vo.BlockVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import cn.dev33.satoken.stp.StpUtil;
import com.isu.gaswellwatch.constants.UserConstant;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.List;
/**
@ -38,8 +31,8 @@ public interface BlockMapper {
default Block create(BlockCreateRequest request) {
Block block =Block.builder().build();
create(request, block);
Block block = Block.builder().build();
this.create(request, block);
return block;
}

View File

@ -1,22 +1,19 @@
package com.isu.gaswellwatch.mapper;
import cn.dev33.satoken.stp.StpUtil;
import com.isu.gaswellwatch.constants.UserConstant;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.entity.GasWell;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import com.isu.gaswellwatch.entity.GasWell;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import cn.dev33.satoken.stp.StpUtil;
import com.isu.gaswellwatch.constants.UserConstant;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.List;
import java.util.Objects;
/**
* 气井Mapper gas_wells
@ -41,14 +38,14 @@ public interface GasWellMapper {
.get(UserConstant.TOKEN_SESSION);
if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) {
}
copyToEntity(request, gasWell);
this.copyToEntity(request, gasWell);
}
default GasWell create(GasWellCreateRequest request) {
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession()
.get(UserConstant.TOKEN_SESSION);
GasWell gasWell =new GasWell();
create(request, gasWell);
GasWell gasWell = new GasWell();
this.create(request, gasWell);
return gasWell;
}

View File

@ -20,6 +20,9 @@ public class SignedNumberDecodeHandler implements DecodeHandler {
@Override
public String decode(Map<String, Object> commandPointMap, String value) {
int decimalNumber = Integer.parseInt(value, 16);
if (decimalNumber == 0) {
return String.valueOf(decimalNumber);
}
String binaryNumber = Integer.toBinaryString(decimalNumber);
binaryNumber = ReverseComplementCodeUtils.binOriginalToReverse(binaryNumber);
binaryNumber = ReverseComplementCodeUtils.binReverseToComplement(binaryNumber, "1");

View File

@ -1,15 +1,14 @@
package com.isu.gaswellwatch.service;
import java.util.List;
import java.util.Collection;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.vo.BlockPageQuery;
import com.isu.gaswellwatch.vo.BlockVO;
import com.isu.gaswellwatch.entity.Block;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.vo.BlockVO;
import java.util.Collection;
import java.util.List;
/**
* 区块Service接口
@ -38,7 +37,7 @@ public interface BlockService extends IService<Block> {
*
* @return 区块
*/
Page<BlockVO> pageForQuery(Integer currentPage,Integer pageSize,String name);
Page<BlockVO> pageForQuery(Integer currentPage, Integer pageSize, String name);
/**
* 新增区块

View File

@ -7,13 +7,14 @@ import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.vo.DepartmentVO;
import java.util.List;
public interface DepartmentService extends IService<Department> {
Page<DepartmentVO> page(Integer currentPage, Integer pageSize, String name, String code);
void add(DepartmentDTO companyDTO);
void edit(DepartmentEditDTO departmentEditDTO);
void delete(Long id);
}

View File

@ -1,14 +1,14 @@
package com.isu.gaswellwatch.service;
import java.util.List;
import java.util.Collection;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.entity.GasWell;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.vo.GasWellVO;
import java.util.Collection;
import java.util.List;
/**
* 气井Service接口

View File

@ -5,13 +5,15 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.isu.gaswellwatch.dto.RoleDTO;
import com.isu.gaswellwatch.dto.RoleEditDTO;
import com.isu.gaswellwatch.entity.Role;
import com.isu.gaswellwatch.vo.RoleVO;
public interface RoleService extends IService<Role> {
Page<Role> page(Integer currentPage, Integer pageSize, String name);
void add(RoleDTO roleDTO);
void edit(RoleEditDTO roleEditDTO);
void delete(Long id);
}

View File

@ -1,33 +1,33 @@
package com.isu.gaswellwatch.service.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.constants.UserConstant;
import com.isu.gaswellwatch.entity.*;
import com.isu.gaswellwatch.dao.BlockDao;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.entity.Block;
import com.isu.gaswellwatch.entity.BlockDepartment;
import com.isu.gaswellwatch.mapper.BlockMapper;
import com.isu.gaswellwatch.service.BlockDepartmentService;
import com.isu.gaswellwatch.service.BlockService;
import com.isu.gaswellwatch.service.UserService;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.BlockVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import com.isu.gaswellwatch.vo.UserVO;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.dto.BlockCreateRequest;
import com.isu.gaswellwatch.dto.BlockEditRequest;
import com.isu.gaswellwatch.vo.BlockPageQuery;
import com.isu.gaswellwatch.vo.BlockVO;
import com.isu.gaswellwatch.dao.BlockDao;
import com.isu.gaswellwatch.service.BlockService;
import com.isu.gaswellwatch.mapper.BlockMapper;
import org.mapstruct.factory.Mappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 区块Service业务层处理
@ -57,7 +57,7 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
*/
@Override
public BlockVO selectBlockById(Long id) {
return ConverterUtil.convert(blockDao.selectBlockById(id),BlockVO.class);
return ConverterUtil.convert(this.blockDao.selectBlockById(id), BlockVO.class);
}
/**
@ -69,14 +69,14 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
public List<BlockVO> selectBlockList() {
//根据当前用户所属的部门筛选可以看到的区块
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession().get(UserConstant.TOKEN_SESSION);
UserVO userVO = userService.selectUserInfo(userLoginInfoVO.getUserVO().getUsername());
if("admin".equals(userVO.getUsername())){
UserVO userVO = this.userService.selectUserInfo(userLoginInfoVO.getUserVO().getUsername());
if ("admin".equals(userVO.getUsername())) {
//对admin用户不进行过滤筛选
return blockDao.selectBlockList(null);
}else{
if(userVO.getDepartment()!=null){
return blockDao.selectBlockList(userVO.getDepartment().getId());
}else{
return this.blockDao.selectBlockList(null);
} else {
if (userVO.getDepartment() != null) {
return this.blockDao.selectBlockList(userVO.getDepartment().getId());
} else {
return new ArrayList<>();
}
}
@ -90,8 +90,8 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
* @return 区块
*/
@Override
public Page<BlockVO> pageForQuery(Integer currentPage,Integer pageSize,String name){
return blockDao.pageForQuery(new Page<>(currentPage, pageSize), name);
public Page<BlockVO> pageForQuery(Integer currentPage, Integer pageSize, String name) {
return this.blockDao.pageForQuery(new Page<>(currentPage, pageSize), name);
}
/**
@ -104,18 +104,18 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
@Transactional(rollbackFor = Throwable.class)
public void insertBlock(BlockCreateRequest blockCreateRequest) {
blockCreateRequest.setId(snowflakeConfig.snowflakeId());
blockDao.insertBlock(blockMapper.create(blockCreateRequest));
blockCreateRequest.setId(this.snowflakeConfig.snowflakeId());
this.blockDao.insertBlock(this.blockMapper.create(blockCreateRequest));
//增加区块部门关联
if(blockCreateRequest.getDepartmentId()!=null){
blockDepartmentService.remove(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getBlockId, blockCreateRequest.getId()));
addDepartment(blockCreateRequest.getDepartmentId(), blockCreateRequest.getId());
if (blockCreateRequest.getDepartmentId() != null) {
this.blockDepartmentService.remove(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getBlockId, blockCreateRequest.getId()));
this.addDepartment(blockCreateRequest.getDepartmentId(), blockCreateRequest.getId());
}
}
private void addDepartment(Long departmentId, Long blockId) {
BlockDepartment.builder().id(snowflakeConfig.snowflakeId()).blockId(blockId).departmentId(departmentId).build().insert();
BlockDepartment.builder().id(this.snowflakeConfig.snowflakeId()).blockId(blockId).departmentId(departmentId).build().insert();
}
/**
@ -127,12 +127,12 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
@Override
@Transactional(rollbackFor = Throwable.class)
public void updateBlock(BlockEditRequest blockEditRequest) {
updateById(Block.builder().id(blockEditRequest.getId()).name(blockEditRequest.getName()).details(blockEditRequest.getDetails()).build());
this.updateById(Block.builder().id(blockEditRequest.getId()).name(blockEditRequest.getName()).details(blockEditRequest.getDetails()).build());
//增加区块部门关联
if(blockEditRequest.getDepartmentId()!=null){
blockDepartmentService.remove(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getBlockId, blockEditRequest.getId()));
addDepartment(blockEditRequest.getDepartmentId(), blockEditRequest.getId());
if (blockEditRequest.getDepartmentId() != null) {
this.blockDepartmentService.remove(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getBlockId, blockEditRequest.getId()));
this.addDepartment(blockEditRequest.getDepartmentId(), blockEditRequest.getId());
}
}
@ -147,8 +147,8 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
public void deleteBlockById(Long id) {
//TODO 校验区块是否被气井关联
blockDao.deleteBlockById(id);
blockDepartmentService.remove(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getBlockId, id));
this.blockDao.deleteBlockById(id);
this.blockDepartmentService.remove(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getBlockId, id));
}
/**
@ -160,7 +160,7 @@ public class BlockServiceImpl extends ServiceImpl<BlockDao, Block> implements B
@Override
@Transactional(rollbackFor = Throwable.class)
public int deleteBlockByIds(Collection<Long> ids) {
return blockDao.deleteBlockByIds(ids);
return this.blockDao.deleteBlockByIds(ids);
}
}

View File

@ -5,13 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.entity.BlockDepartment;
import com.isu.gaswellwatch.service.BlockDepartmentService;
import com.isu.gaswellwatch.service.DepartmentService;
import com.isu.gaswellwatch.dao.DepartmentDao;
import com.isu.gaswellwatch.dto.*;
import com.isu.gaswellwatch.dto.DepartmentDTO;
import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.entity.BlockDepartment;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.service.BlockDepartmentService;
import com.isu.gaswellwatch.service.DepartmentService;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.DepartmentVO;
import jakarta.annotation.Resource;
@ -34,39 +35,39 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentDao, Department
private BlockDepartmentService blockDepartmentService;
@Override
public Page<DepartmentVO> page(Integer currentPage, Integer pageSize, String name, String code){
Page<DepartmentVO> page = companyDao.page(new Page<>(currentPage, pageSize),name,code);
public Page<DepartmentVO> page(Integer currentPage, Integer pageSize, String name, String code) {
Page<DepartmentVO> page = this.companyDao.page(new Page<>(currentPage, pageSize), name, code);
return ConverterUtil.convertPage(page, DepartmentVO.class);
}
@Override
public void add(DepartmentDTO companyDTO){
public void add(DepartmentDTO companyDTO) {
//查重
List<Department> list = list(new LambdaQueryWrapper<Department>().eq(Department::getName, companyDTO.getName()));
if(CollectionUtil.isNotEmpty(list)) {
List<Department> list = this.list(new LambdaQueryWrapper<Department>().eq(Department::getName, companyDTO.getName()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有相同名称,请重新输入");
}
Long companyId = snowflakeConfig.snowflakeId();
save(Department.builder().id(companyId).name(companyDTO.getName()).description(companyDTO.getDescription()).code(companyDTO.getCode()).build());
Long companyId = this.snowflakeConfig.snowflakeId();
this.save(Department.builder().id(companyId).name(companyDTO.getName()).description(companyDTO.getDescription()).code(companyDTO.getCode()).build());
}
@Override
public void edit(DepartmentEditDTO departmentEditDTO){
List<Department> list = list(new LambdaQueryWrapper<Department>().eq(Department::getName, departmentEditDTO.getName()).ne(Department::getId, departmentEditDTO.getId()));
if(CollectionUtil.isNotEmpty(list)) {
public void edit(DepartmentEditDTO departmentEditDTO) {
List<Department> list = this.list(new LambdaQueryWrapper<Department>().eq(Department::getName, departmentEditDTO.getName()).ne(Department::getId, departmentEditDTO.getId()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("部门名称已存在,请重新输入");
}
updateById(ConverterUtil.convert(departmentEditDTO, Department.class));
this.updateById(ConverterUtil.convert(departmentEditDTO, Department.class));
}
@Override
public void delete(Long id){
public void delete(Long id) {
//如果部门绑定了区块 不能删除
BlockDepartment blockDepartment = blockDepartmentService.getOne(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getDepartmentId, id));
if(blockDepartment != null){
BlockDepartment blockDepartment = this.blockDepartmentService.getOne(new LambdaQueryWrapper<BlockDepartment>().eq(BlockDepartment::getDepartmentId, id));
if (blockDepartment != null) {
throw new BusinessException("该部门已被区块绑定,不能删除");
}else {
removeById(id);
} else {
this.removeById(id);
}
}

View File

@ -8,7 +8,9 @@ import com.isu.gaswellwatch.constants.UserConstant;
import com.isu.gaswellwatch.dao.DeviceDao;
import com.isu.gaswellwatch.dao.DeviceOptLogDao;
import com.isu.gaswellwatch.entity.DeviceOptLog;
import com.isu.gaswellwatch.service.*;
import com.isu.gaswellwatch.service.BlockService;
import com.isu.gaswellwatch.service.DeviceOptLogService;
import com.isu.gaswellwatch.service.UserService;
import com.isu.gaswellwatch.vo.BlockVO;
import com.isu.gaswellwatch.vo.DeviceVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
@ -36,25 +38,25 @@ public class DeviceOptLogServiceImpl extends ServiceImpl<DeviceOptLogDao, Device
@Override
public void saveGasWellOptLog(Integer isOpen, Long deviceId) {
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession().get(UserConstant.TOKEN_SESSION);
DeviceVO deviceVO = deviceDao.getDeviceById(deviceId);
DeviceVO deviceVO = this.deviceDao.getDeviceById(deviceId);
DeviceOptLog deviceOptLog = new DeviceOptLog();
deviceOptLog.setId(snowflakeConfig.snowflakeId());
deviceOptLog.setId(this.snowflakeConfig.snowflakeId());
deviceOptLog.setDeviceId(deviceId);
deviceOptLog.setUsername(userLoginInfoVO.getUserVO().getUsername());
deviceOptLog.setName(userLoginInfoVO.getUserVO().getNickname());
BlockVO blockVO = blockService.selectBlockById(deviceVO.getGasWell().getBlockId());
deviceOptLog.setBlock("苏里格气田-"+blockVO.getName());
BlockVO blockVO = this.blockService.selectBlockById(deviceVO.getGasWell().getBlockId());
deviceOptLog.setBlock("苏里格气田-" + blockVO.getName());
deviceOptLog.setGasWell(deviceVO.getGasWell().getName());
deviceOptLog.setDeviceDetail(deviceVO.getDeviceType().getName()+"-"+deviceVO.getProduct().getName());
deviceOptLog.setDeviceDetail(deviceVO.getDeviceType().getName() + "-" + deviceVO.getProduct().getName());
deviceOptLog.setGasStation(deviceVO.getGasStation());
String content = isOpen==null?"设置成功":(isOpen==1?"开井成功":"关井成功");
String content = isOpen == null ? "设置成功" : (isOpen == 1 ? "开井成功" : "关井成功");
deviceOptLog.setContent(content);
deviceOptLogDao.insert(deviceOptLog);
this.deviceOptLogDao.insert(deviceOptLog);
}
@Override
public Page<DeviceOptLog> page(Page<DeviceOptLog> page, Date start, Date end, Long deviceId) {
return deviceDao.deviceOptLogPage(page, start, end, deviceId);
return this.deviceDao.deviceOptLogPage(page, start, end, deviceId);
}
}

View File

@ -2,20 +2,12 @@ package com.isu.gaswellwatch.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.dao.DepartmentDao;
import com.isu.gaswellwatch.dao.DictionaryDao;
import com.isu.gaswellwatch.dto.DepartmentDTO;
import com.isu.gaswellwatch.dto.DepartmentEditDTO;
import com.isu.gaswellwatch.entity.Department;
import com.isu.gaswellwatch.entity.Dictionary;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.service.DepartmentService;
import com.isu.gaswellwatch.service.DictionaryService;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.DepartmentVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -35,53 +27,53 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryDao, Dictionary
private DictionaryDao dictionaryDao;
@Override
public void add(Dictionary dictionary){
public void add(Dictionary dictionary) {
//查重 同一个类型下不能有重复code
List<Dictionary> list = list(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, dictionary.getType())
.eq(Dictionary::getCode,dictionary.getCode()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException(dictionary.getType()+"类型下已有相同code请重新输入");
List<Dictionary> list = this.list(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, dictionary.getType())
.eq(Dictionary::getCode, dictionary.getCode()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException(dictionary.getType() + "类型下已有相同code请重新输入");
}
Long dictionaryId = snowflakeConfig.snowflakeId();
save(Dictionary.builder().id(dictionaryId).type(dictionary.getType()).code(dictionary.getCode()).name(dictionary.getName())
Long dictionaryId = this.snowflakeConfig.snowflakeId();
this.save(Dictionary.builder().id(dictionaryId).type(dictionary.getType()).code(dictionary.getCode()).name(dictionary.getName())
.value(dictionary.getValue()).sort(dictionary.getSort()).build());
}
@Override
public void edit(Dictionary dictionary){
public void edit(Dictionary dictionary) {
//查重 同一个类型下不能有重复code
List<Dictionary> list = list(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, dictionary.getType())
.eq(Dictionary::getCode,dictionary.getCode()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException(dictionary.getType()+"类型下已有相同code请重新输入");
List<Dictionary> list = this.list(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, dictionary.getType())
.eq(Dictionary::getCode, dictionary.getCode()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException(dictionary.getType() + "类型下已有相同code请重新输入");
}
updateById(dictionary);
this.updateById(dictionary);
}
@Override
public void delete(Long id){
public void delete(Long id) {
//删除
removeById(id);
this.removeById(id);
}
@Override
public List<Dictionary> getByType(String type) {
return list(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, type).orderByAsc(Dictionary::getSort));
return this.list(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, type).orderByAsc(Dictionary::getSort));
}
@Override
public Dictionary getByTypeAndCode(String type, String code) {
return getOne(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, type).eq(Dictionary::getCode, code));
return this.getOne(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, type).eq(Dictionary::getCode, code));
}
@Override
public Dictionary getByTypeAndValue(String type, String value) {
return getOne(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, type).eq(Dictionary::getValue, value));
return this.getOne(new LambdaQueryWrapper<Dictionary>().eq(Dictionary::getType, type).eq(Dictionary::getValue, value));
}
@Override
public Map<String, Dictionary> getValueMapByType(String type) {
return getByType(type).stream().collect(Collectors.toMap(Dictionary::getValue, a -> a, (k1, k2) -> k1));
return this.getByType(type).stream().collect(Collectors.toMap(Dictionary::getValue, a -> a, (k1, k2) -> k1));
}

View File

@ -1,27 +1,27 @@
package com.isu.gaswellwatch.service.impl;
import java.util.Collection;
import java.util.List;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.utils.ConverterUtil;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.dao.GasWellDao;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.dao.GasWellDao;
import com.isu.gaswellwatch.entity.GasWell;
import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.mapper.GasWellMapper;
import com.isu.gaswellwatch.service.GasWellService;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.GasWellVO;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.mapstruct.factory.Mappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 气井Service业务层处理
@ -48,7 +48,7 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
*/
@Override
public GasWellVO selectGasWellById(Long id) {
return gasWellDao.selectGasWellById(id);
return this.gasWellDao.selectGasWellById(id);
}
/**
@ -59,7 +59,7 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
*/
@Override
public List<GasWellVO> selectGasWellList(GasWell gasWell) {
return gasWellMapper.toPageVO(gasWellDao.selectGasWellList(gasWell));
return this.gasWellMapper.toPageVO(this.gasWellDao.selectGasWellList(gasWell));
}
/**
@ -68,8 +68,8 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
* @return 气井
*/
@Override
public Page<GasWellVO> pageForQuery(Integer currentPage, Integer pageSize, String name, Long blockId){
return gasWellDao.pageForQuery(new Page<>(currentPage, pageSize), name,blockId);
public Page<GasWellVO> pageForQuery(Integer currentPage, Integer pageSize, String name, Long blockId) {
return this.gasWellDao.pageForQuery(new Page<>(currentPage, pageSize), name, blockId);
}
/**
@ -81,15 +81,15 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Override
@Transactional(rollbackFor = Throwable.class)
public int insertGasWell(GasWellCreateRequest gasWellCreateRequest) {
GasWell gasWell = ConverterUtil.convert(gasWellCreateRequest,GasWell.class);
GasWell gasWell = ConverterUtil.convert(gasWellCreateRequest, GasWell.class);
//查重
List<GasWell> list = list(new LambdaQueryWrapper<GasWell>().eq(GasWell::getName, gasWellCreateRequest.getName()));
if(CollectionUtil.isNotEmpty(list)) {
List<GasWell> list = this.list(new LambdaQueryWrapper<GasWell>().eq(GasWell::getName, gasWellCreateRequest.getName()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有相同名称,请重新输入");
}
gasWell.setId(snowflakeConfig.snowflakeId());
return gasWellDao.insertGasWell(gasWell);
gasWell.setId(this.snowflakeConfig.snowflakeId());
return this.gasWellDao.insertGasWell(gasWell);
}
/**
@ -101,8 +101,8 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Override
@Transactional(rollbackFor = Throwable.class)
public int updateGasWell(GasWellEditRequest gasWellEditRequest) {
GasWellVO gasWellVO = ConverterUtil.convert(gasWellEditRequest,GasWellVO.class);
return gasWellDao.updateGasWell(gasWellVO);
GasWellVO gasWellVO = ConverterUtil.convert(gasWellEditRequest, GasWellVO.class);
return this.gasWellDao.updateGasWell(gasWellVO);
}
/**
@ -115,11 +115,11 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Transactional(rollbackFor = Throwable.class)
public int deleteGasWellById(Long id) {
//判断气井是否被关联设备如果已经关联设备则无法删除
GasWellVO gasWellVO = gasWellDao.selectGasWellById(id);
if(gasWellVO.getDeviceId() != null){
GasWellVO gasWellVO = this.gasWellDao.selectGasWellById(id);
if (gasWellVO.getDeviceId() != null) {
throw new BusinessException("该气井已经关联设备,无法删除");
}
return gasWellDao.deleteGasWellById(id);
return this.gasWellDao.deleteGasWellById(id);
}
/**
@ -131,17 +131,17 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Override
@Transactional(rollbackFor = Throwable.class)
public int deleteGasWellByIds(Collection<Long> ids) {
return gasWellDao.deleteGasWellByIds(ids);
return this.gasWellDao.deleteGasWellByIds(ids);
}
@Override
public void bindDevice(Long gasWellId, Long deviceId) {
gasWellDao.bindDevice(gasWellId,deviceId);
this.gasWellDao.bindDevice(gasWellId, deviceId);
}
@Override
public void unbindDevice(Long id) {
gasWellDao.unbindDevice(id);
this.gasWellDao.unbindDevice(id);
}

View File

@ -4,8 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.constants.UserConstant;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.constants.UserConstant;
import com.isu.gaswellwatch.dao.MenuDao;
import com.isu.gaswellwatch.dto.MenuDTO;
import com.isu.gaswellwatch.dto.MenuEditDTO;
@ -23,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
@ -39,15 +38,15 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuS
private RoleMenuService roleMenuService;
@Override
public List<MenuTreeVO> getMenuTreeByRoleId(Long roleId){
if(roleId != null) return getMenuTreeByRoleIds(Collections.singletonList(roleId));
public List<MenuTreeVO> getMenuTreeByRoleId(Long roleId) {
if (roleId != null) return this.getMenuTreeByRoleIds(Collections.singletonList(roleId));
return new ArrayList<>();
}
@Override
public List<MenuListVO> getMenuListByRoleId(Long roleId){
List<MenuVO> menuVOS = menuDao.selectRoleMenu(Collections.singletonList(roleId));
if(CollectionUtil.isEmpty(menuVOS)) return new ArrayList<>();
public List<MenuListVO> getMenuListByRoleId(Long roleId) {
List<MenuVO> menuVOS = this.menuDao.selectRoleMenu(Collections.singletonList(roleId));
if (CollectionUtil.isEmpty(menuVOS)) return new ArrayList<>();
Map<Long, List<MenuVO>> map = menuVOS.stream().collect(Collectors.groupingBy(MenuVO::getId));
return map.entrySet().stream().map(entry -> {
Long id = entry.getKey();
@ -60,94 +59,94 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuS
@Override
public List<MenuTreeVO> getMenuTree(){
List<MenuTreeVO> convert = ConverterUtil.convert(list(), MenuTreeVO.class);
if(convert == null) return new ArrayList<>();
return buildTree(convert, UserConstant.MENU_ROOT_ID);
public List<MenuTreeVO> getMenuTree() {
List<MenuTreeVO> convert = ConverterUtil.convert(this.list(), MenuTreeVO.class);
if (convert == null) return new ArrayList<>();
return this.buildTree(convert, UserConstant.MENU_ROOT_ID);
}
@Override
public void add(MenuDTO menuDTO){
public void add(MenuDTO menuDTO) {
Menu convert = ConverterUtil.convert(menuDTO, Menu.class);
long menuId = snowflakeConfig.snowflakeId();
long menuId = this.snowflakeConfig.snowflakeId();
convert.setId(menuId);
save(convert);
this.save(convert);
//超管
if(CollectionUtil.isEmpty(menuDTO.getIdentifier())){
roleMenuService.save(RoleMenu.builder().id(snowflakeConfig.snowflakeId()).roleId(UserConstant.SUPER_ADMIN_ID).menuId(menuId).build());
}else{
if (CollectionUtil.isEmpty(menuDTO.getIdentifier())) {
this.roleMenuService.save(RoleMenu.builder().id(this.snowflakeConfig.snowflakeId()).roleId(UserConstant.SUPER_ADMIN_ID).menuId(menuId).build());
} else {
List<RoleMenu> list = new ArrayList<>();
menuDTO.getIdentifier().forEach(s->{
list.add(RoleMenu.builder().id(snowflakeConfig.snowflakeId()).roleId(UserConstant.SUPER_ADMIN_ID).menuId(menuId).identifier(s).build());
menuDTO.getIdentifier().forEach(s -> {
list.add(RoleMenu.builder().id(this.snowflakeConfig.snowflakeId()).roleId(UserConstant.SUPER_ADMIN_ID).menuId(menuId).identifier(s).build());
});
roleMenuService.saveBatch(list);
this.roleMenuService.saveBatch(list);
}
}
@Override
public void edit(MenuEditDTO menuEditDTO){
update(new UpdateWrapper<Menu>().lambda().eq(Menu::getId,menuEditDTO.getId()).set(Menu::getName,menuEditDTO.getName())
.set(Menu::getExtra,menuEditDTO.getExtra()));
public void edit(MenuEditDTO menuEditDTO) {
this.update(new UpdateWrapper<Menu>().lambda().eq(Menu::getId, menuEditDTO.getId()).set(Menu::getName, menuEditDTO.getName())
.set(Menu::getExtra, menuEditDTO.getExtra()));
}
@Override
public void delete(List<Long> ids){
public void delete(List<Long> ids) {
//删除菜单
removeBatchByIds(ids);
this.removeBatchByIds(ids);
//删除菜单与角色关联
roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().in(RoleMenu::getMenuId,ids));
this.roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().in(RoleMenu::getMenuId, ids));
}
@Override
public void editSort(List<MenuSortDTO> menuSortDTOList){
public void editSort(List<MenuSortDTO> menuSortDTOList) {
//更新菜单信息
if(CollectionUtil.isEmpty(menuSortDTOList)) return;
if (CollectionUtil.isEmpty(menuSortDTOList)) return;
Map<Long, MenuSortDTO> map = menuSortDTOList.stream().collect(Collectors.toMap(MenuSortDTO::getId, menuSortDTO -> menuSortDTO, (v1, v2) -> v2));
List<Long> list = menuSortDTOList.stream().map(MenuSortDTO::getId).toList();
List<Menu> menuList = list(new LambdaQueryWrapper<Menu>().in(Menu::getId, list));
if(!CollectionUtil.isEmpty(menuList)){
List<Menu> menuList = this.list(new LambdaQueryWrapper<Menu>().in(Menu::getId, list));
if (!CollectionUtil.isEmpty(menuList)) {
menuList.forEach(menu -> {
menu.setSort(map.get(menu.getId()).getSort());
if(map.get(menu.getId()).getParent() != null){
if (map.get(menu.getId()).getParent() != null) {
menu.setParent(map.get(menu.getId()).getParent());
}
});
}
updateBatchById(menuList);
this.updateBatchById(menuList);
//将移动后未勾选的父菜单也勾选
List<RoleMenu> res = new ArrayList<>();
Long menuId = null;
List<Long> ancestors = null;
for(MenuSortDTO menuSortDTO : menuSortDTOList){
if(!CollectionUtil.isEmpty(menuSortDTO.getAncestors())){
for (MenuSortDTO menuSortDTO : menuSortDTOList) {
if (!CollectionUtil.isEmpty(menuSortDTO.getAncestors())) {
menuId = menuSortDTO.getId();
ancestors = menuSortDTO.getAncestors();
}
}
if(menuId != null){
List<RoleMenu> roleMenuList = roleMenuService.list(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getMenuId, menuId));
if(!CollectionUtil.isEmpty(roleMenuList)){
if (menuId != null) {
List<RoleMenu> roleMenuList = this.roleMenuService.list(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getMenuId, menuId));
if (!CollectionUtil.isEmpty(roleMenuList)) {
List<Long> roleIds = roleMenuList.stream().map(RoleMenu::getRoleId).toList();
List<RoleMenu> roleMenus = roleMenuService.list(new LambdaQueryWrapper<RoleMenu>().in(RoleMenu::getRoleId, roleIds));
List<RoleMenu> roleMenus = this.roleMenuService.list(new LambdaQueryWrapper<RoleMenu>().in(RoleMenu::getRoleId, roleIds));
//带有拖动菜单对应的每个角色的所有菜单
Map<Long, List<Long>> collect = roleMenus.stream().collect(Collectors.groupingBy(RoleMenu::getRoleId, Collectors.mapping(RoleMenu::getMenuId, Collectors.toList())));
for(Map.Entry<Long, List<Long>> entry : collect.entrySet()){
for (Map.Entry<Long, List<Long>> entry : collect.entrySet()) {
Set<Long> set = new HashSet<>(entry.getValue());
for(Long ancestor : ancestors){
if(!set.contains(ancestor)){
res.add(RoleMenu.builder().id(snowflakeConfig.snowflakeId()).roleId(entry.getKey()).menuId(ancestor).build());
for (Long ancestor : ancestors) {
if (!set.contains(ancestor)) {
res.add(RoleMenu.builder().id(this.snowflakeConfig.snowflakeId()).roleId(entry.getKey()).menuId(ancestor).build());
}
}
}
roleMenuService.saveBatch(res);
this.roleMenuService.saveBatch(res);
}
}
}
public List<MenuTreeVO> getMenuTreeByRoleIds(List<Long> ids){
List<MenuVO> menuVOS = menuDao.selectRoleMenu(ids);
if(CollectionUtil.isEmpty(menuVOS)) return new ArrayList<>();
public List<MenuTreeVO> getMenuTreeByRoleIds(List<Long> ids) {
List<MenuVO> menuVOS = this.menuDao.selectRoleMenu(ids);
if (CollectionUtil.isEmpty(menuVOS)) return new ArrayList<>();
Map<Long, List<MenuVO>> map = menuVOS.stream().collect(Collectors.groupingBy(MenuVO::getId));
List<MenuTreeVO> collect = map.entrySet().stream().map(entry -> {
Long id = entry.getKey();
@ -156,16 +155,16 @@ public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuS
return new MenuTreeVO(id, objects.getFirst().getParent(), objects.getFirst().getName(), objects.getFirst().getCode(),
objects.getFirst().getIcon(), objects.getFirst().getSort(), objects.getFirst().getExtra(), identifier, null);
}).toList();
if(CollectionUtil.isEmpty(collect)) return new ArrayList<>();
return buildTree(collect,UserConstant.MENU_ROOT_ID);
if (CollectionUtil.isEmpty(collect)) return new ArrayList<>();
return this.buildTree(collect, UserConstant.MENU_ROOT_ID);
}
private List<MenuTreeVO> buildTree(List<MenuTreeVO> menuTreeVO,Long parentId){
private List<MenuTreeVO> buildTree(List<MenuTreeVO> menuTreeVO, Long parentId) {
return menuTreeVO.stream()
// 筛选父节点
.filter(t -> t.getParent().equals(parentId))
// 递归设置子节点
.peek(item -> item.setChildren(buildTree(menuTreeVO,item.getId())))
.peek(item -> item.setChildren(this.buildTree(menuTreeVO, item.getId())))
.sorted(Comparator.comparing(MenuTreeVO::getSort))
.collect(Collectors.toList());
}

View File

@ -18,7 +18,6 @@ import com.isu.gaswellwatch.service.RoleMenuService;
import com.isu.gaswellwatch.service.RoleService;
import com.isu.gaswellwatch.service.UserRoleService;
import com.isu.gaswellwatch.utils.ConverterUtil;
import com.isu.gaswellwatch.vo.RoleVO;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -42,65 +41,65 @@ public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleS
private UserRoleService userRoleService;
@Override
public Page<Role> page(Integer currentPage, Integer pageSize, String name){
return page(new Page<>(currentPage, pageSize), new LambdaQueryWrapper<Role>().like(StringUtils.isNotBlank(name), Role::getName, name).orderByDesc(Role::getCreateTime));
public Page<Role> page(Integer currentPage, Integer pageSize, String name) {
return this.page(new Page<>(currentPage, pageSize), new LambdaQueryWrapper<Role>().like(StringUtils.isNotBlank(name), Role::getName, name).orderByDesc(Role::getCreateTime));
}
@Override
public void add(RoleDTO roleDTO){
public void add(RoleDTO roleDTO) {
//查重
List<Role> list = list(new LambdaQueryWrapper<Role>().eq(Role::getName, roleDTO.getName()));
if(CollectionUtil.isNotEmpty(list)) {
List<Role> list = this.list(new LambdaQueryWrapper<Role>().eq(Role::getName, roleDTO.getName()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有角色,请重新输入");
}
Long roleId = snowflakeConfig.snowflakeId();
save(Role.builder().id(roleId).name(roleDTO.getName()).description(roleDTO.getDescription()).build());
Long roleId = this.snowflakeConfig.snowflakeId();
this.save(Role.builder().id(roleId).name(roleDTO.getName()).description(roleDTO.getDescription()).build());
//关联
addRelation(roleDTO.getRoleMenuDTOList(), roleId);
this.addRelation(roleDTO.getRoleMenuDTOList(), roleId);
}
@Override
public void edit(RoleEditDTO roleEditDTO){
List<Role> list = list(new LambdaQueryWrapper<Role>().eq(Role::getName, roleEditDTO.getName()).ne(Role::getId, roleEditDTO.getId()));
if(CollectionUtil.isNotEmpty(list)) {
public void edit(RoleEditDTO roleEditDTO) {
List<Role> list = this.list(new LambdaQueryWrapper<Role>().eq(Role::getName, roleEditDTO.getName()).ne(Role::getId, roleEditDTO.getId()));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("角色名称已存在,请重新输入");
}
updateById(ConverterUtil.convert(roleEditDTO, Role.class));
this.updateById(ConverterUtil.convert(roleEditDTO, Role.class));
//关联
roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId,roleEditDTO.getId()));
addRelation(roleEditDTO.getRoleMenuDTOList(), roleEditDTO.getId());
this.roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId, roleEditDTO.getId()));
this.addRelation(roleEditDTO.getRoleMenuDTOList(), roleEditDTO.getId());
}
@Override
public void delete(Long id){
public void delete(Long id) {
//如果角色绑定了用户 不能删除
List<UserRole> list = userRoleService.list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, id));
if(CollectionUtil.isNotEmpty(list)) {
List<UserRole> list = this.userRoleService.list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, id));
if (CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("该角色已和用户绑定,不能删除");
}
//如果是超管角色 不能删除
if(Objects.equals(id, UserConstant.SUPER_ADMIN_ID)) {
if (Objects.equals(id, UserConstant.SUPER_ADMIN_ID)) {
throw new BusinessException("该角色为超管角色,不能删除");
}
//删除
removeById(id);
roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId,id));
this.removeById(id);
this.roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId, id));
}
private void addRelation(List<RoleMenuDTO> roleMenuDTOList, Long roleId) {
if(!CollectionUtil.isEmpty(roleMenuDTOList)){
if (!CollectionUtil.isEmpty(roleMenuDTOList)) {
List<RoleMenu> roleMenus = new ArrayList<>();
roleMenuDTOList.forEach(roleMenuDTO -> {
if(CollectionUtil.isEmpty(roleMenuDTO.getIdentifier())){
roleMenus.add(RoleMenu.builder().id(snowflakeConfig.snowflakeId()).roleId(roleId).menuId(roleMenuDTO.getMenuId()).build());
}else {
if (CollectionUtil.isEmpty(roleMenuDTO.getIdentifier())) {
roleMenus.add(RoleMenu.builder().id(this.snowflakeConfig.snowflakeId()).roleId(roleId).menuId(roleMenuDTO.getMenuId()).build());
} else {
roleMenuDTO.getIdentifier().forEach(identifier -> {
roleMenus.add(RoleMenu.builder().id(snowflakeConfig.snowflakeId()).roleId(roleId).menuId(roleMenuDTO.getMenuId()).identifier(identifier).build());
roleMenus.add(RoleMenu.builder().id(this.snowflakeConfig.snowflakeId()).roleId(roleId).menuId(roleMenuDTO.getMenuId()).identifier(identifier).build());
});
}
});
roleMenuService.saveBatch(roleMenus);
this.roleMenuService.saveBatch(roleMenus);
}
}
}

View File

@ -27,7 +27,8 @@ public class HexUtil {
}
public static void main(String[] args) {
System.out.println(hexStringToBytes("0D"));
System.out.println(new byte[]{(byte) Integer.parseInt("0D", 16)});
// System.out.println(hexStringToBytes("0D"));
// System.out.println(new byte[]{(byte) Integer.parseInt("0D", 16)});
System.out.println(new String(HexUtil.hexStringToBytes("4B454E454E4731343030303030303130")));
}
}

View File

@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.LocalDate;
@ -23,7 +22,7 @@ public class StringToLocalDateTimeConverter extends JsonDeserializer<LocalDateTi
@Override
public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
return convert(jsonParser.getText());
return this.convert(jsonParser.getText());
}
@Override

View File

@ -1,10 +1,8 @@
package com.isu.gaswellwatch.vo;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import java.io.Serial;
@ -24,7 +22,9 @@ public class BlockPageQuery extends PageQuery {
@Serial
private static final long serialVersionUID = 1L;
/** 名称 */
/**
* 名称
*/
private String name;
}

View File

@ -1,10 +1,6 @@
package com.isu.gaswellwatch.vo;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.io.Serial;
@ -27,21 +23,33 @@ public class BlockVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
private Long id;
/** 名称 */
/**
* 名称
*/
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 创建时间 */
/**
* 创建时间
*/
private String createTime;
/** 更新时间 */
/**
* 更新时间
*/
private String updateTime;
/** 关联部门 */
/**
* 关联部门
*/
private DepartmentVO department;
}

View File

@ -1,10 +1,8 @@
package com.isu.gaswellwatch.vo;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import java.io.Serial;
@ -24,10 +22,14 @@ public class GasWellPageQuery extends PageQuery {
@Serial
private static final long serialVersionUID = 1L;
/** 关联公司 */
/**
* 关联公司
*/
private Long companyId;
/** 气井名称 */
/**
* 气井名称
*/
private String name;
}

View File

@ -1,15 +1,10 @@
package com.isu.gaswellwatch.vo;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 气井页面返回对象 gas_wells
@ -28,25 +23,39 @@ public class GasWellVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 主键 */
/**
* 主键
*/
private Long id;
/** 气井名称 */
/**
* 气井名称
*/
private String name;
/** 描述 */
/**
* 描述
*/
private String details;
/** 创建时间 */
/**
* 创建时间
*/
private String createTime;
/** 更新时间 */
/**
* 更新时间
*/
private String updateTime;
/** 设备id */
/**
* 设备id
*/
private Long deviceId;
/** 区块id */
/**
* 区块id
*/
private Long blockId;
}

View File

@ -7,7 +7,7 @@ CREATE TABLE `$TableName$`
`receive_time` datetime NOT NULL COMMENT '接收到数据时间',
`device_time` datetime NULL DEFAULT NULL COMMENT '设备时间。\r\n寄存器地址3:00003:00013:00023:00033:00043:0005\r\n',
`run_mode` smallint NULL DEFAULT NULL COMMENT '运行模式:\r\n0手动模式 \r\n1定时器模式 \r\n2计时器模式 \r\n3压力模式\r\n4柱塞模式\r\n5时压模式',
`gas_status` smallint NULL DEFAULT NULL COMMENT '气井状态:\r\n0关闭 \r\n1打开',
`well_status` smallint NULL DEFAULT NULL COMMENT '气井状态:\r\n0关闭 \r\n1打开',
`plug_status` smallint NULL DEFAULT NULL COMMENT '柱塞状态:\r\n0离开\r\n1上升中\r\n2到达',
`status_start_time` varchar(10) NULL DEFAULT NULL COMMENT '当前状态开始时间',
`status_end_time` varchar(10) NULL DEFAULT NULL COMMENT '当前状态结束时间',

View File

@ -1,5 +1,5 @@
INSERT INTO `$TableName$` (`id`, `device_id`, `created_time`, `collection_time`, `receive_time`,
`device_time`, `run_mode`, `gas_status`, `plug_status`, `status_start_time`,
`device_time`, `run_mode`, `well_status`, `plug_status`, `status_start_time`,
`status_end_time`, `oil_pressure`, `cas_pressure`, `pre_pressure`, `pipe_pressure`,
`liquid_level`, `temperature`, `humidity`, `op_mode`, `timer_able1`,
`timer_able2`, `timer_open1`, `timer_close1`, `timer_open2`, `timer_close2`,
@ -15,7 +15,7 @@ VALUES (?, ?, NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
ON DUPLICATE KEY UPDATE receive_time=VALUES(receive_time),
device_time=VALUES(device_time),
run_mode=VALUES(run_mode),
gas_status=VALUES(gas_status),
well_status=VALUES(well_status),
plug_status=VALUES(plug_status),
status_start_time=VALUES(status_start_time),
status_end_time=VALUES(status_end_time),