|
|
@@ -1,27 +1,41 @@
|
|
|
package com.github.zuihou.business.statisticalAnalysis.impl;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.zuihou.base.service.SuperCacheServiceImpl;
|
|
|
-import com.github.zuihou.business.externalApi.dao.AgvHikOrderDetailInfoMapper;
|
|
|
-import com.github.zuihou.business.externalApi.entity.AgvHikOrderDetailInfo;
|
|
|
-import com.github.zuihou.business.externalApi.service.AgvHikOrderDetailInfoService;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.dao.WorkpieceMapper;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
|
|
|
import com.github.zuihou.business.statisticalAnalysis.ProductLinePerformanceService;
|
|
|
import com.github.zuihou.business.statisticalAnalysis.dao.ProductLinePerformanceMapper;
|
|
|
+import com.github.zuihou.business.util.IPageUtils;
|
|
|
import com.github.zuihou.common.constant.CacheKey;
|
|
|
+import com.github.zuihou.common.util.DateUtil;
|
|
|
import com.github.zuihou.database.mybatis.auth.DataScope;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
import com.github.zuihou.injection.annonation.InjectionResult;
|
|
|
-import com.github.zuihou.utils.BeanPlusUtil;
|
|
|
+import com.github.zuihou.tenant.dto.ProductDto;
|
|
|
+import com.github.zuihou.tenant.dto.ProductInfoDto;
|
|
|
+import com.github.zuihou.tenant.dto.ProductInfoExcelDto;
|
|
|
+import com.github.zuihou.tenant.dto.ProductionStatisticalDto;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -37,6 +51,10 @@ import java.util.List;
|
|
|
|
|
|
public class ProductLinePerformanceServiceImpl extends SuperCacheServiceImpl<ProductLinePerformanceMapper, TaskNode> implements ProductLinePerformanceService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkpieceMapper workpieceMapper;
|
|
|
+
|
|
|
@Override
|
|
|
protected String getRegion() {
|
|
|
return CacheKey.USER;
|
|
|
@@ -77,4 +95,127 @@ public class ProductLinePerformanceServiceImpl extends SuperCacheServiceImpl<Pro
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<ProductDto> getProductStatistics(){
|
|
|
+ List<ProductDto> statistics = workpieceMapper.getProductStatistics();
|
|
|
+ return statistics;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品流转详情
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<ProductInfoDto> getProductInfoStatistics(Long page, Long limit) {
|
|
|
+ List<ProductInfoDto> productInfoDtos = workpieceMapper.selectProductInfo();
|
|
|
+ if (!CollectionUtil.isEmpty(productInfoDtos)) {
|
|
|
+ List<ProductInfoDto> productInfos = productInfoDtos.stream().map(item -> {
|
|
|
+ ProductInfoDto productInfoDto = BeanUtil.toBean(item, ProductInfoDto.class);
|
|
|
+ if (item.getEndTime() != null && item.getStartTime() != null) {
|
|
|
+ String hour = DateUtil.getDatePoor(item.getEndTime(), item.getStartTime());
|
|
|
+ productInfoDto.setHour(hour);
|
|
|
+ } else {
|
|
|
+ productInfoDto.setHour("0");
|
|
|
+ }
|
|
|
+ return productInfoDto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtil.isEmpty(productInfos)) {
|
|
|
+ productInfos.sort((o1, o2) -> {
|
|
|
+ return o2.getPlanStartTime().compareTo(o1.getPlanStartTime());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Page pages = IPageUtils.getPages(page, limit, productInfos);
|
|
|
+ return pages;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void expectProduct(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ List<ProductDto> productStatistics = getProductStatistics();
|
|
|
+ // 设置响应输出的头类型
|
|
|
+ // 设置响应输出的头类型
|
|
|
+ response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
+ // 设计导出文件的名称,尽量不要中文
|
|
|
+ String fileName = new String("产品流转详汇总.xls".getBytes(), "ISO-8859-1");
|
|
|
+ response.setHeader("Content-Disposition","attachment;filename="+ fileName);
|
|
|
+ //输出流。
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("产品流转详汇总", "产品流转详汇总"), ProductDto.class, productStatistics);
|
|
|
+ workbook.write(out);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void expectProductInfo(HttpServletResponse response) throws IOException {
|
|
|
+ List<ProductInfoDto> productInfoDtos = workpieceMapper.selectProductInfo();
|
|
|
+ List<ProductInfoDto> productInfos = productInfoDtos.stream().map(item->{
|
|
|
+ ProductInfoDto productInfoDto = BeanUtil.toBean(item, ProductInfoDto.class);
|
|
|
+ if (item.getEndTime() != null && item.getStartTime() != null) {
|
|
|
+ String hour = DateUtil.getDatePoor(item.getEndTime(), item.getStartTime());
|
|
|
+ productInfoDto.setHour(hour);
|
|
|
+ }else {
|
|
|
+ productInfoDto.setHour("0");
|
|
|
+ }
|
|
|
+ return productInfoDto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ List<ProductInfoExcelDto> excels =productInfos.stream().map(item->{
|
|
|
+ ProductInfoExcelDto excelDto = BeanUtil.toBean(item,ProductInfoExcelDto.class);
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ excelDto.setPlanStartTime(item.getPlanStartTime()!=null ? simpleDateFormat.format(item.getPlanStartTime()):"");
|
|
|
+ excelDto.setPlanEndTime(item.getPlanEndTime()!=null ? simpleDateFormat.format(item.getPlanEndTime()):"");
|
|
|
+ excelDto.setStartTime(item.getStartTime()!=null ? simpleDateFormat.format(item.getStartTime()):"");
|
|
|
+ excelDto.setEndTime(item.getEndTime()!=null ? simpleDateFormat.format(item.getEndTime()):"");
|
|
|
+ return excelDto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 设置响应输出的头类型
|
|
|
+ // 设置响应输出的头类型
|
|
|
+ response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
+ // 设计导出文件的名称,尽量不要中文
|
|
|
+ String fileName = new String("产品流转详情.xls".getBytes(), "ISO-8859-1");
|
|
|
+ response.setHeader("Content-Disposition","attachment;filename="+ fileName);
|
|
|
+ //输出流。
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
+ //将数据导出到Excel
|
|
|
+ //参数1:ExportParams对象 参数2:导出的类型 参数3:导出的数据集合
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("产品流转详情", "产品流转详情"), ProductInfoExcelDto.class, excels);
|
|
|
+ //使用流将excel写入到指定的位置
|
|
|
+ workbook.write(out);//将数据输出
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备工时统计
|
|
|
+ * @param page
|
|
|
+ * @param limit
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<ProductionStatisticalDto> queryProcedure(Long page, Long limit) {
|
|
|
+ List<ProductionStatisticalDto> list = baseMapper.queryProcedure();
|
|
|
+ Page pages = IPageUtils.getPages(page, limit, list);
|
|
|
+ return pages;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备工时导出
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void expectProcedure(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ List<ProductionStatisticalDto> list = baseMapper.queryProcedure();
|
|
|
+ // 设置响应输出的头类型
|
|
|
+ // 设置响应输出的头类型
|
|
|
+ response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
+ // 设计导出文件的名称,尽量不要中文
|
|
|
+ String fileName = new String("设备工时管理.xls".getBytes(), "ISO-8859-1");
|
|
|
+ response.setHeader("Content-Disposition","attachment;filename="+ fileName);
|
|
|
+ //输出流。
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
+ // 创建参数对象(用来设定excel得sheet的内容等信息)
|
|
|
+ // title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("设备工时管理", "设备工时管理"), ProductionStatisticalDto.class, list);
|
|
|
+ workbook.write(out);
|
|
|
+ }
|
|
|
}
|