添加 煤参数定义

This commit is contained in:
2023-07-31 14:36:54 +08:00
parent a95152c8c4
commit 73b3f067fb
15 changed files with 311 additions and 19 deletions

View File

@@ -2,12 +2,9 @@ package cn.lihongjie.coal.controller;
import cn.lihongjie.coal.dto.CoalBlendRequest;
import cn.lihongjie.coal.dto.CoalBlendResult;
import cn.lihongjie.coal.dto.CoalParameterDef;
import cn.lihongjie.coal.dto.R;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.dto.base.CoalParameterDef;
import cn.lihongjie.coal.service.CoalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

View File

@@ -0,0 +1,56 @@
package cn.lihongjie.coal.controller;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.dto.CommonQuery;
import cn.lihongjie.coal.dto.IdRequest;
import cn.lihongjie.coal.dto.CreateCoalParameterDefDto;
import cn.lihongjie.coal.dto.UpdateCoalParameterDefDto;
import cn.lihongjie.coal.dto.CoalParameterDefDto;
import cn.lihongjie.coal.service.CoalParameterDefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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;
@RequestMapping("/coalParameterDef")
@RestController
@SysLog(module = "煤参数配置")
public class CoalParameterDefController {
@Autowired
CoalParameterDefService service;
@PostMapping("/create")
@SysLog(msg = "新增")
public CoalParameterDefDto create(@RequestBody CreateCoalParameterDefDto dto) {
return this.service.create(dto);
}
@PostMapping("/update")
@SysLog(msg = "编辑")
public CoalParameterDefDto update(@RequestBody UpdateCoalParameterDefDto dto) {
return this.service.update(dto);
}
@PostMapping("/delete")
@SysLog(msg = "删除")
public Object delete(@RequestBody IdRequest dto) {
this.service.delete(dto);
return null;
}
@PostMapping("/list")
public Page<CoalParameterDefDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto);
}
@PostMapping("/getById")
public CoalParameterDefDto getById(@RequestBody IdRequest dto) {
return this.service.getById(dto.getId());
}
}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.dao;
import cn.lihongjie.coal.entity.CoalParameterDefEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface CoalParameterDefRepository extends BaseRepository<CoalParameterDefEntity> {
}

View File

@@ -0,0 +1,13 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CoalParameterDefDto extends CommonDto {
}

View File

@@ -0,0 +1,11 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateCoalParameterDefDto extends CommonDto {
}

View File

@@ -0,0 +1,13 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateCoalParameterDefDto extends CommonDto {
}

View File

@@ -1,4 +1,4 @@
package cn.lihongjie.coal.dto;
package cn.lihongjie.coal.dto.base;
import lombok.Data;

View File

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

View File

@@ -0,0 +1,24 @@
package cn.lihongjie.coal.mapper;
import cn.lihongjie.coal.dto.CreateCoalParameterDefDto;
import cn.lihongjie.coal.dto.UpdateCoalParameterDefDto;
import cn.lihongjie.coal.dto.CoalParameterDefDto;
import cn.lihongjie.coal.entity.CoalParameterDefEntity;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;
@Mapper(
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class}
)
public interface CoalParameterDefMapper {
CoalParameterDefDto toDto(CoalParameterDefEntity user);
CoalParameterDefEntity toEntity(CreateCoalParameterDefDto request);
void updateEntity(@MappingTarget CoalParameterDefEntity entity, UpdateCoalParameterDefDto dto);
}

View File

@@ -2,11 +2,15 @@ package cn.lihongjie.coal.runner;
import cn.lihongjie.coal.entity.OrganizationEntity;
import cn.lihongjie.coal.entity.UserEntity;
import cn.lihongjie.coal.service.CoalParameterDefService;
import cn.lihongjie.coal.service.OrganizationService;
import cn.lihongjie.coal.service.SessionService;
import cn.lihongjie.coal.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
@Component
@@ -20,6 +24,8 @@ public class InitDataRunner implements CommandLineRunner {
@Autowired
UserService userService;
@Autowired
CoalParameterDefService coalParameterDefService;
@Override
@@ -31,7 +37,21 @@ public class InitDataRunner implements CommandLineRunner {
UserEntity u = userService.initOrGetAdminUser(e);
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(new SessionService.MyAuthentication(null, u, ""));
SecurityContextHolder.setContext(context);
try {
coalParameterDefService.initDefault();
} finally {
SecurityContextHolder.clearContext();
}
}
}

View File

@@ -36,13 +36,24 @@ public abstract class BaseService<Entity extends BaseEntity, Repository extends
}
public Page<Entity> search(Specification<Entity> spec, Pageable page){
public Page<Entity> findAll(Specification<Entity> spec, Pageable page){
return dao.findAll(spec, page);
}
public List<Entity> search(Specification<Entity> spec){
public List<Entity> findAll(Specification<Entity> spec){
return dao.findAll(spec);
}
public List<Entity> findAll(){
return dao.findAll();
}
public Long count(Specification<Entity> spec){
return dao.count(spec);
}
public Long count(){
return dao.count();
}
}

View File

@@ -0,0 +1,114 @@
package cn.lihongjie.coal.service;
import cn.lihongjie.coal.dao.CoalParameterDefRepository;
import cn.lihongjie.coal.dto.*;
import cn.lihongjie.coal.entity.CoalParameterDefEntity;
import cn.lihongjie.coal.mapper.CoalParameterDefMapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.PostConstruct;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.List;
@Service
@Slf4j
public class CoalParameterDefService extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> {
@Autowired
CoalParameterDefRepository repository;
@Autowired
CoalParameterDefMapper mapper;
@PostConstruct
public void init() {
}
public CoalParameterDefDto create(CreateCoalParameterDefDto request) {
CoalParameterDefEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public CoalParameterDefDto update(UpdateCoalParameterDefDto request) {
CoalParameterDefEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
}
public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds());
}
public CoalParameterDefDto getById(String id) {
CoalParameterDefEntity entity = repository.get(id);
return mapper.toDto(entity);
}
@Autowired
ConversionService conversionService;
public Page<CoalParameterDefDto> list(CommonQuery query) {
Page<CoalParameterDefEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
@SneakyThrows
public void initDefault() {
if (this.count() == 0) {
ClassPathResource classPathResource = new ClassPathResource("/config/CoalParameterDef.json");
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
List<CoalParameterDefEntity> coalParameterDefs;
try (InputStream inputStream = classPathResource.getInputStream()) {
coalParameterDefs = mapper.readValue(inputStream, new TypeReference<List<CoalParameterDefEntity>>() {
});
this.repository.saveAll(coalParameterDefs);
}
}
}
}

View File

@@ -1,6 +1,7 @@
package cn.lihongjie.coal.service;
import cn.lihongjie.coal.dto.*;
import cn.lihongjie.coal.dto.base.CoalParameterDef;
import cn.lihongjie.coal.exception.BizException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -11,7 +12,6 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

View File

@@ -124,7 +124,7 @@ public class UserService extends BaseService<UserEntity, UserRepository>{
public Optional<UserEntity> findByUsername(String username) {
return this.search(new Specification<UserEntity>() {
return this.findAll(new Specification<UserEntity>() {
@Override
public Predicate toPredicate(Root<UserEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.equal(root.get("username"), username);

View File

@@ -2,71 +2,81 @@
{
"code": "param1",
"name": "发热量(Q)",
"desc": "单位质量的煤完全的燃烧时所产生的热量",
"remarks": "单位质量的煤完全的燃烧时所产生的热量",
"order": "6",
"sortKey": "6",
"status": "1"
},
{
"code": "param2",
"name": "硫份(St)",
"desc": "煤中的有害元素,包括有机硫,无机硫",
"remarks": "煤中的有害元素,包括有机硫,无机硫",
"order": "1",
"sortKey": "1",
"status": "1"
},
{
"code": "param3",
"name": "灰分(A)",
"desc": "煤炭在彻底燃烧后所剩下的残渣称为灰分",
"remarks": "煤炭在彻底燃烧后所剩下的残渣称为灰分",
"order": "2",
"sortKey": "2",
"status": "1"
},
{
"code": "param4",
"name": "挥发分(V)",
"desc": "煤炭在高温和隔绝空气的条件下加热时,所排出的气体和液体状态的产物称为挥发分",
"remarks": "煤炭在高温和隔绝空气的条件下加热时,所排出的气体和液体状态的产物称为挥发分",
"order": "7",
"sortKey": "7",
"status": "1"
},
{
"code": "param5",
"name": "固定碳(FC)",
"desc": "固定碳含量是指除去水分、灰分和挥发分的残留物",
"remarks": "固定碳含量是指除去水分、灰分和挥发分的残留物",
"order": "8",
"sortKey": "8",
"status": "1"
},
{
"code": "param6",
"name": "胶质层最大厚度(Y值)",
"desc": "烟煤在加热到一定温度后所形成的胶质层最大厚度是烟煤胶质层指数测定中利用探针测出的胶质体上、F层面差的最大值。",
"remarks": "烟煤在加热到一定温度后所形成的胶质层最大厚度是烟煤胶质层指数测定中利用探针测出的胶质体上、F层面差的最大值。",
"order": "3",
"sortKey": "3",
"status": "1"
},
{
"code": "param7",
"name": "粘结指数(G值)",
"desc": "在规定条件下以烟煤在加热后粘结专用无烟煤的能力",
"remarks": "在规定条件下以烟煤在加热后粘结专用无烟煤的能力",
"order": "4",
"sortKey": "4",
"status": "1"
},
{
"code": "param8",
"name": "内水(Minh)",
"desc": "是由植物变成煤时所含的水分",
"remarks": "是由植物变成煤时所含的水分",
"order": "9",
"sortKey": "9",
"status": "1"
},
{
"code": "param9",
"name": "外水(Mf)",
"desc": "是在开采、运输等过程中附在煤表面和裂隙中的水分",
"remarks": "是在开采、运输等过程中附在煤表面和裂隙中的水分",
"order": "10",
"sortKey": "10",
"status": "1"
},
{
"code": "param10",
"name": "全水(M)",
"desc": "煤的外在水分和内在水分总和",
"remarks": "煤的外在水分和内在水分总和",
"order": "5",
"sortKey": "5",
"status": "1"
}
]