曲线图 根据时间分段查询数据示例

本文介绍了一个用于门店数据报表分析的服务实现。该服务可以根据不同的时间维度(如今天、昨天、近七天等)获取门店的销售单数、营业额、历史单日最高及平均营业额等关键指标,并提供曲线图数据辅助分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

示例代码如下:

package com.hongware.o2o.api.bussiness.openApi.service.mobile.form;




import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

import java.util.Vector;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bstek.bdf2.core.context.ContextHolder;
import com.hongware.o2o.api.bussiness.openApi.bean.baseBean.DynamicResWapper;
import com.hongware.o2o.api.bussiness.openApi.bean.mobileBean.channel.MobileCommonRes;
import com.hongware.o2o.api.bussiness.openApi.service.base.DynamicBaseService;
import com.hongware.o2o.api.bussiness.openApi.service.base.MobileErpBaseService;
import com.hongware.o2o.api.bussiness.openApi.service.base.MobileErpService;
import com.hongware.o2o.api.bussiness.openApi.util.ModeResponseUtil;
import com.hongware.o2o.api.bussiness.openApi.util.OpenApiContants;
import com.hongware.o2o.api.bussiness.openApi.util.ResponseValidUtil;
import com.hongware.shopware5.entity.channel.TTradeFlowRecord;
import com.hongware.shopware5.entity.inventory.TWarehouse;
import com.hongware.shopware5.entity.order.TSalesOrder;
/**
 * function:数据报表-门店
 * date:2018-04-02
 * author:Paul
 * @param type 类型 查询条件 必填
 * @param startDate 开始日期 (选填)
 * @param endDate 结束日期(选填)
 * */
@Service
public class MobileStoreDataReportService extends DynamicBaseService{
	@Resource
	private MobileErpService mobileErpService;
	private static String METHOD = "V5.mobile.store.data.report";
	
	@SuppressWarnings("unchecked")
	@Override
	public DynamicResWapper excute(String nick, String bindKey, String hwwork,
			Map requestParams) {
		MobileCommonRes res = new MobileCommonRes();
		res.setIsSuccess(false);
		TimeToolClass timeToolClass=new TimeToolClass();//得到获取时间的工具类
		try {
			String orgCode = (String)requestParams.get("orgCode");
			String store = String.valueOf(OpenApiContants.shiftEncode(requestParams.get("store"), String.class));
			String op = String.valueOf(OpenApiContants.shiftEncode(requestParams.get("op"), String.class));
			String type = String.valueOf(OpenApiContants.shiftEncode(requestParams.get("type"), String.class));
			Vector<String> vector = null;
			vector = ResponseValidUtil.validParameter(orgCode, "orgCode", vector);
			vector = ResponseValidUtil.validParameter(store, "store", vector);
			vector = ResponseValidUtil.validParameter(op, "op", vector);
			vector = ResponseValidUtil.validParameter(type, "type", vector);
			if(vector!=null){
				return ModeResponseUtil.genDynamicResWapper(this, METHOD, vector);
			}
			MobileErpBaseService mobileErpBaseService=(MobileErpBaseService)ContextHolder.getBean("mobileErpBaseService");
			mobileErpBaseService.setBindKey(orgCode);
			mobileErpBaseService.loadUserByUsername(op);
			mobileErpService.createTLogs("数据报表-门店", op,op);
			String mindianSql="from TWarehouse where isDeleted=0 and isDepot=1 and name='"+store+"'";
			//门店的ID
			TWarehouse tWarehouse= (TWarehouse) mobileErpService.getBaseHibernateService().getSession().createQuery(mindianSql).uniqueResult();
			if (tWarehouse!=null) {
				if ("today".equals(type)) {//今日
					Map mapTime=timeToolClass.getToday();//得到今日的时间
					Map mapTime1=timeToolClass.getToday1();//得到今日的时间 不带时分秒
					//今日销售总单数
					String xiaoshouSql="select COUNT(memberId) from T_SalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
					Object obj1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(xiaoshouSql).uniqueResult();
					String sales=obj1.toString();
					//今日营业额度(实际交易金额)
					double turnover=0.00;
					String xiaoshouSql1="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
					List<TSalesOrder> listTS= mobileErpService.getBaseHibernateService().getSession().createQuery(xiaoshouSql1).list();
					for (TSalesOrder tSalesOrder : listTS) {
						List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
						for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
							turnover+=tTradeFlowRecord.getAmount();
						}
					}
					//历史单日最高
					String danrizuigao="select SUM(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
					List list= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danrizuigao).list();
					double theHighesSingleDay = Collections.max(list);
					//历史单日平均
					String danripingjun="select AVG(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
					List list1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danripingjun).list();
					double singleDayAverage = Collections.max(list1);
					Map map=new HashMap();
					//曲线图的数据--------------------------------------------
					//用来判断当前时间小时   是偶数或奇数  因为曲线图时间每两小时统计一次
					double curveTurnover=0.00;//曲线图的额度
					List listMapA=new ArrayList();
					List listMapB=new ArrayList();
					int dangqian= timeToolClass.getDangqian();//获取当前小时
					for (int i = 0; i < 7; i++) {//循环七次 
					if (dangqian%2==0) {//如果当前小时是偶数
							if (dangqian==0) {//如果当前时间为0点 那么直接结束
								break;
							}else {
								if (dangqian==2||dangqian==4||dangqian==6||dangqian==8) {
									String after="0"+dangqian;//记录最新最后的时间 (查询结束时间)
									dangqian-=2;
									String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime1.get("start")+" 0"+dangqian+":00:00"+"' and postDate<'"+mapTime1.get("end")+" "+after+":00:00"+"'";
									List<TSalesOrder> listT= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
									for (TSalesOrder tSalesOrder : listT) {
										List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
										for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
											curveTurnover+=tTradeFlowRecord.getAmount();
										}
									}
									listMapA.add(curveTurnover);
									curveTurnover=0.00;
									listMapB.add(after);
								}else {
									String after=""+dangqian;//记录最新最后的时间 (查询结束时间)
									dangqian-=2;
									String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime1.get("start")+" "+dangqian+":00:00"+"' and postDate<'"+mapTime1.get("end")+" "+after+":00:00"+"'";
									List<TSalesOrder> listT= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
									for (TSalesOrder tSalesOrder : listT) {
										List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
										for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
											curveTurnover+=tTradeFlowRecord.getAmount();
										}
									}
									listMapA.add(curveTurnover);
									curveTurnover=0.00;
									listMapB.add(after);
								}
							}
					}else {//如果当前小时不是偶数
							if (dangqian==0||dangqian==1) {//如果当前时间为0点 那么直接结束
								break;
							}else {
								dangqian-=1;
								if (dangqian==2||dangqian==4||dangqian==6||dangqian==8) {
									String after="0"+dangqian;//记录最新最后的时间 (查询结束时间)
									dangqian-=2;
									String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime1.get("start")+" 0"+dangqian+":00:00"+"' and postDate<'"+mapTime1.get("end")+" "+after+":00:00"+"'";
									List<TSalesOrder> listT= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
									for (TSalesOrder tSalesOrder : listT) {
										List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
										for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
											curveTurnover+=tTradeFlowRecord.getAmount();
										}
									}
									listMapA.add(curveTurnover);
									curveTurnover=0.00;
									listMapB.add(after);
								}else {
									String after=""+dangqian;//记录最新最后的时间 (查询结束时间)
									dangqian-=2;
									String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime1.get("start")+" "+dangqian+":00:00"+"' and postDate<'"+mapTime1.get("end")+" "+after+":00:00"+"'";
									List<TSalesOrder> listT= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
									for (TSalesOrder tSalesOrder : listT) {
										List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
										for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
											curveTurnover+=tTradeFlowRecord.getAmount();
										}
									}
									listMapA.add(curveTurnover);
									curveTurnover=0.00;
									listMapB.add(after);
									
								}
							}
						}
					}
					//曲线图数据结束--------------------------------------------------
					//保留两位小数点 double
					turnover = (double) Math.round(turnover * 100) / 100;
					theHighesSingleDay = (double) Math.round(theHighesSingleDay * 100) / 100;
					singleDayAverage = (double) Math.round(singleDayAverage * 100) / 100;
					map.put("sales", sales);
					map.put("turnover", turnover);
					map.put("theHighesSingleDay", theHighesSingleDay);
					map.put("singleDayAverage", singleDayAverage);
					//曲线图数据
					//统一list排序  前端取值方便
					Collections.reverse(listMapA);
					Collections.reverse(listMapB);
					map.put("listMapA", listMapA);
					map.put("listMapB", listMapB);
					map.put("start", mapTime1.get("start"));
					map.put("end", mapTime1.get("end"));
					res.setData(map);
					res.setIsSuccess(true);
				}else {
					if ("yesterday".equals(type)) {//昨日
						Map mapTime= timeToolClass.getYesterday();//得到昨日的时间
						Map mapTime1= timeToolClass.getYesterday1();//得到昨日的时间 不帶時分秒
						//昨日销售总单数
						String xiaoshouSql="select COUNT(memberId) from T_SalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
						Object obj1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(xiaoshouSql).uniqueResult();
						String sales=obj1.toString();
						//今日营业额度(实际交易金额)
						double turnover=0.00;
						String xiaoshouSql1="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
						List<TSalesOrder> listTS= mobileErpService.getBaseHibernateService().getSession().createQuery(xiaoshouSql1).list();
						for (TSalesOrder tSalesOrder : listTS) {
							List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
							for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
								turnover+=tTradeFlowRecord.getAmount();
							}
						}
						//历史单日最高
						String danrizuigao="select SUM(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
						List list= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danrizuigao).list();
						double theHighesSingleDay = Collections.max(list);
						//历史单日平均
						String danripingjun="select AVG(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
						List list1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danripingjun).list();
						double singleDayAverage = Collections.max(list1);
						Map map=new HashMap();
						//曲线图数据---------------------------------------------------
						double curveTurnover=0.00;//曲线图的额度
						List listMapA=new ArrayList();
						List listMapB=new ArrayList();
						int dat=0;//记录开始的日期
						for (int j = 0; j < 12; j++) {
							int d= dat+2;
							if (dat==0||dat==2||dat==4||dat==6||dat==8) {
								String a="";
								if (d==0||d==2||d==4||d==6||d==8) {
									a="0"+d;
								}else {
									a=""+d;
								}
								String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime1.get("start")+" 0"+dat+":00:00"+"' and postDate<'"+mapTime1.get("end")+" "+a+":00:00"+"'";
								List<TSalesOrder> listT= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
								for (TSalesOrder tSalesOrder : listT) {
									List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
									for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
										curveTurnover+=tTradeFlowRecord.getAmount();
									}
								}
								listMapA.add(curveTurnover);
								curveTurnover=0.00;//每次统计完把额度清零
								listMapB.add(a);
								dat=d;//把自加2的时间 赋值给开始时间
							}else {
								String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime1.get("start")+" "+dat+":00:00"+"' and postDate<'"+mapTime1.get("end")+" "+d+":00:00"+"'";
								List<TSalesOrder> listT= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
								for (TSalesOrder tSalesOrder : listT) {
									List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
									for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
										curveTurnover+=tTradeFlowRecord.getAmount();
									}
								}
								listMapA.add(curveTurnover);
								curveTurnover=0.00;//每次统计完把额度清零
								listMapB.add(d);
								dat=d;//把自加2的时间 赋值给开始时间
							}
						}
						//---------------------------------------------------------
						//保留两位小数点 double
						turnover = (double) Math.round(turnover * 100) / 100;
						theHighesSingleDay = (double) Math.round(theHighesSingleDay * 100) / 100;
						singleDayAverage = (double) Math.round(singleDayAverage * 100) / 100;
						map.put("sales", sales);
						map.put("turnover", turnover);
						map.put("theHighesSingleDay", theHighesSingleDay);
						map.put("singleDayAverage", singleDayAverage);
						map.put("listMapA", listMapA);
						map.put("listMapB", listMapB);
						map.put("start", mapTime1.get("start"));
						map.put("end", mapTime1.get("end"));
						res.setData(map);
						res.setIsSuccess(true);
					}else {
						if ("sevenDays".equals(type)) {//近七天
							Map mapTime= timeToolClass.getSevenDays();//得到近七天的时间
							Map mapTime1= timeToolClass.getSevenDays1();//得到近七天的时间
							//销售总单数
							String xiaoshouSql="select COUNT(memberId) from T_SalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
							Object obj1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(xiaoshouSql).uniqueResult();
							String sales=obj1.toString();
							//今日营业额度(实际交易金额)
							double turnover=0.00;
							String xiaoshouSql1="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
							List<TSalesOrder> listTS= mobileErpService.getBaseHibernateService().getSession().createQuery(xiaoshouSql1).list();
							for (TSalesOrder tSalesOrder : listTS) {
								List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
								for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
									turnover+=tTradeFlowRecord.getAmount();
								}
							}
							//历史单日最高
							String danrizuigao="select SUM(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
							List list= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danrizuigao).list();
							double theHighesSingleDay = Collections.max(list);
							//历史单日平均
							String danripingjun="select AVG(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
							List list1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danripingjun).list();
							double singleDayAverage = Collections.max(list1);
							Map map=new HashMap();
							//曲线图数据------往前推七天-----------------------------
							List listMapA=new ArrayList();
							List listMapB=new ArrayList();
							double quxianReceipts=0.00;
							for (int i = 1; i < 8; i++) {
								String start= timeToolClass.getForwardDate(i)+" 00:00:00";
								String end= timeToolClass.getForwardDate(i)+" 23:59:59";
								String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+start+"' and postDate<'"+end+"'";
								List<TSalesOrder> listt= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
								for (TSalesOrder tSalesOrder : listt) {
									List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
									for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
										quxianReceipts+=tTradeFlowRecord.getAmount();
									}
								}
								listMapB.add(timeToolClass.getForwardDate(i));
								listMapA.add(quxianReceipts);
								quxianReceipts=0.00;
							}
							//---------------------------------------------------------
							//保留两位小数点 double
							turnover = (double) Math.round(turnover * 100) / 100;
							theHighesSingleDay = (double) Math.round(theHighesSingleDay * 100) / 100;
							singleDayAverage = (double) Math.round(singleDayAverage * 100) / 100;
							map.put("sales", sales);
							//统一list排序  前端取值方便
							Collections.reverse(listMapA);
							Collections.reverse(listMapB);
							map.put("listMapA", listMapA);
							map.put("listMapB", listMapB);
							map.put("turnover", turnover);
							map.put("theHighesSingleDay", theHighesSingleDay);
							map.put("singleDayAverage", singleDayAverage);
							map.put("start", mapTime1.get("start"));
							map.put("end", mapTime1.get("end"));
							res.setData(map);
							res.setIsSuccess(true);
						}else {
							if ("thirtyDays".equals(type)) {//近三十天
								Map mapTime= timeToolClass.getThirtyDays();//得到近三十天的时间
								Map mapTime1= timeToolClass.getThirtyDays1();//得到近三十天的时间
								//销售总单数
								String xiaoshouSql="select COUNT(memberId) from T_SalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
								Object obj1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(xiaoshouSql).uniqueResult();
								String sales=obj1.toString();
								//今日营业额度(实际交易金额)
								double turnover=0.00;
								String xiaoshouSql1="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+mapTime.get("start")+"' and postDate<'"+mapTime.get("end")+"'";
								List<TSalesOrder> listTS= mobileErpService.getBaseHibernateService().getSession().createQuery(xiaoshouSql1).list();
								for (TSalesOrder tSalesOrder : listTS) {
									List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
									for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
										turnover+=tTradeFlowRecord.getAmount();
									}
								}
								//历史单日最高
								String danrizuigao="select SUM(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
								List list= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danrizuigao).list();
								double theHighesSingleDay = Collections.max(list);
								//历史单日平均
								String danripingjun="select AVG(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
								List list1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danripingjun).list();
								double singleDayAverage = Collections.max(list1);
								Map map=new HashMap();
								//曲线图数据--------往前推30天---------------------------
								List listMapA=new ArrayList();
								List listMapB=new ArrayList();
								double quxianReceipts=0.00;
								for (int i = 1; i < 31; i++) {
									String start= timeToolClass.getForwardDate(i)+" 00:00:00";
									String end= timeToolClass.getForwardDate(i)+" 23:59:59";
									String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+start+"' and postDate<'"+end+"'";
									List<TSalesOrder> listt= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
									for (TSalesOrder tSalesOrder : listt) {
										List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
										for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
											quxianReceipts+=tTradeFlowRecord.getAmount();
										}
									}
									listMapB.add(timeToolClass.getForwardDate(i));
									listMapA.add(quxianReceipts);
									quxianReceipts=0.00;
								}
								//---------------------------------------------------
								//保留两位小数点 double
								turnover = (double) Math.round(turnover * 100) / 100;
								theHighesSingleDay = (double) Math.round(theHighesSingleDay * 100) / 100;
								singleDayAverage = (double) Math.round(singleDayAverage * 100) / 100;
								map.put("sales", sales);
								//统一list排序  前端取值方便
								Collections.reverse(listMapA);
								Collections.reverse(listMapB);
								map.put("listMapA", listMapA);
								map.put("listMapB", listMapB);
								map.put("turnover", turnover);
								map.put("start", mapTime1.get("start"));
								map.put("end", mapTime1.get("end"));
								map.put("theHighesSingleDay", theHighesSingleDay);
								map.put("singleDayAverage", singleDayAverage);
								res.setData(map);
								res.setIsSuccess(true);
							}else {
								if ("custom".equals(type)) {//自定义时间 接收时间段
									String startDateA = String.valueOf(OpenApiContants.shiftEncode(requestParams.get("startDate"),String.class));
									String endDateA = String.valueOf(OpenApiContants.shiftEncode(requestParams.get("endDate"),String.class));
									String startDate=startDateA+" 00:00:00";
									String endDate=endDateA+" 23:59:59";
									if ("".equals(startDateA)||"".equals(endDateA)) {
										return genDynamicResWapper("502", METHOD, "请输入开始或结束日期");
									}else {
										//比较两个日期相差多少天 不能大于三十天
										if (timeToolClass.getDifference(startDateA, endDateA)>30) {
											return genDynamicResWapper("502", METHOD, "两个日期之间不能大于三十天");
										}else {
											//今日销售总单数
											String xiaoshouSql="select COUNT(memberId) from T_SalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+startDate+"' and postDate<'"+endDate+"'";
											Object obj1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(xiaoshouSql).uniqueResult();
											String sales=obj1.toString();
											//今日营业额度(实际交易金额)
											double turnover=0.00;
											String xiaoshouSql1="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+startDate+"' and postDate<'"+endDate+"'";
											List<TSalesOrder> listTS= mobileErpService.getBaseHibernateService().getSession().createQuery(xiaoshouSql1).list();
											for (TSalesOrder tSalesOrder : listTS) {
												List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
												for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
													turnover+=tTradeFlowRecord.getAmount();
												}
											}
											//历史单日最高
											String danrizuigao="select SUM(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
											List list= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danrizuigao).list();
											double theHighesSingleDay = Collections.max(list);
											//历史单日平均
											String danripingjun="select AVG(actualAmount) FROM t_salesorder GROUP BY DAY(postDate)";
											List list1= mobileErpService.getBaseHibernateService().getSession().createSQLQuery(danripingjun).list();
											double singleDayAverage = Collections.max(list1);
											Map map=new HashMap();
											//曲线图数据--------往前推自定义---------------------------
											List listMapA=new ArrayList();
											List listMapB=new ArrayList();
											double quxianReceipts=0.00;
											//获取两个日期之间的日子 集合
											List<Date> listDate= timeToolClass.getBetweenDates(timeToolClass.getTransformation(startDateA), timeToolClass.getTransformation(endDateA));
											for (Date date : listDate) {
												String start=timeToolClass.getTransformationString(date)+" 00:00:00";
												String end=timeToolClass.getTransformationString(date)+" 23:59:59";
												String sql="from TSalesOrder where warehouseId="+tWarehouse.getWarehouseId()+" and statusId=10 and o2oStatusId=6 and postDate>='"+start+"' and postDate<'"+end+"'";
												List<TSalesOrder> listt= mobileErpService.getBaseHibernateService().getSession().createQuery(sql).list();
												for (TSalesOrder tSalesOrder : listt) {
													List<TTradeFlowRecord> tradeFlowRecord=  mobileErpService.getBaseHibernateService().getSession().createQuery("from TTradeFlowRecord where orderNumber='"+tSalesOrder.getOrderNumber()+"'").list();
													for (TTradeFlowRecord tTradeFlowRecord : tradeFlowRecord) {
														quxianReceipts+=tTradeFlowRecord.getAmount();
													}
												}
												listMapB.add(timeToolClass.getTransformationString(date));
												listMapA.add(quxianReceipts);
												quxianReceipts=0.00;
											}
											//----------------------------------------------------
											//保留两位小数点 double
											turnover = (double) Math.round(turnover * 100) / 100;
											theHighesSingleDay = (double) Math.round(theHighesSingleDay * 100) / 100;
											singleDayAverage = (double) Math.round(singleDayAverage * 100) / 100;
											map.put("sales", sales);
											map.put("listMapA", listMapA);
											map.put("listMapB", listMapB);
											map.put("turnover", turnover);
											map.put("theHighesSingleDay", theHighesSingleDay);
											map.put("singleDayAverage", singleDayAverage);
											res.setData(map);
											res.setIsSuccess(true);
										}
									}
								}else {
									return genDynamicResWapper("502", METHOD, "传入type类型错误");
								}
							}
						}
					}
				}
			}else {
				return genDynamicResWapper("502", METHOD, "没有此门店信息");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return genDynamicResWapper("502", METHOD, e.getMessage());
		}
		return res;
	}
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

国产野马

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值