feat(organizationInfo): 新增企业信息管理功能

- 添加企业信息相关的控制器、DTO、实体类、映射器、仓库和服务
- 实现企业信息的创建、更新、删除、查询等功能
- 添加企业信息字典脚本
This commit is contained in:
2025-02-23 20:57:20 +08:00
parent 59599d193b
commit b7ddbd0a31
9 changed files with 281 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package cn.lihongjie.coal.organizationInfo.controller;
import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.organizationInfo.dto.CreateOrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.dto.OrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.dto.UpdateOrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.service.OrganizationInfoService;
import lombok.extern.slf4j.Slf4j;
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;
@RestController
@RequestMapping("/organizationInfo")
@SysLog(module = "企业信息")
@Slf4j
@OrgScope
public class OrganizationInfoController {
@Autowired private OrganizationInfoService service;
@PostMapping("/create")
public OrganizationInfoDto create(@RequestBody CreateOrganizationInfoDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public OrganizationInfoDto update(@RequestBody UpdateOrganizationInfoDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public OrganizationInfoDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<OrganizationInfoDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -0,0 +1,20 @@
package cn.lihongjie.coal.organizationInfo.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class CreateOrganizationInfoDto extends OrgCommonDto {
@Comment("企业全称")
private String fullName;
@Comment("企业简称")
private String shortName;
@Comment("统一社会信用代码")
private String creditCode;
}

View File

@@ -0,0 +1,20 @@
package cn.lihongjie.coal.organizationInfo.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class OrganizationInfoDto extends OrgCommonDto {
@Comment("企业全称")
private String fullName;
@Comment("企业简称")
private String shortName;
@Comment("统一社会信用代码")
private String creditCode;
}

View File

@@ -0,0 +1,20 @@
package cn.lihongjie.coal.organizationInfo.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
public class UpdateOrganizationInfoDto extends OrgCommonDto {
@Comment("企业全称")
private String fullName;
@Comment("企业简称")
private String shortName;
@Comment("统一社会信用代码")
private String creditCode;
}

View File

@@ -0,0 +1,29 @@
package cn.lihongjie.coal.organizationInfo.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.Comment;
@Data
@Entity
@Table(
indexes =
@jakarta.persistence.Index(
name = "idx_organizationInfo_org_id",
columnList = "organization_id"))
public class OrganizationInfoEntity extends OrgCommonEntity {
@Comment("企业全称")
private String fullName;
@Comment("企业简称")
private String shortName;
@Comment("统一社会信用代码")
private String creditCode;
}

View File

@@ -0,0 +1,23 @@
package cn.lihongjie.coal.organizationInfo.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.organizationInfo.dto.CreateOrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.dto.OrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.dto.UpdateOrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.entity.OrganizationInfoEntity;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class, CommonEntityMapper.class},
mappingControl = DeepClone.class)
public interface OrganizationInfoMapper
extends BaseMapper<
OrganizationInfoEntity,
OrganizationInfoDto,
CreateOrganizationInfoDto,
UpdateOrganizationInfoDto> {}

View File

@@ -0,0 +1,15 @@
package cn.lihongjie.coal.organizationInfo.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.organizationInfo.entity.OrganizationInfoEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface OrganizationInfoRepository extends BaseRepository<OrganizationInfoEntity> {
@Query("select false")
boolean isLinked(List<String> ids);
}

View File

@@ -0,0 +1,81 @@
package cn.lihongjie.coal.organizationInfo.service;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.organizationInfo.dto.CreateOrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.dto.OrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.dto.UpdateOrganizationInfoDto;
import cn.lihongjie.coal.organizationInfo.entity.OrganizationInfoEntity;
import cn.lihongjie.coal.organizationInfo.mapper.OrganizationInfoMapper;
import cn.lihongjie.coal.organizationInfo.repository.OrganizationInfoRepository;
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;
import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@Transactional
public class OrganizationInfoService
extends BaseService<OrganizationInfoEntity, OrganizationInfoRepository> {
@Autowired private OrganizationInfoRepository repository;
@Autowired private OrganizationInfoMapper mapper;
@Autowired private ConversionService conversionService;
@Autowired private DbFunctionService dbFunctionService;
public OrganizationInfoDto create(CreateOrganizationInfoDto request) {
OrganizationInfoEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public OrganizationInfoDto update(UpdateOrganizationInfoDto request) {
OrganizationInfoEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
boolean linked = this.repository.isLinked(request.getIds());
if (linked) {
throw new BizException("数据已被关联,无法删除");
}
this.repository.deleteAllById(request.getIds());
}
public OrganizationInfoDto getById(String id) {
OrganizationInfoEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<OrganizationInfoDto> list(CommonQuery query) {
Page<OrganizationInfoEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

@@ -0,0 +1,19 @@
package scripts.dict
import cn.lihongjie.coal.base.dto.CommonQuery
import cn.lihongjie.coal.organizationInfo.controller.OrganizationInfoController
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.context.ApplicationContext
ApplicationContext ioc = ioc
def controller = ioc.getBean(OrganizationInfoController.class)
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())