Check.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\CheckDict;
  5. use app\service\CheckClassService;
  6. use app\service\CheckDetailService;
  7. use app\service\CheckService;
  8. use app\service\ZdXzqService;
  9. use app\service\EnterprisesService;
  10. use app\validate\Id;
  11. use app\validate\Page;
  12. use think\annotation\Route;
  13. use think\annotation\route\Middleware;
  14. use hg\apidoc\annotation as Apidoc;
  15. use think\exception\ValidateException;
  16. use think\response\Json;
  17. /**
  18. * @Apidoc\Title("现场检查列表")
  19. * @Apidoc\Group("巡检")
  20. * @Apidoc\Sort (9)
  21. */
  22. class Check extends BaseController
  23. {
  24. protected $middleware = [
  25. 'jwt',
  26. ];
  27. /**
  28. * @Apidoc\Title("获取现场检查列表")
  29. * @Apidoc\Tag("巡检")
  30. * @Apidoc\Method ("GET")
  31. * @Apidoc\Author ("ihavoc")
  32. * @Route("getCheckList",method="GET")
  33. * @Middleware({"jwt"})
  34. */
  35. public function getCheckList(): Json
  36. {
  37. $page = $this->request->get();
  38. try {
  39. validate(Page::class)->check($page);
  40. }catch (ValidateException $e){
  41. return $this->JsonError($e->getError());
  42. }
  43. return $this->JsonSucess(CheckService::getCheckList($page,getXzqdmSub()));
  44. }
  45. /**
  46. * @Apidoc\Title("获取待检检查列表")
  47. * @Apidoc\Tag("巡检")
  48. * @Apidoc\Method ("GET")
  49. * @Apidoc\Author ("ihavoc")
  50. * @Route("getWaitCheckList",method="GET")
  51. * @Middleware({"jwt"})
  52. */
  53. public function getWaitCheckList(): Json
  54. {
  55. $page = $this->request->get();
  56. try {
  57. validate(Page::class)->check($page);
  58. }catch (ValidateException $e){
  59. return $this->JsonError($e->getError());
  60. }
  61. $res = EnterprisesService::getEnterPrisesList($page, getXzqdmSub());
  62. foreach ($res["row"] as $key => $value){
  63. $res["row"][$key]["townsc"]=ZdXzqService::getXzqDetail($value["towns"]);
  64. $res["row"][$key]["countryc"] = ZdXzqService::getXzqDetail(str_pad(substr($value["towns"],0,6),9,'0'));
  65. $res["row"][$key]["cityc"] = ZdXzqService::getXzqDetail(str_pad(substr($value["towns"],0,4),9,'0'));
  66. }
  67. return $this->JsonSucess($res);
  68. }
  69. /**
  70. * @Apidoc\Title("获取现场检查项目16项总表列表")
  71. * @Apidoc\Tag("巡检")
  72. * @Apidoc\Method ("GET")
  73. * @Apidoc\Author ("郑雪瑞")
  74. * @Route("getCheckDict",method="GET")
  75. * @Middleware({"jwt"})
  76. */
  77. public function getCheckDict():Json
  78. {
  79. return $this->JsonSucess(CheckClassService::getCheckDict());
  80. }
  81. /**
  82. * @Apidoc\Title("获取现场检查项目详情列表根据check_class_id")
  83. * @Apidoc\Tag("巡检")
  84. * @Apidoc\Method ("GET")
  85. * @Apidoc\Author ("郑雪瑞")
  86. * @Route("getCheckDetailDict",method="GET")
  87. * @Middleware({"jwt"})
  88. */
  89. public function getCheckDetailDict():Json
  90. {
  91. $id = $this->request->get();
  92. try {
  93. validate(Id::class)->check($id);
  94. }catch (ValidateException $e){
  95. }
  96. return $this->JsonSucess(CheckClassService::getCheckDetailByCheckId($id["id"]));
  97. }
  98. /**
  99. * @Apidoc\Title("添加检查信息")
  100. * @Apidoc\Tag("巡检")
  101. * @Apidoc\Method ("POST")
  102. * @Apidoc\Author ("ihavoc")
  103. * @Route("addCheckInfo",method="POST")
  104. * @Middleware({"jwt"})
  105. */
  106. public function addCheckInfo(): Json
  107. {
  108. $data=$this->request->post();
  109. $data["is_pass"]=0;
  110. $data["nopass"]=0;
  111. for ($i=0;$i<count($data["detail"]);$i++){
  112. if ($data["detail"][$i]["check_res"]=="1" || $data["detail"][$i]["check_res"]=="2"){
  113. $data["is_pass"]++;
  114. }else{
  115. $data["nopass"]++;
  116. }
  117. }
  118. $id=CheckService::addCheck($data);
  119. for ($j=0;$j<count($data["detail"]);$j++){
  120. $data["detail"][$i]["check_id"]=$id;
  121. CheckDetailService::addCheckDetail($data["detail"][$i]);
  122. }
  123. return $this->JsonSucess();
  124. }
  125. }