test successgit add .!

This commit is contained in:
kissxiaohai
2015-12-09 14:33:07 +08:00
parent 04437c0a92
commit d4d74832d2
20 changed files with 2091 additions and 393 deletions

View File

@@ -1,17 +1,20 @@
<div>
<center>
<form action="/report/update" method="post"
enctype="multipart/form-data">
enctype="multipart/form-data" target="rfFrame">
<input type="hidden" name="report_id" value="{{report_id}}">
<lable for="creator">创建者:</lable>
<input id="creator" type="text" value="{{report.report_creator}}" name="report_creator"><br>
<br>
<lable>创建/修改时间:{{report.report_create_time}}</lable>
<br> <br>
<input id="creator" type="text" value="{{report.report_creator}}"
name="report_creator" placeholder="创建者"><br> <br>
<lable for="time">创建时间:</lable>
<input id="time" type="text" value="{{report.report_create_time}}"
name="report_time" placeholder="创建时间" readonly> <a
href="#/reports/" ng-click="remove()">删除</a><br> <br>
<table width="80%" border="1">
<caption>
<input id="name" type="text" value="{{report.report_name}}"
style="width: 30%; text-align: center" name="report_name">
style="width: 30%; text-align: center" name="report_name"
placeholder="请填写安全检查信息表名">
</caption>
<thead>
@@ -53,6 +56,9 @@
<input type="submit"></input>
</form>
<iframe hidden id="rfFrame" name="rfFrame" src="about:blank"$amp;>amp;$lt;</iframe>
</center>
</div>

View File

@@ -1,14 +1,17 @@
<div>
<br>
<h4>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安全检查信息列表
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安全检查信息列表 &nbsp;&nbsp;<a
href="#/reports/add">添加</a>
</h3>
<hr>
<ul>
<div ng-repeat="report in reportList">
<a href="#/reports/{{report.report_id}}"><ui>{{report.report_name}}</ui></a>
<ui>
<a href="#/reports/{{report.report_id}}">{{report.report_name}}</a>
</ui>
</div>
</ul>

View File

@@ -9,23 +9,30 @@ appControllers.controller('ReportListController', [ '$scope', '$http',
});
} ]);
appControllers.controller('ReportDetailController', [
'$scope',
'$routeParams',
'$http',
function($scope, $routeParams, $http) {
appControllers.controller('ReportDetailController', [ '$scope', '$routeParams',
'$http', function($scope, $routeParams, $http) {
$scope.report_id = $routeParams.report_id;
$http.get("/report/query?report_id=" + $scope.report_id).success(
function(response) {
var url = "";
if ($scope.report_id == "add") {
url = "/report/add";
} else {
url += "/report/query?report_id=" + $scope.report_id;
}
$http.get(url).success(function(response) {
$scope.report = response;
$scope.contents = response.contents;
});
$scope.submit = function() {
$scope.remove = function(report_id) {
if (confirm("确定删除?")) {
$http.get("/report/delete?report_id=" + $scope.report_id);
}
};
} ]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -89,7 +89,7 @@ CREATE TABLE `check_record` (
`record_id` int(11) NOT NULL AUTO_INCREMENT,
`report_id` int(11) NOT NULL,
`check_item_id` int(11) NOT NULL,
`passed` varchar(1) NOT NULL,
`passed` varchar(1) DEFAULT '0',
`pic_url` varchar(200) DEFAULT '""',
`note` varchar(200) DEFAULT '""',
PRIMARY KEY (`record_id`),
@@ -147,9 +147,4 @@ CREATE TABLE `report` (
-- ----------------------------
-- Records of report
-- ----------------------------
INSERT INTO `report` VALUES ('1', 'AH-H001-01 2015年3月11日18点测试表', '黄金定', '2015-11-14 11:46:10');
INSERT INTO `report` VALUES ('2', 'AH-H001-02 2015年3月12日18点测试表', '杜佳佳', '2015-11-14 11:46:10');
INSERT INTO `report` VALUES ('3', 'AH-H001-03 2015年3月12日18点测试表', '杜佳佳', '2015-11-14 11:46:10');
INSERT INTO `report` VALUES ('4', 'AH-H001-04 2015年3月12日18点测试表', '杜佳佳', '2015-11-14 11:46:10');
INSERT INTO `report` VALUES ('5', 'AH-H001-05 2015年3月12日18点测试表', '杜佳佳', '2015-11-14 11:46:10');
INSERT INTO `report` VALUES ('6', 'AH-H001-06 2015年3月12日18点测试表', '杜佳佳', '2015-11-14 11:46:10');
INSERT INTO `report` VALUES ('1', 'AH-H001-01 2015年3月11日18点测试表', '杜佳', '2015-12-10 11:46:10');

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,8 @@ public class IndexController extends Controller {
public void index() {
setAttr("status", "SUCCESS");
renderJson();
// setAttr("status", "SUCCESS");
// renderJson();
redirect("/index.html");
}
}

View File

@@ -1,8 +1,11 @@
package com.jinshan.controller;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,6 +35,15 @@ public class ReportController extends Controller {
renderJson();
}
public void add() {
setAttr("report_name", "");
setAttr("report_creator", "");
setAttr("report_create_time", "");
setAttr("contents", Report.dao.query());
renderJson();
}
public void query() {
Integer report_id = getParaToInt("report_id");
@@ -49,82 +61,32 @@ public class ReportController extends Controller {
renderJson();
}
@SuppressWarnings("unused")
public void update() {
// String type = getPara("type");
// if (type.equals("add")) {
// if (add()) {
// setAttr("result", "add success");
// } else {
// setAttr("result", "add failed");
// }
// } else if (type.equals("delete")) {
// if (delete()) {
// setAttr("result", "delete success");
// } else {
// setAttr("result", "delete failed");
// }
// } else if (type.equals("edit")) {
// if (edit()) {
// setAttr("result", "edit success");
// } else {
// setAttr("result", "edit failed");
// }
// }
List<UploadFile> list_uf = getFiles("upload");
Map<String, Object> map = new HashMap<>();
map.put("report_id", getPara("report_id"));
map.put("report_name", getPara("report_name"));
map.put("report_creator", getPara("report_creator"));
ArrayList<Object> items = new ArrayList<>();
List<CheckContent> list_content = CheckContent.dao
.find("select * from check_content");
for (int i = 0; i < list_content.size(); i++) {
List<CheckItem> list_item = CheckItem.dao.find(
"select * from check_item where check_content_id = ?",
list_content.get(i).get("check_content_id"));
for (int j = 0; j < list_item.size(); j++) {
String pic_url = "";
String passed = "0";
String note = "";
if (getPara("pic_url_" + String.valueOf((i + 1)) + "_"
+ String.valueOf((i + 1))) != null) {
pic_url = getPara("pic_url_" + String.valueOf((i + 1))
+ "_" + String.valueOf((j + 1)));
public void updateByJsonStr() {
String type = getPara("type");
if (type.equals("add")) {
if (addByJsonStr()) {
setAttr("result", "add success");
} else {
setAttr("result", "add failed");
}
if (getPara("passed_" + String.valueOf((i + 1)) + "_"
+ String.valueOf((j + 1))) != null) {
passed = "1";
} else if (type.equals("delete")) {
if (delete1()) {
setAttr("result", "delete success");
} else {
setAttr("result", "delete failed");
}
if (getPara("note_" + String.valueOf((i + 1)) + "_"
+ String.valueOf((i + 1))) != null) {
note = getPara("note_" + String.valueOf((i + 1)) + "_"
+ String.valueOf((j + 1)));
}
Map<String, Object> map1 = new HashMap<>();
map1.put("pic_url", pic_url);
map1.put("passed", passed);
map1.put("note", note);
@!!!!!!!!!!
} else if (type.equals("edit")) {
if (editByJsonStr()) {
setAttr("result", "edit success");
} else {
setAttr("result", "edit failed");
}
}
// Map<String, String[]> map = getParaMap();
renderJson();
}
private boolean add() {
private boolean addByJsonStr() {
String jsonStr = null;
try {
jsonStr = getBody(getRequest());
@@ -139,35 +101,118 @@ public class ReportController extends Controller {
}
}
private boolean delete() {
public boolean delete1() {
Integer report_id = getParaToInt("report_id");
if (Report.dao.deleteById(report_id)) {
setAttr("result", "delete success");
return true;
} else {
setAttr("result", "delete failed");
return false;
}
}
public void delete() {
Integer report_id = getParaToInt("report_id");
if (Report.dao.deleteById(report_id)) {
setAttr("result", "delete success");
} else {
setAttr("result", "delete failed");
}
}
private boolean editByJsonStr() {
String jsonStr = null;
try {
jsonStr = getBody(getRequest());
} catch (ServletException | IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = new JSONObject(jsonStr);
if (Report.dao.updateByJSONObject(jsonObject)) {
return true;
} else {
return false;
}
}
private boolean edit() {
// String jsonStr = null;
// try {
// jsonStr = getBody(getRequest());
// } catch (ServletException | IOException e) {
// e.printStackTrace();
// }
// JSONObject jsonObject = new JSONObject(jsonStr);
// if (Report.dao.updateByJSONObject(jsonObject)) {
// return true;
// } else {
// return false;
// }
public void update() {
String saveDirectory = "upload" + File.separator
+ new SimpleDateFormat("yyyyMMdd").format(new Date());
List<UploadFile> list_uf = getFiles(saveDirectory);
// getFiles("/upload");
// if () {
// return true;
// } else {
return true;
// }
Map<String, Object> map = new HashMap<>();
map.put("report_id", getPara("report_id"));
map.put("report_name", getPara("report_name"));
map.put("report_creator", getPara("report_creator"));
map.put("list_uf", list_uf);
ArrayList<Object> items = new ArrayList<>();
List<CheckContent> list_content = CheckContent.dao
.find("select * from check_content");
for (int i = 0; i < list_content.size(); i++) {
List<CheckItem> list_item = CheckItem.dao.find(
"select * from check_item where check_content_id = ?",
list_content.get(i).get("check_content_id"));
for (int j = 0; j < list_item.size(); j++) {
String passed = "0";
String note = "";
int check_content_id = i + 1;
int table_sequence = j + 1;
if (getPara("passed_" + String.valueOf((check_content_id))
+ "_" + String.valueOf((table_sequence))) != null) {
passed = "1";
}
if (getPara("note_" + String.valueOf((check_content_id)) + "_"
+ String.valueOf((table_sequence))) != null) {
note = getPara("note_" + String.valueOf((check_content_id))
+ "_" + String.valueOf((table_sequence)));
}
CheckItem checkItem = CheckItem.dao
.findFirst(
"select * from check_item where check_content_id = ? and table_sequence = ?",
check_content_id, table_sequence);
int check_item_id = checkItem.getInt("check_item_id");
Map<String, Object> map1 = new HashMap<>();
map1.put("passed", passed);
map1.put("note", note);
map1.put("check_item_id", check_item_id);
items.add(map1);
}
}
map.put("items", items);
if (map.get("report_id") != null) {
if (editByMap(map)) {
setAttr("result", "edit success");
} else {
setAttr("result", "edit failed");
}
} else {
if (addByMap(map)) {
setAttr("result", "edit success");
} else {
setAttr("result", "edit failed");
}
}
renderJson();
}
private boolean editByMap(Map<String, Object> map) {
return Report.dao.update(map);
}
private boolean addByMap(Map<String, Object> map) {
return Report.dao.update(map);
}
private String getBody(HttpServletRequest request) throws ServletException,

View File

@@ -1,9 +1,12 @@
package com.jinshan.model;
import java.io.File;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -14,11 +17,14 @@ import org.json.JSONObject;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.upload.UploadFile;
@SuppressWarnings("serial")
public class Report extends Model<Report> {
public static Report dao = new Report();
public int tmp_report_id;
@SuppressWarnings({ "unchecked" })
public List<Object> query(int report_id) {
ArrayList<Object> list = new ArrayList<>();
@@ -99,6 +105,47 @@ public class Report extends Model<Report> {
}
}
public List<Object> query() {
ArrayList<Object> list = new ArrayList<>();
List<CheckContent> list_contents = CheckContent.dao
.find("select * from check_content");
int len_contents = list_contents.size();
for (int i = 0; i < len_contents; i++) {
CheckContent checkContent = list_contents.get(i);
int check_content_id = checkContent.getInt("check_content_id");
String check_content = checkContent.getStr("check_content");
ArrayList<Object> items = new ArrayList<>();
List<CheckItem> list_items = CheckItem.dao.find(
"select * from check_item where check_content_id = ?",
check_content_id);
int len_items = list_items.size();
for (int j = 0; j < len_items; j++) {
CheckItem checkItem = list_items.get(j);
String check_item = checkItem.getStr("check_item");
int table_sequence = checkItem.getLong("table_sequence")
.intValue();
Map<String, Object> item = new HashMap<>();
item.put("item", check_content_id + "." + table_sequence
+ check_item);
item.put("passed", "0");
item.put("note", "");
item.put("pic_url", "");
items.add(item);
}
Map<String, Object> map = new HashMap<>();
map.put("No", check_content_id);
map.put("content", check_content);
map.put("items", items);
list.add(map);
}
return list;
}
public boolean updateByJSONObject(JSONObject jsonObject) {
if (jsonObject.has("report_id")) {
@@ -209,6 +256,131 @@ public class Report extends Model<Report> {
});
return succeed;
}
public boolean update(Map<String, Object> map) {
if (map.get("report_id") != null) {
return edit(map);
}
return false;
}
@SuppressWarnings("unchecked")
private boolean edit(Map<String, Object> map) {
final String report_id = (String) map.get("report_id");
final String report_name = (String) map.get("report_name");
final String report_creator = (String) map.get("report_creator");
final List<UploadFile> list_uf = (List<UploadFile>) map.get("list_uf");
final ArrayList<Object> items = (ArrayList<Object>) map.get("items");
if (report_id.equals("add")) {
String report_create_time = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss").format(new Date());
if (report_name.equals("") || report_creator.equals("")) {
return false;
} else {
if (new Report().set("report_name", report_name)
.set("report_creator", report_creator)
.set("report_create_time", report_create_time).save()) {
Report report_add = dao
.findFirst(
"select * from report where report_name = ? and report_creator = ?",
report_name, report_creator);
int report_id_add = report_add.getInt("report_id");
List<CheckItem> list_checkItems = CheckItem.dao
.find("select * from check_item");
for (int i = 0; i < list_checkItems.size(); i++) {
CheckItem checkItem = list_checkItems.get(i);
int check_item_id = checkItem.getInt("check_item_id");
if (!new CheckRecord().set("report_id", report_id_add)
.set("check_item_id", check_item_id).save()) {
break;
}
}
tmp_report_id = report_id_add;
}
}
}
boolean succeed = Db.tx(new IAtom() {
public boolean run() throws SQLException {
int _report_id;
if (report_id.equals("add")) {
_report_id = tmp_report_id;
} else {
_report_id = Integer.parseInt(report_id);
}
boolean editCheckReports = true;
editCheckReports = dao.findById(_report_id)
.set("report_name", report_name)
.set("report_creator", report_creator).update();
boolean editCheckRecords = true;
for (int i = 0; i < items.size(); i++) {
Map<String, Object> map1 = (Map<String, Object>) items
.get(i);
int check_item_id = (int) map1.get("check_item_id");
CheckRecord checkRecord = CheckRecord.dao
.findFirst(
"select * from check_record where report_id = ? and check_item_id = ?",
_report_id, check_item_id);
editCheckRecords = checkRecord.setAttrs(map1).update();
if (!editCheckRecords) {
break;
}
}
boolean editCheckRecordsPic_url = true;
for (int i = 0; i < list_uf.size(); i++) {
UploadFile uf = list_uf.get(i);
String pic_url_name = uf.getParameterName();
String[] para = pic_url_name.split("_");
int check_content_id = Integer.parseInt(para[2]);
int table_sequence = Integer.parseInt(para[3]);
String saveDirectory = "/upload"
+ File.separator
+ new SimpleDateFormat("yyyyMMdd")
.format(new Date());
String pic_url = saveDirectory + File.separator
+ uf.getFileName();
CheckItem checkItem = CheckItem.dao
.findFirst(
"select * from check_item where check_content_id = ? and table_sequence = ?",
check_content_id, table_sequence);
int check_item_id = checkItem.getInt("check_item_id");
CheckRecord checkRecord = CheckRecord.dao
.findFirst(
"select * from check_record where report_id = ? and check_item_id = ?",
report_id, check_item_id);
editCheckRecordsPic_url = checkRecord.set("pic_url",
pic_url).update();
if (!editCheckRecordsPic_url) {
break;
}
}
return editCheckRecords && editCheckReports
&& editCheckRecordsPic_url;
}
});
return succeed;
}
}
@SuppressWarnings("rawtypes")