TemplateService.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace app\api\servies\template;
  3. use app\api\servies\ZskkDefaultService;
  4. use app\api\utils\UUIDUtils;
  5. use app\api\validate\template\TemplateValidate;
  6. use app\api\dao\template\TemplateDao;
  7. use app\api\servies\common\CommonService;
  8. use think\facade\Log;
  9. /**
  10. * 后台控制器基类
  11. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  12. */
  13. class TemplateService extends ZskkDefaultService {
  14. protected $logName = "TemplateService";
  15. private $templateDao = null;
  16. public function __construct(TemplateDao $templateDao) {
  17. parent::__construct();
  18. $this->templateDao = $templateDao;
  19. }
  20. public function getExamClass($examId)
  21. {
  22. $examClass = $this->templateDao->getExamClass($examId);
  23. return $examClass;
  24. }
  25. public function getPublicTemplate($examClass)
  26. {
  27. try {
  28. // 获取常量
  29. $constantValue = $this->templateDao->getConstant($examClass, 'constant_value');
  30. // 查询数据
  31. $data = $this->templateDao->getPublicInfo($constantValue);
  32. $info = $this->formatTree(0, $data);
  33. return $info;
  34. } catch (Exception $exception) {
  35. $this->throwError($exception->getMessage(),0001);
  36. }
  37. }
  38. /**
  39. * 格式化模板数据
  40. * @param $id
  41. * @param array $data
  42. * @return array
  43. */
  44. public function formatTree($id, array $data)
  45. {
  46. $new_data = [];
  47. if(!empty($data)){
  48. foreach ($data as $v){
  49. if($v['pid'] == $id){
  50. if($id == 0){
  51. unset($v['description']);
  52. unset($v['impression']);
  53. $v['children'] = $this->formatTree($v['id'], $data);
  54. $new_data[] = $v;
  55. } else {
  56. $new_data[] = $v;
  57. }
  58. }
  59. }
  60. }
  61. return $new_data;
  62. }
  63. public function getUser($token)
  64. {
  65. $user = $this->templateDao->getUser($token);
  66. return $user;
  67. }
  68. public function getPrivateTemplate($examClass, $uid)
  69. {
  70. try {
  71. // 获取常量
  72. $constantValue = $this->templateDao->getConstant($examClass, 'constant_value');
  73. // 查询数据
  74. $data = $this->templateDao->getPrivateInfo($constantValue,$uid);
  75. // 格式化数据
  76. $data = $this->formatTree(0, $data);
  77. return $data;
  78. } catch (Exception $exception) {
  79. $this->throwError($exception->getMessage(),0001);
  80. }
  81. }
  82. public function getPublicTemplateKey($exam_class)
  83. {
  84. $key = 'public_template' . $exam_class;
  85. return $key;
  86. }
  87. public function getPublicInfo($key,$exam_class)
  88. {
  89. if(empty($exam_class))
  90. {
  91. return [];
  92. }
  93. $info = $this->templateDao->getPublic($key,$exam_class);
  94. return $info;
  95. }
  96. public function getPrivate($examClass,$userId)
  97. {
  98. if(empty($examClass))
  99. {
  100. return [];
  101. }
  102. $info = $this->templateDao->getPrivate($examClass,$userId);
  103. return $info;
  104. }
  105. public function getChildData($id)
  106. {
  107. $info = $this->templateDao->getChildData($id);
  108. return $info;
  109. }
  110. public function getTemplateInfo($id)
  111. {
  112. $info = $this->templateDao->getTemplate($id);
  113. if($info['parent_id'] !== 0){
  114. // $info['title'] = $this->templateDao->getParentTitle($info['parent_id']);
  115. $info['title'] = $info['parent_id'];
  116. }
  117. unset($info['parent_id']);
  118. return $info;
  119. }
  120. public function saveParent($param,$doctor)
  121. {
  122. $info = array();
  123. $this->templateDao->checkParentTemplate($param,$doctor);
  124. $info['id'] = UUIDUtils::uuid();
  125. $info['title'] = $param['label'];
  126. $info['createdAt'] = date('Y-m-d H:i:s',time());
  127. $info['is_public'] = 2;
  128. $info['create_user'] = $doctor['id'];
  129. $info['exam_class_id'] = $param['exam_class_id'];
  130. $info['parent_id'] = 0;
  131. $data = $this->templateDao->insertTemplate($info);
  132. return $data;
  133. }
  134. public function saveChild($param,$doctor)
  135. {
  136. $info = array();
  137. $this->templateDao->checkChildTemplate($param,$doctor);
  138. $info['id'] = UUIDUtils::uuid();
  139. $info['title'] = $param['label'];
  140. $info['createdAt'] = date('Y-m-d H:i:s',time());
  141. $info['is_public'] = 2;
  142. $exam = $this->templateDao->getTemplateExam($param['id']);
  143. $info['exam_class_id'] = $exam;
  144. $info['create_user'] = $doctor['id'];
  145. $info['parent_id'] = $param['id'];
  146. $info['impression'] = $param['impression'];
  147. $info['description'] = $param['description'];
  148. $data = $this->templateDao->insertTemplate($info);
  149. return $data;
  150. }
  151. public function updateTemplate($param)
  152. {
  153. $info = $param;
  154. $info['title'] = $param['label'];
  155. unset($info['label']);
  156. $data = $this->templateDao->updateTemplate($info);
  157. return $data;
  158. }
  159. public function getParent($doctor,$params)
  160. {
  161. $parent = $this->templateDao->getParentList($doctor['id'],$params);
  162. return $parent;
  163. }
  164. public function delTemplate($doctor,$id)
  165. {
  166. $data = $this->templateDao->checkTemplate($id);
  167. if($data){
  168. $this->throwError('该模板下存在子模板信息,无法删除','0303');
  169. }
  170. $info = $this->templateDao->delTemplate($doctor['id'],$id);
  171. return $info;
  172. }
  173. public function getHospitalTemplate($institution,$class)
  174. {
  175. $info = $this->templateDao->getHospitalTemplate($institution,$class);
  176. return $info;
  177. }
  178. }