写点什么

从 0 到 1:园区巡检与隐患上报小程序开发笔记(上)

作者:CC同学
  • 2025-06-28
    广东
  • 本文字数:3659 字

    阅读完需:约 12 分钟

从0到1:园区巡检与隐患上报小程序开发笔记(上)

背景研究

巡检和隐患上报小程序:可以帮助工厂车间、仓库货物、企业管道阀门、制造车间、施工现场、塔吊升降机、施工围挡、高速公路、铁路设备、车辆安全、港口船舶设施、小区物业设施、学校教学楼实验室、医院医疗设备、商场消防通道检进行巡检和问题上报,并可指定相关工作人员进行处理。其包括管理员,处置工作人员,用户三端,分别有各自独立的系统界面和功能。

概要设计

数据库设计

TaskModel.DB_STRUCTURE = {  _pid: 'string|true',  TASK_ID: 'string|true',
TASK_TYPE: 'int|true|default=0|comment=类型 0=用户创建,1=系统创建', TASK_USER_ID: 'string|false|comment=用户ID',
TASK_STATUS: 'int|true|default=0|comment=状态 0=待派工,1=已派工,2=待处理, 9=已完成', TASK_FORMS: 'array|true|default=[]', TASK_OBJ: 'object|true|default={}',
TASK_MEMBER_ID: 'string|false|comment=工作人员ID', TASK_MEMBER_NAME: 'string|false', TASK_MEMBER_PHONE: 'string|false', TASK_MEMBER_CATE_NAME: 'string|false|comment=工作人员分类', TASK_MEMBER_CATE_ID: 'string|false|comment=工作人员分类ID', TASK_MEMBER_TIME: 'int|true|default=0|comment=工作人员派工时间',

TASK_RUN_FORMS: 'array|true|default=[]', TASK_RUN_OBJ: 'object|true|default={}', TASK_RUN_TIME: 'int|true|default=0',
TASK_OVER_FORMS: 'array|true|default=[]', TASK_OVER_OBJ: 'object|true|default={}', TASK_OVER_TIME: 'int|true|default=0',
TASK_COMMENT_FORMS: 'array|true|default=[]', TASK_COMMENT_OBJ: 'object|true|default={}', TASK_COMMENT_TIME: 'int|true|default=0', TASK_COMMENT_STATUS: 'int|true|default=0',

TASK_MEMBER_ADMIN_ID: 'string|false', TASK_MEMBER_ADMIN_NAME: 'string|false',
TASK_ADD_TIME: 'int|true', TASK_EDIT_TIME: 'int|true', TASK_ADD_IP: 'string|false', TASK_EDIT_IP: 'string|false',};MemberModel.DB_STRUCTURE = { _pid: 'string|true', MEMBER_ID: 'string|true',
MEMBER_TITLE: 'string|true|comment=姓名',
MEMBER_PHONE: 'string|false|comment=登录手机', MEMBER_PASSWORD: 'string|false|comment=登录密码', MEMBER_TOKEN: 'string|false|comment=当前登录token', MEMBER_TOKEN_TIME: 'int|true|default=0|comment=当前登录token time', MEMBER_MINI_OPENID: 'string|false|comment=小程序openid', MEMBER_LOGIN_CNT: 'int|true|default=0|comment=登陆次数', MEMBER_LOGIN_TIME: 'int|false|comment=最近登录时间',

MEMBER_CATE_ID: 'string|true|comment=分类编号', MEMBER_CATE_NAME: 'string|true|comment=分类冗余',
MEMBER_FORMS: 'array|true|default=[]', MEMBER_OBJ: 'object|true|default={}',
MEMBER_STATUS: 'int|true|default=1|comment=状态',

MEMBER_ADD_TIME: 'int|true', MEMBER_EDIT_TIME: 'int|true', MEMBER_ADD_IP: 'string|false', MEMBER_EDIT_IP: 'string|false',};
复制代码

核心实现

class TaskService extends BaseProjectService {
// 取得处理流程 getTaskLogList(task) { let taskLogList = []; if (task.TASK_TYPE == 0) { taskLogList.push( { desc: '用户提交', time: timeUtil.timestamp2Time(task.TASK_ADD_TIME, 'Y-M-D h:m') } ); } else { taskLogList.push( { desc: '后台录入', time: timeUtil.timestamp2Time(task.TASK_ADD_TIME, 'Y-M-D h:m') } ); }
if (task.TASK_STATUS >= TaskModel.STATUS.APPT) { let desc = '已派工给 [' + task.TASK_MEMBER_CATE_NAME + '] ' + task.TASK_MEMBER_NAME + ',正在等待处理'; if (task.TASK_MEMBER_PHONE) desc += ' ,电话' + task.TASK_MEMBER_PHONE + ' '; taskLogList.push( { desc, time: timeUtil.timestamp2Time(task.TASK_MEMBER_TIME, 'Y-M-D h:m') } ); }
if (task.TASK_STATUS >= TaskModel.STATUS.RUN) taskLogList.push( { desc: '[' + task.TASK_MEMBER_CATE_NAME + '] ' + task.TASK_MEMBER_NAME + ' 开始处理', time: timeUtil.timestamp2Time(task.TASK_RUN_TIME, 'Y-M-D h:m'), content: task.TASK_RUN_OBJ.content, img: task.TASK_RUN_OBJ.img, } ); if (task.TASK_STATUS >= TaskModel.STATUS.OVER) taskLogList.push( { desc: '[' + task.TASK_MEMBER_CATE_NAME + '] ' + task.TASK_MEMBER_NAME + ' 已完成', time: timeUtil.timestamp2Time(task.TASK_OVER_TIME, 'Y-M-D h:m'), content: task.TASK_OVER_OBJ.content, img: task.TASK_OVER_OBJ.img, } );
return taskLogList; }
async getTaskCountByType(userId) { let status0Cnt = await TaskModel.count({ TASK_STATUS: 0, TASK_USER_ID: userId }); let status1Cnt = await TaskModel.count({ TASK_STATUS: 1, TASK_USER_ID: userId }); let status2Cnt = await TaskModel.count({ TASK_STATUS: 2, TASK_USER_ID: userId }); let status9Cnt = await TaskModel.count({ TASK_STATUS: 9, TASK_USER_ID: userId }); let task = { status0Cnt, status1Cnt, status2Cnt, status9Cnt } return task; }
async getTaskDetail(userId, id, isAdmin = false) { let where = { _id: id } if (!isAdmin) where.TASK_USER_ID = userId;
let task = await TaskModel.getOne(where);
task.taskLogList = this.getTaskLogList(task);
return task; }
/** 取得我的 */ async getMyTaskList(userId, { search, // 搜索条件 sortType, // 搜索菜单 sortVal, // 搜索菜单 orderBy, // 排序 page, size, isTotal = true, oldTotal }) { orderBy = orderBy || { 'TASK_ADD_TIME': 'desc' }; let fields = '*';
let where = {}; where.and = { _pid: this.getProjectId(), //复杂的查询在此处标注PID TASK_USER_ID: userId };
if (util.isDefined(search) && search) { where.or = [ { ['TASK_OBJ.type']: ['like', search] }, { ['TASK_OBJ.address']: ['like', search] }, { ['TASK_OBJ.person']: ['like', search] } ]; } else if (sortType && sortVal !== '') { // 搜索菜单 switch (sortType) { case 'type': { where.and['TASK_OBJ.type'] = sortVal; break; } case 'status': { where.and.TASK_STATUS = Number(sortVal); break; } case 'sort': { orderBy = this.fmtOrderBySort(sortVal, 'TASK_ADD_TIME'); break; } } } let result = await TaskModel.getList(where, fields, orderBy, page, size, isTotal, oldTotal);
return result; }

async getTaskList({ search, // 搜索条件 sortType, // 搜索菜单 sortVal, // 搜索菜单 orderBy, // 排序 page, size, isTotal = true, oldTotal }) { orderBy = orderBy || { 'TASK_ADD_TIME': 'desc' }; let fields = '*';
let where = {}; where.and = { _pid: this.getProjectId(), //复杂的查询在此处标注PID };
if (util.isDefined(search) && search) { where.or = [ { ['TASK_OBJ.title']: ['like', search] }, { ['TASK_OBJ.building']: ['like', search] }, ]; } else if (sortType && sortVal !== '') { // 搜索菜单 switch (sortType) { case 'type': { where.and['TASK_OBJ.type'] = sortVal; break; } case 'status': { where.and.TASK_STATUS = Number(sortVal); break; } case 'sort': { orderBy = this.fmtOrderBySort(sortVal, 'TASK_ADD_TIME'); break; } } } let result = await TaskModel.getList(where, fields, orderBy, page, size, isTotal, oldTotal);
return result; }
}
复制代码

UI 设计




工作人员平台

后台管理系统



git 代码下载

点击下载

用户头像

CC同学

关注

CC同学的小程序开发笔记 2021-06-13 加入

大鹅厂的小小程序媛,vx: cclinux0730

评论

发布
暂无评论
从0到1:园区巡检与隐患上报小程序开发笔记(上)_CC同学_InfoQ写作社区