提交 df52be0f authored 作者: 刘守彩's avatar 刘守彩

feat: 井道添加上一次记录

上级 ce163f36
import SqlliteDbUtil from '@/utils/sqllitedb'
import table from './sqllite/table.js'
/**
* 清理过期的巡检列表和日志列表,防止数据过多
*/
export async function cleanTimeoutDataApi() {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB()
try {
const sql =
`DELETE FROM ${table.inspectionRecordName} WHERE createTime < (strftime('%s', 'now') - 90 * 24 * 60 * 60) * 1000`;
const ret = await sqllitedb.executeSQL(sql);
const cleanSql = `
DELETE FROM ${table.logListName}
WHERE id NOT IN (
SELECT id FROM ${table.logListName}
ORDER BY time DESC
LIMIT 100
)
`
const ret1 = await sqllitedb.executeSQL(cleanSql)
console.log('cleanTimeoutDataApi success', ret, ret1)
} catch (e) {
console.error('cleanTimeoutDataApi error', e.message)
} finally {
// await sqllitedb.closeDB();
}
}
\ No newline at end of file
import SqlliteDbUtil from "@/utils/sqllitedb"; import SqlliteDbUtil from "@/utils/sqllitedb";
import table from "./sqllite/table.js"; import table from "./sqllite/table.js";
import { fixNullVal } from "@/utils/common"; import { fixNullVal } from "@/utils/common";
// 巡检 // 巡检
export default { export default {
async selectLastData(data) { async selectLastData(data, inspectionType = 1) {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try { try {
let rs = await sqllitedb.selectSQL( let rs = await sqllitedb.selectSQL(
...@@ -12,7 +12,7 @@ export default { ...@@ -12,7 +12,7 @@ export default {
FROM ${table.inspectionRecordName} FROM ${table.inspectionRecordName}
WHERE userId = '${data}' WHERE userId = '${data}'
AND createTime >= strftime('%s', 'now') - 7*24*60*60 AND createTime >= strftime('%s', 'now') - 7*24*60*60
AND inspectionType = 1 AND inspectionType = '${inspectionType}'
AND (synFlag = 0 OR synFlag = 1) AND (synFlag = 0 OR synFlag = 1)
ORDER BY createTime DESC ORDER BY createTime DESC
LIMIT 1;` LIMIT 1;`
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"appid" : "__UNI__A11BFD5", "appid" : "__UNI__A11BFD5",
"description" : "", "description" : "",
"versionName" : "1.0.2", "versionName" : "1.0.2",
"versionCode" : 102, "versionCode" : 103,
"transformPx" : false, "transformPx" : false,
/* 5+App特有相关 */ /* 5+App特有相关 */
"app-plus" : { "app-plus" : {
......
...@@ -71,7 +71,8 @@ ...@@ -71,7 +71,8 @@
<script> <script>
import { copyDirectory } from "@/utils/IoReadingAndWriting.js"; import { copyDirectory } from "@/utils/IoReadingAndWriting.js";
import inspectApi from "@/api/inspect.js"; import inspectApi from "@/api/inspect.js";
import { cleanTimeoutDataApi } from '@/api/base.js'
export default { export default {
data() { data() {
return { return {
...@@ -101,7 +102,8 @@ export default { ...@@ -101,7 +102,8 @@ export default {
}, },
}, },
created() { created() {
console.log(this.$store.state); console.log(this.$store.state);
cleanTimeoutDataApi();
}, },
methods: { methods: {
// 修改密码 // 修改密码
......
...@@ -202,7 +202,11 @@ ...@@ -202,7 +202,11 @@
return item; return item;
}); // 井道数据类型是 2 }); // 井道数据类型是 2
console.log(5151, JFXJ_DATA, JDXJ_DATA); console.log(5151, JFXJ_DATA, JDXJ_DATA);
const batchData = [...JFXJ_DATA, ...JDXJ_DATA] const batchData = [...JFXJ_DATA, ...JDXJ_DATA]
let zipName = '巡检';
if(batchData.length === 1) {
zipName = batchData[0].inspectionType == 1 ? '机房巡检' : '井道巡检';
}
this.loading = true; this.loading = true;
const tmepList = []; const tmepList = [];
if (notSynchronizationList.length > 1) { if (notSynchronizationList.length > 1) {
...@@ -264,7 +268,7 @@ ...@@ -264,7 +268,7 @@
await this.copyPhotos(); await this.copyPhotos();
zipCompress( zipCompress(
`${SYNCHRONIZE_DATA_PAD}/发送数据`, `${SYNCHRONIZE_DATA_PAD}/发送数据`,
`${SYNCHRONIZE_DATA_PAD}/fssj/${userName}_XJ_${timeStr}.zip` `${SYNCHRONIZE_DATA_PAD}/fssj/${userName}_${zipName}_${timeStr}.zip`
); );
// zip // zip
await inspectApi.updateSyncData(ids); await inspectApi.updateSyncData(ids);
......
...@@ -279,7 +279,7 @@ import inspectApi from "@/api/inspect"; ...@@ -279,7 +279,7 @@ import inspectApi from "@/api/inspect";
import signDialog from "@/components/signDialog.vue"; import signDialog from "@/components/signDialog.vue";
import detail from "./model/detail.vue"; import detail from "./model/detail.vue";
import Dialog from "@/pages/inspectionManagement/dialog.vue"; import Dialog from "@/pages/inspectionManagement/dialog.vue";
import { sqlToData, dataToSql } from "./shared"; import { sqlToData, dataToSql, getHistoryData } from "./shared";
export default { export default {
components: { components: {
signDialog, signDialog,
...@@ -315,6 +315,7 @@ export default { ...@@ -315,6 +315,7 @@ export default {
isSign: false, //签名状态 isSign: false, //签名状态
isSubmit: 0, //提交状态 isSubmit: 0, //提交状态
uid: "", uid: "",
did: '', // 最近7天数据的id
options: {}, //存储数据 options: {}, //存储数据
backValue: "", backValue: "",
all_data: [], //所有数据 all_data: [], //所有数据
...@@ -357,12 +358,71 @@ export default { ...@@ -357,12 +358,71 @@ export default {
console.log("options.uid", this.options.uid); console.log("options.uid", this.options.uid);
this.uid = this.options.uid || ""; this.uid = this.options.uid || "";
}, },
onShow() { async onShow() {
if (this.uid) { // if (this.uid) {
this.getDetails(this.uid); // this.getDetails(this.uid);
} else { // } else {
this.init(); // this.init();
} // }
if(this.uid) {
this.getDetails(this.uid)
} else {
// 获取7日(168小时)内最后一条巡检记录回显到页面(选项、文案、照片;异常项-不调出文案及照片)
getHistoryData().then((res) => {
if (res) {
console.log(res);
const detailsInfo = sqlToData(res);
this.did = detailsInfo.id;
console.log("getHistoryData sqltodata", detailsInfo);
this.detailsInfo = detailsInfo;
this.inspectionNumber = detailsInfo.inspectionNumber;
if (detailsInfo.synchronization == 1) {
// 已同步数据的查看详情时,只展示'已巡检'的井道信息,过滤未巡检的井道
let defaultList = detailsInfo.originData;
this.cardsInfo = this.tabList = defaultList.filter((building) => {
building.position = building.position.filter(
(pos) => pos.status == "1" || pos.status == "2"
);
return building.position.length;
});
} else {
this.cardsInfo = this.tabList = detailsInfo.originData;
}
this.inspectionCode = detailsInfo.inspectionCode;
this.isSubmit = 0;
// this.isSubmit = this.detailsInfo.originData
// .reduce((acc, cur) => {
// acc.push(...cur.position);
// return acc;
// }, [])
// .every((pos) => pos.isSubmit === "" || pos.isSubmit === 1);
delete this.detailsInfo.id;
console.log('history detail', this.detailsInfo);
this.tabs = ["所有井道"];
this.tabsDetail = ["所有井道"];
this.isSign = !!this.detailsInfo.signImg;
this.cardsInfo.forEach((item) => {
this.tabs.push(item.name);
this.tabsDetail.push(item.name);
});
if (this.isSign) {
this.getActiveTabDetails(0);
}
this.isDisable = this.isDisable || detailsInfo.synchronization == 1; // 是否禁用 1:已同步数据 0: 未同步数据
uni.hideLoading();
} else {
this.init();
}
});
}
this.all_data = this.$store.state.all_data; this.all_data = this.$store.state.all_data;
}, },
mounted() {}, mounted() {},
...@@ -465,7 +525,6 @@ export default { ...@@ -465,7 +525,6 @@ export default {
this.cardsInfo = this.tabList = detailsInfo.originData; this.cardsInfo = this.tabList = detailsInfo.originData;
} }
this.inspectionCode = detailsInfo.inspectionCode; this.inspectionCode = detailsInfo.inspectionCode;
// this.cardsInfo = this.tabList = detailsInfo.originData;
this.isSubmit = this.detailsInfo.originData this.isSubmit = this.detailsInfo.originData
.reduce((acc, cur) => { .reduce((acc, cur) => {
acc.push(...cur.position); acc.push(...cur.position);
...@@ -583,7 +642,7 @@ export default { ...@@ -583,7 +642,7 @@ export default {
// 跳转到具体的井道 // 跳转到具体的井道
toShaftInspection(value, dictValue, location) { toShaftInspection(value, dictValue, location) {
uni.navigateTo({ uni.navigateTo({
url: `/pages/shaftInspection/shaftInspectionNew?value=${value}&dictValue=${dictValue}&inspectionCode=${this.inspectionCode}&location=${location}&uid=${this.uid}&backValue=${this.backValue}`, url: `/pages/shaftInspection/shaftInspectionNew?value=${value}&dictValue=${dictValue}&inspectionCode=${this.inspectionCode}&location=${location}&uid=${this.uid}&backValue=${this.backValue}&did=${this.did}`,
}); });
}, },
back() { back() {
......
...@@ -169,7 +169,7 @@ import moment from "moment"; ...@@ -169,7 +169,7 @@ import moment from "moment";
import customPopup from "./model/customPopup.vue"; import customPopup from "./model/customPopup.vue";
import _ from "lodash"; import _ from "lodash";
import inspectApi from "@/api/inspect"; import inspectApi from "@/api/inspect";
import { sqlToData, dataToSql } from "./shared"; import { sqlToData, dataToSql, getHistoryData } from "./shared";
export default { export default {
components: { components: {
...@@ -184,6 +184,7 @@ export default { ...@@ -184,6 +184,7 @@ export default {
inspectionCode: "", inspectionCode: "",
isSubmitEnabled: false, // 提交按钮是否可点击 isSubmitEnabled: false, // 提交按钮是否可点击
uid: "", uid: "",
did: '', // 最近7天的井道巡检id
randomDescription: "这是一段随机说明文字。", // 随机说明文字 randomDescription: "这是一段随机说明文字。", // 随机说明文字
tabs: [ tabs: [
{ {
...@@ -232,6 +233,7 @@ export default { ...@@ -232,6 +233,7 @@ export default {
this.coverlist(); this.coverlist();
this.isDisable = options.isDisable == 1 ? true : false; this.isDisable = options.isDisable == 1 ? true : false;
this.uid = options.uid; this.uid = options.uid;
this.did = options.did || '';
this.location = options.location; this.location = options.location;
this.value = options.value; this.value = options.value;
this.dictValue = options.dictValue; this.dictValue = options.dictValue;
...@@ -242,9 +244,32 @@ export default { ...@@ -242,9 +244,32 @@ export default {
if (options.uid) { if (options.uid) {
this.getDetails(options.uid); this.getDetails(options.uid);
} else if(this.did){
getHistoryData().then(res =>{
console.error('getHistoryData detail', res)
const detailsInfo = sqlToData(res);
delete detailsInfo.id;
let list =
detailsInfo.originData[this.value - 1].position[this.dictValue - 1]
.details;
this.detailsInfo = detailsInfo;
// 未巡检需要处理默认数据结构
if (list && list.length) {
this.list = list;
}
this.inspectionResult = list[0].inspectionResult;
list.forEach((item, index) => {
this.tabs[index].status = item.inspectionResult === 0 ? "1" : "2";
});
this.isDisable = this.isDisable || detailsInfo.synchronization == 1; // 是否禁用 1:已同步数据 0: 未同步数据
uni.hideLoading();
})
} else { } else {
this.init(); this.init();
} }
}, },
watch: {}, watch: {},
mounted() {}, mounted() {},
...@@ -390,7 +415,7 @@ export default { ...@@ -390,7 +415,7 @@ export default {
}, },
// 处理提交数据 // 处理提交数据
getParams(isSubmit) { getParams(isSubmit) {
if (this.uid) { if (this.uid || this.did) {
console.log("74", this.value, this.dictValue, this.detailsInfo); console.log("74", this.value, this.dictValue, this.detailsInfo);
let posItem = let posItem =
this.detailsInfo.originData[this.value - 1].position[ this.detailsInfo.originData[this.value - 1].position[
...@@ -593,6 +618,13 @@ export default { ...@@ -593,6 +618,13 @@ export default {
this.uid ? this.uid : saveRes.lastInsertId this.uid ? this.uid : saveRes.lastInsertId
}&backValue=${this.backValue}`, }&backValue=${this.backValue}`,
}); });
// // 更新
// if (!this.uid) {
// this.uid = res.lastInsertId;
// setTimeout(() => {
// this.getDetails(res.lastInsertId);
// }, 300);
// }
} catch (err) { } catch (err) {
console.log("err", err); console.log("err", err);
} }
......
import moment from "moment"; import moment from "moment";
import store from "@/store"; import store from "@/store";
import inspectApi from "@/api/inspect.js";
// 将现有机房巡检数据转换为SQL数据所需要格式
export function dataToSql(data) { // 将现有机房巡检数据转换为SQL数据所需要格式
let synFlag = 0; export function dataToSql(data) {
// 是否有草稿状态的井道 let synFlag = 0;
let hasDraft; // 是否有草稿状态的井道
hasDraft = !(data.originData.reduce((acc,cur) => { let hasDraft;
acc.push(...cur.position) hasDraft = !(data.originData.reduce((acc, cur) => {
return acc acc.push(...cur.position)
}, []).every(pos => pos.isSubmit === '' || pos.isSubmit === 1)) return acc
if (data.synchronization === 1) { }, []).every(pos => pos.isSubmit === '' || pos.isSubmit === 1))
synFlag = 1; if (data.synchronization === 1) {
} else { synFlag = 1;
if(hasDraft || !data.signImg) { } else {
synFlag = 2 if (hasDraft || !data.signImg) {
} else { synFlag = 2
synFlag = 0 } else {
} synFlag = 0
} }
const send = { }
inspectionType: data.inspectionType, const send = {
inspectionCode: data.inspectionCode, inspectionType: data.inspectionType || 2,
recordName: `${moment().format("yyyyMMDD")}-井道巡检`, inspectionCode: data.inspectionCode || `JDXJ${moment().format("yyyyMMDDHHmmss")}${Math.floor(Math.random() * 900) + 100}`,
inspectionTime: moment().valueOf(), recordName: `${moment().format("yyyyMMDD")}-井道巡检`,
isException: data.isException, // 是否异常:0 否 1 是 2 巡检中 inspectionTime: moment().valueOf(),
userId: store.state.now_user.userId, isException: data.isException, // 是否异常:0 否 1 是 2 巡检中
userName: store.state.now_user.user, userId: store.state.now_user.userId,
synFlag: synFlag, // 0.未同步,1.已同步,2.编辑 userName: store.state.now_user.user,
signImg: data.signImg || "", synFlag: synFlag, // 0.未同步,1.已同步,2.编辑
createBy: store.state.now_user.userId, signImg: data.signImg || "",
createTime: data.id ? data.createTime : `${new Date().getTime()}`, createBy: store.state.now_user.userId,
updateTime: `${new Date().getTime()}`, createTime: data.id ? data.createTime : `${new Date().getTime()}`,
updateBy: store.state.now_user.userId, updateTime: `${new Date().getTime()}`,
inspectionData: data.originData, updateBy: store.state.now_user.userId,
}; inspectionData: data.originData,
console.log("dataToSql", send); };
return send; console.log("dataToSql", send);
} return send;
}
export function sqlToData(sqlData) {
try { export function sqlToData(sqlData) {
let isSubmit; try {
let synchronization; let isSubmit;
let synchronization;
if (sqlData.synFlag === 0) {
isSubmit = 0; if (sqlData.synFlag === 0) {
synchronization = 0; isSubmit = 0;
} else { synchronization = 0;
isSubmit = 1; } else {
synchronization = sqlData.synFlag; isSubmit = 1;
} synchronization = sqlData.synFlag;
const originData = JSON.parse(sqlData.inspectionData || "{}"); }
const inspectedItems = originData.reduce((acc,cur) => { const originData = JSON.parse(sqlData.inspectionData || "{}");
acc.push(...cur.position) const inspectedItems = originData.reduce((acc, cur) => {
return acc acc.push(...cur.position)
}, []).filter((item) => (item.status == 1 || item.status == 2) && item.isSubmit !== 0) return acc
console.log(inspectedItems) }, []).filter((item) => (item.status == 1 || item.status == 2) && item.isSubmit !== 0)
console.log(inspectedItems)
// 获取已经巡检过的数量
const inspectionNumber = inspectedItems.length; // 获取已经巡检过的数量
const inspectionNumber = inspectedItems.length;
const ret = {
id: sqlData.id, const ret = {
inspectionType: sqlData.inspectionType, id: sqlData.id,
inspectionCode: sqlData.inspectionCode, inspectionType: sqlData.inspectionType || 2,
isException: sqlData.isException, inspectionCode: sqlData.inspectionCode ,
signImg: sqlData.signImg, isException: sqlData.isException,
createTime: sqlData.createTime, signImg: sqlData.signImg,
isSubmit: isSubmit, createTime: sqlData.createTime,
synchronization: synchronization, isSubmit: isSubmit,
originData, synchronization: synchronization,
inspectionNumber originData,
}; inspectionNumber
console.log(ret) };
return ret; console.log(ret)
} catch (err) { return ret;
console.log(err) } catch (err) {
} console.log(err)
} }
}
export function getHistoryData() {
return new Promise((resolve, reject) => {
inspectApi.selectLastData(store.state.now_user.userId, 2).then((history) => {
if (history && history.length) {
// 处理历史数据(选项、文案、照片;异常项-不调出文案及照片)
const data = setHistoryData(history[0]);
resolve(data);
} else {
resolve(null);
}
});
});
}
function setHistoryData(data) {
const inspectionData = JSON.parse(data.inspectionData || '[]');
// 如果该机房有异常项,则不调出文案及照片
inspectionData.forEach(item => {
item.position.forEach((current) => {
if (current.statusLable == '巡检异常') {
current.statusLable = '草稿'
// 内部的异常标识
current.details.forEach((detail) => {
// 表单项的异常
if (detail.inspectionResult == 1) {
detail.conclusion = "";
detail.photos = [];
}
});
}
});
})
data.inspectionData = JSON.stringify(inspectionData)
data.signImg = "";
data.synFlag = 0
data.inspectionCode = `JDXJ${moment().format("yyyyMMDDHHmmss")}${Math.floor(Math.random() * 900) + 100}`;
delete data.createTime
delete data.delFlag;
delete data.inspectionTime;
// delete data.synFlag;
delete data.updateBy;
delete data.updateTime;
delete data.userId;
delete data.userName;
delete data.recordName;
return data;
}
\ No newline at end of file
...@@ -161,11 +161,11 @@ export default { ...@@ -161,11 +161,11 @@ export default {
const tmepList = []; const tmepList = [];
if (JFXJ_DATA.length) { if (JFXJ_DATA.length) {
let JFXJ_DATA_FILE_NAME = `${userName}_JFXJ_${timeStr}.txt`; let JFXJ_DATA_FILE_NAME = `${userName}_机房巡检_${timeStr}.txt`;
tmepList.push(this.packedData(JDXJ_DATA, JFXJ_DATA_FILE_NAME)); tmepList.push(this.packedData(JDXJ_DATA, JFXJ_DATA_FILE_NAME));
} }
if (JDXJ_DATA.length) { if (JDXJ_DATA.length) {
let JDXJ_DATA_FILE_NAME = `${userName}_JDXJ_${timeStr}.txt`; let JDXJ_DATA_FILE_NAME = `${userName}_井道巡检_${timeStr}.txt`;
tmepList.push(this.packedData(JDXJ_DATA, JDXJ_DATA_FILE_NAME)); tmepList.push(this.packedData(JDXJ_DATA, JDXJ_DATA_FILE_NAME));
} }
...@@ -215,7 +215,7 @@ export default { ...@@ -215,7 +215,7 @@ export default {
"", "",
"同步模块" "同步模块"
); );
this.$logApi.addlog(logContent) this.$logApi.addlog(logContent)
const log_list = this.$store.state.log_list; const log_list = this.$store.state.log_list;
log_list.push(logContent); log_list.push(logContent);
this.$store.commit("SET_LOG_LIST", log_list); this.$store.commit("SET_LOG_LIST", log_list);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论