Redeem 1 anno fa
parent
commit
4d260dc7c0

+ 8 - 0
src/main/java/com/steerinfo/dil/controller/OyeResultController.java

@@ -254,6 +254,14 @@ public class OyeResultController extends BaseRESTfulController {
     }
 
 
+    @ApiOperation("导出excel")
+    @PostMapping("exportExcel")
+    public RESTfulResult exportExcel() {
+        oyeResultService.reportToExcel();
+        return success();
+    }
+
+
 
 
 }

+ 198 - 0
src/main/java/com/steerinfo/dil/model/ReceiveSendReport.java

@@ -0,0 +1,198 @@
+package com.steerinfo.dil.model;
+
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class ReceiveSendReport {
+
+    @ExcelProperty(value = "客户", index = 0)
+    private String companyName;
+
+    @ExcelProperty(value = "片区", index = 1)
+    private String saleArea;
+
+    @ExcelProperty(value = "物资名称", index = 2)
+    private String materialName;
+
+    @ExcelProperty(value = "规格", index = 3)
+    private String materialSpe;
+
+    @ExcelProperty(value = "型号", index = 4)
+    private String materialModel;
+
+    @ExcelProperty(value = "米数", index = 5)
+    private BigDecimal meter;
+
+    @ExcelProperty(value = "单重", index = 6)
+    private BigDecimal singleWeight;
+
+    @ExcelProperty(value = "总入库件数", index = 7)
+    private BigDecimal inboundMaterialNumber;
+
+    @ExcelProperty(value = "总入库重量", index = 8)
+    private BigDecimal inboundMaterialWeight;
+
+    @ExcelProperty(value = "总出库件数", index = 9)
+    private BigDecimal outboundMaterialNumber;
+
+    @ExcelProperty(value = "总出库重量", index = 10)
+    private BigDecimal outboundMaterialWeight;
+
+    @ExcelProperty(value = "当前入库数量", index = 11)
+    private BigDecimal currentInboundMaterialNumber;
+
+    @ExcelProperty(value = "当前入库重量", index = 12)
+    private BigDecimal currentInboundTheoryWeight;
+
+    @ExcelProperty(value = "当前出库数量", index = 13)
+    private BigDecimal currentOutboundMaterialNumber;
+
+    @ExcelProperty(value = "当前出库重量", index = 14)
+    private BigDecimal currentOutboundTheoryWeight;
+
+    @ExcelProperty(value = "库存件数", index = 15)
+    private BigDecimal materialNumber;
+
+    @ExcelProperty(value = "库存重量", index = 16)
+    private BigDecimal materialWeight;
+
+    public String getCompanyName() {
+        return companyName;
+    }
+
+    public void setCompanyName(String companyName) {
+        this.companyName = companyName;
+    }
+
+    public String getSaleArea() {
+        return saleArea;
+    }
+
+    public void setSaleArea(String saleArea) {
+        this.saleArea = saleArea;
+    }
+
+    public String getMaterialName() {
+        return materialName;
+    }
+
+    public void setMaterialName(String materialName) {
+        this.materialName = materialName;
+    }
+
+    public String getMaterialSpe() {
+        return materialSpe;
+    }
+
+    public void setMaterialSpe(String materialSpe) {
+        this.materialSpe = materialSpe;
+    }
+
+    public String getMaterialModel() {
+        return materialModel;
+    }
+
+    public void setMaterialModel(String materialModel) {
+        this.materialModel = materialModel;
+    }
+
+    public BigDecimal getMeter() {
+        return meter;
+    }
+
+    public void setMeter(BigDecimal meter) {
+        this.meter = meter;
+    }
+
+    public BigDecimal getSingleWeight() {
+        return singleWeight;
+    }
+
+    public void setSingleWeight(BigDecimal singleWeight) {
+        this.singleWeight = singleWeight;
+    }
+
+    public BigDecimal getInboundMaterialNumber() {
+        return inboundMaterialNumber;
+    }
+
+    public void setInboundMaterialNumber(BigDecimal inboundMaterialNumber) {
+        this.inboundMaterialNumber = inboundMaterialNumber;
+    }
+
+    public BigDecimal getInboundMaterialWeight() {
+        return inboundMaterialWeight;
+    }
+
+    public void setInboundMaterialWeight(BigDecimal inboundMaterialWeight) {
+        this.inboundMaterialWeight = inboundMaterialWeight;
+    }
+
+    public BigDecimal getOutboundMaterialNumber() {
+        return outboundMaterialNumber;
+    }
+
+    public void setOutboundMaterialNumber(BigDecimal outboundMaterialNumber) {
+        this.outboundMaterialNumber = outboundMaterialNumber;
+    }
+
+    public BigDecimal getOutboundMaterialWeight() {
+        return outboundMaterialWeight;
+    }
+
+    public void setOutboundMaterialWeight(BigDecimal outboundMaterialWeight) {
+        this.outboundMaterialWeight = outboundMaterialWeight;
+    }
+
+    public BigDecimal getCurrentInboundMaterialNumber() {
+        return currentInboundMaterialNumber;
+    }
+
+    public void setCurrentInboundMaterialNumber(BigDecimal currentInboundMaterialNumber) {
+        this.currentInboundMaterialNumber = currentInboundMaterialNumber;
+    }
+
+    public BigDecimal getCurrentInboundTheoryWeight() {
+        return currentInboundTheoryWeight;
+    }
+
+    public void setCurrentInboundTheoryWeight(BigDecimal currentInboundTheoryWeight) {
+        this.currentInboundTheoryWeight = currentInboundTheoryWeight;
+    }
+
+    public BigDecimal getCurrentOutboundMaterialNumber() {
+        return currentOutboundMaterialNumber;
+    }
+
+    public void setCurrentOutboundMaterialNumber(BigDecimal currentOutboundMaterialNumber) {
+        this.currentOutboundMaterialNumber = currentOutboundMaterialNumber;
+    }
+
+    public BigDecimal getCurrentOutboundTheoryWeight() {
+        return currentOutboundTheoryWeight;
+    }
+
+    public void setCurrentOutboundTheoryWeight(BigDecimal currentOutboundTheoryWeight) {
+        this.currentOutboundTheoryWeight = currentOutboundTheoryWeight;
+    }
+
+    public BigDecimal getMaterialNumber() {
+        return materialNumber;
+    }
+
+    public void setMaterialNumber(BigDecimal materialNumber) {
+        this.materialNumber = materialNumber;
+    }
+
+    public BigDecimal getMaterialWeight() {
+        return materialWeight;
+    }
+
+    public void setMaterialWeight(BigDecimal materialWeight) {
+        this.materialWeight = materialWeight;
+    }
+}

+ 42 - 26
src/main/java/com/steerinfo/dil/service/impl/OyeResultServiceImpl.java

@@ -2,28 +2,22 @@ package com.steerinfo.dil.service.impl;
 
 
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.steerinfo.dil.feign.BmsTruckFeign;
 import com.steerinfo.dil.mapper.OyeInboundResultMapper;
 import com.steerinfo.dil.mapper.OyeOutboundResultMapper;
 import com.steerinfo.dil.mapper.OyeRealtimeInventoryMapper;
 import com.steerinfo.dil.mapper.TmstruckWeightBatchMapper;
-import com.steerinfo.dil.model.OyeInboundResult;
-import com.steerinfo.dil.model.OyeOutboundResult;
-import com.steerinfo.dil.model.OyeRealtimeInventory;
-import com.steerinfo.dil.model.TmstruckWeightBatch;
+import com.steerinfo.dil.model.*;
 import com.steerinfo.dil.service.IOyeResultService;
 import com.steerinfo.dil.util.DataChange;
-import com.steerinfo.dil.util.EasyExcelUtils;
-import com.sun.org.apache.bcel.internal.generic.RETURN;
-import org.omg.PortableInterceptor.SUCCESSFUL;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import javax.xml.crypto.Data;
 import java.math.BigDecimal;
-import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -552,21 +546,43 @@ public class OyeResultServiceImpl implements IOyeResultService {
 
 
 
-    //public int exportExcel() {
-    //    Calendar calendar = Calendar.getInstance();
-    //    int year = calendar.get(Calendar.YEAR);
-    //    int month = calendar.get(Calendar.MONTH) + 1;
-    //    int day = calendar.get(Calendar.DAY_OF_MONTH);
-    //    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    //    String dateStr = simpleDateFormat.format(calendar.getTime());
-    //    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
-    //    response.setCharacterEncoding("utf-8");
-    //    String fileName = URLEncoder.encode(year + "" + month + "" + day + "运输单价", "UTF-8").replaceAll("\\+", "%20");
-    //    response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
-    //    EasyExcel.write(response.getOutputStream(), AmsTransPrice.class).sheet(dateStr + "运输单价").
-    //            registerWriteHandler(new CustomCellWriteWidthConfig()).registerWriteHandler(new CustomCellWriteHeightConfig()).
-    //            registerWriteHandler(EasyExcelUtils.getStyleStrategy()).
-    //            doWrite(list);
-    //    return success();
-    //}
+
+    public void reportToExcel() {
+        try {
+            Calendar calendar = Calendar.getInstance();
+            int year = calendar.get(Calendar.YEAR);
+            int month = calendar.get(Calendar.MONTH) + 1;
+            int day = calendar.get(Calendar.DAY_OF_MONTH);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            String dateStr = simpleDateFormat.format(calendar.getTime());
+            //实现写操作
+            //1.设置写入文件夹地址和excel文件名称
+            String filename = "/shared/" + dateStr + ".xlsx";
+            //2.调用easyexcel里的方法实现写操作
+            //String filename = "D:\\write.xlsx";
+            //write方法的两个参数:第一个参数是:文件路径,第二个参数是:实体类的class
+            List<ReceiveSendReport> list = new ArrayList<>();
+            Map<String, Object> map = new HashMap<>();
+            SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            DataChange.queryDataByDateTime(null,null,map,sdfDateTime);
+            List<Map<String,Object>> mapList = oyeRealtimeInventoryMapper.receiveSendReport(map);
+            for(Map<String,Object> mapVal : mapList) {
+                JSONObject jsonObject = new JSONObject(mapVal);
+                String mapValToString = jsonObject.toString();
+                ReceiveSendReport receiveSendReport = JSON.parseObject(mapValToString,ReceiveSendReport.class);
+                list.add(receiveSendReport);
+            }
+            EasyExcel.write(filename, ReceiveSendReport.class).sheet("出入库台账报表").doWrite(list);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Scheduled(cron = "0 40 10 * * ?")
+    public synchronized void dsExportExcel() {
+        reportToExcel();
+    }
+
+
+
 }

+ 1 - 29
src/main/resources/com/steerinfo/dil/mapper/OyeRealtimeInventoryMapper.xml

@@ -674,22 +674,6 @@
   <!-- 友情提示!!!-->
   <!-- 请将自己写的代码放在此标签之下,方便以后粘贴复制。-->
   <select id="getOyeRealTimeResult" resultType="java.util.Map">
-    SELECT
-    TT."materialId" "materialId",
-    TT."meter" "meter",
-    TT."singleWeight" "singleWeight",
-    TT."consigneeName" "consigneeName",
-    TT."materialModel" "materialModel",
-    TT."materialSpe" "materialSpe",
-    TT."materialName" "materialName",
-    TT."consigneeId" "consigneeId",
-    TT."inboundArea" "inboundArea",
-    TT."inboundWarehouse" "inboundWarehouse",
-    TT."saleArea" "saleArea",
-    SUM(TT."materialNumber") "materialNumber",
-    SUM(TT."theoryWeight") "theoryWeight",
-    SUM(TT."netWeight") "netWeight"
-    FROM (
     SELECT ORI.SINGLE_WEIGHT "singleWeight",
     ORI.METER    "meter",
     ORI.MATERIAL_ID  "materialId",
@@ -752,19 +736,7 @@
         </foreach>
       </if>
     </where>
-    ) TT
-    GROUP BY TT."materialId",
-    TT."meter",
-    TT."singleWeight",
-    TT."consigneeName",
-    TT."materialModel",
-    TT."materialSpe",
-    TT."materialName",
-    TT."consigneeId",
-    TT."inboundArea",
-    TT."inboundWarehouse",
-    TT."saleArea"
-    ORDER BY TT."consigneeName" desc, TT."saleArea" desc, TT."inboundWarehouse" DESC
+    ORDER BY RC.CONSIGNEE_COMPANY_NAME desc,ORI.SALE_AREA desc
   </select>
   <select id="getInventoryId" resultType="java.math.BigDecimal" parameterType="java.util.Map">
     SELECT ORI.INVENTORY_ID FROM OYE_REALTIME_INVENTORY ORI