feat(wms): 添加报表结果存储功能支持JSON和横向对比
- 创建WmsReportResultStorage实体类用于存储报表结果数据 - 实现IWmsReportResultStorageService服务接口及其实现类 - 添加WmsReportResultStorageController控制器提供CRUD操作 - 创建WmsReportResultStorageMapper数据访问层 - 配置WmsReportResultStorageMapper.xml映射文件 - 定义WmsReportResultStorageBo业务对象和WmsReportResultStorageVo视图对象 - 实现报表数据按日期、类型、产线进行查询和去重逻辑 - 添加Excel导出功能支持报表数据导出
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user