完善煤参数配置

This commit is contained in:
2023-09-10 23:06:39 +08:00
parent db9ac6b714
commit 81d33b2ef4
7 changed files with 24 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package cn.lihongjie.coal.coalParameterDef.controller;
import cn.lihongjie.coal.annotation.Anonymous;
import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.controller.BaseController;
import cn.lihongjie.coal.base.dto.CommonQuery;
@@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@SysLog(module = "煤参数配置")
@Anonymous
@OrgScope
public class CoalParameterDefController extends BaseController {
@Autowired

View File

@@ -1,10 +1,10 @@
package cn.lihongjie.coal.coalParameterDef.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
@Data
public class CoalParameterDefDto extends CommonDto {
public class CoalParameterDefDto extends OrgCommonDto {

View File

@@ -1,10 +1,10 @@
package cn.lihongjie.coal.coalParameterDef.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
@Data
public class CreateCoalParameterDefDto extends CommonDto {
public class CreateCoalParameterDefDto extends OrgCommonDto {
}

View File

@@ -1,10 +1,10 @@
package cn.lihongjie.coal.coalParameterDef.dto;
import cn.lihongjie.coal.base.dto.CommonDto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
@Data
public class UpdateCoalParameterDefDto extends CommonDto {
public class UpdateCoalParameterDefDto extends OrgCommonDto {

View File

@@ -1,12 +1,12 @@
package cn.lihongjie.coal.coalParameterDef.entity;
import cn.lihongjie.coal.base.entity.CommonEntity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import lombok.Data;
@Entity
@Data
public class CoalParameterDefEntity extends CommonEntity {
public class CoalParameterDefEntity extends OrgCommonEntity {

View File

@@ -6,4 +6,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface CoalParameterDefRepository extends BaseRepository<CoalParameterDefEntity> {
long countByOrganizationId(String organizationId);
}

View File

@@ -9,6 +9,7 @@ import cn.lihongjie.coal.coalParameterDef.dto.UpdateCoalParameterDefDto;
import cn.lihongjie.coal.coalParameterDef.entity.CoalParameterDefEntity;
import cn.lihongjie.coal.coalParameterDef.mapper.CoalParameterDefMapper;
import cn.lihongjie.coal.coalParameterDef.repository.CoalParameterDefRepository;
import cn.lihongjie.coal.organization.service.OrganizationService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -94,10 +95,19 @@ public class CoalParameterDefService extends BaseService<CoalParameterDefEntity,
}
@SneakyThrows
@Autowired
OrganizationService organizationService;
public void initDefault() {
if (this.count() == 0) {
organizationService.findAll().forEach(organizationEntity -> initDefault(organizationEntity.getId()));
}
@SneakyThrows
public void initDefault(String orgId) {
if (repository.countByOrganizationId(orgId) == 0) {
ClassPathResource classPathResource = new ClassPathResource("/config/CoalParameterDef.json");
@@ -109,6 +119,7 @@ public class CoalParameterDefService extends BaseService<CoalParameterDefEntity,
coalParameterDefs = mapper.readValue(inputStream, new TypeReference<List<CoalParameterDefEntity>>() {
});
coalParameterDefs.forEach(x -> x.setOrganizationId(orgId));
this.repository.saveAll(coalParameterDefs);
}