Procházet zdrojové kódy

辅材网点师傅报表

FengChaoYu před 7 měsíci
rodič
revize
88af934731

+ 1 - 1
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/report/MaterialSalesSumBean.java

@@ -15,7 +15,7 @@ public class MaterialSalesSumBean {
     @ApiModelProperty(value = "网点名称")
     private String websitName;
     @ApiModelProperty(value = "工程师手机号")
-    private String mobile;
+    private String workerMobile;
     @ApiModelProperty(value = "工程师编号")
     private String workerId;
     @ApiModelProperty(value = "工程师名称")

+ 31 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/report/MaterialSalesSumDetailBean.java

@@ -0,0 +1,31 @@
+package com.gree.mall.manager.bean.material.report;
+
+import com.gree.mall.manager.plus.entity.WebsitSalesItem;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+
+@EqualsAndHashCode(callSuper = true)
+@ApiModel
+@Data
+public class MaterialSalesSumDetailBean extends WebsitSalesItem {
+    @ApiModelProperty(value = "网点编号")
+    private String websitId;
+    @ApiModelProperty(value = "网点名称")
+    private String websitName;
+    @ApiModelProperty(value = "支付类型")
+    private String payType;
+    @ApiModelProperty(value = "支付状态")
+    private String payFlag;
+    @ApiModelProperty(value = "工程师手机号")
+    private String workerMobile;
+    @ApiModelProperty(value = "工程师编号")
+    private String workerId;
+    @ApiModelProperty(value = "工程师名称")
+    private String workerName;
+    @ApiModelProperty(value = "支付时间/提货时间")
+    private Date payTime;
+}

+ 78 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/report/PurchaseCategoryBean.java

@@ -0,0 +1,78 @@
+package com.gree.mall.manager.bean.material.report;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.math.BigDecimal;
+
+@Data
+@Accessors(chain = true)
+@ApiModel(value="PurchaseCategoryBean对象", description="月度辅材采购类别")
+public class PurchaseCategoryBean {
+    @ApiModelProperty(value = "年月")
+    private String yearMonth;
+    @ApiModelProperty(value = "网点编号")
+    private String websitId;
+    @ApiModelProperty(value = "网点名称")
+    private String websitName;
+    @ApiModelProperty(value = "铜管")
+    private BigDecimal tgQty = new BigDecimal("0");
+    @ApiModelProperty(value = "铜管总价")
+    private BigDecimal tgVal = new BigDecimal("0");
+    @ApiModelProperty(value = "保温棉")
+    private BigDecimal bwmQty = new BigDecimal("0");
+    @ApiModelProperty(value = "保温棉总价")
+    private BigDecimal bwmVal = new BigDecimal("0");
+    @ApiModelProperty(value = "电缆")
+    private BigDecimal dlQty = new BigDecimal("0");
+    @ApiModelProperty(value = "电缆总价")
+    private BigDecimal dlVal = new BigDecimal("0");
+    @ApiModelProperty(value = "支架")
+    private BigDecimal zjQty = new BigDecimal("0");
+    @ApiModelProperty(value = "支架总价")
+    private BigDecimal zjVal = new BigDecimal("0");
+    @ApiModelProperty(value = "冷媒")
+    private BigDecimal lmQty = new BigDecimal("0");
+    @ApiModelProperty(value = "冷媒总价")
+    private BigDecimal lmVal = new BigDecimal("0");
+    @ApiModelProperty(value = "五金")
+    private BigDecimal wjQty = new BigDecimal("0");
+    @ApiModelProperty(value = "五金总价")
+    private BigDecimal wjVal = new BigDecimal("0");
+    @ApiModelProperty(value = "其它")
+    private BigDecimal jtQty = new BigDecimal("0");
+    @ApiModelProperty(value = "其它总价")
+    private BigDecimal jtVal = new BigDecimal("0");
+    @ApiModelProperty(value = "开关")
+    private BigDecimal kgQty = new BigDecimal("0");
+    @ApiModelProperty(value = "开关总价")
+    private BigDecimal kgVal = new BigDecimal("0");
+    @ApiModelProperty(value = "包扎带")
+    private BigDecimal bzdQty = new BigDecimal("0");
+    @ApiModelProperty(value = "包扎带总价")
+    private BigDecimal bzdVal = new BigDecimal("0");
+    @ApiModelProperty(value = "连接器")
+    private BigDecimal ljqQty = new BigDecimal("0");
+    @ApiModelProperty(value = "连接器总价")
+    private BigDecimal ljqVal = new BigDecimal("0");
+    @ApiModelProperty(value = "双壁热缩套管")
+    private BigDecimal rsgQty = new BigDecimal("0");
+    @ApiModelProperty(value = "双壁热缩套管总价")
+    private BigDecimal rsgVal = new BigDecimal("0");
+    @ApiModelProperty(value = "清洗工具")
+    private BigDecimal qxggQty = new BigDecimal("0");
+    @ApiModelProperty(value = "清洗工具总价")
+    private BigDecimal qxggVal = new BigDecimal("0");
+    @ApiModelProperty(value = "管槽")
+    private BigDecimal gcQty = new BigDecimal("0");
+    @ApiModelProperty(value = "管槽总价")
+    private BigDecimal gcVal = new BigDecimal("0");
+    @ApiModelProperty(value = "热水器")
+    private BigDecimal ysqQty = new BigDecimal("0");
+    @ApiModelProperty(value = "热水器总价")
+    private BigDecimal ysqVal = new BigDecimal("0");
+    @ApiModelProperty(value = "上月库存金额")
+    private BigDecimal lastMonthVal = new BigDecimal("0");
+}

+ 23 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/report/PurchaseDetailBean.java

@@ -0,0 +1,23 @@
+package com.gree.mall.manager.bean.material.report;
+
+import com.gree.mall.manager.plus.entity.WebsitPurchaseItem;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@ApiModel
+public class PurchaseDetailBean extends WebsitPurchaseItem {
+    @ApiModelProperty(value = "网点编号")
+    private String websitid;
+    @ApiModelProperty(value = "网点名称")
+    private String websitName;
+    @ApiModelProperty(value = "供应商编号")
+    private String venderId;
+    @ApiModelProperty(value = "供应商名称")
+    private String venderName;
+    @ApiModelProperty(value = "类别名称")
+    private String goodsCategoryName;
+}

+ 14 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/report/WebsiteStockValSumBean.java

@@ -0,0 +1,14 @@
+package com.gree.mall.manager.bean.material.report;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.math.BigDecimal;
+
+@Data
+@ApiModel
+public class WebsiteStockValSumBean {
+    private String websitId;
+    private BigDecimal lastMonthVal;
+}

+ 84 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/material/report/WorkerPurchaseCategoryBean.java

@@ -0,0 +1,84 @@
+package com.gree.mall.manager.bean.material.report;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.math.BigDecimal;
+
+@Data
+@Accessors(chain = true)
+@ApiModel(value = "WorkerPurchaseCategoryBean对象", description = "月度师傅辅材采购类别")
+public class WorkerPurchaseCategoryBean {
+    @ApiModelProperty(value = "年月")
+    private String yearMonth;
+    @ApiModelProperty(value = "网点编号")
+    private String websitId;
+    @ApiModelProperty(value = "网点名称")
+    private String websiteName;
+    @ApiModelProperty(value = "师傅编号")
+    private String workerId;
+    @ApiModelProperty(value = "师傅名称")
+    private String workerName;
+    @ApiModelProperty(value = "铜管")
+    private BigDecimal tgQty;
+    @ApiModelProperty(value = "铜管转换数")
+    private BigDecimal tgConvertQty;
+    @ApiModelProperty(value = "铜管总价")
+    private BigDecimal tgVal;
+    @ApiModelProperty(value = "保温棉")
+    private BigDecimal bwmQty;
+    @ApiModelProperty(value = "保温棉总价")
+    private BigDecimal bwmVal;
+    @ApiModelProperty(value = "电缆")
+    private BigDecimal dlQty;
+    @ApiModelProperty(value = "电缆总价")
+    private BigDecimal dlVal;
+    @ApiModelProperty(value = "支架")
+    private BigDecimal zjQty;
+    @ApiModelProperty(value = "支架总价")
+    private BigDecimal zjVal;
+    @ApiModelProperty(value = "冷媒")
+    private BigDecimal lmQty;
+    @ApiModelProperty(value = "冷媒总价")
+    private BigDecimal lmVal;
+    @ApiModelProperty(value = "五金")
+    private BigDecimal wjQty;
+    @ApiModelProperty(value = "五金总价")
+    private BigDecimal wjVal;
+    @ApiModelProperty(value = "其它")
+    private BigDecimal jtQty;
+    @ApiModelProperty(value = "其它总价")
+    private BigDecimal jtVal;
+    @ApiModelProperty(value = "开关")
+    private BigDecimal kgQty;
+    @ApiModelProperty(value = "开关总价")
+    private BigDecimal kgVal;
+    @ApiModelProperty(value = "包扎带")
+    private BigDecimal bzdQty;
+    @ApiModelProperty(value = "包扎带总价")
+    private BigDecimal bzdVal;
+    @ApiModelProperty(value = "连接器")
+    private BigDecimal ljqQty;
+    @ApiModelProperty(value = "连接器总价")
+    private BigDecimal ljqVal;
+    @ApiModelProperty(value = "双壁热缩套管")
+    private BigDecimal rsgQty;
+    @ApiModelProperty(value = "双壁热缩套管总价")
+    private BigDecimal rsgVal;
+    @ApiModelProperty(value = "清洗工具")
+    private BigDecimal qxggQty;
+    @ApiModelProperty(value = "清洗工具总价")
+    private BigDecimal qxggVal;
+    @ApiModelProperty(value = "管槽")
+    private BigDecimal gcQty;
+    @ApiModelProperty(value = "管槽总价")
+    private BigDecimal gcVal;
+    @ApiModelProperty(value = "热水器")
+    private BigDecimal ysqQty;
+    @ApiModelProperty(value = "热水器总价")
+    private BigDecimal ysqVal;
+    @ApiModelProperty(value = "师傅当月剩余库存金额")
+    private BigDecimal workerGoodsPrice;
+}

+ 130 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/MaterialMapper.java

@@ -6,6 +6,7 @@ import com.gree.mall.manager.bean.engin.EnginPayManageGatherVO;
 import com.gree.mall.manager.bean.engin.EnginPayManageVO;
 import com.gree.mall.manager.bean.material.base.*;
 import com.gree.mall.manager.bean.material.manage.*;
+import com.gree.mall.manager.bean.material.report.*;
 import com.gree.mall.manager.bean.material.stock.WebsitSalesCategoryVO;
 import com.gree.mall.manager.bean.material.stock.WebsitSalesGoodsVO;
 import com.gree.mall.manager.bean.material.vender.WebsitPurchaseCheckVO;
@@ -349,4 +350,133 @@ public interface MaterialMapper {
      * @return
      */
     IPage<WebsitPartsRefundRecordVO> websitPartsRefundRecordPage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+    /**
+     * 按师傅手机号汇总辅材销售单
+     * @param companyWechatId
+     * @param startDate
+     * @param endDate
+     * @param websits
+     * @param websitId
+     * @param workerMobile
+     * @param workerId
+     * @param workerName
+     * @return
+     */
+    List<MaterialSalesSumBean> workerBuySum(@Param("companyWechatId") String companyWechatId,
+                                            @Param("startDate") String startDate,
+                                            @Param("endDate") String endDate,
+                                            @Param("websits") List<String> websits,
+                                            @Param("websitId") String websitId,
+                                            @Param("workerMobile") String workerMobile,
+                                            @Param("workerId") String workerId,
+                                            @Param("workerName") String workerName);
+
+    /**
+     * 根据手机号和时间获取销售单明细
+     * @param companyWechatId
+     * @param startDate
+     * @param endDate
+     * @param websits
+     * @param websitId
+     * @param workerMobile
+     * @return
+     */
+    List<MaterialSalesSumDetailBean> workerBuyDetail(@Param("companyWechatId") String companyWechatId,
+                                                        @Param("startDate") String startDate,
+                                                        @Param("endDate") String endDate,
+                                                        @Param("websits") List<String> websits,
+                                                        @Param("websitId") String websitId,
+                                                        @Param("workerMobile") String workerMobile);
+
+    /**
+     * 按师傅手机号汇总销售明细
+     * @param companyWechatId
+     * @param startDate
+     * @param endDate
+     * @param websits
+     * @param websitId
+     * @param workerMobile
+     * @param workerId
+     * @param workerName
+     * @return
+     */
+    List<MaterialSalesSumDetailBean> workerBuySumDetail(@Param("companyWechatId") String companyWechatId,
+                                                        @Param("startDate") String startDate,
+                                                        @Param("endDate") String endDate,
+                                                        @Param("websits") List<String> websits,
+                                                        @Param("websitId") String websitId,
+                                                        @Param("workerMobile") String workerMobile,
+                                                        @Param("workerId") String workerId,
+                                                        @Param("workerName") String workerName);
+
+    /**
+     * 汇总销售明细
+     * @param companyWechatId
+     * @param startDate
+     * @param endDate
+     * @param websits
+     * @param websitId
+     * @param workerMobile
+     * @param workerId
+     * @param workerName
+     * @return
+     */
+    List<MaterialSalesSumDetailBean> sumBuyDetail(@Param("companyWechatId") String companyWechatId,
+                                                  @Param("startDate") String startDate,
+                                                  @Param("endDate") String endDate,
+                                                  @Param("websits") List<String> websits,
+                                                  @Param("websitId") String websitId,
+                                                  @Param("workerMobile") String workerMobile,
+                                                  @Param("workerId") String workerId,
+                                                  @Param("workerName") String workerName);
+
+    /**
+     * 采购商品汇总
+     * @param companyWechatId
+     * @param startTime
+     * @param endTime
+     * @param websits
+     * @param websitId
+     * @param isSum
+     * @return
+     */
+    List<PurchaseDetailBean> purchaseGoodsSum(@Param("companyWechatId") String companyWechatId,
+                                              @Param("startTime") String startTime,
+                                              @Param("endTime") String endTime,
+                                              @Param("websits") List<String> websits,
+                                              @Param("websitId") String websitId,
+                                              @Param("isSum") boolean isSum);
+
+    /**
+     * 查询网点采购汇总数据
+     * @param companyWechatId
+     * @param websits
+     * @param websitId
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    List<PurchaseCategoryBean> getMonthSummaryData(@Param("companyWechatId") String companyWechatId,
+                                                   @Param("websits") List<String> websits,
+                                                   @Param("websitId") String websitId,
+                                                   @Param("startDate") String startDate,
+                                                   @Param("endDate") String endDate);
+
+    /**
+     * 查询网点上个月结存金额
+     * @param companyWechatId
+     * @param websits
+     * @param websitId
+     * @param startDate
+     * @return
+     */
+    List<WebsiteStockValSumBean> getLastMonthStockSumVal(@Param("companyWechatId") String companyWechatId,
+                                                         @Param("websits") List<String> websits,
+                                                         @Param("websitId") String websitId,
+                                                         @Param("startDate") String startDate);
+
+    List<WorkerPurchaseCategoryBean> getWorkerMonthSummaryData(@Param("companyWechatId") String companyWechatId,
+                                                               @Param("startDate") String startDate,
+                                                               @Param("endDate") String endDate);
 }

+ 180 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/material/report/ReportController.java

@@ -0,0 +1,180 @@
+package com.gree.mall.manager.controller.material.report;
+
+import com.gree.mall.manager.bean.ExcelData;
+import com.gree.mall.manager.bean.material.report.*;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.helper.ResponseHelper;
+import com.gree.mall.manager.logic.material.report.ReportLogic;
+import com.gree.mall.manager.utils.DateUtils;
+import com.gree.mall.manager.utils.excel.ExcelUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@RestController
+@Api(value = "网点物料报表", tags ={"网点物料报表"} )
+@RequestMapping(value = "/websit/report", produces = "application/json; charset=utf-8")
+public class ReportController {
+
+    @Resource
+    ReportLogic reportLogic;
+
+    @PostMapping("/worker/buy/sum")
+    @ApiOperation(value = "销售单按师傅手机号汇总")
+    public ResponseHelper<List<MaterialSalesSumBean>> workerBuySum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
+            @ApiParam(value = "月份") @RequestParam String month,
+            @ApiParam(value = "工程师手机号") @RequestParam(required = false) String workerMobile,
+            @ApiParam(value = "工程师编号") @RequestParam(required = false) String workerId,
+            @ApiParam(value = "工程师名称") @RequestParam(required = false) String workerName
+    ) throws RemoteServiceException {
+        List<MaterialSalesSumBean> materialSalesSumBeanList = reportLogic.workerBuySum(startTime, endTime, month, websitId, workerMobile,workerId, workerName);
+        return ResponseHelper.success(materialSalesSumBeanList);
+    }
+
+    @PostMapping("/worker/buy/sum/detail")
+    @ApiOperation(value = "根据手机号和时间获取销售单明细")
+    public ResponseHelper<List<MaterialSalesSumDetailBean>> workerBuySumDetail(
+            @ApiParam(value = "门店编号", required = true) @RequestParam String websitId,
+            @ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
+            @ApiParam(value = "月份") @RequestParam(required = false) String month,
+            @ApiParam(value = "工程师手机号", required = true) @RequestParam String workerMobile
+    ) throws RemoteServiceException {
+        List<MaterialSalesSumDetailBean> saleSumDetailBeanList = reportLogic.workerBuySumDetail(startTime, endTime, month, websitId, workerMobile);
+        return ResponseHelper.success(saleSumDetailBeanList);
+    }
+
+    @GetMapping("/export/worker/buy/sum")
+    @ApiOperation(value = "导出汇总按师傅手机号销售额")
+    public void exportSaleSum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
+            @ApiParam(value = "月份") @RequestParam(required = false) String month,
+            @ApiParam(value = "工程师手机号") @RequestParam(required = false) String workerMobile,
+            @ApiParam(value = "工程师编号") @RequestParam(required = false) String workerId,
+            @ApiParam(value = "工程师名称") @RequestParam(required = false) String workerName,
+            HttpServletRequest request, HttpServletResponse response
+    ) throws Exception {
+        List<MaterialSalesSumBean> materialSalesSumBeanList = reportLogic.workerBuySum(startTime, endTime, month, websitId, workerMobile, workerId, workerName);
+        ExcelData excelData = reportLogic.workerBuySumExport(materialSalesSumBeanList);
+        ExcelUtils.exportExcel(request,response,"汇总按师傅手机号销售额" + DateUtils.formatDate1(new Date()) + ".xlsx",excelData);
+    }
+
+    @GetMapping("/export/worker/buy/sum/Detail")
+    @ApiOperation(value = "导出汇总按师傅手机号销售明细")
+    public void exportSaleSumDetail(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
+            @ApiParam(value = "月份") @RequestParam(required = false) String month,
+            @ApiParam(value = "工程师手机号") @RequestParam(required = false) String workerMobile,
+            @ApiParam(value = "工程师编号") @RequestParam(required = false) String workerId,
+            @ApiParam(value = "工程师名称") @RequestParam(required = false) String workerName,
+            HttpServletRequest request, HttpServletResponse response
+    ) throws Exception {
+        List<MaterialSalesSumDetailBean> saleSumDetailBeanList = reportLogic.workerBuySumDetail(startTime, endTime, month, websitId, workerMobile, workerId, workerName);
+        ExcelData excelData = reportLogic.workerBuySumDetailExport(saleSumDetailBeanList);
+        ExcelUtils.exportExcel(request,response,"汇总按师傅手机号销售明细" + DateUtils.formatDate1(new Date()) + ".xlsx",excelData);
+    }
+
+    @GetMapping("/export/sum/buy/detail")
+    @ApiOperation(value = "导出汇总销售明细")
+    public void exportSumSaleDetail(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
+            @ApiParam(value = "月份") @RequestParam(required = false) String month,
+            @ApiParam(value = "工程师手机号") @RequestParam(required = false) String workerMobile,
+            @ApiParam(value = "工程师编号") @RequestParam(required = false) String workerId,
+            @ApiParam(value = "工程师名称") @RequestParam(required = false) String workerName,
+            HttpServletRequest request, HttpServletResponse response
+    ) throws Exception {
+        List<MaterialSalesSumDetailBean> saleSumDetailBeanList = reportLogic.sumBuyDetail(startTime, endTime, month, websitId, workerMobile, workerId, workerName);
+        ExcelData excelData = reportLogic.sumBuyDetailExport(saleSumDetailBeanList);
+        ExcelUtils.exportExcel(request,response,"汇总销售明细" + DateUtils.formatDate1(new Date()) + ".xlsx",excelData);
+    }
+
+    @PostMapping("/purchase-goods-sum")
+    @ApiOperation(value = "采购商品汇总")
+    public ResponseHelper<List<PurchaseDetailBean>> purchaseGoodsSum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "入库开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "入库结束时间") @RequestParam(required = false) String endTime
+    ) {
+        List<PurchaseDetailBean> purchaseDetailBeanList = reportLogic.purchaseGoodsSum(startTime, endTime, websitId, false);
+        return ResponseHelper.success(purchaseDetailBeanList);
+    }
+
+    @GetMapping("/export/purchase-goods-sum")
+    @ApiOperation(value = "导出采购商品汇总")
+    public void exportPurchaseGoodsSum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "入库开始时间") @RequestParam(required = false) String startTime,
+            @ApiParam(value = "入库结束时间") @RequestParam(required = false) String endTime,
+            HttpServletRequest request, HttpServletResponse response
+    ) throws Exception {
+        List<PurchaseDetailBean> purchaseDetailBeanList = reportLogic.purchaseGoodsSum(startTime, endTime, websitId, false);
+        List<PurchaseDetailBean> purchaseDetailSumBeanList = reportLogic.purchaseGoodsSum(startTime, endTime, websitId, true);
+        ExcelData excelData = reportLogic.purchaseGoodsSumExport(purchaseDetailBeanList, purchaseDetailSumBeanList);
+        ExcelUtils.exportExcel(request,response,"采购商品汇总" + DateUtils.formatDate1(new Date()) + ".xlsx",excelData);
+    }
+
+    @PostMapping("/purchase-category-sum")
+    @ApiOperation(value = "月度网点采购类别")
+    public ResponseHelper<List<PurchaseCategoryBean>> purchaseCategorySum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "采购月度") @RequestParam String month
+    ) throws Exception {
+        List<PurchaseCategoryBean> purchaseCategoryBeanList = reportLogic.purchaseCategorySum(websitId, month);
+        return ResponseHelper.success(purchaseCategoryBeanList);
+    }
+
+    @GetMapping("/export/purchase-category-sum")
+    @ApiOperation(value = "导出月度网点采购类别")
+    public void exportSaleSumDetail(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "采购月度") @RequestParam String month,
+            HttpServletRequest request, HttpServletResponse response
+    ) throws Exception {
+        List<PurchaseCategoryBean> purchaseCategoryBeanList = reportLogic.purchaseCategorySum(websitId, month);
+        ExcelData excelData = reportLogic.purchaseCategorySumExport(purchaseCategoryBeanList);
+        ExcelUtils.exportExcel(request,response,"月度网点采购类别" + DateUtils.formatDate1(new Date()) + ".xlsx", excelData);
+    }
+
+    @PostMapping("/worker-purchase-category-sum")
+    @ApiOperation(value = "月度师傅采购类别")
+    public ResponseHelper<List<WorkerPurchaseCategoryBean>> workerPurchaseCategorySum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String websitId,
+            @ApiParam(value = "采购月度") @RequestParam String month
+    ) throws Exception {
+        List<WorkerPurchaseCategoryBean> workerPurchaseCategoryBeanList = reportLogic.workerPurchaseCategorySum(websitId, month);
+        return ResponseHelper.success(workerPurchaseCategoryBeanList);
+    }
+
+    @GetMapping("/export/worker-purchase-category-sum")
+    @ApiOperation(value = "导出月度师傅采购类别")
+    public void exportWorkerPurchaseCategorySum(
+            @ApiParam(value = "门店编号") @RequestParam(required = false) String shopId,
+            @ApiParam(value = "采购月度") @RequestParam String month,
+            HttpServletRequest request, HttpServletResponse response
+    ) throws Exception {
+        List<WorkerPurchaseCategoryBean> workerPurchaseCategoryBeanList = reportLogic.workerPurchaseCategorySum(shopId, month);
+        ExcelData excelData = reportLogic.workerPurchaseCategorySumExport(workerPurchaseCategoryBeanList);
+        ExcelUtils.exportExcel(request,response,"月度师傅采购类别" + DateUtils.formatDate1(new Date()) + ".xlsx", excelData);
+    }
+
+
+}

+ 7 - 7
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/manage/WebsitPartsNewInLogic.java

@@ -136,19 +136,19 @@ public class WebsitPartsNewInLogic {
             String receiveUnitArea = (String) row.get(21);
             String repairCustomNo = (String) row.get(22);
             if (StringUtils.isBlank(objectType) || !"新件申领".contains(objectType)) {
-                throw new RemoteServiceException("第" + (i+2) + "行,事物类型格式不符,只能是“新件申领”");
+                throw new RemoteServiceException("第" + (i + 2) + "行,事物类型格式不符,只能是“新件申领”");
             }
             if (StringUtils.isBlank(voucherNo)) {
-                throw new RemoteServiceException("第" + (i+2) + "行,凭证号不能为空");
+                throw new RemoteServiceException("第" + (i + 2) + "行,凭证号不能为空");
             }
             if (StringUtils.isBlank(partsNumber)) {
-                throw new RemoteServiceException("第" + (i+2) + "行,配件编码不能为空");
+                throw new RemoteServiceException("第" + (i + 2) + "行,配件编码不能为空");
             }
             if (StringUtils.isBlank(receiveUnit) || receiveUnit.indexOf(":") <= 0) {
-                throw new RemoteServiceException("第" + (i+2) + "行,领入单位格式不符");
+                throw new RemoteServiceException("第" + (i + 2) + "行,领入单位格式不符");
             }
             if (StringUtils.isBlank(orderDateStr) || !ReUtil.isMatch("^\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{1,2}:\\d{1,2}:\\d{1,2}", orderDateStr)) {
-                throw new RemoteServiceException("第" + (i+1) + "行,开单日期格式不符");
+                throw new RemoteServiceException("第" + (i + 1) + "行,开单日期格式不符");
             }
             String receiveUnitNumber = receiveUnit.split(":")[0];
             AdminWebsit receiveShop = websitMap.get(receiveUnitNumber);
@@ -158,10 +158,10 @@ public class WebsitPartsNewInLogic {
                 continue;
             }
             if (Objects.isNull(parts)) {
-                throw new RemoteServiceException("第" + (i+2) + "行,配件编码未配置");
+                throw new RemoteServiceException("第" + (i + 2) + "行,配件编码未配置");
             }
             if (StringUtils.isBlank(sysNo)) {
-                throw new RemoteServiceException("第" + (i+2) + "行,系统序号不能为空");
+                throw new RemoteServiceException("第" + (i + 2) + "行,系统序号不能为空");
             }
             final Storage storage = storageMap.get(receiveShop.getWebsitId());
 

+ 3 - 1
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/manage/WebsitSalesLogic.java

@@ -331,7 +331,9 @@ public class WebsitSalesLogic {
             }
 
             item.setConvertQty(convertQty)
-                    .setConvertPrice(convertPrice);
+                    .setConvertPrice(convertPrice)
+                    .setCost(websitStock.getLastCost())
+                    .setCostValue(item.getCost().multiply(item.getSalesQty()));
             // 检查数量是否大于当前库存数
 //            final List<WebsitStock> websitStocks = websitStockService.lambdaQuery()
 //                    .eq(WebsitStock::getCompanyWechatId, sales.getCompanyWechatId())

+ 558 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/report/ReportLogic.java

@@ -0,0 +1,558 @@
+package com.gree.mall.manager.logic.material.report;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.gree.mall.manager.bean.ExcelData;
+import com.gree.mall.manager.bean.admin.AdminUserCom;
+import com.gree.mall.manager.bean.material.report.*;
+import com.gree.mall.manager.commonmapper.MaterialMapper;
+import com.gree.mall.manager.enums.IsYesNoEnum;
+import com.gree.mall.manager.enums.base.BaseEnum;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.plus.entity.AdminModule;
+import com.gree.mall.manager.plus.entity.AdminUserModuleRela;
+import com.gree.mall.manager.plus.service.AdminModuleService;
+import com.gree.mall.manager.plus.service.AdminUserModuleRelaService;
+import com.gree.mall.manager.utils.DateUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class ReportLogic {
+
+    private final CommonLogic commonLogic;
+    private final MaterialMapper materialMapper;
+    private final AdminModuleService adminModuleService;
+    private final AdminUserModuleRelaService adminUserModuleRelaService;
+
+
+    public List<MaterialSalesSumBean> workerBuySum(String startTime, String endTime, String month, String websitId,
+                                                   String workerMobile, String workerId, String workerName) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        if (StringUtils.isNotBlank(month)) {
+            String[] monthDateTime = computeMonthDateTime(month);
+            startTime = monthDateTime[0];
+            endTime = monthDateTime[1];
+        }
+        return materialMapper.workerBuySum(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
+            Date startMonth = DateUtils.getStartMonth();
+            return DateUtils.formatDate(startMonth);
+        }), Optional.ofNullable(endTime).orElseGet(() -> {
+            Date endMonth = DateUtils.getEndMonth();
+            return DateUtils.formatDate(endMonth);
+        }), websits, websitId, workerMobile, workerId, workerName);
+    }
+
+    private String[] computeMonthDateTime(String month) throws RemoteServiceException {
+        try {
+            String startDate = String.format("%s-01 00:00:00", month);
+            Date date = DateUtils.parseDate(startDate);
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(date);
+            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
+            String endDate = DateUtils.formatDate1(cal.getTime()) + " 23:59:59";
+            return new String[] { startDate, endDate };
+        } catch (ParseException e) {
+            log.error("computeMonthDateTime() 月份转换出错", e);
+            throw new RemoteServiceException("月份转换出错");
+        }
+    }
+
+    public List<MaterialSalesSumDetailBean> workerBuySumDetail(String startTime, String endTime, String month,
+                                                               String websitId, String workerMobile) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        if (StringUtils.isNotBlank(month)) {
+            String[] monthDateTime = computeMonthDateTime(month);
+            startTime = monthDateTime[0];
+            endTime = monthDateTime[1];
+        }
+        return materialMapper.workerBuyDetail(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
+            Date startMonth = DateUtils.getStartMonth();
+            return DateUtils.formatDate(startMonth);
+        }), Optional.ofNullable(endTime).orElseGet(() -> {
+            Date endMonth = DateUtils.getEndMonth();
+            return DateUtils.formatDate(endMonth);
+        }), websits, websitId, workerMobile);
+    }
+
+    public ExcelData workerBuySumExport(List<MaterialSalesSumBean> beanList) {
+        String[] titles = new String[]{"网点编码", "网点名称","工程师手机","工程师编号","工程师名称", "合计销售金额",
+                "现金销售金额", "通联销售金额", "现金支付次数", "通联次数", "退货金额"};
+        List<List<Object>> rows = new ArrayList<>();
+        for (MaterialSalesSumBean bean : beanList) {
+            List<Object> row = new ArrayList<>();
+            row.add(bean.getWebsitId());
+            row.add(bean.getWebsitName());
+            row.add(bean.getWorkerMobile());
+            row.add(bean.getWorkerId());
+            row.add(bean.getWorkerName());
+            row.add(bean.getTotalSaleValue());
+            row.add(bean.getCashSaleValue());
+            row.add(bean.getAllinpaySaleValue());
+            row.add(bean.getCash());
+            row.add(bean.getAllinpay());
+            row.add(bean.getRetValue());
+            rows.add(row);
+        }
+        ExcelData excelData = new ExcelData();
+        excelData.setRows(rows);
+        excelData.setTitles(Arrays.asList(titles));
+        return excelData;
+    }
+
+    public List<MaterialSalesSumDetailBean> workerBuySumDetail(String startTime, String endTime, String month,
+                                                               String websitId, String workerMobile, String workerId,
+                                                               String workerName) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        if (StringUtils.isNotBlank(month)) {
+            String[] monthDateTime = computeMonthDateTime(month);
+            startTime = monthDateTime[0];
+            endTime = monthDateTime[1];
+        }
+        return materialMapper.workerBuySumDetail(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
+            Date startMonth = DateUtils.getStartMonth();
+            return DateUtils.formatDate(startMonth);
+        }), Optional.ofNullable(endTime).orElseGet(() -> {
+            Date endMonth = DateUtils.getEndMonth();
+            return DateUtils.formatDate(endMonth);
+        }), websits, websitId, workerMobile, workerId, workerName);
+    }
+
+    public ExcelData workerBuySumDetailExport(List<MaterialSalesSumDetailBean> beanList) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        ExcelData excelData = new ExcelData();
+        if (Objects.isNull(beanList) || beanList.size() == 0) {
+            excelData.setName("数据为空");
+            return excelData;
+        }
+        String[] titles = new String[]{"网点编码","网点名称", "支付状态", "工程师手机","工程师编号","工程师名称",
+                "商品名称", "类别名称", "销售数量", "总销售额", "总进价额", "单位转换系数", "转换数"};
+        List<List<Object>> rows = new ArrayList<>();
+        String curWebsitId = beanList.get(0).getWebsitId();
+        String curWebsitName = beanList.get(0).getWebsitName();
+        String curPayFlag = BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, beanList.get(0).getPayFlag()).getRemark();
+        String curMobile = beanList.get(0).getWorkerMobile();
+        String curWorkerId = beanList.get(0).getWorkerId();
+        String curWorkerName = beanList.get(0).getWorkerName();
+        BigDecimal curSumSalesQty = new BigDecimal(0);
+        BigDecimal curSumSalesValue = new BigDecimal(0);
+        BigDecimal curSumCostValue = new BigDecimal(0);
+        for (MaterialSalesSumDetailBean item : beanList) {
+            // 如果当前遍历手机和上一次遍历不一致 插入合计行
+            if (!curMobile.equals(item.getWorkerMobile())) {
+                rows.add(addBuySumRow(curWebsitId, curWebsitName, curPayFlag, curMobile, curWorkerId, curWorkerName, curSumSalesQty, curSumSalesValue, curSumCostValue));
+                curWebsitId = item.getWebsitId();
+                curWebsitName = item.getWebsitName();
+                curPayFlag = BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, item.getPayFlag()).getRemark();
+                curMobile = item.getWorkerMobile();
+                curWorkerId = item.getWorkerId();
+                curWorkerName = item.getWorkerName();
+                curSumSalesQty = new BigDecimal(0);
+                curSumSalesValue = new BigDecimal(0);
+                curSumCostValue = new BigDecimal(0);
+            }
+            List<Object> row = new ArrayList<>();
+            row.add(item.getWebsitId());
+            row.add(item.getWebsitName());
+            row.add(BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, item.getPayFlag()).getRemark());
+            row.add(item.getWorkerMobile());
+            row.add(item.getWorkerId());
+            row.add(item.getWorkerName());
+            row.add(item.getGoodsName());
+            row.add(item.getGoodsCategoryName());
+            row.add(item.getSalesQty());
+            row.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+            if (!adminUser.getType().equals(0) || this.checkIsExistsRole(adminUser)) {
+//                row.add(item.getCost());
+                row.add(item.getCostValue());
+                curSumCostValue = curSumCostValue.add(item.getCostValue());
+            } else {
+//                row.add(new BigDecimal("0"));
+                row.add(new BigDecimal("0"));
+            }
+            row.add(item.getGoodsSalesConvertQty());
+            row.add(item.getConvertQty());
+
+            rows.add(row);
+            curSumSalesQty = curSumSalesQty.add(item.getSalesQty());
+            curSumSalesValue = curSumSalesValue.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+        }
+
+        rows.add(addBuySumRow(curWebsitId, curWebsitName, curPayFlag, curMobile, curWorkerId, curWorkerName, curSumSalesQty, curSumSalesValue, curSumCostValue));
+
+        excelData.setRows(rows);
+        excelData.setTitles(Arrays.asList(titles));
+        return excelData;
+    }
+
+    /**
+     * 返回销售汇总合计行
+     */
+    private List<Object> addBuySumRow(String curWebsitId, String curWebsitName, String curPayFlag, String curMobile,
+                                      String curWorkerId, String curWorkerName,
+                                      BigDecimal curSumSaleQty, BigDecimal curSumSaleValue, BigDecimal curSumCostValue) {
+        List<Object> sumRow = new ArrayList();
+        sumRow.add(curWebsitId);
+        sumRow.add(curWebsitName);
+        sumRow.add(curPayFlag);
+        sumRow.add(curMobile);
+        sumRow.add(curWorkerId);
+        sumRow.add(curWorkerName);
+        sumRow.add("");
+        sumRow.add("小计:");
+        sumRow.add(curSumSaleQty.setScale(2, BigDecimal.ROUND_HALF_UP));
+        sumRow.add(curSumSaleValue.setScale(2, BigDecimal.ROUND_HALF_UP));
+        sumRow.add(curSumCostValue.setScale(2, BigDecimal.ROUND_HALF_UP));
+        return sumRow;
+    }
+
+    /**
+     * 导出汇总销售明细
+     * @param startTime
+     * @param endTime
+     * @param month
+     * @param websitId
+     * @param workerMobile
+     * @param workerId
+     * @param workerName
+     * @return
+     */
+    public List<MaterialSalesSumDetailBean> sumBuyDetail(String startTime, String endTime, String month, String websitId, String workerMobile, String workerId, String workerName) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        if (StringUtils.isNotBlank(month)) {
+            String[] monthDateTime = computeMonthDateTime(month);
+            startTime = monthDateTime[0];
+            endTime = monthDateTime[1];
+        }
+        return materialMapper.sumBuyDetail(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
+            Date startMonth = DateUtils.getStartMonth();
+            return DateUtils.formatDate(startMonth);
+        }), Optional.ofNullable(endTime).orElseGet(() -> {
+            Date endMonth = DateUtils.getEndMonth();
+            return DateUtils.formatDate(endMonth);
+        }), websits, websitId, workerMobile, workerId, workerName);
+    }
+
+    public ExcelData sumBuyDetailExport(List<MaterialSalesSumDetailBean> beanList) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        String[] titles = new String[]{"网点编码","网点名称", "支付状态", "商品名称", "类别名称", "规格",
+                "销售数量", "总销售额", "总进价额", "销售利润", "单位转换系数", "转换数"};
+        List<List<Object>> rows = new ArrayList<>();
+        BigDecimal sumSaleQty = new BigDecimal(0);
+        BigDecimal sumSaleValue = new BigDecimal(0);
+        BigDecimal sumCostValue = new BigDecimal(0);
+        BigDecimal sumProfitValue = new BigDecimal(0);
+        for (MaterialSalesSumDetailBean item : beanList) {
+            List<Object> row = new ArrayList<>();
+            row.add(item.getWebsitId());
+            row.add(item.getWebsitName());
+            row.add(BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, item.getPayFlag()).getRemark());
+            row.add(item.getGoodsName());
+            row.add(item.getGoodsCategoryName());
+            row.add(item.getGoodsSpecification());
+            row.add(item.getSalesQty());
+            row.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+            if (!adminUser.getType().equals(0) || this.checkIsExistsRole(adminUser)) {
+                row.add(item.getCostValue());
+                row.add(item.getSaleAmount().subtract(item.getCostValue()));
+                sumCostValue = sumCostValue.add(item.getCostValue());
+                sumProfitValue = sumProfitValue.add(item.getSaleAmount().subtract(item.getCostValue()));
+            } else {
+                row.add(new BigDecimal("0"));
+                row.add(new BigDecimal("0"));
+                sumProfitValue = sumProfitValue.add(new BigDecimal("0"));
+            }
+            row.add(item.getGoodsSalesConvertQty());
+            row.add(item.getConvertQty());
+
+            rows.add(row);
+            sumSaleQty = sumSaleQty.add(item.getSalesQty());
+            sumSaleValue = sumSaleValue.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+        }
+        List<Object> row = new ArrayList();
+        row.add("");
+        row.add("");
+        row.add("");
+        row.add("");
+        row.add("");
+        row.add("");
+        row.add("");
+        row.add("合计:");
+        row.add(sumSaleQty);
+        row.add(sumSaleValue);
+        row.add(sumCostValue);
+        row.add(sumProfitValue);
+        rows.add(row);
+        ExcelData excelData = new ExcelData();
+        excelData.setRows(rows);
+        excelData.setTitles(Arrays.asList(titles));
+        return excelData;
+    }
+
+    private boolean checkIsExistsRole(AdminUserCom adminUser) {
+        final AdminModule module = adminModuleService.lambdaQuery()
+                .eq(AdminModule::getCode, "query-cost")
+                .one();
+        if (Objects.isNull(module)) {
+            return false;
+        }
+        return adminUserModuleRelaService.lambdaQuery()
+                .eq(AdminUserModuleRela::getAdminRoleId, adminUser.getRoleId())
+                .eq(AdminUserModuleRela::getAdminModuleId, module.getModuleId())
+                .count() > 0;
+    }
+
+    /**
+     * 采购商品汇总
+     * @param startTime
+     * @param endTime
+     * @param websitId
+     * @param isSum
+     * @return
+     */
+    public List<PurchaseDetailBean> purchaseGoodsSum(String startTime, String endTime, String websitId, boolean isSum) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        return materialMapper.purchaseGoodsSum(adminUser.getCompanyWechatId(), startTime, endTime, websits, websitId, isSum);
+    }
+
+    public ExcelData purchaseGoodsSumExport(List<PurchaseDetailBean> purchaseDetailBeanList, List<PurchaseDetailBean> purchaseDetailSumBeanList) {
+        String[] titles = new String[]{"网点编码","网点名称","供应商名称","商品名称","类别名称"
+                , "验收数量", "验收赠品数量", "验收金额"};
+        List<List<Object>> rows = new ArrayList<>();
+        if (CollectionUtil.isEmpty(purchaseDetailBeanList)) {
+            ExcelData excelData = new ExcelData();
+            excelData.setTitles(Collections.singletonList("暂无内容"));
+            return excelData;
+        }
+        String curShopId = purchaseDetailBeanList.get(0).getWebsitid();
+
+        for (PurchaseDetailBean bean : purchaseDetailBeanList) {
+            // 如果当前遍历网点编号和上一次遍历不一致 插入合计行
+            if (!curShopId.equals(bean.getWebsitid())) {
+                rows.add(addPurchaseSumRow(curShopId, purchaseDetailSumBeanList));
+                curShopId = bean.getWebsitid();
+            }
+            List<Object> row = new ArrayList<>();
+            row.add(bean.getWebsitid());
+            row.add(bean.getWebsitName());
+            row.add(bean.getVenderName());
+            row.add(bean.getGoodsName());
+            row.add(bean.getGoodsCategoryName());
+//            row.add(bean.getPurchaseQty());
+            row.add(bean.getRecQty());
+            row.add(bean.getRecGiftQty());
+            row.add(bean.getCostValue());
+            rows.add(row);
+        }
+        rows.add(addPurchaseSumRow(curShopId, purchaseDetailSumBeanList));
+        ExcelData excelData = new ExcelData();
+        excelData.setRows(rows);
+        excelData.setTitles(Arrays.asList(titles));
+        return excelData;
+    }
+
+    private List<Object> addPurchaseSumRow(String curShopId, List<PurchaseDetailBean> purchaseDetailSumBeanList) {
+        List<Object> sumRow = new ArrayList();
+        PurchaseDetailBean bean = purchaseDetailSumBeanList.stream()
+                .filter(purchaseDetailBean -> purchaseDetailBean.getWebsitid().equals(curShopId))
+                .collect(Collectors.toList()).get(0);
+        sumRow.add(bean.getWebsitid());
+        sumRow.add(bean.getWebsitName());
+        sumRow.add("");
+        sumRow.add("");
+        sumRow.add(bean.getGoodsCategoryName());
+//        sumRow.add(bean.getPurchaseQty());
+        sumRow.add(bean.getRecQty());
+        sumRow.add(bean.getRecGiftQty());
+        sumRow.add(bean.getCostValue());
+        return sumRow;
+    }
+
+    /**
+     * 月度辅材采购类别
+     * @param websitId
+     * @param month
+     * @return
+     */
+    public List<PurchaseCategoryBean> purchaseCategorySum(String websitId, String month) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        String[] monthDateTime = computeMonthDateTime(month);
+        String startDate = monthDateTime[0];
+        String endDate = monthDateTime[1];
+        // 查询网点采购汇总数据
+        List<PurchaseCategoryBean> websitePurchaseSumList = materialMapper.getMonthSummaryData(adminUser.getCompanyWechatId(), websits, websitId, startDate, endDate);
+
+        // 查询网点上个月结存金额
+        List<WebsiteStockValSumBean> websiteStockValSumList = materialMapper.getLastMonthStockSumVal(adminUser.getCompanyWechatId(), websits, websitId, startDate);
+
+        Map<String, PurchaseCategoryBean> websitePurchaseSumMap = websitePurchaseSumList.stream()
+                .collect(Collectors.toMap(PurchaseCategoryBean::getWebsitId, Function.identity()));
+
+        // 网点采购汇总数据注入上个月结存金额
+        websiteStockValSumList.forEach(obj -> {
+            PurchaseCategoryBean websitePurchaseSum = websitePurchaseSumMap.get(obj.getWebsitId());
+            if (Objects.nonNull(websitePurchaseSum)) {
+                websitePurchaseSum.setLastMonthVal(obj.getLastMonthVal());
+            }
+        });
+
+        websitePurchaseSumList = new ArrayList<>(websitePurchaseSumMap.values());
+
+        return websitePurchaseSumList;
+    }
+
+    public ExcelData purchaseCategorySumExport(List<PurchaseCategoryBean> purchaseCategoryBeanList) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        String[] titles = new String[]{"年月","辅材网点编号","辅材网点名称","铜管(公斤)","铜管总价","保温棉(条)","保温棉总价"
+                ,"电缆(米)","电缆总价","支架(付)","支架总价","冷媒(罐)","冷媒总价","开关","开关总价"
+                ,"包扎带","包扎带总价","连接器","连接器总价","双壁热缩套管","双壁热缩套管总价","清洗工具","清洗工具总价","管槽","管槽总价"
+                ,"热水器","热水器总价","总采购金额","上月库存金额"};
+        List<List<Object>> rows = new ArrayList<>();
+        for (PurchaseCategoryBean bean : purchaseCategoryBeanList) {
+            List<Object> row = new ArrayList<>();
+            row.add(bean.getYearMonth());
+            row.add(bean.getWebsitId());
+            row.add(bean.getWebsitName());
+            row.add(bean.getTgQty());
+            row.add(bean.getTgVal());
+            row.add(bean.getBwmQty());
+            row.add(bean.getBwmVal());
+            row.add(bean.getDlQty());
+            row.add(bean.getDlVal());
+            row.add(bean.getZjQty());
+            row.add(bean.getZjVal());
+            row.add(bean.getLmQty());
+            row.add(bean.getLmVal());
+            row.add(bean.getKgQty());
+            row.add(bean.getKgVal());
+            row.add(bean.getBzdQty());
+            row.add(bean.getBzdVal());
+            row.add(bean.getLjqQty());
+            row.add(bean.getLjqVal());
+            row.add(bean.getRsgQty());
+            row.add(bean.getRsgVal());
+            row.add(bean.getQxggQty());
+            row.add(bean.getQxggVal());
+            row.add(bean.getGcQty());
+            row.add(bean.getGcVal());
+            row.add(bean.getYsqQty());
+            row.add(bean.getYsqVal());
+            row.add(bean.getTgVal().add(bean.getBwmVal()).add(bean.getDlVal()).add(bean.getZjVal())
+                    .add(bean.getLmVal()).add(bean.getKgVal()).add(bean.getBzdVal()).add(bean.getLjqVal())
+                    .add(bean.getRsgVal()).add(bean.getQxggVal()).add(bean.getGcVal()));
+            row.add(bean.getLastMonthVal());
+            rows.add(row);
+        }
+        ExcelData excelData = new ExcelData();
+        excelData.setRows(rows);
+        excelData.setTitles(Arrays.asList(titles));
+        return excelData;
+    }
+
+    public List<WorkerPurchaseCategoryBean> workerPurchaseCategorySum(String websitId, String month) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<String> websits = adminUser.getAdminWebsitIds();
+        if (CollectionUtil.isEmpty(websits)
+                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
+            return new ArrayList<>();
+        }
+        String[] monthDateTime = computeMonthDateTime(month);
+        String startDate = monthDateTime[0];
+        String endDate = monthDateTime[1];
+        List<WorkerPurchaseCategoryBean> monthSummaryData = materialMapper.getWorkerMonthSummaryData(adminUser.getCompanyWechatId(), startDate, endDate);
+
+        return monthSummaryData;
+    }
+
+    public ExcelData workerPurchaseCategorySumExport(List<WorkerPurchaseCategoryBean> workerPurchaseCategoryBeanList) {
+        String[] titles = new String[]{"年月","网点编号","网点名称","师傅编号", "师傅名称","铜管(公斤)","铜管(米)","铜管总价"
+                ,"保温棉(条)","保温棉总价","电缆(米)","电缆总价","支架(付)","支架总价","冷媒(罐)","冷媒总价","开关","开关总价","包扎带"
+                ,"包扎带总价","连接器","连接器总价","双壁热缩套管","双壁热缩套管总价","清洗工具","清洗工具总价","管槽","管槽总价","热水器"
+                ,"热水器总价","总采购金额"
+                ,"师傅当月剩余库存金额"};
+        List<List<Object>> rows = new ArrayList<>();
+        for (WorkerPurchaseCategoryBean bean : workerPurchaseCategoryBeanList) {
+            List<Object> row = new ArrayList<>();
+            row.add(bean.getYearMonth());
+            row.add(bean.getWebsitId());
+            row.add(bean.getWebsiteName());
+            row.add(bean.getWorkerId());
+            row.add(bean.getWorkerName());
+            row.add(bean.getTgQty());
+            row.add(bean.getTgConvertQty());
+            row.add(bean.getTgVal());
+            row.add(bean.getBwmQty());
+            row.add(bean.getBwmVal());
+            row.add(bean.getDlQty());
+            row.add(bean.getDlVal());
+            row.add(bean.getZjQty());
+            row.add(bean.getZjVal());
+            row.add(bean.getLmQty());
+            row.add(bean.getLmVal());
+            row.add(bean.getKgQty());
+            row.add(bean.getKgVal());
+            row.add(bean.getBzdQty());
+            row.add(bean.getBzdVal());
+            row.add(bean.getLjqQty());
+            row.add(bean.getLjqVal());
+            row.add(bean.getRsgQty());
+            row.add(bean.getRsgVal());
+            row.add(bean.getQxggQty());
+            row.add(bean.getQxggVal());
+            row.add(bean.getGcQty());
+            row.add(bean.getGcVal());
+            row.add(bean.getYsqQty());
+            row.add(bean.getYsqVal());
+            row.add(bean.getTgVal().add(bean.getBwmVal()).add(bean.getDlVal()).add(bean.getZjVal()).add(bean.getLmVal())
+                    .add(bean.getWjVal()).add(bean.getJtVal()).add(bean.getKgVal()).add(bean.getBzdVal())
+                    .add(bean.getLjqVal()).add(bean.getRsgVal())
+                    .add(bean.getQxggVal()).add(bean.getGcVal()).add(bean.getYsqVal()));
+            row.add(bean.getWorkerGoodsPrice());
+            rows.add(row);
+        }
+        ExcelData excelData = new ExcelData();
+        excelData.setRows(rows);
+        excelData.setTitles(Arrays.asList(titles));
+        return excelData;
+    }
+}

+ 696 - 0
mall-server-api/src/main/resources/mapper/MaterialMapper.xml

@@ -765,4 +765,700 @@
         </if>
         ${ex.orderBy}
     </select>
+
+    <select id="workerBuySum" resultType="com.gree.mall.manager.bean.material.report.MaterialSalesSumBean">
+        SELECT
+            t2.websit_id,
+            t2.name AS websit_name,
+            t1.worker_mobile,
+            t1.worker_id,
+            t1.worker_name,
+            IFNULL(SUM( t1.totalSaleValue ) - SUM( t1.retValue ), 0) AS totalSaleValue,
+            IFNULL(SUM( t1.cash ), 0) AS cash,
+            IFNULL(SUM( t1.cashSaleValue ), 0) AS cashSaleValue,
+            IFNULL(SUM( t1.allinpaySaleValue ), 0) AS allinpaySaleValue,
+            IFNULL(SUM( t1.retValue ), 0) AS retValue
+        FROM
+        (
+            SELECT
+                a.websit_id,
+                a.worker_mobile,
+                a.worker_id,
+                a.worker_name,
+                a.websit_name,
+                COUNT(DISTINCT a.sales_id, IF ( a.pay_type = 'CASH', 1, NULL )) AS cash,
+                COUNT(DISTINCT a.sales_id, IF( a.pay_type = 'ALLINPAY', 1, NULL )) AS allinpay,
+                SUM( a.sales_qty * a.price ) AS totalSaleValue,
+                SUM(IF( a.pay_type = 'CASH', a.sales_qty * a.price, 0 )) AS cashSaleValue,
+                SUM(IF( a.pay_type = 'ALLINPAY', a.sales_qty * a.price, 0 )) AS allinpaySaleValue,
+                0 AS retValue
+            FROM
+            (
+                SELECT
+                    t1.sales_id,
+                    t1.websit_id,
+                    t1.websit_name,
+                    t1.worker_mobile,
+                    t1.worker_id,
+                    t1.worker_name,
+                    t1.pay_type,
+                    t2.goods_id,
+                    t2.sales_qty,
+                    t2.price
+                FROM
+                    websit_sales t1,
+                    websit_sales_item t2
+                WHERE
+                    t1.sales_id = t2.sales_id
+                    AND t1.company_wechat_id = #{companyWechatId}
+                    AND t1.buy_people = 'WORKER'
+                    AND t1.flag = 'PAY_TAKE'
+                    <if test="websitId != null and websitId != ''">
+                        AND t1.websit_id = #{websitId}
+                    </if>
+                    <if test="workerMobile != null and workerMobile != ''">
+                        AND t1.worker_mobile = #{workerMobile}
+                    </if>
+                    <if test="workerId != null and workerId != ''">
+                        AND t1.worker_id LIKE CONCAT('%', #{workerId},'%')
+                    </if>
+                    <if test="workerName != null and workerName != ''">
+                        AND t1.worker_name LIKE CONCAT('%', #{workerName},'%')
+                    </if>
+                    <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                        AND t1.confirm_time BETWEEN #{startTime} AND #{endTime}
+                    </if>
+                    <if test="websitId == null and websits != null and websits.size > 0">
+                        AND t1.websit_id IN
+                        <foreach item="item" index="index" collection="websits" open="(" separator=","
+                                 close=")">
+                            #{item}
+                        </foreach>
+                    </if>
+            ) a
+            GROUP BY
+            1,
+            2,
+            3
+        UNION ALL
+            SELECT
+                a.websit_id,
+                a.worker_mobile,
+                a.worker_id,
+                a.worker_name,
+                a.websit_name,
+                0 AS cash,
+                0 AS allinpay,
+                0 AS totalSaleValue,
+                0 AS cashSaleValue,
+                0 AS allinpaySaleValue,
+                SUM( a.ret_qty * a.price ) AS retValue
+            FROM
+               (
+                SELECT
+                    t1.sales_ret_id,
+                    t1.websit_id,
+                    t1.worker_mobile,
+                    t1.worker_id,
+                    t1.worker_name,
+                    t1.websit_name,
+                    t2.goods_id,
+                    t2.ret_qty,
+                    t2.price
+                FROM
+                    websit_sales_ret t1,
+                    websit_sales_ret_item t2
+                WHERE
+                    t1.sales_ret_id = t2.sales_ret_id
+                    AND t1.company_wechat_id = #{companyWechatId}
+                    AND t1.confirm_by IS NOT NULL
+                    <if test="websitId != null and websitId != ''">
+                        AND t1.websit_id = #{websitId}
+                    </if>
+                    <if test="workerMobile != null and workerMobile != ''">
+                        AND t1.worker_mobile = #{workerMobile}
+                    </if>
+                    <if test="workerId != null and workerId != ''">
+                        AND t1.worker_id LIKE CONCAT('%', #{workerId},'%')
+                    </if>
+                    <if test="workerName != null and workerName != ''">
+                        AND t1.worker_name LIKE CONCAT('%', #{workerName},'%')
+                    </if>
+                    <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                        AND t1.confirm_time BETWEEN #{startTime} AND #{endTime}
+                    </if>
+                    <if test="websitId == null and websits != null and websits.size > 0">
+                        AND t1.websit_id IN
+                        <foreach item="item" index="index" collection="shops" open="(" separator=","
+                                 close=")">
+                            #{item}
+                        </foreach>
+                    </if>
+            ) a
+            GROUP BY
+            1,
+            2,
+            3
+        ) t1
+        LEFT JOIN admin_websit t2 ON t1.websit_id = t2.websit_id
+        GROUP BY
+        t1.websit_id,
+        t1.worker_mobile,
+        t1.worker_id
+    </select>
+
+    <select id="workerBuyDetail"
+            resultType="com.gree.mall.manager.bean.material.report.MaterialSalesSumDetailBean">
+        SELECT
+            t1.websit_id,
+            t1.websit_name,
+            t1.pay_type,
+            t1.worker_mobile,
+            t1.worker_id,
+            t1.worker_name,
+            t1.pay_time,
+            t1.sales_id,
+            t1.goods_id,
+            t1.goods_name,
+            t1.sales_qty,
+            t1.price,
+            t1.sale_amount,
+            t1.cost,
+            t1.cost_value
+        FROM
+        (
+            SELECT
+                t1.websit_id,
+                t1.websit_name,
+                t1.pay_type,
+                t1.worker_mobile,
+                t1.worker_id,
+                t1.worker_name,
+                t1.pay_time,
+                t2.sales_id,
+                t2.goods_id,
+                t2.goods_name,
+                t2.sales_qty,
+                t2.price,
+                t2.sale_amount,
+                t2.cost,
+                t2.cost_value
+            FROM
+                websit_sales t1 INNER JOIN websit_sales_item t2 ON t1.sales_id = t2.sales_id
+            WHERE
+                t1.company_wechat_id = #{companyWechatId}
+                AND t1.buy_people = 'WORKER'
+                AND t1.flag = 'PAY_TAKE'
+                <if test="websitId != null and websitId != ''">
+                    AND t1.websit_id = #{websitId}
+                </if>
+                <if test="workerMobile != null and workerMobile != ''">
+                    AND t1.worker_mobile = #{workerMobile}
+                </if>
+                <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                    AND t1.confirm_time BETWEEN #{startTime} AND #{endTime}
+                </if>
+                <if test="websitId == null and websits != null and websits.size > 0">
+                    AND t1.websit_id IN
+                    <foreach item="item" index="index" collection="websits" open="(" separator=","
+                             close=")">
+                        #{item}
+                    </foreach>
+                </if>
+        ) t1 LEFT JOIN admin_websit t2 ON t1.websit_id = t2.websit_id
+        ORDER BY
+        t1.sales_id
+    </select>
+    <select id="workerBuySumDetail"
+            resultType="com.gree.mall.manager.bean.material.report.MaterialSalesSumDetailBean">
+        SELECT
+        t1.websit_id,
+        t1.websit_name,
+        t1.pay_flag,
+        t1.worker_mobile,
+        t1.worker_id,
+        t1.worker_name,
+        t1.goods_id,
+        t1.goods_name,
+        t1.goods_sales_convert_qty,
+        t1.goods_category_name,
+        SUM(t1.sales_qty) as sales_qty,
+        t1.price,
+        SUM(t1.sale_amount) as sale_amount,
+        t1.cost as cost,
+        SUM(t1.cost_value) as cost_value,
+        SUM(t1.convert_qty) as convert_qty
+        FROM
+        (
+            SELECT
+                t1.websit_id,
+                t1.websit_name,
+                t1.pay_flag,
+                t1.worker_mobile,
+                t1.worker_id,
+                t1.worker_name,
+                t2.goods_id,
+                t2.goods_name,
+                t2.sales_qty,
+                t2.price,
+                t2.sale_amount,
+                t2.cost,
+                t2.cost_value,
+                t2.goods_sales_convert_qty,
+                t2.goods_category_name,
+                t2.convert_qty
+            FROM
+                websit_sales t1 INNER JOIN websit_sales_item t2 ON t1.sales_id = t2.sales_id
+            WHERE
+                t1.company_wechat_id = #{companyWechatId}
+                AND t1.buy_people = 'WORKER'
+                AND t1.flag = 'PAY_TAKE'
+                <if test="websitId != null and websitId != ''">
+                    AND t1.websit_id = #{websitId}
+                </if>
+                <if test="workerMobile != null and workerMobile != ''">
+                    AND t1.worker_mobile = #{workerMobile}
+                </if>
+                <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                    AND t1.confirm_time BETWEEN #{startTime} AND #{endTime}
+                </if>
+                <if test="websitId == null and websits != null and websits.size > 0">
+                    AND t1.websit_id IN
+                    <foreach item="item" index="index" collection="websits" open="(" separator=","
+                             close=")">
+                        #{item}
+                    </foreach>
+                </if>
+        ) t1
+        GROUP BY
+        t1.worker_mobile, t1.pay_flag, t1.goods_id
+        ORDER BY
+        t1.worker_mobile, t1.pay_flag DESC
+    </select>
+
+    <select id="sumBuyDetail"
+            resultType="com.gree.mall.manager.bean.material.report.MaterialSalesSumDetailBean">
+        SELECT
+            t1.websit_id,
+            t1.websit_name,
+            t1.pay_flag,
+            t1.goods_id,
+            t1.goods_name,
+            t1.goods_specification,
+            t1.goods_category_name,
+            t1.goods_sales_convert_qty,
+            SUM(t1.sales_qty) as sales_qty,
+            t1.price as price,
+            SUM(t1.sale_amount) as sale_amount,
+            t1.cost as cost,
+            SUM(t1.cost_value) as cost_value,
+            SUM(t1.convert_qty) as convert_qty
+        FROM
+        (
+            SELECT
+                t1.websit_id,
+                t1.websit_name,
+                t1.pay_flag,
+                t1.worker_mobile,
+                t1.worker_id,
+                t1.worker_name,
+                t2.goods_id,
+                t2.goods_name,
+                t2.sales_qty,
+                t2.price,
+                t2.sale_amount,
+                t2.cost,
+                t2.cost_value,
+                t2.goods_specification,
+                t2.goods_category_name,
+                t2.goods_sales_convert_qty,
+                t2.convert_qty
+            FROM
+                websit_sales t1 INNER JOIN websit_sales_item t2 ON t1.sales_id = t2.sales_id
+            WHERE
+                t1.company_wechat_id = #{companyWechatId}
+                AND t1.buy_people = 'WORKER'
+                AND t1.flag = 'PAY_TAKE'
+                <if test="websitId != null and websitId != ''">
+                    AND t1.websit_id = #{websitId}
+                </if>
+                <if test="workerMobile != null and workerMobile != ''">
+                    AND t1.worker_mobile = #{workerMobile}
+                </if>
+                <if test="workerId != null and workerId != ''">
+                    AND t1.worker_id LIKE CONCAT('%', #{workerId},'%')
+                </if>
+                <if test="workerName != null and workerName != ''">
+                    AND t1.worker_name LIKE CONCAT('%', #{workerName},'%')
+                </if>
+                <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+                    AND t1.confirm_time BETWEEN #{startTime} AND #{endTime}
+                </if>
+                <if test="websitId == null and websits != null and websits.size > 0">
+                    AND t1.websit_id IN
+                    <foreach item="item" index="index" collection="websits" open="(" separator=","
+                             close=")">
+                        #{item}
+                    </foreach>
+                </if>
+
+        ) t1
+        GROUP BY
+        t1.pay_flag, t1.goods_id
+        ORDER BY
+        t1.pay_flag DESC, t1.goods_id
+    </select>
+
+    <sql id="purchaseGoodsColSql">
+        t1.websit_id,
+        t1.websit_name,
+        t1.vender_id,
+        t1.vender_name,
+        t2.goods_id,
+        t2.goods_name,
+        t4.goods_category_name,
+        <!-- SUM(t2.purchaseQty) AS purchaseQty, -->
+        SUM(t2.rec_qty) AS rec_qty,
+        SUM(t2.rec_gift_qty) AS rec_gift_qty,
+        SUM(t2.cost_value) AS cost_value
+    </sql>
+
+    <sql id="purchaseGoodsSumColSql">
+        t1.websit_id,
+        t1.websit_name,
+        '' AS vender_id,
+        '' AS vender_name,
+        '' AS goods_id,
+        '' AS goods_name,
+        '合计:' AS goods_category_name,
+        <!-- SUM(t2.purchaseQty) AS purchaseQty, -->
+        SUM(t2.rec_qty) AS rec_qty,
+        SUM(t2.rec_gift_qty) AS rec_gift_qty,
+        SUM(t2.cost_value) AS cost_value
+    </sql>
+
+    <select id="purchaseGoodsSum" resultType="com.gree.mall.manager.bean.material.report.PurchaseDetailBean">
+        SELECT
+        <if test="!isSum">
+            <include refid="purchaseGoodsColSql" />
+        </if>
+        <if test="isSum">
+            <include refid="purchaseGoodsSumColSql" />
+        </if>
+        FROM
+            websit_purchase t1
+        INNER JOIN websit_purchase_item t2 ON t1.purchase_id = t2.purchase_id AND t1.flag = 'OK'
+        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
+            AND t1.purchase_time BETWEEN #{startTime} AND #{endTime}
+        </if>
+        <where>
+            <if test="websitId != null and websitId != ''">
+                AND t1.websit_id = #{websitId}
+            </if>
+            <if test="websitId == null and websits != null and websits.size > 0">
+                AND t1.websit_id IN
+                <foreach item="item" index="index" collection="websits" open="(" separator=","
+                         close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+        <if test="!isSum">
+            GROUP BY
+            t1.websit_id, t1.vender_id, t2.goods_id
+            ORDER BY
+            t1.websit_id, t1.vender_id, t2.goods_id
+        </if>
+        <if test="isSum">
+            GROUP BY
+            t1.websit_id
+            ORDER BY
+            t1.websit_id
+        </if>
+    </select>
+    <select id="getMonthSummaryData"
+            resultType="com.gree.mall.manager.bean.material.report.PurchaseCategoryBean">
+        SELECT
+            LEFT(#{startDate}, 7) AS `yearMonth`,
+            t1.websit_id,
+            t1.websit_name,
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 6, t1.totalQty, 0 )), 0 ), 4) AS 'tgQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 6, t1.totalCostValue, 0 )), 0 ), 4) 'tgVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 4, t1.totalQty, 0 )), 0 ), 4) AS 'bwmQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 4, t1.totalCostValue, 0 )), 0 ), 4) 'bwmVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 18, t1.totalQty, 0 )), 0 ), 4) AS 'dlQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 18, t1.totalCostValue, 0 )), 0 ), 4) 'dlVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 13, t1.totalQty, 0 )), 0 ), 4) AS 'zjQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 13, t1.totalCostValue, 0 )), 0 ), 4) 'zjVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 11, t1.totalQty, 0 )), 0 ), 4) AS 'lmQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 11, t1.totalCostValue, 0 )), 0 ), 4) 'lmVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 22, t1.totalQty, 0 )), 0 ), 4) AS 'wjQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 22, t1.totalCostValue, 0 )), 0 ), 4) 'wjVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 2, t1.totalQty, 0 )), 0 ), 4) AS 'jtQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 2, t1.totalCostValue, 0 )), 0 ), 4) 'jtVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 29, t1.totalQty, 0 )), 0 ), 4) AS 'kgQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 29, t1.totalCostValue, 0 )), 0 ), 4) 'kgVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 30, t1.totalQty, 0 )), 0 ), 4) AS 'bzdQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 30, t1.totalCostValue, 0 )), 0 ), 4) 'bzdVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 31, t1.totalQty, 0 )), 0 ), 4) AS 'ljqQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 31, t1.totalCostValue, 0 )), 0 ), 4) 'ljqVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 32, t1.totalQty, 0 )), 0 ), 4) AS 'rsgQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 32, t1.totalCostValue, 0 )), 0 ), 4) 'rsgVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 33, t1.totalQty, 0 )), 0 ), 4) AS 'qxggQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 33, t1.totalCostValue, 0 )), 0 ), 4) 'qxggVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 35, t1.totalQty, 0 )), 0 ), 4) AS 'gcQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 35, t1.totalCostValue, 0 )), 0 ), 4) 'gcVal',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 37, t1.totalQty, 0 )), 0 ), 4) AS 'ysqQty',
+            ROUND(IFNULL( SUM( IF ( t1.goods_category_id = 37, t1.totalCostValue, 0 )), 0 ), 4) 'ysqVal'
+        FROM
+        (
+            SELECT
+                t1.websit_id,
+                t1.websit_name,
+                SUM( t1.totalQty ) AS totalQty,
+                SUM( t1.totalCostValue ) AS totalCostValue,
+                t1.goods_category_id,
+                t1.goods_category_name
+            FROM
+                (
+                SELECT
+                    t1.websit_id,
+                    t1.websit_name,
+                    t2.goods_category_id,
+                    t2.goods_category_name,
+                    t2.goods_id,
+                    t2.cost,
+                    IFNULL( t2.rec_qty, 0 ) + IFNULL( t2.rec_gift_qty, 0 ) AS totalQty,
+                    IFNULL( t2.rec_qty, 0 ) * t2.cost AS totalCostValue
+                FROM
+                    websit_purchase t1
+                    JOIN websit_purchase_item t2 ON t1.purchase_id = t2.purchase_id
+                WHERE
+                    t1.company_wechat_id = #{companyWechatId}
+                    AND t1.flag = 'OK'
+                    <if test="websitId != null and websitId != ''">
+                        AND t1.websit_id = #{websitId}
+                    </if>
+                    <if test="websitId == null and websits != null and websits.size > 0">
+                        AND t1.websit_id IN
+                        <foreach item="item" index="index" collection="websits" open="(" separator=","
+                                 close=")">
+                            #{item}
+                        </foreach>
+                    </if>
+                    AND t1.purchase_time BETWEEN #{startDate} AND #{endDate}
+                UNION ALL
+                SELECT
+                    t1.websit_id,
+                    t1.websit_name,
+                    t2.goods_category_id,
+                    t2.goods_category_name,
+                    t2.goods_id,
+                    t2.cost,
+                    (IFNULL( t2.ret_qty, 0 ) * -1 ) AS totalRecQty,
+                    (IFNULL( t2.ret_qty, 0 ) * t2.cost * -1 ) AS totalCostValue
+                FROM
+                    websit_purchase_ret t1
+                    JOIN websit_purchase_ret_item t2 ON t1.purchase_ret_id = t2.purchase_ret_id
+                WHERE
+                    t1.company_wechat_id = #{companyWechatId}
+                    AND t1.flag = 'OK'
+                    <if test="websitId != null and websitId != ''">
+                        AND t1.websit_id = #{websitId}
+                    </if>
+                    <if test="websitId == null and websits != null and websits.size > 0">
+                        AND t1.websit_id IN
+                        <foreach item="item" index="index" collection="websits" open="(" separator=","
+                                 close=")">
+                            #{item}
+                        </foreach>
+                    </if>
+                    AND t1.ret_time BETWEEN #{startDate} AND #{endDate}
+                ) t1
+            GROUP BY
+            t1.websit_id,
+            t1.goods_category_id
+        ) t1
+        GROUP BY
+        t1.websit_id
+    </select>
+
+    <select id="getLastMonthStockSumVal"
+            resultType="com.gree.mall.manager.bean.material.report.WebsiteStockValSumBean">
+        SELECT
+            a.websit_id,
+            ROUND(SUM(a.closeQty * IFNULL( b.cost, 0 )), 4) AS lastMonthVal
+        FROM
+        (
+            SELECT
+                a.websit_id,
+                a.goods_id,
+                SUM(IFNULL(a.change_qty, 0) * IF(a.direct_flag = 'ADD', 1, -1)) AS closeQty
+            FROM
+                websit_stock_acc a,
+                websit_goods b
+            <where>
+                a.goods_id = b.goods_id
+                AND a.company_wechat_id = #{companyWechatId}
+                <if test="websitId != null and websitId != ''">
+                    AND a.websit_id = #{websitId}
+                </if>
+                <if test="websitId == null and websits != null and websits.size > 0">
+                    AND a.websit_id IN
+                    <foreach item="item" index="index" collection="websits" open="(" separator=","
+                             close=")">
+                        #{item}
+                    </foreach>
+                </if>
+                AND a.sdate <![CDATA[ < ]]> #{startDate}
+            </where>
+            GROUP BY a.websit_id, a.goods_id
+        ) a
+        LEFT JOIN (
+        SELECT
+            t1.websit_id,
+            t2.goods_id,
+            max( t2.id ) id,
+            t2.cost
+        FROM
+            websit_purchase t1,
+            websit_purchase_item t2
+        WHERE
+            t1.purchase_id = t2.purchase_id
+            AND t1.company_wechat_id = #{companyWechatId}
+            <if test="websitId != null and websitId != ''">
+                AND a.websit_id = #{websitId}
+            </if>
+            <if test="websitId == null and websits != null and websits.size > 0">
+                AND a.websit_id IN
+                <foreach item="item" index="index" collection="websits" open="(" separator=","
+                         close=")">
+                    #{item}
+                </foreach>
+            </if>
+            AND t1.flag = 'OK'
+            AND t1.update_time <![CDATA[ < ]]>  #{startDate}
+        GROUP BY
+            t1.websit_id,
+            t2.goods_id
+        ) b ON a.websit_id = b.websit_id AND a.goods_id = b.goods_id
+        GROUP BY
+        a.websit_id
+    </select>
+
+    <select id="getWorkerMonthSummaryData"
+            resultType="com.gree.mall.manager.bean.material.report.WorkerPurchaseCategoryBean">
+        SELECT
+            a.identity,
+            LEFT(#{startDate}, 7) AS `yearMonth`,
+            a.worker_id,
+            a.worker_name,
+            a.websit_id,
+            a.websit_name,
+            ROUND(IFNULL( SUM( IF ( a.category_id = 6, a.totalQty, 0 )), 0 ), 4)  AS 'tgQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 6, a.totalSaleVal, 0 )), 0 ), 4) AS 'tgVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 6, a.totalConvertQty, 0 )), 0 ), 4) AS 'tgConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 4, a.totalQty, 0 )), 0 ), 4)  AS 'bwmQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 4, a.totalSaleVal, 0 )), 0 ), 4) AS 'bwmVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 4, a.totalConvertQty, 0 )), 0 ), 4) AS 'bwmConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 18, a.totalQty, 0 )), 0 ), 4)  AS 'dlQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 18, a.totalSaleVal, 0 )), 0 ), 4) AS 'dlVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 18, a.totalConvertQty, 0 )), 0 ), 4) AS 'dlConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 13, a.totalQty, 0 )), 0 ), 4)  AS 'zjQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 13, a.totalSaleVal, 0 )), 0 ), 4) AS 'zjVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 13, a.totalConvertQty, 0 )), 0 ), 4) AS 'zjConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 11, a.totalQty, 0 )), 0 ), 4)  AS 'lmQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 11, a.totalSaleVal, 0 )), 0 ), 4) AS 'lmVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 11, a.totalConvertQty, 0 )), 0 ), 4) AS 'lmConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 22, a.totalQty, 0 )), 0 ), 4)  AS 'wjQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 22, a.totalSaleVal, 0 )), 0 ), 4) AS 'wjVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 22, a.totalConvertQty, 0 )), 0 ), 4) AS 'wjConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 2, a.totalQty, 0 )), 0 ), 4)  AS 'jtQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 2, a.totalSaleVal, 0 )), 0 ), 4) AS 'jtVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 2, a.totalConvertQty, 0 )), 0 ), 4) AS 'jtConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 29, a.totalQty, 0 )), 0 ), 4) AS 'kgQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 29, a.totalSaleVal, 0 )), 0 ), 4) 'kgVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 29, a.totalConvertQty, 0 )), 0 ), 4) AS 'kgConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 30, a.totalQty, 0 )), 0 ), 4) AS 'bzdQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 30, a.totalSaleVal, 0 )), 0 ), 4) 'bzdVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 30, a.totalConvertQty, 0 )), 0 ), 4) AS 'bzdConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 31, a.totalQty, 0 )), 0 ), 4) AS 'ljqQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 31, a.totalSaleVal, 0 )), 0 ), 4) 'ljqVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 31, a.totalConvertQty, 0 )), 0 ), 4) AS 'ljqConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 32, a.totalQty, 0 )), 0 ), 4) AS 'rsgQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 32, a.totalSaleVal, 0 )), 0 ), 4) 'rsgVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 32, a.totalConvertQty, 0 )), 0 ), 4) AS 'rsgConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 33, a.totalQty, 0 )), 0 ), 4) AS 'qxggQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 33, a.totalSaleVal, 0 )), 0 ), 4) 'qxggVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 33, a.totalConvertQty, 0 )), 0 ), 4) AS 'qxggConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 35, a.totalQty, 0 )), 0 ), 4) AS 'gcQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 35, a.totalSaleVal, 0 )), 0 ), 4) 'gcVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 35, a.totalConvertQty, 0 )), 0 ), 4) AS 'gcConvertQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 37, a.totalQty, 0 )), 0 ), 4) AS 'ysqQty',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 37, a.totalSaleVal, 0 )), 0 ), 4) 'ysqVal',
+            ROUND(IFNULL( SUM( IF ( a.category_id = 37, a.totalConvertQty, 0 )), 0 ), 4) AS 'ysqConvertQty'
+        FROM
+            (
+                SELECT
+                    a.identity,
+                    a.worker_id,
+                    a.worker_name,
+                    a.websit_id,
+                    a.websit_name,
+                    b.category_id,
+                    SUM( a.sales_qty ) AS totalQty,
+                    SUM( a.totalSaleVal ) AS totalSaleVal,
+                    SUM( a.convert_qty ) as totalConvertQty
+                FROM
+                    (
+                        SELECT
+                            a.identity,
+                            a.worker_id,
+                            a.worker_name,
+                            a.websit_id,
+                            a.websit_name,
+                            b.goods_id,
+                            b.sales_qty,
+                            b.sales_qty * b.price AS totalSaleVal,
+                            b.convert_qty
+                        FROM
+                            websit_sales a,
+                            websit_sales_item b
+                        WHERE
+                            a.sales_id = b.sales_id
+                            AND a.company_wechat_id = #{companyWechatId}
+                            AND a.flag = 'PAY_TAKE'
+                            AND a.confirm_time BETWEEN #{startDate} AND #{endDate}
+                        UNION ALL
+                        SELECT
+                            a.identity,
+                            a.worker_id,
+                            a.worker_name,
+                            a.websit_id,
+                            a.websit_name,
+                            b.goods_id,
+                            b.ret_qty * - 1 AS saleQty,
+                            (b.ret_qty * b.price) * - 1 AS totalSaleVal,
+                            (b.ret_convert_qty * - 1) AS convert_qty
+                        FROM
+                            websit_sales_ret a,
+                            websit_sales_ret_item b
+                        WHERE
+                            a.sales_ret_id = b.sales_ret_id
+                            AND a.company_wechat_id = #{companyWechatId}
+                            AND a.confirm_by IS NOT NULL
+                            AND a.confirm_time BETWEEN #{startDate} AND #{endDate}
+                    ) a
+                    LEFT JOIN goods b ON a.goods_id = b.goods_id
+                GROUP BY
+                    a.worker_id,
+                    a.worker_name,
+                    a.websit_id,
+                    a.websit_name,
+                    b.category_id
+            ) a
+        GROUP BY
+            a.worker_id,
+            a.websit_id
+    </select>
 </mapper>