mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善
This commit is contained in:
@@ -65,7 +65,7 @@ public class AcDeviceService extends BaseService<AcDeviceEntity, AcDeviceReposit
|
||||
}
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class AcDeviceSupplierService
|
||||
}
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -68,7 +68,7 @@ class CoalInfoService extends BaseService<CoalInfoEntity, CoalInfoRepository> {
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -137,7 +137,7 @@ public class DataCollectorService
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -71,7 +71,7 @@ class DepartmentService extends BaseService<DepartmentEntity, DepartmentReposito
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())){
|
||||
throw new BizException("部分数据已关联,无法删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DeviceService extends BaseService<DeviceEntity, DeviceRepository> {
|
||||
}
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DeviceCategoryService
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DeviceSupplierService
|
||||
}
|
||||
|
||||
if (this.repository.isLinked(request.getIds())){
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -3,7 +3,15 @@ package cn.lihongjie.coal.employee.repository;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository extends BaseRepository<EmployeeEntity> {}
|
||||
public interface EmployeeRepository extends BaseRepository<EmployeeEntity> {
|
||||
|
||||
@Query("select exists(select 1 from EmployeeRecordEntity e where e.employee.id in :ids)")
|
||||
boolean isLinked(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import cn.lihongjie.coal.employee.dto.UpdateEmployeeDto;
|
||||
import cn.lihongjie.coal.employee.entity.EmployeeEntity;
|
||||
import cn.lihongjie.coal.employee.mapper.EmployeeMapper;
|
||||
import cn.lihongjie.coal.employee.repository.EmployeeRepository;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.file.service.FileService;
|
||||
import cn.lihongjie.coal.jobPost.dto.CreateJobPostDto;
|
||||
import cn.lihongjie.coal.jobPost.entity.JobPostEntity;
|
||||
@@ -75,6 +76,10 @@ public class EmployeeService extends BaseService<EmployeeEntity, EmployeeReposit
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class JobPostService extends BaseService<JobPostEntity, JobPostRepository
|
||||
|
||||
|
||||
if (this.repository.isLinked(request.getIds())){
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -51,7 +51,7 @@ class MeterService extends BaseService<MeterEntity, MeterRepository> {
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.organization.dto.CreateOrganizationDto;
|
||||
import cn.lihongjie.coal.organization.dto.OrganizationDto;
|
||||
import cn.lihongjie.coal.organization.dto.ResetAdminPasswordRequest;
|
||||
import cn.lihongjie.coal.organization.dto.UpdateOrganizationDto;
|
||||
import cn.lihongjie.coal.organization.service.OrganizationService;
|
||||
|
||||
@@ -47,6 +48,14 @@ public class OrganizationController extends BaseController {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/resetOrgAdminPassword")
|
||||
public Boolean resetOrgAdminPassword(@RequestBody ResetAdminPasswordRequest dto) {
|
||||
this.service.resetOrgAdminPassword(dto);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public OrganizationDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.lihongjie.coal.organization.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ResetAdminPasswordRequest{
|
||||
|
||||
String id;
|
||||
String password;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.coalParameterDef.service.CoalParameterDefService;
|
||||
import cn.lihongjie.coal.organization.dto.CreateOrganizationDto;
|
||||
import cn.lihongjie.coal.organization.dto.OrganizationDto;
|
||||
import cn.lihongjie.coal.organization.dto.ResetAdminPasswordRequest;
|
||||
import cn.lihongjie.coal.organization.dto.UpdateOrganizationDto;
|
||||
import cn.lihongjie.coal.organization.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.organization.mapper.OrganizationMapper;
|
||||
@@ -39,8 +40,7 @@ import java.util.Set;
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public
|
||||
class OrganizationService extends BaseService<OrganizationEntity, OrganizationRepository> {
|
||||
public class OrganizationService extends BaseService<OrganizationEntity, OrganizationRepository> {
|
||||
|
||||
@Autowired OrganizationRepository repository;
|
||||
|
||||
@@ -69,7 +69,8 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
dto.setUsername(request.getOrgAdminUserName());
|
||||
dto.setPassword(request.getOrgAdminPassword());
|
||||
userService.createOrgAdmin(dto);
|
||||
rabbitMQService.sendToSysExchange("organization.create", entity.getId(), new HashMap<String, String>());
|
||||
rabbitMQService.sendToSysExchange(
|
||||
"organization.create", entity.getId(), new HashMap<String, String>());
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@@ -78,10 +79,16 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
rabbitMQService.sendToSysExchange("organization.update", entity.getId(), new HashMap<String, String>());
|
||||
rabbitMQService.sendToSysExchange(
|
||||
"organization.update", entity.getId(), new HashMap<String, String>());
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void resetOrgAdminPassword(ResetAdminPasswordRequest resetAdminPasswordRequest) {
|
||||
userService.resetOrgAdminPassword(
|
||||
resetAdminPasswordRequest.getId(), resetAdminPasswordRequest.getPassword());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
@@ -132,11 +139,14 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
|
||||
List<String> names = this.repository.findNamesByIds(strings);
|
||||
|
||||
Map<String, String> javaMap = Stream.ofAll(names).filter(StringUtils::isNotBlank).toMap(x -> x.split(",")[0], x -> x.split(",")[1]).toJavaMap();
|
||||
Map<String, String> javaMap =
|
||||
Stream.ofAll(names)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.toMap(x -> x.split(",")[0], x -> x.split(",")[1])
|
||||
.toJavaMap();
|
||||
|
||||
strings.forEach(x -> javaMap.putIfAbsent(x, null));
|
||||
|
||||
return javaMap;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,70 @@ package cn.lihongjie.coal.pdcDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class CreatePdcDeviceDataDto extends OrgCommonDto {}
|
||||
public class CreatePdcDeviceDataDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private String device;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("modbus地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("总累计量")
|
||||
private Double totalData;
|
||||
|
||||
@Comment("月累计量")
|
||||
private Double monthData;
|
||||
|
||||
@Comment("日累计量")
|
||||
private Double dayData;
|
||||
|
||||
@Comment("班累计量")
|
||||
private Double classData;
|
||||
|
||||
@Comment(" 批累计量")
|
||||
private Double batchData;
|
||||
|
||||
@Comment("定值累计量")
|
||||
private Double fixedData;
|
||||
|
||||
@Comment("瞬时流量")
|
||||
private Double flowData;
|
||||
|
||||
@Comment("瞬时速度")
|
||||
private Double speedData;
|
||||
|
||||
@Comment("当前负荷")
|
||||
private Double loadData;
|
||||
|
||||
@Comment("控制输出")
|
||||
private Double outputData;
|
||||
|
||||
@Comment("故障状态")
|
||||
private Double faultData;
|
||||
|
||||
@Comment("故障信息")
|
||||
private String faultInfo;
|
||||
|
||||
@Comment("净重")
|
||||
private Double netData;
|
||||
|
||||
@Comment("过程数据1")
|
||||
private Double process1Data;
|
||||
|
||||
@Comment("过程数据2")
|
||||
private Double process2Data;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,70 @@ package cn.lihongjie.coal.pdcDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class UpdatePdcDeviceDataDto extends OrgCommonDto {}
|
||||
public class UpdatePdcDeviceDataDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private String device;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("modbus地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("总累计量")
|
||||
private Double totalData;
|
||||
|
||||
@Comment("月累计量")
|
||||
private Double monthData;
|
||||
|
||||
@Comment("日累计量")
|
||||
private Double dayData;
|
||||
|
||||
@Comment("班累计量")
|
||||
private Double classData;
|
||||
|
||||
@Comment(" 批累计量")
|
||||
private Double batchData;
|
||||
|
||||
@Comment("定值累计量")
|
||||
private Double fixedData;
|
||||
|
||||
@Comment("瞬时流量")
|
||||
private Double flowData;
|
||||
|
||||
@Comment("瞬时速度")
|
||||
private Double speedData;
|
||||
|
||||
@Comment("当前负荷")
|
||||
private Double loadData;
|
||||
|
||||
@Comment("控制输出")
|
||||
private Double outputData;
|
||||
|
||||
@Comment("故障状态")
|
||||
private Double faultData;
|
||||
|
||||
@Comment("故障信息")
|
||||
private String faultInfo;
|
||||
|
||||
@Comment("净重")
|
||||
private Double netData;
|
||||
|
||||
@Comment("过程数据1")
|
||||
private Double process1Data;
|
||||
|
||||
@Comment("过程数据2")
|
||||
private Double process2Data;
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.common.JpaUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.pdcDevice.service.PdcDeviceService;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.CreatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.GetReportRequest;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.PdcDeviceDataDto;
|
||||
@@ -47,9 +48,13 @@ public class PdcDeviceDataService
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
@Autowired PdcDeviceService pdcDeviceService;
|
||||
|
||||
public PdcDeviceDataDto create(CreatePdcDeviceDataDto request) {
|
||||
PdcDeviceDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
entity.setModbusUId(pdcDeviceService.get(request.getDevice()).getModbusUId());
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
@@ -58,6 +63,8 @@ public class PdcDeviceDataService
|
||||
PdcDeviceDataEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
entity.setModbusUId(pdcDeviceService.get(request.getDevice()).getModbusUId());
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PermissionService extends BaseService<PermissionEntity, PermissionR
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -75,7 +75,7 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -62,7 +62,7 @@ class RoleService extends BaseService<RoleEntity, RoleRepository> {
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import com.nulabinc.zxcvbn.Zxcvbn;
|
||||
import io.vavr.collection.Stream;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
@@ -423,4 +425,20 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
return Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
public void resetOrgAdminPassword(String organizationId, String password) {
|
||||
|
||||
|
||||
|
||||
em.createQuery("from UserEntity where organizationId = :organizationId and orgAdmin = true", UserEntity.class)
|
||||
.setParameter("organizationId", organizationId)
|
||||
.getResultList()
|
||||
.forEach(x -> {
|
||||
x.setPassword(passwordEncoder.encode(password));
|
||||
repository.save(x);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class WeightDeviceService extends BaseService<WeightDeviceEntity, WeightD
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
@@ -53,7 +53,7 @@ public class WeightDeviceSupplierService
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
if (this.repository.isLinked(request.getIds())) {
|
||||
throw new BizException("部分数据已关联,无法编辑或删除");
|
||||
throw new BizException("部分数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
35
src/test/java/cn/lihongjie/coal/common/FormatUtilsTest.java
Normal file
35
src/test/java/cn/lihongjie/coal/common/FormatUtilsTest.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
import static cn.lihongjie.coal.common.FormatUtils.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class FormatUtilsTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testFormat() {
|
||||
|
||||
assertEquals("-1 B", humanReadableByteCountBin(-1));
|
||||
assertEquals("0 B", humanReadableByteCountBin(0));
|
||||
assertEquals("1.0 KiB", humanReadableByteCountBin(1024));
|
||||
assertEquals("1000 B", humanReadableByteCountBin(1000));
|
||||
assertEquals("1.1 KiB", humanReadableByteCountBin(1024 + 100));
|
||||
assertEquals("1.0 MiB", humanReadableByteCountBin(1024 * 1024));
|
||||
assertEquals("-1.0 MiB", humanReadableByteCountBin(-1024 * 1024));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user