生成出入库单据逻辑修改

This commit is contained in:
2025-12-25 09:42:51 +08:00
parent 0fe1ee916c
commit b0bbeeec7c
9 changed files with 334 additions and 300 deletions

View File

@@ -50,7 +50,7 @@ public class GysJhController extends BaseController
* @param sapNo
* @return
*/
@PreAuthorize("@ss.hasPermi('plan:jh:list')")
// @PreAuthorize("@ss.hasPermi('plan:jh:list')")
@GetMapping("/getBySapNo")
public AjaxResult getBySapNo(String sapNo)
{
@@ -81,7 +81,6 @@ public class GysJhController extends BaseController
ExcelUtil<GysJh> util = new ExcelUtil<>(GysJh.class);
List<GysJh> jhList = util.importExcel(file.getInputStream());
String operName = getUsername();
String message = gysJhService.importGysJhList(jhList, operName);
return AjaxResult.success(message);
}

View File

@@ -51,7 +51,6 @@ public class RkInfoController extends BaseController
query.getPageNum() == null ? 1 : query.getPageNum(),
query.getPageSize() == null ? 10 : query.getPageSize()
);
List<RkInfo> list = rkInfoService.selectRkInfoList(query);
return getDataTable(list);
}
@@ -75,14 +74,8 @@ public class RkInfoController extends BaseController
// 使用 PageHelper 分页
PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
List<RkInfo> list = rkInfoService.selectAllRkInfo(dto);
// 统计金额
Long sumMoney = rkInfoService.selectStatistics(dto);
// 统计库位
Long pcdeCount = rkInfoService.selectPcde(dto);
Map<String,Object> dataInfo = new HashMap<>();
dataInfo.put("dataList",getDataTable(list));
dataInfo.put("sumMoney",sumMoney);
dataInfo.put("pcdeCount",pcdeCount);
return dataInfo;
}
@@ -360,4 +353,16 @@ public class RkInfoController extends BaseController
}
@PostMapping("/statistics")
public Map<String, Object> statistics(@RequestBody RkInfoQueryDTO dto) {
Long sumMoney = rkInfoService.selectStatistics(dto);
Long pcdeCount = rkInfoService.selectPcde(dto);
Map<String, Object> dataInfo = new HashMap<>();
dataInfo.put("sumMoney", sumMoney);
dataInfo.put("pcdeCount", pcdeCount);
return dataInfo;
}
}

View File

@@ -68,13 +68,10 @@ public class GysJh extends BaseEntity
private String xh;
/** 计划交货数量 */
@Excel(name = "计划交货数量")
private Long jhQty;
private BigDecimal jhQty;
/** 合同数量 */
@Excel(name = "合同数量")
private Long htQty;
private BigDecimal htQty;
/** 计量单位 */
@Excel(name = "计量单位")
private String dw;
@@ -225,25 +222,11 @@ public class GysJh extends BaseEntity
return xh;
}
public void setJhQty(Long jhQty)
{
this.jhQty = jhQty;
}
public void setJhQty(BigDecimal jhQty) { this.jhQty = jhQty; }
public BigDecimal getJhQty() { return jhQty; }
public Long getJhQty()
{
return jhQty;
}
public void setHtQty(Long htQty)
{
this.htQty = htQty;
}
public Long getHtQty()
{
return htQty;
}
public void setHtQty(BigDecimal htQty) { this.htQty = htQty; }
public BigDecimal getHtQty() { return htQty; }
public void setDw(String dw)
{

View File

@@ -243,7 +243,7 @@ public interface RkInfoMapper
/**
* 查询出库单据
*/
List<RkInfo> selectDeliveryCkList(@Param("q") RkInfo query);
List<RkInfo> selectDeliveryCkList(RkInfo query);
/**
@@ -252,4 +252,6 @@ public interface RkInfoMapper
List<RkInfo> selectBorrowAndReturnList(RkInfo rkInfo);
RkInfo selectHeaderByBillNo(String billNo);
String selectMaxBillNo(@Param("prefix") String prefix);
}

View File

@@ -271,11 +271,13 @@ public class GysJhServiceImpl implements IGysJhService
item.setHtDj(parseBigDecimal(cellValue));
break;
case "jhQty":
// Long这里用 Long避免 BigDecimal 转 Long 的报错
item.setJhQty(parseLong(cellValue));
item.setJhQty(parseBigDecimal(cellValue));
break;
case "htQty":
item.setHtQty(parseLong(cellValue));
item.setHtQty(parseBigDecimal(cellValue));
break;
case "entityId":
item.setEntityId(cellValue.trim());
break;
case "sapNo":
item.setSapNo(cellValue.trim());
@@ -289,8 +291,8 @@ public class GysJhServiceImpl implements IGysJhService
// 默认字段
item.setStatus("0");
item.setIsDelete("0");
// String username = SecurityUtils.getUsername();
item.setCreateBy("大爷的!!!");
String username = SecurityUtils.getUsername();
// item.setCreateBy("大爷的!!!");
item.setCreateTime(DateUtils.getNowDate());
result.add(item);

View File

@@ -158,15 +158,18 @@ public class MoveRecordServiceImpl implements IMoveRecordService
if (dto.getTargets().size() == 1 && totalQty.compareTo(realQty) == 0) {
MoveTargetItem target = dto.getTargets().get(0);
// 这里 info 用于记录移库前快照
// 记录移库前快照
RkInfo info = new RkInfo();
BeanUtils.copyProperties(original, info);
// 更新原库存到新位置
original.setWarehouseCode(target.getToCangku());
// 更新原库存到新位置(统一写入 cangku
original.setCangku(target.getToCangku());
original.setPcode(target.getToPcode());
original.setTrayCode(target.getToTrayCode());
// ✅ 发生移库就标记
original.setHasMoved("1");
original.setUpdateBy(username);
original.setUpdateTime(now);
rkInfoMapper.updateRkInfo(original);
@@ -179,9 +182,17 @@ public class MoveRecordServiceImpl implements IMoveRecordService
// ===== 情况二 & 三:需要新建多条库存记录 =====
List<RkInfo> insertList = new ArrayList<>();
// ✅ 注意:做移库的“来源记录快照”,用于日志一致性(不受后面数量更新影响)
RkInfo fromSnapshot = new RkInfo();
BeanUtils.copyProperties(original, fromSnapshot);
// 情况三:部分移库(目标总量 < 原库存) → 原库存数量减少
if (totalQty.compareTo(realQty) < 0) {
original.setRealQty(realQty.subtract(totalQty));
// ✅ 关键:发生移库就标记(你问的 has_moved 应该是 1
original.setHasMoved("1");
original.setUpdateBy(username);
original.setUpdateTime(now);
rkInfoMapper.updateRkInfo(original);
@@ -193,13 +204,19 @@ public class MoveRecordServiceImpl implements IMoveRecordService
// 新增多条目标库存
for (MoveTargetItem target : dto.getTargets()) {
RkInfo newInfo = new RkInfo();
// 注意:这里以 original 为模板(注意上面是否已修改过数量)
BeanUtils.copyProperties(original, newInfo, "id");
// ✅ 以“移库前快照”作为模板,避免被上面修改过数量影响其它字段
BeanUtils.copyProperties(fromSnapshot, newInfo, "id");
// ✅ 目标位置字段
newInfo.setCangku(target.getToCangku());
newInfo.setPcode(target.getToPcode());
newInfo.setTrayCode(target.getToTrayCode());
// ✅ 目标数量
newInfo.setRealQty(target.getRealQty());
// ✅ 发生移库就标记
newInfo.setHasMoved("1");
newInfo.setCreateBy(username);
@@ -209,8 +226,8 @@ public class MoveRecordServiceImpl implements IMoveRecordService
insertList.add(newInfo);
// 移库记录:从原库存 original → 每个 target
moveRecordMapper.insertMoveRecord(createMoveRecord(original, target, dto));
// 移库记录:从“移库前快照” → 每个 target(更准确)
moveRecordMapper.insertMoveRecord(createMoveRecord(fromSnapshot, target, dto));
}
if (!insertList.isEmpty()) {

View File

@@ -279,13 +279,15 @@ public class RkInfoServiceImpl implements IRkInfoService
if (jh != null) {
String status = jh.getStatus();
if ("2".equals(status)) {
// 回补 jh_qty改为未到货
BigDecimal updatedQty = (jh.getJhQty() == null ? BigDecimal.ZERO : new BigDecimal(jh.getJhQty()))
.add(realQty);
jh.setJhQty(updatedQty.longValue());
BigDecimal updatedQty =
(jh.getJhQty() == null ? BigDecimal.ZERO : jh.getJhQty())
.add(realQty);
jh.setJhQty(updatedQty);
jh.setStatus("0");
jh.setUpdateBy(userId);
jh.setUpdateTime(now);
gysJhMapper.updateGysJh(jh);
} else if ("1".equals(status)) {
// 只更新状态
@@ -355,7 +357,7 @@ public class RkInfoServiceImpl implements IRkInfoService
@Transactional(rollbackFor = Exception.class)
public void batchInsert(PcRkInfoBatchDTO dto) {
String billNo = BillNoUtil.generateTodayBillNo("RK");
String billNo = BillNoUtil.generateTodayBillNo("RK", rkInfoMapper);
List<PcRkInfoItemDTO> list = dto.getRkList();
List<RkInfo> rkInfos = new ArrayList<>();
List<AuditSignature> records = new ArrayList<>();
@@ -376,14 +378,15 @@ public class RkInfoServiceImpl implements IRkInfoService
(a, b) -> b
));
// ✅ 2-4. 供应计划扣减&状态更新(保留你原来的逻辑)
// ✅ 2-4. 供应计划扣减&状态更新
if (!realQtyMap.isEmpty()) {
List<GysJh> jhList = gysJhMapper.selectByIds(new ArrayList<>(realQtyMap.keySet()));
Set<Long> idsToUpdateStatus = new HashSet<>();
for (GysJh jh : jhList) {
Long jhId = jh.getId();
BigDecimal planQty = BigDecimal.valueOf(jh.getJhQty());
BigDecimal planQty =
jh.getJhQty() == null ? BigDecimal.ZERO : jh.getJhQty();
BigDecimal realQty = realQtyMap.get(jhId);
if (realQty == null) {
continue;
@@ -446,7 +449,6 @@ public class RkInfoServiceImpl implements IRkInfoService
rk.setStatus("1"); // 审核通过
rk.setIsChuku("0"); // 已入库
}
rkInfos.add(rk);
}
@@ -626,7 +628,7 @@ public class RkInfoServiceImpl implements IRkInfoService
}
boolean needAudit = "1".equals(configService.selectConfigByKey("rk.audit.enabled"));
String billNo = BillNoUtil.generateTodayBillNo("RK");
String billNo = BillNoUtil.generateTodayBillNo("RK", rkInfoMapper);
// ✅ 第1步构造 gysJhId → realQty 的映射(从 scanList 中提取)
Map<Long, BigDecimal> realQtyMap = new HashMap<>();
@@ -650,7 +652,9 @@ public class RkInfoServiceImpl implements IRkInfoService
List<GysJh> jhList = gysJhMapper.selectByIds(allJhIds);
for (GysJh jh : jhList) {
Long jhId = jh.getId();
BigDecimal planQty = BigDecimal.valueOf(jh.getJhQty());
BigDecimal planQty = jh.getJhQty() == null
? BigDecimal.ZERO
: jh.getJhQty();
BigDecimal realQty = realQtyMap.get(jhId);
if (realQty == null) {
continue;
@@ -867,7 +871,7 @@ public class RkInfoServiceImpl implements IRkInfoService
boolean needAudit = "1".equals(configService.selectConfigByKey("rk.audit.enabled"));
// Step 2: 生成出库单据号
String billNo = BillNoUtil.generateTodayBillNo("CK");
String billNo = BillNoUtil.generateTodayBillNo("RK", rkInfoMapper);
// Step 3: 批量更新 rk_info 出库字段
for (StockOutItemDTO item : dto.getCkList()) {
@@ -1122,7 +1126,7 @@ public class RkInfoServiceImpl implements IRkInfoService
newEntry.setPcode(newPcode);
newEntry.setRkType(dto.getRkType());
newEntry.setRkTime(DateUtils.getNowDate());
newEntry.setBillNo(BillNoUtil.generateTodayBillNo("RK"));
newEntry.setBillNo(BillNoUtil.generateTodayBillNo("RK", rkInfoMapper));
newEntry.setCreateBy(SecurityUtils.getUserId().toString());
newEntry.setCreateTime(DateUtils.getNowDate());
newEntry.setUpdateBy(null);
@@ -1288,7 +1292,7 @@ public class RkInfoServiceImpl implements IRkInfoService
// 计划剩余(表里 jh_qty 列)
BigDecimal remain = plan.getJhQty() == null
? BigDecimal.ZERO
: BigDecimal.valueOf(plan.getJhQty());
: plan.getJhQty();
// ① 全额入库realQty >= remain -> 直接置 1不做扣减
if (remain.compareTo(BigDecimal.ZERO) <= 0 || realQty.compareTo(remain) >= 0) {
@@ -1318,11 +1322,14 @@ public class RkInfoServiceImpl implements IRkInfoService
List<Long> toPartial = new ArrayList<>();
for (GysJh r : rows) {
long remain = r.getJhQty() == null ? 0L : r.getJhQty();
if (remain <= 0L) {
toAll.add(r.getId()); // 已经无剩余 -> 置 1
BigDecimal remain = r.getJhQty() == null
? BigDecimal.ZERO
: r.getJhQty();
if (remain.compareTo(BigDecimal.ZERO) <= 0) {
toAll.add(r.getId()); // 已经无剩余 -> 置 1全部入库
} else {
toPartial.add(r.getId()); // 仍有剩余 -> 置 2
toPartial.add(r.getId()); // 仍有剩余 -> 置 2(部分入库)
}
}

View File

@@ -1,5 +1,7 @@
package com.zg.project.wisdom.utils;
import com.zg.project.wisdom.mapper.RkInfoMapper;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@@ -7,28 +9,40 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
public class BillNoUtil {
// 内存缓存key = prefix + datevalue = 当前递增号
// 内存缓存key = prefix + yyyyMMdd
private static final Map<String, AtomicInteger> DAILY_SEQUENCE_MAP = new ConcurrentHashMap<>();
/**
* 生成当天单据号格式RK20250731_1、CK20250731_2
* @param prefix 单据前缀(如 RK 或 CK
* @return 单据号
* 生成当天单据号格式RK20251222_1
*/
public static synchronized String generateTodayBillNo(String prefix) {
if (prefix == null || prefix.trim().isEmpty()) {
prefix = "RK";
}
public static synchronized String generateTodayBillNo(String prefix, RkInfoMapper rkInfoMapper) {
// 获取当天日期字符串 yyyyMMdd
String today = new SimpleDateFormat("yyyyMMdd").format(new Date());
String key = prefix + today;
// ✅ 先得到最终前缀(不要让 lambda 捕获一个会被重新赋值的变量)
final String finalPrefix = (prefix == null || prefix.trim().isEmpty()) ? "RK" : prefix.trim();
// 获取并递增序号
AtomicInteger counter = DAILY_SEQUENCE_MAP.computeIfAbsent(key, k -> new AtomicInteger(1));
int sequence = counter.getAndIncrement();
// ✅ today / key 也用 final确保 lambda 可用
final String today = new SimpleDateFormat("yyyyMMdd").format(new Date());
final String key = finalPrefix + today;
final String likePrefix = finalPrefix + today + "_";
return prefix + today + "_" + sequence;
// 如果当天还没初始化,从数据库取最大号
AtomicInteger counter = DAILY_SEQUENCE_MAP.computeIfAbsent(key, k -> {
String maxBillNo = rkInfoMapper.selectMaxBillNo(likePrefix);
int start = 1;
if (maxBillNo != null) {
try {
String seqStr = maxBillNo.substring(maxBillNo.lastIndexOf("_") + 1);
start = Integer.parseInt(seqStr) + 1;
} catch (Exception ignored) {
}
}
return new AtomicInteger(start);
});
int seq = counter.getAndIncrement();
return finalPrefix + today + "_" + seq;
}
}

View File

@@ -282,8 +282,8 @@
</if>
<if test="endTime != null">
<![CDATA[
AND ri.rk_time < DATE_ADD(#{endTime}, INTERVAL 1 DAY)
]]>
AND ri.rk_time <= #{endTime}
]]>
</if>
<if test="lyStartTime != null">
@@ -381,6 +381,7 @@
ORDER BY ri.rk_time DESC
</select>
<!-- 借料 / 还料专用列表查询 -->
<select id="selectBorrowAndReturnList"
parameterType="RkInfo"
resultMap="RkInfoResult">
@@ -389,72 +390,29 @@
<where>
<!-- 只查未删除 -->
<choose>
<when test="isDelete != null and isDelete != ''">
AND ri.is_delete = #{isDelete}
</when>
<otherwise>
AND ri.is_delete = 0
</otherwise>
</choose>
AND ri.is_delete = 0
<!-- 借料/还料状态0 否1 借料中2 已归还 -->
<!-- ✅ 关键:只允许未出库的数据 -->
AND ri.is_chuku = '0'
<!-- 借料状态 -->
<choose>
<when test="isBorrowed != null and isBorrowed != ''">
AND ri.is_borrowed = #{isBorrowed}
</when>
<otherwise>
AND ri.is_borrowed IN ('1','2')
AND (ri.is_borrowed = 0 OR ri.is_borrowed IS NULL)
</otherwise>
</choose>
<!-- 时间范围:根据 isBorrowed 选择 borrow_time / return_time -->
<!-- 先添加通用时间条件如果isBorrowed为1或2时使用对应的时间字段 -->
<if test="startTime != null">
<choose>
<when test="isBorrowed != null and (isBorrowed == '1' or isBorrowed == 1)">
<![CDATA[
AND ri.borrow_time >= #{startTime}
]]>
</when>
<when test="isBorrowed != null and (isBorrowed == '2' or isBorrowed == 2)">
<![CDATA[
AND ri.return_time >= #{startTime}
]]>
</when>
<otherwise>
<![CDATA[
AND ri.rk_time >= #{startTime}
]]>
</otherwise>
</choose>
</if>
<if test="endTime != null">
<choose>
<when test="isBorrowed != null and (isBorrowed == '1' or isBorrowed == 1)">
<![CDATA[
AND ri.borrow_time < DATE_ADD(#{endTime}, INTERVAL 1 DAY)
]]>
</when>
<when test="isBorrowed != null and (isBorrowed == '2' or isBorrowed == 2)">
<![CDATA[
AND ri.return_time < DATE_ADD(#{endTime}, INTERVAL 1 DAY)
]]>
</when>
<otherwise>
<![CDATA[
AND ri.rk_time < DATE_ADD(#{endTime}, INTERVAL 1 DAY)
]]>
</otherwise>
</choose>
</if>
<if test="xmNo != null and xmNo != ''">
AND ri.xm_no LIKE concat('%', #{xmNo}, '%')
</if>
<if test="sapNo != null and sapNo != ''">
AND ri.sap_no LIKE concat('%', #{sapNo}, '%')
</if>
<if test="billNo != null and billNo != ''">
AND ri.bill_no LIKE concat('%', #{billNo}, '%')
</if>
@@ -463,15 +421,18 @@
ORDER BY ri.borrow_time DESC, ri.return_time DESC, ri.id DESC
</select>
<select id="selectGroupedByBill" resultMap="RkInfoResult" parameterType="map">
<select id="selectGroupedByBill"
resultMap="RkInfoResult"
parameterType="map">
SELECT
a.id,
a.bill_no,
a.bill_no_ck,
a.rk_type,
si.type_name AS rk_type_name,
si.type_name AS rk_type_name,
a.wl_type,
mt.type_name AS wl_type_name,
mt.type_name AS wl_type_name,
a.cangku,
a.rk_time,
a.lihuo_y,
@@ -487,37 +448,51 @@
a.gys_no,
a.sap_no,
a.ck_type,
so.type_name AS ck_type_name,
so.type_name AS ck_type_name,
a.ly_time,
a.ck_lihuo_y,
u.user_name AS ck_lihuo_y_name,
ru.user_name AS lihuo_y_name,
a.is_delivery AS is_delivery
u.user_name AS ck_lihuo_y_name,
ru.user_name AS lihuo_y_name,
a.is_delivery AS is_delivery
FROM (
SELECT
MIN(t.id) AS id,
t.bill_no AS bill_no,
MIN(t.bill_no_ck) AS bill_no_ck,
MIN(t.rk_type) AS rk_type,
MIN(t.wl_type) AS wl_type,
MIN(t.cangku) AS cangku,
MIN(t.rk_time) AS rk_time,
MIN(t.lihuo_y) AS lihuo_y,
MAX(t.is_chuku) AS is_chuku,
MIN(t.xj) AS xj,
MIN(t.xm_no) AS xm_no,
MIN(t.xm_ms) AS xm_ms,
MIN(t.xm_no_ck) AS xm_no_ck,
MIN(t.xm_ms_ck) AS xm_ms_ck,
MIN(t.gys_mc) AS gys_mc,
MIN(t.wl_no) AS wl_no,
MIN(t.wl_ms) AS wl_ms,
MIN(t.gys_no) AS gys_no,
MIN(t.sap_no) AS sap_no,
MIN(t.ck_type) AS ck_type,
MAX(t.ly_time) AS ly_time,
MIN(t.ck_lihuo_y) AS ck_lihuo_y,
MIN(t.is_delivery) AS is_delivery
MIN(t.id) AS id,
/* ✅ 单据号:出库/借料出库 -> CK其它 -> RK用于页面展示 */
t.show_bill_no AS bill_no,
/* 保留 bill_no_ck 字段(出库态有值) */
MIN(t.bill_no_ck) AS bill_no_ck,
MIN(t.rk_type) AS rk_type,
MIN(t.wl_type) AS wl_type,
MIN(t.cangku) AS cangku,
/* 时间:你要更合理也可以改成 MAX(COALESCE(ly_time,rk_time)) */
MIN(t.rk_time) AS rk_time,
MIN(t.lihuo_y) AS lihuo_y,
MAX(t.is_chuku) AS is_chuku,
MIN(t.xj) AS xj,
MIN(t.xm_no) AS xm_no,
MIN(t.xm_ms) AS xm_ms,
MIN(t.xm_no_ck) AS xm_no_ck,
MIN(t.xm_ms_ck) AS xm_ms_ck,
MIN(t.gys_mc) AS gys_mc,
MIN(t.wl_no) AS wl_no,
MIN(t.wl_ms) AS wl_ms,
MIN(t.gys_no) AS gys_no,
MIN(t.sap_no) AS sap_no,
MIN(t.ck_type) AS ck_type,
MAX(t.ly_time) AS ly_time,
MIN(t.ck_lihuo_y) AS ck_lihuo_y,
MIN(t.is_delivery) AS is_delivery,
/* ✅ 用于 needAudit 子查询判断:本组是 RK 组还是 CK 组 */
MIN(t.show_bill_type) AS show_bill_type
FROM (
SELECT
ri.id,
@@ -544,11 +519,29 @@
ri.ck_lihuo_y,
ri.pcode,
ri.is_delete,
ri.is_delivery
ri.is_delivery,
CASE
WHEN ri.is_chuku IN ('1','3')
AND ri.bill_no_ck IS NOT NULL
AND ri.bill_no_ck != ''
THEN ri.bill_no_ck
ELSE ri.bill_no
END AS show_bill_no,
CASE
WHEN ri.is_chuku IN ('1','3')
AND ri.bill_no_ck IS NOT NULL
AND ri.bill_no_ck != ''
THEN 'CK'
ELSE 'RK'
END AS show_bill_type
FROM rk_info ri
) t
<where>
<!-- is_delete -->
<!-- 只查未删除 -->
<choose>
<when test="q.isDelete != null and q.isDelete != ''">
AND t.is_delete = #{q.isDelete}
@@ -571,60 +564,102 @@
</when>
</choose>
<!-- keyword -->
<if test="q.keyword != null and q.keyword != ''">
AND (
t.xm_no LIKE concat('%', #{q.keyword}, '%')
OR t.xm_ms LIKE concat('%', #{q.keyword}, '%')
OR t.wl_no LIKE concat('%', #{q.keyword}, '%')
OR t.wl_ms LIKE concat('%', #{q.keyword}, '%')
OR t.gys_no LIKE concat('%', #{q.keyword}, '%')
OR t.gys_mc LIKE concat('%', #{q.keyword}, '%')
OR t.sap_no LIKE concat('%', #{q.keyword}, '%')
OR t.bill_no LIKE concat('%', #{q.keyword}, '%')
OR t.bill_no_ck LIKE concat('%', #{q.keyword}, '%')
OR t.ck_type LIKE concat('%', #{q.keyword}, '%')
OR t.pcode LIKE concat('%', #{q.keyword}, '%')
)
<!-- 时间过滤rk_time -->
<if test="q.startTime != null and q.startTime != ''">
<![CDATA[ AND t.rk_time >= #{q.startTime} ]]>
</if>
<if test="q.endTime != null and q.endTime != ''">
<![CDATA[ AND t.rk_time <= #{q.endTime} ]]>
</if>
<!-- 维度 -->
<if test="q.rkType != null and q.rkType != ''"> AND t.rk_type LIKE concat('%', #{q.rkType}, '%') </if>
<if test="q.wlType != null and q.wlType != ''"> AND t.wl_type LIKE concat('%', #{q.wlType}, '%') </if>
<if test="q.cangku != null and q.cangku != ''"> AND t.cangku LIKE concat('%', #{q.cangku}, '%') </if>
<!-- 时间过滤ly_time -->
<if test="q.lyStartTime != null and q.lyStartTime != ''">
<![CDATA[ AND t.ly_time >= #{q.lyStartTime} ]]>
</if>
<if test="q.lyEndTime != null and q.lyEndTime != ''">
<![CDATA[ AND t.ly_time <= #{q.lyEndTime} ]]>
</if>
<!-- 时间 -->
<if test="q.startTime != null"><![CDATA[ AND t.rk_time >= #{q.startTime} ]]></if>
<if test="q.endTime != null"><![CDATA[ AND t.rk_time <= #{q.endTime} ]]></if>
<if test="q.lyStartTime!= null"><![CDATA[ AND t.ly_time >= #{q.lyStartTime}]]></if>
<if test="q.lyEndTime != null"><![CDATA[ AND t.ly_time <= #{q.lyEndTime} ]]></if>
<!-- 维度条件 -->
<if test="q.rkType != null and q.rkType != ''">
AND t.rk_type LIKE concat('%', #{q.rkType}, '%')
</if>
<if test="q.wlType != null and q.wlType != ''">
AND t.wl_type LIKE concat('%', #{q.wlType}, '%')
</if>
<if test="q.cangku != null and q.cangku != ''">
AND t.cangku LIKE concat('%', #{q.cangku}, '%')
</if>
<!-- 模糊字段 -->
<if test="q.lihuoY != null and q.lihuoY != ''"> AND t.lihuo_y LIKE concat('%', #{q.lihuoY}, '%') </if>
<if test="q.xj != null and q.xj != ''"> AND t.xj LIKE concat('%', #{q.xj}, '%') </if>
<if test="q.billNo != null and q.billNo != ''"> AND t.bill_no LIKE concat('%', #{q.billNo}, '%') </if>
<if test="q.billNoCk != null and q.billNoCk != ''"> AND t.bill_no_ck LIKE concat('%', #{q.billNoCk}, '%') </if>
<if test="q.xmNo != null and q.xmNo != ''"> AND t.xm_no LIKE concat('%', #{q.xmNo}, '%') </if>
<if test="q.xmMs != null and q.xmMs != ''"> AND t.xm_ms LIKE concat('%', #{q.xmMs}, '%') </if>
<if test="q.wlNo != null and q.wlNo != ''"> AND t.wl_no LIKE concat('%', #{q.wlNo}, '%') </if>
<if test="q.wlMs != null and q.wlMs != ''"> AND t.wl_ms LIKE concat('%', #{q.wlMs}, '%') </if>
<if test="q.gysNo != null and q.gysNo != ''"> AND t.gys_no LIKE concat('%', #{q.gysNo}, '%') </if>
<if test="q.gysMc != null and q.gysMc != ''"> AND t.gys_mc LIKE concat('%', #{q.gysMc}, '%') </if>
<if test="q.sapNo != null and q.sapNo != ''"> AND t.sap_no LIKE concat('%', #{q.sapNo}, '%') </if>
<if test="q.pcode != null and q.pcode != ''"> AND t.pcode LIKE concat('%', #{q.pcode}, '%') </if>
<if test="q.ckType != null and q.ckType != ''"> AND t.ck_type LIKE concat('%', #{q.ckType}, '%') </if>
<if test="q.lihuoY != null and q.lihuoY != ''">
AND t.lihuo_y LIKE concat('%', #{q.lihuoY}, '%')
</if>
<if test="q.xj != null and q.xj != ''">
AND t.xj LIKE concat('%', #{q.xj}, '%')
</if>
<!-- 单据号(如果你页面输入框叫 billNo就建议这里也去匹配 show_bill_no -->
<if test="q.billNo != null and q.billNo != ''">
AND t.show_bill_no LIKE concat('%', #{q.billNo}, '%')
</if>
<!-- 如果你还保留 billNoCk 入参,也允许精确筛 CK -->
<if test="q.billNoCk != null and q.billNoCk != ''">
AND t.bill_no_ck LIKE concat('%', #{q.billNoCk}, '%')
</if>
<!-- 其它模糊 -->
<if test="q.xmNo != null and q.xmNo != ''">
AND t.xm_no LIKE concat('%', #{q.xmNo}, '%')
</if>
<if test="q.xmMs != null and q.xmMs != ''">
AND t.xm_ms LIKE concat('%', #{q.xmMs}, '%')
</if>
<if test="q.wlNo != null and q.wlNo != ''">
AND t.wl_no LIKE concat('%', #{q.wlNo}, '%')
</if>
<if test="q.wlMs != null and q.wlMs != ''">
AND t.wl_ms LIKE concat('%', #{q.wlMs}, '%')
</if>
<if test="q.gysNo != null and q.gysNo != ''">
AND t.gys_no LIKE concat('%', #{q.gysNo}, '%')
</if>
<if test="q.gysMc != null and q.gysMc != ''">
AND t.gys_mc LIKE concat('%', #{q.gysMc}, '%')
</if>
<if test="q.sapNo != null and q.sapNo != ''">
AND t.sap_no LIKE concat('%', #{q.sapNo}, '%')
</if>
<if test="q.pcode != null and q.pcode != ''">
AND t.pcode LIKE concat('%', #{q.pcode}, '%')
</if>
<if test="q.ckType != null and q.ckType != ''">
AND t.ck_type LIKE concat('%', #{q.ckType}, '%')
</if>
<if test="q.isDelivery != null and q.isDelivery != ''">
AND t.is_delivery = #{q.isDelivery}
</if>
<!-- 出库才要 bill_no_ck 非空 -->
<if test="(q.isChuku != null and q.isChuku == '1')
or (q.isChukuList != null and q.isChukuList.size > 0 and q.isChukuList.contains('1'))">
AND t.bill_no_ck IS NOT NULL
<!-- keyword建议也命中 show_bill_no解决用户输入 CK/RK 都能搜到) -->
<if test="q.keyword != null and q.keyword != ''">
AND (
t.xm_no LIKE concat('%', #{q.keyword}, '%')
OR t.xm_ms LIKE concat('%', #{q.keyword}, '%')
OR t.wl_no LIKE concat('%', #{q.keyword}, '%')
OR t.wl_ms LIKE concat('%', #{q.keyword}, '%')
OR t.gys_no LIKE concat('%', #{q.keyword}, '%')
OR t.gys_mc LIKE concat('%', #{q.keyword}, '%')
OR t.sap_no LIKE concat('%', #{q.keyword}, '%')
OR t.bill_no LIKE concat('%', #{q.keyword}, '%')
OR t.bill_no_ck LIKE concat('%', #{q.keyword}, '%')
OR t.show_bill_no LIKE concat('%', #{q.keyword}, '%')
OR t.ck_type LIKE concat('%', #{q.keyword}, '%')
OR t.pcode LIKE concat('%', #{q.keyword}, '%')
)
</if>
<!-- 审核 -->
<!-- ✅ 审核过滤:按组类型匹配 RK 或 CK -->
<if test="needAudit != null and needAudit == 1">
AND NOT EXISTS (
SELECT 1
@@ -633,12 +668,19 @@
ON asg.rk_id = r2.id
AND asg.approver_id IS NOT NULL
AND (asg.audit_result IS NOT NULL AND asg.audit_result != '1')
WHERE r2.bill_no = t.bill_no
AND r2.is_delete = 0
WHERE r2.is_delete = 0
AND (
(t.show_bill_type = 'RK' AND r2.bill_no = t.show_bill_no)
OR (t.show_bill_type = 'CK' AND r2.bill_no_ck = t.show_bill_no)
)
)
</if>
</where>
GROUP BY t.bill_no
/* ✅ 关键:按 show_bill_no 分组(出库合并 CK在库保留 RK */
GROUP BY t.show_bill_no
) a
LEFT JOIN stock_in_type si ON a.rk_type = si.type_code
LEFT JOIN stock_out_type so ON a.ck_type = so.type_code
@@ -646,8 +688,10 @@
LEFT JOIN material_type mt ON a.wl_type = mt.type_code
LEFT JOIN sys_user ru ON a.lihuo_y = ru.user_id
ORDER BY a.rk_time DESC
</select>
<!-- ================== /按单据分组查询 ================== -->
<select id="selectRkInfoById" parameterType="Long" resultMap="RkInfoResult">
@@ -863,9 +907,12 @@
<trim prefix="SET" suffixOverrides=",">
<if test="rkType != null">rk_type = #{rkType},</if>
<if test="wlType != null">wl_type = #{wlType},</if>
<if test="warehouseCode != null and warehouseCode != ''">
cangku = #{warehouseCode},
<!-- ✅ 仓库字段统一使用 cangku -->
<if test="cangku != null and cangku != ''">
cangku = #{cangku},
</if>
<if test="rkTime != null">rk_time = #{rkTime},</if>
<if test="lihuoY != null">lihuo_y = #{lihuoY},</if>
<if test="isChuku != null">is_chuku = #{isChuku},</if>
@@ -1055,74 +1102,81 @@
<if test="parentWarehouseCode != null and parentWarehouseCode != ''">
AND wh.parent_warehouse_code = #{parentWarehouseCode}
</if>
<if test="startTime != null and startTime != ''">
<!-- Date 类型:只能判 null别再判 '' -->
<if test="startTime != null">
AND ri.rk_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
<if test="endTime != null">
AND ri.rk_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="statDate != null and statDate != ''">
<if test="statDate != null">
AND ri.return_time <![CDATA[ >= ]]> #{statDate}
</if>
<if test="endDate != null and endDate != ''">
<if test="endDate != null">
AND ri.return_time <![CDATA[ <= ]]> #{endDate}
</if>
<if test="rkType != null and rkType != ''">
AND ri.rk_type = #{rkType}
</if>
<if test="wlType != null and wlType != ''">
AND ri.wl_type = #{wlType}
</if>
<if test="lyStartTime != null and lyStartTime != ''">
<!-- Date 类型:只能判 null -->
<if test="lyStartTime != null">
AND ri.ly_time <![CDATA[ >= ]]> #{lyStartTime}
</if>
<if test="lyEndTime != null and lyEndTime != ''">
<if test="lyEndTime != null">
AND ri.ly_time <![CDATA[ <= ]]> #{lyEndTime}
</if>
<if test="xmNo != null and xmNo != ''">
AND ri.xm_no LIKE CONCAT('%', #{xmNo}, '%')
AND ri.xm_no LIKE CONCAT('%', #{xmNo}, '%')
</if>
<if test="xmMs != null and xmMs != ''">
AND ri.xm_ms LIKE CONCAT('%', #{xmMs}, '%')
AND ri.xm_ms LIKE CONCAT('%', #{xmMs}, '%')
</if>
<if test="wlNo != null and wlNo != ''">
AND ri.wl_no LIKE CONCAT('%', #{wlNo}, '%')
AND ri.wl_no LIKE CONCAT('%', #{wlNo}, '%')
</if>
<if test="wlMs != null and wlMs != ''">
AND ri.wl_ms LIKE CONCAT('%', #{wlMs}, '%')
AND ri.wl_ms LIKE CONCAT('%', #{wlMs}, '%')
</if>
<if test="gysNo != null and gysNo != ''">
AND ri.gys_no LIKE CONCAT('%', #{gysNo}, '%')
AND ri.gys_no LIKE CONCAT('%', #{gysNo}, '%')
</if>
<if test="gysMc != null and gysMc != ''">
AND ri.gys_mc LIKE CONCAT('%', #{gysMc}, '%')
AND ri.gys_mc LIKE CONCAT('%', #{gysMc}, '%')
</if>
<if test="sapNo != null and sapNo != ''">
AND ri.sap_no LIKE CONCAT('%', #{sapNo}, '%')
AND ri.sap_no LIKE CONCAT('%', #{sapNo}, '%')
</if>
<if test="billNo != null and billNo != ''">
AND ri.bill_no LIKE CONCAT('%', #{billNo}, '%')
AND ri.bill_no LIKE CONCAT('%', #{billNo}, '%')
</if>
<if test="billNoCk != null and billNoCk != ''">
AND ri.bill_no_ck LIKE CONCAT('%', #{billNoCk}, '%')
</if>
<if test="ckType != null and ckType != ''">
AND ri.ck_type LIKE CONCAT('%', #{ckType}, '%')
AND ri.ck_type LIKE CONCAT('%', #{ckType}, '%')
</if>
<if test="pcode != null and pcode != ''">
AND ri.pcode LIKE CONCAT('%', #{pcode}, '%')
AND ri.pcode LIKE CONCAT('%', #{pcode}, '%')
</if>
<if test="fycde1 != null and fycde1 != ''">
AND ri.fycde_1 LIKE CONCAT('%', #{fycde1}, '%')
AND ri.fycde_1 LIKE CONCAT('%', #{fycde1}, '%')
</if>
<if test="fycde2 != null and fycde2 != ''">
AND ri.fycde_2 LIKE CONCAT('%', #{fycde2}, '%')
AND ri.fycde_2 LIKE CONCAT('%', #{fycde2}, '%')
</if>
</where>
ORDER BY ri.create_time DESC, ri.id DESC
</select>
<select id="selectStatistics" resultType="java.lang.Long" parameterType="java.lang.Object" >
SELECT sum(ri.ht_dj * ri.real_qty)
FROM rk_info ri
@@ -1266,80 +1320,24 @@
</select>
<select id="selectDeliveryCkList"
resultType="com.zg.project.wisdom.domain.RkInfo">
parameterType="com.zg.project.wisdom.domain.RkInfo"
resultMap="RkInfoResult">
SELECT
id,
gys_jh_id AS gysJhId,
rk_type AS rkType,
wl_type AS wlType,
cangku,
rk_time AS rkTime,
borrow_time AS borrowTime,
return_time AS returnTime,
lihuo_y AS lihuoY,
is_chuku AS isChuku,
bill_no AS billNo,
bill_no_ck AS billNoCk,
is_delivery AS isDelivery,
remark,
xj,
xm_no AS xmNo,
xm_ms AS xmMs,
xm_no_ck AS xmNoCk,
xm_ms_ck AS xmMsCk,
wl_no AS wlNo,
wl_ms AS wlMs,
gys_no AS gysNo,
gys_mc AS gysMc,
jh_amt AS jhAmt,
ht_dj AS htDj,
sap_no AS sapNo,
xh,
jh_qty AS jhQty,
ht_qty AS htQty,
dw,
real_qty AS realQty,
pcode,
pcode_id AS pcodeId,
tray_code AS trayCode,
entity_id AS entityId,
ck_lihuo_y AS ckLihuoY,
ck_type AS ckType,
team_code AS teamCode,
ck_remark AS ckRemark,
ly_time AS lyTime,
has_moved AS hasMoved,
is_borrowed AS isBorrowed,
fycde_1 AS fycde1,
fycde_2 AS fycde2,
is_delete AS isDelete,
create_by AS createBy,
create_time AS createTime,
update_by AS updateBy,
update_time AS updateTime
FROM rk_info
WHERE is_delete = '0'
AND is_chuku = '1'
AND is_delivery = '1'
<include refid="selectRkInfoVo"/>
<if test="q.xj != null and q.xj != ''">
AND xj = #{q.xj}
</if>
<if test="q.xmNoCk != null and q.xmNoCk != ''">
AND xm_no_ck = #{q.xmNoCk}
</if>
<if test="q.teamCode != null and q.teamCode != ''">
AND team_code = #{q.teamCode}
</if>
<if test="q.lyStartTime != null">
AND ly_time &gt;= #{q.lyStartTime}
</if>
<if test="q.lyEndTime != null">
AND ly_time &lt;= #{q.lyEndTime}
</if>
<where>
AND ri.is_delete = 0
AND ri.is_delivery = '1'
ORDER BY bill_no_ck, ly_time, id
<if test="isChuku != null and isChuku != ''">
AND ri.is_chuku = #{isChuku}
</if>
<if test="billNoCk != null and billNoCk != ''">
AND ri.bill_no_ck LIKE concat('%', #{billNoCk}, '%')
</if>
</where>
ORDER BY ri.rk_time DESC
</select>
<!-- 根据入库单号查询单据头公共信息 -->
@@ -1378,6 +1376,13 @@
LIMIT 1
</select>
<select id="selectMaxBillNo" resultType="java.lang.String">
SELECT MAX(bill_no)
FROM rk_info
WHERE is_delete = 0
AND bill_no LIKE CONCAT(#{prefix}, '%')
</select>
<update id="updateBillInfo" parameterType="com.zg.project.wisdom.domain.RkInfo">
UPDATE rk_info
<set>