mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-07-25 07:07:37 +08:00
feat(ThreePhaseDevice): implement CRUD operations and DTOs for three-phase devices
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.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.threePhaseDevice.dto.CreateThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.dto.ThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.dto.UpdateThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.service.ThreePhaseDeviceService;
|
||||
|
||||
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("/threePhaseDevice")
|
||||
@SysLog(module = "")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class ThreePhaseDeviceController {
|
||||
@Autowired private ThreePhaseDeviceService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public ThreePhaseDeviceDto create(@RequestBody CreateThreePhaseDeviceDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ThreePhaseDeviceDto update(@RequestBody UpdateThreePhaseDeviceDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public ThreePhaseDeviceDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<ThreePhaseDeviceDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateThreePhaseDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
String supplier;
|
||||
|
||||
|
||||
|
||||
|
||||
private String location;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.ThreePhaseDeviceSupplierDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThreePhaseDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
|
||||
ThreePhaseDeviceSupplierDto supplier;
|
||||
|
||||
|
||||
|
||||
|
||||
private String location;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateThreePhaseDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
String supplier;
|
||||
|
||||
|
||||
|
||||
|
||||
private String location;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.entity.ThreePhaseDeviceSupplierEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_threePhaseDevice_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class ThreePhaseDeviceEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
ThreePhaseDeviceSupplierEntity supplier;
|
||||
|
||||
|
||||
|
||||
|
||||
private String location;
|
||||
|
||||
|
||||
private String imei;
|
||||
|
||||
|
||||
private String iccid;
|
||||
|
||||
private String sno;
|
||||
|
||||
private LocalDateTime lastOnlineTime;
|
||||
|
||||
private LocalDateTime lastOfflineTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.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.threePhaseDevice.dto.CreateThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.dto.ThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.dto.UpdateThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.entity.ThreePhaseDeviceEntity;
|
||||
|
||||
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 ThreePhaseDeviceMapper
|
||||
extends BaseMapper<
|
||||
ThreePhaseDeviceEntity,
|
||||
ThreePhaseDeviceDto,
|
||||
CreateThreePhaseDeviceDto,
|
||||
UpdateThreePhaseDeviceDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.threePhaseDevice.entity.ThreePhaseDeviceEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ThreePhaseDeviceRepository extends BaseRepository<ThreePhaseDeviceEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.threePhaseDevice.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.threePhaseDevice.dto.CreateThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.dto.ThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.dto.UpdateThreePhaseDeviceDto;
|
||||
import cn.lihongjie.coal.threePhaseDevice.entity.ThreePhaseDeviceEntity;
|
||||
import cn.lihongjie.coal.threePhaseDevice.mapper.ThreePhaseDeviceMapper;
|
||||
import cn.lihongjie.coal.threePhaseDevice.repository.ThreePhaseDeviceRepository;
|
||||
|
||||
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 ThreePhaseDeviceService
|
||||
extends BaseService<ThreePhaseDeviceEntity, ThreePhaseDeviceRepository> {
|
||||
@Autowired private ThreePhaseDeviceRepository repository;
|
||||
|
||||
@Autowired private ThreePhaseDeviceMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public ThreePhaseDeviceDto create(CreateThreePhaseDeviceDto request) {
|
||||
ThreePhaseDeviceEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public ThreePhaseDeviceDto update(UpdateThreePhaseDeviceDto request) {
|
||||
ThreePhaseDeviceEntity 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 ThreePhaseDeviceDto getById(String id) {
|
||||
ThreePhaseDeviceEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<ThreePhaseDeviceDto> list(CommonQuery query) {
|
||||
Page<ThreePhaseDeviceEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.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.threePhaseDeviceData.dto.CreateThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.dto.ThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.dto.UpdateThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.service.ThreePhaseDeviceDataService;
|
||||
|
||||
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("/threePhaseDeviceData")
|
||||
@SysLog(module = "")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class ThreePhaseDeviceDataController {
|
||||
@Autowired private ThreePhaseDeviceDataService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public ThreePhaseDeviceDataDto create(@RequestBody CreateThreePhaseDeviceDataDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ThreePhaseDeviceDataDto update(@RequestBody UpdateThreePhaseDeviceDataDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public ThreePhaseDeviceDataDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<ThreePhaseDeviceDataDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateThreePhaseDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThreePhaseDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateThreePhaseDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_threePhaseDeviceData_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class ThreePhaseDeviceDataEntity extends OrgCommonEntity {}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.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.threePhaseDeviceData.dto.CreateThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.dto.ThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.dto.UpdateThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.entity.ThreePhaseDeviceDataEntity;
|
||||
|
||||
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 ThreePhaseDeviceDataMapper
|
||||
extends BaseMapper<
|
||||
ThreePhaseDeviceDataEntity,
|
||||
ThreePhaseDeviceDataDto,
|
||||
CreateThreePhaseDeviceDataDto,
|
||||
UpdateThreePhaseDeviceDataDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.entity.ThreePhaseDeviceDataEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ThreePhaseDeviceDataRepository extends BaseRepository<ThreePhaseDeviceDataEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceData.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.threePhaseDeviceData.dto.CreateThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.dto.ThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.dto.UpdateThreePhaseDeviceDataDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.entity.ThreePhaseDeviceDataEntity;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.mapper.ThreePhaseDeviceDataMapper;
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.repository.ThreePhaseDeviceDataRepository;
|
||||
|
||||
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 ThreePhaseDeviceDataService
|
||||
extends BaseService<ThreePhaseDeviceDataEntity, ThreePhaseDeviceDataRepository> {
|
||||
@Autowired private ThreePhaseDeviceDataRepository repository;
|
||||
|
||||
@Autowired private ThreePhaseDeviceDataMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public ThreePhaseDeviceDataDto create(CreateThreePhaseDeviceDataDto request) {
|
||||
ThreePhaseDeviceDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public ThreePhaseDeviceDataDto update(UpdateThreePhaseDeviceDataDto request) {
|
||||
ThreePhaseDeviceDataEntity 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 ThreePhaseDeviceDataDto getById(String id) {
|
||||
ThreePhaseDeviceDataEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<ThreePhaseDeviceDataDto> list(CommonQuery query) {
|
||||
Page<ThreePhaseDeviceDataEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.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.threePhaseDeviceSupplier.dto.CreateThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.ThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.UpdateThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.service.ThreePhaseDeviceSupplierService;
|
||||
|
||||
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("/threePhaseDeviceSupplier")
|
||||
@SysLog(module = "")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class ThreePhaseDeviceSupplierController {
|
||||
@Autowired private ThreePhaseDeviceSupplierService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public ThreePhaseDeviceSupplierDto create(
|
||||
@RequestBody CreateThreePhaseDeviceSupplierDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ThreePhaseDeviceSupplierDto update(
|
||||
@RequestBody UpdateThreePhaseDeviceSupplierDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public ThreePhaseDeviceSupplierDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<ThreePhaseDeviceSupplierDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateThreePhaseDeviceSupplierDto extends OrgCommonDto {
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThreePhaseDeviceSupplierDto extends OrgCommonDto {
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateThreePhaseDeviceSupplierDto extends OrgCommonDto {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_threePhaseDeviceSupplier_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class ThreePhaseDeviceSupplierEntity extends OrgCommonEntity {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.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.threePhaseDeviceSupplier.dto.CreateThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.ThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.UpdateThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.entity.ThreePhaseDeviceSupplierEntity;
|
||||
|
||||
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 ThreePhaseDeviceSupplierMapper
|
||||
extends BaseMapper<
|
||||
ThreePhaseDeviceSupplierEntity,
|
||||
ThreePhaseDeviceSupplierDto,
|
||||
CreateThreePhaseDeviceSupplierDto,
|
||||
UpdateThreePhaseDeviceSupplierDto> {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.entity.ThreePhaseDeviceSupplierEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ThreePhaseDeviceSupplierRepository
|
||||
extends BaseRepository<ThreePhaseDeviceSupplierEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.threePhaseDeviceSupplier.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.threePhaseDeviceSupplier.dto.CreateThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.ThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.dto.UpdateThreePhaseDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.entity.ThreePhaseDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.mapper.ThreePhaseDeviceSupplierMapper;
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.repository.ThreePhaseDeviceSupplierRepository;
|
||||
|
||||
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 ThreePhaseDeviceSupplierService
|
||||
extends BaseService<ThreePhaseDeviceSupplierEntity, ThreePhaseDeviceSupplierRepository> {
|
||||
@Autowired private ThreePhaseDeviceSupplierRepository repository;
|
||||
|
||||
@Autowired private ThreePhaseDeviceSupplierMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public ThreePhaseDeviceSupplierDto create(CreateThreePhaseDeviceSupplierDto request) {
|
||||
ThreePhaseDeviceSupplierEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public ThreePhaseDeviceSupplierDto update(UpdateThreePhaseDeviceSupplierDto request) {
|
||||
ThreePhaseDeviceSupplierEntity 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 ThreePhaseDeviceSupplierDto getById(String id) {
|
||||
ThreePhaseDeviceSupplierEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<ThreePhaseDeviceSupplierDto> list(CommonQuery query) {
|
||||
Page<ThreePhaseDeviceSupplierEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.threePhaseDeviceData.controller.ThreePhaseDeviceDataController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(ThreePhaseDeviceDataController.class)
|
||||
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.threePhaseDevice.controller.ThreePhaseDeviceController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(ThreePhaseDeviceController.class)
|
||||
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.threePhaseDeviceSupplier.controller.ThreePhaseDeviceSupplierController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(ThreePhaseDeviceSupplierController.class)
|
||||
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user