Commit 8d10b3c4 by chuishuo

新增字段 ---完成

关联改为用id(物料、库位、仓库)——测试数据有问题,需要造数据后再测试
首页统计接口--完成
parent c38b7b1a
......@@ -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;
......
......@@ -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();
}
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);
}
}
......@@ -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">
......
......@@ -73,8 +73,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<!-- 获取库位表 的 location_code 编码 location_name 做成字典-->
<select id="getMapList" parameterType="StorageLocations" resultType="java.util.Map">
select location_code, IFNULL(location_name, '') as location_name from storage_locations where is_used = 1
<if test="warehousesCode != null and warehousesCode != ''"> and warehouses_code = #{warehousesCode}</if>
select id, IFNULL(location_name, '') as location_name from storage_locations where is_used = 1
<if test="warehousesCode != null and warehousesCode != ''"> and warehouses_id = #{warehousesCode}</if>
</select>
<insert id="insertStorageLocations" parameterType="StorageLocations">
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论