From 2f8f6e850c2be83c1f65a14a0466de1e59f88613 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sun, 30 Jul 2023 23:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86curd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coal/controller/SupplierController.java | 52 ++++++++++++ .../coal/dao/SupplierRepository.java | 8 ++ .../lihongjie/coal/dto/CreateSupplierDto.java | 27 +++++++ .../cn/lihongjie/coal/dto/SupplierDto.java | 27 +++++++ .../lihongjie/coal/dto/UpdateSupplierDto.java | 27 +++++++ .../lihongjie/coal/entity/SupplierEntity.java | 41 ++++++++++ .../lihongjie/coal/mapper/SupplierMapper.java | 24 ++++++ .../coal/service/SupplierService.java | 81 +++++++++++++++++++ 8 files changed, 287 insertions(+) create mode 100644 src/main/java/cn/lihongjie/coal/controller/SupplierController.java create mode 100644 src/main/java/cn/lihongjie/coal/dao/SupplierRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/CreateSupplierDto.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/SupplierDto.java create mode 100644 src/main/java/cn/lihongjie/coal/dto/UpdateSupplierDto.java create mode 100644 src/main/java/cn/lihongjie/coal/entity/SupplierEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/mapper/SupplierMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/service/SupplierService.java diff --git a/src/main/java/cn/lihongjie/coal/controller/SupplierController.java b/src/main/java/cn/lihongjie/coal/controller/SupplierController.java new file mode 100644 index 00000000..e1a5fd23 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/controller/SupplierController.java @@ -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 list(@RequestBody CommonQuery dto) { + return this.service.list(dto); + } + + + @PostMapping("/getById") + public SupplierDto getById(@RequestBody IdRequest dto) { + return this.service.getById(dto.getId()); + } +} diff --git a/src/main/java/cn/lihongjie/coal/dao/SupplierRepository.java b/src/main/java/cn/lihongjie/coal/dao/SupplierRepository.java new file mode 100644 index 00000000..fd9a2397 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dao/SupplierRepository.java @@ -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 { +} \ No newline at end of file diff --git a/src/main/java/cn/lihongjie/coal/dto/CreateSupplierDto.java b/src/main/java/cn/lihongjie/coal/dto/CreateSupplierDto.java new file mode 100644 index 00000000..22a2c317 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/CreateSupplierDto.java @@ -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; + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/SupplierDto.java b/src/main/java/cn/lihongjie/coal/dto/SupplierDto.java new file mode 100644 index 00000000..0a591e65 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/SupplierDto.java @@ -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; + +} diff --git a/src/main/java/cn/lihongjie/coal/dto/UpdateSupplierDto.java b/src/main/java/cn/lihongjie/coal/dto/UpdateSupplierDto.java new file mode 100644 index 00000000..0e180f2d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dto/UpdateSupplierDto.java @@ -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; + +} diff --git a/src/main/java/cn/lihongjie/coal/entity/SupplierEntity.java b/src/main/java/cn/lihongjie/coal/entity/SupplierEntity.java new file mode 100644 index 00000000..0e21a7b5 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/entity/SupplierEntity.java @@ -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; + + + + + + + + + + + +} diff --git a/src/main/java/cn/lihongjie/coal/mapper/SupplierMapper.java b/src/main/java/cn/lihongjie/coal/mapper/SupplierMapper.java new file mode 100644 index 00000000..b48cb6f3 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/mapper/SupplierMapper.java @@ -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); +} diff --git a/src/main/java/cn/lihongjie/coal/service/SupplierService.java b/src/main/java/cn/lihongjie/coal/service/SupplierService.java new file mode 100644 index 00000000..ca9615c1 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/service/SupplierService.java @@ -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 { + + @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 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); + + } +}