This commit is contained in:
2023-08-30 22:44:31 +08:00
parent ab1461e0ea
commit 760b0f9e88
32 changed files with 393 additions and 32 deletions

View File

@@ -23,4 +23,6 @@ public class MyPostgreSQLDialect extends PostgreSQLDialect {
public String getAddForeignKeyConstraintString(String constraintName, String foreignKeyDefinition) {
return " DROP CONSTRAINT IF EXISTS notexist ";
}
}

View File

@@ -50,5 +50,8 @@ public class DictionaryController extends BaseController{
public DictionaryDto getById(@RequestBody IdRequest dto) {
return this.service.getById(dto.getId());
}
@PostMapping("/getByIdDetailed")
public DictionaryDetailedDto getByIdDetailed(@RequestBody IdRequest dto) {
return this.service.getByIdDetailed(dto.getId());
}
}

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.CreateDictionaryItemDto;
import cn.lihongjie.coal.dto.UpdateDictionaryItemDto;
import cn.lihongjie.coal.dto.DictionaryItemDto;
import cn.lihongjie.coal.service.DictionaryItemService;
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("/dictionaryItem")
@RestController
@SysLog(module = "数据字典项")
public class DictionaryItemController {
@Autowired
DictionaryItemService service;
@PostMapping("/create")
@SysLog(action = "新增")
public DictionaryItemDto create(@RequestBody CreateDictionaryItemDto dto) {
return this.service.create(dto);
}
@PostMapping("/update")
@SysLog(action = "编辑")
public DictionaryItemDto update(@RequestBody UpdateDictionaryItemDto dto) {
return this.service.update(dto);
}
@PostMapping("/delete")
@SysLog(action = "删除")
public Object delete(@RequestBody IdRequest dto) {
this.service.delete(dto);
return null;
}
@PostMapping("/list")
public Page<DictionaryItemDto> list(@RequestBody CommonQuery dto) {
return this.service.list(dto);
}
@PostMapping("/getById")
public DictionaryItemDto 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.DictionaryItemEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface DictionaryItemRepository extends BaseRepository<DictionaryItemEntity> {
}

View File

@@ -1,7 +1,9 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import jakarta.persistence.OneToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.util.List;
@@ -9,14 +11,30 @@ import java.util.List;
public class CreateDictionaryDto extends CommonDto
{
@Comment("字典类型 1 静态字典 2 动态字典")
private String dictType;
@OneToOne
@Comment("动态字典关联的脚本")
private String script;
private List<DictionaryItemDto> item;
@Data
public static class DictionaryItemDto extends CommonDto {
private List<DictionaryItemDto> children;
private String parent;
}
}

View File

@@ -0,0 +1,11 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
@Data
public class CreateDictionaryItemDto extends CommonDto {
private String parent;
private String dictionary;
}

View File

@@ -0,0 +1,22 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
import java.util.List;
@Data
public class DictionaryDetailedDto extends DictionaryDto {
private List<DictionaryItemDto> item;
@Data
public static class DictionaryItemDto extends CommonDto {
private String parent;
private List<DictionaryItemDto> children;
}
}

View File

@@ -1,22 +1,18 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import cn.lihongjie.coal.entity.ScriptEntity;
import lombok.Data;
import java.util.List;
@Data
public class DictionaryDto extends CommonDto
{
private List<DictionaryItemDto> item;
@Data
public static class DictionaryItemDto extends CommonDto {
private String dictType;
private ScriptEntity script;
private List<DictionaryItemDto> children;
}
}

View File

@@ -0,0 +1,11 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
@Data
public class DictionaryItemDto extends CommonDto {
private String parent;
private String dictionary;
}

View File

@@ -1,7 +1,9 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import jakarta.persistence.OneToOne;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.util.List;
@@ -9,14 +11,27 @@ import java.util.List;
public class UpdateDictionaryDto extends CommonDto
{
private List<DictionaryItemDto> item;
@Comment("字典类型 1 静态字典 2 动态字典")
private String dictType;
@OneToOne
@Comment("动态字典关联的脚本")
private String script;
private List<DictionaryItemDto > item;
@Data
public static class DictionaryItemDto extends CommonDto {
private List<CreateDictionaryDto.DictionaryItemDto> children;
private List<DictionaryItemDto> children;
private String parent;
}
}

View File

@@ -0,0 +1,12 @@
package cn.lihongjie.coal.dto;
import cn.lihongjie.coal.dto.base.CommonDto;
import lombok.Data;
@Data
public class UpdateDictionaryItemDto extends CommonDto {
private String parent;
private String dictionary;
}

View File

@@ -1,9 +1,10 @@
package cn.lihongjie.coal.entity;
import cn.lihongjie.coal.entity.base.CommonEntity;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
@@ -17,8 +18,24 @@ import java.util.List;
public class DictionaryEntity extends CommonEntity {
@OneToMany(mappedBy = "dictionary")
@JsonManagedReference
@OneToMany(mappedBy = "dictionary", cascade = CascadeType.ALL)
private List<DictionaryItemEntity> item;
@Comment("字典类型 1 静态字典 2 动态字典")
private String dictType;
@OneToOne
@Comment("动态字典关联的脚本")
private ScriptEntity script;
public void setItem(List<DictionaryItemEntity> item) {
this.item = item;
if (item != null) {
this.item.forEach(x -> x.setDictionary(this));
}
}
}

View File

@@ -15,7 +15,7 @@ import java.util.List;
public class DictionaryItemEntity extends CommonEntity {
@ManyToOne
@ManyToOne()
private DictionaryEntity dictionary;
@OneToMany(mappedBy = "parent")

View File

@@ -13,6 +13,7 @@ import java.time.LocalDateTime;
@MappedSuperclass
@Getter
@Setter
@DynamicUpdate
public class BaseEntity {

View File

@@ -1,6 +1,8 @@
package cn.lihongjie.coal.mapper;
import cn.lihongjie.coal.dto.base.BaseDto;
import cn.lihongjie.coal.entity.*;
import cn.lihongjie.coal.entity.base.BaseEntity;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
@@ -97,4 +99,40 @@ public interface CommonMapper {
return e;
}
public default ScriptEntity createScript(String id) {
if (StringUtils.isEmpty(id)) {
return null;
}
ScriptEntity e = new ScriptEntity();
e.setId(id);
return e;
}
public default String toString(Object o){
if (o instanceof String) {
return ((String) o);
}
if (o == null) {
return null;
}else if (o instanceof BaseEntity) {
return ((BaseEntity) o).getId();
} else if (o instanceof BaseDto) {
return ((BaseDto) o).getId();
} else if (o instanceof String) {
return (String) o;
}else {
return o.toString();
}
}
}

View File

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

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.mapper;
import cn.lihongjie.coal.dto.CreateDictionaryDto;
import cn.lihongjie.coal.dto.DictionaryDetailedDto;
import cn.lihongjie.coal.dto.DictionaryDto;
import cn.lihongjie.coal.dto.UpdateDictionaryDto;
import cn.lihongjie.coal.entity.DictionaryEntity;
@@ -23,4 +24,6 @@ public interface DictionaryMapper {
void updateEntity(@MappingTarget DictionaryEntity entity, UpdateDictionaryDto dto);
DictionaryDetailedDto toDetailedDto(DictionaryEntity entity);
}

View File

@@ -47,7 +47,9 @@ public class CoalBlendService extends BaseService<CoalBlendEntity, CoalBlendRepo
CoalBlendEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -55,7 +55,9 @@ public class CoalParameterDefService extends BaseService<CoalParameterDefEntity,
CoalParameterDefEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -59,7 +59,9 @@ public class CoalWashingDailyAnalysisService extends BaseService<CoalWashingDail
CoalWashingDailyAnalysisEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -47,7 +47,9 @@ public class DepartmentService extends BaseService<DepartmentEntity, DepartmentR
DepartmentEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -0,0 +1,82 @@
package cn.lihongjie.coal.service;
import cn.lihongjie.coal.dao.DictionaryItemRepository;
import cn.lihongjie.coal.dto.*;
import cn.lihongjie.coal.entity.DictionaryItemEntity;
import cn.lihongjie.coal.mapper.DictionaryItemMapper;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class DictionaryItemService extends BaseService<DictionaryItemEntity, DictionaryItemRepository> {
@Autowired
DictionaryItemRepository repository;
@Autowired
DictionaryItemMapper mapper;
@PostConstruct
public void init() {
}
public DictionaryItemDto create(CreateDictionaryItemDto request) {
DictionaryItemEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public DictionaryItemDto update(UpdateDictionaryItemDto request) {
DictionaryItemEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds());
}
public DictionaryItemDto getById(String id) {
DictionaryItemEntity entity = repository.get(id);
return mapper.toDto(entity);
}
@Autowired
ConversionService conversionService;
public Page<DictionaryItemDto> list(CommonQuery query) {
Page<DictionaryItemEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

@@ -36,7 +36,6 @@ public class DictionaryService extends BaseService<DictionaryEntity, DictionaryR
DictionaryEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
@@ -47,10 +46,19 @@ public class DictionaryService extends BaseService<DictionaryEntity, DictionaryR
DictionaryEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
if (entity.getItem() != null) {
entity.getItem().forEach(x -> x.setDictionary(entity));
}
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds());
@@ -67,6 +75,8 @@ public class DictionaryService extends BaseService<DictionaryEntity, DictionaryR
}
@Autowired
ConversionService conversionService;
@@ -78,4 +88,11 @@ public class DictionaryService extends BaseService<DictionaryEntity, DictionaryR
return page.map(this.mapper::toDto);
}
public DictionaryDetailedDto getByIdDetailed(String id) {
DictionaryEntity entity = repository.get(id);
return mapper.toDetailedDto(entity);
}
}

View File

@@ -47,7 +47,9 @@ public class OrganizationService extends BaseService<OrganizationEntity, Organiz
OrganizationEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -47,7 +47,9 @@ public class PermissionService extends BaseService<PermissionEntity, PermissionR
PermissionEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -65,7 +65,9 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
ResourceEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -47,7 +47,9 @@ public class RoleService extends BaseService<RoleEntity, RoleRepository>{
RoleEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -47,7 +47,9 @@ public class ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
ScriptEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -47,7 +47,9 @@ public class SupplierService extends BaseService<SupplierEntity, SupplierReposit
SupplierEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -47,7 +47,9 @@ public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepo
SysConfigEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -50,7 +50,9 @@ public class SysLogService extends BaseService<SysLogEntity, SysLogRepository>{
SysLogEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
return null;
this.repository.save(entity);
return getById(entity.getId());
}

View File

@@ -62,7 +62,8 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
UserEntity user = this.repository.get(request.getId());
this.mapper.updateEntity(user, request);
return null;
this.repository.save(user);
return getById(user.getId());
}