TemplateController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. namespace app\api\controller\template;
  3. use app\api\controller\Template;
  4. use app\api\controller\ZskkDefaultController;
  5. use app\api\validate\template\TemplateValidate;
  6. use app\api\servies\template\TemplateService;
  7. use think\Db;
  8. use think\Exception;
  9. class TemplateController extends ZskkDefaultController
  10. {
  11. protected $needToken = true;
  12. protected $logName = "TemplateController";
  13. /**
  14. * 获取公有、私有模板
  15. */
  16. public function getAllTemplate(TemplateService $service)
  17. {
  18. try{
  19. // 参数
  20. $params = $this->getParams();
  21. TemplateValidate::check($params);
  22. // exam_class
  23. $examClass = $service->getExamClass($params['examId']);
  24. // 获取公有、私有模板
  25. $public = $service->getPublicTemplate($examClass);
  26. $user = $service->getUser($this->getToken());
  27. $private = $service->getPrivateTemplate($examClass,$user['id']);
  28. // 返回
  29. $data = [
  30. 'public' => $public,
  31. 'private' => $private
  32. ];
  33. return $this->success($data);
  34. } catch (Exception $exception){
  35. $this->throwError($exception->getMessage(),0001);
  36. }
  37. }
  38. /**
  39. * 获取公有模板(父级)
  40. */
  41. public function getPublic(TemplateService $service)
  42. {
  43. try{
  44. // 参数
  45. $params = $this->getParams();
  46. // TemplateValidate::checkPublic($params);
  47. // exam_class
  48. $exam_class = $params['exam_class'];
  49. // 判断是否存储catch
  50. $key = $service->getPublicTemplateKey($exam_class);
  51. $public = $service->getPublicInfo($key,$exam_class);
  52. //返回
  53. return $this->success($public);
  54. } catch (Exception $exception){
  55. $this->throwError($exception->getMessage(),0001);
  56. }
  57. }
  58. public function getPrivate(TemplateService $service)
  59. {
  60. try{
  61. // 参数
  62. $params = $this->getParams();
  63. // TemplateValidate::checkPublic($params);
  64. // exam_class
  65. $exam_class = $params['exam_class'];
  66. // 获取公有
  67. $token = $this->getToken();
  68. $user = $service->getUser($token);
  69. $private = $service->getPrivate($exam_class,$user['id']);
  70. //返回
  71. return $this->success($private);
  72. } catch (Exception $exception){
  73. $this->throwError($exception->getMessage(),0001);
  74. }
  75. }
  76. public function getChild(TemplateService $service)
  77. {
  78. try{
  79. // 参数
  80. $params = $this->getParams();
  81. TemplateValidate::checkId($params);
  82. // 获取子级数据
  83. $child = $service->getChildData($params['id']);
  84. // 返回
  85. return $this->success($child);
  86. } catch (Exception $exception){
  87. $this->throwError($exception->getMessage(),0001);
  88. }
  89. }
  90. public function saveParentTemplate(TemplateService $service)
  91. {
  92. try{
  93. // 参数
  94. $params = $this->getParams();
  95. TemplateValidate::checkSaveParent($params);
  96. $doctor = $service->getUser($this->getToken());
  97. // 获取子级数据
  98. $info = $service->saveParent($params,$doctor);
  99. // 返回
  100. return $this->success($info);
  101. } catch (Exception $exception){
  102. $this->throwError($exception->getMessage(),0001);
  103. }
  104. }
  105. public function saveChildTemplate(TemplateService $service)
  106. {
  107. try{
  108. // 参数
  109. $params = $this->getParams();
  110. TemplateValidate::checkSaveChild($params);
  111. $doctor = $service->getUser($this->getToken());
  112. // 获取子级数据
  113. $info = $service->saveChild($params,$doctor);
  114. // 返回
  115. return $this->success($info);
  116. } catch (Exception $exception){
  117. $this->throwError($exception->getMessage(),0001);
  118. }
  119. }
  120. //获取模板信息
  121. public function getTemplateInfo(TemplateService $service)
  122. {
  123. try{
  124. // 参数
  125. $params = $this->getParams();
  126. TemplateValidate::checkId($params);
  127. // 获取子级数据
  128. $child = $service->getTemplateInfo($params['id']);
  129. // 返回
  130. return $this->success($child);
  131. } catch (Exception $exception){
  132. $this->throwError($exception->getMessage(),0001);
  133. }
  134. }
  135. //修改模板
  136. public function updateTemplate(TemplateService $service)
  137. {
  138. try{
  139. // 参数
  140. $params = $this->getParams();
  141. TemplateValidate::checkId($params);
  142. // 获取子级数据
  143. $child = $service->updateTemplate($params);
  144. // 返回
  145. return $this->success($child);
  146. } catch (Exception $exception){
  147. $this->throwError($exception->getMessage(),0001);
  148. }
  149. }
  150. //获取父类模板列表
  151. public function getParent(TemplateService $service)
  152. {
  153. try{
  154. $doctor = $service->getUser($this->getToken());
  155. $params = $this->getParams();
  156. // 获取列表数据
  157. $child = $service->getParent($doctor,$params);
  158. // 返回
  159. return $this->success($child);
  160. } catch (Exception $exception){
  161. $this->throwError($exception->getMessage(),0001);
  162. }
  163. }
  164. //删除私有模板
  165. public function delTemplate(TemplateService $service)
  166. {
  167. try{
  168. // 参数
  169. $params = $this->getParams();
  170. TemplateValidate::checkId($params);
  171. $doctor = $service->getUser($this->getToken());
  172. // 获取子级数据
  173. $child = $service->delTemplate($doctor,$params['id']);
  174. // 返回
  175. return $this->success($child);
  176. } catch (Exception $exception){
  177. $this->throwError($exception->getMessage(),0001);
  178. }
  179. }
  180. public function getHospitalTemplate(TemplateService $service)
  181. {
  182. try{
  183. // 参数
  184. $params = $this->getParams();
  185. $doctor = $service->getUser($this->getToken());
  186. // 获取子级数据
  187. $hospital = $service->getHospitalTemplate($doctor['institution_id'],$params['exam_class'] ?? '');
  188. // 返回
  189. return $this->success($hospital);
  190. } catch (Exception $exception){
  191. $this->throwError($exception->getMessage(),0001);
  192. }
  193. }
  194. }