first commit

This commit is contained in:
hjd
2015-11-14 18:14:47 +08:00
commit b3b836ae23
42 changed files with 4878 additions and 0 deletions

13
.classpath Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>

36
.project Normal file
View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jinshan</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

12
.settings/.jsdtscope Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebRoot"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="jinshan">
<wb-resource deploy-path="/" source-path="/WebRoot" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/res"/>
<property name="context-root" value="jinshan"/>
<property name="java-output-path" value="/jinshan/WebRoot/WEB-INF/classes"/>
</wb-module>
</project-modules>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="java"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

View File

@@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

View File

@@ -0,0 +1 @@
Window

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

View File

@@ -0,0 +1,4 @@
jdbcUrl = jdbc:mysql://127.0.0.1/jinshan?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
user = root
password = root
devMode = true

Binary file not shown.

View File

@@ -0,0 +1,11 @@
log4j.rootLogger=WARN, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n
# Output to the File
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=./zhongchou.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n

View File

@@ -0,0 +1,37 @@
{
report_name:"AH-H001-01 2015年3月11日18点测试表",
report_creator:"黄金定",
report_crete_time:"2015-11-14 11:46:10",
contents:
[{
No:"1",
content:"劳动防护用品",
items:
[{
item:"1.1按规定穿戴安全帽、工作服、劳保鞋等劳保用品,并保持整洁",
passed"1",
note:"",
picUrl:""
}]
},
{
No:"2",
content:"防雷防静电",
items:
[{
item:"2.1按规定进行防雷防静电检测,并提供检测记录",
passed"1",
note:"",
picUrl:""
},
{
item:"2.2接地线、网无破损、断裂",
passed"1",
note:"",
picUrl:""
}
]
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

19
WebRoot/WEB-INF/web.xml Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<filter>
<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<param-name>configClass</param-name>
<param-value>com.jinshan.common.RunConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

View File

123
doc/database/jinshan.sql Normal file
View File

@@ -0,0 +1,123 @@
/*
Navicat MySQL Data Transfer
Source Server : root
Source Server Version : 50627
Source Host : localhost:3306
Source Database : jinshan
Target Server Type : MYSQL
Target Server Version : 50627
File Encoding : 65001
Date: 2015-11-14 17:51:34
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `check_content`
-- ----------------------------
DROP TABLE IF EXISTS `check_content`;
CREATE TABLE `check_content` (
`check_content_id` int(11) NOT NULL,
`check_content` varchar(200) NOT NULL,
PRIMARY KEY (`check_content_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of check_content
-- ----------------------------
INSERT INTO `check_content` VALUES ('1', '劳动防护用品');
INSERT INTO `check_content` VALUES ('2', '防雷防静电');
INSERT INTO `check_content` VALUES ('3', '出入库管理');
INSERT INTO `check_content` VALUES ('4', '库区环境管理');
INSERT INTO `check_content` VALUES ('5', '爆破器材的堆放标准');
INSERT INTO `check_content` VALUES ('6', '消防设施');
-- ----------------------------
-- Table structure for `check_item`
-- ----------------------------
DROP TABLE IF EXISTS `check_item`;
CREATE TABLE `check_item` (
`check_item` varchar(200) NOT NULL,
`table_sequence` int(11) unsigned NOT NULL,
`check_content_id` int(11) NOT NULL,
PRIMARY KEY (`check_item`),
KEY `check_content_id` (`check_content_id`),
CONSTRAINT `check_content_id` FOREIGN KEY (`check_content_id`) REFERENCES `check_content` (`check_content_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of check_item
-- ----------------------------
INSERT INTO `check_item` VALUES ('严禁人员携带火种、通讯工具、易燃易爆物品进入库区', '2', '3');
INSERT INTO `check_item` VALUES ('仓库门窗无破损,库内通风良好', '4', '4');
INSERT INTO `check_item` VALUES ('喷淋设施完好且水源充足', '6', '6');
INSERT INTO `check_item` VALUES ('外来人员应有人带领,实行严格登记手续', '1', '3');
INSERT INTO `check_item` VALUES ('库内安全通道无杂物堆放,畅通无阻', '2', '4');
INSERT INTO `check_item` VALUES ('库内温度保持在35度以下湿度计保持在85%以下', '1', '4');
INSERT INTO `check_item` VALUES ('库区夜间照明充足(固定、移动照明)并设有应急照明', '7', '4');
INSERT INTO `check_item` VALUES ('库区有足够的消防通道并保持畅通不小于4米且形成环形通道', '3', '4');
INSERT INTO `check_item` VALUES ('库区范围内无山火', '9', '4');
INSERT INTO `check_item` VALUES ('库房值班室应装有两部与外界联系的固定电话', '6', '3');
INSERT INTO `check_item` VALUES ('库房围墙、电网无破损', '10', '4');
INSERT INTO `check_item` VALUES ('库房无破损,屋顶无漏雨', '5', '4');
INSERT INTO `check_item` VALUES ('按规定穿戴安全帽、工作服、劳保鞋等劳保用品,并保持整洁', '1', '1');
INSERT INTO `check_item` VALUES ('按规定进行防雷防静电检测,并提供检测记录', '1', '2');
INSERT INTO `check_item` VALUES ('接地线、网无破损、断裂', '2', '2');
INSERT INTO `check_item` VALUES ('消防栓闸阀灵敏、可靠 ', '4', '6');
INSERT INTO `check_item` VALUES ('消防水池蓄满水,消防沙定期翻动 ', '3', '6');
INSERT INTO `check_item` VALUES ('消防水管、水泵完好并保证双回路供电 ', '2', '6');
INSERT INTO `check_item` VALUES ('消防水袋齐全、完好?确定数量 ', '5', '6');
INSERT INTO `check_item` VALUES ('火工器材出入帐目清楚,帐物相符', '3', '3');
INSERT INTO `check_item` VALUES ('火工器材箱子条码与货物条码一致', '5', '3');
INSERT INTO `check_item` VALUES ('灭火器插销完好并在有效期内使用,指针显示在绿色区域', '1', '6');
INSERT INTO `check_item` VALUES ('炸药堆高不超过1.8米、雷管堆高不超过1.6米', '2', '5');
INSERT INTO `check_item` VALUES ('炸药库周围无杂草及其它易燃物', '8', '4');
INSERT INTO `check_item` VALUES ('炸药库设双门双锁,门无变形、破损;标识牌、警示牌齐全、规范', '6', '4');
INSERT INTO `check_item` VALUES ('爆破器材要按类分存,严禁混存', '1', '5');
INSERT INTO `check_item` VALUES ('禁止车辆未熄火时进行装卸;装卸时必须轻拿轻放', '4', '3');
INSERT INTO `check_item` VALUES ('通道宽不少于1.3米堆垛距离边墙不少于0.3米', '3', '5');
-- ----------------------------
-- Table structure for `check_record`
-- ----------------------------
DROP TABLE IF EXISTS `check_record`;
CREATE TABLE `check_record` (
`record_id` int(11) NOT NULL AUTO_INCREMENT,
`report_id` int(11) NOT NULL,
`check_item` varchar(200) NOT NULL,
`passed` varchar(1) NOT NULL,
`pic_url` varchar(200) DEFAULT '""',
`note` varchar(200) DEFAULT '""',
PRIMARY KEY (`record_id`),
KEY `check_item` (`check_item`),
KEY `report_id` (`report_id`),
CONSTRAINT `check_item` FOREIGN KEY (`check_item`) REFERENCES `check_item` (`check_item`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `report_id` FOREIGN KEY (`report_id`) REFERENCES `report` (`report_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of check_record
-- ----------------------------
INSERT INTO `check_record` VALUES ('1', '1', '按规定穿戴安全帽、工作服、劳保鞋等劳保用品,并保持整洁', '1', '', '备注1');
INSERT INTO `check_record` VALUES ('2', '1', '按规定进行防雷防静电检测,并提供检测记录', '1', '', '备注2');
INSERT INTO `check_record` VALUES ('3', '1', '接地线、网无破损、断裂', '0', '', '备注3');
-- ----------------------------
-- Table structure for `report`
-- ----------------------------
DROP TABLE IF EXISTS `report`;
CREATE TABLE `report` (
`report_id` int(11) NOT NULL AUTO_INCREMENT,
`report_name` varchar(200) NOT NULL,
`report_creator` varchar(200) NOT NULL,
`report_create_time` varchar(19) NOT NULL,
PRIMARY KEY (`report_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of report
-- ----------------------------
INSERT INTO `report` VALUES ('1', 'AH-H001-01 2015年3月11日18点测试表', '黄金定', '2015-11-14 11:46:10');

20
doc/启动说明.txt Normal file
View File

@@ -0,0 +1,20 @@
项目启动步骤
1 使用 jinshan.sql 中的 sql 语句创建数据库与数据库表
2: 修改 WebRoot/WEB-INF/a_little_config.txt 文件,填入正确的数据库连接用户名、密码
3: 将项目导入 eclipse。推荐使用 Eclipse IDE for Java EE Developers 版本Eclipse Kepler (4.3.2) SR2此版本天然支持 git
下载地址:
32位 https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR2/eclipse-jee-kepler-SR2-win32.zip&mirror_id=547
64位 https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR2/eclipse-jee-kepler-SR2-win32-x86_64.zip&mirror_id=547
如果觉得皮肤不好看可以通过设置Windows ---> Preferences ---> General ---> Appearance ---> Theme 选择 classic
4: 打开 com.jinshan.common包下的 RunConfig文件右键单击该文件并选择 Debug As ---> Java Application。
其它启动项目的方式见 《JFinal手册》。除此之外项目还可以与其它普通java web 项目一样使用 tomcat
jetty 等 web server 来启动启动方式与非jfinal项目完全一样。
5: 打开浏览器输入 localhost 即可查看运行效果
注意: 请确保您安装了 JavaSE 1.6 或更高版本tomcat下运行项目需要先删除 jetty-server-xxx.jar否则会有冲突

4
res/a_little_config.txt Normal file
View File

@@ -0,0 +1,4 @@
jdbcUrl = jdbc:mysql://127.0.0.1/jinshan?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
user = root
password = root
devMode = true

11
res/log4j.properties Normal file
View File

@@ -0,0 +1,11 @@
log4j.rootLogger=WARN, stdout, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n
# Output to the File
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=./zhongchou.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n

View File

@@ -0,0 +1,79 @@
package com.jinshan.common;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jinshan.controller.IndexController;
import com.jinshan.controller.ReportController;
import com.jinshan.model.CheckContent;
import com.jinshan.model.CheckItem;
import com.jinshan.model.CheckRecord;
import com.jinshan.model.Report;
public class RunConfig extends JFinalConfig {
@Override
public void configConstant(Constants me) {
// TODO Auto-generated method stub
PropKit.use("a_little_config.txt");
me.setDevMode(PropKit.getBoolean("devMode", false));
}
@Override
public void configRoute(Routes me) {
// TODO Auto-generated method stub
me.add("/", IndexController.class);// 默认
me.add("report", ReportController.class);
}
@Override
public void configPlugin(Plugins me) {
// TODO Auto-generated method stub
C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
PropKit.get("password").trim());
me.add(c3p0Plugin);
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
me.add(arp);
arp.addMapping("check_content", "check_content_id", CheckContent.class);
arp.addMapping("check_item", "check_item", CheckItem.class);
arp.addMapping("check_record", "record_id", CheckRecord.class);
arp.addMapping("report", "report_id", Report.class);
}
@Override
public void configInterceptor(Interceptors me) {
// TODO Auto-generated method stub
}
@Override
public void configHandler(Handlers me) {
// TODO Auto-generated method stub
}
@Override
public void afterJFinalStart() {
// TODO Auto-generated method stub
super.afterJFinalStart();
}
@Override
public void beforeJFinalStop() {
// TODO Auto-generated method stub
super.beforeJFinalStop();
}
public static void main(String[] args) {
JFinal.start("WebRoot", 80, "/", 5);
}
}

View File

@@ -0,0 +1,12 @@
package com.jinshan.controller;
import com.jfinal.core.Controller;
public class IndexController extends Controller {
public void index() {
setAttr("status", "SUCCESS");
renderJson();
}
}

View File

@@ -0,0 +1,113 @@
package com.jinshan.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.jfinal.core.Controller;
import com.jinshan.model.Report;
public class ReportController extends Controller {
public void query() {
Integer report_id = getParaToInt("report_id");
Report report = Report.dao.findById(report_id);
if (report != null) {
String report_name = report.getStr("report_name");
String report_creator = report.getStr("report_creator");
String report_create_time = report.getStr("report_create_time");
setAttr("report_name", report_name);
setAttr("report_creator", report_creator);
setAttr("report_create_time", report_create_time);
List<Object> contents = Report.dao.query(report_id);
setAttr("contents", contents);
}
renderJson();
}
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");
}
}
renderJson();
}
private boolean add() {
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 delete() {
Integer report_id = getParaToInt("report_id");
if (Report.dao.deleteById(report_id)) {
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;
}
}
private String getBody(HttpServletRequest request) throws ServletException, IOException {
StringBuilder sb = new StringBuilder();
BufferedReader reader = request.getReader();
try {
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
} finally {
reader.close();
}
String bodyStr = new String(sb);
return bodyStr;
}
}

View File

@@ -0,0 +1,8 @@
package com.jinshan.model;
import com.jfinal.plugin.activerecord.Model;
@SuppressWarnings("serial")
public class CheckContent extends Model<CheckContent> {
public static CheckContent dao = new CheckContent();
}

View File

@@ -0,0 +1,9 @@
package com.jinshan.model;
import com.jfinal.plugin.activerecord.Model;
@SuppressWarnings("serial")
public class CheckItem extends Model<CheckItem>{
public static CheckItem dao = new CheckItem();
}

View File

@@ -0,0 +1,9 @@
package com.jinshan.model;
import com.jfinal.plugin.activerecord.Model;
@SuppressWarnings("serial")
public class CheckRecord extends Model<CheckRecord>{
public static CheckRecord dao = new CheckRecord();
}

View File

@@ -0,0 +1,190 @@
package com.jinshan.model;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Model;
@SuppressWarnings("serial")
public class Report extends Model<Report> {
public static Report dao = new Report();
@SuppressWarnings({ "unchecked" })
public List<Object> query(int report_id) {
ArrayList<Object> list = new ArrayList<>();
List<CheckRecord> check_records = CheckRecord.dao.find("select * from check_record where report_id = ?",
report_id);
if (check_records != null && check_records.size() > 0) {
for (int i = 0; i < check_records.size(); i++) {
CheckRecord check_record = check_records.get(i);
String check_item = check_record.getStr("check_item");
String passed = check_record.getStr("passed");
String pic_url = check_record.getStr("pic_url");
String note = check_record.getStr("note");
CheckItem checkItem = CheckItem.dao.findById(check_item);
int check_content_id = checkItem.getInt("check_content_id");
int table_sequence = checkItem.getLong("table_sequence").intValue();
CheckContent checkContent = CheckContent.dao.findById(check_content_id);
String check_content = checkContent.getStr("check_content");
Map<String, Object> item = new HashMap<>();
item.put("item", check_content_id + "." + table_sequence + check_item);
item.put("passed", passed);
item.put("note", note);
item.put("pic_url", pic_url);
boolean hasThisNo = false;
int NoIndex = -1;
for (int j = 0; j < list.size(); j++) {
Map<String, Object> map = (Map<String, Object>) list.get(j);
if ((int) map.get("No") == check_content_id) {
hasThisNo = true;
NoIndex = j;
break;
} else {
continue;
}
}
if (hasThisNo) {
Map<String, Object> map = (Map<String, Object>) list.get(NoIndex);
ArrayList<Object> items = (ArrayList<Object>) map.get("items");
items.add(item);
map.put("items", items);
list.set(NoIndex, map);
} else {
ArrayList<Object> items = new ArrayList<>();
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;
} else {
return null;
}
}
public boolean updateByJSONObject(JSONObject jsonObject) {
if (jsonObject.has("report_id")) {
add(jsonObject);
} else {
edit(jsonObject);
}
return false;
}
private boolean add(JSONObject jsonObject) {
String report_create_time = jsonObject.getString("report_create_time");
String report_name = jsonObject.getString("report_name");
String report_creator = jsonObject.getString("report_creator");
Map<String, Object> map = new HashMap<>();
map.put("report_create_time", report_create_time);
map.put("report_name", report_name);
map.put("report_creator", report_creator);
JSONArray contents = jsonObject.getJSONArray("contents");
boolean succeed = Db.tx(new IAtom() {
public boolean run() throws SQLException {
boolean addReport = new Report().setAttrs(map).save();
int report_id = dao.findFirst(
"select * from report where report_create_time = ? and report_name = ? and report_creator = ",
report_create_time, report_name, report_creator).getInt("report_id");
boolean addCheckRecords = true;
lableA: for (int i = 0; i < contents.length(); i++) {
JSONObject content = contents.getJSONObject(i);
JSONArray items = content.getJSONArray("items");
for (int j = 0; j < items.length(); j++) {
JSONObject item = items.getJSONObject(j);
String check_item = item.getString("item").substring(2, item.getString("item").length() - 1);
String passed = item.getString("passed");
String pic_url = item.getString("pic_url");
String note = item.getString("note");
Map<String, Object> map = new HashMap<>();
map.put("report_id", report_id);
map.put("check_item", check_item);
map.put("passed", passed);
map.put("pic_url", pic_url);
map.put("note", note);
addCheckRecords = new CheckRecord().setAttrs(map).save();
if (!addCheckRecords) {
break lableA;
}
}
}
return addReport && addCheckRecords;
}
});
return succeed;
}
private boolean edit(JSONObject jsonObject) {
int report_id = jsonObject.getInt("report_id");
String report_create_time = jsonObject.getString("report_create_time");
String report_name = jsonObject.getString("report_name");
String report_creator = jsonObject.getString("report_creator");
Map<String, Object> map = new HashMap<>();
map.put("report_create_time", report_create_time);
map.put("report_name", report_name);
map.put("report_creator", report_creator);
JSONArray contents = jsonObject.getJSONArray("contents");
boolean succeed = Db.tx(new IAtom() {
public boolean run() throws SQLException {
boolean addReport = new Report().setAttrs(map).save();
boolean addCheckRecords = true;
lableA: for (int i = 0; i < contents.length(); i++) {
JSONObject content = contents.getJSONObject(i);
JSONArray items = content.getJSONArray("items");
for (int j = 0; j < items.length(); j++) {
JSONObject item = items.getJSONObject(j);
String check_item = item.getString("item").substring(2, item.getString("item").length() - 1);
String passed = item.getString("passed");
String pic_url = item.getString("pic_url");
String note = item.getString("note");
Map<String, Object> map = new HashMap<>();
map.put("report_id", report_id);
map.put("check_item", check_item);
map.put("passed", passed);
map.put("pic_url", pic_url);
map.put("note", note);
addCheckRecords = new CheckRecord().setAttrs(map).update();
if (!addCheckRecords) {
break lableA;
}
}
}
return addReport && addCheckRecords;
}
});
return succeed;
}
}

37
src/report.json Normal file
View File

@@ -0,0 +1,37 @@
{
report_name:"AH-H001-01 2015年3月11日18点测试表",
report_creator:"黄金定",
report_crete_time:"2015-11-14 11:46:10",
contents:
[{
No:"1",
content:"劳动防护用品",
items:
[{
item:"1.1按规定穿戴安全帽、工作服、劳保鞋等劳保用品,并保持整洁",
passed"1",
note:"",
picUrl:""
}]
},
{
No:"2",
content:"防雷防静电",
items:
[{
item:"2.1按规定进行防雷防静电检测,并提供检测记录",
passed"1",
note:"",
picUrl:""
},
{
item:"2.2接地线、网无破损、断裂",
passed"1",
note:"",
picUrl:""
}
]
}
}

4101
zhongchou.log Normal file

File diff suppressed because it is too large Load Diff