吴洪双 6 лет назад
Родитель
Сommit
fcbbd2d4eb

+ 20 - 0
src/main/java/com/shawn/constant/ChartType.java

@@ -0,0 +1,20 @@
+package com.shawn.constant;
+
+public enum ChartType {
+	/**
+	 * 日统计
+	 */
+	day,
+	/**
+	 * 周统计
+	 */
+	week,
+	/**
+	 * 月统计
+	 */
+	month,
+	/**
+	 * 年统计
+	 */
+	year
+}

+ 6 - 3
src/main/java/com/shawn/model/Bean/ChartBean.java

@@ -15,8 +15,11 @@ import lombok.experimental.Accessors;
 public class ChartBean {
 
     @ApiModelProperty(value="统计类目")
-    private String categories;
+    private String categorie;
 
-    @ApiModelProperty(value="数量")
-    private Integer seriesData;
+    @ApiModelProperty(value="销量")
+    private Integer saleNum;
+
+    @ApiModelProperty(value="销售额")
+    private Integer salePrice;
 }

+ 19 - 3
src/main/java/com/shawn/model/Bean/ChartColumn.java

@@ -21,13 +21,29 @@ public class ChartColumn {
     @ApiModelProperty(value="统计类目值")
     private ArrayList<ChartSerie> series;
 
-    public ChartColumn(ArrayList<String> categories,ArrayList<Integer> seriesDatas,String serieName){
+    public ChartColumn(List<ChartBean>  list){
+        ArrayList<String> categories = new ArrayList<>();
+        ArrayList<Integer> salePriceList = new ArrayList<>();
+        ArrayList<Integer> saleNumList = new ArrayList<>();
+
+        for (ChartBean bean :list) {
+            categories.add(bean.getCategorie());
+            saleNumList.add(bean.getSaleNum());
+            salePriceList.add(bean.getSalePrice());
+        }
+
         this.setCategories(categories);
         ChartSerie chartSerie = new ChartSerie();
-        chartSerie.setName(serieName);
-        chartSerie.setData(seriesDatas);
+        chartSerie.setName("销售个数");
+        chartSerie.setData(saleNumList);
+
+        ChartSerie chartSerie2 = new ChartSerie();
+        chartSerie2.setName("销售额");
+        chartSerie2.setData(salePriceList);
+
         ArrayList<ChartSerie> series = new ArrayList<>();
         series.add(chartSerie);
+        series.add(chartSerie2);
         this.setSeries(series);
     }
 }

+ 24 - 0
src/main/java/com/shawn/model/dto/TAdminDTO.java

@@ -0,0 +1,24 @@
+package com.shawn.model.dto;
+
+import com.shawn.model.entity.TAdmin;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+@Accessors(chain = true)
+@NoArgsConstructor
+@Getter
+@Setter
+@ToString
+public class TAdminDTO extends TAdmin {
+
+	@ApiModelProperty(value="设备列表")
+	private List<TEquipmentDTO> equipmentList;
+
+	private boolean ifShow = false;
+}

+ 56 - 0
src/main/java/com/shawn/model/dto/TEquipmentDTO.java

@@ -0,0 +1,56 @@
+package com.shawn.model.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.shawn.model.entity.TEquipment;
+import com.shawn.util.DateUtils;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+@Accessors(chain = true)
+@NoArgsConstructor
+@ToString
+public class TEquipmentDTO extends TEquipment {
+
+    @ApiModelProperty(value="最新报警信息")
+    private String alarmContent = "暂无数据";
+
+    @ApiModelProperty(value="当天是否存在告警")
+    private boolean hasTodayAlarm= false;
+
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value="报警发生时间")
+    private Date occurrenceTime;
+
+    public String getAlarmContent() {
+        return alarmContent;
+    }
+
+    public void setAlarmContent(String alarmContent) {
+        this.alarmContent = alarmContent;
+    }
+
+    public boolean isHasTodayAlarm() {
+        return hasTodayAlarm;
+    }
+
+    public void setHasTodayAlarm(boolean hasTodayAlarm) {
+        this.hasTodayAlarm = hasTodayAlarm;
+    }
+
+    public Date getOccurrenceTime() {
+        return occurrenceTime;
+    }
+
+    public void setOccurrenceTime(Date occurrenceTime) {
+        this.hasTodayAlarm = DateUtils.isSameDay(new Date(),occurrenceTime);
+        this.occurrenceTime = occurrenceTime;
+    }
+}

+ 32 - 0
src/main/java/com/shawn/model/param/StatisticsParam.java

@@ -0,0 +1,32 @@
+package com.shawn.model.param;
+
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+@Accessors(chain = true)
+@NoArgsConstructor
+@Getter
+@Setter
+@ToString
+public class StatisticsParam {
+    @ApiModelProperty(value="商家id")
+    private String adminId;
+
+    @ApiModelProperty(value="设备id")
+    private String equipmentId;
+
+    @ApiModelProperty(value="开始日期")
+    private String startDate;
+
+    @ApiModelProperty(value="结束日期")
+    private String endDate;
+
+    @ApiModelProperty(value="统计类型")
+    private String chartType;
+
+}

+ 6 - 1
src/main/java/com/shawn/repository/TAlarmRecordMapper.java

@@ -9,6 +9,11 @@ import com.shawn.model.entity.TAlarmRecord;
 import com.shawn.model.entity.TAlarmRecordExample;
 import com.shawn.model.param.TAlarmRecordParam;
 import com.shawn.repository.base.BaseDaoInterface;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface TAlarmRecordMapper extends BaseDaoInterface<TAlarmRecord,TAlarmRecordExample,TAlarmRecordParam, Long>{
-}
+
+    public List<TAlarmRecord> getLastAlarmRecord(@Param("adminId") Long adminId);
+}

+ 7 - 1
src/main/java/com/shawn/repository/TOrderMapper.java

@@ -8,6 +8,7 @@ package com.shawn.repository;
 import com.shawn.model.Bean.ChartBean;
 import com.shawn.model.entity.TOrder;
 import com.shawn.model.entity.TOrderExample;
+import com.shawn.model.param.StatisticsParam;
 import com.shawn.model.param.TOrderParam;
 import com.shawn.repository.base.BaseDaoInterface;
 
@@ -15,5 +16,10 @@ import java.util.List;
 
 public interface TOrderMapper extends BaseDaoInterface<TOrder,TOrderExample,TOrderParam, Long>{
 
-    public List<ChartBean> getProductSaleMonth(String userId);
+    public List<ChartBean> getDayStatistics(StatisticsParam param);
+    public List<ChartBean> getWeekStatistics(StatisticsParam param);
+    public List<ChartBean> getMonthStatistics(StatisticsParam param);
+    public List<ChartBean> getYearStatistics(StatisticsParam param);
+
+    public List<ChartBean> getMainStatistics(StatisticsParam param);
 }

+ 7 - 0
src/main/java/com/shawn/service/impl/TAlarmRecordServiceImpl.java

@@ -14,6 +14,9 @@ import com.shawn.model.param.TAlarmRecordParam;
 import com.shawn.repository.TAlarmRecordMapper;
 import com.shawn.service.base.BaseService;
 import com.shawn.service.interfac.TAlarmRecordServiceInterface;
+
+import java.util.List;
+
 @Service
 public class TAlarmRecordServiceImpl extends BaseService<TAlarmRecord,TAlarmRecordExample,TAlarmRecordParam,Long> implements TAlarmRecordServiceInterface{
 	@Autowired
@@ -28,4 +31,8 @@ public class TAlarmRecordServiceImpl extends BaseService<TAlarmRecord,TAlarmReco
 		return "TAlarmRecord";
 	}
 
+	@Override
+	public List<TAlarmRecord> getLastAlarmRecord(Long adminId){
+		return tAlarmRecordMapper.getLastAlarmRecord(adminId);
+	}
 }

+ 36 - 8
src/main/java/com/shawn/service/impl/TOrderServiceImpl.java

@@ -5,21 +5,25 @@
 
 package com.shawn.service.impl;
 
+import com.shawn.constant.ChartType;
 import com.shawn.model.Bean.ChartBean;
-import com.shawn.web.exception.MyException;
-import org.apache.commons.collections4.CollectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
+import com.shawn.model.Bean.ChartColumn;
 import com.shawn.model.entity.TOrder;
 import com.shawn.model.entity.TOrderExample;
+import com.shawn.model.param.StatisticsParam;
 import com.shawn.model.param.TOrderParam;
 import com.shawn.repository.TOrderMapper;
 import com.shawn.service.base.BaseService;
 import com.shawn.service.interfac.TOrderServiceInterface;
+import com.shawn.web.exception.MyException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
-
+@Slf4j
 @Service
 public class TOrderServiceImpl extends BaseService<TOrder,TOrderExample,TOrderParam,Long> implements TOrderServiceInterface{
 	@Autowired
@@ -35,8 +39,32 @@ public class TOrderServiceImpl extends BaseService<TOrder,TOrderExample,TOrderPa
 	}
 
 	@Override
-	public List<ChartBean> getProductSaleMonth(String userId){
-		List<ChartBean> list = tOrderMapper.getProductSaleMonth(userId);
+	public ChartColumn getStatistics(StatisticsParam param){
+
+		List<ChartBean> list = new ArrayList<>();
+		if(ChartType.day.toString().equals(param.getChartType())){
+			list = tOrderMapper.getDayStatistics(param);
+		}
+		if(ChartType.week.toString().equals(param.getChartType())){
+			list = tOrderMapper.getWeekStatistics(param);
+		}
+		if(ChartType.month.toString().equals(param.getChartType())){
+			list = tOrderMapper.getMonthStatistics(param);
+		}
+		if(ChartType.year.toString().equals(param.getChartType())){
+			list = tOrderMapper.getYearStatistics(param);
+		}
+
+		if(CollectionUtils.isEmpty(list)){
+			throw new MyException("获取数据为空");
+		}
+		ChartColumn chartColumn = new ChartColumn(list);
+		return chartColumn;
+	}
+
+	@Override
+	public List<ChartBean> getMainStatistics(StatisticsParam param){
+		List<ChartBean> list = tOrderMapper.getMainStatistics(param);
 		if(CollectionUtils.isEmpty(list)){
 			throw new MyException("获取数据为空");
 		}

+ 3 - 0
src/main/java/com/shawn/service/interfac/TAlarmRecordServiceInterface.java

@@ -10,5 +10,8 @@ import com.shawn.model.entity.TAlarmRecordExample;
 import com.shawn.model.param.TAlarmRecordParam;
 import com.shawn.service.base.BaseServiceInterface;
 
+import java.util.List;
+
 public interface TAlarmRecordServiceInterface extends BaseServiceInterface<TAlarmRecord,TAlarmRecordExample,TAlarmRecordParam,Long>{
+    public List<TAlarmRecord> getLastAlarmRecord(Long clientId);
 }

+ 5 - 1
src/main/java/com/shawn/service/interfac/TOrderServiceInterface.java

@@ -6,13 +6,17 @@
 package com.shawn.service.interfac;
 
 import com.shawn.model.Bean.ChartBean;
+import com.shawn.model.Bean.ChartColumn;
 import com.shawn.model.entity.TOrder;
 import com.shawn.model.entity.TOrderExample;
+import com.shawn.model.param.StatisticsParam;
 import com.shawn.model.param.TOrderParam;
 import com.shawn.service.base.BaseServiceInterface;
 
 import java.util.List;
 
 public interface TOrderServiceInterface extends BaseServiceInterface<TOrder,TOrderExample,TOrderParam,Long>{
-    public List<ChartBean> getProductSaleMonth(String userId);
+
+    public ChartColumn getStatistics(StatisticsParam param);
+    public List<ChartBean> getMainStatistics(StatisticsParam param);
 }

+ 1 - 0
src/main/java/com/shawn/web/controller/TAdminController.java

@@ -68,4 +68,5 @@ public class TAdminController extends BaseController<TAdmin,TAdminExample,TAdmin
 				.body(new ResultMessage().setCode(false).setData(null).setMessage("用户名或密码错误"));
 
 	}
+
 }

+ 77 - 4
src/main/java/com/shawn/web/controller/TEquipmentController.java

@@ -5,8 +5,18 @@
 
 package com.shawn.web.controller;
 
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
+import com.shawn.model.dto.TAdminDTO;
+import com.shawn.model.dto.TEquipmentDTO;
+import com.shawn.model.entity.TAdmin;
+import com.shawn.model.entity.TAlarmRecord;
+import com.shawn.service.interfac.TAdminServiceInterface;
+import com.shawn.service.interfac.TAlarmRecordServiceInterface;
+import com.shawn.util.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -17,7 +27,6 @@ import org.springframework.web.bind.annotation.RestController;
 
 import com.shawn.model.dto.ResultMessage;
 import com.shawn.web.controller.base.BaseController;
-import com.shawn.web.exception.MyException;
 import com.shawn.model.entity.TEquipment;
 import com.shawn.model.entity.TEquipmentExample;
 import com.shawn.model.param.TEquipmentParam;
@@ -31,6 +40,12 @@ public class TEquipmentController extends BaseController<TEquipment,TEquipmentEx
 	@Autowired
 	private TEquipmentServiceInterface tEquipmentService;
 	@Autowired
+	private TAdminServiceInterface tAdminService;
+	@Autowired
+	private TAlarmRecordServiceInterface tAlarmRecordService;
+
+
+	@Autowired
 	public TEquipmentController(TEquipmentServiceInterface service) {
 		super(service);
 	}
@@ -39,6 +54,64 @@ public class TEquipmentController extends BaseController<TEquipment,TEquipmentEx
 	protected TEquipmentExample createNewExample() {
 		return new TEquipmentExample();
 	}
-	
-    
+
+	@PostMapping("/getEquipmentListByUser")
+	public ResponseEntity<?> getEquipmentListByUser(@RequestBody TAdmin param) {
+
+		List<TAdminDTO> resultList = new ArrayList<>();
+
+		if("admin".equals(param.getUsername())){ // 管理员查所有商家
+			List<TAdmin> adminList = tAdminService.selectByOption(null);
+			List<TEquipment> equipmentList = tEquipmentService.selectByOption(null);
+			List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(null);
+
+			resultList = adminList.stream().map(e ->{
+				TAdminDTO dto = new TAdminDTO();
+				BeanUtils.copyPropertiesIgnoreNull(e,dto,true);
+
+				List<TEquipmentDTO> selList =  equipmentList.stream()
+						.filter(equipment ->e.getId().equals(equipment.getAdminId())) // 查对应的设备
+						.map(equipment -> {
+							TEquipmentDTO equipmentDTO = new TEquipmentDTO();
+							BeanUtils.copyPropertiesIgnoreNull(equipment,equipmentDTO,true);
+							Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
+							if(op.isPresent()){
+								equipmentDTO.setAlarmContent(op.get().getAlarmContent());
+								equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
+							}
+							return equipmentDTO;
+						}).collect(Collectors.toList());
+				dto.setEquipmentList(selList);
+				return dto;
+			}).collect(Collectors.toList());
+		}else{ // 只查当前商家的设备列表
+			TAdminDTO dto = new TAdminDTO();
+			BeanUtils.copyPropertiesIgnoreNull(param,dto,true);
+			TEquipmentExample example = new TEquipmentExample();
+			TEquipmentExample.Criteria criteria = example.createCriteria();
+			criteria.andAdminIdEqualTo(param.getId());
+			List<TEquipment> equipmentList = tEquipmentService.selectByOption(example);
+			List<TAlarmRecord> alarmRecordList = tAlarmRecordService.getLastAlarmRecord(param.getId());
+
+			List<TEquipmentDTO> equipmentDTOList = equipmentList.stream().map(equipment -> {
+				TEquipmentDTO equipmentDTO = new TEquipmentDTO();
+				BeanUtils.copyPropertiesIgnoreNull(equipment,equipmentDTO,true);
+				Optional<TAlarmRecord> op = alarmRecordList.stream().filter(alarm -> equipment.getClientId().equals(alarm.getClientId())).findFirst();
+				if(op.isPresent()){
+					equipmentDTO.setAlarmContent(op.get().getAlarmContent());
+					equipmentDTO.setOccurrenceTime(op.get().getOccurrenceTime());
+
+				}
+				return equipmentDTO;
+			}).collect(Collectors.toList());
+
+			dto.setEquipmentList(equipmentDTOList);
+			resultList.add(dto);
+		}
+		resultList.get(0).setIfShow(true);
+
+		return ResponseEntity.status(HttpStatus.OK)
+				.body(new ResultMessage().setCode(true).setData(resultList).setMessage("SUCCESS"));
+
+	}
 }

+ 20 - 18
src/main/java/com/shawn/web/controller/TOrderController.java

@@ -6,11 +6,11 @@
 package com.shawn.web.controller;
 
 import java.util.*;
-import java.util.stream.Collectors;
 
 import com.shawn.model.Bean.ChartBean;
 import com.shawn.model.Bean.ChartColumn;
-import com.shawn.model.Bean.ChartSerie;
+import com.shawn.model.param.StatisticsParam;
+import com.shawn.util.FgObjectUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -19,13 +19,11 @@ import org.springframework.web.bind.annotation.*;
 
 import com.shawn.model.dto.ResultMessage;
 import com.shawn.web.controller.base.BaseController;
-import com.shawn.web.exception.MyException;
 import com.shawn.model.entity.TOrder;
 import com.shawn.model.entity.TOrderExample;
 import com.shawn.model.param.TOrderParam;
 import com.shawn.service.interfac.TOrderServiceInterface;
 
-import lombok.extern.apachecommons.CommonsLog;
 @Slf4j
 @RestController
 @RequestMapping("TOrder")
@@ -43,20 +41,11 @@ public class TOrderController extends BaseController<TOrder,TOrderExample,TOrder
 	}
 
 
-	@GetMapping("/getProductSaleMonth")
-	public ResponseEntity<?> getProductSaleMonth(String userId) {
-		log.info("userId:{}", userId);
-		List<ChartBean> list = tOrderService.getProductSaleMonth(userId);
-		ArrayList<String> categories = new ArrayList<>();
-		ArrayList<Integer> seriesDatas = new ArrayList<>();
-
-		for (ChartBean bean :list) {
-			categories.add(bean.getCategories());
-			seriesDatas.add(bean.getSeriesData());
-		}
-
-
-		ChartColumn chartColumn = new ChartColumn(categories,seriesDatas,"当月销量");
+	@PostMapping("/getStatistics")
+	public ResponseEntity<?> getStatistics(@RequestBody StatisticsParam param) {
+		log.info("param:{}", param);
+		FgObjectUtil.objectNullOrEmptySel(param, "chartType$");
+		ChartColumn chartColumn  = tOrderService.getStatistics(param);
 
 		return ResponseEntity
 				.status(HttpStatus.OK)
@@ -65,4 +54,17 @@ public class TOrderController extends BaseController<TOrder,TOrderExample,TOrder
 						.setData(chartColumn)
 						.setMessage("SUCCESS"));
 	}
+
+	@PostMapping("/getMainStatistics")
+	public ResponseEntity<?> getMainStatistics(@RequestBody StatisticsParam param) {
+		return ResponseEntity
+				.status(HttpStatus.OK)
+				.body(new ResultMessage()
+						.setCode(true)
+						.setData(tOrderService.getMainStatistics(param))
+						.setMessage("SUCCESS"));
+	}
+
+
+
 }

+ 16 - 1
src/main/resources/com/shawn/repository/mybatis/TAlarmRecordMapper.xml

@@ -460,4 +460,19 @@
       #{item}
     </foreach>
   </update>
-</mapper>
+
+  <!-- 获取最新警告-->
+  <select id="getLastAlarmRecord" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    select * from t_alarm_record b where EXISTS(
+  select * from (
+  select a.client_id,max(a.create_date) as create_date
+  from t_alarm_record a
+  where 1=1
+    <if test="adminId != null and adminId !=''">
+    and a.admin_id = #{adminId}
+    </if>
+  group by a.client_id)
+  tab1 where b.client_id = tab1.client_id and b.create_date = tab1.create_date
+  )
+  </select>
+</mapper>

+ 126 - 9
src/main/resources/com/shawn/repository/mybatis/TOrderMapper.xml

@@ -31,8 +31,9 @@
   </resultMap>
 
   <resultMap id="chartBean" type="com.shawn.model.Bean.ChartBean">
-    <result column="categories" jdbcType="VARCHAR" property="categories" />
-    <result column="seriesData" jdbcType="INTEGER" property="seriesData" />
+    <result column="categorie" jdbcType="VARCHAR" property="categorie" />
+    <result column="saleNum" jdbcType="INTEGER" property="saleNum" />
+    <result column="salePrice" jdbcType="DECIMAL" property="salePrice" />
   </resultMap>
 
 
@@ -654,12 +655,128 @@
       #{item}
     </foreach>
   </update>
-  <select id="getProductSaleMonth" resultMap="chartBean" parameterType="java.lang.String">
-    select a.product_name as categories,count(1) as seriesData from t_order a where 1=1
-    and DATE_FORMAT( a.create_date,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
-    and a.admin_id='56'
-    <!-- and a.admin_id=#{userId} -->
-    group by a.product_name
-    order by seriesData desc
+  <!-- 日统计 -->
+  <select id="getDayStatistics" resultMap="chartBean" parameterType="com.shawn.model.param.StatisticsParam">
+    select concat(DATE_FORMAT( a.create_date,'%H'),'点') as categorie,count(1) as saleNum,sum(a.price) as salePrice from t_order a
+    where a.status='1' -- 支付成功
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+    and DATE_FORMAT( a.create_date,'%Y/%m/%d') = #{startDate}
+    group by DATE_FORMAT( a.create_date,'%H')
+    order by categorie
+  </select>
+
+  <!-- 周统计 -->
+  <select id="getWeekStatistics" resultMap="chartBean" parameterType="com.shawn.model.param.StatisticsParam">
+    SELECT tab1.categorie,ifnull(tab2.saleNum,0) as saleNum,ifnull(tab2.salePrice,0) as salePrice from (
+    select '周1' as categorie from dual UNION all
+    select '周2' as categorie from dual UNION all
+    select '周3' as categorie from dual UNION all
+    select '周4' as categorie from dual UNION all
+    select '周5' as categorie from dual UNION all
+    select '周6' as categorie from dual UNION all
+    select '周日' as categorie from dual) tab1
+    left join (
+    select case DATE_FORMAT( a.create_date,'%w') when 0 then '周日' else CONCAT('周',DATE_FORMAT( a.create_date,'%w')) end as categorie,
+    count(1) as saleNum,sum(a.price) as salePrice from t_order a
+    where a.status='1' -- 支付成功
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+      AND a.create_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
+      <![CDATA[ AND a.create_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
+    group by DATE_FORMAT( a.create_date,'%w')
+    ) tab2 on tab1.categorie = tab2.categorie
+  </select>
+
+  <!-- 月统计 -->
+  <select id="getMonthStatistics" resultMap="chartBean" parameterType="com.shawn.model.param.StatisticsParam">
+    select DATE_FORMAT( a.create_date,'%m月%d') as categorie,count(1) as saleNum,sum(a.price) as salePrice from t_order a
+    where a.status='1' -- 支付成功
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+    AND a.create_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
+    <![CDATA[ AND a.create_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
+    group by DATE_FORMAT( a.create_date,'%m月%d')
+  </select>
+
+  <!-- 年统计 -->
+  <select id="getYearStatistics" resultMap="chartBean" parameterType="com.shawn.model.param.StatisticsParam">
+    SELECT tab1.categorie,ifnull(tab2.saleNum,0) as saleNum,ifnull(tab2.salePrice,0) as salePrice from (
+    select '01月' as categorie from dual UNION all
+    select '02月' as categorie from dual UNION all
+    select '03月' as categorie from dual UNION all
+    select '04月' as categorie from dual UNION all
+    select '05月' as categorie from dual UNION all
+    select '06月' as categorie from dual UNION all
+    select '07月' as categorie from dual UNION all
+    select '08月' as categorie from dual UNION all
+    select '09月' as categorie from dual UNION all
+    select '10月' as categorie from dual UNION all
+    select '11月' as categorie from dual UNION all
+    select '12月' as categorie from dual) tab1
+    left join (
+    select concat(DATE_FORMAT( a.create_date,'%m'),'月') as categorie,count(1) as saleNum,sum(a.price) as salePrice from t_order a
+    where a.status='1' -- 支付成功
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+    AND a.create_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
+    <![CDATA[ AND a.create_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
+    group by DATE_FORMAT( a.create_date,'%m')
+    ) tab2 on tab1.categorie = tab2.categorie
+  </select>
+
+  <!-- 汇总统计-->
+  <select id="getMainStatistics" resultMap="chartBean">
+    select 'day' as categorie, count(1) as saleNum,ifnull(sum(a.price),0) as salePrice from t_order a
+where date_format(a.create_date,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+UNION all
+select 'week' as categorie, count(1) as saleNum,ifnull(sum(a.price),0) as salePrice from t_order a
+where YEARWEEK(date_format(a.create_date,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+UNION all
+select 'month' as categorie, count(1) as saleNum,ifnull(sum(a.price),0) as salePrice from t_order a
+where date_format(a.create_date,'%Y-%m') = date_format(now(),'%Y-%m')
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
+UNION all
+select 'year' as categorie, count(1) as saleNum,ifnull(sum(a.price),0) as salePrice from t_order a
+where date_format(a.create_date,'%Y') = date_format(now(),'%Y')
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId} -- 所属商家id
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId} -- 设备id
+    </if>
   </select>
 </mapper>