Sfoglia il codice sorgente

获取随机,定时清洗次数

李天标 5 anni fa
parent
commit
2c635f36ae

+ 25 - 0
src/main/java/com/shawn/model/Bean/UseBean.java

@@ -0,0 +1,25 @@
+package com.shawn.model.Bean;
+
+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 UseBean {
+
+    @ApiModelProperty(value="统计类目")
+    private String categorie;
+
+    @ApiModelProperty(value="随机清洗次数")
+    private Integer randomTimes;
+
+    @ApiModelProperty(value="定时清洗次数")
+    private Integer regularTimes;
+}

+ 5 - 0
src/main/java/com/shawn/repository/TCleanHistoryMapper.java

@@ -5,10 +5,15 @@
 
 package com.shawn.repository;
 
+import com.shawn.model.Bean.UseBean;
 import com.shawn.model.entity.TCleanHistory;
 import com.shawn.model.entity.TCleanHistoryExample;
+import com.shawn.model.param.StatisticsParam;
 import com.shawn.model.param.TCleanHistoryParam;
 import com.shawn.repository.base.BaseDaoInterface;
 
+import java.util.List;
+
 public interface TCleanHistoryMapper extends BaseDaoInterface<TCleanHistory,TCleanHistoryExample,TCleanHistoryParam, Long>{
+    List<UseBean> getMainStatistics(StatisticsParam param);
 }

+ 17 - 0
src/main/java/com/shawn/service/impl/TCleanHistoryServiceImpl.java

@@ -5,6 +5,11 @@
 
 package com.shawn.service.impl;
 
+import com.shawn.model.Bean.ChartBean;
+import com.shawn.model.Bean.UseBean;
+import com.shawn.model.param.StatisticsParam;
+import com.shawn.web.exception.MyException;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -14,6 +19,9 @@ import com.shawn.model.param.TCleanHistoryParam;
 import com.shawn.repository.TCleanHistoryMapper;
 import com.shawn.service.base.BaseService;
 import com.shawn.service.interfac.TCleanHistoryServiceInterface;
+
+import java.util.List;
+
 @Service
 public class TCleanHistoryServiceImpl extends BaseService<TCleanHistory,TCleanHistoryExample,TCleanHistoryParam,Long> implements TCleanHistoryServiceInterface{
 	@Autowired
@@ -28,4 +36,13 @@ public class TCleanHistoryServiceImpl extends BaseService<TCleanHistory,TCleanHi
 		return "TCleanHistory";
 	}
 
+	@Override
+	public List<UseBean> getMainStatistics(StatisticsParam param) {
+
+		List<UseBean> list = tCleanHistoryMapper.getMainStatistics(param);
+		if (CollectionUtils.isEmpty(list)) {
+			throw new MyException("获取数据为空");
+		}
+		return list;
+	}
 }

+ 5 - 0
src/main/java/com/shawn/service/interfac/TCleanHistoryServiceInterface.java

@@ -5,10 +5,15 @@
 
 package com.shawn.service.interfac;
 
+import com.shawn.model.Bean.UseBean;
 import com.shawn.model.entity.TCleanHistory;
 import com.shawn.model.entity.TCleanHistoryExample;
+import com.shawn.model.param.StatisticsParam;
 import com.shawn.model.param.TCleanHistoryParam;
 import com.shawn.service.base.BaseServiceInterface;
 
+import java.util.List;
+
 public interface TCleanHistoryServiceInterface extends BaseServiceInterface<TCleanHistory,TCleanHistoryExample,TCleanHistoryParam,Long>{
+    public List<UseBean> getMainStatistics(StatisticsParam param);
 }

+ 10 - 1
src/main/java/com/shawn/web/controller/TCleanHistoryController.java

@@ -7,6 +7,7 @@ package com.shawn.web.controller;
 
 import java.util.Date;
 
+import com.shawn.model.param.StatisticsParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -39,6 +40,14 @@ public class TCleanHistoryController extends BaseController<TCleanHistory,TClean
 	protected TCleanHistoryExample createNewExample() {
 		return new TCleanHistoryExample();
 	}
-	
+	@PostMapping("/getMainStatistics")
+	public ResponseEntity<?> getMainStatistics(@RequestBody StatisticsParam param) {
+		return ResponseEntity
+				.status(HttpStatus.OK)
+				.body(new ResultMessage()
+						.setCode(true)
+						.setData(tCleanHistoryService.getMainStatistics(param))
+						.setMessage("SUCCESS"));
+	}
     
 }

+ 2 - 2
src/main/java/com/shawn/web/controller/TWeixinController.java

@@ -172,9 +172,9 @@ public class TWeixinController extends BaseController<TWeixin,TWeixinExample,TWe
     @GetMapping("/getOpenid")
     public ResponseEntity<?> getOpenid(String code) {
         // 微信小程序ID
-        String appid = "wx3844925af1740a7d";
+        String appid = "wxfffa94218fe6667b";
         // 微信小程序秘钥
-        String secret = "c1f0363a78d1c580388d6c4f14674733";
+        String secret = "153787ad08cc6cbddf57b28b6f0be66a";
 
         // 根据小程序穿过来的code想这个url发送请求
         String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + secret + "&js_code=" + code + "&grant_type=authorization_code";

+ 52 - 0
src/main/resources/com/shawn/repository/mybatis/TCleanHistoryMapper.xml

@@ -12,6 +12,11 @@
     <result column="water" jdbcType="INTEGER" property="water" />
     <result column="electricity" jdbcType="INTEGER" property="electricity" />
   </resultMap>
+  <resultMap id="useBean" type="com.shawn.model.Bean.UseBean">
+    <result column="categorie" jdbcType="VARCHAR" property="categorie" />
+    <result column="regularTimes" jdbcType="INTEGER" property="regularTimes" />
+    <result column="randomTimes" jdbcType="DECIMAL" property="randomTimes" />
+  </resultMap>
   <sql id="Example_Where_Clause">
     <where>
       <foreach collection="oredCriteria" item="criteria" separator="or">
@@ -111,6 +116,53 @@
       <include refid="Example_Where_Clause" />
     </if>
   </delete>
+
+  <!-- 汇总统计-->
+  <select id="getMainStatistics" resultMap="useBean">
+    select 'day' as categorie, sum(IF(a.`type` = '1', 1, 0)) AS randomTimes,sum(IF(a.`type` = '0', 1, 0)) AS regularTimes
+    from t_clean_history a
+    where 1=1
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId}
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+        and a.equipment_id= #{equipmentId}
+    </if>
+    and date_format(a.create_date,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
+    UNION all
+    select 'week' as categorie, sum(IF(a.`type` = '1', 1, 0)) AS randomTimes,sum(IF(a.`type` = '0', 1, 0)) AS regularTimes
+    from t_clean_history a
+    where 1=1
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId}
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId}
+    </if>
+    and YEARWEEK(date_format(a.create_date,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
+    UNION all
+    select 'month' as categorie, sum(IF(a.`type` = '1', 1, 0)) AS randomTimes,sum(IF(a.`type` = '0', 1, 0)) AS regularTimes
+    from t_clean_history a
+    where 1=1
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId}
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId}
+    </if>
+    and date_format(a.create_date,'%Y-%m') = date_format(now(),'%Y-%m')
+    UNION all
+    select 'year' as categorie, sum(IF(a.`type` = '1', 1, 0)) AS randomTimes,sum(IF(a.`type` = '0', 1, 0)) AS regularTimes
+    from t_clean_history a
+    where 1=1
+    <if test="adminId != null and adminId !=''">
+      and a.admin_id= #{adminId}
+    </if>
+    <if test="equipmentId != null and equipmentId !=''">
+      and a.equipment_id= #{equipmentId}
+    </if>
+    and date_format(a.create_date,'%Y') = date_format(now(),'%Y')
+  </select>
   <insert id="insert" parameterType="com.shawn.model.entity.TCleanHistory">
     insert into t_clean_history (id, create_date, modify_date, 
       type, client_id, admin_id,