Merge pull request 'SafetyHazard' (#48) from zhangwei into dev

Reviewed-on: #48
This commit is contained in:
weiz 2023-12-19 17:37:13 +08:00
commit 78bbdc1e7e
5 changed files with 530 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\safety;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\safety\SafetyHazardLists;
use app\adminapi\logic\safety\SafetyHazardLogic;
use app\adminapi\validate\safety\SafetyHazardValidate;
/**
* 危险源管理控制器
* Class SafetyHazardController
* @package app\adminapi\controller\safety
*/
class SafetyHazardController extends BaseAdminController
{
/**
* @notes 获取危险源管理列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function lists()
{
return $this->dataLists(new SafetyHazardLists());
}
/**
* @notes 添加危险源管理
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function add()
{
$params = (new SafetyHazardValidate())->post()->goCheck('add');
$result = SafetyHazardLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(SafetyHazardLogic::getError());
}
/**
* @notes 编辑危险源管理
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function edit()
{
$params = (new SafetyHazardValidate())->post()->goCheck('edit');
$result = SafetyHazardLogic::edit($params,$this->adminId);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(SafetyHazardLogic::getError());
}
/**
* @notes 删除危险源管理
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function delete()
{
$params = (new SafetyHazardValidate())->post()->goCheck('delete');
SafetyHazardLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取危险源管理详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function detail()
{
$params = (new SafetyHazardValidate())->goCheck('detail');
$result = SafetyHazardLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\safety;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\model\safety\SafetyHazard;
use app\common\lists\ListsSearchInterface;
/**
* 危险源管理列表
* Class SafetyHazardLists
* @package app\adminapi\listssafety
*/
class SafetyHazardLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function setSearch(): array
{
return [
'%like%' => ['fill_company', 'construction_company_user', 'supervision_company_user', 'build_company_user'],
];
}
/**
* @notes 获取危险源管理列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function lists(): array
{
return SafetyHazard::where($this->searchWhere)
->field(['id', 'org_id', 'dept_id', 'project_id', 'fill_company', 'construction_company_user', 'supervision_company_user', 'build_company_user', 'source', 'accident', 'risk_level', 'control_level', 'department', 'users', 'technical_measure', 'manage_measure', 'emergency_measure', 'remark', 'file'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
$org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty();
$dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty();
$item['org_name'] = $org['name'];
$item['dept_name'] = $dept['name'];
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
return $item;
})
->toArray();
}
/**
* @notes 获取危险源管理数量
* @return int
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function count(): int
{
return SafetyHazard::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,158 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\safety;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\model\safety\SafetyHazard;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 危险源管理逻辑
* Class SafetyHazardLogic
* @package app\adminapi\logic\safety
*/
class SafetyHazardLogic extends BaseLogic
{
/**
* @notes 添加危险源管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/19 17:22
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
SafetyHazard::create([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'fill_company' => $params['fill_company'],
'construction_company_user' => $params['construction_company_user'],
'supervision_company_user' => $params['supervision_company_user'],
'build_company_user' => $params['build_company_user'],
'source' => $params['source'],
'accident' => $params['accident'],
'risk_level' => $params['risk_level'],
'control_level' => $params['control_level'],
'department' => $params['department'],
'users' => $params['users'],
'technical_measure' => $params['technical_measure'],
'manage_measure' => $params['manage_measure'],
'emergency_measure' => $params['emergency_measure'],
'remark' => $params['remark'],
'file' => !empty($params['file']) ? $params['file'] : null,
'add_user' => $admin_id,
'update_user' => $admin_id,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑危险源管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/19 17:22
*/
public static function edit(array $params,$admin_id): bool
{
Db::startTrans();
try {
SafetyHazard::where('id', $params['id'])->update([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'fill_company' => $params['fill_company'],
'construction_company_user' => $params['construction_company_user'],
'supervision_company_user' => $params['supervision_company_user'],
'build_company_user' => $params['build_company_user'],
'source' => $params['source'],
'accident' => $params['accident'],
'risk_level' => $params['risk_level'],
'control_level' => $params['control_level'],
'department' => $params['department'],
'users' => $params['users'],
'technical_measure' => $params['technical_measure'],
'manage_measure' => $params['manage_measure'],
'emergency_measure' => $params['emergency_measure'],
'remark' => $params['remark'],
'file' => !empty($params['file']) ? $params['file'] : null,
'update_user' => $admin_id,
'update_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除危险源管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/19 17:22
*/
public static function delete(array $params): bool
{
return SafetyHazard::destroy($params['id']);
}
/**
* @notes 获取危险源管理详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/19 17:22
*/
public static function detail($params): array
{
$data = SafetyHazard::findOrEmpty($params['id'])->toArray();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
$admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id');
$data['org_name'] = $org['name'];
$data['dept_name'] = $dept['name'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['add_user_name'] = $admin[$data['add_user']];
$data['update_user_name'] = $admin[$data['update_user']];
return $data;
}
}

View File

@ -0,0 +1,138 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\safety;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\validate\BaseValidate;
/**
* 危险源管理验证器
* Class SafetyHazardValidate
* @package app\adminapi\validate\safety
*/
class SafetyHazardValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'file' => 'checkFile'
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
];
/**
* @notes 添加场景
* @return SafetyHazardValidate
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SafetyHazardValidate
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SafetyHazardValidate
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SafetyHazardValidate
* @author likeadmin
* @date 2023/12/19 17:22
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkOrg($value): bool|string
{
$data = Orgs::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '组织不存在';
}
return true;
}
public function checkDept($value,$rule,$data): bool|string
{
$dept = Dept::where('id',$value)->findOrEmpty();
if($dept->isEmpty()){
return '部门不存在';
}
if($dept['org_id'] != $data['org_id']){
return '部门不属于当前选择的组织';
}
return true;
}
public function checkProject($value): bool|string
{
$data = Project::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkFile($value): bool|string
{
if($value != ''){
$file = json_decode($value,true);
if(empty($file)){
return '附件必须是json数组';
}
}
return true;
}
}

View File

@ -0,0 +1,37 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\safety;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 危险源管理模型
* Class SafetyHazard
* @package app\common\model\safety
*/
class SafetyHazard extends BaseModel
{
use SoftDelete;
protected $name = 'safety_hazard';
protected $deleteTime = 'delete_time';
public function getFileAttr($value)
{
return json_decode($value,true);
}
}