Commit 7c470ce3 by yubin

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	ruoyi-inventory/src/main/resources/mapper/inventory/StorageLocationsMapper.xml
parents 37ede93e f7e6543a
......@@ -62,3 +62,11 @@ export function delStocktakes(id) {
method: 'delete'
})
}
// 首页-本月盘点次数
export function countStocktakes() {
return request({
url: '/inventory/stocktakes/countStocktakes',
method: 'get'
})
}
......@@ -42,3 +42,19 @@ export function delItems(id) {
method: 'delete'
})
}
// 盘盈金额 盘亏金额
export function stocktakeVarianceAmount() {
return request({
url: '/inventory/items/stocktakeVarianceAmount',
method: 'get'
})
}
// 3. 本月差异分析
export function varianceAnalysis() {
return request({
url: '/inventory/items/varianceAnalysis',
method: 'get'
})
}
......@@ -101,4 +101,27 @@ public class StocktakeItemsController extends BaseController
{
return toAjax(stocktakeItemsService.deleteStocktakeItemsByIds(ids));
}
/**
* @description: 本月 盘盈金额 和 盘亏金额
* @author cs
* @date 2025/12/10
* @version 1.0
*/
@GetMapping(value = "/stocktakeVarianceAmount")
public AjaxResult stocktakeVarianceAmount()
{
return success(stocktakeItemsService.stocktakeVarianceAmount());
}
/**
* @description: 本月 本月差异分析
* @author cs
* @date 2025/12/10
* @version 1.0
*/
@GetMapping(value = "/varianceAnalysis")
public AjaxResult varianceAnalysis()
{
return success(stocktakeItemsService.selectItemsVarianceAnalysis());
}
}
......@@ -125,4 +125,16 @@ public class StocktakesController extends BaseController
List<StocktakesVo> list = stocktakesService.selectStocktakesCountInfo(stocktakes);
return getDataTable(list);
}
/**
* @description: 首页-本月盘点次数
* @author cs
* @date 2025/12/10
* @version 1.0
*/
@GetMapping(value = "/countStocktakes")
public AjaxResult countStocktakes()
{
return success(stocktakesService.selectStocktakesCountByMonth());
}
}
......@@ -127,6 +127,16 @@ public class StocktakeItems extends BaseEntity
/** 单价 */
@Excel(name = "单价")
private double unitPrice;
@Excel(name = "调整原因类型0-未调整、1-数量差异、2-记录错误、3-损坏丢失、4-其他,默认为0")
private String adjustedType;
public String getAdjustedType() {
return adjustedType;
}
public void setAdjustedType(String adjustedType) {
this.adjustedType = adjustedType;
}
public double getUnitPrice() {
return unitPrice;
......
......@@ -7,9 +7,12 @@ import java.util.Date;
public class InboundDetailsVO {
private static final long serialVersionUID = 1L;
@Excel(name = "物料sapNo")
private String materialId;
@Excel(name = "物料SAP")
private String sapNo;
@Excel(name = "物料名")
private String materialName;
......@@ -171,10 +174,19 @@ public class InboundDetailsVO {
this.locationName = locationName;
}
public String getSapNo() {
return sapNo;
}
public void setSapNo(String sapNo) {
this.sapNo = sapNo;
}
@Override
public String toString() {
return "InboundDetailsVO{" +
"materialId='" + materialId + '\'' +
", sapNo='" + sapNo + '\'' +
", materialName='" + materialName + '\'' +
", orderId='" + orderId + '\'' +
", batchId='" + batchId + '\'' +
......
......@@ -68,4 +68,10 @@ public interface StocktakeItemsMapper
// 查询处理统计-详情
public List<StocktakesVo> selectStocktakesCountInfo(StocktakesVo stocktakes);
// 本月 盘盈金额 和 盘亏金额
@SuppressWarnings("MybatisX")
public Map<String, Object> selectstocktakeVarianceAmount(StocktakeItems stocktakeItems);
// 本月 本月差异分析
public Map<String, Object> selectItemsVarianceAnalysis(StocktakeItems stocktakeItems);
}
......@@ -94,4 +94,11 @@ public interface StocktakesMapper
* @version 1.0
*/
public List<StocktakesVo> selectStocktakesListCount(StocktakesVo stocktakes);
/**
* @description: 首页-本月盘点次数
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public int selectStocktakesCountByMonth(Stocktakes stocktakes);
}
......@@ -3,9 +3,11 @@ package com.ruoyi.inventory.service;
import java.util.List;
import java.util.Map;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.inventory.domain.StocktakeItems;
import com.ruoyi.inventory.domain.TO.StocktakeItemsTo;
import com.ruoyi.inventory.domain.TO.StocktakesVo;
import org.springframework.web.bind.annotation.GetMapping;
/**
* 盘点单明细Service接口
......@@ -68,4 +70,22 @@ public interface IStocktakeItemsService
// 查询处理统计-详情
public List<StocktakesVo> selectStocktakesCountInfo(StocktakesVo stocktakes);
/**
* @description: 本月 盘盈金额 和 盘亏金额
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public Map<String, Object> stocktakeVarianceAmount();
/**
* @description: 本月 本月差异分析
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public Map<String, Object> selectItemsVarianceAnalysis();
public Map<String,Object> getMonthDay();
}
......@@ -80,4 +80,12 @@ public interface IStocktakesService
* @version 1.0
*/
public List<StocktakesVo> selectStocktakesCountInfo(StocktakesVo stocktakes);
/**
* @description: 首页-本月盘点次数
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public int selectStocktakesCountByMonth();
}
......@@ -243,7 +243,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
"orderId", "systemNo", "orderTypeId", "batchId"); // 排除主表字段
// 填充明细必填字段
itemDO.setId(UUID.randomUUID().toString());
itemDO.setMaterialId(vo.getSapNo());
itemDO.setMaterialId(vo.getId());
itemDO.setOrderId(orderId); // 关联入库单号
itemDO.setBatchId(mainDO.getBatchId());
itemDO.setInboundOrderId(mainDO.getId()); // 关联主表ID(核心!)
......
package com.ruoyi.inventory.service.impl;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -126,4 +129,46 @@ public class StocktakeItemsServiceImpl implements IStocktakeItemsService
}
return stocktakeItemsMapper.selectStocktakesCountInfo(stocktakes);
}
/**
* @description: 本月 盘盈金额 和 盘亏金额
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public Map<String, Object> stocktakeVarianceAmount(){
StocktakeItems stocktakeItems = new StocktakeItems();
Map<String, Object> params = getMonthDay();
stocktakeItems.setParams(params);
return stocktakeItemsMapper.selectstocktakeVarianceAmount(stocktakeItems);
}
/**
* @description: 本月 本月差异分析
* 统计 adjusted_type 字段为 1-数量差异、2-记录错误、3-损坏丢失、4-其他 的
* 1-数量差异 占比
* 2-记录错误 占比
* 3-损坏丢失 占比
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public Map<String, Object> selectItemsVarianceAnalysis(){
StocktakeItems stocktakeItems = new StocktakeItems();
Map<String, Object> params = getMonthDay();
stocktakeItems.setParams(params);
return stocktakeItemsMapper.selectItemsVarianceAnalysis(stocktakeItems);
}
public Map<String,Object> getMonthDay(){
Map<String, Object> params = new HashMap<>();
// 获取当前日期
LocalDate today = LocalDate.now();
// 本月第一天
LocalDate firstDay = today.with(TemporalAdjusters.firstDayOfMonth());
// 本月最后一天
LocalDate lastDay = today.with(TemporalAdjusters.lastDayOfMonth());
params.put("beginTime",firstDay);
params.put("endTime",lastDay);
return params;
}
}
package com.ruoyi.inventory.service.impl;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import com.ruoyi.common.core.domain.model.LoginUser;
......@@ -302,4 +304,17 @@ public class StocktakesServiceImpl implements IStocktakesService
List<StocktakesVo> list = stocktakeItemsService.selectStocktakesCountInfo(stocktakes);
return list;
}
/**
* @description: 首页-本月盘点次数
* @author cs
* @date 2025/12/10
* @version 1.0
*/
public int selectStocktakesCountByMonth(){
Stocktakes stocktakes = new Stocktakes();
Map<String, Object> params = stocktakeItemsService.getMonthDay();
stocktakes.setParams(params);
return stocktakesMapper.selectStocktakesCountByMonth(stocktakes);
}
}
......@@ -105,7 +105,7 @@
ii.inbound_order_id,
m.material_name
FROM inbound_order_items ii
LEFT JOIN materials m ON ii.material_id = m.sap_no
LEFT JOIN materials m ON ii.material_id = m.id
left join warehouses w on ii.warehouse_id = w.id
left join storage_locations sl on ii.location_id = sl.id
<where>
......@@ -311,6 +311,7 @@
<resultMap id="InboundDetailsResultMap" type="com.ruoyi.inventory.domain.vo.InboundDetailsVO">
<!-- 基础字段映射 -->
<result column="material_id" property="materialId" jdbcType="VARCHAR" />
<result column="sap_no" property="sapNo" jdbcType="VARCHAR" />
<result column="material_name" property="materialName" jdbcType="VARCHAR" />
<result column="order_id" property="orderId" jdbcType="VARCHAR" />
<result column="batch_id" property="batchId" jdbcType="VARCHAR" />
......@@ -339,6 +340,7 @@
<select id="selectInboundDetailsVOBySapNo" resultMap="InboundDetailsResultMap" parameterType="com.ruoyi.inventory.domain.vo.InboundDetailsVO">
SELECT
ioi.material_id,
ms.sap_no,
ms.material_name,
ioi.order_id,
ioi.batch_id,
......@@ -355,13 +357,13 @@
io.inbound_date
FROM inbound_orders io
INNER JOIN inbound_order_items ioi ON io.id = ioi.inbound_order_id
INNER JOIN materials ms ON ms.sap_no = ioi.material_id
INNER JOIN materials ms ON ms.id = ioi.material_id
inner join warehouses w on ioi.warehouse_id = w.id
inner join storage_locations sl on ioi.location_id = sl.id
<where>
io.order_status = 2
<if test="materialId != null and materialId != ''">
AND ioi.material_id = #{materialId}
<if test="sapNo != null and sapNo != ''">
AND ms.sap_no = #{sapNo}
</if>
<if test="materialName != null and materialName != ''">
AND ms.material_name LIKE CONCAT('%', #{materialName}, '%')
......
......@@ -112,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from inbound_order_items as ioi
left join warehouses as w on ioi.warehouse_id = w.id
left join storage_locations as sl on ioi.location_id = sl.id
left join materials as m on ioi.material_id = m.sap_no
left join materials as m on ioi.material_id = m.id
where ioi.inbound_order_id = #{id}
</select>
......@@ -244,8 +244,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result column="total_money" property="totalMoney" jdbcType="DECIMAL"/>
</resultMap>
<select id="countInboundMaterialQuantity" resultMap="InboundMaterialTotalResultMap" parameterType="String">
select ioi.material_name,sum(ioi.actual_quantity) as total_quantity
from inbound_order as io
select m.material_name,sum(ioi.actual_quantity) as total_quantity
from inbound_orders as io
inner join inbound_order_items as ioi on io.id = ioi.inbound_order_id
inner join materials as m on ioi.material_id = m.id
where io.order_status = 2
......@@ -254,8 +254,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
limit 10
</select>
<select id="countInboundMaterialMoney" resultMap="InboundMaterialTotalResultMap" parameterType="String">
select ioi.material_name,sum(ioi.actual_quantity * ioi.unit_price) as total_money
from inbound_order as io
select m.material_name,sum(ioi.actual_quantity * ioi.unit_price) as total_money
from inbound_orders as io
inner join inbound_order_items as ioi on io.id = ioi.inbound_order_id
inner join materials as m on ioi.material_id = m.id
where io.order_status = 2
......
......@@ -328,14 +328,15 @@ and inventory_status = '1'
</resultMap>
<select id="selectInventoryExceedWarnList" resultMap="InventoryExceedWarnResultMap">
select m.material_name,mc.category_name,m.sap_no,
COALESCE(i.quantity, 0) AS quantity,
sum(COALESCE(i.quantity, 0)) AS quantity,
COALESCE(m.min_stock_level, 0) AS min_stock_level,
COALESCE(m.max_stock_level, 9999) AS max_stock_level
from materials as m
inner join inventory as i on i.material_id = m.id
inner join materials_category as mc on m.category_code = mc.id
where COALESCE(i.quantity, 0) &gt; COALESCE(m.max_stock_level, 999999)
or COALESCE(i.quantity, 0) &lt; COALESCE(m.min_stock_level, 0)
inner join materials_category as mc on m.category_code = mc.category_code
where (COALESCE(i.quantity, 0) &gt; COALESCE(m.max_stock_level, 999999)) or (COALESCE(i.quantity, 0) &lt; COALESCE(m.min_stock_level, 0))
and m.is_used = 1
group by m.id
</select>
<select id="selectInventoryTopTenByAmount" resultType="java.util.Map">
......
......@@ -88,7 +88,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<!-- 获取物料 的 sap_no Name 做成字典-->
<select id="getMapList" resultType="java.util.Map">
select sap_no, IFNULL(material_name, '') as material_name from materials where is_used = 1;
select id, IFNULL(material_name, '') as material_name from materials where is_used = 1;
</select>
<insert id="insertMaterials" parameterType="Materials">
......
......@@ -37,15 +37,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateUserCode" column="update_user_code" />
<result property="inventoryId" column="inventory_id" />
<result property="unitPrice" column="unit_price" />
<result property="adjustedType" column="adjusted_type" />
</resultMap>
<sql id="selectStocktakeItemsVo">
select id, inventory_id,unit_price, stocktake_id, material_id, batch_code, warehouse_id, location_id, system_quantity, actual_quantity, variance_quantity, variance_amount, stocktake_status, counted_by, counted_at, adjusted, adjustment_reason, adjusted_by, adjusted_at, start_time, end_time, material_range, location_range, remark, is_used, sort_no, create_time, create_user_code, update_time, update_user_code from stocktake_items
select id, inventory_id,adjusted_type,unit_price, stocktake_id, material_id, batch_code, warehouse_id, location_id, system_quantity, actual_quantity, variance_quantity, variance_amount, stocktake_status, counted_by, counted_at, adjusted, adjustment_reason, adjusted_by, adjusted_at, start_time, end_time, material_range, location_range, remark, is_used, sort_no, create_time, create_user_code, update_time, update_user_code from stocktake_items
</sql>
<select id="selectStocktakeItemsList" parameterType="StocktakeItems" resultMap="StocktakeItemsResult">
<include refid="selectStocktakeItemsVo"/>
<where>
<if test="adjustedType != null and adjustedType != ''"> and adjusted_type = #{adjustedType}</if>
<if test="stocktakeId != null and stocktakeId != ''"> and stocktake_id = #{stocktakeId}</if>
<if test="materialId != null and materialId != ''"> and material_id = #{materialId}</if>
<if test="batchCode != null and batchCode != ''"> and batch_code = #{batchCode}</if>
......@@ -103,8 +105,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
, st_it.end_time
, st_it.material_range
, st_it.location_range
,(select w.warehouses_name from warehouses w where st_it.warehouse_id = w.warehouses_code and w.is_used = 1) as warehouse_name
,(select sl.location_name from storage_locations sl where st_it.location_id = sl.location_code and sl.is_used = 1) as location_name
,(select w.warehouses_name from warehouses w where st_it.warehouse_id = w.id and w.is_used = 1) as warehouse_name
,(select sl.location_name from storage_locations sl where st_it.location_id = sl.id and sl.is_used = 1) as location_name
,(select dict.dict_label from sys_dict_data dict where st_it.adjusted_type = dict.dict_sort and dict.status =0 and dict.dict_type ='adjusted_type') as adjusted_type
from stocktake_items st_it
where stocktake_id = #{stocktake_id} and is_used = 1
<if test="adjusted != null and adjusted != ''"> and adjusted = #{adjusted}</if>
......@@ -123,11 +126,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
,dict.dict_label as hazardName
,IFNULL(st_it.variance_quantity, '0') as varianceQuantity
,IFNULL(st_it.variance_amount, '0') as varianceAmount
,(select dict.dict_label from sys_dict_data dict where st_it.adjusted_type = dict.dict_sort and dict.status =0 and dict.dict_type ='adjusted_type') as adjustedType
from stocktakes st
left join stocktake_items st_it on st.id = st_it.stocktake_id and st_it.is_used = 1
left join materials ma on st_it.material_id = ma.sap_no and ma.is_used = 1
left join warehouses w on st_it.warehouse_id = w.warehouses_code and w.is_used = 1
left join storage_locations sl on st_it.location_id = sl.location_code and sl.is_used = 1
left join materials ma on st_it.material_id = ma.id and ma.is_used = 1
left join warehouses w on st_it.warehouse_id = w.id and w.is_used = 1
left join storage_locations sl on st_it.location_id = sl.id and sl.is_used = 1
left join sys_dict_data dict on ma.hazard_id = dict.dict_sort and dict.status =0 and dict.dict_type ='danger_type'
where
st.is_used = 1 and IFNULL(st_it.variance_quantity, 0) != 0
......@@ -152,11 +156,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
order by st.planned_date
</select>
<!-- 本月 盘盈金额 和 盘亏金额-->
<select id="selectstocktakeVarianceAmount" parameterType="StocktakeItems" resultType="java.util.Map">
select
SUM(CASE WHEN variance_amount &gt;= 0 THEN variance_amount ELSE 0 END) AS positiveTotal,
SUM(CASE WHEN variance_amount &lt; 0 THEN ABS(variance_amount) ELSE 0 END) AS negativeAbsTotal
from stocktake_items
where
is_used = 1 and IFNULL(variance_quantity, 0) != 0
AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
</select>
<!-- 本月 本月差异分析-->
<select id="selectItemsVarianceAnalysis" parameterType="StocktakeItems" resultType="java.util.Map">
select
COUNT(*) AS totalCount, -- 修改总记录数
ROUND(IFNULL(COUNT(CASE WHEN adjusted_type = 1 THEN 1 END) / NULLIF(COUNT(*), 0) * 100, 0), 2) AS type1Ratio,
ROUND(IFNULL(COUNT(CASE WHEN adjusted_type = 2 THEN 1 END) / NULLIF(COUNT(*), 0) * 100, 0), 2) AS type2Ratio,
ROUND(IFNULL(COUNT(CASE WHEN adjusted_type = 3 THEN 1 END) / NULLIF(COUNT(*), 0) * 100, 0), 2) AS type3Ratio
FROM stocktake_items
where
is_used = 1 and adjusted_type != '0'
AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
</select>
<insert id="insertStocktakeItems" parameterType="StocktakeItems">
insert into stocktake_items
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="adjustedType != null">adjusted_type,</if>
<if test="stocktakeId != null">stocktake_id,</if>
<if test="inventoryId != null">inventory_id,</if>
<if test="materialId != null">material_id,</if>
......@@ -189,6 +219,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="adjustedType != null">#{adjustedType},</if>
<if test="stocktakeId != null">#{stocktakeId},</if>
<if test="inventoryId != null">#{inventoryId},</if>
<if test="materialId != null">#{materialId},</if>
......@@ -224,6 +255,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateStocktakeItems" parameterType="StocktakeItems">
update stocktake_items
<trim prefix="SET" suffixOverrides=",">
<if test="adjustedType != null">adjusted_type = #{adjustedType},</if>
<if test="stocktakeId != null">stocktake_id = #{stocktakeId},</if>
<if test="inventoryId != null">inventory_id = #{inventoryId},</if>
<if test="materialId != null">material_id = #{materialId},</if>
......
......@@ -75,12 +75,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
,GROUP_CONCAT(DISTINCT dict.dict_label SEPARATOR ',') as hazardName
,IFNULL(sum(st_it.variance_quantity), '0') as countQuantity
,IFNULL(sum(st_it.variance_amount), '0') as countAmount
,GROUP_CONCAT(DISTINCT dict1.dict_label SEPARATOR ',') as adjustedType
from stocktakes st
left join stocktake_items st_it on st.id = st_it.stocktake_id and st_it.is_used = 1
left join materials ma on st_it.material_id = ma.sap_no and ma.is_used = 1
left join warehouses w on st_it.warehouse_id = w.warehouses_code and w.is_used = 1
left join storage_locations sl on st_it.location_id = sl.location_code and sl.is_used = 1
left join materials ma on st_it.material_id = ma.id and ma.is_used = 1
left join warehouses w on st_it.warehouse_id = w.id and w.is_used = 1
left join storage_locations sl on st_it.location_id = sl.id and sl.is_used = 1
left join sys_dict_data dict on ma.hazard_id = dict.dict_sort and dict.status =0 and dict.dict_type ='danger_type'
left join sys_dict_data dict1 on st_it.adjusted_type = dict1.dict_sort and dict1.status =0 and dict1.dict_type ='adjusted_type'
where
st.is_used = 1 and IFNULL(st_it.variance_quantity, 0) != 0
<if test="materialId != null "> and st_it.material_id = #{materialId}</if>
......@@ -94,6 +96,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="locationId != null "> and st_it.location_id = #{locationId}</if>
group by st_it.material_id
</select>
<!-- 首页-本月盘点次数-->
<select id="selectStocktakesCountByMonth" parameterType="Stocktakes" resultType="java.lang.Integer">
select count(*) from stocktakes
where is_used = 1
AND date_format(planned_date,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
AND date_format(planned_date,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
</select>
<insert id="insertStocktakes" parameterType="Stocktakes">
......
......@@ -52,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<!-- 获取仓库 的 warehouses_code 仓库编码 warehouses_name 做成字典-->
<select id="getMapList" resultType="java.util.Map">
select warehouses_code, IFNULL(warehouses_name, '') as warehouses_name from warehouses where is_used = 1;
select id, IFNULL(warehouses_name, '') as warehouses_name from warehouses where is_used = 1;
</select>
<insert id="insertWarehouses" parameterType="Warehouses">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论