Commit 0612d926 authored by chenying's avatar chenying

2019.7.1

(1)线路添加分页
parent 979d71ad
package com.example.tdl.domain.dto;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
public class EasyUIResult {
// 定义jackson对象
private static final ObjectMapper MAPPER = new ObjectMapper();
private Integer total;
private List<?> rows;
public EasyUIResult() {
}
public EasyUIResult(Integer total, List<?> rows) {
this.total = total;
this.rows = rows;
}
public EasyUIResult(Long total, List<?> rows) {
this.total = total.intValue();
this.rows = rows;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public List<?> getRows() {
return rows;
}
public void setRows(List<?> rows) {
this.rows = rows;
}
/**
* Object是集合转化
*
* @param jsonData json数据
* @param clazz 集合中的类型
* @return
*/
public static EasyUIResult formatToList(String jsonData, Class<?> clazz) {
try {
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("rows");
List<?> list = null;
if (data.isArray() && data.size() > 0) {
list = MAPPER.readValue(data.traverse(),
MAPPER.getTypeFactory().constructCollectionType(List.class, clazz));
}
return new EasyUIResult(jsonNode.get("total").intValue(), list);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
......@@ -9,9 +9,13 @@ import java.util.Map;
@Mapper
public interface CircuitMapper {
List<CircuitResultVo> getAll(@Param("companyNo") String companyNo);
List<CircuitResultVo> getAll(@Param("companyNo") String companyNo,@Param("page") Integer page,@Param("rows") Integer rows);
List<CircuitResultVo> getByTerm(CircuitTermVo circuitTermVo);
Integer getAllCount(@Param("companyNo") String companyNo);
Integer getByTermCount(CircuitTermVo circuitTermVo);
List<CircuitResultVo> getByTerm(@Param("circuitTermVo") CircuitTermVo circuitTermVo,@Param("page") Integer page,@Param("rows") Integer rows);
int addCircuit(Map<Object,Object> map);
......@@ -37,7 +41,6 @@ public interface CircuitMapper {
Integer getDelay(@Param("compTime")Long compTime,@Param("companyNo") String companyNo);
Integer getCount(@Param("time") String time,@Param("endTime") Long endTime,@Param("companyNo") String companyNo);
List<AppCircuitVo> getByPlateNo(@Param("plateNo") String plateNo,@Param("companyNo") String companyNo);
......@@ -57,4 +60,9 @@ public interface CircuitMapper {
List<ResultCircuitVo> getByTime(String companyNo);
CircuitMessage getMessage(String transportationNo);
String getStartCity(String transportationNo);
String getEndCity(String transportationNo);
}
......@@ -14,12 +14,20 @@ public class CircuitService {
@Autowired
private CircuitMapper circuitMapper;
public List<CircuitResultVo> getAll(String companyNo){
return circuitMapper.getAll(companyNo);
public List<CircuitResultVo> getAll(String companyNo,Integer page,Integer rows){
return circuitMapper.getAll(companyNo,page,rows);
}
public List<CircuitResultVo> getByTerm(CircuitTermVo circuitTermVo){
return circuitMapper.getByTerm(circuitTermVo);
public Integer getAllCount(String companyNo){
return circuitMapper.getAllCount(companyNo);
}
public List<CircuitResultVo> getByTerm(CircuitTermVo circuitTermVo,Integer page,Integer rows){
return circuitMapper.getByTerm(circuitTermVo,page,rows);
}
public Integer getByTermCount(CircuitTermVo circuitTermVo){
return circuitMapper.getByTermCount(circuitTermVo);
}
public int addCircuit(Map<Object,Object> map){
......
......@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.influxdb.InfluxDBTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import retrofit2.http.POST;
......@@ -95,8 +96,6 @@ public class CircuitController {
private final static String database ="original";
//获取本公司的线路信息
@ApiOperation(value = "获取本公司的线路信息",notes = "获取本公司的线路信息,返回值说明:" +
" transportationNo:运输编号," +
......@@ -117,11 +116,12 @@ public class CircuitController {
@ApiImplicitParam(paramType="header", name = "AccountLanguage", value = "language", required = false, dataType = "String"),
})
@RequestMapping(value="/getAll",method = RequestMethod.GET)
public Object getAll(HttpServletRequest request){
public Object getAll(@RequestParam(value ="page",defaultValue = "1")Integer page,
@RequestParam(value = "rows",defaultValue = "5")Integer rows,HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
List<CircuitResultVo> list = circuitService.getAll(user.getCompanyNo());
List<CircuitResultVo> list = circuitService.getAll(user.getCompanyNo(),(page-1)*rows,rows);
for(int i = 0,length=list.size();i<length;i++){
if(list.get(i).getCircuitState() == 1){
//获取设备在线情况
......@@ -152,7 +152,8 @@ public class CircuitController {
continue;
}
}
return list;
Integer num = circuitService.getAllCount(user.getCompanyNo());
return ResponseEntity.ok(new EasyUIResult(num, list));
}
......@@ -253,7 +254,8 @@ public class CircuitController {
@ApiImplicitParam(paramType="header", name = "AccountLanguage", value = "language", required = false, dataType = "String"),
})
@RequestMapping(value="/getByTerm",method = RequestMethod.POST)
public Object getByTerm(@RequestBody CircuitTermVo circuitTermVo,HttpServletRequest request){
public Object getByTerm(@RequestBody CircuitTermVo circuitTermVo,@RequestParam(value ="page",defaultValue = "1")Integer page,
@RequestParam(value = "rows",defaultValue = "5")Integer rows,HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
......@@ -280,7 +282,9 @@ public class CircuitController {
circuitTermVo.setTime(circuitTermVo.getTime().replace("天","").trim());
}
circuitTermVo.setCompanyNo(user.getCompanyNo());
return circuitService.getByTerm(circuitTermVo);
Integer num = circuitService.getByTermCount(circuitTermVo);
List<CircuitResultVo> circuitResultVos = circuitService.getByTerm(circuitTermVo,(page-1)*rows,rows);
return ResponseEntity.ok(new EasyUIResult(num, circuitResultVos));
}
......
#spring.datasource.url=jdbc:mysql://47.97.184.225:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.url=jdbc:mysql://47.97.184.225:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
#spring.datasource.url=jdbc:mysql://47.110.153.44:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.url=jdbc:mysql://172.16.1.13:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
#spring.datasource.url=jdbc:mysql://172.16.1.13:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=37774020
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
......
#\u9884\u8B66\u7C7B\u578B
s#\u9884\u8B66\u7C7B\u578B
alarmType = \u9884\u8B66\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A
alarmTypeEmpty= \u8BE5\u9884\u8B66\u7C7B\u578B\u4E0D\u5B58\u5728
alarmScene = \u9884\u8B66\u573A\u666F\u4E0D\u80FD\u4E3A\u7A7A
......
......@@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.tdl.mapper.CircuitMapper">
<!--获取所有线路的信息-->
<select id="getAll" resultType="com.example.tdl.domain.vo.CircuitResultVo" parameterType="String">
<select id="getAll" resultType="com.example.tdl.domain.vo.CircuitResultVo">
SELECT c.transportationNo,cargoNo,cargoName,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence LIMIT 1)) startCity,startTime,
(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence DESC LIMIT 1)) endCity,endTime,circuitState,
(SELECT GROUP_CONCAT(alarmType) FROM alarm WHERE id IN (SELECT alarm_id from tdl_gateway_log WHERE transportationNo=c.transportationNo)) alarmType,
......@@ -12,11 +12,17 @@
from circuit c
where c.state=1
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
order by c.createTime desc LIMIT #{page,jdbcType=INTEGER},#{rows,jdbcType=INTEGER}
</select>
<select id="getAllCount" resultType="Integer" parameterType="String">
SELECT count(id) from circuit c where c.state=1
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
order by c.createTime desc
</select>
<!--根据条件查询线路信息-->
<select id="getByTerm" resultType="com.example.tdl.domain.vo.CircuitResultVo" parameterType="com.example.tdl.domain.vo.CircuitTermVo">
<select id="getByTerm" resultType="com.example.tdl.domain.vo.CircuitResultVo">
SELECT c.transportationNo,cargoNo,cargoName,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence LIMIT 1)) startCity,startTime,
(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence DESC LIMIT 1)) endCity,endTime,circuitState,
(SELECT GROUP_CONCAT(alarmType) FROM alarm WHERE id IN (SELECT alarm_id from tdl_gateway_log WHERE transportationNo=c.transportationNo)) alarmType,
......@@ -25,6 +31,27 @@
(select DISTINCT gatewayType from tdl_gateway_log WHERE transportationNo=c.transportationNo) gType
from circuit c
where c.state=1
AND company_id=(SELECT id from company where companyNo=#{circuitTermVo.companyNo,jdbcType=VARCHAR})
<if test="circuitTermVo.time !=null">
AND DATE_SUB(CURDATE(), INTERVAL #{circuitTermVo.time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(createTime/1000,'%Y-%m-%d %H:%i:%s'))
</if>
<if test="circuitTermVo.circuitState!=null">
AND c.circuitState=#{circuitTermVo.circuitState,jdbcType=INTEGER}
</if>
<if test="circuitTermVo.cargoNo!=null">
AND c.cargoNo like CONCAT(CONCAT('%',#{circuitTermVo.cargoNo,jdbcType=VARCHAR}),'%')
</if>
<if test="circuitTermVo.startTime!=null">
AND c.createTime &gt;= #{circuitTermVo.circuitTermVo.startTime,jdbcType=BIGINT}
</if>
<if test="circuitTermVo.endTime!=null">
AND c.createTime &lt;= #{circuitTermVo.endTime,jdbcType=BIGINT}
</if>
LIMIT #{page,jdbcType=INTEGER},#{rows,jdbcType=INTEGER}
</select>
<select id="getByTermCount" resultType="Integer" parameterType="com.example.tdl.domain.vo.CircuitTermVo">
SELECT count(id) from circuit c where c.state=1
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
<if test="time !=null">
AND DATE_SUB(CURDATE(), INTERVAL #{time,jdbcType=VARCHAR} DAY) &lt;= date(FROM_UNIXTIME(createTime/1000,'%Y-%m-%d %H:%i:%s'))
......@@ -212,7 +239,6 @@
]]>
</delete>
<!--根据线路编号获取线路信息-->
<select id="getByTransportationNo" resultType="com.example.tdl.domain.vo.ResultCircuitVo" parameterType="String">
SELECT c.transportationNo,cargoNo,cargoName,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence LIMIT 1)) startCity,startTime,
......@@ -250,14 +276,12 @@
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
</select>
<!-- 运输中数量-->
<select id="getOnRoute" resultType="java.lang.Integer" parameterType="String">
select count(transportationNo) from circuit where circuitState=1 AND state = 1
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
</select>
<!--延误数量-->
<select id="getDelayCount" resultType="java.lang.Integer" >
select count(id) from circuit where state =1
......@@ -266,8 +290,6 @@
AND ifnull(endtime,#{compTime,jdbcType=BIGINT}) > compTime
</select>
<!--总数量-->
<select id="getCount" resultType="java.lang.Integer">
select count(id) from circuit
......@@ -298,7 +320,6 @@
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
</select>
<!--评价-->
<update id="updateEvaluate" parameterType="com.example.tdl.domain.vo.UpdateEvaluateVo">
update circuit set
......@@ -307,19 +328,16 @@
WHERE transportationNo=#{transportationNo,jdbcType=VARCHAR}
</update>
<select id="getNo" parameterType="String" resultType="java.lang.Integer">
SELECT count(transportationNo) from circuit
WHERE transportationNo=#{transportationNo,jdbcType=VARCHAR}
</select>
<select id="getByNo" parameterType="String" resultType="com.example.tdl.domain.vo.ResultGatewayVo">
SELECT SN,`name`,type,state,bConfig,useScene,from_unixtime((createTime/1000),'%Y-%m-%d %T') createTime,from_unixtime((updateTime/1000),'%Y-%m-%d %T') updateTime
from gateway WHERE id=(SELECT gateway_id from tdldevice where circuit_id =(SELECT id from circuit WHERE transportationNo=#{transportationNo,jdbcType=VARCHAR}) LIMIT 1)
</select>
<select id="getByTime" parameterType="java.lang.String" resultType="com.example.tdl.domain.vo.ResultCircuitVo">
SELECT c.transportationNo,cargoNo,cargoName,(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence LIMIT 1)) startCity,startTime,
(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id ORDER BY sequence DESC LIMIT 1)) endCity,endTime,circuitState,
......@@ -330,7 +348,6 @@
AND company_id=(SELECT id from company where companyNo=#{companyNo,jdbcType=VARCHAR})
</select>
<select id="getDelay" resultType="java.lang.Integer">
select count(transportationNo) from circuit
where #{compTime,jdbcType=BIGINT}> compTime
......@@ -338,8 +355,6 @@
and circuitState = 1
</select>
<select id="getMessage" parameterType="String" resultType="com.example.tdl.domain.vo.CircuitMessage">
select c.transportationNo,CONCAT_WS("-",(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id AND sequence =LEFT(s.sequence,1))),
(SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=c.id AND sequence=RIGHT(s.sequence,1)))) routeName,
......@@ -350,6 +365,15 @@
and c.transportationNo=#{transportationNo,jdbcType=VARCHAR}
</select>
<select id="getStartCity" parameterType="String" resultType="String">
SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=(
select id from circuit where transportationNo=#{transportationNo,jdbcType=VARCHAR}) ORDER BY sequence LIMIT 1)
</select>
<select id="getEndCity" parameterType="String" resultType="String">
SELECT city from city WHERE id =(SELECT city_id from circuit_transfer WHERE circuit_id=(
select id from circuit where transportationNo=#{transportationNo,jdbcType=VARCHAR}) ORDER BY sequence DESC LIMIT 1)
</select>
<!--
<select id="getDistinct" resultType="com.example.tdl.domain.vo.CircuitVo">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment