diff --git a/src/main/java/cn/lihongjie/coal/controller/CoalController.java b/src/main/java/cn/lihongjie/coal/controller/CoalController.java index 075229d0..4a5cdccd 100644 --- a/src/main/java/cn/lihongjie/coal/controller/CoalController.java +++ b/src/main/java/cn/lihongjie/coal/controller/CoalController.java @@ -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; diff --git a/src/main/java/cn/lihongjie/coal/controller/CoalParameterDefController.java b/src/main/java/cn/lihongjie/coal/controller/CoalParameterDefController.java new file mode 100644 index 00000000..876256af --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/controller/CoalParameterDefController.java @@ -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 list(@RequestBody CommonQuery dto) { + return this.service.list(dto); + } + + + @PostMapping("/getById") + public CoalParameterDefDto getById(@RequestBody IdRequest dto) { + return this.service.getById(dto.getId()); + } +} diff --git a/src/main/java/cn/lihongjie/coal/dao/CoalParameterDefRepository.java b/src/main/java/cn/lihongjie/coal/dao/CoalParameterDefRepository.java new file mode 100644 index 00000000..46a8262c --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dao/CoalParameterDefRepository.java @@ -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 { +} \ No newline at end of file diff --git a/src/main/java/cn/lihongjie/coal/dto/CoalParameterDefDto.java b/src/main/java/cn/lihongjie/coal/dto/CoalParameterDefDto.java new file mode 100644 index 00000000..f2c8afce --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/CoalParameterDefDto.java @@ -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 { + + + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/CreateCoalParameterDefDto.java b/src/main/java/cn/lihongjie/coal/dto/CreateCoalParameterDefDto.java new file mode 100644 index 00000000..8d834004 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/CreateCoalParameterDefDto.java @@ -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 { + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/UpdateCoalParameterDefDto.java b/src/main/java/cn/lihongjie/coal/dto/UpdateCoalParameterDefDto.java new file mode 100644 index 00000000..ecc982c8 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/UpdateCoalParameterDefDto.java @@ -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 { + + + + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/CoalParameterDef.java b/src/main/java/cn/lihongjie/coal/dto/base/CoalParameterDef.java similarity index 84% rename from src/main/java/cn/lihongjie/coal/dto/CoalParameterDef.java rename to src/main/java/cn/lihongjie/coal/dto/base/CoalParameterDef.java index e296dc7b..ee4d600f 100644 --- a/src/main/java/cn/lihongjie/coal/dto/CoalParameterDef.java +++ b/src/main/java/cn/lihongjie/coal/dto/base/CoalParameterDef.java @@ -1,4 +1,4 @@ -package cn.lihongjie.coal.dto; +package cn.lihongjie.coal.dto.base; import lombok.Data; diff --git a/src/main/java/cn/lihongjie/coal/entity/CoalParameterDefEntity.java b/src/main/java/cn/lihongjie/coal/entity/CoalParameterDefEntity.java new file mode 100644 index 00000000..ce787e9d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/entity/CoalParameterDefEntity.java @@ -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 { + + + + + +} diff --git a/src/main/java/cn/lihongjie/coal/mapper/CoalParameterDefMapper.java b/src/main/java/cn/lihongjie/coal/mapper/CoalParameterDefMapper.java new file mode 100644 index 00000000..28cca44d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/mapper/CoalParameterDefMapper.java @@ -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); +} diff --git a/src/main/java/cn/lihongjie/coal/runner/InitDataRunner.java b/src/main/java/cn/lihongjie/coal/runner/InitDataRunner.java index 40772656..308e47fc 100644 --- a/src/main/java/cn/lihongjie/coal/runner/InitDataRunner.java +++ b/src/main/java/cn/lihongjie/coal/runner/InitDataRunner.java @@ -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(); + + } + } } diff --git a/src/main/java/cn/lihongjie/coal/service/BaseService.java b/src/main/java/cn/lihongjie/coal/service/BaseService.java index caa35323..765668d5 100644 --- a/src/main/java/cn/lihongjie/coal/service/BaseService.java +++ b/src/main/java/cn/lihongjie/coal/service/BaseService.java @@ -36,13 +36,24 @@ public abstract class BaseService search(Specification spec, Pageable page){ + public Page findAll(Specification spec, Pageable page){ return dao.findAll(spec, page); } - public List search(Specification spec){ + public List findAll(Specification spec){ return dao.findAll(spec); } + public List findAll(){ + return dao.findAll(); + } + + public Long count(Specification spec){ + return dao.count(spec); + } + + public Long count(){ + return dao.count(); + } } diff --git a/src/main/java/cn/lihongjie/coal/service/CoalParameterDefService.java b/src/main/java/cn/lihongjie/coal/service/CoalParameterDefService.java new file mode 100644 index 00000000..76ee85b2 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/service/CoalParameterDefService.java @@ -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 { + + @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 list(CommonQuery query) { + + Page 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 coalParameterDefs; + try (InputStream inputStream = classPathResource.getInputStream()) { + coalParameterDefs = mapper.readValue(inputStream, new TypeReference>() { + }); + + + this.repository.saveAll(coalParameterDefs); + } + + + + } + + } +} diff --git a/src/main/java/cn/lihongjie/coal/service/CoalService.java b/src/main/java/cn/lihongjie/coal/service/CoalService.java index e18fddc9..ab622083 100644 --- a/src/main/java/cn/lihongjie/coal/service/CoalService.java +++ b/src/main/java/cn/lihongjie/coal/service/CoalService.java @@ -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; diff --git a/src/main/java/cn/lihongjie/coal/service/UserService.java b/src/main/java/cn/lihongjie/coal/service/UserService.java index d4ef888c..915ef64f 100644 --- a/src/main/java/cn/lihongjie/coal/service/UserService.java +++ b/src/main/java/cn/lihongjie/coal/service/UserService.java @@ -124,7 +124,7 @@ public class UserService extends BaseService{ public Optional findByUsername(String username) { - return this.search(new Specification() { + return this.findAll(new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { return criteriaBuilder.equal(root.get("username"), username); diff --git a/src/main/resources/config/CoalParameterDef.json b/src/main/resources/config/CoalParameterDef.json index dd6f985a..c14c7511 100644 --- a/src/main/resources/config/CoalParameterDef.json +++ b/src/main/resources/config/CoalParameterDef.json @@ -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" } ] \ No newline at end of file