Authored by zhengyouwei

项目展示

  1 +package com.monitor.model.request;
  2 +
  3 +import com.monitor.model.page.PageRequest;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * Created by zhengyouwei on 2016/7/21.
  8 + */
  9 +@Data
  10 +public class ProjectBuildReq extends PageRequest {
  11 +
  12 + private String currentProject;
  13 +
  14 + private String environment;
  15 +
  16 +}
  1 +package com.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * Created by zhengyouwei on 2016/7/21.
  7 + */
  8 +@Data
  9 +public class BuildProcessHistory {
  10 +
  11 + private int id;
  12 +
  13 + private String localid;
  14 +
  15 + private String environment;
  16 + private String operate;
  17 + private int status;
  18 + private String user;
  19 + private String projectOrder;
  20 + private String branch;
  21 + private String currentProject;
  22 + private String rollbackfile;
  23 + private String tag;
  24 + private String createTime;
  25 +
  26 +
  27 +
  28 +}
  1 +package com.monitor.mysql.mapper;
  2 +
  3 +import com.model.BuildProcessHistory;
  4 +import com.monitor.model.domain.PageBean;
  5 +
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * Created by zhengyouwei on 2016/7/21.
  10 + */
  11 +public interface BuildHistoryMapper {
  12 +
  13 + int selectCountByCodition(PageBean page);
  14 +
  15 + List<BuildProcessHistory> selectByCodition(PageBean page);
  16 +
  17 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.monitor.mysql.mapper.BuildHistoryMapper" >
  4 + <resultMap id="BaseResultMap" type="com.model.BuildProcessHistory" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="status" property="status" jdbcType="INTEGER" />
  7 + <result column="localid" property="localid" jdbcType="VARCHAR" />
  8 + <result column="environment" property="environment" jdbcType="VARCHAR" />
  9 + <result column="operate" property="operate" jdbcType="VARCHAR" />
  10 + <result column="user" property="user" jdbcType="VARCHAR" />
  11 + <result column="project_order" property="projectOrder" jdbcType="VARCHAR" />
  12 + <result column="branch" property="branch" jdbcType="VARCHAR" />
  13 + <result column="currentProject" property="currentProject" jdbcType="VARCHAR" />
  14 + <result column="rollbackfile" property="rollbackfile" jdbcType="VARCHAR" />
  15 + <result column="tag" property="tag" jdbcType="VARCHAR" />
  16 + <result column="createTime" property="createTime" jdbcType="VARCHAR" />
  17 +
  18 + </resultMap>
  19 +
  20 + <select id="selectCountByCodition" resultType="java.lang.Integer">
  21 + select
  22 + count(1)
  23 + from build_process_history
  24 + where
  25 + 1=1
  26 + <if test="params.environment != null &amp;&amp; params.environment != ''" >
  27 + and environment = #{params.environment}
  28 + </if>
  29 + <if test="params.currentProject != null &amp;&amp; params.currentProject != ''" >
  30 + and currentProject = #{params.currentProject}
  31 + </if>
  32 + </select>
  33 +
  34 + <select id="selectByCodition" resultMap="BaseResultMap">
  35 + select
  36 + id,status,localid,environment,operate,user,project_order,branch,currentProject,rollbackfile,tag,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime
  37 + from build_process_history
  38 + where
  39 + 1=1
  40 + <if test="params.environment != null &amp;&amp; params.environment != ''" >
  41 + and environment = #{params.environment}
  42 + </if>
  43 + <if test="params.currentProject != null &amp;&amp; params.currentProject != ''" >
  44 + and currentProject = #{params.currentProject}
  45 + </if>
  46 + order by create_time desc
  47 + limit #{startIndex},#{pageSize}
  48 + </select>
  49 +
  50 +</mapper>
  1 +package com.monitor.user.ctrl;
  2 +
  3 +import com.model.BuildProcessHistory;
  4 +import com.monitor.model.domain.PageBean;
  5 +import com.monitor.model.request.ProjectBuildReq;
  6 +import com.monitor.model.response.BaseResponse;
  7 +import com.monitor.model.response.PageResponse;
  8 +import com.monitor.mysql.mapper.BuildHistoryMapper;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Controller;
  13 +import org.springframework.web.bind.annotation.RequestBody;
  14 +import org.springframework.web.bind.annotation.RequestMapping;
  15 +import org.springframework.web.bind.annotation.ResponseBody;
  16 +
  17 +import java.util.List;
  18 +
  19 +
  20 +/**
  21 + * Created by yoho on 2016/6/14.
  22 + * 查询机器信息
  23 + */
  24 +@Controller
  25 +@RequestMapping("projectBuild")
  26 +public class BuildProjectCtrl {
  27 +
  28 + Logger log = LoggerFactory.getLogger(BuildProjectCtrl.class);
  29 +
  30 + @Autowired
  31 + private BuildHistoryMapper buildHistoryMapper;
  32 +
  33 + @RequestMapping("/getHistory")
  34 + @ResponseBody
  35 + public BaseResponse<PageResponse<BuildProcessHistory>> getHistory(@RequestBody ProjectBuildReq req) throws Exception {
  36 +
  37 + log.info("getHistory with param is {}", req);
  38 +
  39 + // 组装分页对象
  40 + PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
  41 + req.getPageSize(), req);
  42 + // 先查询符合条件的总数量
  43 + int total = buildHistoryMapper.selectCountByCodition(page);
  44 + // 数量为0 直接返回
  45 + if (total == 0) {
  46 + // 返回初始page对象
  47 + return new BaseResponse<>();
  48 + }
  49 + // 获取列表
  50 + List<BuildProcessHistory> buildProcessHistoryList = buildHistoryMapper.selectByCodition(page);
  51 + PageResponse<BuildProcessHistory> response = new PageResponse<BuildProcessHistory>();
  52 + response.setCurrentPage(req.getCurrentPage());
  53 + response.setPageSize(req.getPageSize());
  54 + response.setTotal(total);
  55 + response.setRows(buildProcessHistoryList);
  56 +
  57 + log.info("getHistory success and total={}", response.getTotal());
  58 + return new BaseResponse<PageResponse<BuildProcessHistory>>(response);
  59 + }
  60 +
  61 +}
  62 +