tj
2025-04-17 add52b2fce633d62fb6cf829cc9ee58cb3727257
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.mzl.flower.service.impl.statisticsAnalysis;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.base.cache.DictCacheClient;
import com.mzl.flower.dto.request.statisticAnalysis.FlowerMaterialDTO;
import com.mzl.flower.dto.request.statisticAnalysis.FlowerSaleDTO;
import com.mzl.flower.dto.response.report.OrderReportResultVO;
import com.mzl.flower.dto.response.statisticAnalysis.FlowerMaterialStaticVO;
import com.mzl.flower.dto.response.statisticAnalysis.FlowerMaterialVO;
import com.mzl.flower.dto.response.statisticAnalysis.FlowerSaleStatisticVO;
import com.mzl.flower.dto.response.statisticAnalysis.FlowerSaleVO;
import com.mzl.flower.mapper.statisticsAnalysis.FlowerMaterialMapper;
import com.mzl.flower.mapper.statisticsAnalysis.SalesStatisticsAnalysisMapper;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.service.statisticsAnalysis.StatisticAnalysisService;
import com.mzl.flower.utils.ExcelExportUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
 
@Slf4j
@Service
public class StatisticAnalysisServiceImpl extends BaseService implements StatisticAnalysisService {
 
    @Autowired
    private DictCacheClient dictCacheClient;
 
    @Autowired
    private FlowerMaterialMapper flowerMaterialMapper;
    @Resource
    SalesStatisticsAnalysisMapper salesStatisticAnalysisMapper;
 
    @Override
    public Page<FlowerMaterialVO> getFlowerMaterialPage(Page page, FlowerMaterialDTO dto) {
        // 判断传入的排序字段是否在特定的字符串里面,如果不在则将排序字段设置未空
        if (!"f.`level`".equals(dto.getOrderField()) && !"f.price".equals(dto.getOrderField())&&!"f.stock".equals(dto.getOrderField())) {
            dto.setOrderField(null);
        }
 
        Page<FlowerMaterialVO> result=flowerMaterialMapper.getFlowerMaterialPage(page, dto);
 
        return result;
    }
 
    @Override
    public FlowerMaterialStaticVO getFlowerMaterialStatis(FlowerMaterialDTO dto) {
       List<FlowerMaterialStaticVO> list=  flowerMaterialMapper.getFlowerMaterialStatis(dto);
       if(!CollectionUtils.isEmpty(list)){
           return list.get(0);
       }
       return null;
    }
 
    @Override
    public void exportFlowerMaterialSales(HttpServletResponse response, FlowerMaterialDTO dto) {
        // 判断传入的排序字段是否在特定的字符串里面,如果不在则将排序字段设置未空
        if (!"f.`level`".equals(dto.getOrderField()) && !"f.price".equals(dto.getOrderField())&&!"f.stock".equals(dto.getOrderField())) {
            dto.setOrderField(null);
        }
        List<FlowerMaterialVO> list=flowerMaterialMapper.getFlowerMaterialList(dto);
 
        String[] rowsName = new String[]{
                "序号"
                ,"供应商ID", "供应商名称","注册手机号","联系方式","所属集货站","品类","商品名称","等级","商品规格","价格","库存","状态",};
        List<Object[]> dataList = new ArrayList<>();
        int sn = 1;
        for (FlowerMaterialVO o : list) {
            Object[] objs = new Object[rowsName.length];
            int a = 0;
            objs[a++] = sn; // 序号
            objs[a++] = o.getSupplierId(); // 供应商ID
            objs[a++] = o.getSupplierName(); // 供应商名称
            objs[a++] = o.getLoginName(); // 注册手机号
            objs[a++] = o.getContactTel(); // 联系方式"
            objs[a++] = o.getStationName(); // 所属集货站
//            objs[a++] = o.getCategoryName(); // 品类
            objs[a++] = o.getParentCategoryName(); // 品类
            objs[a++] = o.getFlowerName(); //商品名称
//            String dictValue = dictCacheClient.getDict("FLOWER_LEVEL", o.getFlowerLevel());
//            objs[a++] = dictValue; //等级
            objs[a++] = o.getFlowerLevelStr(); //等级
            objs[a++] = o.getFlowerUnit(); //商品规格
            objs[a++] = o.getFlowerPrice();//价格
            objs[a++] = o.getFlowerStock();//库存
//            String dictValueStatus = dictCacheClient.getDict("FLOWER_STATUS", o.getFlowerStatus());
            //            objs[a++] =dictValueStatus;
            objs[a++] = o.getFlowerStatusStr(); // 状态
 
            dataList.add(objs);
            sn++;
        }
 
        ExcelExportUtil excelExportUtil = new ExcelExportUtil("花材统计报表", rowsName, dataList, response);
        try {
            response.addHeader("filename", URLEncoder.encode("花材统计报表.xls", "UTF-8"));
            response.addHeader("Access-Control-Expose-Headers", "filename");
            excelExportUtil.export();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
 
 
    @Override
    public Page<FlowerSaleVO> getFlowerSalePage(Page page, FlowerSaleDTO dto) {
        dto.setCreateStartDate(parseLocalDateTime(dto.getCreateStartDateStr(), 17, 0, 0, -1));
        dto.setCreateEndDate(parseLocalDateTime(dto.getCreateEndDateStr(), 17, 0, 0, 0));
        return salesStatisticAnalysisMapper.getFlowerSalePage(page, dto);
    }
 
    @Override
    public FlowerSaleStatisticVO getFlowerSaleStatistics(FlowerSaleDTO dto) {
        dto.setCreateStartDate(parseLocalDateTime(dto.getCreateStartDateStr(), 17, 0, 0, -1));
        dto.setCreateEndDate(parseLocalDateTime(dto.getCreateEndDateStr(), 17, 0, 0, 0));
        return salesStatisticAnalysisMapper.getFlowerSaleStatistics(dto);
    }
 
    @Override
    public void exportFlowerSales(HttpServletResponse response, FlowerSaleDTO dto) {
        dto.setCreateStartDate(parseLocalDateTime(dto.getCreateStartDateStr(), 17, 0, 0, -1));
        dto.setCreateEndDate(parseLocalDateTime(dto.getCreateEndDateStr(), 17, 0, 0, 0));
        List<FlowerSaleVO> list=salesStatisticAnalysisMapper.getFlowerSaleSList(dto);
        String[] rowsName = new String[]{"序号", "供应商id", "供应商名称", "注册手机号", "联系方式", "集货站", "品类", "商品名称", "等级", "规格", "底价", "售价",
                "销售扎数", "销售地址", "支付时间", "订单号", "缺货扎数", "补货扎数", "降级扎数"};
        List<Object[]> dataList = new ArrayList<>();
        int sn = 1;
        for (FlowerSaleVO o : list) {
            Object[] objs = new Object[rowsName.length];
            int a = 0;
            objs[a++] = sn; // 序号
            objs[a++] = o.getSupplierId(); // 供应商id
            objs[a++] = o.getSupplierName(); // 供应商名称
            objs[a++] = o.getRegisterTel(); // 注册手机号
            objs[a++] = o.getCustomerTel(); // 联系方式"
            objs[a++] = o.getStationName(); // 集货站
            objs[a++] = o.getFlowerCategory(); // 品类
            objs[a++] = o.getFlowerName(); //商品名称
            objs[a++] = o.getFlowerLevel(); //等级
            objs[a++] = o.getFlowerUnit(); //规格
            objs[a++] = o.getSupplierPrice();//底价
            objs[a++] = o.getPrice(); //售价
            objs[a++] = o.getNum(); //销售扎数
            objs[a++] = o.getAddress(); //销售地址
            objs[a++] = o.getPaymentTime(); //支付时间
            objs[a++] = o.getOrderNo(); //订单号
            objs[a++] = o.getLackNum(); //缺货扎数
            objs[a++] = o.getReduceNum(); //补货扎数
            objs[a++] = o.getReduceNum(); //降级扎数
            dataList.add(objs);
            sn++;
        }
        ExcelExportUtil excelExportUtil = new ExcelExportUtil("花材销售统计", rowsName, dataList, response);
        try {
            response.addHeader("filename", URLEncoder.encode("花材销售统计.xls", "UTF-8"));
            response.addHeader("Access-Control-Expose-Headers", "filename");
            excelExportUtil.export();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
 
    protected LocalDateTime parseLocalDateTime(final String dateStr, int hour, int minute, int second, long plusDays) {
        LocalDateTime dateTime = null;
        if (StringUtils.isNotBlank(dateStr)) {
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate date = LocalDate.parse(dateStr, dateTimeFormatter).plusDays(plusDays);
            dateTime = date.atTime(hour, minute, second);
        }
 
        return dateTime;
    }
}