use of beans.dbaccess.PlanInfo in project MSEC by Tencent.
the class GetPlanList method exec.
public GetPlanListResponse exec(GetPlanListRequest request) {
GetPlanListResponse resp = new GetPlanListResponse();
String result = checkIdentity();
if (!result.equals("success")) {
resp.setStatus(99);
resp.setMessage(result);
return resp;
}
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
resp.setStatus(100);
resp.setMessage("db connect failed!");
return resp;
}
List<PlanInfo> planList;
HashMap<String, String> plan_status_map = new HashMap<>();
ArrayList<PlanInfo> plans = new ArrayList<>();
try {
String sql = "select plan_id, operation, status from t_install_plan where first_level_service_name=? and second_level_service_name=?" + " and create_time>=? and create_time<=? group by plan_id, operation, status order by plan_id desc";
List<Object> params = new ArrayList<Object>();
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
params.add(request.getBegin_date() + " 00:00:00");
params.add(request.getEnd_date() + " 23:59:59");
planList = util.findMoreRefResult(sql, params, PlanInfo.class);
for (PlanInfo plan : planList) {
String status = plan_status_map.get(plan.getPlan_id());
if (status == null) {
if (plan.getStatus().startsWith("Done")) {
plan_status_map.put(plan.getPlan_id(), status_ok);
} else if (plan.getStatus().startsWith("[ERROR]")) {
plan_status_map.put(plan.getPlan_id(), status_error);
} else {
plan_status_map.put(plan.getPlan_id(), status_ip);
}
} else {
//ERROR > In Progress > Done.
if (!plan.getStatus().startsWith("Done")) {
if (!status.equals(status_error)) {
if (plan.getStatus().startsWith("[ERROR]")) {
plan_status_map.put(plan.getPlan_id(), status_error);
} else {
//in progress
if (status.equals(status_ok)) {
plan_status_map.put(plan.getPlan_id(), status_ip);
}
}
}
}
}
}
for (PlanInfo plan : planList) {
String status = plan_status_map.remove(plan.getPlan_id());
if (status != null) {
if (plan.getOperation().equals("add")) {
plan.setOperation(op_add);
} else if (plan.getOperation().equals("del")) {
plan.setOperation(op_remove);
} else {
plan.setOperation(op_recover);
}
plan.setStatus(status);
plans.add(plan);
}
}
} catch (Exception e) {
resp.setStatus(100);
resp.setMessage("db query exception!");
e.printStackTrace();
return resp;
} finally {
util.releaseConn();
}
resp.setPlans(plans);
resp.setMessage("success");
resp.setStatus(0);
return resp;
}
Aggregations