hydEquipmentModel = $hydEquipmentModel; } /** * 列表 * @time 2022年06月21日 11:02 * @param Request $request */ public function index(Request $request): \think\Response { return CatchResponse::paginate($this->hydEquipmentModel->getList()); } /** * 保存信息 * @time 2022年06月21日 11:02 * @param Request $request */ public function save(Request $request): \think\Response { $data = $request->post(); $hydraulic = null; $wrench = null; $hydequ = [ // 物料号 'material_number' => $data['material_number'], // 设备类别 'equipment_type' => $data['equipment_type'], // 工具名称 'name' => $data['name'], // 设备型号 'equipment_model' => $data['equipment_model'], // 发放单位 'issue_unit' => $data['issue_unit'], // 固定资产编号 'fixed_asset_number' => $data['fixed_asset_number'], // 类固定资产编号 'fixed_asset_number2' => $data['fixed_asset_number2'], // 序列号 'serial_number' => $data['serial_number'], // 出厂编号 'factory_number' => $data['factory_number'], // 上次校验时间 'check_last_time' => $data['check_last_time'], // 下次校验时间 'check_next_time' => $data['check_next_time'], // 校验状态 'check_status' => $data['check_status'], // 状态 'status' => $data['status'], 'address' => $data['address'], 'longitude' => $data['longitude'], 'latitude' => $data['latitude'] ]; Db::startTrans(); try { $id = $this->hydEquipmentModel->storeBy($hydequ); if ($data['equipment_type'] == 2) { $hydraulic = [ // 编号 'number' => $data['number'], // 所属部门 'department_id' => $data['department_id'], 'remark' => $data['remark'] ? $data['remark'] : '', 'max_pressure' => $data['max_pressure'], 'min_pressure' => $data['min_pressure'], 'imei' => $data['imei'], 'effective_period' => $data['effective_period'], //设备的id 'eq_id' => $id ]; $hyd_exist = Hydraulic::where('imei', $data['imei'])->find(); if ($hyd_exist) { Db::rollback(); return CatchResponse::fail('imei号已存在'); } Hydraulic::create($hydraulic); } //保存扳手 if ($data['equipment_type'] == 3 || $data['equipment_type'] == 4) { $wrench = [ // 编号 'number' => $data['number'], //设备id 'eq_id' => $id, // 所属部门 'department_id' => $data['department_id'], 'remark' => $data['remark'] ? $data['remark'] : '', 'min_pressure' => $data['min_pressure'], 'max_pressure' => $data['max_pressure'], 'min_torque' => $data['min_torque'], 'max_torque' => $data['max_torque'], 'angle_sensor' => $data['angle_sensor'], 'angular_resolution' => $data['angular_resolution'] ]; $wrench_exist = Wrench::where('number', $data['number'])->find(); if ($wrench_exist) { Db::rollback(); return CatchResponse::fail('扳手编号已存在'); } Wrench::create($wrench); } } catch (\Exception $e) { Db::rollback(); return CatchResponse::fail($e->getMessage()); } Db::commit(); return CatchResponse::success(); } /** * 读取 * @time 2022年06月21日 11:02 * @param $id */ public function read($id): \think\Response { return CatchResponse::success($this->hydEquipmentModel->findBy($id)); } /** * 更新 * @time 2022年06月21日 11:02 * @param Request $request * @param $id */ public function update(Request $request, $id): \think\Response { $data = $request->post(); $hydraulic = null; $wrench = null; $hydequ = [ // 物料号 'material_number' => $data['material_number'], // 设备类别 'equipment_type' => $data['equipment_type'], // 工具名称 'name' => $data['name'], // 设备型号 'equipment_model' => $data['equipment_model'], // 发放单位 'issue_unit' => $data['issue_unit'], // 固定资产编号 'fixed_asset_number' => $data['fixed_asset_number'], // 类固定资产编号 'fixed_asset_number2' => $data['fixed_asset_number2'], // 序列号 'serial_number' => $data['serial_number'], // 出厂编号 'factory_number' => $data['factory_number'], // 上次校验时间 'check_last_time' => $data['check_last_time'] ? strstr($data['check_last_time'], '-') ? strtotime($data['check_last_time']) : $data['check_last_time'] : '', // 下次校验时间 'check_next_time' => $data['check_next_time'] ? strstr($data['check_next_time'], '-') ? strtotime($data['check_next_time']) : $data['check_next_time'] : '', // 校验状态 'check_status' => $data['check_status'], // 状态 'status' => $data['status'], 'address' => $data['address'], 'longitude' => $data['longitude'], 'latitude' => $data['latitude'] ]; if ($data['equipment_type'] == 2) { $hydraulic = [ // 编号 'number' => $data['number'], // 所属部门 'department_id' => $data['department_id'], //备注 'remark' => $data['remark'], 'max_pressure' => $data['max_pressure'], 'min_pressure' => $data['min_pressure'], 'imei' => $data['imei'], 'effective_period' => $data['effective_period'], //设备的id 'eq_id' => $id ]; $hyd_exist = Hydraulic::where('imei', $data['imei'])->where('eq_id', '<>', $id)->find(); if ($hyd_exist) { Db::rollback(); return CatchResponse::fail('imei号已存在'); } $bool = Hydraulic::where('eq_id', $id)->find(); if ($bool) { Hydraulic::where('eq_id', $id)->update($hydraulic); } else { Hydraulic::create($hydraulic); } } //保存扳手 if ($data['equipment_type'] == 3 || $data['equipment_type'] == 4) { $wrench = [ // 编号 'number' => $data['number'], //设备id 'eq_id' => $id, // 所属部门 'department_id' => $data['department_id'], 'remark' => $data['remark'], 'min_pressure' => $data['min_pressure'], 'max_pressure' => $data['max_pressure'], 'min_torque' => $data['min_torque'], 'max_torque' => $data['max_torque'], 'angular_resolution' => $data['angular_resolution'], 'angle_sensor' => $data['angle_sensor'], // 扭矩 ]; $wrench_exist = Wrench::where('number', $data['number'])->where('id', '<>', $data['list']['id'])->find(); if ($wrench_exist) { Db::rollback(); return CatchResponse::fail('扳手编号已存在'); } $bool = Wrench::where('eq_id', $id)->find(); if ($bool) { Wrench::update($wrench, ['eq_id' => $id]); } else { Wrench::create($wrench); } } return CatchResponse::success($this->hydEquipmentModel->updateBy($id, $hydequ)); } /** * 删除 * @time 2022年06月21日 11:02 * @param $id */ public function delete($id): \think\Response { $data = array(); $where = []; if (is_array($id)) { $where[] = ['id', 'in', $id]; $data = $this->hydEquipmentModel->where($where)->select()->toArray(); } else { $list = $this->hydEquipmentModel->where('id', $id)->find(); $data[] = $list; } Db::startTrans(); try { foreach ($data as $item) { if ($item['equipment_type'] == 2) { Hydraulic::where('eq_id', '=', $item['id'])->delete(); } if ($item['equipment_type'] == 3 || $item['equipment_type'] == 4) { $wrench = Wrench::where('eq_id', '=', $item['id'])->find(); $wrench->delete(); } } $this->hydEquipmentModel->deleteBy($id, true); } catch (\Exception $e) { Db::rollback(); return CatchResponse::fail($e->getMessage()); } Db::commit(); return CatchResponse::success(); } /** * @Descripttion: 获取设备状态和校验状态 * @name: likang * @return {*} */ public function getHydEquipmentType(Request $request) { $data = $request->get(); $code = $data['code']; $sysDict = new SysDictData(); $list = $sysDict->getTypesByCodeWithRemark($code, ''); return CatchResponse::success($list); } /** * 根据设备类别统计每个设备的总数 */ public function getTotalByEquipmentType($id) { $list = EquipmentType::where('pid', $id)->order('order desc')->field('id,name')->limit(4)->select(); foreach ($list as $key => $value) { $list[$key]['total'] = $this->hydEquipmentModel->where('equipment_type', $value['id'])->count(); } return CatchResponse::success($list); } /** * @Descripttion: 获取不同类型的设备 * @name: likang * @return {*} */ public function getAllHydEqu(Request $request) { $data = $request->get(); $type = $data['type']; $list = $this->hydEquipmentModel->where('equipment_type', $type)->field('id as value,name as text')->select(); return CatchResponse::success($list); } public function importExcel(Request $request) { $map = [ ['key' => 'A', 'value' => 'material_number'], ['key' => 'C', 'value' => 'equipment_type'], ['key' => 'D', 'value' => 'name'], ['key' => 'E', 'value' => 'equipment_model'], ['key' => 'F', 'value' => 'issue_unit'], ['key' => 'G', 'value' => 'fixed_asset_number'], ['key' => 'H', 'value' => 'fixed_asset_number2'], ['key' => 'I', 'value' => 'serial_number'], ['key' => 'J', 'value' => 'factory_number'], ['key' => 'K', 'value' => 'check_last_time'], ['key' => 'L', 'value' => 'check_next_time'], ['key' => 'M', 'value' => 'check_status'], ['key' => 'N', 'value' => 'status'], ]; //过滤 $func = function ($data) { $data['equipment_type'] = EquipmentType::where('pid', '<>', 0)->where('name', $data['equipment_type'])->value('id'); if ($data['check_status'] == '已校验') { $data['check_status'] = 2; } else if ($data['check_status'] == '待校验') { $data['check_status'] = 1; } else if ($data['check_status'] == '已报废') { $data['check_status'] = -1; } else { $data['check_status'] = 1; } if ($data['status'] = '使用中') { $data['status'] = 4; } else if ($data['status'] == '待维修') { $data['status'] = -1; } else if ($data['status'] == '在途') { $data['status'] = 1; } else if ($data['status'] == '待校验') { $data['status'] = 2; } else if ($data['status'] == '备用') { $data['status'] = 3; } return $data; }; return importExcel($request, $map, $this->hydEquipmentModel, $func); } /** * @Descripttion: 查看上传的日志 * @name: likang * @return {*} */ public function SelectLogByImei(Request $request) { //获取设备的imei号 $imei = $request->get('imei'); $pub_ack = new PublishAck(); $list = Db::name('publish_ack')->where('Imei', $imei)->field('id,PublishVersion,AddTime,Succ,AckTime,Imei')->order('PublishVersion', 'desc')->select()->toArray(); foreach ($list as $key => $item) { //时间 $list[$key]['AddTime'] = date('Y-m-d H:i:s', substr($item['AddTime'], 0, 10)); $list[$key]['AckTime'] = date('Y-m-d H:i:s', substr($item['AckTime'], 0, 10)); } return CatchResponse::success($list); } /** * @Descripttion: 获取日志详情 * @name: likang * @param {Request} $request * @return {*} */ public function getLogDetail(Request $request) { $type = $request->get('type'); $id = $request->get('id'); $data = null; if ($type == 1) { $data = Db::name('publish_ack')->where('id', $id)->value('PublishContent'); $data = optimize_json($data); $data = json_decode($data, true); if (json_last_error() != 0) { return CatchResponse::fail(json_last_error_msg()); } } else { $data = Db::name('publish_ack')->where('id', $id)->value('Extra'); $data = optimize_json($data); } return CatchResponse::success($data); } }