mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat(JsReceipt): implement CRUD operations and DTOs for receipt management
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.jsReceipt.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.jsReceipt.dto.CreateJsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.JsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.UpdateJsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.service.JsReceiptService;
|
||||
|
||||
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("/jsReceipt")
|
||||
@SysLog(module = "")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class JsReceiptController {
|
||||
@Autowired private JsReceiptService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public JsReceiptDto create(@RequestBody CreateJsReceiptDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public JsReceiptDto update(@RequestBody UpdateJsReceiptDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public JsReceiptDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<JsReceiptDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.lihongjie.coal.jsReceipt.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.CreateJsReceiptDetailDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateJsReceiptDto extends OrgCommonDto {
|
||||
|
||||
@Comment("单据编号")
|
||||
private String receiptNo;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
@Comment("供应商ID")
|
||||
private String supplier;
|
||||
|
||||
@Comment("总金额")
|
||||
private Double totalAmount;
|
||||
|
||||
@Comment("税额合计")
|
||||
private Double totalTaxAmount;
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
private List<CreateJsReceiptDetailDto> detail;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.lihongjie.coal.jsReceipt.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.JsReceiptDetailSimpleDto;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class JsReceiptDto extends OrgCommonDto {
|
||||
private String archiveStatus;
|
||||
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
|
||||
@Comment("单据编号")
|
||||
private String receiptNo;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
@Comment("供应商")
|
||||
private cn.lihongjie.coal.jsSupplier.dto.JsSupplierDto supplier;
|
||||
|
||||
@Comment("商品数量(明细行数)")
|
||||
private Integer itemCount;
|
||||
|
||||
@Comment("数量合计")
|
||||
private Double totalNumber;
|
||||
|
||||
@Comment("总金额")
|
||||
private Double totalAmount;
|
||||
|
||||
@Comment("税额合计")
|
||||
private Double totalTaxAmount;
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
private List<JsReceiptDetailSimpleDto> detail;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.lihongjie.coal.jsReceipt.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.jsSupplier.dto.JsSupplierDto;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class JsReceiptSimpleDto extends OrgCommonDto {
|
||||
|
||||
@Comment("单据编号")
|
||||
private String receiptNo;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
@Comment("供应商")
|
||||
private JsSupplierDto supplier;
|
||||
|
||||
@Comment("商品数量(明细行数)")
|
||||
private Integer itemCount;
|
||||
|
||||
@Comment("数量合计")
|
||||
private Double totalNumber;
|
||||
|
||||
@Comment("总金额")
|
||||
private Double totalAmount;
|
||||
|
||||
@Comment("税额合计")
|
||||
private Double totalTaxAmount;
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
@Comment("归档状态")
|
||||
private String archiveStatus;
|
||||
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.lihongjie.coal.jsReceipt.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.CreateJsReceiptDetailDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateJsReceiptDto extends OrgCommonDto {
|
||||
|
||||
@Comment("单据编号")
|
||||
private String receiptNo;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
@Comment("供应商ID")
|
||||
private String supplier;
|
||||
|
||||
@Comment("总金额")
|
||||
private Double totalAmount;
|
||||
|
||||
@Comment("税额合计")
|
||||
private Double totalTaxAmount;
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
private List<CreateJsReceiptDetailDto> detail;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package cn.lihongjie.coal.jsReceipt.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.entity.JsReceiptDetailEntity;
|
||||
import cn.lihongjie.coal.jsSupplier.entity.JsSupplierEntity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes = {
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_jsReceipt_org_id",
|
||||
columnList = "organization_id"),
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_jsReceipt_receipt_no",
|
||||
columnList = "receipt_no, organization_id",
|
||||
unique = true)
|
||||
})
|
||||
@EqualsAndHashCode(callSuper = false, exclude = {"detail"})
|
||||
public class JsReceiptEntity extends OrgCommonEntity {
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Comment("单据编号")
|
||||
@Column(nullable = false)
|
||||
private String receiptNo;
|
||||
|
||||
@Comment("单据日期")
|
||||
private LocalDateTime receiptDate;
|
||||
|
||||
@Comment("供应商")
|
||||
@ManyToOne
|
||||
private JsSupplierEntity supplier;
|
||||
|
||||
@Comment("商品数量(明细行数)")
|
||||
private Integer itemCount;
|
||||
|
||||
@Comment("数量合计")
|
||||
private Double totalNumber;
|
||||
|
||||
@Comment("总金额")
|
||||
private Double totalAmount;
|
||||
|
||||
@Comment("税额合计")
|
||||
private Double totalTaxAmount;
|
||||
|
||||
@Comment("制单人")
|
||||
private String creator;
|
||||
|
||||
@OneToMany(mappedBy = "receipt", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<JsReceiptDetailEntity> detail;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.jsReceipt.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.jsReceipt.dto.CreateJsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.JsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.UpdateJsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.entity.JsReceiptEntity;
|
||||
|
||||
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 JsReceiptMapper
|
||||
extends BaseMapper<JsReceiptEntity, JsReceiptDto, CreateJsReceiptDto, UpdateJsReceiptDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.jsReceipt.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.jsReceipt.entity.JsReceiptEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface JsReceiptRepository extends BaseRepository<JsReceiptEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package cn.lihongjie.coal.jsReceipt.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.jsReceipt.dto.CreateJsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.JsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.UpdateJsReceiptDto;
|
||||
import cn.lihongjie.coal.jsReceipt.entity.JsReceiptEntity;
|
||||
import cn.lihongjie.coal.jsReceipt.mapper.JsReceiptMapper;
|
||||
import cn.lihongjie.coal.jsReceipt.repository.JsReceiptRepository;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.entity.JsReceiptDetailEntity;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.repository.JsReceiptDetailRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
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 JsReceiptService extends BaseService<JsReceiptEntity, JsReceiptRepository> {
|
||||
@Autowired private JsReceiptRepository repository;
|
||||
|
||||
@Autowired private JsReceiptMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
@Autowired private JsReceiptDetailRepository detailRepository;
|
||||
|
||||
public JsReceiptDto create(CreateJsReceiptDto request) {
|
||||
JsReceiptEntity entity = mapper.toEntity(request);
|
||||
|
||||
// 处理明细关联
|
||||
processDetail(entity);
|
||||
|
||||
// 计算统计字段
|
||||
calculateSummary(entity);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
private void processDetail(JsReceiptEntity entity) {
|
||||
if (CollectionUtils.isNotEmpty(entity.getDetail())) {
|
||||
entity.getDetail().forEach(detail -> {
|
||||
detail.setReceipt(entity);
|
||||
detail.setOrganizationId(entity.getOrganizationId());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算统计字段
|
||||
*/
|
||||
private void calculateSummary(JsReceiptEntity entity) {
|
||||
if (CollectionUtils.isEmpty(entity.getDetail())) {
|
||||
entity.setItemCount(0);
|
||||
entity.setTotalNumber(0.0);
|
||||
entity.setTotalAmount(0.0);
|
||||
entity.setTotalTaxAmount(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
// 商品数量(明细行数)
|
||||
entity.setItemCount(entity.getDetail().size());
|
||||
|
||||
// 数量合计
|
||||
Double totalNumber = entity.getDetail().stream()
|
||||
.map(JsReceiptDetailEntity::getNumber)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.reduce(0.0, Double::sum);
|
||||
entity.setTotalNumber(totalNumber);
|
||||
|
||||
// 总金额
|
||||
Double totalAmount = entity.getDetail().stream()
|
||||
.map(JsReceiptDetailEntity::getAmount)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.reduce(0.0, Double::sum);
|
||||
entity.setTotalAmount(totalAmount);
|
||||
|
||||
// 税额合计
|
||||
Double totalTaxAmount = entity.getDetail().stream()
|
||||
.map(JsReceiptDetailEntity::getTaxAmount)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.reduce(0.0, Double::sum);
|
||||
entity.setTotalTaxAmount(totalTaxAmount);
|
||||
}
|
||||
|
||||
public JsReceiptDto update(UpdateJsReceiptDto request) {
|
||||
JsReceiptEntity entity = this.repository.get(request.getId());
|
||||
if (this.repository.containArchived(request.getId())) {
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
|
||||
// 删除旧的明细
|
||||
if (CollectionUtils.isNotEmpty(entity.getDetail())) {
|
||||
detailRepository.deleteAll(entity.getDetail());
|
||||
entity.getDetail().clear();
|
||||
}
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
// 处理新的明细
|
||||
processDetail(entity);
|
||||
|
||||
// 计算统计字段
|
||||
calculateSummary(entity);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
if (this.repository.containArchived(request)) {
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public JsReceiptDto getById(String id) {
|
||||
JsReceiptEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<JsReceiptDto> list(CommonQuery query) {
|
||||
Page<JsReceiptEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.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.jsReceiptDetail.dto.CreateJsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.JsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.UpdateJsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.service.JsReceiptDetailService;
|
||||
|
||||
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("/jsReceiptDetail")
|
||||
@SysLog(module = "")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class JsReceiptDetailController {
|
||||
@Autowired private JsReceiptDetailService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public JsReceiptDetailDto create(@RequestBody CreateJsReceiptDetailDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public JsReceiptDetailDto update(@RequestBody UpdateJsReceiptDetailDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public JsReceiptDetailDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<JsReceiptDetailDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreateJsReceiptDetailDto extends OrgCommonDto {
|
||||
|
||||
private String receipt;
|
||||
|
||||
@Comment("类目ID")
|
||||
private String category;
|
||||
|
||||
@Comment("商品名称")
|
||||
private String goodsName;
|
||||
|
||||
@Comment("单位ID")
|
||||
private String unit;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
@Comment("金额")
|
||||
private Double amount;
|
||||
|
||||
@Comment("税率(%)")
|
||||
private Double taxRate;
|
||||
|
||||
@Comment("税额")
|
||||
private Double taxAmount;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.jsItemCategory.dto.JsItemCategoryDto;
|
||||
import cn.lihongjie.coal.jsItemUnit.dto.JsItemUnitDto;
|
||||
import cn.lihongjie.coal.jsReceipt.dto.JsReceiptSimpleDto;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class JsReceiptDetailDto extends OrgCommonDto {
|
||||
private String archiveStatus;
|
||||
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
|
||||
private JsReceiptSimpleDto receipt;
|
||||
|
||||
@Comment("类目")
|
||||
private JsItemCategoryDto category;
|
||||
|
||||
@Comment("商品名称")
|
||||
private String goodsName;
|
||||
|
||||
@Comment("单位")
|
||||
private JsItemUnitDto unit;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
@Comment("金额")
|
||||
private Double amount;
|
||||
|
||||
@Comment("税率(%)")
|
||||
private Double taxRate;
|
||||
|
||||
@Comment("税额")
|
||||
private Double taxAmount;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class JsReceiptDetailSimpleDto extends OrgCommonDto {
|
||||
|
||||
@Comment("商品名称")
|
||||
private String goodsName;
|
||||
|
||||
@Comment("单位")
|
||||
private String unit;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
@Comment("金额")
|
||||
private Double amount;
|
||||
|
||||
@Comment("税率(%)")
|
||||
private Double taxRate;
|
||||
|
||||
@Comment("税额")
|
||||
private Double taxAmount;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdateJsReceiptDetailDto extends OrgCommonDto {
|
||||
|
||||
private String receipt;
|
||||
|
||||
@Comment("类目ID")
|
||||
private String category;
|
||||
|
||||
@Comment("商品名称")
|
||||
private String goodsName;
|
||||
|
||||
@Comment("单位ID")
|
||||
private String unit;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
@Comment("金额")
|
||||
private Double amount;
|
||||
|
||||
@Comment("税率(%)")
|
||||
private Double taxRate;
|
||||
|
||||
@Comment("税额")
|
||||
private Double taxAmount;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.jsItemCategory.entity.JsItemCategoryEntity;
|
||||
import cn.lihongjie.coal.jsItemUnit.entity.JsItemUnitEntity;
|
||||
import cn.lihongjie.coal.jsReceipt.entity.JsReceiptEntity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(
|
||||
indexes = {
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_jsReceiptDetail_org_id",
|
||||
columnList = "organization_id"),
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_jsReceiptDetail_receipt_id",
|
||||
columnList = "receipt_id")
|
||||
})
|
||||
public class JsReceiptDetailEntity extends OrgCommonEntity {
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "receipt_id")
|
||||
private JsReceiptEntity receipt;
|
||||
|
||||
@Comment("类目")
|
||||
@ManyToOne
|
||||
private JsItemCategoryEntity category;
|
||||
|
||||
@Comment("商品名称")
|
||||
@Column(nullable = false)
|
||||
private String goodsName;
|
||||
|
||||
@Comment("单位")
|
||||
@ManyToOne
|
||||
private JsItemUnitEntity unit;
|
||||
|
||||
@Comment("数量")
|
||||
private Double number;
|
||||
|
||||
@Comment("单价")
|
||||
private Double price;
|
||||
|
||||
@Comment("金额")
|
||||
private Double amount;
|
||||
|
||||
@Comment("税率(%)")
|
||||
private Double taxRate;
|
||||
|
||||
@Comment("税额")
|
||||
private Double taxAmount;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.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.jsReceiptDetail.dto.CreateJsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.JsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.UpdateJsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.entity.JsReceiptDetailEntity;
|
||||
|
||||
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 JsReceiptDetailMapper
|
||||
extends BaseMapper<
|
||||
JsReceiptDetailEntity,
|
||||
JsReceiptDetailDto,
|
||||
CreateJsReceiptDetailDto,
|
||||
UpdateJsReceiptDetailDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.entity.JsReceiptDetailEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface JsReceiptDetailRepository extends BaseRepository<JsReceiptDetailEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package cn.lihongjie.coal.jsReceiptDetail.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.jsReceiptDetail.dto.CreateJsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.JsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.dto.UpdateJsReceiptDetailDto;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.entity.JsReceiptDetailEntity;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.mapper.JsReceiptDetailMapper;
|
||||
import cn.lihongjie.coal.jsReceiptDetail.repository.JsReceiptDetailRepository;
|
||||
|
||||
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 JsReceiptDetailService
|
||||
extends BaseService<JsReceiptDetailEntity, JsReceiptDetailRepository> {
|
||||
@Autowired private JsReceiptDetailRepository repository;
|
||||
|
||||
@Autowired private JsReceiptDetailMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public JsReceiptDetailDto create(CreateJsReceiptDetailDto request) {
|
||||
JsReceiptDetailEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public JsReceiptDetailDto update(UpdateJsReceiptDetailDto request) {
|
||||
JsReceiptDetailEntity entity = this.repository.get(request.getId());
|
||||
if (this.repository.containArchived(request.getId())) {
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
if (this.repository.containArchived(request)) {
|
||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||
}
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public JsReceiptDetailDto getById(String id) {
|
||||
JsReceiptDetailEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<JsReceiptDetailDto> list(CommonQuery query) {
|
||||
Page<JsReceiptDetailEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.archive(dto);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.unArchive(dto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.jsReceiptDetail.controller.JsReceiptDetailController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(JsReceiptDetailController.class)
|
||||
def objectMapper = ioc.getBean(ObjectMapper.class) as ObjectMapper
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(params!=null ? objectMapper.convertValue(params, CommonQuery.class ) : new CommonQuery())
|
||||
|
||||
|
||||
19
src/main/resources/scripts/dict/enum/jsReceiptDict.groovy
Normal file
19
src/main/resources/scripts/dict/enum/jsReceiptDict.groovy
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.jsReceipt.controller.JsReceiptController
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(JsReceiptController.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