SuperviserTaskBus.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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['creater'] = $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 deleteTaskItem($data,$data_count)
  59. {
  60. for ($i = 0; $i < $data_count; $i++) {
  61. //从数据库中查询选取的数据
  62. $task_info[$i] = (new Ccjc())->getTaskInfoByTaskID($data[$i]['id']);
  63. }
  64. //将数据库中的数据和选取的数据进行校验
  65. for ($i = 0; $i < $data_count; $i++) {
  66. //如果查询结果存在null值,则未选取有效数据
  67. if ($task_info[$i] == null) {
  68. throw new ApiException(config('status.none_data'));
  69. }
  70. //判断操作者是否具有操作权限(是否为创建者)
  71. if ($task_info[$i]['creater'] != $this->rymc) {
  72. throw new ApiException(config('status.none_authority'));
  73. }
  74. }
  75. //进行删除操作
  76. for ($i = 0; $i < $data_count; $i++) {
  77. $result[$i] = (new Ccjc())->deleteItemById($data[$i]['id']);//删除的结果为布尔值
  78. }
  79. //检查删除结果是否都为真
  80. for ($i = 0; $i < $data_count; $i++) {
  81. if ($result[$i] != 1) {
  82. throw new ApiException(config('status.data_abnormal'));
  83. }
  84. }
  85. return '成功删除'."$data_count".'条数据';
  86. }
  87. //修改任务发布状态(发布/废止)
  88. public function updateTaskUpdateInfo($data,$data_count)
  89. {
  90. //从数据库中获取任务信息
  91. for ($i = 0; $i < $data_count; $i++) {
  92. $task[$i]=(new Ccjc())->getTaskInfoByTaskID($data[$i]['id'])->toArray();
  93. }
  94. //是否发布,0:未发布,1:已发布,2:废止;3:已结束未完成;4:已结束已完成;5:执行中
  95. for ($i = 0; $i < $data_count; $i++) {
  96. //只有未发布的,状态可以变成发布(0->1)
  97. if ($data[$i]['ispublic']==1 && $task[$i]['ispublic'] != 0) {
  98. throw new ApiException(config('status.err_enPublic_status'));//当前任务不可发布
  99. }
  100. //只已发布的,状态可以变成废止(1->2)
  101. if ($data[$i]['ispublic'] == 2 && $task[$i]['ispublic'] != 1) {
  102. throw new ApiException(config('status.err_disPublic_status'));//当前任务不可废止
  103. }
  104. //只有创建者creater是当前操作员才可以发布
  105. if ($task[$i]['creater'] != $this->rymc) {
  106. throw new ApiException(config('status.none_authority'));//无权操作此项数据
  107. }
  108. }
  109. //将releaser赋值为当前操作者的人员名称
  110. for ($i = 0; $i < $data_count; $i++) {
  111. $data[$i]['releaser'] = $this->rymc;
  112. }
  113. //写入数据库
  114. $result = (new Ccjc())->updateTaskByArrCondition($data);
  115. return $result;
  116. }
  117. }