This commit is contained in:
猫猫guowen
2025-06-11 11:41:28 +08:00
parent 378eb0ba1c
commit 45f450de47
8 changed files with 204 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
package com.ruoyi.api.statistics.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.api.statistics.service.IJobStatisticsService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 作业统计 Controller
*/
@RestController
@RequestMapping("/api/statistics")
public class JobStatisticsController {
@Autowired
private IJobStatisticsService jobStatisticsService;
/**
* 获取当日入库和出库数量统计,以及货位状态统计
*/
@GetMapping("/daily")
public AjaxResult getDailyStatistics() {
Map<String, Object> result = jobStatisticsService.getDailyStatistics();
Map<String, Object> statusCount = jobStatisticsService.getCargoSpaceStatusCount();
// 将状态统计转换为饼图所需的格式
List<Map<String, Object>> pieData = new ArrayList<>();
Map<String, String> statusMap = new HashMap<>();
statusMap.put("1", "空货位");
statusMap.put("2", "满货位");
statusMap.put("3", "入库分配");
statusMap.put("4", "出库分配");
statusMap.put("5", "入库需盘点");
statusMap.put("6", "出库需盘点");
for (Map.Entry<String, String> entry : statusMap.entrySet()) {
Map<String, Object> item = new HashMap<>();
item.put("name", entry.getValue());
item.put("value", statusCount.getOrDefault(entry.getKey(), 0));
pieData.add(item);
}
result.put("pie", pieData);
return AjaxResult.success(result);
}
}

View File

@@ -0,0 +1,25 @@
package com.ruoyi.api.statistics.mapper;
import org.apache.ibatis.annotations.Param;
/**
* 作业统计 Mapper 接口
*/
public interface JobStatisticsMapper {
/**
* 查询当日入库数量(inOrOut < 20)
*
* @param createTime 创建日期
* @return 入库数量
*/
public int selectDailyInCount(@Param("createTime") String createTime);
/**
* 查询当日出库数量(inOrOut >= 20)
*
* @param createTime 创建日期
* @return 出库数量
*/
public int selectDailyOutCount(@Param("createTime") String createTime);
}

View File

@@ -0,0 +1,24 @@
package com.ruoyi.api.statistics.service;
import com.ruoyi.common.core.domain.AjaxResult;
import java.util.Map;
/**
* 作业统计 Service 接口
*/
public interface IJobStatisticsService {
/**
* 获取当日入库和出库数量统计
*
* @return 统计结果
*/
public Map<String, Object> getDailyStatistics();
/**
* 获取货位状态统计
*
* @return 状态统计结果,key为状态值,value为数量
*/
public Map<String, Object> getCargoSpaceStatusCount();
}

View File

@@ -0,0 +1,63 @@
package com.ruoyi.api.statistics.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.api.statistics.service.IJobStatisticsService;
import com.ruoyi.api.statistics.mapper.JobStatisticsMapper;
import com.ruoyi.bas.cargoSpace.mapper.BasCargoSpaceMapper;
/**
* 作业统计 Service 实现
*/
@Service
public class JobStatisticsServiceImpl implements IJobStatisticsService {
@Autowired
private JobStatisticsMapper jobStatisticsMapper;
@Autowired
private BasCargoSpaceMapper basCargoSpaceMapper;
/**
* 获取当日入库和出库数量统计
*/
@Override
public Map<String, Object> getDailyStatistics() {
// 获取当前日期
String today = DateUtils.getDate();
// 查询当日入库数量
int inCount = jobStatisticsMapper.selectDailyInCount(today);
// 查询当日出库数量
int outCount = jobStatisticsMapper.selectDailyOutCount(today);
// 返回统计结果
Map<String, Object> result = new HashMap<>();
result.put("drrk", String.valueOf(inCount));
result.put("drck", String.valueOf(outCount));
return result;
}
/**
* 获取货位状态统计
*/
@Override
public Map<String, Object> getCargoSpaceStatusCount() {
List<Map<String, Object>> statusCounts = basCargoSpaceMapper.selectStatusCount();
Map<String, Object> result = new HashMap<>();
// 将查询结果转换为所需格式
for (Map<String, Object> count : statusCounts) {
String status = String.valueOf(count.get("status"));
Object countValue = count.get("count");
result.put(status, countValue);
}
return result;
}
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.bas.cargoSpace.domain.BasCargoSpace;
import java.util.List;
import java.util.Map;
/**
* 库存信息Mapper接口
@@ -61,5 +62,10 @@ public interface BasCargoSpaceMapper extends BaseMapper<BasCargoSpace>
*/
public int deleteBasCargoSpaceByCargoSpaceIds(String[] cargoSpaceIds);
/**
* 查询不同状态的货位数量统计
*
* @return 状态统计结果列表
*/
public List<Map<String, Object>> selectStatusCount();
}

View File

@@ -0,0 +1,23 @@
<?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.ruoyi.api.statistics.mapper.JobStatisticsMapper">
<!-- 查询当日入库数量 -->
<select id="selectDailyInCount" parameterType="String" resultType="Integer">
SELECT COUNT(1)
FROM mydo_job_finish
WHERE CONVERT(varchar(10), create_time, 120) = #{createTime}
AND in_or_out &lt; 20
</select>
<!-- 查询当日出库数量 -->
<select id="selectDailyOutCount" parameterType="String" resultType="Integer">
SELECT COUNT(1)
FROM mydo_job_finish
WHERE CONVERT(varchar(10), create_time, 120) = #{createTime}
AND in_or_out >= 20
</select>
</mapper>

View File

@@ -141,4 +141,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<select id="selectStatusCount" resultType="java.util.Map">
SELECT
status,
COUNT(*) as count
FROM bas_cargo_space
GROUP BY status
</select>
</mapper>

View File

@@ -115,6 +115,7 @@ public class SecurityConfig
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html","/changeLanguage", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/pda/**").permitAll()
.antMatchers("/api/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();
})