From bbe0a2fd03063316e50cf141986bda984599bbda Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Tue, 22 Feb 2022 23:41:42 +0800
Subject: [PATCH] Merge branch 'developer'

---
 zq-erp/src/main/java/com/matrix/system/hive/statistics/AchieveAction.java |  214 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 169 insertions(+), 45 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/hive/statistics/AchieveAction.java b/zq-erp/src/main/java/com/matrix/system/hive/statistics/AchieveAction.java
index 7f452ad..1668d00 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/statistics/AchieveAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/statistics/AchieveAction.java
@@ -1,5 +1,8 @@
 package com.matrix.system.hive.statistics;
 
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.matrix.core.constance.MatrixConstance;
 import com.matrix.core.pojo.AjaxResult;
 import com.matrix.core.pojo.PaginationVO;
@@ -7,19 +10,23 @@
 import com.matrix.core.tools.WebUtil;
 import com.matrix.core.tools.excl.ExcelSheetPO;
 import com.matrix.core.tools.excl.ExcelVersion;
+import com.matrix.system.common.bean.CustomerDataDictionary;
 import com.matrix.system.common.bean.SysUsers;
-import com.matrix.system.common.constance.AppConstance;
+import com.matrix.system.common.dao.CustomerDataDictionaryDao;
+import com.matrix.system.common.tools.DataAuthUtil;
 import com.matrix.system.common.tools.ResponseHeadUtil;
 import com.matrix.system.hive.action.util.QueryUtil;
 import com.matrix.system.hive.bean.AchieveNew;
-import com.matrix.system.hive.bean.SysOrder;
-import com.matrix.system.hive.bean.SysOrderItem;
+import com.matrix.system.hive.dao.AchieveNewDao;
+import com.matrix.system.hive.dto.AchieveNewStatisticsDto;
+import com.matrix.system.hive.plugin.util.CollectionUtils;
 import com.matrix.system.hive.service.AchieveNewService;
-import com.matrix.system.hive.service.SysOrderItemService;
-import com.matrix.system.hive.service.SysOrderService;
+import com.matrix.system.hive.vo.AchieveNewStatisticsVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -44,19 +51,35 @@
     private AchieveNewService achieveNewService;
 
     @Autowired
-    private SysOrderService sysOrderService;
+    private AchieveNewDao achieveNewDao;
 
-    @Autowired
-    private SysOrderItemService sysOrderItemService;
+
+
+    /**
+     * 员工业绩统计
+     */
+    @PostMapping(value = "/achieveNewStatistics")
+    public @ResponseBody
+    AjaxResult achieveNewStatistics(@RequestBody  AchieveNewStatisticsDto queryDto){
+        SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
+
+        queryDto.setCompanyId(sysUsers.getCompanyId());
+
+        Page<AchieveNewStatisticsVo> page = new Page(queryDto.getPageNum(), queryDto.getPageSize());
+        IPage<AchieveNewStatisticsVo> rows = achieveNewDao.achieveNewStatistics(page,queryDto);
+        AjaxResult result = AjaxResult.buildSuccessInstance(rows.getRecords(),rows.getTotal());
+        return result;
+    }
+
 
     /**
      * 门店每日单据明细表
      */
     @RequestMapping(value = "/findSumDailyInfoNew")
     public @ResponseBody
-    AjaxResult findSumDailyInfoNew(AchieveNew achieveNew, PaginationVO pageVo) {
+    AjaxResult findSumDailyInfoNew(@RequestBody  AchieveNew achieveNew) {
         SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
-        if(!AppConstance.ZONGDIAN.equals(sysUsers.getShopName())){
+         if (!DataAuthUtil.hasAllShopAuth()) {
             achieveNew.setShopId(sysUsers.getShopId());
         }
         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, achieveNewService.findSumDailyInfoNew(achieveNew, null),
@@ -70,11 +93,16 @@
      */
     @RequestMapping(value = "/findDailyInfoNew")
     public @ResponseBody
-    AjaxResult findDailyInfoNew(AchieveNew achieveNew, PaginationVO pageVo) {
+    AjaxResult findDailyInfoNew(@RequestBody  AchieveNew achieveNew) {
         SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
-        if(!AppConstance.ZONGDIAN.equals(sysUsers.getShopName())){
+        achieveNew.setCompanyId(sysUsers.getCompanyId());
+         if (!DataAuthUtil.hasAllShopAuth()) {
             achieveNew.setShopId(sysUsers.getShopId());
         }
+        PaginationVO pageVo = new PaginationVO();
+
+        pageVo.setOffset(achieveNew.getOffset());
+        pageVo.setLimit(achieveNew.getLimit());
         pageVo.setSort("datatime");
         pageVo.setOrder("desc");
         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, achieveNewService.findDayFlow(achieveNew, pageVo),
@@ -82,18 +110,104 @@
         return result;
     }
 
-    @RequestMapping(value = "/exportDailyInfoNew")
-    public void exportDailyInfoNew(ModelMap model, HttpServletRequest request, HttpServletResponse response, AchieveNew achieveNew) throws IOException {
+    @RequestMapping(value = "/exportAchieveNewStatisticsExcel")
+    public void exportAchieveNewStatisticsExcel(ModelMap model, HttpServletRequest request, HttpServletResponse response,   AchieveNewStatisticsDto queryDto) throws IOException {
         //这里是从数据库里查数据并组装成我们想要的数据结构的过程
         List<ExcelSheetPO> res = new ArrayList<>();
         ExcelSheetPO orderSheet = new ExcelSheetPO();
-        String title = "每日单据明细";
+        String title = "员工业绩统计";
         orderSheet.setSheetName(title);
         orderSheet.setTitle(title);
-        String[] header = {"年", "月", "日",   "订单类型", "订单编号", "会员级别", "姓名", "项目名称", "总金额", "卡项", "现金单次", "现金产品", "划扣", "本金消耗", "赠消", "提成", "顾问", "美疗师", "人头", "项目个数", "项目时间", "门店"};
+        String[] header = {"规则名称", "门店名称", "业绩归属人", "业绩创建人", "订单金额", "现金", "划扣", "本金消耗", "赠送消耗"
+                , "服务提成", "人头", "项目个数", "服务时间", "订单类型"};
         orderSheet.setHeaders(header);
         SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
-        if(!AppConstance.ZONGDIAN.equals(sysUsers.getShopName())){
+         if (!DataAuthUtil.hasAllShopAuth()) {
+            queryDto.setShopId(sysUsers.getShopId());
+        }
+        queryDto.setCompanyId(sysUsers.getCompanyId());
+        Page<AchieveNewStatisticsVo> page = new Page(1, Long.MAX_VALUE);
+
+        if (StrUtil.isNotBlank(queryDto.getBeginTimeStr())) {
+            queryDto.setBeginTime(DateUtil.stringToDate(queryDto.getBeginTimeStr(), DateUtil.DATE_FORMAT_MM));
+        }
+
+        if (StrUtil.isNotBlank(queryDto.getEndTimeStr())) {
+            queryDto.setEndTime(DateUtil.stringToDate(queryDto.getEndTimeStr(), DateUtil.DATE_FORMAT_MM));
+        }
+        IPage<AchieveNewStatisticsVo> rows = achieveNewDao.achieveNewStatistics(page,queryDto);
+        List<AchieveNewStatisticsVo> dataList = rows.getRecords();
+        List<List<Object>> list = new ArrayList<>();
+        if (dataList.size() > 0) {
+            for (AchieveNewStatisticsVo item : dataList) {
+                List<Object> temp = new ArrayList<>();
+                temp.add(item.getRuleName());
+                temp.add(item.getShopName());
+                temp.add(item.getGuwen());
+                temp.add(item.getCreateBy());
+                temp.add(item.getZkTotal());
+                temp.add(item.getGoodsCash());
+                temp.add(item.getCardCash());
+                temp.add(item.getHisConsume());
+                temp.add(item.getFreeConsume());
+                temp.add(item.getProjPercentage());
+                temp.add(item.getNumberOfPeople());
+                temp.add(item.getProjNum());
+                temp.add(item.getProjTime());
+                temp.add(item.getOrderType());
+                list.add(temp);
+            }
+        }
+        orderSheet.setDataList(list);
+        res.add(orderSheet);
+        response = ResponseHeadUtil.setExcelHead(response);
+        response.setHeader("Content-Disposition",
+                "attachment;filename=" + java.net.URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8"));
+        OutputStream os = response.getOutputStream();
+        com.matrix.core.tools.excl.ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true);
+    }
+
+    @Autowired
+    CustomerDataDictionaryDao dataDictionaryDao;
+
+    @RequestMapping(value = "/exportDailyInfoNew")
+    public void exportDailyInfoNew(ModelMap model, HttpServletRequest request, HttpServletResponse response, AchieveNew achieveNew) throws IOException {
+        SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
+
+        List<CustomerDataDictionary> achieveTyps = dataDictionaryDao.selectByParentCode("YJLX", sysUsers.getCompanyId());
+
+        List<ExcelSheetPO> res = new ArrayList<>();
+        ExcelSheetPO orderSheet = new ExcelSheetPO();
+        String title = "员工业绩报表";
+        orderSheet.setSheetName(title);
+        orderSheet.setTitle(title);
+        List<String> headerList =new ArrayList();
+        headerList.add("订单时间");
+        headerList.add("订单编号");
+        headerList.add("订单类型");
+        headerList.add("会员姓名");
+        headerList.add("产品");
+        headerList.add("业绩规则");
+        headerList.add("产品分类");
+        headerList.add("订单金额");
+        headerList.add("现金");
+        headerList.add("划扣");
+        headerList.add("员工");
+        achieveTyps.forEach(item->{headerList.add(item.getValue());});
+        headerList.add("本金消耗");
+        headerList.add("赠消");
+        headerList.add("提成");
+        headerList.add("人头");
+        headerList.add("项目个数");
+        headerList.add("项目时间");
+        headerList.add("顾问");
+        headerList.add("门店");
+
+        String[] header =  headerList.toArray(new String[headerList.size()]);
+
+
+        orderSheet.setHeaders(header);
+         if (!DataAuthUtil.hasAllShopAuth()) {
             achieveNew.setShopId(sysUsers.getShopId());
         }
 
@@ -103,27 +217,32 @@
         if (dataList.size() > 0) {
             for (AchieveNew item : dataList) {
                 List<Object> temp = new ArrayList<>();
-                temp.add(item.getYear());
-                temp.add(item.getMonth());
-                temp.add(item.getDay());
-                temp.add(item.getOrderType());
+                temp.add(DateUtil.dateFormatStr(item.getDatatime(), DateUtil.DATE_FORMAT_MM));
                 temp.add(item.getOrderNo());
-                temp.add(item.getLevelName());
+                temp.add(item.getOrderType());
                 temp.add(item.getVipName());
                 temp.add(item.getProName());
+                temp.add(item.getAchieveRuleName());
+                temp.add(item.getCateName());
                 temp.add(item.getZkTotal());
-                temp.add(item.getCardCash());
-                temp.add(item.getProjCash());
                 temp.add(item.getGoodsCash());
-                temp.add(item.getConsume());
+                temp.add(item.getCardCash());
+                temp.add(item.getMeiliao());
+                //动态导出列----
+                achieveTyps.forEach(item2->{
+                    if(item2.getValue().equals(item.getAchieveType())){
+                        temp.add(item.getGoodsCash());
+                    }else{
+                        temp.add("");
+                    }
+                 });
                 temp.add(item.getHisConsume());
                 temp.add(item.getFreeConsume());
                 temp.add(item.getProjPercentage());
-                temp.add(item.getGuwen());
-                temp.add(item.getMeiliao());
                 temp.add(item.getNumberOfPeople());
                 temp.add(item.getProjNum());
                 temp.add(item.getProjTime());
+                temp.add(item.getGuwen());
                 temp.add(item.getShopName());
                 list.add(temp);
             }
@@ -149,27 +268,32 @@
 
     @RequestMapping(value = "/add")
     @ResponseBody
+    @Transactional
     public AjaxResult add(@RequestBody List<AchieveNew> list) {
-        SysOrder order = sysOrderService.findById(list.get(0).getOrderId());
-        List<SysOrderItem> orderItems = sysOrderItemService.findByOrderId(order.getId());
-        orderItems.forEach(item -> {
-            List<AchieveNew> achieveNewList = new ArrayList<>();
-            for(AchieveNew achieveNew : list) {
-                achieveNewService.removeById(achieveNew.getId());
-                achieveNew.setId(null);
-                achieveNew.setConsume(null);
-                achieveNew.setCardCash(null);
+        if (CollectionUtils.isNotEmpty(list)) {
+            //删除原业绩
+            achieveNewDao.deleteByOrderId(list.get(0).getOrderId());
+            //插入新业绩
+            achieveNewDao.batchInsert(list);
+            return AjaxResult.buildSuccessInstance("保存成功");
+        } else {
+            return AjaxResult.buildFailInstance("未找到业绩数据");
+        }
+    }
 
-                if (achieveNew.getOrderItemId().equals(item.getId())) {
-                    achieveNewList.add(achieveNew);
-                }
+    @RequestMapping(value = "/findDailyBeautyList")
+    @ResponseBody
+    public AjaxResult findDailyBeautyList(@RequestBody  AchieveNew achieveNew) {
+        SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
+        achieveNew.setCompanyId(sysUsers.getCompanyId());
+        if (!DataAuthUtil.hasAllShopAuth()) {
+            achieveNew.setShopId(sysUsers.getShopId());
+        }
+        PaginationVO pageVo = new PaginationVO();
 
-            }
-            item.setAchaeveList(achieveNewList);
-        });
-        order.setItems(orderItems);
-        achieveNewService.addAchaeveByOrder(order);
-        return AjaxResult.buildSuccessInstance("保存成功");
+        pageVo.setOffset(achieveNew.getOffset());
+        pageVo.setLimit(achieveNew.getLimit());
+        return AjaxResult.buildSuccessInstance(achieveNewService.findDailyBeautyList(achieveNew, pageVo), achieveNewService.findDailyBeautyListTotal(achieveNew));
     }
 
 }

--
Gitblit v1.9.1