从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代码下载

点击下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值