8 changed files with 962 additions and 0 deletions
-
183src/main/java/com/gaotao/modules/warehouse/controller/CountingWIPController.java
-
26src/main/java/com/gaotao/modules/warehouse/dao/CountingReportMapper.java
-
100src/main/java/com/gaotao/modules/warehouse/dao/CountingWIPMapper.java
-
67src/main/java/com/gaotao/modules/warehouse/entity/CountingWIP.java
-
71src/main/java/com/gaotao/modules/warehouse/service/CountingWIPService.java
-
283src/main/java/com/gaotao/modules/warehouse/service/impl/CountingWIPServiceImpl.java
-
49src/main/resources/mapper/warehouse/CountingReportMapper.xml
-
183src/main/resources/mapper/warehouse/CountingWIPMapper.xml
@ -0,0 +1,183 @@ |
|||||
|
package com.gaotao.modules.warehouse.controller; |
||||
|
|
||||
|
import com.gaotao.common.utils.R; |
||||
|
import com.gaotao.modules.sys.controller.AbstractController; |
||||
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
||||
|
import com.gaotao.modules.warehouse.entity.CountingWIP; |
||||
|
import com.gaotao.modules.warehouse.service.CountingWIPService; |
||||
|
import org.apache.shiro.SecurityUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 盘点扫描暂存区控制器 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("warehouse/countingWIP") |
||||
|
public class CountingWIPController extends AbstractController { |
||||
|
|
||||
|
@Autowired |
||||
|
private CountingWIPService countingWIPService; |
||||
|
|
||||
|
/** |
||||
|
* 查询当天的盘点单列表(PDA列表页) |
||||
|
*/ |
||||
|
@PostMapping("todayList") |
||||
|
public R todayList(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
// 添加当前用户信息 |
||||
|
params.put("userName", ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername()); |
||||
|
|
||||
|
List<Map<String, Object>> list = countingWIPService.queryTodayCountingList(params); |
||||
|
|
||||
|
return R.ok() |
||||
|
.put("code", 0) |
||||
|
.put("msg", "查询成功") |
||||
|
.put("list", list); |
||||
|
} catch (Exception e) { |
||||
|
logger.error("查询当天的盘点单列表失败", e); |
||||
|
return R.error("查询失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据盘点单号查询WIP数据(PDA明细页) |
||||
|
*/ |
||||
|
@PostMapping("wipList") |
||||
|
public R wipList(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
String site = (String) params.get("site"); |
||||
|
String buNo = (String) params.get("buNo"); |
||||
|
String reportId = (String) params.get("reportId"); |
||||
|
|
||||
|
if (site == null || site.isEmpty()) { |
||||
|
return R.error("站点不能为空"); |
||||
|
} |
||||
|
if (reportId == null || reportId.isEmpty()) { |
||||
|
return R.error("盘点任务单号不能为空"); |
||||
|
} |
||||
|
|
||||
|
Map<String, Object> result = countingWIPService.queryWIPWithStatistics(site, buNo, reportId); |
||||
|
|
||||
|
return R.ok() |
||||
|
.put("code", 0) |
||||
|
.put("msg", "查询成功") |
||||
|
.put("wipList", result.get("wipList")) |
||||
|
.put("totalCount", result.get("totalCount")) |
||||
|
.put("totalQty", result.get("totalQty")) |
||||
|
.put("checkedCount", result.get("checkedCount")) |
||||
|
.put("checkedQty", result.get("checkedQty")); |
||||
|
} catch (Exception e) { |
||||
|
logger.error("查询WIP数据失败", e); |
||||
|
return R.error("查询失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 扫描标签 |
||||
|
*/ |
||||
|
@PostMapping("scanLabel") |
||||
|
public R scanLabel(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
String site = (String) params.get("site"); |
||||
|
String reportId = (String) params.get("reportId"); |
||||
|
String rollNo = (String) params.get("rollNo"); |
||||
|
|
||||
|
if (site == null || site.isEmpty()) { |
||||
|
return R.error("站点不能为空"); |
||||
|
} |
||||
|
if (reportId == null || reportId.isEmpty()) { |
||||
|
return R.error("盘点任务单号不能为空"); |
||||
|
} |
||||
|
if (rollNo == null || rollNo.isEmpty()) { |
||||
|
return R.error("标签条码不能为空"); |
||||
|
} |
||||
|
|
||||
|
String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); |
||||
|
Map<String, Object> result = countingWIPService.scanLabel(site, reportId, rollNo, username); |
||||
|
|
||||
|
if ((Boolean) result.get("success")) { |
||||
|
return R.ok() |
||||
|
.put("code", 0) |
||||
|
.put("msg", result.get("message")) |
||||
|
.put("data", result.get("data")); |
||||
|
} else { |
||||
|
return R.error((String) result.get("message")); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
logger.error("扫描标签失败", e); |
||||
|
return R.error("扫描失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新盘点数量 |
||||
|
*/ |
||||
|
@PostMapping("updateCheckedQty") |
||||
|
public R updateCheckedQty(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
String site = (String) params.get("site"); |
||||
|
String reportId = (String) params.get("reportId"); |
||||
|
String rollNo = (String) params.get("rollNo"); |
||||
|
Object checkedQtyObj = params.get("checkedQty"); |
||||
|
|
||||
|
if (site == null || site.isEmpty()) { |
||||
|
return R.error("站点不能为空"); |
||||
|
} |
||||
|
if (reportId == null || reportId.isEmpty()) { |
||||
|
return R.error("盘点任务单号不能为空"); |
||||
|
} |
||||
|
if (rollNo == null || rollNo.isEmpty()) { |
||||
|
return R.error("标签条码不能为空"); |
||||
|
} |
||||
|
if (checkedQtyObj == null) { |
||||
|
return R.error("盘点数量不能为空"); |
||||
|
} |
||||
|
|
||||
|
Float checkedQty = Float.parseFloat(checkedQtyObj.toString()); |
||||
|
countingWIPService.updateCheckedQty(site, reportId, rollNo, checkedQty); |
||||
|
|
||||
|
return R.ok() |
||||
|
.put("code", 0) |
||||
|
.put("msg", "更新成功"); |
||||
|
} catch (Exception e) { |
||||
|
logger.error("更新盘点数量失败", e); |
||||
|
return R.error("更新失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 确认盘点 |
||||
|
*/ |
||||
|
@PostMapping("confirmCounting") |
||||
|
public R confirmCounting(@RequestBody Map<String, Object> params) { |
||||
|
try { |
||||
|
String site = (String) params.get("site"); |
||||
|
String reportId = (String) params.get("reportId"); |
||||
|
|
||||
|
if (site == null || site.isEmpty()) { |
||||
|
return R.error("站点不能为空"); |
||||
|
} |
||||
|
if (reportId == null || reportId.isEmpty()) { |
||||
|
return R.error("盘点任务单号不能为空"); |
||||
|
} |
||||
|
|
||||
|
Map<String, Object> result = countingWIPService.confirmCounting(site, reportId); |
||||
|
|
||||
|
if ((Boolean) result.get("success")) { |
||||
|
return R.ok() |
||||
|
.put("code", 0) |
||||
|
.put("msg", result.get("message")); |
||||
|
} else { |
||||
|
return R.error((String) result.get("message")); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
logger.error("确认盘点失败", e); |
||||
|
return R.error("确认失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,100 @@ |
|||||
|
package com.gaotao.modules.warehouse.dao; |
||||
|
|
||||
|
import com.gaotao.modules.warehouse.entity.CountingWIP; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 盘点扫描暂存区Mapper接口 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface CountingWIPMapper { |
||||
|
|
||||
|
/** |
||||
|
* 查询当天的盘点单列表(用于PDA列表展示) |
||||
|
* |
||||
|
* @param params 查询参数 |
||||
|
* @return 盘点单列表 |
||||
|
*/ |
||||
|
List<Map<String, Object>> queryTodayCountingList(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 根据盘点单号查询WIP数据 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @return WIP数据列表 |
||||
|
*/ |
||||
|
List<CountingWIP> queryWIPByReportId(@Param("site") String site, |
||||
|
@Param("reportId") String reportId); |
||||
|
|
||||
|
/** |
||||
|
* 根据盘点单号查询WIP数据(带buNo) |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param buNo BU编码 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @return WIP数据列表 |
||||
|
*/ |
||||
|
List<CountingWIP> queryWIPByReportIdWithBuNo(@Param("site") String site, |
||||
|
@Param("buNo") String buNo, |
||||
|
@Param("reportId") String reportId); |
||||
|
|
||||
|
/** |
||||
|
* 新增WIP数据 |
||||
|
* |
||||
|
* @param countingWIP WIP数据 |
||||
|
* @return 影响行数 |
||||
|
*/ |
||||
|
int save(CountingWIP countingWIP); |
||||
|
|
||||
|
/** |
||||
|
* 更新WIP数据的盘点数量 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @param rollNo 标签条码 |
||||
|
* @param checkedQty 盘点数量 |
||||
|
* @return 影响行数 |
||||
|
*/ |
||||
|
int updateCheckedQty(@Param("site") String site, |
||||
|
@Param("reportId") String reportId, |
||||
|
@Param("rollNo") String rollNo, |
||||
|
@Param("checkedQty") Float checkedQty); |
||||
|
|
||||
|
/** |
||||
|
* 根据盘点单号删除WIP数据 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @return 影响行数 |
||||
|
*/ |
||||
|
int deleteByReportId(@Param("site") String site, |
||||
|
@Param("reportId") String reportId); |
||||
|
|
||||
|
/** |
||||
|
* 检查标签是否存在于WIP中 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @param rollNo 标签条码 |
||||
|
* @return WIP数据 |
||||
|
*/ |
||||
|
CountingWIP checkWIPExists(@Param("site") String site, |
||||
|
@Param("reportId") String reportId, |
||||
|
@Param("rollNo") String rollNo); |
||||
|
|
||||
|
/** |
||||
|
* 根据标签条码查询库存信息 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param rollNo 标签条码 |
||||
|
* @return 库存信息 |
||||
|
*/ |
||||
|
Map<String, Object> queryInventoryByRollNo(@Param("site") String site, |
||||
|
@Param("rollNo") String rollNo); |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,67 @@ |
|||||
|
package com.gaotao.modules.warehouse.entity; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 盘点扫描暂存区实体类 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class CountingWIP implements Serializable { |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 站点编码 |
||||
|
*/ |
||||
|
private String site; |
||||
|
|
||||
|
/** |
||||
|
* BU编码 |
||||
|
*/ |
||||
|
private String buNo; |
||||
|
|
||||
|
/** |
||||
|
* 盘点任务单号,与主表关联 |
||||
|
*/ |
||||
|
private String reportId; |
||||
|
|
||||
|
/** |
||||
|
* 标签条码,如 B202506001 |
||||
|
*/ |
||||
|
private String rollNo; |
||||
|
|
||||
|
/** |
||||
|
* 标签数量 |
||||
|
*/ |
||||
|
private Float rollQty; |
||||
|
|
||||
|
/** |
||||
|
* 实际盘点数量 |
||||
|
*/ |
||||
|
private Float checkedQty; |
||||
|
|
||||
|
/** |
||||
|
* 创建人账号 |
||||
|
*/ |
||||
|
private String username; |
||||
|
|
||||
|
/** |
||||
|
* 创建时间 |
||||
|
*/ |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
|
private Date createDate; |
||||
|
|
||||
|
/** |
||||
|
* 盘点状态:正常、盘盈、盘亏 |
||||
|
*/ |
||||
|
private String checkedStatus; |
||||
|
|
||||
|
// 扩展字段 |
||||
|
private String partNo; // 物料编码 |
||||
|
private String partDesc; // 物料名称 |
||||
|
private String labelType; // 标签类型 |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,71 @@ |
|||||
|
package com.gaotao.modules.warehouse.service; |
||||
|
|
||||
|
import com.gaotao.modules.warehouse.entity.CountingWIP; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 盘点扫描暂存区Service接口 |
||||
|
*/ |
||||
|
public interface CountingWIPService { |
||||
|
|
||||
|
/** |
||||
|
* 查询当天的盘点单列表(用于PDA列表展示) |
||||
|
* |
||||
|
* @param params 查询参数 |
||||
|
* @return 盘点单列表 |
||||
|
*/ |
||||
|
List<Map<String, Object>> queryTodayCountingList(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 根据盘点单号查询WIP数据 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @return WIP数据列表 |
||||
|
*/ |
||||
|
List<CountingWIP> queryWIPByReportId(String site, String reportId); |
||||
|
|
||||
|
/** |
||||
|
* 根据盘点单号查询WIP数据及统计信息 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param buNo BU编码 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @return 包含WIP数据和统计信息的Map |
||||
|
*/ |
||||
|
Map<String, Object> queryWIPWithStatistics(String site, String buNo, String reportId); |
||||
|
|
||||
|
/** |
||||
|
* 扫描标签并添加到WIP |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @param rollNo 标签条码 |
||||
|
* @param username 用户名 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
Map<String, Object> scanLabel(String site, String reportId, String rollNo, String username); |
||||
|
|
||||
|
/** |
||||
|
* 更新WIP数据的盘点数量 |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @param rollNo 标签条码 |
||||
|
* @param checkedQty 盘点数量 |
||||
|
* @return 影响行数 |
||||
|
*/ |
||||
|
int updateCheckedQty(String site, String reportId, String rollNo, Float checkedQty); |
||||
|
|
||||
|
/** |
||||
|
* 确认盘点(将WIP数据反刷到明细表) |
||||
|
* |
||||
|
* @param site 站点 |
||||
|
* @param reportId 盘点任务单号 |
||||
|
* @return 操作结果 |
||||
|
*/ |
||||
|
Map<String, Object> confirmCounting(String site, String reportId); |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,283 @@ |
|||||
|
package com.gaotao.modules.warehouse.service.impl; |
||||
|
|
||||
|
import com.gaotao.modules.warehouse.dao.CountingReportMapper; |
||||
|
import com.gaotao.modules.warehouse.dao.CountingWIPMapper; |
||||
|
import com.gaotao.modules.warehouse.entity.CountingReportDetail; |
||||
|
import com.gaotao.modules.warehouse.entity.CountingWIP; |
||||
|
import com.gaotao.modules.warehouse.service.CountingWIPService; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 盘点扫描暂存区Service实现类 |
||||
|
*/ |
||||
|
@Service("countingWIPService") |
||||
|
public class CountingWIPServiceImpl implements CountingWIPService { |
||||
|
|
||||
|
private static final Logger logger = LoggerFactory.getLogger(CountingWIPServiceImpl.class); |
||||
|
|
||||
|
@Autowired |
||||
|
private CountingWIPMapper countingWIPMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private CountingReportMapper countingReportMapper; |
||||
|
|
||||
|
@Override |
||||
|
public List<Map<String, Object>> queryTodayCountingList(Map<String, Object> params) { |
||||
|
logger.info("查询当天的盘点单列表"); |
||||
|
try { |
||||
|
List<Map<String, Object>> list = countingWIPMapper.queryTodayCountingList(params); |
||||
|
logger.info("查询当天的盘点单列表成功,数量: {}", list != null ? list.size() : 0); |
||||
|
return list; |
||||
|
} catch (Exception e) { |
||||
|
logger.error("查询当天的盘点单列表失败,错误信息: {}", e.getMessage(), e); |
||||
|
throw new RuntimeException("查询当天的盘点单列表失败: " + e.getMessage(), e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<CountingWIP> queryWIPByReportId(String site, String reportId) { |
||||
|
logger.info("根据盘点单号查询WIP数据,盘点任务单号: {}", reportId); |
||||
|
try { |
||||
|
List<CountingWIP> wipList = countingWIPMapper.queryWIPByReportId(site, reportId); |
||||
|
logger.info("查询WIP数据成功,数量: {}", wipList != null ? wipList.size() : 0); |
||||
|
return wipList; |
||||
|
} catch (Exception e) { |
||||
|
logger.error("查询WIP数据失败,错误信息: {}", e.getMessage(), e); |
||||
|
throw new RuntimeException("查询WIP数据失败: " + e.getMessage(), e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Map<String, Object> queryWIPWithStatistics(String site, String buNo, String reportId) { |
||||
|
logger.info("根据盘点单号查询WIP数据及统计信息,站点: {}, BU: {}, 盘点任务单号: {}", site, buNo, reportId); |
||||
|
Map<String, Object> result = new HashMap<>(); |
||||
|
|
||||
|
try { |
||||
|
// 1. 查询WIP数据(使用带buNo的查询方法) |
||||
|
List<CountingWIP> wipList = buNo != null && !buNo.isEmpty() |
||||
|
? countingWIPMapper.queryWIPByReportIdWithBuNo(site, buNo, reportId) |
||||
|
: countingWIPMapper.queryWIPByReportId(site, reportId); |
||||
|
|
||||
|
// 2. 查询明细表统计信息 |
||||
|
List<CountingReportDetail> detailList = countingReportMapper.queryDetailList(site, buNo, reportId); |
||||
|
|
||||
|
// 3. 计算统计信息 |
||||
|
int totalCount = 0; |
||||
|
float totalQty = 0f; |
||||
|
int checkedCount = 0; |
||||
|
float checkedQty = 0f; |
||||
|
|
||||
|
if (detailList != null) { |
||||
|
totalCount = detailList.size(); |
||||
|
for (CountingReportDetail detail : detailList) { |
||||
|
// 总物料数 |
||||
|
if (detail.getRollQty() != null) { |
||||
|
totalQty += detail.getRollQty(); |
||||
|
} |
||||
|
// 已盘点统计 |
||||
|
if ("Y".equals(detail.getCheckedFlag())) { |
||||
|
checkedCount++; |
||||
|
if (detail.getCheckedQty() != null) { |
||||
|
checkedQty += detail.getCheckedQty(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.put("wipList", wipList); |
||||
|
result.put("totalCount", totalCount); |
||||
|
result.put("totalQty", totalQty); |
||||
|
result.put("checkedCount", checkedCount); |
||||
|
result.put("checkedQty", checkedQty); |
||||
|
|
||||
|
logger.info("查询WIP数据及统计信息成功,WIP数量: {}, 总标签数: {}, 总物料数: {}, 已盘点标签数: {}, 已盘点物料数: {}", |
||||
|
wipList != null ? wipList.size() : 0, totalCount, totalQty, checkedCount, checkedQty); |
||||
|
return result; |
||||
|
} catch (Exception e) { |
||||
|
logger.error("查询WIP数据及统计信息失败,错误信息: {}", e.getMessage(), e); |
||||
|
throw new RuntimeException("查询WIP数据及统计信息失败: " + e.getMessage(), e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public Map<String, Object> scanLabel(String site, String reportId, String rollNo, String username) { |
||||
|
logger.info("扫描标签,盘点单号: {}, 标签条码: {}", reportId, rollNo); |
||||
|
Map<String, Object> result = new HashMap<>(); |
||||
|
|
||||
|
try { |
||||
|
// 1. 检查标签是否已在WIP中 |
||||
|
CountingWIP existsWIP = countingWIPMapper.checkWIPExists(site, reportId, rollNo); |
||||
|
if (existsWIP != null) { |
||||
|
result.put("success", false); |
||||
|
result.put("message", "该标签已扫描!"); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// 2. 获取盘点单的 buNo |
||||
|
Map<String, Object> reportParams = new HashMap<>(); |
||||
|
reportParams.put("site", site); |
||||
|
reportParams.put("reportId", reportId); |
||||
|
reportParams.put("userName", username); |
||||
|
List<Map<String, Object>> reportList = countingReportMapper.queryList(reportParams); |
||||
|
String buNo = null; |
||||
|
if (reportList != null && !reportList.isEmpty()) { |
||||
|
Map<String, Object> report = reportList.get(0); |
||||
|
buNo = (String) report.get("buNo"); |
||||
|
logger.info("获取到盘点单的 buNo: {}", buNo); |
||||
|
} |
||||
|
|
||||
|
if (buNo == null || buNo.isEmpty()) { |
||||
|
logger.error("无法获取盘点单的 buNo,盘点单号: {}, 用户: {}", reportId, username); |
||||
|
result.put("success", false); |
||||
|
result.put("message", "盘点单信息异常,无法获取 BU 编码"); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// 3. 在明细表中查询标签(正常情况) |
||||
|
List<CountingReportDetail> detailList = countingReportMapper.queryDetailList(site, buNo, reportId); |
||||
|
CountingReportDetail detail = null; |
||||
|
for (CountingReportDetail d : detailList) { |
||||
|
if (rollNo.equals(d.getRollNo())) { |
||||
|
detail = d; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
CountingWIP wip = new CountingWIP(); |
||||
|
wip.setSite(site); |
||||
|
wip.setBuNo(buNo); |
||||
|
wip.setReportId(reportId); |
||||
|
wip.setRollNo(rollNo); |
||||
|
wip.setUsername(username); |
||||
|
|
||||
|
if (detail != null) { |
||||
|
// 正常:在明细表中找到 |
||||
|
wip.setRollQty(detail.getRollQty() != null ? detail.getRollQty().floatValue() : 0f); |
||||
|
wip.setCheckedQty(detail.getRollQty() != null ? detail.getRollQty().floatValue() : 0f); |
||||
|
wip.setCheckedStatus("正常"); |
||||
|
wip.setPartNo(detail.getPartNo()); |
||||
|
wip.setPartDesc(detail.getPartDesc()); |
||||
|
wip.setLabelType(detail.getLabelType()); |
||||
|
} else { |
||||
|
// 4. 在库存表中查询标签(盘盈情况) |
||||
|
Map<String, Object> inventory = countingWIPMapper.queryInventoryByRollNo(site, rollNo); |
||||
|
if (inventory != null && !inventory.isEmpty()) { |
||||
|
// 盘盈:在库存表中找到 |
||||
|
Object rollQtyObj = inventory.get("rollQty"); |
||||
|
Float rollQty = 0f; |
||||
|
if (rollQtyObj != null) { |
||||
|
if (rollQtyObj instanceof Integer) { |
||||
|
rollQty = ((Integer) rollQtyObj).floatValue(); |
||||
|
} else if (rollQtyObj instanceof Float) { |
||||
|
rollQty = (Float) rollQtyObj; |
||||
|
} else if (rollQtyObj instanceof Double) { |
||||
|
rollQty = ((Double) rollQtyObj).floatValue(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
wip.setRollQty(rollQty); |
||||
|
wip.setCheckedQty(rollQty); |
||||
|
wip.setCheckedStatus("盘盈"); |
||||
|
wip.setPartNo((String) inventory.get("partNo")); |
||||
|
wip.setPartDesc((String) inventory.get("partDesc")); |
||||
|
wip.setLabelType((String) inventory.get("labelType")); |
||||
|
} else { |
||||
|
// 标签不存在 |
||||
|
result.put("success", false); |
||||
|
result.put("message", "该标签不存在!"); |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 5. 保存到WIP表 |
||||
|
countingWIPMapper.save(wip); |
||||
|
|
||||
|
result.put("success", true); |
||||
|
result.put("message", "扫描成功"); |
||||
|
result.put("data", wip); |
||||
|
logger.info("扫描标签成功,状态: {}", wip.getCheckedStatus()); |
||||
|
return result; |
||||
|
} catch (Exception e) { |
||||
|
logger.error("扫描标签失败,错误信息: {}", e.getMessage(), e); |
||||
|
throw new RuntimeException("扫描标签失败: " + e.getMessage(), e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int updateCheckedQty(String site, String reportId, String rollNo, Float checkedQty) { |
||||
|
logger.info("更新盘点数量,标签条码: {}, 数量: {}", rollNo, checkedQty); |
||||
|
try { |
||||
|
int result = countingWIPMapper.updateCheckedQty(site, reportId, rollNo, checkedQty); |
||||
|
logger.info("更新盘点数量成功"); |
||||
|
return result; |
||||
|
} catch (Exception e) { |
||||
|
logger.error("更新盘点数量失败,错误信息: {}", e.getMessage(), e); |
||||
|
throw new RuntimeException("更新盘点数量失败: " + e.getMessage(), e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public Map<String, Object> confirmCounting(String site, String reportId) { |
||||
|
logger.info("确认盘点,盘点单号: {}", reportId); |
||||
|
Map<String, Object> result = new HashMap<>(); |
||||
|
|
||||
|
try { |
||||
|
// 1. 查询WIP数据 |
||||
|
List<CountingWIP> wipList = countingWIPMapper.queryWIPByReportId(site, reportId); |
||||
|
if (wipList == null || wipList.isEmpty()) { |
||||
|
result.put("success", false); |
||||
|
result.put("message", "没有需要确认的盘点数据"); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// 2. 反刷数据到明细表 |
||||
|
for (CountingWIP wip : wipList) { |
||||
|
if ("正常".equals(wip.getCheckedStatus())) { |
||||
|
// 正常:更新明细表的盘点数量和状态 |
||||
|
countingReportMapper.updateDetailCheckedQty(site, reportId, wip.getRollNo(), |
||||
|
wip.getCheckedQty(), "正常", "Y"); |
||||
|
} else if ("盘盈".equals(wip.getCheckedStatus())) { |
||||
|
// 盘盈:添加到明细表 |
||||
|
CountingReportDetail detail = new CountingReportDetail(); |
||||
|
detail.setSite(site); |
||||
|
detail.setBuNo(wip.getBuNo()); |
||||
|
detail.setReportId(reportId); |
||||
|
detail.setRollNo(wip.getRollNo()); |
||||
|
detail.setRollQty(wip.getRollQty() != null ? wip.getRollQty().intValue() : 0); |
||||
|
detail.setLabelType(wip.getLabelType()); |
||||
|
detail.setPartNo(wip.getPartNo()); |
||||
|
detail.setPartDesc(wip.getPartDesc()); |
||||
|
detail.setCheckedFlag("Y"); |
||||
|
detail.setCheckedStatus("盘盈"); |
||||
|
detail.setCheckedQty(wip.getCheckedQty()); |
||||
|
detail.setCreateBy(wip.getUsername()); |
||||
|
detail.setUpdateBy(wip.getUsername()); |
||||
|
|
||||
|
countingReportMapper.saveDetail(detail); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 3. 删除WIP数据 |
||||
|
countingWIPMapper.deleteByReportId(site, reportId); |
||||
|
|
||||
|
result.put("success", true); |
||||
|
result.put("message", "盘点确认成功"); |
||||
|
logger.info("确认盘点成功"); |
||||
|
return result; |
||||
|
} catch (Exception e) { |
||||
|
logger.error("确认盘点失败,错误信息: {}", e.getMessage(), e); |
||||
|
throw new RuntimeException("确认盘点失败: " + e.getMessage(), e); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,183 @@ |
|||||
|
<?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.gaotao.modules.warehouse.dao.CountingWIPMapper"> |
||||
|
|
||||
|
<!-- 结果映射 --> |
||||
|
<resultMap id="countingWIPMap" type="com.gaotao.modules.warehouse.entity.CountingWIP"> |
||||
|
<result property="site" column="site"/> |
||||
|
<result property="buNo" column="bu_no"/> |
||||
|
<result property="reportId" column="report_id"/> |
||||
|
<result property="rollNo" column="roll_no"/> |
||||
|
<result property="rollQty" column="roll_qty"/> |
||||
|
<result property="checkedQty" column="checked_qty"/> |
||||
|
<result property="username" column="username"/> |
||||
|
<result property="createDate" column="create_date"/> |
||||
|
<result property="checkedStatus" column="checked_status"/> |
||||
|
<result property="partNo" column="part_no"/> |
||||
|
<result property="partDesc" column="part_desc"/> |
||||
|
<result property="labelType" column="label_type"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<!-- 查询当天的盘点单列表 --> |
||||
|
<select id="queryTodayCountingList" resultType="map"> |
||||
|
SELECT |
||||
|
cr.site, |
||||
|
cr.bu_no AS buNo, |
||||
|
cr.report_id AS reportId, |
||||
|
cr.check_dimension AS checkDimension, |
||||
|
cr.plan_date AS planDate, |
||||
|
cr.status, |
||||
|
CASE cr.status |
||||
|
WHEN 0 THEN '草稿' |
||||
|
WHEN 1 THEN '盘点中' |
||||
|
WHEN 2 THEN '待核销' |
||||
|
WHEN 3 THEN '已完成' |
||||
|
ELSE '未知' |
||||
|
END AS statusDesc, |
||||
|
-- 标签总数 |
||||
|
(SELECT COUNT(*) FROM counting_report_detail WHERE site = cr.site AND report_id = cr.report_id) AS totalCount, |
||||
|
-- 已盘点标签数 |
||||
|
(SELECT COUNT(*) FROM counting_report_detail WHERE site = cr.site AND report_id = cr.report_id AND checked_flag = 'Y') AS checkedCount, |
||||
|
-- 物料总数(所有标签数量总和) |
||||
|
(SELECT ISNULL(SUM(roll_qty), 0) FROM counting_report_detail WHERE site = cr.site AND report_id = cr.report_id) AS totalQty, |
||||
|
-- 已盘点数(已盘点标签数量总和) |
||||
|
(SELECT ISNULL(SUM(checked_qty), 0) FROM counting_report_detail WHERE site = cr.site AND report_id = cr.report_id AND checked_flag = 'Y') AS checkedQty |
||||
|
FROM counting_report cr |
||||
|
WHERE cr.site IN (SELECT site FROM AccessSite WHERE UPPER(userID) = #{userName}) |
||||
|
AND cr.bu_no IN (SELECT bu_no FROM AccessBu WHERE username = #{userName}) |
||||
|
AND CONVERT(varchar(10), cr.plan_date, 120) = CONVERT(varchar(10), GETDATE(), 120) |
||||
|
<if test="reportId != null and reportId != ''"> |
||||
|
AND cr.report_id LIKE '%' + #{reportId} + '%' |
||||
|
</if> |
||||
|
ORDER BY cr.create_date DESC |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据盘点单号查询WIP数据 --> |
||||
|
<select id="queryWIPByReportId" resultMap="countingWIPMap"> |
||||
|
SELECT |
||||
|
site, |
||||
|
bu_no, |
||||
|
report_id, |
||||
|
roll_no, |
||||
|
roll_qty, |
||||
|
checked_qty, |
||||
|
username, |
||||
|
create_date, |
||||
|
checked_status, |
||||
|
part_no, |
||||
|
part_desc, |
||||
|
label_type |
||||
|
FROM CountingWIP |
||||
|
WHERE site = #{site} |
||||
|
AND report_id = #{reportId} |
||||
|
ORDER BY create_date DESC |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据盘点单号查询WIP数据(带buNo) --> |
||||
|
<select id="queryWIPByReportIdWithBuNo" resultMap="countingWIPMap"> |
||||
|
SELECT |
||||
|
site, |
||||
|
bu_no, |
||||
|
report_id, |
||||
|
roll_no, |
||||
|
roll_qty, |
||||
|
checked_qty, |
||||
|
username, |
||||
|
create_date, |
||||
|
checked_status, |
||||
|
part_no, |
||||
|
part_desc, |
||||
|
label_type |
||||
|
FROM CountingWIP |
||||
|
WHERE site = #{site} |
||||
|
AND bu_no = #{buNo} |
||||
|
AND report_id = #{reportId} |
||||
|
ORDER BY create_date DESC |
||||
|
</select> |
||||
|
|
||||
|
<!-- 新增WIP数据 --> |
||||
|
<insert id="save"> |
||||
|
INSERT INTO CountingWIP ( |
||||
|
site, |
||||
|
bu_no, |
||||
|
report_id, |
||||
|
roll_no, |
||||
|
roll_qty, |
||||
|
checked_qty, |
||||
|
username, |
||||
|
create_date, |
||||
|
checked_status, |
||||
|
part_no, |
||||
|
part_desc, |
||||
|
label_type |
||||
|
) VALUES ( |
||||
|
#{site}, |
||||
|
#{buNo}, |
||||
|
#{reportId}, |
||||
|
#{rollNo}, |
||||
|
#{rollQty}, |
||||
|
#{checkedQty}, |
||||
|
#{username}, |
||||
|
GETDATE(), |
||||
|
#{checkedStatus}, |
||||
|
#{partNo}, |
||||
|
#{partDesc}, |
||||
|
#{labelType} |
||||
|
) |
||||
|
</insert> |
||||
|
|
||||
|
<!-- 更新WIP数据的盘点数量 --> |
||||
|
<update id="updateCheckedQty"> |
||||
|
UPDATE CountingWIP |
||||
|
SET checked_qty = #{checkedQty} |
||||
|
WHERE site = #{site} |
||||
|
AND report_id = #{reportId} |
||||
|
AND roll_no = #{rollNo} |
||||
|
</update> |
||||
|
|
||||
|
<!-- 根据盘点单号删除WIP数据 --> |
||||
|
<delete id="deleteByReportId"> |
||||
|
DELETE FROM CountingWIP |
||||
|
WHERE site = #{site} |
||||
|
AND report_id = #{reportId} |
||||
|
</delete> |
||||
|
|
||||
|
<!-- 检查标签是否存在于WIP中 --> |
||||
|
<select id="checkWIPExists" resultMap="countingWIPMap"> |
||||
|
SELECT |
||||
|
site, |
||||
|
bu_no, |
||||
|
report_id, |
||||
|
roll_no, |
||||
|
roll_qty, |
||||
|
checked_qty, |
||||
|
username, |
||||
|
create_date, |
||||
|
checked_status, |
||||
|
part_no, |
||||
|
part_desc, |
||||
|
label_type |
||||
|
FROM CountingWIP |
||||
|
WHERE site = #{site} |
||||
|
AND report_id = #{reportId} |
||||
|
AND roll_no = #{rollNo} |
||||
|
</select> |
||||
|
|
||||
|
<!-- 根据标签条码查询库存信息 --> |
||||
|
<select id="queryInventoryByRollNo" resultType="map"> |
||||
|
SELECT |
||||
|
a.site, |
||||
|
a.roll_no AS rollNo, |
||||
|
a.qty_on_hand AS rollQty, |
||||
|
a.label_type AS labelType, |
||||
|
a.part_no AS partNo, |
||||
|
p.PartDescription AS partDesc |
||||
|
FROM inventory_stock AS a |
||||
|
LEFT JOIN part AS p ON a.site = p.site AND a.part_no = p.partNo |
||||
|
WHERE a.site = #{site} |
||||
|
AND a.roll_no = #{rollNo} |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue