feat(wms): 添加报表结果存储功能支持JSON和横向对比

- 创建WmsReportResultStorage实体类用于存储报表结果数据
- 实现IWmsReportResultStorageService服务接口及其实现类
- 添加WmsReportResultStorageController控制器提供CRUD操作
- 创建WmsReportResultStorageMapper数据访问层
- 配置WmsReportResultStorageMapper.xml映射文件
- 定义WmsReportResultStorageBo业务对象和WmsReportResultStorageVo视图对象
- 实现报表数据按日期、类型、产线进行查询和去重逻辑
- 添加Excel导出功能支持报表数据导出
This commit is contained in:
2026-03-25 16:23:39 +08:00
parent e8568b6ec7
commit 9dc8d589f0
8 changed files with 516 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
package com.klp.controller;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.klp.common.annotation.RepeatSubmit;
import com.klp.common.annotation.Log;
import com.klp.common.core.controller.BaseController;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.domain.R;
import com.klp.common.core.validate.AddGroup;
import com.klp.common.core.validate.EditGroup;
import com.klp.common.enums.BusinessType;
import com.klp.common.utils.poi.ExcelUtil;
import com.klp.domain.vo.WmsReportResultStorageVo;
import com.klp.domain.bo.WmsReportResultStorageBo;
import com.klp.service.IWmsReportResultStorageService;
import com.klp.common.core.page.TableDataInfo;
/**
* 报结果存储JSON+横向对比专用)
*
* @author klp
* @date 2026-03-25
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/reportResultStorage")
public class WmsReportResultStorageController extends BaseController {
private final IWmsReportResultStorageService iWmsReportResultStorageService;
/**
* 查询报结果存储JSON+横向对比专用)列表
*/
@GetMapping("/list")
public TableDataInfo<WmsReportResultStorageVo> list(WmsReportResultStorageBo bo, PageQuery pageQuery) {
return iWmsReportResultStorageService.queryPageList(bo, pageQuery);
}
/**
* 导出报结果存储JSON+横向对比专用)列表
*/
@Log(title = "报结果存储JSON+横向对比专用)", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(WmsReportResultStorageBo bo, HttpServletResponse response) {
List<WmsReportResultStorageVo> list = iWmsReportResultStorageService.queryList(bo);
ExcelUtil.exportExcel(list, "报结果存储JSON+横向对比专用)", WmsReportResultStorageVo.class, response);
}
/**
* 获取报结果存储JSON+横向对比专用)详细信息
*
* @param storageId 主键
*/
@GetMapping("/{storageId}")
public R<WmsReportResultStorageVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long storageId) {
return R.ok(iWmsReportResultStorageService.queryById(storageId));
}
/**
* 新增报结果存储JSON+横向对比专用)
*/
@Log(title = "报结果存储JSON+横向对比专用)", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsReportResultStorageBo bo) {
return toAjax(iWmsReportResultStorageService.insertByBo(bo));
}
/**
* 修改报结果存储JSON+横向对比专用)
*/
@Log(title = "报结果存储JSON+横向对比专用)", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsReportResultStorageBo bo) {
return toAjax(iWmsReportResultStorageService.updateByBo(bo));
}
/**
* 删除报结果存储JSON+横向对比专用)
*
* @param storageIds 主键串
*/
@Log(title = "报结果存储JSON+横向对比专用)", businessType = BusinessType.DELETE)
@DeleteMapping("/{storageIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] storageIds) {
return toAjax(iWmsReportResultStorageService.deleteWithValidByIds(Arrays.asList(storageIds), true));
}
}

View File

@@ -0,0 +1,55 @@
package com.klp.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.klp.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* 报结果存储JSON+横向对比专用)对象 wms_report_result_storage
*
* @author klp
* @date 2026-03-25
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("wms_report_result_storage")
public class WmsReportResultStorage extends BaseEntity {
private static final long serialVersionUID=1L;
/**
* 主键ID
*/
@TableId(value = "storage_id")
private Long storageId;
/**
* 报表日期(横向对比用)
*/
private Date reportDate;
/**
* 报表类型(横向对比用)
*/
private String reportType;
/**
* 产线类型(横向对比用)
*/
private String productionLine;
/**
* 报表完整JSON数据
*/
private String reportJson;
/**
* 备注
*/
private String remark;
/**
* 删除标志0=正常1=已删除)
*/
@TableLogic
private Integer delFlag;
}

View File

@@ -0,0 +1,68 @@
package com.klp.domain.bo;
import com.klp.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.*;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* 报结果存储JSON+横向对比专用)业务对象 wms_report_result_storage
*
* @author klp
* @date 2026-03-25
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WmsReportResultStorageBo extends BaseEntity {
/**
* 主键ID
*/
private Long storageId;
/**
* 报表日期(横向对比用)
*/
private Date reportDate;
/**
* 报表日期开始(时间段筛选)
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date reportDateStart;
/**
* 报表日期结束(时间段筛选)
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date reportDateEnd;
/**
* 报表类型(横向对比用)
*/
private String reportType;
/**
* 产线类型(横向对比用)
*/
private String productionLine;
/**
* 报表完整JSON数据
*/
private String reportJson;
/**
* 备注
*/
private String remark;
}

View File

@@ -0,0 +1,64 @@
package com.klp.domain.vo;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.klp.common.annotation.ExcelDictFormat;
import com.klp.common.convert.ExcelDictConvert;
import lombok.Data;
/**
* 报结果存储JSON+横向对比专用)视图对象 wms_report_result_storage
*
* @author klp
* @date 2026-03-25
*/
@Data
@ExcelIgnoreUnannotated
public class WmsReportResultStorageVo {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@ExcelProperty(value = "主键ID")
private Long storageId;
/**
* 报表日期(横向对比用)
*/
@ExcelProperty(value = "报表日期", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "横=向对比用")
private Date reportDate;
/**
* 报表类型(横向对比用)
*/
@ExcelProperty(value = "报表类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "横=向对比用")
private String reportType;
/**
* 产线类型(横向对比用)
*/
@ExcelProperty(value = "产线类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "横=向对比用")
private String productionLine;
/**
* 报表完整JSON数据
*/
@ExcelProperty(value = "报表完整JSON数据")
private String reportJson;
/**
* 备注
*/
@ExcelProperty(value = "备注")
private String remark;
}

View File

@@ -0,0 +1,15 @@
package com.klp.mapper;
import com.klp.domain.WmsReportResultStorage;
import com.klp.domain.vo.WmsReportResultStorageVo;
import com.klp.common.core.mapper.BaseMapperPlus;
/**
* 报结果存储JSON+横向对比专用Mapper接口
*
* @author klp
* @date 2026-03-25
*/
public interface WmsReportResultStorageMapper extends BaseMapperPlus<WmsReportResultStorageMapper, WmsReportResultStorage, WmsReportResultStorageVo> {
}

View File

@@ -0,0 +1,49 @@
package com.klp.service;
import com.klp.domain.WmsReportResultStorage;
import com.klp.domain.vo.WmsReportResultStorageVo;
import com.klp.domain.bo.WmsReportResultStorageBo;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.domain.PageQuery;
import java.util.Collection;
import java.util.List;
/**
* 报结果存储JSON+横向对比专用Service接口
*
* @author klp
* @date 2026-03-25
*/
public interface IWmsReportResultStorageService {
/**
* 查询报结果存储JSON+横向对比专用)
*/
WmsReportResultStorageVo queryById(Long storageId);
/**
* 查询报结果存储JSON+横向对比专用)列表
*/
TableDataInfo<WmsReportResultStorageVo> queryPageList(WmsReportResultStorageBo bo, PageQuery pageQuery);
/**
* 查询报结果存储JSON+横向对比专用)列表
*/
List<WmsReportResultStorageVo> queryList(WmsReportResultStorageBo bo);
/**
* 新增报结果存储JSON+横向对比专用)
*/
Boolean insertByBo(WmsReportResultStorageBo bo);
/**
* 修改报结果存储JSON+横向对比专用)
*/
Boolean updateByBo(WmsReportResultStorageBo bo);
/**
* 校验并批量删除报结果存储JSON+横向对比专用)信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@@ -0,0 +1,144 @@
package com.klp.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.klp.common.exception.ServiceException;
import com.klp.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.klp.domain.bo.WmsReportResultStorageBo;
import com.klp.domain.vo.WmsReportResultStorageVo;
import com.klp.domain.WmsReportResultStorage;
import com.klp.mapper.WmsReportResultStorageMapper;
import com.klp.service.IWmsReportResultStorageService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
/**
* 报结果存储JSON+横向对比专用Service业务层处理
*
* @author klp
* @date 2026-03-25
*/
@RequiredArgsConstructor
@Service
public class WmsReportResultStorageServiceImpl implements IWmsReportResultStorageService {
private final WmsReportResultStorageMapper baseMapper;
/**
* 查询报结果存储JSON+横向对比专用)
*/
@Override
public WmsReportResultStorageVo queryById(Long storageId){
return baseMapper.selectVoById(storageId);
}
/**
* 查询报结果存储JSON+横向对比专用)列表
*/
@Override
public TableDataInfo<WmsReportResultStorageVo> queryPageList(WmsReportResultStorageBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<WmsReportResultStorage> lqw = buildQueryWrapper(bo);
Page<WmsReportResultStorageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询报结果存储JSON+横向对比专用)列表
*/
@Override
public List<WmsReportResultStorageVo> queryList(WmsReportResultStorageBo bo) {
LambdaQueryWrapper<WmsReportResultStorage> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<WmsReportResultStorage> buildQueryWrapper(WmsReportResultStorageBo bo) {
Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<WmsReportResultStorage> lqw = Wrappers.lambdaQuery();
if (bo.getReportDateStart() != null || bo.getReportDateEnd() != null) {
lqw.ge(bo.getReportDateStart() != null, WmsReportResultStorage::getReportDate, bo.getReportDateStart());
lqw.le(bo.getReportDateEnd() != null, WmsReportResultStorage::getReportDate, bo.getReportDateEnd());
} else {
lqw.eq(bo.getReportDate() != null, WmsReportResultStorage::getReportDate, bo.getReportDate());
}
lqw.eq(StringUtils.isNotBlank(bo.getReportType()), WmsReportResultStorage::getReportType, bo.getReportType());
lqw.eq(StringUtils.isNotBlank(bo.getProductionLine()), WmsReportResultStorage::getProductionLine, bo.getProductionLine());
lqw.eq(StringUtils.isNotBlank(bo.getReportJson()), WmsReportResultStorage::getReportJson, bo.getReportJson());
lqw.orderByDesc(WmsReportResultStorage::getReportDate);
return lqw;
}
/**
* 新增报结果存储JSON+横向对比专用)
*/
@Override
public Boolean insertByBo(WmsReportResultStorageBo bo) {
WmsReportResultStorage add = BeanUtil.toBean(bo, WmsReportResultStorage.class);
validEntityBeforeSave(add);
// 当天仅允许存在一条计算结果(精确到“天”);如需修改请走更新接口
Date baseDate = add.getReportDate() != null ? add.getReportDate() : new Date();
ZoneId zone = ZoneId.systemDefault();
LocalDate day = baseDate.toInstant().atZone(zone).toLocalDate();
ZonedDateTime startZdt = day.atStartOfDay(zone);
ZonedDateTime endZdt = day.plusDays(1).atStartOfDay(zone).minusNanos(1);
Date startOfDay = Date.from(startZdt.toInstant());
Date endOfDay = Date.from(endZdt.toInstant());
LambdaQueryWrapper<WmsReportResultStorage> existsQw = Wrappers.lambdaQuery();
existsQw.ge(WmsReportResultStorage::getReportDate, startOfDay)
.le(WmsReportResultStorage::getReportDate, endOfDay)
.eq(StringUtils.isNotBlank(add.getReportType()), WmsReportResultStorage::getReportType, add.getReportType())
.eq(StringUtils.isNotBlank(add.getProductionLine()), WmsReportResultStorage::getProductionLine, add.getProductionLine());
Long cnt = baseMapper.selectCount(existsQw);
if (cnt != null && cnt > 0) {
throw new ServiceException("今天已经存在计算结果了");
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setStorageId(add.getStorageId());
}
return flag;
}
/**
* 修改报结果存储JSON+横向对比专用)
*/
@Override
public Boolean updateByBo(WmsReportResultStorageBo bo) {
WmsReportResultStorage update = BeanUtil.toBean(bo, WmsReportResultStorage.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(WmsReportResultStorage entity){
//TODO 做一些数据校验,如唯一约束
}
/**
* 批量删除报结果存储JSON+横向对比专用)
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
//TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteBatchIds(ids) > 0;
}
}

View File

@@ -0,0 +1,22 @@
<?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.klp.mapper.WmsReportResultStorageMapper">
<resultMap type="com.klp.domain.WmsReportResultStorage" id="WmsReportResultStorageResult">
<result property="storageId" column="storage_id"/>
<result property="reportDate" column="report_date"/>
<result property="reportType" column="report_type"/>
<result property="productionLine" column="production_line"/>
<result property="reportJson" column="report_json"/>
<result property="remark" column="remark"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="createBy" column="create_by"/>
<result property="updateTime" column="update_time"/>
<result property="updateBy" column="update_by"/>
</resultMap>
</mapper>