From 5ebd9f5e6d8fd16922fe03b9e39f4bd1a535803c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=B8=E7=86=9F=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Fri, 13 Nov 2026 15:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=93=81=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SupplierNewProductHistoryController.java | 31 ++++++ ...SupplierNewProductHistoryQueryService.java | 95 +++++++++++++++++++ .../vo/SupplierNewProductHistoryQuery.java | 15 +++ 3 files changed, 141 insertions(+) create mode 100644 src/main/java/com/xujie/modules/order/controller/SupplierNewProductHistoryController.java create mode 100644 src/main/java/com/xujie/modules/order/service/Impl/SupplierNewProductHistoryQueryService.java create mode 100644 src/main/java/com/xujie/modules/order/vo/SupplierNewProductHistoryQuery.java diff --git a/src/main/java/com/xujie/modules/order/controller/SupplierNewProductHistoryController.java b/src/main/java/com/xujie/modules/order/controller/SupplierNewProductHistoryController.java new file mode 100644 index 0000000..8569b2a --- /dev/null +++ b/src/main/java/com/xujie/modules/order/controller/SupplierNewProductHistoryController.java @@ -0,0 +1,31 @@ +package com.xujie.modules.order.controller; + +import com.xujie.common.utils.R; +import com.xujie.modules.order.service.Impl.SupplierNewProductHistoryQueryService; +import com.xujie.modules.order.vo.SupplierNewProductHistoryQuery; +import com.xujie.modules.sys.entity.SysUserEntity; +import org.apache.shiro.SecurityUtils; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/supplierNewProductHistory") +public class SupplierNewProductHistoryController { + + private final SupplierNewProductHistoryQueryService queryService; + + public SupplierNewProductHistoryController(SupplierNewProductHistoryQueryService queryService) { + this.queryService = queryService; + } + + @PostMapping("/page") + public R page(@RequestBody(required = false) SupplierNewProductHistoryQuery query) { + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + if (user == null) { + throw new IllegalStateException("请先登录后再查询供应商新品历史"); + } + return R.ok().put("page", queryService.page(user.getSite(), query)); + } +} diff --git a/src/main/java/com/xujie/modules/order/service/Impl/SupplierNewProductHistoryQueryService.java b/src/main/java/com/xujie/modules/order/service/Impl/SupplierNewProductHistoryQueryService.java new file mode 100644 index 0000000..320573b --- /dev/null +++ b/src/main/java/com/xujie/modules/order/service/Impl/SupplierNewProductHistoryQueryService.java @@ -0,0 +1,95 @@ +package com.xujie.modules.order.service.Impl; + +import com.xujie.common.utils.PageUtils; +import com.xujie.modules.order.vo.SupplierNewProductHistoryQuery; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +public class SupplierNewProductHistoryQueryService { + + private final JdbcTemplate jdbcTemplate; + + public SupplierNewProductHistoryQueryService(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public PageUtils page(String site, SupplierNewProductHistoryQuery query) { + if (!StringUtils.hasText(site)) { + throw new IllegalArgumentException("当前账号未设置 Site,无法查询供应商新品历史"); + } + if (query == null) { + query = new SupplierNewProductHistoryQuery(); + } + int page = query.getPage() == null ? 1 : Math.max(1, query.getPage()); + int limit = query.getLimit() == null ? 20 : Math.max(1, Math.min(500, query.getLimit())); + LocalDate start = parseDate(query.getOrderDateStart(), "订单日期开始"); + LocalDate end = parseDate(query.getOrderDateEnd(), "订单日期结束"); + if (start != null && end != null && start.isAfter(end)) { + throw new IllegalArgumentException("订单日期开始不能晚于结束"); + } + + StringBuilder fromWhere = new StringBuilder( + " FROM dbo.supplier_new_product_history h WITH (NOLOCK) " + + "LEFT JOIN dbo.part p WITH (NOLOCK) ON p.site = h.site AND p.part_no = h.part_no " + + "LEFT JOIN dbo.srm_supplier s WITH (NOLOCK) " + + "ON s.site = h.site AND s.supplier_no = h.supplier_no " + + "WHERE h.site = ?"); + List params = new ArrayList<>(); + params.add(site.trim()); + appendLike(fromWhere, params, "s.c_short_office", query.getShortOffice()); + appendLike(fromWhere, params, "s.c_short_npc", query.getShortNpc()); + appendLike(fromWhere, params, "h.base_part_no", query.getBasePartNo()); + appendLike(fromWhere, params, "p.sku", query.getSku()); + if (start != null) { + fromWhere.append(" AND h.ori_order_date >= CAST(? AS DATE)"); + params.add(start.toString()); + } + if (end != null) { + fromWhere.append(" AND h.ori_order_date < DATEADD(DAY, 1, CAST(? AS DATE))"); + params.add(end.toString()); + } + + Integer total = jdbcTemplate.queryForObject( + "SELECT COUNT(1)" + fromWhere, Integer.class, params.toArray()); + List pageParams = new ArrayList<>(params); + pageParams.add((long) (page - 1) * limit); + pageParams.add(limit); + String dataSql = "SELECT h.id AS id, s.c_short_office AS shortOffice, " + + "s.c_short_npc AS shortNpc, h.base_part_no AS basePartNo, " + + "p.sku AS sku, h.first_order_no AS firstOrderNo, " + + "h.item_no AS itemNo, h.part_no AS partNo, " + + "CONVERT(VARCHAR(10), h.ori_order_date, 23) AS oriOrderDate, " + + "CONVERT(VARCHAR(19), h.create_time, 120) AS createTime" + + fromWhere + + " ORDER BY h.ori_order_date DESC, h.id DESC" + + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + List> rows = jdbcTemplate.queryForList(dataSql, pageParams.toArray()); + return new PageUtils(rows, total == null ? 0 : total, limit, page); + } + + private static void appendLike(StringBuilder sql, List params, String column, String value) { + if (StringUtils.hasText(value)) { + sql.append(" AND ").append(column).append(" LIKE ?"); + params.add("%" + value.trim() + "%"); + } + } + + private static LocalDate parseDate(String value, String label) { + if (!StringUtils.hasText(value)) { + return null; + } + try { + return LocalDate.parse(value.trim()); + } catch (DateTimeParseException ex) { + throw new IllegalArgumentException(label + "格式应为 yyyy-MM-dd", ex); + } + } +} diff --git a/src/main/java/com/xujie/modules/order/vo/SupplierNewProductHistoryQuery.java b/src/main/java/com/xujie/modules/order/vo/SupplierNewProductHistoryQuery.java new file mode 100644 index 0000000..418f201 --- /dev/null +++ b/src/main/java/com/xujie/modules/order/vo/SupplierNewProductHistoryQuery.java @@ -0,0 +1,15 @@ +package com.xujie.modules.order.vo; + +import lombok.Data; + +@Data +public class SupplierNewProductHistoryQuery { + private String shortOffice; + private String shortNpc; + private String basePartNo; + private String sku; + private String orderDateStart; + private String orderDateEnd; + private Integer page = 1; + private Integer limit = 20; +}