Authored by zhengyouwei

项目展示

package com.monitor.model.request;
import com.monitor.model.page.PageRequest;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/7/21.
*/
@Data
public class ProjectBuildReq extends PageRequest {
private String currentProject;
private String environment;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/7/21.
*/
@Data
public class BuildProcessHistory {
private int id;
private String localid;
private String environment;
private String operate;
private int status;
private String user;
private String projectOrder;
private String branch;
private String currentProject;
private String rollbackfile;
private String tag;
private String createTime;
}
... ...
package com.monitor.mysql.mapper;
import com.model.BuildProcessHistory;
import com.monitor.model.domain.PageBean;
import java.util.List;
/**
* Created by zhengyouwei on 2016/7/21.
*/
public interface BuildHistoryMapper {
int selectCountByCodition(PageBean page);
List<BuildProcessHistory> selectByCodition(PageBean page);
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.BuildHistoryMapper" >
<resultMap id="BaseResultMap" type="com.model.BuildProcessHistory" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="localid" property="localid" jdbcType="VARCHAR" />
<result column="environment" property="environment" jdbcType="VARCHAR" />
<result column="operate" property="operate" jdbcType="VARCHAR" />
<result column="user" property="user" jdbcType="VARCHAR" />
<result column="project_order" property="projectOrder" jdbcType="VARCHAR" />
<result column="branch" property="branch" jdbcType="VARCHAR" />
<result column="currentProject" property="currentProject" jdbcType="VARCHAR" />
<result column="rollbackfile" property="rollbackfile" jdbcType="VARCHAR" />
<result column="tag" property="tag" jdbcType="VARCHAR" />
<result column="createTime" property="createTime" jdbcType="VARCHAR" />
</resultMap>
<select id="selectCountByCodition" resultType="java.lang.Integer">
select
count(1)
from build_process_history
where
1=1
<if test="params.environment != null &amp;&amp; params.environment != ''" >
and environment = #{params.environment}
</if>
<if test="params.currentProject != null &amp;&amp; params.currentProject != ''" >
and currentProject = #{params.currentProject}
</if>
</select>
<select id="selectByCodition" resultMap="BaseResultMap">
select
id,status,localid,environment,operate,user,project_order,branch,currentProject,rollbackfile,tag,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime
from build_process_history
where
1=1
<if test="params.environment != null &amp;&amp; params.environment != ''" >
and environment = #{params.environment}
</if>
<if test="params.currentProject != null &amp;&amp; params.currentProject != ''" >
and currentProject = #{params.currentProject}
</if>
order by create_time desc
limit #{startIndex},#{pageSize}
</select>
</mapper>
\ No newline at end of file
... ...
package com.monitor.user.ctrl;
import com.model.BuildProcessHistory;
import com.monitor.model.domain.PageBean;
import com.monitor.model.request.ProjectBuildReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.BuildHistoryMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* Created by yoho on 2016/6/14.
* 查询机器信息
*/
@Controller
@RequestMapping("projectBuild")
public class BuildProjectCtrl {
Logger log = LoggerFactory.getLogger(BuildProjectCtrl.class);
@Autowired
private BuildHistoryMapper buildHistoryMapper;
@RequestMapping("/getHistory")
@ResponseBody
public BaseResponse<PageResponse<BuildProcessHistory>> getHistory(@RequestBody ProjectBuildReq req) throws Exception {
log.info("getHistory with param is {}", req);
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = buildHistoryMapper.selectCountByCodition(page);
// 数量为0 直接返回
if (total == 0) {
// 返回初始page对象
return new BaseResponse<>();
}
// 获取列表
List<BuildProcessHistory> buildProcessHistoryList = buildHistoryMapper.selectByCodition(page);
PageResponse<BuildProcessHistory> response = new PageResponse<BuildProcessHistory>();
response.setCurrentPage(req.getCurrentPage());
response.setPageSize(req.getPageSize());
response.setTotal(total);
response.setRows(buildProcessHistoryList);
log.info("getHistory success and total={}", response.getTotal());
return new BaseResponse<PageResponse<BuildProcessHistory>>(response);
}
}
... ...