AlarmRecordsGet.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace catchAdmin\alarm\model\get;
  3. use catchAdmin\system\model\SysDictData;
  4. use Exception;
  5. use think\facade\Db;
  6. trait AlarmRecordsGet
  7. {
  8. /**
  9. * 获取原因名称(文本)
  10. */
  11. public function getResultTextAttr($value)
  12. {
  13. $type = $this->result;
  14. if($type){
  15. return $this->getDictValue('AlarmHandleResult',$type);
  16. }else{
  17. return '未处理';
  18. }
  19. }
  20. /**
  21. * 获取开始时间(文本)
  22. */
  23. public function getStartTimeTextAttr($value)
  24. {
  25. if($this->start_time){
  26. return date('Y-m-d H:i:s',$this->start_time);
  27. }else{
  28. return '';
  29. }
  30. }
  31. /**
  32. * 获取结束时间(文本)
  33. */
  34. public function getEndTimeTextAttr($value)
  35. {
  36. if($this->end_time){
  37. return date('Y-m-d H:i:s',$this->end_time);
  38. }else{
  39. return '';
  40. }
  41. }
  42. /**
  43. * 获取处理人
  44. */
  45. public function getHandlerNameAttr($value)
  46. {
  47. return Db::table('users')->where('id',$this->handler_id)->value('realname');
  48. }
  49. /**
  50. * 获取原因
  51. */
  52. public function getReasonTextAttr($value)
  53. {
  54. return $this->getDictValue('AlarmType',$this->alarm_reason);
  55. }
  56. /**
  57. * 获取告警状态
  58. */
  59. public function getStateAttr($value)
  60. {
  61. return $this->getDictValue('AlarmState',$value);
  62. }
  63. /*
  64. * 获取字典值(文本)
  65. */
  66. public function getDictValue($typeCode,$value)
  67. {
  68. return (new SysDictData())->getValueByCode($typeCode,$value);
  69. }
  70. }