Showing
15 changed files
with
1106 additions
and
0 deletions
| @@ -2242,3 +2242,53 @@ CREATE TABLE `procurement_plan_replenish_line` | @@ -2242,3 +2242,53 @@ CREATE TABLE `procurement_plan_replenish_line` | ||
| 2242 | PRIMARY KEY (`id`), | 2242 | PRIMARY KEY (`id`), |
| 2243 | KEY `idx_pp_replenish_line_main` (`procurement_plan_replenish_id`) | 2243 | KEY `idx_pp_replenish_line_main` (`procurement_plan_replenish_id`) |
| 2244 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='采购计划补单明细表'; | 2244 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='采购计划补单明细表'; |
| 2245 | + | ||
| 2246 | + | ||
| 2247 | +CREATE TABLE domestic_plan_summary | ||
| 2248 | +( | ||
| 2249 | + id VARCHAR(32) NOT NULL COMMENT '主键ID', | ||
| 2250 | + code VARCHAR(32) NOT NULL COMMENT '编号', | ||
| 2251 | + summary_date DATE NOT NULL COMMENT '汇总生成日期', | ||
| 2252 | + total_quantity DECIMAL(18, 4) NOT NULL DEFAULT 0 COMMENT '合计(数量合计 吨)', | ||
| 2253 | + weighted_avg_coordination DECIMAL(18, 6) NOT NULL DEFAULT 0 COMMENT '吨超协加权平均 Σ(吨超协*数量)/Σ数量', | ||
| 2254 | + create_by_id VARCHAR(32) DEFAULT NULL COMMENT '创建人ID', | ||
| 2255 | + create_by VARCHAR(64) DEFAULT NULL COMMENT '创建人', | ||
| 2256 | + create_time DATETIME NOT NULL COMMENT '创建时间', | ||
| 2257 | + update_by_id VARCHAR(32) DEFAULT NULL COMMENT '修改人ID', | ||
| 2258 | + update_by VARCHAR(64) DEFAULT NULL COMMENT '修改人', | ||
| 2259 | + update_time DATETIME DEFAULT NULL COMMENT '修改时间', | ||
| 2260 | + PRIMARY KEY (id), | ||
| 2261 | + UNIQUE KEY uk_dps_code (code), | ||
| 2262 | + KEY idx_dps_summary_date (summary_date) | ||
| 2263 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='内贸计划明细汇总主表'; | ||
| 2264 | + | ||
| 2265 | +CREATE TABLE domestic_plan_summary_detail | ||
| 2266 | +( | ||
| 2267 | + id VARCHAR(32) NOT NULL COMMENT '主键ID', | ||
| 2268 | + summary_id VARCHAR(32) NOT NULL COMMENT '汇总主表ID', | ||
| 2269 | + order_no INT(11) NOT NULL DEFAULT 0 COMMENT '排序号(审核通过时间 + 明细行号 最终排序)', | ||
| 2270 | + plan_create_date DATE NOT NULL COMMENT '计划创建日期', | ||
| 2271 | + purchase_dept_id VARCHAR(32) DEFAULT NULL COMMENT '采购处ID', | ||
| 2272 | + supplier_name VARCHAR(200) NOT NULL COMMENT '客户名称(供应商简称)', | ||
| 2273 | + plan_id VARCHAR(32) NOT NULL COMMENT '原采购计划ID', | ||
| 2274 | + plan_code VARCHAR(64) NOT NULL COMMENT '订单编号(原计划单编号)', | ||
| 2275 | + product_id VARCHAR(32) DEFAULT NULL COMMENT '品种ID', | ||
| 2276 | + quantity DECIMAL(18, 4) NOT NULL DEFAULT 0 COMMENT '数量(吨)', | ||
| 2277 | + actual_purchase_price DECIMAL(18, 4) NOT NULL DEFAULT 0 COMMENT '实际采购价(元/吨)', | ||
| 2278 | + shipping_cost DECIMAL(18, 4) NOT NULL DEFAULT 0 COMMENT '运费(元/吨)', | ||
| 2279 | + price_with_shipping DECIMAL(18, 4) NOT NULL DEFAULT 0 COMMENT '单价(含运) = 实际采购价 + 运费', | ||
| 2280 | + workshop_id VARCHAR(32) DEFAULT NULL COMMENT '分厂ID', | ||
| 2281 | + coordination_range DECIMAL(18, 6) NOT NULL DEFAULT 0 COMMENT '吨超协(协调幅度)', | ||
| 2282 | + remark_flag VARCHAR(64) DEFAULT NULL COMMENT '备注标识 空/买断/补单/"买断 补单"(同时有)', | ||
| 2283 | + plan_line_id VARCHAR(32) DEFAULT NULL COMMENT '原计划明细行ID(便于追溯)', | ||
| 2284 | + approval_pass_Time DATETIME DEFAULT NULL COMMENT '审核时间', | ||
| 2285 | + create_by_id VARCHAR(32) DEFAULT NULL COMMENT '创建人ID', | ||
| 2286 | + create_by VARCHAR(64) DEFAULT NULL COMMENT '创建人', | ||
| 2287 | + create_time DATETIME NOT NULL COMMENT '创建时间', | ||
| 2288 | + update_by_id VARCHAR(32) DEFAULT NULL COMMENT '修改人ID', | ||
| 2289 | + update_by VARCHAR(64) DEFAULT NULL COMMENT '修改人', | ||
| 2290 | + update_time DATETIME DEFAULT NULL COMMENT '修改时间', | ||
| 2291 | + PRIMARY KEY (id), | ||
| 2292 | + KEY idx_dpsd_summary_id (summary_id), | ||
| 2293 | + KEY idx_dpsd_plan_id (plan_id) | ||
| 2294 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='内贸计划明细汇总明细表'; |
xingyun-sc/src/main/java/com/lframework/xingyun/sc/bo/procurement/GetDomesticPlanSummaryBo.java
0 → 100644
| 1 | +package com.lframework.xingyun.sc.bo.procurement; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 4 | +import com.lframework.starter.common.constants.StringPool; | ||
| 5 | +import com.lframework.starter.web.core.bo.BaseBo; | ||
| 6 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary; | ||
| 7 | +import io.swagger.annotations.ApiModelProperty; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.time.LocalDate; | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +@Data | ||
| 15 | +public class GetDomesticPlanSummaryBo extends BaseBo<DomesticPlanSummary> { | ||
| 16 | + | ||
| 17 | + @ApiModelProperty("ID") | ||
| 18 | + private String id; | ||
| 19 | + | ||
| 20 | + @ApiModelProperty("汇总编号") | ||
| 21 | + private String code; | ||
| 22 | + | ||
| 23 | + @ApiModelProperty("汇总日期") | ||
| 24 | + @JsonFormat(pattern = StringPool.DATE_PATTERN) | ||
| 25 | + private LocalDate summaryDate; | ||
| 26 | + | ||
| 27 | + @ApiModelProperty("总数量") | ||
| 28 | + private BigDecimal totalQuantity; | ||
| 29 | + | ||
| 30 | + @ApiModelProperty("加权平均协调幅度") | ||
| 31 | + private BigDecimal weightedAvgCoordination; | ||
| 32 | + | ||
| 33 | + @ApiModelProperty("明细信息") | ||
| 34 | + private List<GetDomesticPlanSummaryDetailBo> details; | ||
| 35 | + | ||
| 36 | + @ApiModelProperty("创建人") | ||
| 37 | + private String createBy; | ||
| 38 | + | ||
| 39 | + @ApiModelProperty("创建时间") | ||
| 40 | + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN) | ||
| 41 | + private LocalDateTime createTime; | ||
| 42 | + | ||
| 43 | + public GetDomesticPlanSummaryBo() { | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public GetDomesticPlanSummaryBo(DomesticPlanSummary dto) { | ||
| 47 | + super(dto); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public BaseBo<DomesticPlanSummary> convert(DomesticPlanSummary dto) { | ||
| 52 | + return super.convert(dto); | ||
| 53 | + } | ||
| 54 | +} |
| 1 | +package com.lframework.xingyun.sc.bo.procurement; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 4 | +import com.lframework.starter.common.constants.StringPool; | ||
| 5 | +import com.lframework.starter.web.core.bo.BaseBo; | ||
| 6 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummaryDetail; | ||
| 7 | +import io.swagger.annotations.ApiModelProperty; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.time.LocalDate; | ||
| 11 | + | ||
| 12 | +@Data | ||
| 13 | +public class GetDomesticPlanSummaryDetailBo extends BaseBo<DomesticPlanSummaryDetail> { | ||
| 14 | + | ||
| 15 | + @ApiModelProperty("序号") | ||
| 16 | + private Integer seq; | ||
| 17 | + | ||
| 18 | + @ApiModelProperty("计划创建日期") | ||
| 19 | + @JsonFormat(pattern = StringPool.DATE_PATTERN) | ||
| 20 | + private LocalDate planCreateDate; | ||
| 21 | + | ||
| 22 | + @ApiModelProperty("采购处") | ||
| 23 | + private String purchaseDeptName; | ||
| 24 | + | ||
| 25 | + @ApiModelProperty("客户名称") | ||
| 26 | + private String supplierName; | ||
| 27 | + | ||
| 28 | + @ApiModelProperty("订单编号") | ||
| 29 | + private String planCode; | ||
| 30 | + | ||
| 31 | + @ApiModelProperty("品种") | ||
| 32 | + private String productName; | ||
| 33 | + | ||
| 34 | + @ApiModelProperty("数量") | ||
| 35 | + private BigDecimal quantity; | ||
| 36 | + | ||
| 37 | + @ApiModelProperty("单价(含运)") | ||
| 38 | + private BigDecimal priceWithShipping; | ||
| 39 | + | ||
| 40 | + @ApiModelProperty("分厂") | ||
| 41 | + private String workshopName; | ||
| 42 | + | ||
| 43 | + @ApiModelProperty("吨超协(协调幅度)") | ||
| 44 | + private BigDecimal coordinationRange; | ||
| 45 | + | ||
| 46 | + @ApiModelProperty("与平均对比 吨超协 - 吨超协*数量加权核算/总数量 结果为正标红") | ||
| 47 | + private BigDecimal compareWithAvg; | ||
| 48 | + | ||
| 49 | + @ApiModelProperty("备注 有买断显示买断 有补单显示补单 同时有显示买断 补单") | ||
| 50 | + private String remarkLabel; | ||
| 51 | + | ||
| 52 | + public GetDomesticPlanSummaryDetailBo() { | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public GetDomesticPlanSummaryDetailBo(DomesticPlanSummaryDetail dto) { | ||
| 56 | + super(dto); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public BaseBo<DomesticPlanSummaryDetail> convert(DomesticPlanSummaryDetail dto) { | ||
| 61 | + return super.convert(dto); | ||
| 62 | + } | ||
| 63 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.controller.summary; | ||
| 2 | + | ||
| 3 | +import com.lframework.starter.common.constants.StringPool; | ||
| 4 | +import com.lframework.starter.web.core.annotations.security.HasPermission; | ||
| 5 | +import com.lframework.starter.web.core.components.resp.InvokeResult; | ||
| 6 | +import com.lframework.starter.web.core.components.resp.InvokeResultBuilder; | ||
| 7 | +import com.lframework.starter.web.core.components.resp.PageResult; | ||
| 8 | +import com.lframework.starter.web.core.controller.DefaultBaseController; | ||
| 9 | +import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryBo; | ||
| 10 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary; | ||
| 11 | +import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryService; | ||
| 12 | +import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo; | ||
| 13 | +import io.swagger.annotations.Api; | ||
| 14 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 15 | +import io.swagger.annotations.ApiOperation; | ||
| 16 | +import javax.validation.Valid; | ||
| 17 | +import javax.validation.constraints.NotBlank; | ||
| 18 | +import lombok.extern.slf4j.Slf4j; | ||
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 21 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 22 | +import org.springframework.validation.annotation.Validated; | ||
| 23 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 24 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 25 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 26 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 27 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 28 | +import org.springframework.web.bind.annotation.RestController; | ||
| 29 | + | ||
| 30 | +import java.time.LocalDate; | ||
| 31 | + | ||
| 32 | +@Api(tags = "内贸计划明细汇总表管理") | ||
| 33 | +@Slf4j | ||
| 34 | +@Validated | ||
| 35 | +@RestController | ||
| 36 | +@RequestMapping("/procurement/plan/summary") | ||
| 37 | +public class DomesticPlanSummaryController extends DefaultBaseController { | ||
| 38 | + | ||
| 39 | + @Autowired | ||
| 40 | + private DomesticPlanSummaryService domesticPlanSummaryService; | ||
| 41 | + | ||
| 42 | + @ApiOperation("分页查询内贸计划明细汇总表列表") | ||
| 43 | + @HasPermission({"plan-manage:domestic-plan-summary:query"}) | ||
| 44 | + @GetMapping("/query") | ||
| 45 | + public InvokeResult<PageResult<DomesticPlanSummary>> query(@Valid QueryDomesticPlanSummaryVo vo) { | ||
| 46 | + PageResult<DomesticPlanSummary> result = domesticPlanSummaryService.query(getPageIndex(vo), getPageSize(vo), vo); | ||
| 47 | + return InvokeResultBuilder.success(result); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @ApiOperation("查询内贸计划明细汇总表详情") | ||
| 51 | + @ApiImplicitParam(value = "ID", name = "id", paramType = "path", required = true) | ||
| 52 | + @HasPermission({"plan-manage:domestic-plan-summary:query","plan-manage:domestic-plan-summary:view"}) | ||
| 53 | + @GetMapping("") | ||
| 54 | + public InvokeResult<GetDomesticPlanSummaryBo> findById(@NotBlank(message = "ID不能为空!") String id) { | ||
| 55 | + GetDomesticPlanSummaryBo result = domesticPlanSummaryService.findDetail(id); | ||
| 56 | + return InvokeResultBuilder.success(result); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @ApiOperation("触发生成内贸计划明细汇总表(补跑)") | ||
| 60 | + @ApiImplicitParam(value = "生成日期(yyyy-MM-dd 默认当天)", name = "date", paramType = "query", required = false) | ||
| 61 | + @HasPermission({"plan-manage:domestic-plan-summary:add"}) | ||
| 62 | + @PostMapping("/generate") | ||
| 63 | + public InvokeResult<String> generate( | ||
| 64 | + @RequestParam(required = false) @DateTimeFormat(pattern = StringPool.DATE_PATTERN) LocalDate date) { | ||
| 65 | + String id = domesticPlanSummaryService.generateDailySummary(date); | ||
| 66 | + return InvokeResultBuilder.success(id); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Scheduled(cron = "0 0 1 * * ?") | ||
| 70 | + @ApiOperation(hidden = true, value = "定时生成前一天的内贸计划明细汇总表 每天1点") | ||
| 71 | + public void scheduledGenerateDailySummary() { | ||
| 72 | + try { | ||
| 73 | + log.info("[内贸计划明细汇总表] 定时任务开始执行..."); | ||
| 74 | + String id = domesticPlanSummaryService.generateDailySummary(LocalDate.now()); | ||
| 75 | + log.info("[内贸计划明细汇总表] 定时任务执行完毕,生成汇总表ID: {}", id); | ||
| 76 | + } catch (Exception e) { | ||
| 77 | + log.error("[内贸计划明细汇总表] 定时任务执行失败!", e); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.entity.summary; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.FieldFill; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import com.lframework.starter.web.core.dto.BaseDto; | ||
| 7 | +import com.lframework.starter.web.core.entity.BaseEntity; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.time.LocalDate; | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Data | ||
| 14 | +@TableName("domestic_plan_summary") | ||
| 15 | +public class DomesticPlanSummary extends BaseEntity implements BaseDto { | ||
| 16 | + | ||
| 17 | + private static final long serialVersionUID = 1L; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 主键ID | ||
| 21 | + */ | ||
| 22 | + private String id; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 编号 XT260001 (XT+年份后2位+4位流水 每年重置) | ||
| 26 | + */ | ||
| 27 | + private String code; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 汇总生成日期(年月日) | ||
| 31 | + */ | ||
| 32 | + private LocalDate summaryDate; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 合计(数量合计 吨) | ||
| 36 | + */ | ||
| 37 | + private BigDecimal totalQuantity; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 吨超协加权平均 Σ(吨超协*数量)/Σ数量 | ||
| 41 | + */ | ||
| 42 | + private BigDecimal weightedAvgCoordination; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 创建人ID | ||
| 46 | + */ | ||
| 47 | + @TableField(fill = FieldFill.INSERT) | ||
| 48 | + private String createById; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 创建人 | ||
| 52 | + */ | ||
| 53 | + @TableField(fill = FieldFill.INSERT) | ||
| 54 | + private String createBy; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 创建时间 | ||
| 58 | + */ | ||
| 59 | + @TableField(fill = FieldFill.INSERT) | ||
| 60 | + private LocalDateTime createTime; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 修改人ID | ||
| 64 | + */ | ||
| 65 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 66 | + private String updateById; | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 修改人 | ||
| 70 | + */ | ||
| 71 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 72 | + private String updateBy; | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 修改时间 | ||
| 76 | + */ | ||
| 77 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 78 | + private LocalDateTime updateTime; | ||
| 79 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.entity.summary; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.FieldFill; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | +import com.lframework.starter.web.core.dto.BaseDto; | ||
| 7 | +import com.lframework.starter.web.core.entity.BaseEntity; | ||
| 8 | +import lombok.Data; | ||
| 9 | +import java.math.BigDecimal; | ||
| 10 | +import java.time.LocalDate; | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Data | ||
| 14 | +@TableName("domestic_plan_summary_detail") | ||
| 15 | +public class DomesticPlanSummaryDetail extends BaseEntity implements BaseDto { | ||
| 16 | + | ||
| 17 | + private static final long serialVersionUID = 1L; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 主键ID | ||
| 21 | + */ | ||
| 22 | + private String id; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 汇总主表ID | ||
| 26 | + */ | ||
| 27 | + private String summaryId; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 排序号(审核通过时间 + 明细行号 最终排序) | ||
| 31 | + */ | ||
| 32 | + private Integer orderNo; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 计划创建日期(年-月-日) | ||
| 36 | + */ | ||
| 37 | + private LocalDate planCreateDate; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 采购处ID | ||
| 41 | + */ | ||
| 42 | + private String purchaseDeptId; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 采购处名称(冗余) | ||
| 46 | + */ | ||
| 47 | + @TableField(exist = false) | ||
| 48 | + private String purchaseDeptName; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 客户名称(供应商简称) | ||
| 52 | + */ | ||
| 53 | + private String supplierName; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 原采购计划ID | ||
| 57 | + */ | ||
| 58 | + private String planId; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 订单编号(原计划单编号) | ||
| 62 | + */ | ||
| 63 | + private String planCode; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 品种ID | ||
| 67 | + */ | ||
| 68 | + private String productId; | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 品种名称(冗余) | ||
| 72 | + */ | ||
| 73 | + @TableField(exist = false) | ||
| 74 | + private String productName; | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 数量(吨) | ||
| 78 | + */ | ||
| 79 | + private BigDecimal quantity; | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * 实际采购价(元/吨) | ||
| 83 | + */ | ||
| 84 | + private BigDecimal actualPurchasePrice; | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 运费(元/吨) | ||
| 88 | + */ | ||
| 89 | + private BigDecimal shippingCost; | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * 单价(含运) = 实际采购价 + 运费 | ||
| 93 | + */ | ||
| 94 | + private BigDecimal priceWithShipping; | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * 分厂ID | ||
| 98 | + */ | ||
| 99 | + private String workshopId; | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * 分厂名称(冗余) | ||
| 103 | + */ | ||
| 104 | + @TableField(exist = false) | ||
| 105 | + private String workshopName; | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 吨超协(协调幅度) | ||
| 109 | + */ | ||
| 110 | + private BigDecimal coordinationRange; | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * 备注标识 空/买断/补单/"买断 补单"(同时有) | ||
| 114 | + */ | ||
| 115 | + private String remarkFlag; | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * 原计划明细行ID(便于追溯) | ||
| 119 | + */ | ||
| 120 | + private String planLineId; | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 原计划审核通过时间(用于全局排序) | ||
| 124 | + */ | ||
| 125 | + private LocalDateTime approvalPassTime; | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 创建人ID | ||
| 129 | + */ | ||
| 130 | + @TableField(fill = FieldFill.INSERT) | ||
| 131 | + private String createById; | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * 创建人 | ||
| 135 | + */ | ||
| 136 | + @TableField(fill = FieldFill.INSERT) | ||
| 137 | + private String createBy; | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * 创建时间 | ||
| 141 | + */ | ||
| 142 | + @TableField(fill = FieldFill.INSERT) | ||
| 143 | + private LocalDateTime createTime; | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 修改人ID | ||
| 147 | + */ | ||
| 148 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 149 | + private String updateById; | ||
| 150 | + | ||
| 151 | + /** | ||
| 152 | + * 修改人 | ||
| 153 | + */ | ||
| 154 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 155 | + private String updateBy; | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * 修改时间 | ||
| 159 | + */ | ||
| 160 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 161 | + private LocalDateTime updateTime; | ||
| 162 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.impl.summary; | ||
| 2 | + | ||
| 3 | +import com.lframework.starter.web.core.impl.BaseMpServiceImpl; | ||
| 4 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummaryDetail; | ||
| 5 | +import com.lframework.xingyun.sc.procurement.mappers.summary.DomesticPlanSummaryDetailMapper; | ||
| 6 | +import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryDetailService; | ||
| 7 | +import java.util.List; | ||
| 8 | +import org.springframework.stereotype.Service; | ||
| 9 | + | ||
| 10 | +@Service | ||
| 11 | +public class DomesticPlanSummaryDetailServiceImpl extends | ||
| 12 | + BaseMpServiceImpl<DomesticPlanSummaryDetailMapper, DomesticPlanSummaryDetail> implements | ||
| 13 | + DomesticPlanSummaryDetailService { | ||
| 14 | + | ||
| 15 | + @Override | ||
| 16 | + public List<DomesticPlanSummaryDetail> getBySummaryId(String summaryId) { | ||
| 17 | + return getBaseMapper().getBySummaryId(summaryId); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public void deleteBySummaryId(String summaryId) { | ||
| 22 | + getBaseMapper().deleteBySummaryId(summaryId); | ||
| 23 | + } | ||
| 24 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.impl.summary; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||
| 4 | +import com.github.pagehelper.PageInfo; | ||
| 5 | +import com.lframework.starter.common.utils.Assert; | ||
| 6 | +import com.lframework.starter.common.utils.CollectionUtil; | ||
| 7 | +import com.lframework.starter.common.utils.StringUtil; | ||
| 8 | +import com.lframework.starter.web.core.components.resp.PageResult; | ||
| 9 | +import com.lframework.starter.web.core.impl.BaseMpServiceImpl; | ||
| 10 | +import com.lframework.starter.web.core.utils.IdUtil; | ||
| 11 | +import com.lframework.starter.web.core.utils.PageHelperUtil; | ||
| 12 | +import com.lframework.starter.web.core.utils.PageResultUtil; | ||
| 13 | +import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryBo; | ||
| 14 | +import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryDetailBo; | ||
| 15 | +import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApply; | ||
| 16 | +import com.lframework.xingyun.sc.procurement.entity.replenish.ProcurementPlanReplenish; | ||
| 17 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary; | ||
| 18 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummaryDetail; | ||
| 19 | +import com.lframework.xingyun.sc.procurement.mappers.summary.DomesticPlanSummaryDetailMapper; | ||
| 20 | +import com.lframework.xingyun.sc.procurement.mappers.summary.DomesticPlanSummaryMapper; | ||
| 21 | +import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService; | ||
| 22 | +import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService; | ||
| 23 | +import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryDetailService; | ||
| 24 | +import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryService; | ||
| 25 | +import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo; | ||
| 26 | +import java.math.BigDecimal; | ||
| 27 | +import java.math.RoundingMode; | ||
| 28 | +import java.sql.Timestamp; | ||
| 29 | +import java.time.LocalDate; | ||
| 30 | +import java.time.LocalDateTime; | ||
| 31 | +import java.util.ArrayList; | ||
| 32 | +import java.util.Collections; | ||
| 33 | +import java.util.List; | ||
| 34 | +import java.util.Map; | ||
| 35 | +import java.util.Objects; | ||
| 36 | +import java.util.Set; | ||
| 37 | +import java.util.stream.Collectors; | ||
| 38 | +import javax.annotation.Resource; | ||
| 39 | +import org.springframework.stereotype.Service; | ||
| 40 | +import org.springframework.transaction.annotation.Transactional; | ||
| 41 | + | ||
| 42 | +@Service | ||
| 43 | +public class DomesticPlanSummaryServiceImpl extends | ||
| 44 | + BaseMpServiceImpl<DomesticPlanSummaryMapper, DomesticPlanSummary> implements | ||
| 45 | + DomesticPlanSummaryService { | ||
| 46 | + | ||
| 47 | + @Resource | ||
| 48 | + private DomesticPlanSummaryMapper domesticPlanSummaryMapper; | ||
| 49 | + @Resource | ||
| 50 | + private DomesticPlanSummaryDetailMapper domesticPlanSummaryDetailMapper; | ||
| 51 | + @Resource | ||
| 52 | + private DomesticPlanSummaryDetailService domesticPlanSummaryDetailService; | ||
| 53 | + @Resource | ||
| 54 | + private ProcurementBuyoutApplyService procurementBuyoutApplyService; | ||
| 55 | + @Resource | ||
| 56 | + private ProcurementPlanReplenishService procurementPlanReplenishService; | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public PageResult<DomesticPlanSummary> query(Integer pageIndex, Integer pageSize, | ||
| 60 | + QueryDomesticPlanSummaryVo vo) { | ||
| 61 | + Assert.greaterThanZero(pageIndex); | ||
| 62 | + Assert.greaterThanZero(pageSize); | ||
| 63 | + | ||
| 64 | + PageHelperUtil.startPage(pageIndex, pageSize); | ||
| 65 | + List<DomesticPlanSummary> datas = this.query(vo); | ||
| 66 | + return PageResultUtil.convert(new PageInfo<>(datas)); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public List<DomesticPlanSummary> query(QueryDomesticPlanSummaryVo vo) { | ||
| 71 | + return domesticPlanSummaryMapper.query(vo); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public GetDomesticPlanSummaryBo findDetail(String id) { | ||
| 76 | + if (StringUtil.isBlank(id)) { | ||
| 77 | + throw new com.lframework.starter.common.exceptions.impl.InputErrorException("ID不能为空!"); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + DomesticPlanSummary entity = domesticPlanSummaryMapper.findById(id); | ||
| 81 | + if (entity == null) { | ||
| 82 | + throw new com.lframework.starter.common.exceptions.impl.DefaultClientException("汇总记录不存在!"); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + GetDomesticPlanSummaryBo bo = new GetDomesticPlanSummaryBo(entity); | ||
| 86 | + bo.convert(entity); | ||
| 87 | + | ||
| 88 | + List<DomesticPlanSummaryDetail> details = domesticPlanSummaryDetailService.getBySummaryId(id); | ||
| 89 | + if (!CollectionUtil.isEmpty(details)) { | ||
| 90 | + List<GetDomesticPlanSummaryDetailBo> detailBoList = new ArrayList<>(); | ||
| 91 | + for (int i = 0; i < details.size(); i++) { | ||
| 92 | + GetDomesticPlanSummaryDetailBo dbo = new GetDomesticPlanSummaryDetailBo(details.get(i)); | ||
| 93 | + dbo.setSeq(i + 1); | ||
| 94 | + BigDecimal cr = details.get(i).getCoordinationRange() != null | ||
| 95 | + ? details.get(i).getCoordinationRange() : BigDecimal.ZERO; | ||
| 96 | + BigDecimal avg = | ||
| 97 | + entity.getWeightedAvgCoordination() != null ? entity.getWeightedAvgCoordination() | ||
| 98 | + : BigDecimal.ZERO; | ||
| 99 | + dbo.setCompareWithAvg(cr.subtract(avg)); | ||
| 100 | + dbo.setRemarkLabel(details.get(i).getRemarkFlag()); | ||
| 101 | + detailBoList.add(dbo); | ||
| 102 | + } | ||
| 103 | + bo.setDetails(detailBoList); | ||
| 104 | + } else { | ||
| 105 | + bo.setDetails(Collections.emptyList()); | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + return bo; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + @Override | ||
| 112 | + @Transactional(rollbackFor = Exception.class) | ||
| 113 | + public String generateDailySummary(LocalDate summaryDate) { | ||
| 114 | + if (summaryDate == null) { | ||
| 115 | + summaryDate = LocalDate.now(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + long existCount = domesticPlanSummaryMapper.countBySummaryDate(summaryDate); | ||
| 119 | + if (existCount > 0) { | ||
| 120 | + DomesticPlanSummary exist = this.getOne( | ||
| 121 | + Wrappers.lambdaQuery(DomesticPlanSummary.class) | ||
| 122 | + .eq(DomesticPlanSummary::getSummaryDate, summaryDate)); | ||
| 123 | + return exist.getId(); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + LocalDate yesterday = summaryDate.minusDays(1); | ||
| 127 | + LocalDateTime auditStart = yesterday.atStartOfDay(); | ||
| 128 | + LocalDateTime auditEnd = yesterday.atTime(23, 59, 59); | ||
| 129 | + | ||
| 130 | + List<Map<String, Object>> rawLines = | ||
| 131 | + domesticPlanSummaryDetailMapper.selectPlanLinesForYesterdaySummary(auditStart, auditEnd); | ||
| 132 | + if (rawLines == null) { | ||
| 133 | + return null; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + Set<String> planIds = rawLines.stream() | ||
| 137 | + .map(row -> (String) row.get("plan_id")) | ||
| 138 | + .filter(Objects::nonNull) | ||
| 139 | + .collect(Collectors.toSet()); | ||
| 140 | + | ||
| 141 | + Set<String> buyoutPlanIds = Collections.emptySet(); | ||
| 142 | + if (CollectionUtil.isNotEmpty(planIds)) { | ||
| 143 | + buyoutPlanIds = procurementBuyoutApplyService.list( | ||
| 144 | + Wrappers.lambdaQuery(ProcurementBuyoutApply.class) | ||
| 145 | + .in(ProcurementBuyoutApply::getProcurementPlanId, planIds) | ||
| 146 | + .select(ProcurementBuyoutApply::getProcurementPlanId)) | ||
| 147 | + .stream() | ||
| 148 | + .map(ProcurementBuyoutApply::getProcurementPlanId) | ||
| 149 | + .collect(Collectors.toSet()); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + Set<String> replenishPlanIds = Collections.emptySet(); | ||
| 153 | + if (CollectionUtil.isNotEmpty(planIds)) { | ||
| 154 | + replenishPlanIds = procurementPlanReplenishService.list( | ||
| 155 | + Wrappers.lambdaQuery(ProcurementPlanReplenish.class) | ||
| 156 | + .in(ProcurementPlanReplenish::getProcurementPlanId, planIds) | ||
| 157 | + .eq(ProcurementPlanReplenish::getApprovalStatus, "PASS") | ||
| 158 | + .select(ProcurementPlanReplenish::getProcurementPlanId)) | ||
| 159 | + .stream() | ||
| 160 | + .map(ProcurementPlanReplenish::getProcurementPlanId) | ||
| 161 | + .collect(Collectors.toSet()); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + DomesticPlanSummary summary = new DomesticPlanSummary(); | ||
| 165 | + summary.setId(IdUtil.getId()); | ||
| 166 | + | ||
| 167 | + String yearPart = String.format("%02d", summaryDate.getYear() % 100); | ||
| 168 | + String prefix = "XT" + yearPart; | ||
| 169 | + DomesticPlanSummary max = domesticPlanSummaryMapper.findMaxCodeByYearPrefix(prefix); | ||
| 170 | + int seq = 1; | ||
| 171 | + if (max != null && StringUtil.isNotBlank(max.getCode())) { | ||
| 172 | + String numPart = max.getCode().substring(prefix.length()); | ||
| 173 | + seq = Integer.parseInt(numPart) + 1; | ||
| 174 | + } | ||
| 175 | + summary.setCode(prefix + String.format("%04d", seq)); | ||
| 176 | + | ||
| 177 | + summary.setSummaryDate(summaryDate); | ||
| 178 | + summary.setTotalQuantity(BigDecimal.ZERO); | ||
| 179 | + summary.setWeightedAvgCoordination(BigDecimal.ZERO); | ||
| 180 | + | ||
| 181 | + List<DomesticPlanSummaryDetail> detailList = new ArrayList<>(); | ||
| 182 | + BigDecimal totalQty = BigDecimal.ZERO; | ||
| 183 | + BigDecimal weightedSum = BigDecimal.ZERO; | ||
| 184 | + int orderNo = 0; | ||
| 185 | + | ||
| 186 | + for (Map<String, Object> row : rawLines) { | ||
| 187 | + DomesticPlanSummaryDetail d = new DomesticPlanSummaryDetail(); | ||
| 188 | + d.setId(IdUtil.getId()); | ||
| 189 | + d.setSummaryId(summary.getId()); | ||
| 190 | + d.setOrderNo(++orderNo); | ||
| 191 | + | ||
| 192 | + Object planCreateTime = row.get("plan_create_time"); | ||
| 193 | + if (planCreateTime != null) { | ||
| 194 | + if (planCreateTime instanceof LocalDateTime) { | ||
| 195 | + d.setPlanCreateDate(((LocalDateTime) planCreateTime).toLocalDate()); | ||
| 196 | + } else if (planCreateTime instanceof LocalDate) { | ||
| 197 | + d.setPlanCreateDate((LocalDate) planCreateTime); | ||
| 198 | + } else if (planCreateTime instanceof Timestamp) { | ||
| 199 | + d.setPlanCreateDate(((Timestamp) planCreateTime).toLocalDateTime().toLocalDate()); | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + d.setPurchaseDeptId((String) row.get("purchase_dept_id")); | ||
| 204 | + d.setSupplierName( | ||
| 205 | + row.get("supplier_name") != null ? (String) row.get("supplier_name") : ""); | ||
| 206 | + d.setPlanId((String) row.get("plan_id")); | ||
| 207 | + d.setPlanCode((String) row.get("plan_code")); | ||
| 208 | + d.setProductId((String) row.get("product_id")); | ||
| 209 | + | ||
| 210 | + BigDecimal qty = toDecimal(row.get("quantity")); | ||
| 211 | + d.setQuantity(qty); | ||
| 212 | + BigDecimal actualPrice = toDecimal(row.get("actual_purchase_price")); | ||
| 213 | + d.setActualPurchasePrice(actualPrice); | ||
| 214 | + BigDecimal shippingCost = toDecimal(row.get("shipping_cost")); | ||
| 215 | + d.setShippingCost(shippingCost); | ||
| 216 | + d.setPriceWithShipping(actualPrice.add(shippingCost)); | ||
| 217 | + d.setWorkshopId((String) row.get("workshop_id")); | ||
| 218 | + BigDecimal cr = toDecimal(row.get("coordination_range")); | ||
| 219 | + d.setCoordinationRange(cr); | ||
| 220 | + d.setCreateById("1"); | ||
| 221 | + d.setCreateBy("系统管理员"); | ||
| 222 | + d.setUpdateById("1"); | ||
| 223 | + d.setUpdateBy("系统管理员"); | ||
| 224 | + | ||
| 225 | + boolean hasBuyout = buyoutPlanIds.contains(d.getPlanId()); | ||
| 226 | + boolean hasReplenish = replenishPlanIds.contains(d.getPlanId()); | ||
| 227 | + if (hasBuyout && hasReplenish) { | ||
| 228 | + d.setRemarkFlag("买断 补单"); | ||
| 229 | + } else if (hasBuyout) { | ||
| 230 | + d.setRemarkFlag("买断"); | ||
| 231 | + } else if (hasReplenish) { | ||
| 232 | + d.setRemarkFlag("补单"); | ||
| 233 | + } else { | ||
| 234 | + d.setRemarkFlag(null); | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + d.setPlanLineId((String) row.get("plan_line_id")); | ||
| 238 | + Object apt = row.get("approval_pass_time"); | ||
| 239 | + if (apt != null) { | ||
| 240 | + if (apt instanceof LocalDateTime) { | ||
| 241 | + d.setApprovalPassTime((LocalDateTime) apt); | ||
| 242 | + } else if (apt instanceof Timestamp) { | ||
| 243 | + d.setApprovalPassTime(((Timestamp) apt).toLocalDateTime()); | ||
| 244 | + } | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + detailList.add(d); | ||
| 248 | + totalQty = totalQty.add(qty); | ||
| 249 | + weightedSum = weightedSum.add(cr.multiply(qty)); | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + summary.setTotalQuantity(totalQty); | ||
| 253 | + if (totalQty.compareTo(BigDecimal.ZERO) > 0) { | ||
| 254 | + BigDecimal weightedAvg = weightedSum.divide(totalQty, 6, RoundingMode.HALF_UP); | ||
| 255 | + summary.setWeightedAvgCoordination(weightedAvg); | ||
| 256 | + } else { | ||
| 257 | + summary.setWeightedAvgCoordination(BigDecimal.ZERO); | ||
| 258 | + } | ||
| 259 | + summary.setCreateById("1"); | ||
| 260 | + summary.setCreateBy("系统管理员"); | ||
| 261 | + summary.setUpdateById("1"); | ||
| 262 | + summary.setUpdateBy("系统管理员"); | ||
| 263 | + | ||
| 264 | + this.save(summary); | ||
| 265 | + if (!CollectionUtil.isEmpty(detailList)) { | ||
| 266 | + domesticPlanSummaryDetailService.saveBatch(detailList); | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + return summary.getId(); | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + private BigDecimal toDecimal(Object obj) { | ||
| 273 | + if (obj == null) { | ||
| 274 | + return BigDecimal.ZERO; | ||
| 275 | + } | ||
| 276 | + if (obj instanceof BigDecimal) { | ||
| 277 | + return (BigDecimal) obj; | ||
| 278 | + } | ||
| 279 | + if (obj instanceof Number) { | ||
| 280 | + return new BigDecimal(obj.toString()); | ||
| 281 | + } | ||
| 282 | + if (obj instanceof String) { | ||
| 283 | + String str = ((String) obj).trim(); | ||
| 284 | + if (StringUtil.isBlank(str)) { | ||
| 285 | + return BigDecimal.ZERO; | ||
| 286 | + } | ||
| 287 | + return new BigDecimal(str); | ||
| 288 | + } | ||
| 289 | + return BigDecimal.ZERO; | ||
| 290 | + } | ||
| 291 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.mappers.summary; | ||
| 2 | + | ||
| 3 | +import com.lframework.starter.web.core.mapper.BaseMapper; | ||
| 4 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummaryDetail; | ||
| 5 | +import java.time.LocalDateTime; | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.Map; | ||
| 8 | +import org.apache.ibatis.annotations.Param; | ||
| 9 | + | ||
| 10 | +public interface DomesticPlanSummaryDetailMapper extends BaseMapper<DomesticPlanSummaryDetail> { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 根据汇总ID查询明细列表 | ||
| 14 | + * | ||
| 15 | + * @param summaryId | ||
| 16 | + * @return | ||
| 17 | + */ | ||
| 18 | + List<DomesticPlanSummaryDetail> getBySummaryId(@Param("summaryId") String summaryId); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 根据汇总ID删除明细 | ||
| 22 | + * | ||
| 23 | + * @param summaryId | ||
| 24 | + */ | ||
| 25 | + void deleteBySummaryId(@Param("summaryId") String summaryId); | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 查询前一天审核通过的计划明细用于汇总 | ||
| 29 | + * | ||
| 30 | + * @param yesterdayStart | ||
| 31 | + * @param yesterdayEnd | ||
| 32 | + * @return | ||
| 33 | + */ | ||
| 34 | + List<Map<String, Object>> selectPlanLinesForYesterdaySummary( | ||
| 35 | + @Param("yesterdayStart") LocalDateTime yesterdayStart, | ||
| 36 | + @Param("yesterdayEnd") LocalDateTime yesterdayEnd); | ||
| 37 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.mappers.summary; | ||
| 2 | + | ||
| 3 | +import com.lframework.starter.web.core.mapper.BaseMapper; | ||
| 4 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary; | ||
| 5 | +import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo; | ||
| 6 | +import java.time.LocalDate; | ||
| 7 | +import java.util.List; | ||
| 8 | +import org.apache.ibatis.annotations.Param; | ||
| 9 | + | ||
| 10 | +public interface DomesticPlanSummaryMapper extends BaseMapper<DomesticPlanSummary> { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 查询列表 | ||
| 14 | + * | ||
| 15 | + * @param vo | ||
| 16 | + * @return | ||
| 17 | + */ | ||
| 18 | + List<DomesticPlanSummary> query(@Param("vo") QueryDomesticPlanSummaryVo vo); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 根据ID查询 | ||
| 22 | + * | ||
| 23 | + * @param id | ||
| 24 | + * @return | ||
| 25 | + */ | ||
| 26 | + DomesticPlanSummary findById(@Param("id") String id); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 根据汇总日期统计数量(幂等用) | ||
| 30 | + * | ||
| 31 | + * @param summaryDate | ||
| 32 | + * @return | ||
| 33 | + */ | ||
| 34 | + long countBySummaryDate(@Param("summaryDate") LocalDate summaryDate); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 根据年份前缀查找最大编码的记录 | ||
| 38 | + * | ||
| 39 | + * @param prefix | ||
| 40 | + * @return | ||
| 41 | + */ | ||
| 42 | + DomesticPlanSummary findMaxCodeByYearPrefix(@Param("prefix") String prefix); | ||
| 43 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.service.summary; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummaryDetail; | ||
| 5 | +import java.util.List; | ||
| 6 | + | ||
| 7 | +public interface DomesticPlanSummaryDetailService extends IService<DomesticPlanSummaryDetail> { | ||
| 8 | + | ||
| 9 | + List<DomesticPlanSummaryDetail> getBySummaryId(String summaryId); | ||
| 10 | + | ||
| 11 | + void deleteBySummaryId(String summaryId); | ||
| 12 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.service.summary; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | +import com.lframework.starter.web.core.components.resp.PageResult; | ||
| 5 | +import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryBo; | ||
| 6 | +import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary; | ||
| 7 | +import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo; | ||
| 8 | +import java.time.LocalDate; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +public interface DomesticPlanSummaryService extends IService<DomesticPlanSummary> { | ||
| 12 | + | ||
| 13 | + PageResult<DomesticPlanSummary> query(Integer pageIndex, Integer pageSize, | ||
| 14 | + QueryDomesticPlanSummaryVo vo); | ||
| 15 | + | ||
| 16 | + List<DomesticPlanSummary> query(QueryDomesticPlanSummaryVo vo); | ||
| 17 | + | ||
| 18 | + GetDomesticPlanSummaryBo findDetail(String id); | ||
| 19 | + | ||
| 20 | + String generateDailySummary(LocalDate summaryDate); | ||
| 21 | +} |
| 1 | +package com.lframework.xingyun.sc.procurement.vo.summary; | ||
| 2 | + | ||
| 3 | +import com.lframework.starter.web.core.vo.SortPageVo; | ||
| 4 | +import io.swagger.annotations.ApiModel; | ||
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 6 | +import java.time.LocalDate; | ||
| 7 | +import lombok.Data; | ||
| 8 | + | ||
| 9 | +@Data | ||
| 10 | +@ApiModel("查询内销计划汇总Vo") | ||
| 11 | +public class QueryDomesticPlanSummaryVo extends SortPageVo { | ||
| 12 | + | ||
| 13 | + private static final long serialVersionUID = 1L; | ||
| 14 | + | ||
| 15 | + @ApiModelProperty("汇总编号") | ||
| 16 | + private String code; | ||
| 17 | + | ||
| 18 | + @ApiModelProperty("汇总日期起始") | ||
| 19 | + private LocalDate startDate; | ||
| 20 | + | ||
| 21 | + @ApiModelProperty("汇总日期截止") | ||
| 22 | + private LocalDate endDate; | ||
| 23 | +} |
xingyun-sc/src/main/resources/mappers/procurement/summary/DomesticPlanSummaryDetailMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.summary.DomesticPlanSummaryDetailMapper"> | ||
| 4 | + | ||
| 5 | + <resultMap id="DomesticPlanSummaryDetail" type="com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummaryDetail"> | ||
| 6 | + <id column="id" property="id"/> | ||
| 7 | + <result column="summary_id" property="summaryId"/> | ||
| 8 | + <result column="order_no" property="orderNo"/> | ||
| 9 | + <result column="plan_create_date" property="planCreateDate"/> | ||
| 10 | + <result column="purchase_dept_id" property="purchaseDeptId"/> | ||
| 11 | + <result column="purchase_dept_name" property="purchaseDeptName"/> | ||
| 12 | + <result column="supplier_name" property="supplierName"/> | ||
| 13 | + <result column="plan_id" property="planId"/> | ||
| 14 | + <result column="plan_code" property="planCode"/> | ||
| 15 | + <result column="product_id" property="productId"/> | ||
| 16 | + <result column="product_name" property="productName"/> | ||
| 17 | + <result column="quantity" property="quantity"/> | ||
| 18 | + <result column="actual_purchase_price" property="actualPurchasePrice"/> | ||
| 19 | + <result column="shipping_cost" property="shippingCost"/> | ||
| 20 | + <result column="price_with_shipping" property="priceWithShipping"/> | ||
| 21 | + <result column="workshop_id" property="workshopId"/> | ||
| 22 | + <result column="workshop_name" property="workshopName"/> | ||
| 23 | + <result column="coordination_range" property="coordinationRange"/> | ||
| 24 | + <result column="remark_flag" property="remarkFlag"/> | ||
| 25 | + <result column="plan_line_id" property="planLineId"/> | ||
| 26 | + <result column="approval_pass_time" property="approvalPassTime"/> | ||
| 27 | + <result column="create_by_id" property="createById"/> | ||
| 28 | + <result column="create_by" property="createBy"/> | ||
| 29 | + <result column="update_by_id" property="updateById"/> | ||
| 30 | + <result column="update_by" property="updateBy"/> | ||
| 31 | + <result column="create_time" property="createTime"/> | ||
| 32 | + <result column="update_time" property="updateTime"/> | ||
| 33 | + </resultMap> | ||
| 34 | + | ||
| 35 | + <sql id="DomesticPlanSummaryDetail_sql"> | ||
| 36 | + SELECT | ||
| 37 | + dpsd.id, | ||
| 38 | + dpsd.summary_id, | ||
| 39 | + dpsd.order_no, | ||
| 40 | + dpsd.plan_create_date, | ||
| 41 | + dpsd.purchase_dept_id, | ||
| 42 | + sd.name AS purchase_dept_name, | ||
| 43 | + dpsd.supplier_name, | ||
| 44 | + dpsd.plan_id, | ||
| 45 | + dpsd.plan_code, | ||
| 46 | + dpsd.product_id, | ||
| 47 | + br.product_name, | ||
| 48 | + dpsd.quantity, | ||
| 49 | + dpsd.actual_purchase_price, | ||
| 50 | + dpsd.shipping_cost, | ||
| 51 | + dpsd.price_with_shipping, | ||
| 52 | + dpsd.workshop_id, | ||
| 53 | + ws.name AS workshop_name, | ||
| 54 | + dpsd.coordination_range, | ||
| 55 | + dpsd.remark_flag, | ||
| 56 | + dpsd.plan_line_id, | ||
| 57 | + dpsd.approval_pass_time, | ||
| 58 | + dpsd.create_by_id, | ||
| 59 | + dpsd.create_by, | ||
| 60 | + dpsd.update_by_id, | ||
| 61 | + dpsd.update_by, | ||
| 62 | + dpsd.create_time, | ||
| 63 | + dpsd.update_time | ||
| 64 | + FROM domestic_plan_summary_detail AS dpsd | ||
| 65 | + LEFT JOIN base_data_breed_relationship br ON br.id = dpsd.product_id | ||
| 66 | + LEFT JOIN base_data_workshop as ws on ws.id = dpsd.workshop_id | ||
| 67 | + LEFT JOIN sys_dept sd ON sd.id = dpsd.purchase_dept_id | ||
| 68 | + </sql> | ||
| 69 | + | ||
| 70 | + <select id="getBySummaryId" resultMap="DomesticPlanSummaryDetail"> | ||
| 71 | + <include refid="DomesticPlanSummaryDetail_sql"/> | ||
| 72 | + WHERE dpsd.summary_id = #{summaryId} | ||
| 73 | + ORDER BY dpsd.order_no ASC | ||
| 74 | + </select> | ||
| 75 | + | ||
| 76 | + <delete id="deleteBySummaryId"> | ||
| 77 | + DELETE FROM domestic_plan_summary_detail WHERE summary_id = #{summaryId} | ||
| 78 | + </delete> | ||
| 79 | + | ||
| 80 | + <select id="selectPlanLinesForYesterdaySummary" resultType="java.util.HashMap"> | ||
| 81 | + SELECT | ||
| 82 | + pp.id AS plan_id, | ||
| 83 | + pp.code AS plan_code, | ||
| 84 | + pp.create_time AS plan_create_time, | ||
| 85 | + pp.purchase_department AS purchase_dept_id, | ||
| 86 | + pdc.customer_short_name AS supplier_name, | ||
| 87 | + pp.shipping_cost AS shipping_cost, | ||
| 88 | + pp.approval_pass_time AS approval_pass_time, | ||
| 89 | + ppl.id AS plan_line_id, | ||
| 90 | + ppl.product_id AS product_id, | ||
| 91 | + ppl.quantity AS quantity, | ||
| 92 | + ppl.actual_purchase_price AS actual_purchase_price, | ||
| 93 | + ppl.coordination_range AS coordination_range, | ||
| 94 | + ppl.workshop_id AS workshop_id | ||
| 95 | + FROM procurement_plan_line ppl | ||
| 96 | + INNER JOIN procurement_plan pp ON ppl.procurement_plan_id = pp.id | ||
| 97 | + AND pp.process_status = 'COMPLETED' | ||
| 98 | + AND (pp.frozen = 0 OR pp.frozen IS NULL) | ||
| 99 | + AND pp.deleted = 0 | ||
| 100 | + AND pp.approval_pass_time BETWEEN #{yesterdayStart} AND #{yesterdayEnd} | ||
| 101 | + LEFT JOIN procurement_domestic_customer_credit pdc ON pdc.id = pp.supplier_id | ||
| 102 | + ORDER BY pp.approval_pass_time ASC, ppl.id ASC | ||
| 103 | + </select> | ||
| 104 | +</mapper> |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.summary.DomesticPlanSummaryMapper"> | ||
| 4 | + | ||
| 5 | + <resultMap id="DomesticPlanSummary" type="com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary"> | ||
| 6 | + <id column="id" property="id"/> | ||
| 7 | + <result column="code" property="code"/> | ||
| 8 | + <result column="summary_date" property="summaryDate"/> | ||
| 9 | + <result column="total_quantity" property="totalQuantity"/> | ||
| 10 | + <result column="weighted_avg_coordination" property="weightedAvgCoordination"/> | ||
| 11 | + <result column="create_by_id" property="createById"/> | ||
| 12 | + <result column="create_by" property="createBy"/> | ||
| 13 | + <result column="create_time" property="createTime"/> | ||
| 14 | + <result column="update_by_id" property="updateById"/> | ||
| 15 | + <result column="update_by" property="updateBy"/> | ||
| 16 | + <result column="update_time" property="updateTime"/> | ||
| 17 | + </resultMap> | ||
| 18 | + | ||
| 19 | + <sql id="DomesticPlanSummary_sql"> | ||
| 20 | + SELECT | ||
| 21 | + dps.id, | ||
| 22 | + dps.code, | ||
| 23 | + dps.summary_date, | ||
| 24 | + dps.total_quantity, | ||
| 25 | + dps.weighted_avg_coordination, | ||
| 26 | + dps.create_by_id, | ||
| 27 | + dps.create_by, | ||
| 28 | + dps.create_time, | ||
| 29 | + dps.update_by_id, | ||
| 30 | + dps.update_by, | ||
| 31 | + dps.update_time | ||
| 32 | + FROM domestic_plan_summary AS dps | ||
| 33 | + </sql> | ||
| 34 | + | ||
| 35 | + <select id="query" resultMap="DomesticPlanSummary"> | ||
| 36 | + <include refid="DomesticPlanSummary_sql"/> | ||
| 37 | + <where> | ||
| 38 | + <if test="vo.code != null and vo.code != ''"> | ||
| 39 | + AND dps.code LIKE CONCAT('%', #{vo.code}, '%') | ||
| 40 | + </if> | ||
| 41 | + <if test="vo.startDate != null"> | ||
| 42 | + AND dps.summary_date >= #{vo.startDate} | ||
| 43 | + </if> | ||
| 44 | + <if test="vo.endDate != null"> | ||
| 45 | + AND dps.summary_date <= #{vo.endDate} | ||
| 46 | + </if> | ||
| 47 | + </where> | ||
| 48 | + ORDER BY dps.summary_date DESC, dps.code DESC | ||
| 49 | + </select> | ||
| 50 | + | ||
| 51 | + <select id="findById" resultMap="DomesticPlanSummary"> | ||
| 52 | + <include refid="DomesticPlanSummary_sql"/> | ||
| 53 | + WHERE dps.id = #{id} | ||
| 54 | + </select> | ||
| 55 | + | ||
| 56 | + <select id="countBySummaryDate" resultType="long"> | ||
| 57 | + SELECT COUNT(1) FROM domestic_plan_summary WHERE summary_date = #{summaryDate} | ||
| 58 | + </select> | ||
| 59 | + | ||
| 60 | + <select id="findMaxCodeByYearPrefix" resultMap="DomesticPlanSummary"> | ||
| 61 | + SELECT * FROM domestic_plan_summary WHERE code LIKE CONCAT(#{prefix}, '%') ORDER BY code DESC LIMIT 1 | ||
| 62 | + </select> | ||
| 63 | +</mapper> |