New file |
| | |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.system.app.dto.VipStatisticsParamDto; |
| | | import com.matrix.system.common.bean.SysCompany; |
| | | import com.matrix.system.common.bean.SysUsers; |
| | | import com.matrix.system.common.dao.SysCompanyDao; |
| | | import com.matrix.system.common.dao.SysUsersDao; |
| | | import com.matrix.system.common.tools.DataAuthUtil; |
| | | import com.matrix.system.hive.bean.SysShopInfo; |
| | | import com.matrix.system.hive.dao.SysShopInfoDao; |
| | | import com.matrix.system.hiveErp.analysUtil.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-12-30 |
| | | **/ |
| | | @Service |
| | | public class DataAnalysisCustomerServiceImpl { |
| | | |
| | | @Autowired |
| | | private SysShopInfoDao shopInfoDao; |
| | | |
| | | @Autowired |
| | | private SysCompanyDao sysCompanyDao; |
| | | |
| | | @Autowired |
| | | private SysUsersDao sysUsersDao; |
| | | |
| | | /** |
| | | * 按店铺查询数据通用格式执行方法,支持时、日、月、年维度 |
| | | * 如: A店铺 B店铺 |
| | | * 2020-01-01 12 13 |
| | | * 2020-02-02 10 11 |
| | | * |
| | | * @param statisticsParam 时间条件 |
| | | * @param caculate 循环调用caculate计算该店的数据 |
| | | * 查询的数据需满足 只有一个门店只有一行 列名称为 t0,t1,t2 |
| | | * @return |
| | | */ |
| | | public AjaxResult getAnalysisResult(StatisticsParamVo statisticsParam, Caculate caculate) { |
| | | AjaxResult result = new AjaxResult(); |
| | | |
| | | //根据计算横坐标 |
| | | List<Date> xAxis = StatisticsTimeUtil.getTimeSpace(statisticsParam.getBeginTime(), statisticsParam.getEndTime(), statisticsParam.getStatisticsUnit()); |
| | | |
| | | //获取所有门店 |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | List<SysShopInfo> shops = null; |
| | | if (statisticsParam.getShopId() != null) { |
| | | shops = Arrays.asList(shopInfoDao.selectById(user.getShopId())); |
| | | } else { |
| | | if (DataAuthUtil.hasAllShopAuth()) { |
| | | shops = shopInfoDao.selectShopInfo(user.getCompanyId()); |
| | | } else { |
| | | shops = Arrays.asList(shopInfoDao.selectById(user.getShopId())); |
| | | } |
| | | } |
| | | //定义数据项内容 |
| | | List<SeriesVo> series = new ArrayList<>(); |
| | | |
| | | //定义数据主体 |
| | | String[] legendData = new String[shops.size()]; |
| | | |
| | | int i = 0; |
| | | |
| | | //按门店统计数据 |
| | | List<StatisticsTimeDaoParam> timeSpaceParam = StatisticsTimeUtil.buidParam(xAxis); |
| | | for (SysShopInfo shop : shops) { |
| | | |
| | | legendData[i++] = shop.getShopName(); |
| | | //数据项内容 |
| | | SeriesVo storeInfoSeries = new SeriesVo(); |
| | | storeInfoSeries.setName(shop.getShopName()); |
| | | //调用计算器获取数据库统计的结果 |
| | | Map<String, Integer> yAxisMap = caculate.exec(timeSpaceParam, shop.getId(), null); |
| | | //把统计结果转成数组格式 |
| | | storeInfoSeries.setData(StatisticsTimeUtil.getSeries(yAxisMap)); |
| | | series.add(storeInfoSeries); |
| | | |
| | | } |
| | | //构造返回对象 |
| | | Map<Object, Object> data = new HashMap<>(); |
| | | data.put("legendData", legendData); |
| | | data.put("series", series); |
| | | String[] xData = StatisticsTimeUtil.getFormartDateList(xAxis, statisticsParam); |
| | | data.put("xAxis", Arrays.copyOf(xData, xData.length - 1)); |
| | | result.setMapInfo(data); |
| | | result.setStatus(AjaxResult.STATUS_SUCCESS); |
| | | return result; |
| | | } |
| | | |
| | | public AjaxResult getCompanyAnalysisResult(StatisticsParamVo statisticsParam, Caculate caculate) { |
| | | AjaxResult result = new AjaxResult(); |
| | | |
| | | //根据计算横坐标 |
| | | List<Date> xAxis = StatisticsTimeUtil.getTimeSpace(statisticsParam.getBeginTime(), statisticsParam.getEndTime(), statisticsParam.getStatisticsUnit()); |
| | | |
| | | //获取所有门店 |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | SysCompany company = sysCompanyDao.selectById(user.getCompanyId()); |
| | | |
| | | //定义数据项内容 |
| | | List<SeriesVo> series = new ArrayList<>(); |
| | | |
| | | //定义数据主体 |
| | | String[] legendData = new String[1]; |
| | | |
| | | int i = 0; |
| | | |
| | | //按门店统计数据 |
| | | List<StatisticsTimeDaoParam> timeSpaceParam = StatisticsTimeUtil.buidParam(xAxis); |
| | | |
| | | legendData[0] = company.getComName(); |
| | | //数据项内容 |
| | | SeriesVo storeInfoSeries = new SeriesVo(); |
| | | storeInfoSeries.setName(company.getComName()); |
| | | //调用计算器获取数据库统计的结果 |
| | | Map<String, Integer> yAxisMap = caculate.exec(timeSpaceParam, null, company.getComId()); |
| | | //把统计结果转成数组格式 |
| | | storeInfoSeries.setData(StatisticsTimeUtil.getSeries(yAxisMap)); |
| | | series.add(storeInfoSeries); |
| | | |
| | | //构造返回对象 |
| | | Map<Object, Object> data = new HashMap<>(); |
| | | data.put("legendData", legendData); |
| | | data.put("series", series); |
| | | String[] xData = StatisticsTimeUtil.getFormartDateList(xAxis, statisticsParam); |
| | | data.put("xAxis", Arrays.copyOf(xData, xData.length - 1)); |
| | | result.setMapInfo(data); |
| | | result.setStatus(AjaxResult.STATUS_SUCCESS); |
| | | return result; |
| | | } |
| | | |
| | | public AjaxResult getStaffAnalysisResult(VipStatisticsParamDto statisticsParam, Caculate caculate) { |
| | | AjaxResult result = new AjaxResult(); |
| | | |
| | | //根据计算横坐标 |
| | | List<Date> xAxis = StatisticsTimeUtil.getTimeSpace(statisticsParam.getBeginTime(), statisticsParam.getEndTime(), statisticsParam.getStatisticsUnit()); |
| | | |
| | | //获取所有门店 |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | Long staffId = null; |
| | | if (statisticsParam.getStaffId() == null) { |
| | | staffId = user.getSuId(); |
| | | } else { |
| | | staffId = statisticsParam.getStaffId(); |
| | | } |
| | | SysUsers sysUsers = sysUsersDao.selectById(staffId); |
| | | |
| | | //定义数据项内容 |
| | | List<SeriesVo> series = new ArrayList<>(); |
| | | |
| | | //定义数据主体 |
| | | String[] legendData = new String[1]; |
| | | |
| | | int i = 0; |
| | | |
| | | //按门店统计数据 |
| | | List<StatisticsTimeDaoParam> timeSpaceParam = StatisticsTimeUtil.buidParam(xAxis); |
| | | |
| | | legendData[0] = sysUsers.getSuName(); |
| | | //数据项内容 |
| | | SeriesVo storeInfoSeries = new SeriesVo(); |
| | | storeInfoSeries.setName(sysUsers.getSuName()); |
| | | //调用计算器获取数据库统计的结果 |
| | | Map<String, Integer> yAxisMap = caculate.exec(timeSpaceParam, null, sysUsers.getSuId()); |
| | | //把统计结果转成数组格式 |
| | | storeInfoSeries.setData(StatisticsTimeUtil.getSeries(yAxisMap)); |
| | | series.add(storeInfoSeries); |
| | | |
| | | //构造返回对象 |
| | | Map<Object, Object> data = new HashMap<>(); |
| | | data.put("legendData", legendData); |
| | | data.put("series", series); |
| | | StatisticsParamVo statisticsParam1 = new StatisticsParamVo(); |
| | | statisticsParam1.setStatisticsUnit(statisticsParam.getStatisticsUnit()); |
| | | String[] xData = StatisticsTimeUtil.getFormartDateList(xAxis, statisticsParam1); |
| | | data.put("xAxis", Arrays.copyOf(xData, xData.length - 1)); |
| | | result.setMapInfo(data); |
| | | result.setStatus(AjaxResult.STATUS_SUCCESS); |
| | | return result; |
| | | } |
| | | } |