mirror of
https://gitee.com/qqtt-ah/ai-crm.git
synced 2026-11-24 07:49:20 +08:00
feat: 落地 CRM Phase1 报价闭环与 PI 导出、单证资料
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.document.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.document.model.po.CrmDocumentPO;
|
||||
|
||||
@Mapper
|
||||
public interface CrmDocumentMapper extends BaseMapper<CrmDocumentPO> {
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.document.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 单证记录。 */
|
||||
@Data
|
||||
@TableName("crm_document")
|
||||
public class CrmDocumentPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
@TableField("doc_type")
|
||||
private String docType;
|
||||
@TableField("doc_no")
|
||||
private String docNo;
|
||||
@TableField("ref_type")
|
||||
private String refType;
|
||||
@TableField("ref_id")
|
||||
private Long refId;
|
||||
@TableField("file_id")
|
||||
private Long fileId;
|
||||
@TableField("is_latest")
|
||||
private Integer isLatest;
|
||||
@TableField("version_no")
|
||||
private Integer versionNo;
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.dto.UpdateCrmCompanyProfileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.vo.CrmCompanyProfileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.service.CrmCompanyProfileService;
|
||||
|
||||
/** 本公司出口抬头。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/crm/profile")
|
||||
public class CrmCompanyProfileController {
|
||||
|
||||
private final CrmCompanyProfileService crmCompanyProfileService;
|
||||
|
||||
public CrmCompanyProfileController(CrmCompanyProfileService crmCompanyProfileService) {
|
||||
this.crmCompanyProfileService = crmCompanyProfileService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@RequirePermission(value = "crm:profile:read", description = "查看单证资料")
|
||||
public ApiResponse<CrmCompanyProfileVO> get() {
|
||||
return ApiResponse.success("获取成功", crmCompanyProfileService.getCurrent());
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@RequirePermission(value = "crm:profile:update", description = "更新单证资料")
|
||||
public ApiResponse<CrmCompanyProfileVO> save(@Valid @RequestBody UpdateCrmCompanyProfileDTO dto) {
|
||||
return ApiResponse.success("保存成功", crmCompanyProfileService.save(dto));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.po.CrmCompanyProfilePO;
|
||||
|
||||
@Mapper
|
||||
public interface CrmCompanyProfileMapper extends BaseMapper<CrmCompanyProfilePO> {
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/** 更新本公司出口抬头。 */
|
||||
@Data
|
||||
public class UpdateCrmCompanyProfileDTO {
|
||||
|
||||
@Size(max = 200)
|
||||
private String legalNameZh;
|
||||
@Size(max = 200)
|
||||
private String legalNameEn;
|
||||
@Size(max = 500)
|
||||
private String addressZh;
|
||||
@Size(max = 500)
|
||||
private String addressEn;
|
||||
@Size(max = 64)
|
||||
private String country;
|
||||
@Size(max = 50)
|
||||
private String phone;
|
||||
@Size(max = 100)
|
||||
private String email;
|
||||
@Size(max = 64)
|
||||
private String taxNo;
|
||||
@Size(max = 200)
|
||||
private String bankName;
|
||||
@Size(max = 100)
|
||||
private String bankAccount;
|
||||
@Size(max = 32)
|
||||
private String bankSwift;
|
||||
@Size(max = 500)
|
||||
private String bankAddress;
|
||||
@Size(max = 3)
|
||||
private String defaultCurrency;
|
||||
@Size(max = 16)
|
||||
private String defaultIncoterm;
|
||||
@Size(max = 500)
|
||||
private String remark;
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 本公司出口抬头。 */
|
||||
@Data
|
||||
@TableName("crm_company_profile")
|
||||
public class CrmCompanyProfilePO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
@TableField("legal_name_zh")
|
||||
private String legalNameZh;
|
||||
@TableField("legal_name_en")
|
||||
private String legalNameEn;
|
||||
@TableField("address_zh")
|
||||
private String addressZh;
|
||||
@TableField("address_en")
|
||||
private String addressEn;
|
||||
@TableField("country")
|
||||
private String country;
|
||||
@TableField("phone")
|
||||
private String phone;
|
||||
@TableField("email")
|
||||
private String email;
|
||||
@TableField("tax_no")
|
||||
private String taxNo;
|
||||
@TableField("bank_name")
|
||||
private String bankName;
|
||||
@TableField("bank_account")
|
||||
private String bankAccount;
|
||||
@TableField("bank_swift")
|
||||
private String bankSwift;
|
||||
@TableField("bank_address")
|
||||
private String bankAddress;
|
||||
@TableField("default_currency")
|
||||
private String defaultCurrency;
|
||||
@TableField("default_incoterm")
|
||||
private String defaultIncoterm;
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 本公司出口抬头视图。 */
|
||||
@Data
|
||||
public class CrmCompanyProfileVO {
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private String legalNameZh;
|
||||
private String legalNameEn;
|
||||
private String addressZh;
|
||||
private String addressEn;
|
||||
private String country;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String taxNo;
|
||||
private String bankName;
|
||||
private String bankAccount;
|
||||
private String bankSwift;
|
||||
private String bankAddress;
|
||||
private String defaultCurrency;
|
||||
private String defaultIncoterm;
|
||||
private String remark;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.dto.UpdateCrmCompanyProfileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.vo.CrmCompanyProfileVO;
|
||||
|
||||
/** 本公司出口抬头。 */
|
||||
public interface CrmCompanyProfileService {
|
||||
|
||||
CrmCompanyProfileVO getCurrent();
|
||||
|
||||
CrmCompanyProfileVO save(UpdateCrmCompanyProfileDTO dto);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.profile.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.mapper.CrmCompanyProfileMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.dto.UpdateCrmCompanyProfileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.po.CrmCompanyProfilePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.vo.CrmCompanyProfileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.service.CrmCompanyProfileService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 一公司一行出口抬头;不存在时返回空壳。
|
||||
*/
|
||||
@Service
|
||||
public class CrmCompanyProfileServiceImpl
|
||||
extends ServiceImpl<CrmCompanyProfileMapper, CrmCompanyProfilePO>
|
||||
implements CrmCompanyProfileService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public CrmCompanyProfileServiceImpl(CurrentUserContext currentUserContext) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CrmCompanyProfileVO getCurrent() {
|
||||
Long companyId = requireCompanyId();
|
||||
CrmCompanyProfilePO po = findByCompany(companyId);
|
||||
if (po == null) {
|
||||
CrmCompanyProfileVO empty = new CrmCompanyProfileVO();
|
||||
empty.setCompanyId(companyId);
|
||||
empty.setDefaultCurrency("USD");
|
||||
return empty;
|
||||
}
|
||||
return toVo(po);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CrmCompanyProfileVO save(UpdateCrmCompanyProfileDTO dto) {
|
||||
Long companyId = requireCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
CrmCompanyProfilePO po = findByCompany(companyId);
|
||||
if (po == null) {
|
||||
po = new CrmCompanyProfilePO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setCreateBy(userId);
|
||||
}
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
if (!StringUtils.hasText(po.getDefaultCurrency())) {
|
||||
po.setDefaultCurrency("USD");
|
||||
} else {
|
||||
po.setDefaultCurrency(po.getDefaultCurrency().trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
po.setUpdateBy(userId);
|
||||
if (po.getId() == null) {
|
||||
this.save(po);
|
||||
} else {
|
||||
this.updateById(po);
|
||||
}
|
||||
return toVo(this.getById(po.getId()));
|
||||
}
|
||||
|
||||
private CrmCompanyProfilePO findByCompany(Long companyId) {
|
||||
return this.getOne(new LambdaQueryWrapper<CrmCompanyProfilePO>()
|
||||
.eq(CrmCompanyProfilePO::getCompanyId, companyId)
|
||||
.last("LIMIT 1"), false);
|
||||
}
|
||||
|
||||
private Long requireCompanyId() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (companyId == null) {
|
||||
throw new BusinessException("请先选择公司");
|
||||
}
|
||||
return companyId;
|
||||
}
|
||||
|
||||
private CrmCompanyProfileVO toVo(CrmCompanyProfilePO po) {
|
||||
CrmCompanyProfileVO vo = new CrmCompanyProfileVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.ChangeCrmQuoteStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.CreateCrmQuoteDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.CrmQuoteFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.UpdateCrmQuoteDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.vo.CrmQuoteVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.service.CrmQuoteService;
|
||||
|
||||
/** 报价管理。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/crm/quote")
|
||||
public class CrmQuoteController {
|
||||
|
||||
private final CrmQuoteService crmQuoteService;
|
||||
|
||||
public CrmQuoteController(CrmQuoteService crmQuoteService) {
|
||||
this.crmQuoteService = crmQuoteService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "crm:quote:create", description = "创建报价")
|
||||
public ApiResponse<CrmQuoteVO> create(@Valid @RequestBody CreateCrmQuoteDTO dto) {
|
||||
return ApiResponse.success("创建成功", crmQuoteService.create(dto));
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "crm:quote:update", description = "更新报价")
|
||||
public ApiResponse<CrmQuoteVO> update(@PathVariable Long id, @Valid @RequestBody UpdateCrmQuoteDTO dto) {
|
||||
return ApiResponse.success("更新成功", crmQuoteService.update(id, dto));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "crm:quote:delete", description = "删除报价")
|
||||
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||
crmQuoteService.delete(id);
|
||||
return ApiResponse.success("删除成功");
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@RequirePermission(value = "crm:quote:read", description = "报价详情")
|
||||
public ApiResponse<CrmQuoteVO> get(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", crmQuoteService.get(id));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "crm:quote:read", description = "报价列表")
|
||||
public ApiResponse<PageResultVO<CrmQuoteVO>> list(
|
||||
@Valid @RequestBody PageQueryDTO<CrmQuoteFilterDTO> query) {
|
||||
return ApiResponse.success("获取成功", crmQuoteService.page(query));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/status")
|
||||
@RequirePermission(value = "crm:quote:status", description = "变更报价状态")
|
||||
public ApiResponse<CrmQuoteVO> changeStatus(
|
||||
@PathVariable Long id, @Valid @RequestBody ChangeCrmQuoteStatusDTO dto) {
|
||||
return ApiResponse.success("状态已更新", crmQuoteService.changeStatus(id, dto));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/export-pi")
|
||||
@RequirePermission(value = "crm:quote:export", description = "导出形式发票 PI")
|
||||
public ApiResponse<CrmQuoteVO> exportPi(@PathVariable Long id) {
|
||||
return ApiResponse.success("PI 已生成", crmQuoteService.exportPi(id));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.po.CrmQuoteItemPO;
|
||||
|
||||
@Mapper
|
||||
public interface CrmQuoteItemMapper extends BaseMapper<CrmQuoteItemPO> {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.po.CrmQuotePO;
|
||||
|
||||
@Mapper
|
||||
public interface CrmQuoteMapper extends BaseMapper<CrmQuotePO> {
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/** 变更报价状态。 */
|
||||
@Data
|
||||
public class ChangeCrmQuoteStatusDTO {
|
||||
|
||||
/** sent / accepted / rejected / expired / draft */
|
||||
@NotBlank(message = "目标状态不能为空")
|
||||
private String status;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/** 创建报价。 */
|
||||
@Data
|
||||
public class CreateCrmQuoteDTO {
|
||||
|
||||
@NotNull(message = "客户不能为空")
|
||||
private Long customerId;
|
||||
|
||||
private LocalDate quoteDate;
|
||||
|
||||
private LocalDate validUntil;
|
||||
|
||||
@Size(max = 3)
|
||||
private String currency;
|
||||
|
||||
@Size(max = 16)
|
||||
private String incoterm;
|
||||
|
||||
@Size(max = 200)
|
||||
private String paymentTerms;
|
||||
|
||||
private Long ownerUserId;
|
||||
|
||||
@Size(max = 1000)
|
||||
private String remark;
|
||||
|
||||
@NotEmpty(message = "至少一行明细")
|
||||
@Valid
|
||||
private List<CrmQuoteItemDTO> items;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/** 报价列表筛选。 */
|
||||
@Data
|
||||
public class CrmQuoteFilterDTO {
|
||||
private String keyword;
|
||||
private String status;
|
||||
private Long customerId;
|
||||
private Boolean onlyMine;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/** 报价行入参。 */
|
||||
@Data
|
||||
public class CrmQuoteItemDTO {
|
||||
|
||||
private Long productId;
|
||||
|
||||
@Size(max = 64)
|
||||
private String productCode;
|
||||
|
||||
@NotBlank(message = "英文品名不能为空")
|
||||
@Size(max = 200)
|
||||
private String nameEn;
|
||||
|
||||
@Size(max = 200)
|
||||
private String nameZh;
|
||||
|
||||
@Size(max = 500)
|
||||
private String spec;
|
||||
|
||||
@Size(max = 32)
|
||||
private String unit;
|
||||
|
||||
@NotNull(message = "数量不能为空")
|
||||
private BigDecimal qty;
|
||||
|
||||
@NotNull(message = "单价不能为空")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
@Size(max = 500)
|
||||
private String remark;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/** 更新报价(仅 draft)。 */
|
||||
@Data
|
||||
public class UpdateCrmQuoteDTO {
|
||||
|
||||
@NotNull(message = "客户不能为空")
|
||||
private Long customerId;
|
||||
|
||||
private LocalDate quoteDate;
|
||||
|
||||
private LocalDate validUntil;
|
||||
|
||||
@Size(max = 3)
|
||||
private String currency;
|
||||
|
||||
@Size(max = 16)
|
||||
private String incoterm;
|
||||
|
||||
@Size(max = 200)
|
||||
private String paymentTerms;
|
||||
|
||||
private Long ownerUserId;
|
||||
|
||||
@Size(max = 1000)
|
||||
private String remark;
|
||||
|
||||
@NotEmpty(message = "至少一行明细")
|
||||
@Valid
|
||||
private List<CrmQuoteItemDTO> items;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 报价行。 */
|
||||
@Data
|
||||
@TableName("crm_quote_item")
|
||||
public class CrmQuoteItemPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
@TableField("quote_id")
|
||||
private Long quoteId;
|
||||
@TableField("line_no")
|
||||
private Integer lineNo;
|
||||
@TableField("product_id")
|
||||
private Long productId;
|
||||
@TableField("product_code")
|
||||
private String productCode;
|
||||
@TableField("name_en")
|
||||
private String nameEn;
|
||||
@TableField("name_zh")
|
||||
private String nameZh;
|
||||
@TableField("spec")
|
||||
private String spec;
|
||||
@TableField("unit")
|
||||
private String unit;
|
||||
@TableField("qty")
|
||||
private BigDecimal qty;
|
||||
@TableField("unit_price")
|
||||
private BigDecimal unitPrice;
|
||||
@TableField("amount")
|
||||
private BigDecimal amount;
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 报价单头。 */
|
||||
@Data
|
||||
@TableName("crm_quote")
|
||||
public class CrmQuotePO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
@TableField("quote_no")
|
||||
private String quoteNo;
|
||||
@TableField("customer_id")
|
||||
private Long customerId;
|
||||
@TableField("quote_date")
|
||||
private LocalDate quoteDate;
|
||||
@TableField("valid_until")
|
||||
private LocalDate validUntil;
|
||||
@TableField("currency")
|
||||
private String currency;
|
||||
@TableField("incoterm")
|
||||
private String incoterm;
|
||||
@TableField("payment_terms")
|
||||
private String paymentTerms;
|
||||
@TableField("status")
|
||||
private String status;
|
||||
@TableField("total_amount")
|
||||
private BigDecimal totalAmount;
|
||||
@TableField("owner_user_id")
|
||||
private Long ownerUserId;
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
@TableLogic
|
||||
@TableField("delete_time")
|
||||
private LocalDateTime deleteTime;
|
||||
@TableField("delete_by")
|
||||
private Long deleteBy;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/** 报价行视图。 */
|
||||
@Data
|
||||
public class CrmQuoteItemVO {
|
||||
private Long id;
|
||||
private Integer lineNo;
|
||||
private Long productId;
|
||||
private String productCode;
|
||||
private String nameEn;
|
||||
private String nameZh;
|
||||
private String spec;
|
||||
private String unit;
|
||||
private BigDecimal qty;
|
||||
private BigDecimal unitPrice;
|
||||
private BigDecimal amount;
|
||||
private String remark;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** 报价视图。 */
|
||||
@Data
|
||||
public class CrmQuoteVO {
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private String quoteNo;
|
||||
private Long customerId;
|
||||
private String customerName;
|
||||
private LocalDate quoteDate;
|
||||
private LocalDate validUntil;
|
||||
private String currency;
|
||||
private String incoterm;
|
||||
private String paymentTerms;
|
||||
private String status;
|
||||
private BigDecimal totalAmount;
|
||||
private Long ownerUserId;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private List<CrmQuoteItemVO> items;
|
||||
/** 最新 PI 文件 ID */
|
||||
private Long latestPiFileId;
|
||||
private String latestPiAccessUrl;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.ChangeCrmQuoteStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.CreateCrmQuoteDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.CrmQuoteFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.UpdateCrmQuoteDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.vo.CrmQuoteVO;
|
||||
|
||||
/** 报价用例。 */
|
||||
public interface CrmQuoteService {
|
||||
|
||||
CrmQuoteVO create(CreateCrmQuoteDTO dto);
|
||||
|
||||
CrmQuoteVO update(Long id, UpdateCrmQuoteDTO dto);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
CrmQuoteVO get(Long id);
|
||||
|
||||
PageResultVO<CrmQuoteVO> page(PageQueryDTO<CrmQuoteFilterDTO> query);
|
||||
|
||||
CrmQuoteVO changeStatus(Long id, ChangeCrmQuoteStatusDTO dto);
|
||||
|
||||
/** 生成 PI PDF,返回含最新文件信息的报价详情。 */
|
||||
CrmQuoteVO exportPi(Long id);
|
||||
}
|
||||
+481
@@ -0,0 +1,481 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.quote.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.customer.mapper.CrmCustomerMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.customer.model.po.CrmCustomerPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.document.mapper.CrmDocumentMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.document.model.po.CrmDocumentPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.product.mapper.CrmProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.product.model.po.CrmProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.model.vo.CrmCompanyProfileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.profile.service.CrmCompanyProfileService;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.mapper.CrmQuoteItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.mapper.CrmQuoteMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.dto.*;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.po.CrmQuoteItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.po.CrmQuotePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.vo.CrmQuoteItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.model.vo.CrmQuoteVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.quote.service.CrmQuoteService;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.support.CrmGeneratedFileService;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.support.CrmPiPdfRenderer;
|
||||
import top.xyquan.ecomdmbbackend.modules.crm.support.CrmSeqService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 报价:草稿可改删;状态流转;导出 PI 挂 crm_document。
|
||||
*/
|
||||
@Service
|
||||
public class CrmQuoteServiceImpl extends ServiceImpl<CrmQuoteMapper, CrmQuotePO> implements CrmQuoteService {
|
||||
|
||||
private static final Set<String> STATUSES =
|
||||
Set.of("draft", "sent", "accepted", "rejected", "expired");
|
||||
|
||||
private final CrmQuoteItemMapper quoteItemMapper;
|
||||
private final CrmCustomerMapper customerMapper;
|
||||
private final CrmProductMapper productMapper;
|
||||
private final CrmDocumentMapper documentMapper;
|
||||
private final CrmSeqService crmSeqService;
|
||||
private final CrmCompanyProfileService profileService;
|
||||
private final CrmPiPdfRenderer piPdfRenderer;
|
||||
private final CrmGeneratedFileService generatedFileService;
|
||||
private final SysFileService sysFileService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public CrmQuoteServiceImpl(CrmQuoteItemMapper quoteItemMapper,
|
||||
CrmCustomerMapper customerMapper,
|
||||
CrmProductMapper productMapper,
|
||||
CrmDocumentMapper documentMapper,
|
||||
CrmSeqService crmSeqService,
|
||||
CrmCompanyProfileService profileService,
|
||||
CrmPiPdfRenderer piPdfRenderer,
|
||||
CrmGeneratedFileService generatedFileService,
|
||||
SysFileService sysFileService,
|
||||
CurrentUserContext currentUserContext) {
|
||||
this.quoteItemMapper = quoteItemMapper;
|
||||
this.customerMapper = customerMapper;
|
||||
this.productMapper = productMapper;
|
||||
this.documentMapper = documentMapper;
|
||||
this.crmSeqService = crmSeqService;
|
||||
this.profileService = profileService;
|
||||
this.piPdfRenderer = piPdfRenderer;
|
||||
this.generatedFileService = generatedFileService;
|
||||
this.sysFileService = sysFileService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CrmQuoteVO create(CreateCrmQuoteDTO dto) {
|
||||
Long companyId = requireCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
requireCustomer(companyId, dto.getCustomerId());
|
||||
|
||||
CrmQuotePO quote = new CrmQuotePO();
|
||||
quote.setCompanyId(companyId);
|
||||
quote.setQuoteNo(crmSeqService.nextQuoteNo(companyId));
|
||||
quote.setCustomerId(dto.getCustomerId());
|
||||
quote.setQuoteDate(dto.getQuoteDate() != null ? dto.getQuoteDate() : LocalDate.now());
|
||||
quote.setValidUntil(dto.getValidUntil());
|
||||
quote.setCurrency(normalizeCurrency(dto.getCurrency()));
|
||||
quote.setIncoterm(trimToNull(dto.getIncoterm()));
|
||||
quote.setPaymentTerms(trimToNull(dto.getPaymentTerms()));
|
||||
quote.setStatus("draft");
|
||||
quote.setOwnerUserId(dto.getOwnerUserId() != null ? dto.getOwnerUserId() : userId);
|
||||
quote.setRemark(trimToNull(dto.getRemark()));
|
||||
quote.setCreateBy(userId);
|
||||
quote.setUpdateBy(userId);
|
||||
|
||||
List<CrmQuoteItemPO> items = buildItems(companyId, dto.getItems());
|
||||
quote.setTotalAmount(sumAmount(items));
|
||||
this.save(quote);
|
||||
persistItems(quote.getId(), companyId, items);
|
||||
return get(quote.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CrmQuoteVO update(Long id, UpdateCrmQuoteDTO dto) {
|
||||
CrmQuotePO quote = requireOwned(id);
|
||||
if (!"draft".equals(quote.getStatus())) {
|
||||
throw new BusinessException("仅草稿状态可编辑");
|
||||
}
|
||||
Long companyId = quote.getCompanyId();
|
||||
requireCustomer(companyId, dto.getCustomerId());
|
||||
|
||||
quote.setCustomerId(dto.getCustomerId());
|
||||
if (dto.getQuoteDate() != null) {
|
||||
quote.setQuoteDate(dto.getQuoteDate());
|
||||
}
|
||||
quote.setValidUntil(dto.getValidUntil());
|
||||
quote.setCurrency(normalizeCurrency(dto.getCurrency()));
|
||||
quote.setIncoterm(trimToNull(dto.getIncoterm()));
|
||||
quote.setPaymentTerms(trimToNull(dto.getPaymentTerms()));
|
||||
if (dto.getOwnerUserId() != null) {
|
||||
quote.setOwnerUserId(dto.getOwnerUserId());
|
||||
}
|
||||
quote.setRemark(trimToNull(dto.getRemark()));
|
||||
quote.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
List<CrmQuoteItemPO> items = buildItems(companyId, dto.getItems());
|
||||
quote.setTotalAmount(sumAmount(items));
|
||||
this.updateById(quote);
|
||||
|
||||
quoteItemMapper.delete(new LambdaQueryWrapper<CrmQuoteItemPO>()
|
||||
.eq(CrmQuoteItemPO::getQuoteId, id));
|
||||
persistItems(id, companyId, items);
|
||||
return get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Long id) {
|
||||
CrmQuotePO quote = requireOwned(id);
|
||||
if (!Set.of("draft", "rejected").contains(quote.getStatus())) {
|
||||
throw new BusinessException("仅草稿或已拒绝的报价可删除");
|
||||
}
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
this.lambdaUpdate()
|
||||
.eq(CrmQuotePO::getId, id)
|
||||
.set(CrmQuotePO::getDeleteBy, userId)
|
||||
.update();
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CrmQuoteVO get(Long id) {
|
||||
CrmQuotePO quote = requireOwned(id);
|
||||
return toDetailVo(quote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<CrmQuoteVO> page(PageQueryDTO<CrmQuoteFilterDTO> query) {
|
||||
Long companyId = requireCompanyId();
|
||||
CrmQuoteFilterDTO filters = query.getFilters() != null ? query.getFilters() : new CrmQuoteFilterDTO();
|
||||
LambdaQueryWrapper<CrmQuotePO> w = new LambdaQueryWrapper<>();
|
||||
w.eq(CrmQuotePO::getCompanyId, companyId);
|
||||
if (StringUtils.hasText(filters.getStatus())) {
|
||||
w.eq(CrmQuotePO::getStatus, filters.getStatus().trim());
|
||||
}
|
||||
if (filters.getCustomerId() != null) {
|
||||
w.eq(CrmQuotePO::getCustomerId, filters.getCustomerId());
|
||||
}
|
||||
if (Boolean.TRUE.equals(filters.getOnlyMine())) {
|
||||
w.eq(CrmQuotePO::getOwnerUserId, currentUserContext.getCurrentUserId());
|
||||
}
|
||||
if (StringUtils.hasText(filters.getKeyword())) {
|
||||
String kw = filters.getKeyword().trim();
|
||||
w.and(x -> x.like(CrmQuotePO::getQuoteNo, kw).or().like(CrmQuotePO::getRemark, kw));
|
||||
}
|
||||
w.orderByDesc(CrmQuotePO::getId);
|
||||
IPage<CrmQuotePO> page = this.page(new Page<>(query.getPage(), query.getPageSize()), w);
|
||||
Map<Long, String> customerNames = loadCustomerNames(
|
||||
companyId, page.getRecords().stream().map(CrmQuotePO::getCustomerId).collect(Collectors.toSet()));
|
||||
List<CrmQuoteVO> records = page.getRecords().stream().map(q -> {
|
||||
CrmQuoteVO vo = toBriefVo(q);
|
||||
vo.setCustomerName(customerNames.get(q.getCustomerId()));
|
||||
return vo;
|
||||
}).toList();
|
||||
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CrmQuoteVO changeStatus(Long id, ChangeCrmQuoteStatusDTO dto) {
|
||||
CrmQuotePO quote = requireOwned(id);
|
||||
String target = dto.getStatus().trim().toLowerCase(Locale.ROOT);
|
||||
if (!STATUSES.contains(target)) {
|
||||
throw new BusinessException("目标状态不合法");
|
||||
}
|
||||
String from = quote.getStatus();
|
||||
if (!isAllowedTransition(from, target)) {
|
||||
throw new BusinessException("不允许从 " + from + " 变更为 " + target);
|
||||
}
|
||||
quote.setStatus(target);
|
||||
quote.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(quote);
|
||||
return get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CrmQuoteVO exportPi(Long id) {
|
||||
CrmQuotePO quote = requireOwned(id);
|
||||
Long companyId = quote.getCompanyId();
|
||||
List<CrmQuoteItemPO> items = listItems(id);
|
||||
if (items.isEmpty()) {
|
||||
throw new BusinessException("报价无明细,无法导出 PI");
|
||||
}
|
||||
CrmCustomerPO customer = requireCustomer(companyId, quote.getCustomerId());
|
||||
CrmCompanyProfileVO profile = profileService.getCurrent();
|
||||
|
||||
CrmPiPdfRenderer.Party seller = new CrmPiPdfRenderer.Party(
|
||||
firstNonBlank(profile.getLegalNameEn(), profile.getLegalNameZh()),
|
||||
firstNonBlank(profile.getAddressEn(), profile.getAddressZh()),
|
||||
profile.getCountry(),
|
||||
profile.getPhone(),
|
||||
profile.getEmail());
|
||||
CrmPiPdfRenderer.Party buyer = new CrmPiPdfRenderer.Party(
|
||||
firstNonBlank(customer.getNameEn(), customer.getName()),
|
||||
customer.getAddress(),
|
||||
customer.getCountry(),
|
||||
customer.getPhone(),
|
||||
customer.getEmail());
|
||||
|
||||
List<CrmPiPdfRenderer.Line> lines = new ArrayList<>();
|
||||
for (CrmQuoteItemPO item : items) {
|
||||
lines.add(new CrmPiPdfRenderer.Line(
|
||||
item.getLineNo(),
|
||||
item.getProductCode(),
|
||||
item.getNameEn(),
|
||||
item.getSpec(),
|
||||
item.getUnit(),
|
||||
item.getQty(),
|
||||
item.getUnitPrice(),
|
||||
item.getAmount()));
|
||||
}
|
||||
CrmPiPdfRenderer.PiModel model = new CrmPiPdfRenderer.PiModel(
|
||||
"PROFORMA INVOICE",
|
||||
quote.getQuoteNo(),
|
||||
quote.getQuoteDate() != null ? quote.getQuoteDate().toString() : "",
|
||||
quote.getValidUntil() != null ? quote.getValidUntil().toString() : null,
|
||||
quote.getCurrency(),
|
||||
quote.getIncoterm(),
|
||||
quote.getPaymentTerms(),
|
||||
quote.getRemark(),
|
||||
seller,
|
||||
buyer,
|
||||
lines,
|
||||
quote.getTotalAmount());
|
||||
|
||||
byte[] pdf = piPdfRenderer.render(model);
|
||||
String filename = "PI-" + quote.getQuoteNo() + ".pdf";
|
||||
SysFilePO file = generatedFileService.saveBytes(
|
||||
companyId, filename, "application/pdf", pdf);
|
||||
|
||||
// 旧版本取消 latest
|
||||
documentMapper.update(null, new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<CrmDocumentPO>()
|
||||
.eq(CrmDocumentPO::getCompanyId, companyId)
|
||||
.eq(CrmDocumentPO::getRefType, "quote")
|
||||
.eq(CrmDocumentPO::getRefId, id)
|
||||
.eq(CrmDocumentPO::getDocType, "pi")
|
||||
.eq(CrmDocumentPO::getIsLatest, 1)
|
||||
.set(CrmDocumentPO::getIsLatest, 0));
|
||||
|
||||
int nextVersion = 1;
|
||||
CrmDocumentPO last = documentMapper.selectOne(new LambdaQueryWrapper<CrmDocumentPO>()
|
||||
.eq(CrmDocumentPO::getCompanyId, companyId)
|
||||
.eq(CrmDocumentPO::getRefType, "quote")
|
||||
.eq(CrmDocumentPO::getRefId, id)
|
||||
.eq(CrmDocumentPO::getDocType, "pi")
|
||||
.orderByDesc(CrmDocumentPO::getVersionNo)
|
||||
.last("LIMIT 1"));
|
||||
if (last != null && last.getVersionNo() != null) {
|
||||
nextVersion = last.getVersionNo() + 1;
|
||||
}
|
||||
|
||||
CrmDocumentPO doc = new CrmDocumentPO();
|
||||
doc.setCompanyId(companyId);
|
||||
doc.setDocType("pi");
|
||||
doc.setDocNo(quote.getQuoteNo());
|
||||
doc.setRefType("quote");
|
||||
doc.setRefId(id);
|
||||
doc.setFileId(file.getId());
|
||||
doc.setIsLatest(1);
|
||||
doc.setVersionNo(nextVersion);
|
||||
doc.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
documentMapper.insert(doc);
|
||||
|
||||
return get(id);
|
||||
}
|
||||
|
||||
private boolean isAllowedTransition(String from, String to) {
|
||||
if (from.equals(to)) {
|
||||
return true;
|
||||
}
|
||||
return switch (from) {
|
||||
case "draft" -> Set.of("sent", "rejected").contains(to);
|
||||
case "sent" -> Set.of("accepted", "rejected", "expired", "draft").contains(to);
|
||||
case "rejected", "expired" -> "draft".equals(to);
|
||||
case "accepted" -> false;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private List<CrmQuoteItemPO> buildItems(Long companyId, List<CrmQuoteItemDTO> dtos) {
|
||||
List<CrmQuoteItemPO> items = new ArrayList<>();
|
||||
int lineNo = 1;
|
||||
for (CrmQuoteItemDTO dto : dtos) {
|
||||
if (dto.getQty() == null || dto.getQty().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new BusinessException("第 " + lineNo + " 行数量须大于 0");
|
||||
}
|
||||
if (dto.getUnitPrice() == null || dto.getUnitPrice().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new BusinessException("第 " + lineNo + " 行单价不能为负");
|
||||
}
|
||||
CrmQuoteItemPO item = new CrmQuoteItemPO();
|
||||
item.setCompanyId(companyId);
|
||||
item.setLineNo(lineNo++);
|
||||
item.setProductId(dto.getProductId());
|
||||
item.setProductCode(trimToNull(dto.getProductCode()));
|
||||
item.setNameEn(dto.getNameEn().trim());
|
||||
item.setNameZh(trimToNull(dto.getNameZh()));
|
||||
item.setSpec(trimToNull(dto.getSpec()));
|
||||
item.setUnit(StringUtils.hasText(dto.getUnit()) ? dto.getUnit().trim() : "PCS");
|
||||
item.setQty(dto.getQty());
|
||||
item.setUnitPrice(dto.getUnitPrice());
|
||||
item.setAmount(dto.getQty().multiply(dto.getUnitPrice()).setScale(2, RoundingMode.HALF_UP));
|
||||
item.setRemark(trimToNull(dto.getRemark()));
|
||||
|
||||
if (dto.getProductId() != null) {
|
||||
CrmProductPO product = productMapper.selectById(dto.getProductId());
|
||||
if (product == null || !companyId.equals(product.getCompanyId())) {
|
||||
throw new BusinessException("产品不存在: " + dto.getProductId());
|
||||
}
|
||||
if (!StringUtils.hasText(item.getProductCode())) {
|
||||
item.setProductCode(product.getCode());
|
||||
}
|
||||
if (!StringUtils.hasText(item.getNameZh())) {
|
||||
item.setNameZh(product.getNameZh());
|
||||
}
|
||||
if (!StringUtils.hasText(item.getSpec())) {
|
||||
item.setSpec(product.getSpec());
|
||||
}
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private void persistItems(Long quoteId, Long companyId, List<CrmQuoteItemPO> items) {
|
||||
for (CrmQuoteItemPO item : items) {
|
||||
item.setId(null);
|
||||
item.setQuoteId(quoteId);
|
||||
item.setCompanyId(companyId);
|
||||
quoteItemMapper.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal sumAmount(List<CrmQuoteItemPO> items) {
|
||||
return items.stream()
|
||||
.map(CrmQuoteItemPO::getAmount)
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private List<CrmQuoteItemPO> listItems(Long quoteId) {
|
||||
return quoteItemMapper.selectList(new LambdaQueryWrapper<CrmQuoteItemPO>()
|
||||
.eq(CrmQuoteItemPO::getQuoteId, quoteId)
|
||||
.orderByAsc(CrmQuoteItemPO::getLineNo));
|
||||
}
|
||||
|
||||
private CrmQuoteVO toDetailVo(CrmQuotePO quote) {
|
||||
CrmQuoteVO vo = toBriefVo(quote);
|
||||
CrmCustomerPO customer = customerMapper.selectById(quote.getCustomerId());
|
||||
if (customer != null) {
|
||||
vo.setCustomerName(customer.getName());
|
||||
}
|
||||
vo.setItems(listItems(quote.getId()).stream().map(item -> {
|
||||
CrmQuoteItemVO iv = new CrmQuoteItemVO();
|
||||
BeanCopyUtils.copyProperties(item, iv);
|
||||
return iv;
|
||||
}).toList());
|
||||
|
||||
CrmDocumentPO latestPi = documentMapper.selectOne(new LambdaQueryWrapper<CrmDocumentPO>()
|
||||
.eq(CrmDocumentPO::getCompanyId, quote.getCompanyId())
|
||||
.eq(CrmDocumentPO::getRefType, "quote")
|
||||
.eq(CrmDocumentPO::getRefId, quote.getId())
|
||||
.eq(CrmDocumentPO::getDocType, "pi")
|
||||
.eq(CrmDocumentPO::getIsLatest, 1)
|
||||
.last("LIMIT 1"));
|
||||
if (latestPi != null) {
|
||||
vo.setLatestPiFileId(latestPi.getFileId());
|
||||
vo.setLatestPiAccessUrl(sysFileService.resolveAccessUrl(latestPi.getFileId()));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private CrmQuoteVO toBriefVo(CrmQuotePO quote) {
|
||||
CrmQuoteVO vo = new CrmQuoteVO();
|
||||
BeanCopyUtils.copyProperties(quote, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private Map<Long, String> loadCustomerNames(Long companyId, Set<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return customerMapper.selectList(new LambdaQueryWrapper<CrmCustomerPO>()
|
||||
.eq(CrmCustomerPO::getCompanyId, companyId)
|
||||
.in(CrmCustomerPO::getId, ids))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(CrmCustomerPO::getId, CrmCustomerPO::getName, (a, b) -> a));
|
||||
}
|
||||
|
||||
private CrmCustomerPO requireCustomer(Long companyId, Long customerId) {
|
||||
CrmCustomerPO customer = customerMapper.selectById(customerId);
|
||||
if (customer == null || !companyId.equals(customer.getCompanyId())) {
|
||||
throw new BusinessException("客户不存在");
|
||||
}
|
||||
return customer;
|
||||
}
|
||||
|
||||
private CrmQuotePO requireOwned(Long id) {
|
||||
Long companyId = requireCompanyId();
|
||||
CrmQuotePO quote = this.getById(id);
|
||||
if (quote == null || !companyId.equals(quote.getCompanyId())) {
|
||||
throw new BusinessException("报价不存在");
|
||||
}
|
||||
return quote;
|
||||
}
|
||||
|
||||
private Long requireCompanyId() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (companyId == null) {
|
||||
throw new BusinessException("请先选择公司");
|
||||
}
|
||||
return companyId;
|
||||
}
|
||||
|
||||
private static String normalizeCurrency(String currency) {
|
||||
if (!StringUtils.hasText(currency)) {
|
||||
return "USD";
|
||||
}
|
||||
return currency.trim().toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static String trimToNull(String s) {
|
||||
if (!StringUtils.hasText(s)) {
|
||||
return null;
|
||||
}
|
||||
return s.trim();
|
||||
}
|
||||
|
||||
private static String firstNonBlank(String a, String b) {
|
||||
if (StringUtils.hasText(a)) {
|
||||
return a.trim();
|
||||
}
|
||||
if (StringUtils.hasText(b)) {
|
||||
return b.trim();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.FileCategory;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.support.FileStorageSupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.support.StoragePathBuilder;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileHashUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 业务生成文件写入 sys_file(复用存储路径规则)。
|
||||
*/
|
||||
@Service
|
||||
public class CrmGeneratedFileService {
|
||||
|
||||
private final SysFileMapper sysFileMapper;
|
||||
private final FileStorageSupport fileStorageSupport;
|
||||
private final StoragePathBuilder storagePathBuilder;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public CrmGeneratedFileService(SysFileMapper sysFileMapper,
|
||||
FileStorageSupport fileStorageSupport,
|
||||
StoragePathBuilder storagePathBuilder,
|
||||
CurrentUserContext currentUserContext) {
|
||||
this.sysFileMapper = sysFileMapper;
|
||||
this.fileStorageSupport = fileStorageSupport;
|
||||
this.storagePathBuilder = storagePathBuilder;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public SysFilePO saveBytes(Long companyId, String filename, String mimeType, byte[] content) {
|
||||
String hash = FileHashUtils.calculateFileHash(content);
|
||||
LambdaQueryWrapper<SysFilePO> w = new LambdaQueryWrapper<>();
|
||||
w.eq(SysFilePO::getCompanyId, companyId)
|
||||
.eq(SysFilePO::getFileHash, hash)
|
||||
.isNull(SysFilePO::getDeleteTime)
|
||||
.last("LIMIT 1");
|
||||
SysFilePO existing = sysFileMapper.selectOne(w);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
String relative = storagePathBuilder.build(filename, hash, FileCategory.FILE);
|
||||
String storagePath = fileStorageSupport.persist(relative, new ByteArrayInputStream(content));
|
||||
String ext = "";
|
||||
int dot = filename.lastIndexOf('.');
|
||||
if (dot >= 0) {
|
||||
ext = filename.substring(dot + 1).toLowerCase();
|
||||
}
|
||||
SysFilePO po = new SysFilePO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setStorageType(fileStorageSupport.storageType());
|
||||
po.setStoragePath(storagePath);
|
||||
po.setFilename(filename);
|
||||
po.setFileFormat(ext);
|
||||
po.setMimeType(mimeType);
|
||||
po.setFileSize((long) content.length);
|
||||
po.setFileHash(hash);
|
||||
po.setCategory(FileCategory.FILE);
|
||||
po.setUploadBy(currentUserContext.getCurrentUserId());
|
||||
po.setUploadTime(LocalDateTime.now());
|
||||
sysFileMapper.insert(po);
|
||||
return po;
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.support;
|
||||
|
||||
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 形式发票 PI → PDF(英文排版,避免中文字体依赖)。
|
||||
*/
|
||||
@Component
|
||||
public class CrmPiPdfRenderer {
|
||||
|
||||
public record Party(String name, String address, String country, String phone, String email) {
|
||||
}
|
||||
|
||||
public record Line(int lineNo, String code, String nameEn, String spec, String unit,
|
||||
BigDecimal qty, BigDecimal unitPrice, BigDecimal amount) {
|
||||
}
|
||||
|
||||
public record PiModel(
|
||||
String docTitle,
|
||||
String quoteNo,
|
||||
String quoteDate,
|
||||
String validUntil,
|
||||
String currency,
|
||||
String incoterm,
|
||||
String paymentTerms,
|
||||
String remark,
|
||||
Party seller,
|
||||
Party buyer,
|
||||
List<Line> lines,
|
||||
BigDecimal totalAmount
|
||||
) {
|
||||
}
|
||||
|
||||
public byte[] render(PiModel model) {
|
||||
String html = buildHtml(model);
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
PdfRendererBuilder builder = new PdfRendererBuilder();
|
||||
builder.useFastMode();
|
||||
builder.withHtmlContent(html, null);
|
||||
builder.toStream(out);
|
||||
builder.run();
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("生成 PI PDF 失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String buildHtml(PiModel m) {
|
||||
StringBuilder rows = new StringBuilder();
|
||||
for (Line line : m.lines()) {
|
||||
rows.append("<tr>")
|
||||
.append("<td>").append(line.lineNo()).append("</td>")
|
||||
.append("<td>").append(esc(line.code())).append("</td>")
|
||||
.append("<td>").append(esc(line.nameEn())).append("</td>")
|
||||
.append("<td>").append(esc(line.spec())).append("</td>")
|
||||
.append("<td>").append(esc(line.unit())).append("</td>")
|
||||
.append("<td class='num'>").append(fmt(line.qty(), 3)).append("</td>")
|
||||
.append("<td class='num'>").append(fmt(line.unitPrice(), 4)).append("</td>")
|
||||
.append("<td class='num'>").append(fmt(line.amount(), 2)).append("</td>")
|
||||
.append("</tr>");
|
||||
}
|
||||
Party s = m.seller() != null ? m.seller() : new Party("", "", "", "", "");
|
||||
Party b = m.buyer() != null ? m.buyer() : new Party("", "", "", "", "");
|
||||
StringBuilder html = new StringBuilder();
|
||||
html.append("<!DOCTYPE html><html><head><meta charset=\"UTF-8\"/>")
|
||||
.append("<style>")
|
||||
.append("@page { size: A4; margin: 18mm; }")
|
||||
.append("body { font-family: Helvetica, Arial, sans-serif; font-size: 11px; color: #222; }")
|
||||
.append("h1 { font-size: 18px; margin: 0 0 8px 0; letter-spacing: 1px; }")
|
||||
.append(".meta td { padding: 2px 8px 2px 0; vertical-align: top; }")
|
||||
.append(".box { border: 1px solid #ccc; padding: 8px; width: 48%; }")
|
||||
.append(".row { width: 100%; margin-bottom: 12px; }")
|
||||
.append(".row td { vertical-align: top; }")
|
||||
.append("table.items { width: 100%; border-collapse: collapse; margin-top: 10px; }")
|
||||
.append("table.items th, table.items td { border: 1px solid #999; padding: 5px 6px; }")
|
||||
.append("table.items th { background: #f2f2f2; text-align: left; }")
|
||||
.append(".num { text-align: right; white-space: nowrap; }")
|
||||
.append(".total { margin-top: 10px; text-align: right; font-size: 13px; font-weight: bold; }")
|
||||
.append(".muted { color: #666; font-size: 10px; }")
|
||||
.append("</style></head><body>")
|
||||
.append("<h1>").append(esc(m.docTitle())).append("</h1>")
|
||||
.append("<table class=\"meta\">")
|
||||
.append("<tr><td><b>No.</b></td><td>").append(esc(m.quoteNo())).append("</td>")
|
||||
.append("<td><b>Date</b></td><td>").append(esc(m.quoteDate())).append("</td></tr>")
|
||||
.append("<tr><td><b>Valid Until</b></td><td>").append(esc(dash(m.validUntil()))).append("</td>")
|
||||
.append("<td><b>Currency</b></td><td>").append(esc(m.currency())).append("</td></tr>")
|
||||
.append("<tr><td><b>Incoterm</b></td><td>").append(esc(dash(m.incoterm()))).append("</td>")
|
||||
.append("<td><b>Payment</b></td><td>").append(esc(dash(m.paymentTerms()))).append("</td></tr>")
|
||||
.append("</table>")
|
||||
.append("<table class=\"row\"><tr>")
|
||||
.append("<td class=\"box\"><b>Seller</b><br/>").append(esc(s.name())).append("<br/>")
|
||||
.append(esc(s.address())).append("<br/>").append(esc(s.country())).append("<br/>")
|
||||
.append(esc(s.phone())).append(" ").append(esc(s.email())).append("</td>")
|
||||
.append("<td style=\"width:4%\"></td>")
|
||||
.append("<td class=\"box\"><b>Buyer</b><br/>").append(esc(b.name())).append("<br/>")
|
||||
.append(esc(b.address())).append("<br/>").append(esc(b.country())).append("<br/>")
|
||||
.append(esc(b.phone())).append(" ").append(esc(b.email())).append("</td>")
|
||||
.append("</tr></table>")
|
||||
.append("<table class=\"items\"><thead><tr>")
|
||||
.append("<th>#</th><th>Code</th><th>Description</th><th>Spec</th>")
|
||||
.append("<th>Unit</th><th>Qty</th><th>Unit Price</th><th>Amount</th>")
|
||||
.append("</tr></thead><tbody>")
|
||||
.append(rows)
|
||||
.append("</tbody></table>")
|
||||
.append("<div class=\"total\">Total ").append(esc(m.currency())).append(" ")
|
||||
.append(fmt(m.totalAmount(), 2)).append("</div>")
|
||||
.append("<p class=\"muted\">Remark: ").append(esc(dash(m.remark()))).append("</p>")
|
||||
.append("</body></html>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String fmt(BigDecimal v, int scale) {
|
||||
if (v == null) {
|
||||
return "-";
|
||||
}
|
||||
return v.setScale(scale, RoundingMode.HALF_UP).toPlainString();
|
||||
}
|
||||
|
||||
private static String dash(String s) {
|
||||
return s == null || s.isBlank() ? "-" : s;
|
||||
}
|
||||
|
||||
private static String esc(String s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
}
|
||||
return s.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace("\"", """);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface CrmSeqMapper extends BaseMapper<CrmSeqPO> {
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.support;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 单号发号器实体。 */
|
||||
@Data
|
||||
@TableName("crm_seq")
|
||||
public class CrmSeqPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("biz_type")
|
||||
private String bizType;
|
||||
|
||||
@TableField("year")
|
||||
private Integer year;
|
||||
|
||||
@TableField("next_val")
|
||||
private Integer nextVal;
|
||||
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.crm.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Year;
|
||||
|
||||
/**
|
||||
* 公司+年维度发号:Qyyyy###### / SHyyyy######。
|
||||
*/
|
||||
@Service
|
||||
public class CrmSeqService {
|
||||
|
||||
public static final String BIZ_QUOTE = "quote";
|
||||
public static final String BIZ_SHIPMENT = "shipment";
|
||||
|
||||
private final CrmSeqMapper crmSeqMapper;
|
||||
|
||||
public CrmSeqService(CrmSeqMapper crmSeqMapper) {
|
||||
this.crmSeqMapper = crmSeqMapper;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String nextQuoteNo(Long companyId) {
|
||||
int seq = nextVal(companyId, BIZ_QUOTE);
|
||||
return String.format("Q%d%06d", Year.now().getValue(), seq);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String nextShipmentNo(Long companyId) {
|
||||
int seq = nextVal(companyId, BIZ_SHIPMENT);
|
||||
return String.format("SH%d%06d", Year.now().getValue(), seq);
|
||||
}
|
||||
|
||||
private int nextVal(Long companyId, String bizType) {
|
||||
int year = Year.now().getValue();
|
||||
LambdaQueryWrapper<CrmSeqPO> q = new LambdaQueryWrapper<>();
|
||||
q.eq(CrmSeqPO::getCompanyId, companyId)
|
||||
.eq(CrmSeqPO::getBizType, bizType)
|
||||
.eq(CrmSeqPO::getYear, year)
|
||||
.last("FOR UPDATE");
|
||||
CrmSeqPO row = crmSeqMapper.selectOne(q);
|
||||
if (row == null) {
|
||||
row = new CrmSeqPO();
|
||||
row.setCompanyId(companyId);
|
||||
row.setBizType(bizType);
|
||||
row.setYear(year);
|
||||
row.setNextVal(2);
|
||||
crmSeqMapper.insert(row);
|
||||
return 1;
|
||||
}
|
||||
int current = row.getNextVal() == null ? 1 : row.getNextVal();
|
||||
row.setNextVal(current + 1);
|
||||
crmSeqMapper.updateById(row);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -73,10 +73,23 @@ public class FileStorageSupport {
|
||||
* @param relativePath OSS 为 app/env/module/yyyy/hash.ext;本地为 uploads/...
|
||||
*/
|
||||
public String persist(String relativePath, MultipartFile file) {
|
||||
try {
|
||||
return persist(relativePath, file.getInputStream());
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("读取上传文件失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 由业务生成的字节流落库(如单证 PDF)。
|
||||
*/
|
||||
public String persist(String relativePath, java.io.InputStream inputStream) {
|
||||
if (isOssStorage()) {
|
||||
ensureOssAvailable();
|
||||
try {
|
||||
boolean ok = ossService.uploadFile(relativePath, file.getInputStream());
|
||||
boolean ok = ossService.uploadFile(relativePath, inputStream);
|
||||
if (!ok) {
|
||||
throw new BusinessException("文件上传到对象存储失败");
|
||||
}
|
||||
@@ -91,7 +104,7 @@ public class FileStorageSupport {
|
||||
try {
|
||||
java.nio.file.Path path = java.nio.file.Paths.get(localPath);
|
||||
java.nio.file.Files.createDirectories(path.getParent());
|
||||
java.nio.file.Files.copy(file.getInputStream(), path);
|
||||
java.nio.file.Files.copy(inputStream, path);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("文件保存到本地失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -29,6 +29,21 @@ public class FileHashUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算字节数组的 SHA-256。
|
||||
*/
|
||||
public static String calculateFileHash(byte[] content) {
|
||||
if (content == null) {
|
||||
throw new IllegalArgumentException("content 不能为空");
|
||||
}
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
return bytesToHex(digest.digest(content));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("计算哈希失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算文件的SHA-256哈希值
|
||||
*
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
-- CRM Phase1 报价/单证资料菜单权限(幂等)
|
||||
|
||||
-- ------------------------------------------------
|
||||
-- CRM Phase1:报价 / 单证资料
|
||||
-- ------------------------------------------------
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6300, (SELECT id FROM `sys_permission` WHERE `code` = 'crm' LIMIT 1), 'crm:quote', '报价', 'module', 1, '', 30
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6300 OR `code` = 'crm:quote');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6301, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:read', '查看', 'api', 1, '', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6301 OR `code` = 'crm:quote:read');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6302, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:create', '创建', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6302 OR `code` = 'crm:quote:create');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6303, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:update', '更新', 'api', 1, '', 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6303 OR `code` = 'crm:quote:update');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6304, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:delete', '删除', 'api', 1, '', 4
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6304 OR `code` = 'crm:quote:delete');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6305, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:status', '改状态', 'api', 1, '', 5
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6305 OR `code` = 'crm:quote:status');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6306, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:export', '导出PI', 'api', 1, '', 6
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6306 OR `code` = 'crm:quote:export');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6400, (SELECT id FROM `sys_permission` WHERE `code` = 'crm' LIMIT 1), 'crm:profile', '单证资料', 'module', 1, '', 90
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6400 OR `code` = 'crm:profile');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6401, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:profile' LIMIT 1), 'crm:profile:read', '查看', 'api', 1, '', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6401 OR `code` = 'crm:profile:read');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6402, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:profile' LIMIT 1), 'crm:profile:update', '更新', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6402 OR `code` = 'crm:profile:update');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14103, (SELECT id FROM `sys_menu` WHERE `id` = 14100 OR `route_name` = 'CrmCatalog' LIMIT 1), 0, 'CrmQuote', '报价', '/crm/quote', '/crm/quote/index', '', 'lucide:file-text', 'menu', 1, 1, 1, 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14103 OR `route_name` = 'CrmQuote');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14104, (SELECT id FROM `sys_menu` WHERE `id` = 14100 OR `route_name` = 'CrmCatalog' LIMIT 1), 0, 'CrmProfile', '单证资料', '/crm/profile', '/crm/profile/index', '', 'lucide:building', 'menu', 1, 1, 0, 9
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14104 OR `route_name` = 'CrmProfile');
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'crm:quote:%' WHERE m.route_name = 'CrmQuote';
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'crm:profile:%' WHERE m.route_name = 'CrmProfile';
|
||||
@@ -563,3 +563,61 @@ SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'crm:
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'crm:product:%' WHERE m.route_name = 'CrmProduct';
|
||||
|
||||
-- ------------------------------------------------
|
||||
-- CRM Phase1:报价 / 单证资料
|
||||
-- ------------------------------------------------
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6300, (SELECT id FROM `sys_permission` WHERE `code` = 'crm' LIMIT 1), 'crm:quote', '报价', 'module', 1, '', 30
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6300 OR `code` = 'crm:quote');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6301, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:read', '查看', 'api', 1, '', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6301 OR `code` = 'crm:quote:read');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6302, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:create', '创建', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6302 OR `code` = 'crm:quote:create');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6303, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:update', '更新', 'api', 1, '', 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6303 OR `code` = 'crm:quote:update');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6304, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:delete', '删除', 'api', 1, '', 4
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6304 OR `code` = 'crm:quote:delete');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6305, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:status', '改状态', 'api', 1, '', 5
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6305 OR `code` = 'crm:quote:status');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6306, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:quote' LIMIT 1), 'crm:quote:export', '导出PI', 'api', 1, '', 6
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6306 OR `code` = 'crm:quote:export');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6400, (SELECT id FROM `sys_permission` WHERE `code` = 'crm' LIMIT 1), 'crm:profile', '单证资料', 'module', 1, '', 90
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6400 OR `code` = 'crm:profile');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6401, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:profile' LIMIT 1), 'crm:profile:read', '查看', 'api', 1, '', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6401 OR `code` = 'crm:profile:read');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 6402, (SELECT id FROM `sys_permission` WHERE `code` = 'crm:profile' LIMIT 1), 'crm:profile:update', '更新', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 6402 OR `code` = 'crm:profile:update');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14103, (SELECT id FROM `sys_menu` WHERE `id` = 14100 OR `route_name` = 'CrmCatalog' LIMIT 1), 0, 'CrmQuote', '报价', '/crm/quote', '/crm/quote/index', '', 'lucide:file-text', 'menu', 1, 1, 1, 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14103 OR `route_name` = 'CrmQuote');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14104, (SELECT id FROM `sys_menu` WHERE `id` = 14100 OR `route_name` = 'CrmCatalog' LIMIT 1), 0, 'CrmProfile', '单证资料', '/crm/profile', '/crm/profile/index', '', 'lucide:building', 'menu', 1, 1, 0, 9
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14104 OR `route_name` = 'CrmProfile');
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'crm:quote:%' WHERE m.route_name = 'CrmQuote';
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'crm:profile:%' WHERE m.route_name = 'CrmProfile';
|
||||
|
||||
Reference in New Issue
Block a user