| | |
| | | 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 implements StatisticAnalysisService { |
| | | 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) { |
| | | return null; |
| | | // 判断传入的排序字段是否在特定的字符串里面,如果不在则将排序字段设置未空 |
| | | 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) { |
| | | return null; |
| | | 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.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) { |
| | | 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; |
| | | } |
| | | } |