mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
供应商curd
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package cn.lihongjie.coal.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.service.SupplierService;
|
||||
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("/supplier")
|
||||
@RestController
|
||||
@SysLog(module = "供应商")
|
||||
public class SupplierController {
|
||||
|
||||
@Autowired
|
||||
SupplierService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@SysLog(msg = "新增")
|
||||
public SupplierDto create(@RequestBody CreateSupplierDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@SysLog(msg = "编辑")
|
||||
public SupplierDto update(@RequestBody UpdateSupplierDto 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<SupplierDto> list(@RequestBody CommonQuery dto) {
|
||||
return this.service.list(dto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getById")
|
||||
public SupplierDto getById(@RequestBody IdRequest dto) {
|
||||
return this.service.getById(dto.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.dao;
|
||||
|
||||
import cn.lihongjie.coal.entity.SupplierEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SupplierRepository extends BaseRepository<SupplierEntity> {
|
||||
}
|
||||
27
src/main/java/cn/lihongjie/coal/dto/CreateSupplierDto.java
Normal file
27
src/main/java/cn/lihongjie/coal/dto/CreateSupplierDto.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreateSupplierDto extends OrgCommonDto {
|
||||
@Comment("联系人")
|
||||
private String contact;
|
||||
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
|
||||
|
||||
@Comment("地址")
|
||||
private String address;
|
||||
|
||||
}
|
||||
27
src/main/java/cn/lihongjie/coal/dto/SupplierDto.java
Normal file
27
src/main/java/cn/lihongjie/coal/dto/SupplierDto.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class SupplierDto extends OrgCommonDto {
|
||||
@Comment("联系人")
|
||||
private String contact;
|
||||
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
|
||||
|
||||
@Comment("地址")
|
||||
private String address;
|
||||
|
||||
}
|
||||
27
src/main/java/cn/lihongjie/coal/dto/UpdateSupplierDto.java
Normal file
27
src/main/java/cn/lihongjie/coal/dto/UpdateSupplierDto.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package cn.lihongjie.coal.dto;
|
||||
|
||||
import cn.lihongjie.coal.dto.base.OrgCommonDto;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateSupplierDto extends OrgCommonDto {
|
||||
@Comment("联系人")
|
||||
private String contact;
|
||||
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
|
||||
|
||||
@Comment("地址")
|
||||
private String address;
|
||||
|
||||
}
|
||||
41
src/main/java/cn/lihongjie/coal/entity/SupplierEntity.java
Normal file
41
src/main/java/cn/lihongjie/coal/entity/SupplierEntity.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package cn.lihongjie.coal.entity;
|
||||
|
||||
import cn.lihongjie.coal.entity.base.OrgCommonEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class SupplierEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@Comment("联系人")
|
||||
private String contact;
|
||||
|
||||
|
||||
|
||||
@Comment("邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
|
||||
|
||||
@Comment("地址")
|
||||
private String address;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
24
src/main/java/cn/lihongjie/coal/mapper/SupplierMapper.java
Normal file
24
src/main/java/cn/lihongjie/coal/mapper/SupplierMapper.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.mapper;
|
||||
|
||||
|
||||
import cn.lihongjie.coal.dto.CreateSupplierDto;
|
||||
import cn.lihongjie.coal.dto.UpdateSupplierDto;
|
||||
import cn.lihongjie.coal.dto.SupplierDto;
|
||||
import cn.lihongjie.coal.entity.SupplierEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(
|
||||
componentModel = MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class}
|
||||
|
||||
)
|
||||
public interface SupplierMapper {
|
||||
SupplierDto toDto(SupplierEntity user);
|
||||
|
||||
SupplierEntity toEntity(CreateSupplierDto request);
|
||||
|
||||
|
||||
void updateEntity(@MappingTarget SupplierEntity entity, UpdateSupplierDto dto);
|
||||
}
|
||||
81
src/main/java/cn/lihongjie/coal/service/SupplierService.java
Normal file
81
src/main/java/cn/lihongjie/coal/service/SupplierService.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.service;
|
||||
|
||||
import cn.lihongjie.coal.dao.SupplierRepository;
|
||||
import cn.lihongjie.coal.dto.*;
|
||||
import cn.lihongjie.coal.entity.SupplierEntity;
|
||||
import cn.lihongjie.coal.mapper.SupplierMapper;
|
||||
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 SupplierService extends BaseService<SupplierEntity, SupplierRepository> {
|
||||
|
||||
@Autowired
|
||||
SupplierRepository repository;
|
||||
|
||||
@Autowired
|
||||
SupplierMapper mapper;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SupplierDto create(CreateSupplierDto request) {
|
||||
|
||||
|
||||
SupplierEntity entity = mapper.toEntity(request);
|
||||
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SupplierDto update(UpdateSupplierDto request) {
|
||||
SupplierEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SupplierDto getById(String id) {
|
||||
|
||||
SupplierEntity entity = repository.get(id);
|
||||
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
ConversionService conversionService;
|
||||
|
||||
public Page<SupplierDto> list(CommonQuery query) {
|
||||
|
||||
Page<SupplierEntity> page = repository.findAll(query.specification(conversionService), PageRequest.of(query.getPageNo(), query.getPageSize(), Sort.by(query.getOrders())));
|
||||
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user