mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
添加仓库管理
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.warehouse.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.warehouse.dto.CreateWarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.UpdateWarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.service.WarehouseService;
|
||||
|
||||
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("/warehouse")
|
||||
@SysLog(module = "仓库管理")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class WarehouseController {
|
||||
@Autowired private WarehouseService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public WarehouseDto create(@RequestBody CreateWarehouseDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public WarehouseDto update(@RequestBody UpdateWarehouseDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public WarehouseDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<WarehouseDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.warehouse.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateWarehouseDto extends OrgCommonDto {
|
||||
|
||||
private String address;
|
||||
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.warehouse.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateWarehouseDto extends OrgCommonDto {
|
||||
private String address;
|
||||
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.warehouse.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WarehouseDto extends OrgCommonDto {
|
||||
|
||||
private String address;
|
||||
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.lihongjie.coal.warehouse.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class WarehouseEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
private String address;
|
||||
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.warehouse.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.warehouse.dto.CreateWarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.UpdateWarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
|
||||
|
||||
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 WarehouseMapper
|
||||
extends BaseMapper<WarehouseEntity, WarehouseDto, CreateWarehouseDto, UpdateWarehouseDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.warehouse.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface WarehouseRepository extends BaseRepository<WarehouseEntity> {}
|
||||
@@ -0,0 +1,70 @@
|
||||
package cn.lihongjie.coal.warehouse.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.warehouse.dto.CreateWarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.UpdateWarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
|
||||
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
|
||||
import cn.lihongjie.coal.warehouse.mapper.WarehouseMapper;
|
||||
import cn.lihongjie.coal.warehouse.repository.WarehouseRepository;
|
||||
|
||||
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 WarehouseService extends BaseService<WarehouseEntity, WarehouseRepository> {
|
||||
@Autowired private WarehouseRepository repository;
|
||||
|
||||
@Autowired private WarehouseMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
public WarehouseDto create(CreateWarehouseDto request) {
|
||||
WarehouseEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public WarehouseDto update(UpdateWarehouseDto request) {
|
||||
WarehouseEntity 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 WarehouseDto getById(String id) {
|
||||
WarehouseEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<WarehouseDto> list(CommonQuery query) {
|
||||
Page<WarehouseEntity> 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