123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- namespace app\api\servies\template;
- use app\api\servies\ZskkDefaultService;
- use app\api\utils\UUIDUtils;
- use app\api\validate\template\TemplateValidate;
- use app\api\dao\template\TemplateDao;
- use app\api\servies\common\CommonService;
- use think\facade\Log;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class TemplateService extends ZskkDefaultService {
- protected $logName = "TemplateService";
- private $templateDao = null;
- public function __construct(TemplateDao $templateDao) {
- parent::__construct();
- $this->templateDao = $templateDao;
- }
- public function getExamClass($examId)
- {
- $examClass = $this->templateDao->getExamClass($examId);
- return $examClass;
- }
- public function getPublicTemplate($examClass)
- {
- try {
- // 获取常量
- $constantValue = $this->templateDao->getConstant($examClass, 'constant_value');
- // 查询数据
- $data = $this->templateDao->getPublicInfo($constantValue);
- $info = $this->formatTree(0, $data);
- return $info;
- } catch (Exception $exception) {
- $this->throwError($exception->getMessage(),0001);
- }
- }
- /**
- * 格式化模板数据
- * @param $id
- * @param array $data
- * @return array
- */
- public function formatTree($id, array $data)
- {
- $new_data = [];
- if(!empty($data)){
- foreach ($data as $v){
- if($v['pid'] == $id){
- if($id == 0){
- unset($v['description']);
- unset($v['impression']);
- $v['children'] = $this->formatTree($v['id'], $data);
- $new_data[] = $v;
- } else {
- $new_data[] = $v;
- }
- }
- }
- }
- return $new_data;
- }
- public function getUser($token)
- {
- $user = $this->templateDao->getUser($token);
- return $user;
- }
- public function getPrivateTemplate($examClass, $uid)
- {
- try {
- // 获取常量
- $constantValue = $this->templateDao->getConstant($examClass, 'constant_value');
- // 查询数据
- $data = $this->templateDao->getPrivateInfo($constantValue,$uid);
- // 格式化数据
- $data = $this->formatTree(0, $data);
- return $data;
- } catch (Exception $exception) {
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getPublicTemplateKey($exam_class)
- {
- $key = 'public_template' . $exam_class;
- return $key;
- }
- public function getPublicInfo($key,$exam_class)
- {
- if(empty($exam_class))
- {
- return [];
- }
- $info = $this->templateDao->getPublic($key,$exam_class);
- return $info;
- }
- public function getPrivate($examClass,$userId)
- {
- if(empty($examClass))
- {
- return [];
- }
- $info = $this->templateDao->getPrivate($examClass,$userId);
- return $info;
- }
- public function getChildData($id)
- {
- $info = $this->templateDao->getChildData($id);
- return $info;
- }
- public function getTemplateInfo($id)
- {
- $info = $this->templateDao->getTemplate($id);
- if($info['parent_id'] !== 0){
- // $info['title'] = $this->templateDao->getParentTitle($info['parent_id']);
- $info['title'] = $info['parent_id'];
- }
- unset($info['parent_id']);
- return $info;
- }
- public function saveParent($param,$doctor)
- {
- $info = array();
- $this->templateDao->checkParentTemplate($param,$doctor);
- $info['id'] = UUIDUtils::uuid();
- $info['title'] = $param['label'];
- $info['createdAt'] = date('Y-m-d H:i:s',time());
- $info['is_public'] = 2;
- $info['create_user'] = $doctor['id'];
- $info['exam_class_id'] = $param['exam_class_id'];
- $info['parent_id'] = 0;
- $data = $this->templateDao->insertTemplate($info);
- return $data;
- }
- public function saveChild($param,$doctor)
- {
- $info = array();
- $this->templateDao->checkChildTemplate($param,$doctor);
- $info['id'] = UUIDUtils::uuid();
- $info['title'] = $param['label'];
- $info['createdAt'] = date('Y-m-d H:i:s',time());
- $info['is_public'] = 2;
- $exam = $this->templateDao->getTemplateExam($param['id']);
- $info['exam_class_id'] = $exam;
- $info['create_user'] = $doctor['id'];
- $info['parent_id'] = $param['id'];
- $info['impression'] = $param['impression'];
- $info['description'] = $param['description'];
- $data = $this->templateDao->insertTemplate($info);
- return $data;
- }
- public function updateTemplate($param)
- {
- $info = $param;
- $info['title'] = $param['label'];
- unset($info['label']);
- $data = $this->templateDao->updateTemplate($info);
- return $data;
- }
- public function getParent($doctor,$params)
- {
- $parent = $this->templateDao->getParentList($doctor['id'],$params);
- return $parent;
- }
- public function delTemplate($doctor,$id)
- {
- $data = $this->templateDao->checkTemplate($id);
- if($data){
- $this->throwError('该模板下存在子模板信息,无法删除','0303');
- }
- $info = $this->templateDao->delTemplate($doctor['id'],$id);
- return $info;
- }
- public function getHospitalTemplate($institution,$class)
- {
- $info = $this->templateDao->getHospitalTemplate($institution,$class);
- return $info;
- }
- }
|