SafetyModify

This commit is contained in:
weiz 2023-12-19 16:54:01 +08:00
parent 01611309cd
commit 247d909cda
5 changed files with 527 additions and 0 deletions
app
adminapi
common/model/safety

@ -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\SafetyModifyLists;
use app\adminapi\logic\safety\SafetyModifyLogic;
use app\adminapi\validate\safety\SafetyModifyValidate;
/**
* 安全整改控制器
* Class SafetyModifyController
* @package app\adminapi\controller\safety
*/
class SafetyModifyController extends BaseAdminController
{
/**
* @notes 获取安全整改列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function lists()
{
return $this->dataLists(new SafetyModifyLists());
}
/**
* @notes 添加安全整改
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function add()
{
$params = (new SafetyModifyValidate())->post()->goCheck('add');
$result = SafetyModifyLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(SafetyModifyLogic::getError());
}
/**
* @notes 编辑安全整改
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function edit()
{
$params = (new SafetyModifyValidate())->post()->goCheck('edit');
$result = SafetyModifyLogic::edit($params,$this->adminId);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(SafetyModifyLogic::getError());
}
/**
* @notes 删除安全整改
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function delete()
{
$params = (new SafetyModifyValidate())->post()->goCheck('delete');
SafetyModifyLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取安全整改详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function detail()
{
$params = (new SafetyModifyValidate())->goCheck('detail');
$result = SafetyModifyLogic::detail($params);
return $this->data($result);
}
}

@ -0,0 +1,91 @@
<?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\SafetyModify;
use app\common\lists\ListsSearchInterface;
/**
* 安全整改列表
* Class SafetyModifyLists
* @package app\adminapi\listssafety
*/
class SafetyModifyLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function setSearch(): array
{
return [
'=' => ['check_date', 'modify_term'],
'%like%' => ['check_nature', 'check_user', 'check_company', 'modify_company', 'modify_user', 'resp_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 16:40
*/
public function lists(): array
{
return SafetyModify::where($this->searchWhere)
->field(['id', 'org_id', 'dept_id', 'project_id', 'check_nature', 'check_date', 'check_user', 'check_company', 'check_item', 'check_result', 'modify_term', 'modify_company', 'modify_user', 'safety_hazard', 'resp_user'])
->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 16:40
*/
public function count(): int
{
return SafetyModify::where($this->searchWhere)->count();
}
}

@ -0,0 +1,149 @@
<?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\SafetyModify;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 安全整改逻辑
* Class SafetyModifyLogic
* @package app\adminapi\logic\safety
*/
class SafetyModifyLogic extends BaseLogic
{
/**
* @notes 添加安全整改
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/19 16:40
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
SafetyModify::create([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'check_nature' => $params['check_nature'],
'check_date' => strtotime($params['check_date']),
'check_user' => $params['check_user'],
'check_company' => $params['check_company'],
'check_item' => $params['check_item'],
'check_result' => $params['check_result'],
'modify_term' => $params['modify_term'],
'modify_company' => $params['modify_company'],
'modify_user' => $params['modify_user'],
'safety_hazard' => $params['safety_hazard'],
'resp_user' => $params['resp_user'],
'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 16:40
*/
public static function edit(array $params,$admin_id): bool
{
Db::startTrans();
try {
SafetyModify::where('id', $params['id'])->update([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'check_nature' => $params['check_nature'],
'check_date' => strtotime($params['check_date']),
'check_user' => $params['check_user'],
'check_company' => $params['check_company'],
'check_item' => $params['check_item'],
'check_result' => $params['check_result'],
'modify_term' => $params['modify_term'],
'modify_company' => $params['modify_company'],
'modify_user' => $params['modify_user'],
'safety_hazard' => $params['safety_hazard'],
'resp_user' => $params['resp_user'],
'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 16:40
*/
public static function delete(array $params): bool
{
return SafetyModify::destroy($params['id']);
}
/**
* @notes 获取安全整改详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/19 16:40
*/
public static function detail($params): array
{
$data = SafetyModify::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;
}
}

@ -0,0 +1,142 @@
<?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 SafetyModifyValidate
* @package app\adminapi\validate\safety
*/
class SafetyModifyValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'check_date' => 'date',
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
'check_date.date' => '检查日期格式错误',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'org_id' => '组织id',
'dept_id' => '部门id',
'project_id' => '项目id',
'add_user' => '添加人',
'update_user' => '更新人',
];
/**
* @notes 添加场景
* @return SafetyModifyValidate
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SafetyModifyValidate
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SafetyModifyValidate
* @author likeadmin
* @date 2023/12/19 16:40
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SafetyModifyValidate
* @author likeadmin
* @date 2023/12/19 16:40
*/
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;
}
}

@ -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 SafetyModify
* @package app\common\model\safety
*/
class SafetyModify extends BaseModel
{
use SoftDelete;
protected $name = 'safety_modify';
protected $deleteTime = 'delete_time';
public function getCheckDateAttr($value): string
{
return date('Y-m-d',$value);
}
}