123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Models\CorpUserScaleWarningConf;
- use App\Service\WarnService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class WarnController extends Controller
- {
- /**
- * 预警用户组列表
- * @param Request $request
- * @return array
- */
- public function groupList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'keyword' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $keyword = $request->input('keyword');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- $isSelect = $request->input('is_select', 0);
- list($list, $total) = WarnService::groupList($sysGroupId, $keyword, $page, $pageSize, $isSelect);
- if(1 == $isSelect){
- return self::returnValue($list);
- } else {
- return self::returnPageValue($list, $total, $pageSize, $page);
- }
- }
- /**
- * 预警用户组添加
- * @param Request $request
- * @return array
- */
- public function groupAdd(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'group_name' => 'required|string',
- 'user_list' => 'required|string',
- 'djuser_list' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $groupName = $request->input('group_name');
- $userList = $request->input('user_list');
- $djuserList = $request->input('djuser_list');
- list($res, $code) = WarnService::groupOperate($sysGroupId, $groupName, $userList, $djuserList);
- return self::returnValue($res, $code);
- }
- /**
- * 预警用户组数据详情
- * @param Request $request
- * @return array
- */
- public function groupDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'group_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $groupId = $request->input('group_id');
- list($res, $code) = WarnService::groupDetail($sysGroupId, $groupId);
- return self::returnValue($res, $code);
- }
- /**
- * 预警用户组编辑
- * @param Request $request
- * @return array
- */
- public function groupEdit(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'group_name' => 'required|string',
- 'user_list' => 'required|string',
- 'djuser_list' => 'nullable|string',
- 'group_id' => 'required|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $groupName = $request->input('group_name');
- $userList = $request->input('user_list');
- $djuserList = $request->input('djuser_list');
- $groupId = $request->input('group_id');
- list($res, $code) = WarnService::groupOperate($sysGroupId, $groupName, $userList, $djuserList, $groupId);
- return self::returnValue($res, $code);
- }
- /**
- * 预警组开启和禁用
- * @param Request $request
- * @return array
- */
- public function groupEableOp(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'group_id' => 'required|int',
- 'enable' => ['required',Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $groupId = $request->input('group_id');
- $enable = $request->input('enable');
- list($res, $code) = WarnService::groupEableOp($sysGroupId, $groupId, $enable);
- return self::returnValue($res, $code);
- }
- /**
- * 预警规则配置列表
- * @param Request $request
- * @return array
- */
- public function ruleConfList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $res = WarnService::ruleConfList($sysGroupId);
- return self::returnValue($res);
- }
- /**
- * 预警规则配置操作
- * @param Request $request
- * @return array
- */
- public function ruleConfOperate(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'rule_id' => 'required|string',
- 'set_val' => 'nullable|int',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $ruleId = $request->input('rule_id');
- $setVal = $request->input('set_val');
- list($res, $code) = WarnService::ruleConfOperate($sysGroupId, $ruleId, $setVal);
- return self::returnValue($res, $code);
- }
- /**
- * 预警人员列表
- * @param Request $request
- * @return array
- */
- public function userList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'keyword' => 'nullable|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $keyword = $request->input('keyword');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- list($list, $total) = WarnService::userList($sysGroupId, $keyword, $page, $pageSize);
- return self::returnPageValue($list, $total, $pageSize, $page);
- }
- /**
- * 预警人员操作
- * @param Request $request
- * @return array
- */
- public function userOperate(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int',
- 'name' => 'required|string',
- 'phone' => 'required|string',
- 'enable' => ['required',Rule::in([0, 1])],
- 'user_id' => 'nullable|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $name = $request->input('name');
- $phone = $request->input('phone');
- $enable = $request->input('enable');
- $userId = $request->input('user_id');
- list($res, $code) = WarnService::userOperate($sysGroupId, $name, $phone, $enable, $userId);
- return self::returnValue($res, $code);
- }
- /**
- * 预警客服列表
- * @param Request $request
- * @return array
- */
- public function djuserList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'nullable|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $isActive = $request->input('is_active');
- $res = WarnService::djuserList($sysGroupId, $isActive);
- return self::returnValue($res);
- }
- /**
- * 企微用户规模预警 阈值列表(没有用到)
- * @return array
- */
- public function corpUserScaleWarnThresholdList() {
- $list = CorpUserScaleWarningConf::THRESHOLD_LIST;
- return self::returnValue($list);
- }
- /**
- * 企微用户规模预警规则设置(废弃)
- * @param Request $request
- */
- public function setCorpUserScaleWarnConf(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'required|int',
- 'conf_list' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $confList = $request->input('conf_list');
- $isSystemAdmin = $request->input("is_system_admin"); //是否是系统管理员,中间件赋值
- $adminId = $request->input('admin_id');
- list($res, $code) = WarnService::setCorpUserScaleWarnConf($sysGroupId, $adminId, $confList, $isSystemAdmin);
- return self::returnValue($res, $code);
- }
- /**
- * 企微用户规模预警规则展示
- * @param Request $request
- */
- public function getCorpUserScaleWarnConf(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'required|int'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $adminId = $request->input('admin_id');
- $isSystemAdmin = $request->input("is_system_admin"); //是否是系统管理员,中间件赋值
- $data = WarnService::getCorpUserScaleWarnConf($sysGroupId, $adminId, $isSystemAdmin);
- return self::returnValue($data);
- }
- /**
- * 企微用户规模预警规则设置(单条设置)
- * @param Request $request
- */
- public static function setCorpUserScaleWarnConfNew(Request $request) {
- $validator = \Validator::make($request->all(),[
- 'sys_group_id' => 'required|int',
- 'threshold' => 'required|in:4700,4800,9700,9800,14700,14800,19700,19800',
- 'corp_list' => 'nullable|array',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 3001);
- }
- $sysGroupId = $request->input('sys_group_id');
- $threshold = $request->input('threshold');
- $corpList = $request->input('corp_list');
- $isSystemAdmin = $request->input("is_system_admin"); //是否是系统管理员,中间件赋值
- $adminId = $request->input('admin_id');
- list($res, $code) = WarnService::setCorpUserScaleWarnConfNew($sysGroupId, $adminId, $isSystemAdmin, $threshold, $corpList);
- return self::returnValue($res, $code);
- }
- }
|