SuperviserTaskBus.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. *
  4. *User:Administrator
  5. *Date:2021/10/9
  6. */
  7. namespace app\api\business;
  8. use app\api\exception\ApiException;
  9. use app\api\model\Ccjc;
  10. use app\api\model\Jcdw;
  11. use app\api\model\Orgs;
  12. use app\common\lib\Arr;
  13. use app\common\lib\auth\JwtAuth;
  14. class SuperviserTaskBus
  15. {
  16. private $rymc;
  17. public function __construct()
  18. {
  19. $jwtAuth=JwtAuth::getInstance(); //实例化jwtAuth
  20. $this->rymc = $jwtAuth->getRymc(); //setRybh是在middleware/jwtAuth中完成的
  21. }
  22. //查询任务列表数据
  23. public function selectTask($data)
  24. {
  25. //如果需要查询的字段不为空就push一个查询条件
  26. $where=[];//初始化$where
  27. //任务年度
  28. if ($data['year']!='') array_push($where, ['year', '=', $data['year']]);
  29. //任务状态:0:未发布,1:执行中,2:已结束未完成,3:已结束已完成
  30. if ($data['ispublic'] != '') array_push($where, ['ispublic', '=', $data['ispublic']]);
  31. //任务开始时间
  32. if ($data['starttime'] != '') array_push($where, ['starttime', '>=', $data['starttime']]);
  33. //任务结束时间
  34. if ($data['endtime'] != '') array_push($where, ['endtime', '<=', $data['endtime']]);
  35. //任务分类:例行or专项
  36. if ($data['task_class'] != '') array_push($where, ['task_class', '=', $data['task_class']]);
  37. //任务名称:模糊查询
  38. if ($data['task_name'] != '' ) array_push($where, ['task_name', 'LIKE', '%'.$data['task_name'].'%']);
  39. $result = (new Ccjc())->getInfoByTaskClass($where,(int)$data['pageNum'],(int)$data['pageSize'])->toArray();
  40. $count = (new Ccjc())->getInfoListCount($where);
  41. return ['rows'=>$result, 'total'=>$count,];
  42. }
  43. //创建任务
  44. public function createTask($data,$orgs_data)
  45. {
  46. $data['releaser'] = $this->rymc;
  47. //创建任务
  48. $task_id = (new Ccjc())->createTask($data);
  49. for($i=0;$i<count($orgs_data);$i++){
  50. $orgs[$i]['task_id']=$task_id;
  51. $orgs[$i]['unit_id']=$orgs_data[$i]['id'];
  52. $orgs[$i]['unit_name']=$orgs_data[$i]['name'];
  53. }
  54. $result = (new Orgs())->createOrgsInfo($orgs);
  55. return $result;
  56. }
  57. //删除任务
  58. public function deleteTask($arr_del_task)
  59. {
  60. //根据ID检索创建者
  61. $releaser = (new Ccjc())->getReleaserById($arr_del_task);
  62. if (empty($releaser)) {
  63. throw new ApiException(config('status.none_data'));
  64. }
  65. //将创建者releaser和token中的rymc匹配,不相等则throw无权限操作
  66. foreach ($releaser as $k => $v) {
  67. if (strcmp($this->rymc, $v) != 0) {
  68. throw new ApiException(config('status.none_authority'));
  69. }
  70. }
  71. //进行删除操作
  72. $result = (new Ccjc())->deleteTaskByID($arr_del_task);
  73. return $result;
  74. }
  75. public function updateTask($data)
  76. {
  77. //过滤字段,保留id,ispublic,releaser
  78. $arr = (new Arr())->Arr_columns($data, 'id,ispublic,releaser');
  79. //校验 任务状态 && 操作权限
  80. foreach ($arr as $k=>$value) {
  81. if ($value['ispublic'] != 1) {
  82. throw new ApiException(config('status.err_public_status'));
  83. }
  84. if (strcmp($value['releaser'], $this->rymc) != 0) {
  85. throw new ApiException(config('status.none_authority'));
  86. }
  87. }
  88. $result = (new Ccjc())->updateTaskByArrCondition($arr);
  89. return $result;
  90. }
  91. }