Commit 69969693 authored by chew's avatar chew

增加追溯码客户商品信息

parent 3d0659cd
...@@ -98,6 +98,13 @@ ...@@ -98,6 +98,13 @@
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- JUnit 4(兼容 surefire 2.12.4 默认版本,单元测试使用)-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
......
...@@ -2,17 +2,36 @@ package com.ekingwin.tms_app.common.config; ...@@ -2,17 +2,36 @@ package com.ekingwin.tms_app.common.config;
import com.ekingwin.tms_app.common.interceptor.JwtInterceptor; import com.ekingwin.tms_app.common.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.File;
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
@Autowired @Autowired
private JwtInterceptor jwtInterceptor; private JwtInterceptor jwtInterceptor;
/** 文件上传根目录 */
@Value("${app.upload-dir:./upload/}")
private String uploadDir;
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor).addPathPatterns("/**"); registry.addInterceptor(jwtInterceptor).addPathPatterns("/**");
} }
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 上传文件访问映射:/upload/** -> 本地 upload 目录
String location = new File(uploadDir).getAbsolutePath();
if (!location.endsWith(File.separator)) {
location = location + File.separator;
}
registry.addResourceHandler("/upload/**")
.addResourceLocations("file:" + location);
}
} }
...@@ -25,8 +25,9 @@ public class JwtInterceptor implements HandlerInterceptor { ...@@ -25,8 +25,9 @@ public class JwtInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String path = request.getRequestURI(); String path = request.getRequestURI();
System.out.println(">>> [DEBUG] JwtInterceptor 拦截到请求: " + path); // <--- System.out.println(">>> [DEBUG] JwtInterceptor 拦截到请求: " + path); // <---
// 白名单:以 /auth/login、/auth/logout 结尾,或包含 /actuator // 白名单:上传的静态资源(应用图标等)、登录/登出、actuator
if (path.endsWith("/auth/login") || path.endsWith("/auth/logout") || path.contains("/actuator")) { if (path.contains("/upload/")
|| path.endsWith("/auth/login") || path.endsWith("/auth/logout") || path.contains("/actuator")) {
return true; return true;
} }
String authHeader = request.getHeader("Authorization"); String authHeader = request.getHeader("Authorization");
......
package com.ekingwin.tms_app.dispatchui.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* 界面查询基础请求(机构/仓库/配送日期)
*/
@Data
public class BaseQueryReq {
/** 机构ID */
@NotBlank(message = "机构ID不能为空")
private String orgId;
/** 仓库ID */
@NotBlank(message = "仓库ID不能为空")
private String warehouseId;
/** 配送日期 */
@NotNull(message = "配送日期不能为空")
private Date deliverDate;
}
package com.ekingwin.tms_app.module.admin.controller;
import com.ekingwin.tms_app.common.dto.PageResult;
import com.ekingwin.tms_app.common.dto.Result;
import com.ekingwin.tms_app.module.admin.dto.AppAddReq;
import com.ekingwin.tms_app.module.admin.dto.AppIdReq;
import com.ekingwin.tms_app.module.admin.dto.AppQueryReq;
import com.ekingwin.tms_app.module.admin.dto.AppUpdateReq;
import com.ekingwin.tms_app.module.admin.service.AppService;
import com.ekingwin.tms_app.module.admin.vo.AppMenuVo;
import com.ekingwin.tms_app.module.admin.vo.AppVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
/**
* 应用管理接口(管理平台 + APP菜单)
*/
@Log4j2
@RestController
@RequestMapping("/admin/app")
public class AppController {
@Autowired
private AppService appService;
/**
* 新增应用
*/
@PostMapping("/add")
public Result<Long> add(@RequestBody @Valid AppAddReq req,
@RequestAttribute("userId") String userId) {
log.info("新增应用:operator={}, req={}", userId, req);
return Result.success(appService.addApp(req, userId));
}
/**
* 修改应用
*/
@PostMapping("/update")
public Result<Void> update(@RequestBody @Valid AppUpdateReq req,
@RequestAttribute("userId") String userId) {
appService.updateApp(req, userId);
return Result.success(null);
}
/**
* 删除应用
*/
@PostMapping("/delete")
public Result<Void> delete(@RequestBody @Valid AppIdReq req) {
appService.deleteApp(req.getAppId());
return Result.success(null);
}
/**
* 发布应用
*/
@PostMapping("/publish")
public Result<Void> publish(@RequestBody @Valid AppIdReq req) {
appService.publishApp(req.getAppId());
return Result.success(null);
}
/**
* 下架应用
*/
@PostMapping("/offline")
public Result<Void> offline(@RequestBody @Valid AppIdReq req) {
appService.offlineApp(req.getAppId());
return Result.success(null);
}
/**
* 应用分页查询(管理端)
*/
@PostMapping("/page")
public Result<PageResult<AppVo>> page(@RequestBody @Valid AppQueryReq req) {
return Result.success(appService.pageApps(req));
}
/**
* 应用图标上传
*/
@PostMapping("/uploadIcon")
public Result<Map<String, String>> uploadIcon(@RequestParam("file") MultipartFile file) {
String url = appService.uploadIcon(file);
return Result.success(java.util.Collections.singletonMap("url", url));
}
/**
* APP菜单接口:根据登录用户以及平台类型查询(过滤已下架应用)
* 请求示例:GET /admin/app/menu?platformType=WEB
*/
@GetMapping("/menu")
public Result<List<AppMenuVo>> menu(@RequestParam(value = "platformType", required = false) String platformType,
@RequestAttribute("userId") String userId) {
log.info("APP菜单查询:userId={}, platformType={}", userId, platformType);
return Result.success(appService.getAppMenu(userId, platformType));
}
}
package com.ekingwin.tms_app.module.admin.service.impl;
import com.ekingwin.tms_app.common.dto.PageResult;
import com.ekingwin.tms_app.common.util.RedisUtil;
import com.ekingwin.tms_app.module.admin.dao.AdminUserMapper;
import com.ekingwin.tms_app.module.admin.dao.AppUserLockMapper;
import com.ekingwin.tms_app.module.admin.dto.UserQueryReq;
import com.ekingwin.tms_app.module.admin.entity.AppUserLock;
import com.ekingwin.tms_app.module.admin.service.AdminUserService;
import com.ekingwin.tms_app.module.admin.vo.UserAdminVo;
import com.ekingwin.tms_app.module.auth.dao.UserMapper;
import com.ekingwin.tms_app.module.auth.entity.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 管理平台-用户管理Service实现
* 说明:bsm_user 用户表只读,锁定状态写入 app_user_lock 表并同步 Redis
*/
@Service
@Log4j2
public class AdminUserServiceImpl implements AdminUserService {
@Autowired
private AdminUserMapper adminUserMapper;
@Autowired
private AppUserLockMapper appUserLockMapper;
@Autowired
private UserMapper userMapper;
@Autowired
private RedisUtil redisUtil;
@Override
public PageResult<UserAdminVo> pageUsers(UserQueryReq req) {
PageHelper.startPage(req.getPageNum(), req.getPageSize());
List<UserAdminVo> list = adminUserMapper.selectUserPage(req.getKeyword(),
req.getHasLoggedIn(), req.getLocked());
PageInfo<UserAdminVo> pageInfo = new PageInfo<>(list);
return PageResult.of(pageInfo.getTotal(), pageInfo.getList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void lockUser(String userId, String operatorId) {
User user = userMapper.selectById(userId);
if (user == null) {
throw new RuntimeException("用户不存在:" + userId);
}
// 1. 写入 app_user_lock 表(bsm_user 只读,不修改)
AppUserLock lock = appUserLockMapper.selectById(userId);
Date now = new Date();
if (lock == null) {
lock = new AppUserLock();
lock.setUserId(userId);
lock.setLockStatus(1);
lock.setLockBy(operatorId);
lock.setLockTime(now);
appUserLockMapper.insert(lock);
} else {
lock.setLockStatus(1);
lock.setLockBy(operatorId);
lock.setLockTime(now);
appUserLockMapper.updateById(lock);
}
// 2. 同步设置 Redis 锁定标记,与登录失败锁定保持一致
redisUtil.set("login:lock:" + userId, "locked", 24 * 60, TimeUnit.MINUTES);
log.info("管理员[{}]锁定用户[{}]", operatorId, userId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void unlockUser(String userId, String operatorId) {
User user = userMapper.selectById(userId);
if (user == null) {
throw new RuntimeException("用户不存在:" + userId);
}
// 1. 更新 app_user_lock 表(bsm_user 只读,不修改)
AppUserLock lock = appUserLockMapper.selectById(userId);
Date now = new Date();
if (lock != null) {
lock.setLockStatus(0);
lock.setUnlockBy(operatorId);
lock.setUnlockTime(now);
appUserLockMapper.updateById(lock);
} else {
lock = new AppUserLock();
lock.setUserId(userId);
lock.setLockStatus(0);
lock.setUnlockBy(operatorId);
lock.setUnlockTime(now);
appUserLockMapper.insert(lock);
}
// 2. 清除 Redis 锁定标记和失败计数
redisUtil.delete("login:lock:" + userId);
redisUtil.delete("login:fail:count:" + userId);
log.info("管理员[{}]解锁用户[{}]", operatorId, userId);
}
}
...@@ -3,6 +3,8 @@ package com.ekingwin.tms_app.module.auth.service.impl; ...@@ -3,6 +3,8 @@ package com.ekingwin.tms_app.module.auth.service.impl;
import com.ekingwin.tms_app.common.config.SecurityConfig; import com.ekingwin.tms_app.common.config.SecurityConfig;
import com.ekingwin.tms_app.common.util.JwtUtil; import com.ekingwin.tms_app.common.util.JwtUtil;
import com.ekingwin.tms_app.common.util.RedisUtil; import com.ekingwin.tms_app.common.util.RedisUtil;
import com.ekingwin.tms_app.module.admin.dao.AppUserLockMapper;
import com.ekingwin.tms_app.module.admin.entity.AppUserLock;
import com.ekingwin.tms_app.module.auth.dao.UserCredentialMapper; import com.ekingwin.tms_app.module.auth.dao.UserCredentialMapper;
import com.ekingwin.tms_app.module.auth.dao.UserMapper; import com.ekingwin.tms_app.module.auth.dao.UserMapper;
import com.ekingwin.tms_app.module.auth.dto.LoginReq; import com.ekingwin.tms_app.module.auth.dto.LoginReq;
...@@ -32,6 +34,8 @@ public class AuthServiceImpl implements AuthService { ...@@ -32,6 +34,8 @@ public class AuthServiceImpl implements AuthService {
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@Autowired @Autowired
private SecurityConfig securityConfig; private SecurityConfig securityConfig;
@Autowired
private AppUserLockMapper appUserLockMapper;
private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
...@@ -42,6 +46,12 @@ public class AuthServiceImpl implements AuthService { ...@@ -42,6 +46,12 @@ public class AuthServiceImpl implements AuthService {
} }
String userId = user.getUserid(); String userId = user.getUserid();
// 0. 管理员锁定检查(app_user_lock 表:1-锁定;bsm_user 只读,不修改)
Integer lockStatus = appUserLockMapper.selectLockStatus(userId);
if (lockStatus != null && lockStatus == 1) {
throw new RuntimeException("账号已被管理员锁定,请联系管理员解锁");
}
// 1. 锁定检查(Redis) // 1. 锁定检查(Redis)
String lockKey = "login:lock:" + userId; String lockKey = "login:lock:" + userId;
if (Boolean.TRUE.equals(redisUtil.hasKey(lockKey))) { if (Boolean.TRUE.equals(redisUtil.hasKey(lockKey))) {
...@@ -143,10 +153,18 @@ public class AuthServiceImpl implements AuthService { ...@@ -143,10 +153,18 @@ public class AuthServiceImpl implements AuthService {
if (operator == null || !isAdmin(operator)) { if (operator == null || !isAdmin(operator)) {
throw new RuntimeException("无权限执行解锁操作,仅管理员可操作"); throw new RuntimeException("无权限执行解锁操作,仅管理员可操作");
} }
// 2. 清除锁定标记 // 2. 更新 app_user_lock 表锁定状态(bsm_user 只读,不修改)
AppUserLock lock = appUserLockMapper.selectById(targetUserId);
if (lock != null) {
lock.setLockStatus(0);
lock.setUnlockBy(operatorId);
lock.setUnlockTime(new Date());
appUserLockMapper.updateById(lock);
}
// 3. 清除锁定标记
String lockKey = "login:lock:" + targetUserId; String lockKey = "login:lock:" + targetUserId;
redisUtil.delete(lockKey); redisUtil.delete(lockKey);
// 3. 清除失败计数(可选) // 4. 清除失败计数(可选)
String failKey = "login:fail:count:" + targetUserId; String failKey = "login:fail:count:" + targetUserId;
redisUtil.delete(failKey); redisUtil.delete(failKey);
} }
......
package com.ekingwin.tms_app.module.cargo.outbound.controller; package com.ekingwin.tms_app.module.cargo.outbound.controller;
import com.ekingwin.tms_app.common.dto.Result; import com.ekingwin.tms_app.common.dto.Result;
import com.ekingwin.tms_app.module.cargo.outbound.dto.CustomerScanHeaderQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.CustomerScanQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateReq; import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateResp; import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateResp;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeAdminUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeMyQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeSaveReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteReq; import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteResp; import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteResp;
import com.ekingwin.tms_app.module.cargo.outbound.service.OutboundOrderService;
import com.ekingwin.tms_app.module.cargo.outbound.service.ScanService; import com.ekingwin.tms_app.module.cargo.outbound.service.ScanService;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanDetailVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanHeaderVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeListsVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -17,6 +26,7 @@ import javax.validation.Valid; ...@@ -17,6 +26,7 @@ import javax.validation.Valid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@Log4j2 @Log4j2
@RestController @RestController
@RequestMapping("/cargo/outbound/scan") @RequestMapping("/cargo/outbound/scan")
...@@ -24,40 +34,35 @@ public class ScanController { ...@@ -24,40 +34,35 @@ public class ScanController {
@Autowired @Autowired
private ScanService scanService; private ScanService scanService;
// ===================== 扫码/人工业绩 =====================
@PostMapping("/execute") @PostMapping("/execute")
public Result<ScanExecuteResp> executeScan(@RequestBody @Valid ScanExecuteReq req, public Result<ScanExecuteResp> executeScan(@RequestBody @Valid ScanExecuteReq req,
@RequestAttribute("userId") String userId) { @RequestAttribute("userId") String userId) {
return Result.success(scanService.executeScan(req, userId));
//根据码的类判断去订单表查询
return Result.success(scanService.executeScan(req,userId));
} }
@PostMapping("/manual/update") @PostMapping("/manual/update")
public Result<List<ManualTallyUpdateResp>> manualTallyUpdate(@RequestBody @Valid List<ManualTallyUpdateReq> reqList) { public Result<List<ManualTallyUpdateResp>> manualTallyUpdate(@RequestBody @Valid List<ManualTallyUpdateReq> reqList) {
if (CollectionUtils.isEmpty(reqList)) { if (CollectionUtils.isEmpty(reqList)) {
return Result.success(Collections.emptyList()); return Result.success(Collections.emptyList());
} }
List<ManualTallyUpdateResp> resultList = new ArrayList<>(); List<ManualTallyUpdateResp> resultList = new ArrayList<>();
for (ManualTallyUpdateReq req : reqList) { for (ManualTallyUpdateReq req : reqList) {
ManualTallyUpdateResp resp = new ManualTallyUpdateResp(); ManualTallyUpdateResp resp = new ManualTallyUpdateResp();
resp.setOrderNo(req.getOrderNo().toString()); // 假设 req 有 orderNo 字段 resp.setOrderNo(req.getOrderNo().toString());
try { try {
ManualTallyUpdateResp serviceResp = scanService.manualTallyUpdate(req); ManualTallyUpdateResp serviceResp = scanService.manualTallyUpdate(req);
// 如果 service 返回了结果,直接使用 if (StringUtils.isNotBlank(serviceResp.getResult())) {
if ( StringUtils.isNotBlank(serviceResp.getResult()) ) { if ("500".equals(serviceResp.getResult())) {
if (serviceResp.getResult().equals("500")){
resp.setMassage(serviceResp.getMassage()); resp.setMassage(serviceResp.getMassage());
resp.setSuccess("500"); resp.setSuccess("500");
} }
if (serviceResp.getResult().equals("000")){ if ("000".equals(serviceResp.getResult())) {
resp.setSuccess("200"); resp.setSuccess("200");
} }
resp.setOrderNo(serviceResp.getOrderNo()); resp.setOrderNo(serviceResp.getOrderNo());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("人工理货更新失败, orderNo: {}", req.getOrderNo(), e); log.error("人工理货更新失败, orderNo: {}", req.getOrderNo(), e);
...@@ -66,7 +71,147 @@ public class ScanController { ...@@ -66,7 +71,147 @@ public class ScanController {
} }
resultList.add(resp); resultList.add(resp);
} }
return Result.success(resultList); return Result.success(resultList);
} }
/** 客户编码查询:查询指定客户下未完成扫描的订单明细 */
@PostMapping("/customer/pending")
public Result<List<CustomerScanDetailVo>> queryCustomerScanDetail(@RequestBody @Valid CustomerScanQueryReq req,
@RequestAttribute("userId") String userId) {
if (StringUtils.isBlank(req.getCustomerCode())) {
return Result.error("客户编码不能为空");
}
return Result.success(scanService.queryCustomerScanDetail(req, userId));
}
/**
* 客户订单头查询(订单头维度,关联 T_DOC_OUTBOUND_SCAN_ORDERTYPE)
*
* 业务逻辑:
* - INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE:仅显示当前用户偏好 ORDERTYPE 的订单头
* - scanUser 不传时默认用 token.userId
* - 必含 IS_ODD_LOT='C' 明细行
*
* 注意:本接口不要求 customerCode,与 /customer/pending 的"按客户筛选"不同。
* 适用于「我的待处理订单(按订单类型过滤)」场景。
*/
@PostMapping("/customer/header/list")
public Result<List<CustomerScanHeaderVo>> queryCustomerScanHeader(@RequestBody(required = false) CustomerScanHeaderQueryReq req,
@RequestAttribute("userId") String userId) {
if (req == null) {
req = new CustomerScanHeaderQueryReq();
}
return Result.success(scanService.queryCustomerScanHeader(req, userId));
}
// ===================== 订单类型(SCAN_USER 为主键,每人一行) =====================
/**
* a. 订单类型聚合查询(前端 3 个下拉)
* 数据源:T_DOC_OUTBOUND_SCAN_HEADER,按 (orderType, reference5, temperatureclass) GROUP BY 后
* 在 service 层扁平化为 3 个 distinct 值列表
* 用于前端 3 个下拉控件:orderType / reference5 / temperatureclass
* 缓存:Redis 5 分钟
*/
@PostMapping("/orderType/list")
public Result<OrderTypeListsVo> queryOrderTypeGroup() {
return Result.success(scanService.queryOrderTypeGroup());
}
/**
* b. 订单类型保存(UPSERT by SCAN_USER)
* 人员 ID 取自 token,每个人只有一行记录
* 已存在则更新 ORDER_TYPE,不存在则插入新行
* @return 该人员的 REC_ID
*/
@PostMapping("/orderType/save")
public Result<String> saveOrderType(@RequestBody @Valid OrderTypeSaveReq req,
@RequestAttribute("userId") String userId) {
String recId = scanService.saveOrderType(req, userId);
return Result.success(recId);
}
/**
* d. 查询当前人员的"当前选择"
* 人员 ID 取自 token,返回该人员的当前订单类型(0 或 1 条)
*/
@PostMapping("/orderType/my/list")
public Result<OrderTypeRecordVo> queryMyOrderType(@RequestBody(required = false) OrderTypeMyQueryReq req,
@RequestAttribute("userId") String userId) {
return Result.success(scanService.queryMyOrderType(userId));
}
/**
* e. 删除当前人员的"当前选择"
* 限本人:天然防越权(WHERE SCAN_USER = 当前用户)
*/
@PostMapping("/orderType/delete")
public Result<Boolean> deleteMyOrderType(@RequestAttribute("userId") String userId) {
boolean ok = scanService.deleteMyOrderType(userId);
if (!ok) {
return Result.error("当前用户没有订单类型选择记录");
}
return Result.success(Boolean.TRUE);
}
/**
* f. 更新当前人员的"当前选择"
* 不依赖数据库 recId,按 SCAN_USER 定位
* 已存在则更新,不存在则插入(与 b 接口语义等价)
*/
@PostMapping("/orderType/update")
public Result<Boolean> updateOrderType(@RequestBody @Valid OrderTypeUpdateReq req,
@RequestAttribute("userId") String userId) {
scanService.updateOrderType(req, userId);
return Result.success(Boolean.TRUE);
}
/**
* g. 按 recId 查单条记录
* 用于后台调试或按 recId 直接查询
*/
@PostMapping("/orderType/get")
public Result<OrderTypeRecordVo> getOrderType(@RequestParam("recId") String recId) {
OrderTypeRecordVo vo = scanService.getOrderTypeByRecId(recId);
if (vo == null) {
return Result.error("记录不存在:recId=" + recId);
}
return Result.success(vo);
}
/**
* h. 管理员用:全量选择列表
* 表每人一行,数据量小无需分页
* 返回所有人员的"当前选择"(用于后台监控/统计)
*/
@PostMapping("/orderType/all")
public Result<List<OrderTypeRecordVo>> queryAllOrderTypes() {
return Result.success(scanService.queryAllOrderTypes());
}
/**
* i. 管理员用:按 ORDER_TYPE 分组统计人数
* 返回 Map<ORDER_TYPE, 人数>
* 配合 a 接口的"订单数"统计使用:
* - a 返回订单数(来自 SCAN_HEADER GROUP BY)
* - i 返回偏好人数(来自 ORDERTYPE GROUP BY)
* - 二者对比可看出"该类型单量 vs 偏好该类型的人数"
*/
@PostMapping("/orderType/count")
public Result<java.util.Map<String, Integer>> countByOrderType() {
return Result.success(scanService.countByOrderType());
}
/**
* j. 管理员代改任意人员的当前选择
* 支持场景:"用户选错了,管理员帮改"
* 入参:scanUser(被改的人员)+ orderType
* 复用原子 MERGE + 清缓存
*/
@PostMapping("/orderType/admin/update")
public Result<String> adminUpdateOrderType(@RequestBody @Valid OrderTypeAdminUpdateReq req) {
String recId = scanService.adminUpsertOrderType(req.getScanUser(),
req.getOrderType(), req.getReference5(), req.getTemperatureclass());
return Result.success(recId);
}
} }
package com.ekingwin.tms_app.module.cargo.outbound.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ekingwin.tms_app.module.cargo.outbound.entity.OutboundOrderTypeRecord;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface OutboundOrderTypeRecordMapper extends BaseMapper<OutboundOrderTypeRecord> {
/**
* 获取订单类型选择表主键(Oracle 序列 SEQ_T_DOC_OUTBOUND_SCAN_ORDERTYPE)
* 需在数据库中预先创建序列(见 sql/outbound_ordertype.sql)
*/
@Select("SELECT SEQ_T_DOC_OUTBOUND_SCAN_ORDERTYPE.NEXTVAL FROM DUAL")
String nextId();
/**
* 按人员 ID 查询该人员的"当前选择"
* 表 SCAN_USER 上有 UNIQUE 约束,最多返回 1 条
* 用于 d 接口(/orderType/my/list)和 save 时的存在性判断
*/
OrderTypeRecordVo selectByScanUser(@Param("scanUser") String scanUser);
/**
* 按人员 ID 删除该人员的"当前选择"
* 简单物理删除,因为每人最多一条
*/
int deleteByScanUser(@Param("scanUser") String scanUser);
/**
* 原子 UPSERT(Oracle MERGE)
* - 已存在 (SCAN_USER) → UPDATE ORDER_TYPE, REFERENCE5, TEMPERATURECLASS, UPDATE_TIME=SYSDATE
* - 不存在 → INSERT 新行(REC_ID 由序列生成)
* 解决 SELECT-then-INSERT/UPDATE 模式的并发竞态
*
* 三个业务字段均可传 null/空串(表示"不过滤该字段")
*/
void upsertByScanUser(@Param("scanUser") String scanUser,
@Param("orderType") String orderType,
@Param("reference5") String reference5,
@Param("temperatureclass") String temperatureclass);
/**
* 取指定人员的 REC_ID(用于 UPSERT 后回传)
*/
String selectRecIdByScanUser(@Param("scanUser") String scanUser);
/**
* 按 recId 查单条记录(保留此接口以便调试/后台查询)
*/
OrderTypeRecordVo selectByRecId(@Param("recId") String recId);
/**
* 全量列表(管理员用,按更新时间倒序)
* 表很小(每人一行),无需分页
*/
List<OrderTypeRecordVo> selectAll();
/**
* 按 ORDERTYPE 分组统计人数
* 配合 a 接口的"订单数"统计,可对比"订单数 vs 偏好人数"
*/
java.util.Map<String, Integer> countGroupByOrderType();
}
package com.ekingwin.tms_app.module.cargo.outbound.dao; package com.ekingwin.tms_app.module.cargo.outbound.dao;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanDetailVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanHeaderVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map; import java.util.Map;
@Mapper @Mapper
...@@ -12,4 +16,50 @@ public interface ScanMapper { ...@@ -12,4 +16,50 @@ public interface ScanMapper {
* 调用人工理货更新存储过程 * 调用人工理货更新存储过程
*/ */
void callManualTallyUpdate(Map<String, Object> params); void callManualTallyUpdate(Map<String, Object> params);
/**
* 按客户编码查询未完成扫描的订单明细
* 可选按 orderType / reference5 / temperatureclass 过滤
* - 字段为 null/空串时不过滤该字段(XML 中 if 判断跳过)
* - 字段非空时按 INSTR 逗号包含匹配(兼容 SCAN_HEADER 单值 vs 偏好逗号分隔多值)
*/
List<CustomerScanDetailVo> selectCustomerScanDetail(@Param("customerCode") String customerCode,
@Param("scanUser") String scanUser,
@Param("orderType") String orderType,
@Param("reference5") String reference5,
@Param("temperatureclass") String temperatureclass);
/**
* 查询 T_DOC_OUTBOUND_SCAN_HEADER 中所有出现过的 ORDERTYPE distinct 值(按字典序 ASC)
* 用于 /orderType/list 接口的第一个 list
*/
List<String> selectDistinctOrderType();
/**
* 查询 T_DOC_OUTBOUND_SCAN_HEADER 中所有出现过的 REFERENCE5 distinct 值(按字典序 ASC)
* 用于 /orderType/list 接口的第二个 list
*/
List<String> selectDistinctReference5();
/**
* 查询 T_DOC_OUTBOUND_SCAN_HEADER 中所有出现过的 TEMPERATURECLASS distinct 值(按字典序 ASC)
* 用于 /orderType/list 接口的第三个 list
*/
List<String> selectDistinctTemperatureclass();
/**
* 按客户编码查询订单头列表(订单头维度)
*
* 过滤条件:
* 1. EXISTS 至少一行明细 IS_ODD_LOT = 'C'
* 2. INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE:仅返回与该扫描员偏好 ORDERTYPE 匹配的订单头
* 3. 可选:customerName 模糊 / orderNo 精确 / statusList IN / scanUser 精确
*
* 注意:scanUser 必传(service 层兜底为 token.userId),
* 这样 INNER JOIN 才有匹配的 SCAN_USER 值。
*/
List<CustomerScanHeaderVo> selectCustomerScanHeader(@Param("customerName") String customerName,
@Param("orderNo") String orderNo,
@Param("statusList") List<String> statusList,
@Param("scanUser") String scanUser);
} }
...@@ -24,6 +24,8 @@ public class OutboundOrderHeader { ...@@ -24,6 +24,8 @@ public class OutboundOrderHeader {
private Date createTime; private Date createTime;
private Date updateTime; private Date updateTime;
private String scanUser; private String scanUser;
// 订单类型(用于读取 T_DOC_outbound_scan_HEADER.ORDERTYPE,写入请使用 T_DOC_OUTBOUND_SCAN_ORDERTYPE 表)
private String orderType;
@TableField(exist = false) @TableField(exist = false)
private List<OutboundOrderDetail> list; private List<OutboundOrderDetail> list;
} }
\ No newline at end of file
package com.ekingwin.tms_app.module.cargo.outbound.entity;
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.util.Date;
/**
* 出库订单类型选择表实体(简化版)
* 对应 T_DOC_OUTBOUND_SCAN_ORDERTYPE
* 设计:每人一行(SCAN_USER 上有 UNIQUE 约束),记录该人员当前选定的偏好
* 业务字段(orderType / reference5 / temperatureclass)均可为空:
* - 存逗号分隔多值时按包含匹配
* - 字段为 null 或空串时表示"不过滤该字段"(关联查询走全集)
* 更新策略:按 SCAN_USER 定位(不用 recId),即为「我的当前选择」
*/
@Data
@TableName("T_DOC_OUTBOUND_SCAN_ORDERTYPE")
public class OutboundOrderTypeRecord {
/** 主键 ID(SEQ_T_DOC_OUTBOUND_SCAN_ORDERTYPE) */
@TableId(value = "REC_ID", type = IdType.INPUT)
private String recId;
/** 人员 ID(取自 JWT userId,唯一) */
private String scanUser;
/** 订单类型(可空,逗号分隔多值) */
private String orderType;
/** 参考 5(可空,逗号分隔多值) */
@TableField("REFERENCE5")
private String reference5;
/** 温度类别(可空,逗号分隔多值) */
@TableField("TEMPERATURECLASS")
private String temperatureclass;
/** 首次保存时间(默认 SYSDATE) */
@TableField(value = "CREATE_TIME")
private Date createTime;
/** 最近更新时间 */
@TableField(value = "UPDATE_TIME")
private Date updateTime;
}
package com.ekingwin.tms_app.module.cargo.outbound.service; package com.ekingwin.tms_app.module.cargo.outbound.service;
import com.ekingwin.tms_app.module.cargo.outbound.dto.CustomerScanHeaderQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.CustomerScanQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateReq; import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateResp; import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateResp;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeSaveReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteReq; import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteResp; import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteResp;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanDetailVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanHeaderVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeListsVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo;
public interface ScanService { public interface ScanService {
ScanExecuteResp executeScan(ScanExecuteReq req,String userId); ScanExecuteResp executeScan(ScanExecuteReq req, String userId);
ManualTallyUpdateResp manualTallyUpdate(ManualTallyUpdateReq req); ManualTallyUpdateResp manualTallyUpdate(ManualTallyUpdateReq req);
java.util.List<CustomerScanDetailVo> queryCustomerScanDetail(CustomerScanQueryReq req, String userId);
/**
* 客户订单头查询(订单头维度)
*
* 业务逻辑:
* - 关联 T_DOC_OUTBOUND_SCAN_ORDERTYPE(INNER JOIN),按偏好 (orderType, reference5, temperatureclass) 过滤
* 每个偏好字段独立判断:空时不过滤该字段,非空时按 INSTR 逗号包含匹配
* - scanUser 兜底为 token.userId
* - customerName 模糊、orderNo 精确、statusList IN 可选
* - 要求 header 至少存在一行 IS_ODD_LOT='C' 的明细(EXISTS 校验)
*/
java.util.List<CustomerScanHeaderVo> queryCustomerScanHeader(CustomerScanHeaderQueryReq req, String userId);
/**
* a. 订单类型聚合查询(前端 3 个下拉)
* 返回 OrderTypeListsVo:单一对象包 orderType / reference5 / temperatureclass 三个 distinct 值列表
* 数据源:T_DOC_OUTBOUND_SCAN_HEADER;Redis 5min 缓存
* 内部缓存仍按三元组 GROUP BY 存,service 出参前扁平化为 3 个独立 list
*/
OrderTypeListsVo queryOrderTypeGroup();
/** b. 订单类型保存(业务键:SCAN_USER,UPSERT),三个业务字段均可传 null/空串 */
String saveOrderType(OrderTypeSaveReq req, String userId);
/** d. 查询当前人员的"当前选择"(返回 0 或 1 条,含 reference5/temperatureclass) */
OrderTypeRecordVo queryMyOrderType(String userId);
/** e. 删除当前人员的"当前选择" */
boolean deleteMyOrderType(String userId);
/** f. 更新当前人员的"当前选择"(与 b 语义等价) */
boolean updateOrderType(OrderTypeUpdateReq req, String userId);
/** g. 按 recId 查单条记录 */
OrderTypeRecordVo getOrderTypeByRecId(String recId);
/** h. 管理员用:全量选择列表 */
java.util.List<OrderTypeRecordVo> queryAllOrderTypes();
/** i. 管理员用:按 ORDER_TYPE 分组统计人数(拆逗号) */
java.util.Map<String, Integer> countByOrderType();
/** j. 管理员代改:更新指定人员的当前选择(支持任意 scanUser),三个业务字段均可传 null/空串 */
String adminUpsertOrderType(String scanUser, String orderType, String reference5, String temperatureclass);
} }
package com.ekingwin.tms_app.module.cargo.outbound.service.impl; package com.ekingwin.tms_app.module.cargo.outbound.service.impl;
import com.ekingwin.tms_app.common.util.RedisUtil;
import com.ekingwin.tms_app.module.cargo.outbound.dao.OutboundOrderTypeRecordMapper;
import com.ekingwin.tms_app.module.cargo.outbound.dao.ScanMapper; import com.ekingwin.tms_app.module.cargo.outbound.dao.ScanMapper;
import com.ekingwin.tms_app.module.cargo.outbound.dto.*; import com.ekingwin.tms_app.module.cargo.outbound.dto.CustomerScanHeaderQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.CustomerScanQueryReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ItemDetail;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ManualTallyUpdateResp;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeSaveReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.OrderTypeUpdateReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteReq;
import com.ekingwin.tms_app.module.cargo.outbound.dto.ScanExecuteResp;
import com.ekingwin.tms_app.module.cargo.outbound.service.ScanService; import com.ekingwin.tms_app.module.cargo.outbound.service.ScanService;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanDetailVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanHeaderVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeListsVo;
import com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -15,27 +32,37 @@ import java.util.Map; ...@@ -15,27 +32,37 @@ import java.util.Map;
@Log4j2 @Log4j2
public class ScanServiceImpl implements ScanService { public class ScanServiceImpl implements ScanService {
/** 订单类型下拉 Redis 缓存 key(含 orderType/reference5/temperatureclass 三个 distinct list) */
private static final String CACHE_KEY_ORDER_TYPE_GROUP = "tms:outbound:orderType:lists";
/** 缓存过期时间:5 分钟(订单类型变化频率低,可容忍一定延迟) */
private static final long CACHE_TTL_SECONDS = 5 * 60L;
@Autowired @Autowired
private ScanMapper scanMapper; private ScanMapper scanMapper;
@Autowired
private OutboundOrderTypeRecordMapper orderTypeRecordMapper;
@Autowired
private RedisUtil redisUtil;
// ===================== 扫码/人工业绩 =====================
@Override @Override
public ScanExecuteResp executeScan(ScanExecuteReq req,String userId) { public ScanExecuteResp executeScan(ScanExecuteReq req, String userId) {
// 1. 构造参数 Map
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("P_AUTO_CONFIRM", "Y"); params.put("P_AUTO_CONFIRM", "Y");
params.put("p_scan_code", req.getScanCode()); params.put("p_scan_code", req.getScanCode());
// 输出参数占位,MyBatis 会自动填充 params.put("p_out_scan_type", null);
params.put("p_out_scan_type", userId); params.put("p_user_id", userId);
params.put("p_user_id", null);
params.put("p_out_match_type", null); params.put("p_out_match_type", null);
params.put("p_out_items", null); params.put("p_out_items", null);
params.put("p_out_result", null); params.put("p_out_result", null);
params.put("p_out_message", null); params.put("p_out_message", null);
log.info(params.toString()); log.info(params.toString());
// 2. 调用存储过程
scanMapper.executeScan(params); scanMapper.executeScan(params);
// 3. 提取输出参数
ScanExecuteResp resp = new ScanExecuteResp(); ScanExecuteResp resp = new ScanExecuteResp();
resp.setScanType((String) params.get("p_out_scan_type")); resp.setScanType((String) params.get("p_out_scan_type"));
resp.setMatchType((String) params.get("p_out_match_type")); resp.setMatchType((String) params.get("p_out_match_type"));
...@@ -45,7 +72,6 @@ public class ScanServiceImpl implements ScanService { ...@@ -45,7 +72,6 @@ public class ScanServiceImpl implements ScanService {
return resp; return resp;
} }
@Override @Override
public ManualTallyUpdateResp manualTallyUpdate(ManualTallyUpdateReq req) { public ManualTallyUpdateResp manualTallyUpdate(ManualTallyUpdateReq req) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
...@@ -53,7 +79,6 @@ public class ScanServiceImpl implements ScanService { ...@@ -53,7 +79,6 @@ public class ScanServiceImpl implements ScanService {
params.put("p_detail_ids", req.getDetailIds()); params.put("p_detail_ids", req.getDetailIds());
params.put("p_tally_qty", req.getTallyQtys()); params.put("p_tally_qty", req.getTallyQtys());
params.put("p_status_flag", req.getStatusFlag()); params.put("p_status_flag", req.getStatusFlag());
// 输出参数占位
params.put("p_out_result", null); params.put("p_out_result", null);
params.put("p_out_message", null); params.put("p_out_message", null);
...@@ -64,4 +89,247 @@ public class ScanServiceImpl implements ScanService { ...@@ -64,4 +89,247 @@ public class ScanServiceImpl implements ScanService {
resp.setMassage((String) params.get("p_out_message")); resp.setMassage((String) params.get("p_out_message"));
return resp; return resp;
} }
@Override
public List<CustomerScanDetailVo> queryCustomerScanDetail(CustomerScanQueryReq req, String userId) {
// 默认按当前用户的偏好过滤(关联 T_DOC_OUTBOUND_SCAN_ORDERTYPE:orderType/reference5/temperatureclass)
// 显式传入 orderType 时优先使用(其余两个字段仍走偏好;如需全覆盖可手动改 XML)
String orderType = req.getOrderType();
String reference5 = null;
String temperatureclass = null;
if (orderType == null || orderType.isEmpty()) {
OrderTypeRecordVo myType = orderTypeRecordMapper.selectByScanUser(userId);
if (myType != null) {
orderType = myType.getOrderType();
reference5 = myType.getReference5();
temperatureclass = myType.getTemperatureclass();
log.debug("客户查询使用用户偏好 orderType={}, reference5={}, temperatureclass={}, userId={}",
orderType, reference5, temperatureclass, userId);
}
}
return scanMapper.selectCustomerScanDetail(req.getCustomerCode(), userId,
orderType, reference5, temperatureclass);
}
@Override
public List<CustomerScanHeaderVo> queryCustomerScanHeader(CustomerScanHeaderQueryReq req, String userId) {
// 1. 前置:用户必须有订单类型偏好记录
// (INNER JOIN ORDERTYPE 表:偏好缺失则无匹配,结果集为空)
OrderTypeRecordVo myType = orderTypeRecordMapper.selectByScanUser(userId);
if (myType == null) {
log.debug("客户订单头查询跳过:用户无偏好订单类型, userId={}", userId);
return Collections.emptyList();
}
// 2. scanUser 兜底为 token.userId(INNER JOIN 需匹配 SCAN_USER)
String effectiveScanUser = StringUtils.isBlank(req.getScanUser()) ? userId : req.getScanUser();
log.debug("客户订单头查询 userId={}, scanUser={}, orderType偏好={}, customerName={}, orderNo={}, statusList={}",
userId, effectiveScanUser, myType.getOrderType(),
req.getCustomerName(), req.getOrderNo(), req.getStatusList());
// 3. 调用 mapper(INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE 按偏好过滤)
return scanMapper.selectCustomerScanHeader(
req.getCustomerName(),
req.getOrderNo(),
req.getStatusList(),
effectiveScanUser);
}
// ===================== 订单类型 (a/b/d/e/f/g) =====================
@Override
public OrderTypeListsVo queryOrderTypeGroup() {
// 直接加载(内部已做 Redis 缓存 + DB 回写)
return loadOrderTypeLists();
}
/**
* b. 保存订单类型(原子 UPSERT by SCAN_USER)
* 表 T_DOC_OUTBOUND_SCAN_ORDERTYPE 上 SCAN_USER 有 UNIQUE 约束,每人一行
* - 业务校验(2026-09-07 末+2 起):不做强校验,三个字段均仅做格式规范化(trim/去空段/去重)
* - 用 Oracle MERGE 原子完成 INSERT or UPDATE(并发安全)
* - 清缓存
*/
@Override
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
public String saveOrderType(OrderTypeSaveReq req, String userId) {
return upsertOrderType(req.getOrderType(), req.getReference5(), req.getTemperatureclass(), userId);
}
/**
* d. 查询当前人员的"当前选择"(返回 0 或 1 条)
*/
@Override
public OrderTypeRecordVo queryMyOrderType(String userId) {
return orderTypeRecordMapper.selectByScanUser(userId);
}
/**
* e. 删除当前人员的"当前选择"
*/
@Override
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
public boolean deleteMyOrderType(String userId) {
int rows = orderTypeRecordMapper.deleteByScanUser(userId);
log.info("删除订单类型选择:userId={}, rows={}", userId, rows);
return rows > 0;
}
/**
* f. 更新订单类型(与 b 等价:原子 UPSERT)
*/
@Override
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
public boolean updateOrderType(OrderTypeUpdateReq req, String userId) {
upsertOrderType(req.getOrderType(), req.getReference5(), req.getTemperatureclass(), userId);
return true;
}
/**
* 私有原子 UPSERT(业务复用,b/f/j 共用)
* 顺序:规范化 → 原子 MERGE → 取 REC_ID → 清缓存
*
* 三个业务字段均可空(null/空串 → 不过滤该字段):
* - orderType、reference5、temperatureclass:2026-09-07 末+2 起均不做合法性校验,
* 仅做格式规范化(trim/去空段/去重)后直接保存
*/
private String upsertOrderType(String orderType, String reference5, String temperatureclass, String userId) {
// 规范化(按逗号拆分 → trim → 去空段 → 去重 → 拼回)
String nOrderType = normalizeOrderType(orderType);
String nReference5 = normalizeOrderType(reference5);
String nTempClass = normalizeOrderType(temperatureclass);
// orderType 强校验(业务必填且必须合法)— 2026-09-07 末+2 起已删除,由调用方保证合法性
orderTypeRecordMapper.upsertByScanUser(userId, nOrderType, nReference5, nTempClass);
String recId = orderTypeRecordMapper.selectRecIdByScanUser(userId);
log.info("UPSERT 订单类型:recId={}, orderType={}, reference5={}, temperatureclass={}, userId={}",
recId, nOrderType, nReference5, nTempClass, userId);
clearOrderTypeCache();
return recId;
}
@Override
public OrderTypeRecordVo getOrderTypeByRecId(String recId) {
return orderTypeRecordMapper.selectByRecId(recId);
}
/**
* h. 管理员用:全量选择列表
* 表 T_DOC_OUTBOUND_SCAN_ORDERTYPE 每人一行,数据量小无需分页
*/
@Override
public java.util.List<OrderTypeRecordVo> queryAllOrderTypes() {
java.util.List<OrderTypeRecordVo> list = orderTypeRecordMapper.selectAll();
if (list == null) {
return java.util.Collections.emptyList();
}
return list;
}
/**
* i. 管理员用:按 ORDER_TYPE 分组统计人数
* 返回 Map<ORDER_TYPE, 人数>
*/
@Override
public java.util.Map<String, Integer> countByOrderType() {
return orderTypeRecordMapper.countGroupByOrderType();
}
/**
* j. 管理员代改任意人员的当前选择
* 用于支持场景:"用户选错了,管理员帮改"
* 与 saveOrderType 区别:scanUser 由调用方传入,而非取自 token
* 仍复用 MERGE + 清缓存
*/
@Override
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
public String adminUpsertOrderType(String scanUser, String orderType, String reference5, String temperatureclass) {
if (scanUser == null || scanUser.isEmpty()) {
throw new IllegalArgumentException("scanUser 不能为空");
}
// 复用 upsertOrderType 私有方法(统一规范化、校验、MERGE 逻辑)
return upsertOrderType(orderType, reference5, temperatureclass, scanUser);
}
// ===================== 内部辅助 =====================
/**
* 加载 a 接口的 3 个 distinct list(OrderTypeListsVo)
* 优先 Redis 缓存(key=tms:outbound:orderType:lists,TTL=5min),miss 则查 DB 并回写
* 供 /orderType/list 接口本身使用(orderType 强校验已停用,缓存仍保留供前端下拉使用)
*/
private OrderTypeListsVo loadOrderTypeLists() {
OrderTypeListsVo vo = null;
try {
Object cached = redisUtil.get(CACHE_KEY_ORDER_TYPE_GROUP);
if (cached instanceof OrderTypeListsVo) {
vo = (OrderTypeListsVo) cached;
}
} catch (Exception e) {
log.warn("Redis 读取 orderType 下拉缓存失败", e);
}
if (vo == null) {
vo = new OrderTypeListsVo();
// 3 个独立 distinct 查询,互不影响(即使某些字段全为 NULL/空也不会报错)
List<String> orderTypeList = safeDistinct(scanMapper::selectDistinctOrderType);
List<String> reference5List = safeDistinct(scanMapper::selectDistinctReference5);
List<String> tempClassList = safeDistinct(scanMapper::selectDistinctTemperatureclass);
vo.setOrderType(orderTypeList);
vo.setReference5(reference5List);
vo.setTemperatureclass(tempClassList);
try {
redisUtil.set(CACHE_KEY_ORDER_TYPE_GROUP, vo, CACHE_TTL_SECONDS);
} catch (Exception e) {
log.warn("Redis 写入 orderType 下拉缓存失败,不影响查询", e);
}
}
return vo;
}
/**
* 安全调用 mapper 的 distinct 查询:异常/返回 null 时兜底为空列表
*/
private List<String> safeDistinct(java.util.function.Supplier<List<String>> supplier) {
try {
List<String> list = supplier.get();
return list == null ? Collections.emptyList() : list;
} catch (Exception e) {
log.warn("distinct 查询失败:{}", e.getMessage());
return Collections.emptyList();
}
}
/**
* 规范化订单类型(统一处理 orderType / reference5 / temperatureclass 三字段):
* 按逗号拆分 → 去首尾空格 → 去空段 → 去重 → 拼回逗号分隔串。
* 返回 null 表示输入为 null 或全为空段(视为"不过滤该字段",可安全落库为 NULL)。
* 例:" NORMAL , URGENT ,NORMAL " -> "NORMAL,URGENT"
*/
private String normalizeOrderType(String value) {
if (value == null) {
return null;
}
LinkedHashSet<String> set = new LinkedHashSet<>();
for (String part : value.split(",")) {
String type = part == null ? "" : part.trim();
if (!type.isEmpty()) {
set.add(type);
}
}
if (set.isEmpty()) {
return null;
}
return String.join(",", set);
}
private void clearOrderTypeCache() {
try {
redisUtil.del(CACHE_KEY_ORDER_TYPE_GROUP);
log.debug("已清除订单类型聚合缓存");
} catch (Exception e) {
log.warn("清除订单类型聚合缓存失败", e);
}
}
} }
package com.ekingwin.tms_app.module.cargo.outbound.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* 客户编码查询结果 VO:按客户编码查询未完成扫描的订单明细
*/
@Data
public class CustomerScanDetailVo {
private String customerCode; // 客户代码
private String customerName; // 客户名称
private String orderNo; // 订单号
private String orderType; // 订单类型
private String reference5; // 参考 5
private String temperatureclass; // 温度类别
private Integer lineNo; // 行号
private String itemCode; // 商品编码
private String itemName; // 商品名称
private String batchNo; // 生产批号
private String lotNo; // 批次号
private BigDecimal orderQty; // 订单数量
private BigDecimal tallyQty; // 已理货数量
private BigDecimal remainingQty; // 待扫描数量
private String unit; // 单位
private String scanStatus; // 扫描状态(未扫描/部分完成)
private String status; // 明细状态(PENDING/...)
}
package com.ekingwin.tms_app.module.cargo.outbound.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 客户编码查询 - 订单头维度 VO
*
* 数据源:T_DOC_OUTBOUND_SCAN_HEADER(订单头)
* 过滤条件:
* 1. EXISTS 子查询:至少有一行明细 IS_ODD_LOT = 'C'
* 2. INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE:仅显示"该扫描员偏好的订单类型"
* 3. 可选:customerName 模糊 / orderNo 精确 / statusList IN / scanUser 精确
*/
@Data
public class CustomerScanHeaderVo {
/** 组织 ID */
private String organizationid;
/** 订单号 */
private String orderNo;
/** 客户名称 */
private String customerName;
/** 客户编码 */
private String customerCode;
/** 订单总行数 */
private Integer totalLines;
/** 已理货行数 */
private Integer tallyLines;
/** 状态 */
private String status;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/** 订单类型(与 T_DOC_OUTBOUND_SCAN_ORDERTYPE.ORDERTYPE 匹配) */
private String orderType;
/** 参考 5(与 T_DOC_OUTBOUND_SCAN_ORDERTYPE.REFERENCE5 匹配) */
private String reference5;
/** 温度类别(与 T_DOC_OUTBOUND_SCAN_ORDERTYPE.TEMPERATURECLASS 匹配) */
private String temperatureclass;
/** 客户收货地址 */
private String customerAddr;
/** 所属机构名称 */
private String orgName;
/** 扫描员(与 T_DOC_OUTBOUND_SCAN_ORDERTYPE.SCAN_USER 关联) */
private String scanUser;
}
package com.ekingwin.tms_app.module.cargo.outbound.vo;
import lombok.Data;
import java.util.Date;
/**
* 订单类型选择记录 VO(简化版)
* 对应 T_DOC_OUTBOUND_SCAN_ORDERTYPE 单条记录
* 该表 SCAN_USER 上有 UNIQUE 约束,每人最多一条
*
* 三个业务字段(orderType / reference5 / temperatureclass)均可为空:
* - 存逗号分隔多值时按包含匹配
* - 字段为 null 或空串时表示"不过滤该字段"(关联查询走全集)
*/
@Data
public class OrderTypeRecordVo {
private String recId; // 主键
private String scanUser; // 人员 ID(取自 token.userId)
private String orderType; // 订单类型,逗号分隔多值,可空(2026-09-07 末+2 起不做合法性校验)
private String reference5; // 参考 5(来自 T_DOC_OUTBOUND_SCAN_HEADER.REFERENCE5),逗号分隔多值,可空
private String temperatureclass; // 温度类别(来自 T_DOC_OUTBOUND_SCAN_HEADER.TEMPERATURECLASS),逗号分隔多值,可空
private Date createTime; // 首次保存时间
private Date updateTime; // 最近更新时间
}
...@@ -11,8 +11,8 @@ public class OrderWithPendingVo { ...@@ -11,8 +11,8 @@ public class OrderWithPendingVo {
private Integer totalLines; private Integer totalLines;
private Integer tallyLines; private Integer tallyLines;
private Integer remainLines; // 剩余行数 private Integer remainLines; // 剩余行数
private Integer remain_c; // 剩余行数 private String remainC; // 剩余行数
private Integer remain_a; // 剩余行数 private String remainA; // 剩余行数
private BigDecimal progressPct; // 进度百分比 private BigDecimal progressPct; // 进度百分比
private String status; private String status;
private String statusCn; // 中文状态 private String statusCn; // 中文状态
......
...@@ -14,6 +14,8 @@ public class OutboundOrderVo { ...@@ -14,6 +14,8 @@ public class OutboundOrderVo {
private String status; private String status;
private String createTime; private String createTime;
private String orderType; private String orderType;
private String reference5;
private String temperatureclass;
private String customerAddr; private String customerAddr;
private String orgName; private String orgName;
private String scanUser; private String scanUser;
......
...@@ -15,3 +15,15 @@ app.security.lock-duration-minutes= 5 ...@@ -15,3 +15,15 @@ app.security.lock-duration-minutes= 5
spring.application.name=tms-app spring.application.name=tms-app
server.servlet.context-path=/tms-app server.servlet.context-path=/tms-app
app.default-password= welcome1 app.default-password= welcome1
# 文件上传根目录(应用图标等)
app.upload-dir=./upload/
# ===================== AI调度中心(aidispatch 模块)=====================
# 高德地图API Key(未配置时距离矩阵仅可命中缓存,无法实时获取)
app.amap.key=
# 高德驾车距离测量API地址
app.amap.distance-url=https://restapi.amap.com/v3/distance
# 距离矩阵缓存有效期(天),对应配置项 DISTANCE_MATRIX_EXPIRE_DAYS
app.amap.expire-days=30
# 单次批量刷新最大地址对数
app.amap.refresh-batch-limit=200
\ No newline at end of file
...@@ -3,35 +3,47 @@ ...@@ -3,35 +3,47 @@
<mapper namespace="com.ekingwin.tms_app.module.cargo.outbound.dao.OutboundOrderHeaderMapper"> <mapper namespace="com.ekingwin.tms_app.module.cargo.outbound.dao.OutboundOrderHeaderMapper">
<select id="selectOrderList" resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OutboundOrderVo"> <select id="selectOrderList" resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OutboundOrderVo">
SELECT organizationid, order_no AS orderNo, customer_name AS customerName, SELECT h.organizationid, h.order_no AS orderNo, h.customer_name AS customerName,
customer_code AS customerCode, total_lines AS totalLines, h.customer_code AS customerCode, h.total_lines AS totalLines,
tally_lines AS tallyLines, status, create_time AS createTime, h.tally_lines AS tallyLines, h.status, h.create_time AS createTime,
ordertype AS orderType, customer_addr AS customerAddr,org_name AS orgName, h.ordertype AS orderType, h.customer_addr AS customerAddr,h.org_name AS orgName,
scan_user as scanUser h.reference5 AS reference5, h.temperatureclass AS temperatureclass,
FROM T_DOC_outbound_scan_HEADER h.scan_user as scanUser
FROM T_DOC_outbound_scan_HEADER h
INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE o
ON o.SCAN_USER = h.SCAN_USER
-- 偏好 (orderType, reference5, temperatureclass) 三元组过滤:每个字段空时不过滤该字段
-- 空场景包括:1) 偏好 o.X 为 NULL/空 2) SCAN_HEADER h.X 为 NULL/空(未分类订单也应匹配任何偏好)
AND (NVL(o.ORDERTYPE, '') = ''
OR NVL(h.ORDERTYPE, '') = ''
OR INSTR(',' || o.ORDERTYPE || ',', ',' || h.ORDERTYPE || ',') <![CDATA[ > ]]> 0)
AND (NVL(o.REFERENCE5, '') = ''
OR NVL(h.REFERENCE5, '') = ''
OR INSTR(',' || o.REFERENCE5 || ',', ',' || h.REFERENCE5 || ',') <![CDATA[ > ]]> 0)
AND (NVL(o.TEMPERATURECLASS, '') = ''
OR NVL(h.TEMPERATURECLASS, '') = ''
OR INSTR(',' || o.TEMPERATURECLASS || ',', ',' || h.TEMPERATURECLASS || ',') <![CDATA[ > ]]> 0)
WHERE 1=1 WHERE 1=1
AND EXISTS (
SELECT 1 FROM T_DOC_OUTBOUND_SCAN_DETAIL d
WHERE d.ORDER_NO = h.ORDER_NO AND d.IS_ODD_LOT = 'C'
)
<if test="customerName != null and customerName != ''"> <if test="customerName != null and customerName != ''">
AND customer_name LIKE CONCAT(CONCAT('%', #{customerName}), '%') AND h.customer_name LIKE CONCAT(CONCAT('%', #{customerName}), '%')
</if> </if>
<if test="orderNo != null and orderNo != ''"> <if test="orderNo != null and orderNo != ''">
AND order_no = #{orderNo} AND h.order_no = #{orderNo}
</if> </if>
<if test="statusList != null and statusList != ''"> <if test="statusList != null and statusList != ''">
AND status in AND h.status in
<foreach collection="statusList" item="status" open="(" separator="," close=")"> <foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status} #{status}
</foreach> </foreach>
</if> </if>
<if test="scanUser != null and scanUser != ''"> <if test="scanUser != null and scanUser != ''">
and scan_user= #{scanUser} and h.scan_user= #{scanUser}
</if> </if>
<!-- <if test="startTime != null">--> ORDER BY h.customer_name,h.create_time DESC
<!-- AND create_time >= #{startTime}-->
<!-- </if>-->
<!-- <if test="endTime != null">-->
<!-- AND create_time >= #{endTime}-->
<!-- </if>-->
ORDER BY customerName,create_time DESC
</select> </select>
<select id="selectOrderCount" resultType="java.lang.Integer"> <select id="selectOrderCount" resultType="java.lang.Integer">
...@@ -115,8 +127,33 @@ ...@@ -115,8 +127,33 @@
<select id="selectOrderWithPending" <select id="selectOrderWithPending"
resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OrderWithPendingVo"> resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OrderWithPendingVo">
WITH box_stats AS (
SELECT
order_no,
COUNT(DISTINCT CASE WHEN status != 'DONE' AND is_odd_lot = 'C' THEN TRACEID END) AS remainC,
COUNT(DISTINCT CASE WHEN status != 'DONE' AND is_odd_lot = 'A' THEN TRACEID END) AS remainA,
LISTAGG(CASE WHEN status != 'DONE' THEN box_no END, ',')
WITHIN GROUP (ORDER BY box_no) AS pendingBoxes
FROM t_doc_outbound_box
GROUP BY order_no
),
detail_stats AS (
SELECT
order_no,
LISTAGG(item_name || '(' || (order_qty - tally_qty) || ')', '; ')
WITHIN GROUP (ORDER BY line_no) AS pendingItems
FROM T_DOC_outbound_scan_DETAIL
WHERE status != 'DONE'
GROUP BY order_no
),
trace_stats AS (
SELECT
order_no,
COUNT(*) AS pendingTraces
FROM T_DOC_outbound_tracecode
WHERE status = 'PENDING'
GROUP BY order_no
)
SELECT SELECT
h.order_no AS orderNo, h.order_no AS orderNo,
h.customer_name AS customerName, h.customer_name AS customerName,
...@@ -124,48 +161,18 @@ ...@@ -124,48 +161,18 @@
h.total_lines AS totalLines, h.total_lines AS totalLines,
h.tally_lines AS tallyLines, h.tally_lines AS tallyLines,
(h.total_lines - h.tally_lines) AS remainLines, (h.total_lines - h.tally_lines) AS remainLines,
COALESCE( COALESCE(b.remainC, 0) AS remainC,
(SELECT COUNT(DISTINCT A.TRACEID) COALESCE(b.remainA, 0) AS remainA,
FROM t_doc_outbound_box a
WHERE a.order_no = H.order_no
AND a.status != 'DONE'
AND a.is_odd_lot = 'C'),
0
) AS remain_c, -- 标签整件
COALESCE(
(SELECT COUNT(DISTINCT B.TRACEID)
FROM t_doc_outbound_box B
WHERE B.order_no = H.order_no
AND B.status != 'DONE'
AND B.is_odd_lot = 'A'),
0
) AS remain_a, -- 标签零头
ROUND(h.tally_lines / NULLIF(h.total_lines, 0) * 100, 1) AS progressPct, ROUND(h.tally_lines / NULLIF(h.total_lines, 0) * 100, 1) AS progressPct,
h.status, h.status,
DECODE(h.status, 'PENDING','待理货','TALLYING','理货中','DONE','已完成', h.status) AS statusCn, DECODE(h.status, 'PENDING','待理货','TALLYING','理货中','DONE','已完成', h.status) AS statusCn,
-- 未理货明细(也可能为 NULL,建议一并处理) COALESCE(d.pendingItems, '无未理货明细') AS pendingItems,
COALESCE( COALESCE(b.pendingBoxes, '') AS pendingBoxes,
(SELECT LISTAGG(ol.item_name || '(' || (ol.order_qty - ol.tally_qty) || ')', '; ') COALESCE(t.pendingTraces, 0) AS pendingTraces
WITHIN GROUP (ORDER BY ol.line_no)
FROM T_DOC_outbound_scan_DETAIL ol
WHERE ol.order_no = h.order_no AND ol.status != 'DONE'),
'无未理货明细'
) AS pendingItems,
-- 未理货箱号
COALESCE(
(SELECT LISTAGG(b.box_no, ',') WITHIN GROUP (ORDER BY b.box_no)
FROM T_DOC_outbound_box b
WHERE b.order_no = h.order_no AND b.status != 'DONE'),
''
) AS pendingBoxes,
-- 未理货追溯码数(本身为 COUNT,理论上返回 0,但加 COALESCE 更安全)
COALESCE(
(SELECT COUNT(*)
FROM T_DOC_outbound_tracecode t
WHERE t.order_no = h.order_no AND t.status = 'PENDING'),
0
) AS pendingTraces
FROM T_DOC_outbound_scan_HEADER h FROM T_DOC_outbound_scan_HEADER h
LEFT JOIN box_stats b ON b.order_no = h.order_no
LEFT JOIN detail_stats d ON d.order_no = h.order_no
LEFT JOIN trace_stats t ON t.order_no = h.order_no
WHERE 1=1 WHERE 1=1
<if test="customerName != null and customerName != ''"> <if test="customerName != null and customerName != ''">
AND h.customer_name LIKE '%' || #{customerName} || '%' AND h.customer_name LIKE '%' || #{customerName} || '%'
...@@ -186,11 +193,83 @@ ...@@ -186,11 +193,83 @@
AND h.create_time <![CDATA[ <= ]]> #{endTime, jdbcType=TIMESTAMP} AND h.create_time <![CDATA[ <= ]]> #{endTime, jdbcType=TIMESTAMP}
</if> </if>
<if test="scanUser != null and scanUser != ''"> <if test="scanUser != null and scanUser != ''">
and h.scan_user= #{scanUser} AND h.scan_user = #{scanUser}
</if> </if>
<!-- 如果默认不查已完成,可加 --> AND h.status != 'DONE'
<!-- AND h.status != 'DONE' -->
ORDER BY h.status, h.create_time DESC ORDER BY h.status, h.create_time DESC
<!-- SELECT-->
<!-- h.order_no AS orderNo,-->
<!-- h.customer_name AS customerName,-->
<!-- h.customer_code AS customerCode,-->
<!-- h.total_lines AS totalLines,-->
<!-- h.tally_lines AS tallyLines,-->
<!-- (h.total_lines - h.tally_lines) AS remainLines,-->
<!-- COALESCE(-->
<!-- (SELECT COUNT(DISTINCT A.TRACEID)-->
<!-- FROM t_doc_outbound_box a-->
<!-- WHERE a.order_no = H.order_no-->
<!-- AND a.status != 'DONE'-->
<!-- AND a.is_odd_lot = 'C'),-->
<!-- 0-->
<!-- ) AS remainC, &#45;&#45; 标签整件-->
<!-- COALESCE(-->
<!-- (SELECT COUNT(DISTINCT B.TRACEID)-->
<!-- FROM t_doc_outbound_box B-->
<!-- WHERE B.order_no = H.order_no-->
<!-- AND B.status != 'DONE'-->
<!-- AND B.is_odd_lot = 'A'),-->
<!-- 0-->
<!-- ) AS remainA, &#45;&#45; 标签零头-->
<!-- ROUND(h.tally_lines / NULLIF(h.total_lines, 0) * 100, 1) AS progressPct,-->
<!-- h.status,-->
<!-- DECODE(h.status, 'PENDING','待理货','TALLYING','理货中','DONE','已完成', h.status) AS statusCn,-->
<!-- &#45;&#45; 未理货明细(也可能为 NULL,建议一并处理)-->
<!-- COALESCE(-->
<!-- (SELECT LISTAGG(ol.item_name || '(' || (ol.order_qty - ol.tally_qty) || ')', '; ')-->
<!-- WITHIN GROUP (ORDER BY ol.line_no)-->
<!-- FROM T_DOC_outbound_scan_DETAIL ol-->
<!-- WHERE ol.order_no = h.order_no AND ol.status != 'DONE'),-->
<!-- '无未理货明细'-->
<!-- ) AS pendingItems,-->
<!-- &#45;&#45; 未理货箱号-->
<!-- COALESCE(-->
<!-- (SELECT LISTAGG(b.box_no, ',') WITHIN GROUP (ORDER BY b.box_no)-->
<!-- FROM T_DOC_outbound_box b-->
<!-- WHERE b.order_no = h.order_no AND b.status != 'DONE'),-->
<!-- ''-->
<!-- ) AS pendingBoxes,-->
<!-- &#45;&#45; 未理货追溯码数(本身为 COUNT,理论上返回 0,但加 COALESCE 更安全)-->
<!-- COALESCE(-->
<!-- (SELECT COUNT(*)-->
<!-- FROM T_DOC_outbound_tracecode t-->
<!-- WHERE t.order_no = h.order_no AND t.status = 'PENDING'),-->
<!-- 0-->
<!-- ) AS pendingTraces-->
<!-- FROM T_DOC_outbound_scan_HEADER h-->
<!-- WHERE 1=1-->
<!-- <if test="customerName != null and customerName != ''">-->
<!-- AND h.customer_name LIKE '%' || #{customerName} || '%'-->
<!-- </if>-->
<!-- <if test="orderNo != null and orderNo != ''">-->
<!-- AND h.order_no = #{orderNo}-->
<!-- </if>-->
<!-- <if test="statusList != null and statusList.size() > 0">-->
<!-- AND h.status IN-->
<!-- <foreach collection="statusList" item="status" open="(" separator="," close=")">-->
<!-- #{status}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="startTime != null">-->
<!-- AND h.create_time >= #{startTime, jdbcType=TIMESTAMP}-->
<!-- </if>-->
<!-- <if test="endTime != null">-->
<!-- AND h.create_time <![CDATA[ <= ]]> #{endTime, jdbcType=TIMESTAMP}-->
<!-- </if>-->
<!-- <if test="scanUser != null and scanUser != ''">-->
<!-- and h.scan_user= #{scanUser}-->
<!-- </if>-->
<!-- ORDER BY h.status, h.create_time DESC-->
</select> </select>
<select id="queryCustomer" resultType="com.ekingwin.tms_app.module.cargo.vo.CustomerVo"> <select id="queryCustomer" resultType="com.ekingwin.tms_app.module.cargo.vo.CustomerVo">
SELECT SELECT
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ekingwin.tms_app.module.cargo.outbound.dao.OutboundOrderTypeRecordMapper">
<!-- 通用结果映射(用于 BaseMapper.insert 兜底) -->
<resultMap id="baseResultMap" type="com.ekingwin.tms_app.module.cargo.outbound.entity.OutboundOrderTypeRecord">
<id column="REC_ID" property="recId"/>
<result column="SCAN_USER" property="scanUser"/>
<result column="ORDERTYPE" property="orderType"/>
<result column="CREATE_TIME" property="createTime"/>
<result column="UPDATE_TIME" property="updateTime"/>
</resultMap>
<!--
兼容 MyBatis-Plus 默认 insert:BaseMapper.insert() 会按 @TableField 自动拼 INSERT。
本 SQL 是冗余兜底(手动调用时使用),与 @TableName 实体配合即可。
-->
<insert id="insertRecord" parameterType="com.ekingwin.tms_app.module.cargo.outbound.entity.OutboundOrderTypeRecord">
INSERT INTO T_DOC_OUTBOUND_SCAN_ORDERTYPE (
REC_ID, SCAN_USER, ORDERTYPE, CREATE_TIME, UPDATE_TIME
) VALUES (
#{recId, jdbcType=VARCHAR},
#{scanUser, jdbcType=VARCHAR},
#{orderType, jdbcType=VARCHAR},
#{createTime, jdbcType=DATE},
#{updateTime, jdbcType=DATE}
)
</insert>
<!-- 按人员 ID 查该人员的"当前选择"(UNIQUE 约束,最多 1 条) -->
<select id="selectByScanUser" resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo">
SELECT REC_ID AS recId,
SCAN_USER AS scanUser,
ORDERTYPE AS orderType,
REFERENCE5 AS reference5,
TEMPERATURECLASS AS temperatureclass,
CREATE_TIME AS createTime,
UPDATE_TIME AS updateTime
FROM T_DOC_OUTBOUND_SCAN_ORDERTYPE
WHERE SCAN_USER = #{scanUser, jdbcType=VARCHAR}
</select>
<!-- 按 recId 查单条记录 -->
<select id="selectByRecId" resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo">
SELECT REC_ID AS recId,
SCAN_USER AS scanUser,
ORDERTYPE AS orderType,
REFERENCE5 AS reference5,
TEMPERATURECLASS AS temperatureclass,
CREATE_TIME AS createTime,
UPDATE_TIME AS updateTime
FROM T_DOC_OUTBOUND_SCAN_ORDERTYPE
WHERE REC_ID = #{recId, jdbcType=VARCHAR}
</select>
<!-- 全量列表(管理员用,表小无需分页) -->
<select id="selectAll" resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.OrderTypeRecordVo">
SELECT REC_ID AS recId,
SCAN_USER AS scanUser,
ORDERTYPE AS orderType,
REFERENCE5 AS reference5,
TEMPERATURECLASS AS temperatureclass,
CREATE_TIME AS createTime,
UPDATE_TIME AS updateTime
FROM T_DOC_OUTBOUND_SCAN_ORDERTYPE
ORDER BY UPDATE_TIME DESC, REC_ID DESC
</select>
<!-- 按 ORDERTYPE 分组统计人数(管理员监控)
注意:ORDERTYPE 可能为逗号分隔的多值(如 'A,B'),需拆分为单个类型后再 GROUP BY -->
<select id="countGroupByOrderType" resultType="java.util.HashMap">
SELECT orderType AS "key",
COUNT(1) AS "value"
FROM (
SELECT TRIM(REGEXP_SUBSTR(t.ORDERTYPE, '[^,]+', 1, LEVEL)) AS orderType
FROM T_DOC_OUTBOUND_SCAN_ORDERTYPE t
CONNECT BY LEVEL <![CDATA[ <= ]]> REGEXP_COUNT(t.ORDERTYPE, ',') + 1
AND PRIOR t.REC_ID = t.REC_ID
AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL
)
WHERE orderType IS NOT NULL
GROUP BY orderType
ORDER BY orderType
</select>
<!-- 按人员 ID 删除该人员的"当前选择" -->
<delete id="deleteByScanUser">
DELETE FROM T_DOC_OUTBOUND_SCAN_ORDERTYPE
WHERE SCAN_USER = #{scanUser, jdbcType=VARCHAR}
</delete>
<!--
原子 UPSERT(MERGE):并发安全
- MATCHED (SCAN_USER 已存在) → UPDATE ORDERTYPE/REFERENCE5/TEMPERATURECLASS, UPDATE_TIME=SYSDATE
- NOT MATCHED → INSERT 新行(REC_ID 由序列生成)
三个业务字段均可传 null/空串(表示"不过滤该字段"),MERGE 写入时统一以 NULL 落库
-->
<insert id="upsertByScanUser">
MERGE INTO T_DOC_OUTBOUND_SCAN_ORDERTYPE t
USING (SELECT #{scanUser, jdbcType=VARCHAR} AS SCAN_USER FROM DUAL) s
ON (t.SCAN_USER = s.SCAN_USER)
WHEN MATCHED THEN
UPDATE SET t.ORDERTYPE = NULLIF(#{orderType, jdbcType=VARCHAR}, ''),
t.REFERENCE5 = NULLIF(#{reference5, jdbcType=VARCHAR}, ''),
t.TEMPERATURECLASS = NULLIF(#{temperatureclass, jdbcType=VARCHAR}, ''),
t.UPDATE_TIME = SYSDATE
WHEN NOT MATCHED THEN
INSERT (REC_ID, SCAN_USER, ORDERTYPE, REFERENCE5, TEMPERATURECLASS, CREATE_TIME, UPDATE_TIME)
VALUES (SEQ_T_DOC_OUTBOUND_SCAN_ORDERTYPE.NEXTVAL,
#{scanUser, jdbcType=VARCHAR},
NULLIF(#{orderType, jdbcType=VARCHAR}, ''),
NULLIF(#{reference5, jdbcType=VARCHAR}, ''),
NULLIF(#{temperatureclass, jdbcType=VARCHAR}, ''),
SYSDATE, SYSDATE)
</insert>
<!-- 根据 scanUser 取 REC_ID(用于 MERGE 后回传) -->
<select id="selectRecIdByScanUser" resultType="string">
SELECT REC_ID
FROM T_DOC_OUTBOUND_SCAN_ORDERTYPE
WHERE SCAN_USER = #{scanUser, jdbcType=VARCHAR}
</select>
</mapper>
...@@ -52,4 +52,142 @@ ...@@ -52,4 +52,142 @@
)} )}
</select> </select>
<!-- 按客户编码查询未完成扫描的订单明细(可选按订单类型过滤) -->
<select id="selectCustomerScanDetail"
resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanDetailVo">
SELECT h.CUSTOMER_CODE AS customerCode,
h.CUSTOMER_NAME AS customerName,
h.ORDER_NO AS orderNo,
h.ORDERTYPE AS orderType,
h.REFERENCE5 AS reference5,
h.TEMPERATURECLASS AS temperatureclass,
d.LINE_NO AS lineNo,
d.ITEM_CODE AS itemCode,
d.ITEM_NAME AS itemName,
d.BATCH_NO AS batchNo,
d.LOT_NO AS lotNo,
d.ORDER_QTY AS orderQty,
d.TALLY_QTY AS tallyQty,
NVL(d.ORDER_QTY, 0) - NVL(d.TALLY_QTY, 0) AS remainingQty,
d.UNIT AS unit,
CASE WHEN NVL(d.TALLY_QTY, 0) = 0 THEN '未扫描' ELSE '部分完成' END AS scanStatus,
d.STATUS AS status
FROM T_DOC_OUTBOUND_SCAN_DETAIL d
JOIN T_DOC_OUTBOUND_SCAN_HEADER h
ON h.ORGANIZATIONID = d.ORGANIZATIONID
AND h.ORDER_NO = d.ORDER_NO
WHERE h.CUSTOMER_CODE = #{customerCode, jdbcType=VARCHAR}
AND h.scan_user = #{scanUser, jdbcType=VARCHAR}
AND NVL(d.TALLY_QTY, 0) <![CDATA[ < ]]> NVL(d.ORDER_QTY, 0)
<if test="orderType != null and orderType != ''">
AND (NVL(h.ORDERTYPE, '') = ''
OR INSTR(',' || #{orderType, jdbcType=VARCHAR} || ',', ',' || h.ORDERTYPE || ',') <![CDATA[ > ]]> 0)
</if>
<if test="reference5 != null and reference5 != ''">
AND (NVL(h.REFERENCE5, '') = ''
OR INSTR(',' || #{reference5, jdbcType=VARCHAR} || ',', ',' || h.REFERENCE5 || ',') <![CDATA[ > ]]> 0)
</if>
<if test="temperatureclass != null and temperatureclass != ''">
AND (NVL(h.TEMPERATURECLASS, '') = ''
OR INSTR(',' || #{temperatureclass, jdbcType=VARCHAR} || ',', ',' || h.TEMPERATURECLASS || ',') <![CDATA[ > ]]> 0)
</if>
ORDER BY h.ORDER_NO, d.LINE_NO
</select>
<!-- 订单类型下拉:distinct ORDER_TYPE(来自 T_DOC_OUTBOUND_SCAN_HEADER.ORDERTYPE) -->
<select id="selectDistinctOrderType" resultType="string">
SELECT DISTINCT ORDERTYPE AS val
FROM T_DOC_OUTBOUND_SCAN_HEADER
WHERE ORDERTYPE IS NOT NULL
ORDER BY ORDERTYPE
</select>
<!-- 订单类型下拉:distinct REFERENCE5(来自 T_DOC_OUTBOUND_SCAN_HEADER.REFERENCE5) -->
<select id="selectDistinctReference5" resultType="string">
SELECT DISTINCT REFERENCE5 AS val
FROM T_DOC_OUTBOUND_SCAN_HEADER
WHERE REFERENCE5 IS NOT NULL
ORDER BY REFERENCE5
</select>
<!-- 订单类型下拉:distinct TEMPERATURECLASS(来自 T_DOC_OUTBOUND_SCAN_HEADER.TEMPERATURECLASS) -->
<select id="selectDistinctTemperatureclass" resultType="string">
SELECT DISTINCT TEMPERATURECLASS AS val
FROM T_DOC_OUTBOUND_SCAN_HEADER
WHERE TEMPERATURECLASS IS NOT NULL
ORDER BY TEMPERATURECLASS
</select>
<!--
按扫描员偏好查询订单头列表(订单头维度,含 INNER JOIN ORDERTYPE 表)
业务约束:
1) 必须存在 IS_ODD_LOT='C' 的明细行(EXISTS)
2) INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE:仅显示该扫描员偏好 ORDERTYPE 的订单头
- 若该扫描员在偏好表无记录,结果集为空
- 关联键:o.SCAN_USER = h.SCAN_USER,且偏好 ORDERTYPE(逗号分隔多值时按包含匹配)
3) 可选过滤:customerName 模糊、orderNo 精确、statusList IN、scanUser 精确
(注:scanUser 不传时由 service 层兜底为 token.userId,避免空匹配)
字段名映射:
- 偏好表字段名是 ORDERTYPE(与 header 同名,逗号分隔多值时按包含匹配)
-->
<select id="selectCustomerScanHeader"
resultType="com.ekingwin.tms_app.module.cargo.outbound.vo.CustomerScanHeaderVo">
SELECT h.organizationid AS organizationid,
h.order_no AS orderNo,
h.customer_name AS customerName,
h.customer_code AS customerCode,
h.total_lines AS totalLines,
h.tally_lines AS tallyLines,
h.status AS status,
h.create_time AS createTime,
h.ordertype AS orderType,
h.reference5 AS reference5,
h.temperatureclass AS temperatureclass,
h.customer_addr AS customerAddr,
h.org_name AS orgName,
h.scan_user AS scanUser
FROM T_DOC_OUTBOUND_SCAN_HEADER h
<!-- INNER JOIN 偏好表:只返回该扫描员偏好 (orderType, reference5, temperatureclass) 的订单头
每个偏好字段独立判断(任一为真即匹配):
- 偏好 o.X 为 NULL/空 → 不过滤该字段(关联条件恒真)
- SCAN_HEADER h.X 为 NULL/空 → 也通过(未分类订单应出现在任何偏好下)
- 偏好字段非空 & SCAN_HEADER 字段非空 → 按 INSTR 逗号包含匹配 -->
INNER JOIN T_DOC_OUTBOUND_SCAN_ORDERTYPE o
ON o.SCAN_USER = h.SCAN_USER
AND (NVL(o.ORDERTYPE, '') = ''
OR NVL(h.ORDERTYPE, '') = ''
OR INSTR(',' || o.ORDERTYPE || ',', ',' || h.ORDERTYPE || ',') <![CDATA[ > ]]> 0)
AND (NVL(o.REFERENCE5, '') = ''
OR NVL(h.REFERENCE5, '') = ''
OR INSTR(',' || o.REFERENCE5 || ',', ',' || h.REFERENCE5 || ',') <![CDATA[ > ]]> 0)
AND (NVL(o.TEMPERATURECLASS, '') = ''
OR NVL(h.TEMPERATURECLASS, '') = ''
OR INSTR(',' || o.TEMPERATURECLASS || ',', ',' || h.TEMPERATURECLASS || ',') <![CDATA[ > ]]> 0)
WHERE 1=1
AND EXISTS (
SELECT 1
FROM T_DOC_OUTBOUND_SCAN_DETAIL d
WHERE d.ORDER_NO = h.ORDER_NO
AND d.IS_ODD_LOT = 'C'
)
<if test="customerName != null and customerName != ''">
AND h.customer_name LIKE CONCAT(CONCAT('%', #{customerName, jdbcType=VARCHAR}), '%')
</if>
<if test="orderNo != null and orderNo != ''">
AND h.order_no = #{orderNo, jdbcType=VARCHAR}
</if>
<if test="statusList != null and statusList.size() > 0">
AND h.status IN
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status, jdbcType=VARCHAR}
</foreach>
</if>
<if test="scanUser != null and scanUser != ''">
AND h.scan_user = #{scanUser, jdbcType=VARCHAR}
</if>
ORDER BY h.customer_name, h.create_time DESC
</select>
</mapper> </mapper>
\ No newline at end of file
package com.ekingwin.tms_app;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class TmsAppApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment