This commit is contained in:
猫猫guowen
2025-06-11 15:50:10 +08:00
parent 45f450de47
commit bc84930d80
10 changed files with 186 additions and 143 deletions

View File

@@ -0,0 +1,36 @@
package com.ruoyi.api.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.service.IJobStatisticsService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 作业统计 Controller
*/
@RestController
@RequestMapping("/api")
public class JobStatisticsController {
@Autowired
private IJobStatisticsService jobStatisticsService;
/**
* 获取统计数据,包含:
* 1. 当日入库和出库数量统计
* 2. 货位状态统计
* 3. 当前任务列表
*/
@GetMapping("/daily")
public AjaxResult getDailyStatistics() {
Map<String, Object> result = jobStatisticsService.getDailyStatistics();
return AjaxResult.success(result);
}
}

View File

@@ -1,6 +1,8 @@
package com.ruoyi.api.statistics.mapper;
package com.ruoyi.api.mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 作业统计 Mapper 接口
@@ -22,4 +24,14 @@ public interface JobStatisticsMapper {
* @return 出库数量
*/
public int selectDailyOutCount(@Param("createTime") String createTime);
/**
* 查询当月每日入库出库统计
*
* @param year 年份
* @param month 月份
* @return 每日入库出库统计列表
*/
public List<Map<String, Object>> selectMonthlyStatistics(@Param("year") int year, @Param("month") int month);
}

View File

@@ -0,0 +1,20 @@
package com.ruoyi.api.service;
import com.ruoyi.common.core.domain.AjaxResult;
import java.util.Map;
/**
* 作业统计 Service 接口
*/
public interface IJobStatisticsService {
/**
* 获取统计数据,包含:
* 1. 当日入库和出库数量统计
* 2. 货位状态统计
* 3. 当前任务列表
*
* @return 统计结果
*/
public Map<String, Object> getDailyStatistics();
}

View File

@@ -0,0 +1,91 @@
package com.ruoyi.api.service.impl;
import java.util.ArrayList;
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.service.IJobStatisticsService;
import com.ruoyi.api.mapper.JobStatisticsMapper;
import com.ruoyi.bas.cargoSpace.mapper.BasCargoSpaceMapper;
import com.ruoyi.job.mydojob.mapper.MydoJobMapper;
import com.ruoyi.job.mydojob.domain.MydoJob;
/**
* 作业统计 Service 实现
*/
@Service
public class JobStatisticsServiceImpl implements IJobStatisticsService {
@Autowired
private JobStatisticsMapper jobStatisticsMapper;
@Autowired
private BasCargoSpaceMapper basCargoSpaceMapper;
@Autowired
private MydoJobMapper mydoJobMapper;
/**
* 获取当日入库和出库数量统计
*/
@Override
public Map<String, Object> getDailyStatistics() {
// 获取当前日期
String today = DateUtils.getDate();
// 查询当日入库数量
int inCount = jobStatisticsMapper.selectDailyInCount(today);
// 查询当日出库数量
int outCount = jobStatisticsMapper.selectDailyOutCount(today);
// 获取货位状态统计
List<Map<String, Object>> statusCounts = basCargoSpaceMapper.selectStatusCount();
List<Map<String, Object>> cargoSpaceStatus = new ArrayList<>();
Map<String, String> statusNameMap = new HashMap<>();
statusNameMap.put("1", "空货位");
statusNameMap.put("2", "满货位");
statusNameMap.put("3", "入库已分配");
statusNameMap.put("4", "出库已分配");
statusNameMap.put("5", "入库需盘点");
statusNameMap.put("6", "出库需盘点");
for (Map.Entry<String, String> entry : statusNameMap.entrySet()) {
Map<String, Object> item = new HashMap<>();
String status = entry.getKey();
item.put("name", entry.getValue());
item.put("value", 0);
for (Map<String, Object> count : statusCounts) {
if (status.equals(String.valueOf(count.get("status")))) {
item.put("value", count.get("count"));
break;
}
}
cargoSpaceStatus.add(item);
}
// 获取当前任务列表
List<MydoJob> currentTasks = mydoJobMapper.selectCurrentTasks();
// 获取当前年月
int year = Integer.parseInt(DateUtils.dateTimeNow("yyyy"));
int month = Integer.parseInt(DateUtils.dateTimeNow("MM"));
// 获取当月每日统计数据
List<Map<String, Object>> dailyStats = jobStatisticsMapper.selectMonthlyStatistics(year, month);
// 返回统计结果
Map<String, Object> result = new HashMap<>();
result.put("drrk", String.valueOf(inCount));
result.put("drck", String.valueOf(outCount));
result.put("cargoSpaceStatus", cargoSpaceStatus);
result.put("currentTask", currentTasks);
result.put("statistic", dailyStats);
return result;
}
}

View File

@@ -1,53 +0,0 @@
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

@@ -1,24 +0,0 @@
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

@@ -1,63 +0,0 @@
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

@@ -9,8 +9,14 @@ import com.ruoyi.job.mydojob.domain.MydoJob;
* @author ruoyi
* @date 2025-05-23
*/
public interface MydoJobMapper
public interface MydoJobMapper
{
/**
* 查询当前任务列表
*
* @return 当前任务列表
*/
public List<MydoJob> selectCurrentTasks();
/**
* 查询任务表
*

View File

@@ -2,7 +2,7 @@
<!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">
<mapper namespace="com.ruoyi.api.mapper.JobStatisticsMapper">
<!-- 查询当日入库数量 -->
<select id="selectDailyInCount" parameterType="String" resultType="Integer">
@@ -20,4 +20,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND in_or_out >= 20
</select>
<!-- 查询当月每日入库出库统计 -->
<select id="selectMonthlyStatistics" resultType="java.util.Map">
SELECT
CONVERT(varchar(10), create_time, 120) as date,
SUM(CASE WHEN in_or_out &lt; 20 THEN 1 ELSE 0 END) as '入库',
SUM(CASE WHEN in_or_out >= 20 THEN 1 ELSE 0 END) as '出库'
FROM mydo_job_finish
WHERE YEAR(create_time) = #{year}
AND MONTH(create_time) = #{month}
GROUP BY CONVERT(varchar(10), create_time, 120)
ORDER BY date
</select>
</mapper>

View File

@@ -196,4 +196,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{jobId}
</foreach>
</delete>
<select id="selectCurrentTasks" resultMap="MydoJobResult">
<include refid="selectMydoJobVo"/>
where mj.status = '3'
</select>
</mapper>