|
@@ -7,6 +7,7 @@ import (
|
7
|
7
|
"XT_New/utils"
|
8
|
8
|
"encoding/json"
|
9
|
9
|
"fmt"
|
|
10
|
+ "github.com/jinzhu/gorm"
|
10
|
11
|
"reflect"
|
11
|
12
|
"strconv"
|
12
|
13
|
"time"
|
|
@@ -21,17 +22,18 @@ type ScheduleApiController struct {
|
21
|
22
|
func ScheduleApiRegistRouters() {
|
22
|
23
|
beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
|
23
|
24
|
beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
|
|
25
|
+ beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
|
|
26
|
+
|
24
|
27
|
beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
|
25
|
28
|
beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
|
26
|
29
|
beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
|
27
|
30
|
beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
|
28
|
31
|
beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
|
29
|
|
-
|
30
|
32
|
beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
|
31
|
|
-
|
32
|
33
|
beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
|
33
|
|
-
|
34
|
34
|
beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
|
|
35
|
+ beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
|
|
36
|
+ beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
|
35
|
37
|
|
36
|
38
|
}
|
37
|
39
|
|
|
@@ -702,3 +704,941 @@ func Struct2Map(obj interface{}) map[string]interface{} {
|
702
|
704
|
}
|
703
|
705
|
return data
|
704
|
706
|
}
|
|
707
|
+
|
|
708
|
+func (this *ScheduleApiController) ExportSchedule() {
|
|
709
|
+ dataBody := make(map[string]interface{}, 0)
|
|
710
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
711
|
+ if err != nil {
|
|
712
|
+ utils.ErrorLog(err.Error())
|
|
713
|
+ return
|
|
714
|
+ }
|
|
715
|
+ utils.ErrorLog("%v", dataBody)
|
|
716
|
+ export_time := time.Now().Unix()
|
|
717
|
+ var schedules []*models.Schedule
|
|
718
|
+ var total_schedule []interface{}
|
|
719
|
+
|
|
720
|
+ var patients []*models.Patients
|
|
721
|
+
|
|
722
|
+ patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
|
|
723
|
+
|
|
724
|
+ if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
|
|
725
|
+ tempSchedule := dataBody["schedule"].([]interface{})
|
|
726
|
+ total_schedule = tempSchedule
|
|
727
|
+ for _, schMap := range tempSchedule {
|
|
728
|
+ schMapM := schMap.(map[string]interface{})
|
|
729
|
+ var sch models.Schedule
|
|
730
|
+
|
|
731
|
+ if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
|
|
732
|
+ utils.ErrorLog("name")
|
|
733
|
+ return
|
|
734
|
+ }
|
|
735
|
+
|
|
736
|
+ name, _ := schMapM["name"].(string)
|
|
737
|
+ fmt.Println(name)
|
|
738
|
+ if len(name) == 0 { //名字为空则生成一条导入错误日志
|
|
739
|
+ err_log := models.ExportErrLog{
|
|
740
|
+ LogType: 2,
|
|
741
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
742
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
|
|
743
|
+ Status: 1,
|
|
744
|
+ CreateTime: time.Now().Unix(),
|
|
745
|
+ UpdateTime: time.Now().Unix(),
|
|
746
|
+ ExportTime: export_time,
|
|
747
|
+ }
|
|
748
|
+ service.CreateExportErrLog(&err_log)
|
|
749
|
+ continue
|
|
750
|
+
|
|
751
|
+ } else {
|
|
752
|
+ var patient []*models.Patients
|
|
753
|
+ for _, item := range patients {
|
|
754
|
+ if item.Name == name {
|
|
755
|
+ patient = append(patient, item)
|
|
756
|
+ }
|
|
757
|
+ }
|
|
758
|
+ if len(patient) == 0 { //错误日志
|
|
759
|
+ err_log := models.ExportErrLog{
|
|
760
|
+ LogType: 2,
|
|
761
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
762
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
|
|
763
|
+ Status: 1,
|
|
764
|
+ CreateTime: time.Now().Unix(),
|
|
765
|
+ UpdateTime: time.Now().Unix(),
|
|
766
|
+ ExportTime: export_time,
|
|
767
|
+ }
|
|
768
|
+ service.CreateExportErrLog(&err_log)
|
|
769
|
+ continue
|
|
770
|
+
|
|
771
|
+ } else if len(patient) == 1 { //
|
|
772
|
+ sch.PatientId = patient[0].ID
|
|
773
|
+
|
|
774
|
+ } else if len(patient) > 2 { //出现同名的情况
|
|
775
|
+
|
|
776
|
+ err_log := models.ExportErrLog{
|
|
777
|
+ LogType: 2,
|
|
778
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
779
|
+ ErrMsg: "存在同名同姓的两个病人",
|
|
780
|
+ Status: 1,
|
|
781
|
+ CreateTime: time.Now().Unix(),
|
|
782
|
+ UpdateTime: time.Now().Unix(),
|
|
783
|
+ ExportTime: export_time,
|
|
784
|
+ }
|
|
785
|
+ service.CreateExportErrLog(&err_log)
|
|
786
|
+ continue
|
|
787
|
+
|
|
788
|
+ }
|
|
789
|
+ }
|
|
790
|
+
|
|
791
|
+ if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
|
|
792
|
+ utils.ErrorLog("schedule_type")
|
|
793
|
+ return
|
|
794
|
+ }
|
|
795
|
+ schedule_type := int64(schMapM["schedule_type"].(float64))
|
|
796
|
+ if schedule_type <= 0 { //班次格式有误,插入日志
|
|
797
|
+
|
|
798
|
+ log := models.ExportLog{
|
|
799
|
+ LogType: 2,
|
|
800
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
801
|
+ TotalNum: int64(len(total_schedule)),
|
|
802
|
+ FailNum: 1,
|
|
803
|
+ SuccessNum: int64(len(schedules)),
|
|
804
|
+ CreateTime: time.Now().Unix(),
|
|
805
|
+ UpdateTime: time.Now().Unix(),
|
|
806
|
+ ExportTime: export_time,
|
|
807
|
+ Status: 1,
|
|
808
|
+ }
|
|
809
|
+ service.CreateExportLog(&log)
|
|
810
|
+
|
|
811
|
+ err_log := models.ExportErrLog{
|
|
812
|
+ LogType: 2,
|
|
813
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
814
|
+ ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
|
|
815
|
+ Status: 1,
|
|
816
|
+ CreateTime: time.Now().Unix(),
|
|
817
|
+ UpdateTime: time.Now().Unix(),
|
|
818
|
+ ExportTime: export_time,
|
|
819
|
+ }
|
|
820
|
+ service.CreateExportErrLog(&err_log)
|
|
821
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
822
|
+ return
|
|
823
|
+
|
|
824
|
+ } else {
|
|
825
|
+ sch.ScheduleType = schedule_type
|
|
826
|
+ }
|
|
827
|
+
|
|
828
|
+ if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
|
|
829
|
+ utils.ErrorLog("partition_name")
|
|
830
|
+ return
|
|
831
|
+ }
|
|
832
|
+
|
|
833
|
+ partition_name, _ := schMapM["partition_name"].(string)
|
|
834
|
+ if len(partition_name) == 0 { //分区为空
|
|
835
|
+ log := models.ExportLog{
|
|
836
|
+ LogType: 2,
|
|
837
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
838
|
+ TotalNum: int64(len(total_schedule)),
|
|
839
|
+ FailNum: 1,
|
|
840
|
+ SuccessNum: int64(len(schedules)),
|
|
841
|
+ CreateTime: time.Now().Unix(),
|
|
842
|
+ UpdateTime: time.Now().Unix(),
|
|
843
|
+ ExportTime: export_time,
|
|
844
|
+ Status: 1,
|
|
845
|
+ }
|
|
846
|
+ service.CreateExportLog(&log)
|
|
847
|
+
|
|
848
|
+ err_log := models.ExportErrLog{
|
|
849
|
+ LogType: 2,
|
|
850
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
851
|
+ //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
|
|
852
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
|
|
853
|
+ Status: 1,
|
|
854
|
+ CreateTime: time.Now().Unix(),
|
|
855
|
+ UpdateTime: time.Now().Unix(),
|
|
856
|
+ ExportTime: export_time,
|
|
857
|
+ }
|
|
858
|
+ service.CreateExportErrLog(&err_log)
|
|
859
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
860
|
+ return
|
|
861
|
+
|
|
862
|
+ } else {
|
|
863
|
+ zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
|
|
864
|
+ if err == nil {
|
|
865
|
+ sch.PartitionId = zone.ID
|
|
866
|
+ } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
|
|
867
|
+
|
|
868
|
+ log := models.ExportLog{
|
|
869
|
+ LogType: 2,
|
|
870
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
871
|
+ TotalNum: int64(len(total_schedule)),
|
|
872
|
+ FailNum: 1,
|
|
873
|
+ SuccessNum: int64(len(schedules)),
|
|
874
|
+ CreateTime: time.Now().Unix(),
|
|
875
|
+ UpdateTime: time.Now().Unix(),
|
|
876
|
+ ExportTime: export_time,
|
|
877
|
+ Status: 1,
|
|
878
|
+ }
|
|
879
|
+ service.CreateExportLog(&log)
|
|
880
|
+
|
|
881
|
+ err_log := models.ExportErrLog{
|
|
882
|
+ LogType: 2,
|
|
883
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
884
|
+ //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
|
|
885
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
|
|
886
|
+ Status: 1,
|
|
887
|
+ CreateTime: time.Now().Unix(),
|
|
888
|
+ UpdateTime: time.Now().Unix(),
|
|
889
|
+ ExportTime: export_time,
|
|
890
|
+ }
|
|
891
|
+ service.CreateExportErrLog(&err_log)
|
|
892
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
893
|
+ return
|
|
894
|
+
|
|
895
|
+ }
|
|
896
|
+
|
|
897
|
+ }
|
|
898
|
+
|
|
899
|
+ if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
|
|
900
|
+ utils.ErrorLog("device_number_name")
|
|
901
|
+ return
|
|
902
|
+ }
|
|
903
|
+
|
|
904
|
+ device_number_name, _ := schMapM["device_number_name"].(string)
|
|
905
|
+ if len(device_number_name) == 0 { //分区为空
|
|
906
|
+
|
|
907
|
+ log := models.ExportLog{
|
|
908
|
+ LogType: 2,
|
|
909
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
910
|
+ TotalNum: int64(len(total_schedule)),
|
|
911
|
+ FailNum: 1,
|
|
912
|
+ SuccessNum: int64(len(schedules)),
|
|
913
|
+ CreateTime: time.Now().Unix(),
|
|
914
|
+ UpdateTime: time.Now().Unix(),
|
|
915
|
+ ExportTime: export_time,
|
|
916
|
+ Status: 1,
|
|
917
|
+ }
|
|
918
|
+ service.CreateExportLog(&log)
|
|
919
|
+
|
|
920
|
+ err_log := models.ExportErrLog{
|
|
921
|
+ LogType: 2,
|
|
922
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
923
|
+ //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
|
|
924
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
|
|
925
|
+
|
|
926
|
+ Status: 1,
|
|
927
|
+ CreateTime: time.Now().Unix(),
|
|
928
|
+ UpdateTime: time.Now().Unix(),
|
|
929
|
+ ExportTime: export_time,
|
|
930
|
+ }
|
|
931
|
+ service.CreateExportErrLog(&err_log)
|
|
932
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
933
|
+ return
|
|
934
|
+
|
|
935
|
+ } else {
|
|
936
|
+ device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
|
|
937
|
+ if err == nil {
|
|
938
|
+ if len(device) == 0 { //没查到数据,插入错误日志
|
|
939
|
+
|
|
940
|
+ log := models.ExportLog{
|
|
941
|
+ LogType: 2,
|
|
942
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
943
|
+ TotalNum: int64(len(total_schedule)),
|
|
944
|
+ FailNum: 1,
|
|
945
|
+ SuccessNum: int64(len(schedules)),
|
|
946
|
+ CreateTime: time.Now().Unix(),
|
|
947
|
+ UpdateTime: time.Now().Unix(),
|
|
948
|
+ ExportTime: export_time,
|
|
949
|
+ Status: 1,
|
|
950
|
+ }
|
|
951
|
+ service.CreateExportLog(&log)
|
|
952
|
+
|
|
953
|
+ err_log := models.ExportErrLog{
|
|
954
|
+ LogType: 2,
|
|
955
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
956
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
|
|
957
|
+ Status: 1,
|
|
958
|
+ CreateTime: time.Now().Unix(),
|
|
959
|
+ UpdateTime: time.Now().Unix(),
|
|
960
|
+ ExportTime: export_time,
|
|
961
|
+ }
|
|
962
|
+ service.CreateExportErrLog(&err_log)
|
|
963
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
964
|
+ return
|
|
965
|
+
|
|
966
|
+ } else if len(device) == 1 {
|
|
967
|
+ sch.BedId = device[0].ID
|
|
968
|
+
|
|
969
|
+ } else if len(device) > 1 { //出现重名,插入错误日志
|
|
970
|
+
|
|
971
|
+ log := models.ExportLog{
|
|
972
|
+ LogType: 2,
|
|
973
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
974
|
+ TotalNum: int64(len(total_schedule)),
|
|
975
|
+ FailNum: 1,
|
|
976
|
+ SuccessNum: int64(len(schedules)),
|
|
977
|
+ CreateTime: time.Now().Unix(),
|
|
978
|
+ UpdateTime: time.Now().Unix(),
|
|
979
|
+ ExportTime: export_time,
|
|
980
|
+ Status: 1,
|
|
981
|
+ }
|
|
982
|
+ service.CreateExportLog(&log)
|
|
983
|
+
|
|
984
|
+ err_log := models.ExportErrLog{
|
|
985
|
+ LogType: 2,
|
|
986
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
987
|
+ ErrMsg: "出现两个床位号相同的床位",
|
|
988
|
+ Status: 1,
|
|
989
|
+ CreateTime: time.Now().Unix(),
|
|
990
|
+ UpdateTime: time.Now().Unix(),
|
|
991
|
+ ExportTime: export_time,
|
|
992
|
+ }
|
|
993
|
+ service.CreateExportErrLog(&err_log)
|
|
994
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
995
|
+ return
|
|
996
|
+
|
|
997
|
+ }
|
|
998
|
+ }
|
|
999
|
+ }
|
|
1000
|
+
|
|
1001
|
+ if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
|
|
1002
|
+ utils.ErrorLog("schedule_week")
|
|
1003
|
+ return
|
|
1004
|
+ }
|
|
1005
|
+ schedule_week, _ := schMapM["schedule_week"].(string)
|
|
1006
|
+ if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
|
|
1007
|
+
|
|
1008
|
+ log := models.ExportLog{
|
|
1009
|
+ LogType: 2,
|
|
1010
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1011
|
+ TotalNum: int64(len(total_schedule)),
|
|
1012
|
+ FailNum: 1,
|
|
1013
|
+ SuccessNum: int64(len(schedules)),
|
|
1014
|
+ CreateTime: time.Now().Unix(),
|
|
1015
|
+ UpdateTime: time.Now().Unix(),
|
|
1016
|
+ ExportTime: export_time,
|
|
1017
|
+ Status: 1,
|
|
1018
|
+ }
|
|
1019
|
+ service.CreateExportLog(&log)
|
|
1020
|
+
|
|
1021
|
+ err_log := models.ExportErrLog{
|
|
1022
|
+ LogType: 2,
|
|
1023
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1024
|
+ //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
|
|
1025
|
+ ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
|
|
1026
|
+
|
|
1027
|
+ Status: 1,
|
|
1028
|
+ CreateTime: time.Now().Unix(),
|
|
1029
|
+ UpdateTime: time.Now().Unix(),
|
|
1030
|
+ ExportTime: export_time,
|
|
1031
|
+ }
|
|
1032
|
+ service.CreateExportErrLog(&err_log)
|
|
1033
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1034
|
+ return
|
|
1035
|
+
|
|
1036
|
+ } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
|
|
1037
|
+
|
|
1038
|
+ log := models.ExportLog{
|
|
1039
|
+ LogType: 2,
|
|
1040
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1041
|
+ TotalNum: int64(len(total_schedule)),
|
|
1042
|
+ FailNum: 1,
|
|
1043
|
+ SuccessNum: int64(len(schedules)),
|
|
1044
|
+ CreateTime: time.Now().Unix(),
|
|
1045
|
+ UpdateTime: time.Now().Unix(),
|
|
1046
|
+ ExportTime: export_time,
|
|
1047
|
+ Status: 1,
|
|
1048
|
+ }
|
|
1049
|
+ service.CreateExportLog(&log)
|
|
1050
|
+
|
|
1051
|
+ err_log := models.ExportErrLog{
|
|
1052
|
+ LogType: 2,
|
|
1053
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1054
|
+ ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
|
|
1055
|
+ Status: 1,
|
|
1056
|
+ CreateTime: time.Now().Unix(),
|
|
1057
|
+ UpdateTime: time.Now().Unix(),
|
|
1058
|
+ ExportTime: export_time,
|
|
1059
|
+ }
|
|
1060
|
+ service.CreateExportErrLog(&err_log)
|
|
1061
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1062
|
+ return
|
|
1063
|
+
|
|
1064
|
+ } else {
|
|
1065
|
+ schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
|
|
1066
|
+ sch.ScheduleWeek = schedule_week
|
|
1067
|
+
|
|
1068
|
+ }
|
|
1069
|
+
|
|
1070
|
+ if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
|
|
1071
|
+ utils.ErrorLog("schedule_date")
|
|
1072
|
+ return
|
|
1073
|
+ }
|
|
1074
|
+ schedule_date, _ := schMapM["schedule_date"].(string)
|
|
1075
|
+
|
|
1076
|
+ if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
|
|
1077
|
+
|
|
1078
|
+ log := models.ExportLog{
|
|
1079
|
+ LogType: 2,
|
|
1080
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1081
|
+ TotalNum: int64(len(total_schedule)),
|
|
1082
|
+ FailNum: 1,
|
|
1083
|
+ SuccessNum: int64(len(schedules)),
|
|
1084
|
+ CreateTime: time.Now().Unix(),
|
|
1085
|
+ UpdateTime: time.Now().Unix(),
|
|
1086
|
+ ExportTime: export_time,
|
|
1087
|
+ Status: 1,
|
|
1088
|
+ }
|
|
1089
|
+ service.CreateExportLog(&log)
|
|
1090
|
+
|
|
1091
|
+ err_log := models.ExportErrLog{
|
|
1092
|
+ LogType: 2,
|
|
1093
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1094
|
+ ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
|
|
1095
|
+ Status: 1,
|
|
1096
|
+ CreateTime: time.Now().Unix(),
|
|
1097
|
+ UpdateTime: time.Now().Unix(),
|
|
1098
|
+ ExportTime: export_time,
|
|
1099
|
+ }
|
|
1100
|
+ service.CreateExportErrLog(&err_log)
|
|
1101
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1102
|
+ return
|
|
1103
|
+
|
|
1104
|
+ } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
|
|
1105
|
+
|
|
1106
|
+ log := models.ExportLog{
|
|
1107
|
+ LogType: 2,
|
|
1108
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1109
|
+ TotalNum: int64(len(total_schedule)),
|
|
1110
|
+ FailNum: 1,
|
|
1111
|
+ SuccessNum: int64(len(schedules)),
|
|
1112
|
+ CreateTime: time.Now().Unix(),
|
|
1113
|
+ UpdateTime: time.Now().Unix(),
|
|
1114
|
+ ExportTime: export_time,
|
|
1115
|
+ Status: 1,
|
|
1116
|
+ }
|
|
1117
|
+ service.CreateExportLog(&log)
|
|
1118
|
+
|
|
1119
|
+ err_log := models.ExportErrLog{
|
|
1120
|
+ LogType: 2,
|
|
1121
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1122
|
+ ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
|
|
1123
|
+ Status: 1,
|
|
1124
|
+ CreateTime: time.Now().Unix(),
|
|
1125
|
+ UpdateTime: time.Now().Unix(),
|
|
1126
|
+ ExportTime: export_time,
|
|
1127
|
+ }
|
|
1128
|
+ service.CreateExportErrLog(&err_log)
|
|
1129
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1130
|
+ return
|
|
1131
|
+
|
|
1132
|
+ } else {
|
|
1133
|
+ date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
|
|
1134
|
+ sch.ScheduleDate = date.Unix()
|
|
1135
|
+ }
|
|
1136
|
+ sch.CreatedTime = time.Now().Unix()
|
|
1137
|
+ sch.UpdatedTime = time.Now().Unix()
|
|
1138
|
+ sch.ModeId = 1
|
|
1139
|
+ sch.Status = 1
|
|
1140
|
+ sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
|
|
1141
|
+ sch.IsExport = 1
|
|
1142
|
+ schedules = append(schedules, &sch)
|
|
1143
|
+ }
|
|
1144
|
+
|
|
1145
|
+ errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
|
|
1146
|
+
|
|
1147
|
+ if len(schedules) > 0 {
|
|
1148
|
+ schedule_date := this.GetString("date")
|
|
1149
|
+ date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
|
|
1150
|
+ clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据
|
|
1151
|
+ err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
|
|
1152
|
+ if err == nil {
|
|
1153
|
+ for _, item := range schedules {
|
|
1154
|
+ service.CreateSchedule(item)
|
|
1155
|
+ }
|
|
1156
|
+
|
|
1157
|
+ log := models.ExportLog{
|
|
1158
|
+ LogType: 2,
|
|
1159
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1160
|
+ TotalNum: int64(len(total_schedule)),
|
|
1161
|
+ FailNum: int64(len(errLogs)),
|
|
1162
|
+ SuccessNum: int64(len(schedules)),
|
|
1163
|
+ CreateTime: time.Now().Unix(),
|
|
1164
|
+ UpdateTime: time.Now().Unix(),
|
|
1165
|
+ ExportTime: export_time,
|
|
1166
|
+ Status: 1,
|
|
1167
|
+ }
|
|
1168
|
+ service.CreateExportLog(&log)
|
|
1169
|
+
|
|
1170
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
1171
|
+ "msg": "导入成功",
|
|
1172
|
+ "total_num": len(total_schedule),
|
|
1173
|
+ "success_num": len(schedules),
|
|
1174
|
+ "fail_num": int64(len(errLogs)),
|
|
1175
|
+ })
|
|
1176
|
+ } else {
|
|
1177
|
+ log := models.ExportLog{
|
|
1178
|
+ LogType: 2,
|
|
1179
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1180
|
+ TotalNum: int64(len(total_schedule)),
|
|
1181
|
+ FailNum: int64(len(errLogs)),
|
|
1182
|
+ SuccessNum: int64(len(schedules)),
|
|
1183
|
+ CreateTime: time.Now().Unix(),
|
|
1184
|
+ UpdateTime: time.Now().Unix(),
|
|
1185
|
+ ExportTime: export_time,
|
|
1186
|
+ Status: 1,
|
|
1187
|
+ }
|
|
1188
|
+ service.CreateExportLog(&log)
|
|
1189
|
+
|
|
1190
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
1191
|
+ "msg": "导入成功",
|
|
1192
|
+ "total_num": len(total_schedule),
|
|
1193
|
+ "success_num": len(schedules),
|
|
1194
|
+ "fail_num": int64(len(errLogs)),
|
|
1195
|
+ })
|
|
1196
|
+ }
|
|
1197
|
+ } else {
|
|
1198
|
+ log := models.ExportLog{
|
|
1199
|
+ LogType: 2,
|
|
1200
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1201
|
+ TotalNum: int64(len(total_schedule)),
|
|
1202
|
+ FailNum: int64(len(errLogs)),
|
|
1203
|
+ SuccessNum: int64(len(schedules)),
|
|
1204
|
+ CreateTime: time.Now().Unix(),
|
|
1205
|
+ UpdateTime: time.Now().Unix(),
|
|
1206
|
+ ExportTime: export_time,
|
|
1207
|
+ Status: 1,
|
|
1208
|
+ }
|
|
1209
|
+ service.CreateExportLog(&log)
|
|
1210
|
+
|
|
1211
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
1212
|
+ "msg": "导入成功",
|
|
1213
|
+ "total_num": len(total_schedule),
|
|
1214
|
+ "success_num": len(schedules),
|
|
1215
|
+ "fail_num": int64(len(errLogs)),
|
|
1216
|
+ })
|
|
1217
|
+ }
|
|
1218
|
+ }
|
|
1219
|
+
|
|
1220
|
+}
|
|
1221
|
+
|
|
1222
|
+func (this *ScheduleApiController) ExportScheduleTemplate() {
|
|
1223
|
+ dataBody := make(map[string]interface{}, 0)
|
|
1224
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
1225
|
+ if err != nil {
|
|
1226
|
+ utils.ErrorLog(err.Error())
|
|
1227
|
+ return
|
|
1228
|
+ }
|
|
1229
|
+ utils.ErrorLog("%v", dataBody)
|
|
1230
|
+ export_time := time.Now().Unix()
|
|
1231
|
+ var schedules []*models.PatientScheduleTemplateItem
|
|
1232
|
+ var total_schedule []interface{}
|
|
1233
|
+
|
|
1234
|
+ patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
|
|
1235
|
+
|
|
1236
|
+ if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
|
|
1237
|
+ tempSchedule := dataBody["schedule"].([]interface{})
|
|
1238
|
+ total_schedule = tempSchedule
|
|
1239
|
+ for _, schMap := range tempSchedule {
|
|
1240
|
+ schMapM := schMap.(map[string]interface{})
|
|
1241
|
+ var sch models.PatientScheduleTemplateItem
|
|
1242
|
+
|
|
1243
|
+ if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
|
|
1244
|
+ utils.ErrorLog("name")
|
|
1245
|
+ return
|
|
1246
|
+ }
|
|
1247
|
+
|
|
1248
|
+ name, _ := schMapM["name"].(string)
|
|
1249
|
+ fmt.Println(name)
|
|
1250
|
+ if len(name) == 0 { //名字为空则生成一条导入错误日志
|
|
1251
|
+ err_log := models.ExportErrLog{
|
|
1252
|
+ LogType: 3,
|
|
1253
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1254
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
|
|
1255
|
+ Status: 1,
|
|
1256
|
+ CreateTime: time.Now().Unix(),
|
|
1257
|
+ UpdateTime: time.Now().Unix(),
|
|
1258
|
+ ExportTime: export_time,
|
|
1259
|
+ }
|
|
1260
|
+ service.CreateExportErrLog(&err_log)
|
|
1261
|
+ continue
|
|
1262
|
+
|
|
1263
|
+ } else {
|
|
1264
|
+ var patient []*models.Patients
|
|
1265
|
+ for _, item := range patients {
|
|
1266
|
+ if item.Name == name {
|
|
1267
|
+ patient = append(patient, item)
|
|
1268
|
+ }
|
|
1269
|
+ }
|
|
1270
|
+ if len(patient) == 0 { //错误日志
|
|
1271
|
+ err_log := models.ExportErrLog{
|
|
1272
|
+ LogType: 3,
|
|
1273
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1274
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
|
|
1275
|
+ Status: 1,
|
|
1276
|
+ CreateTime: time.Now().Unix(),
|
|
1277
|
+ UpdateTime: time.Now().Unix(),
|
|
1278
|
+ ExportTime: export_time,
|
|
1279
|
+ }
|
|
1280
|
+ service.CreateExportErrLog(&err_log)
|
|
1281
|
+ continue
|
|
1282
|
+
|
|
1283
|
+ } else if len(patient) == 1 { //
|
|
1284
|
+ sch.PatientID = patient[0].ID
|
|
1285
|
+
|
|
1286
|
+ } else if len(patient) > 2 { //出现同名的情况
|
|
1287
|
+
|
|
1288
|
+ err_log := models.ExportErrLog{
|
|
1289
|
+ LogType: 3,
|
|
1290
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1291
|
+ ErrMsg: "存在同名同姓的两个病人",
|
|
1292
|
+ Status: 1,
|
|
1293
|
+ CreateTime: time.Now().Unix(),
|
|
1294
|
+ UpdateTime: time.Now().Unix(),
|
|
1295
|
+ ExportTime: export_time,
|
|
1296
|
+ }
|
|
1297
|
+ service.CreateExportErrLog(&err_log)
|
|
1298
|
+ continue
|
|
1299
|
+
|
|
1300
|
+ }
|
|
1301
|
+ }
|
|
1302
|
+
|
|
1303
|
+ if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
|
|
1304
|
+ utils.ErrorLog("schedule_type")
|
|
1305
|
+ return
|
|
1306
|
+ }
|
|
1307
|
+ schedule_type := int64(schMapM["schedule_type"].(float64))
|
|
1308
|
+ if schedule_type <= 0 { //班次格式有误,插入日志
|
|
1309
|
+ log := models.ExportLog{
|
|
1310
|
+ LogType: 3,
|
|
1311
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1312
|
+ TotalNum: int64(len(total_schedule)),
|
|
1313
|
+ FailNum: 1,
|
|
1314
|
+ SuccessNum: int64(len(schedules)),
|
|
1315
|
+ CreateTime: time.Now().Unix(),
|
|
1316
|
+ UpdateTime: time.Now().Unix(),
|
|
1317
|
+ ExportTime: export_time,
|
|
1318
|
+ Status: 1,
|
|
1319
|
+ }
|
|
1320
|
+ service.CreateExportLog(&log)
|
|
1321
|
+
|
|
1322
|
+ err_log := models.ExportErrLog{
|
|
1323
|
+ LogType: 3,
|
|
1324
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1325
|
+ ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
|
|
1326
|
+ Status: 1,
|
|
1327
|
+ CreateTime: time.Now().Unix(),
|
|
1328
|
+ UpdateTime: time.Now().Unix(),
|
|
1329
|
+ ExportTime: export_time,
|
|
1330
|
+ }
|
|
1331
|
+ service.CreateExportErrLog(&err_log)
|
|
1332
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1333
|
+ return
|
|
1334
|
+
|
|
1335
|
+ } else {
|
|
1336
|
+ sch.TimeType = int8(schedule_type)
|
|
1337
|
+ }
|
|
1338
|
+
|
|
1339
|
+ if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
|
|
1340
|
+ utils.ErrorLog("template_id")
|
|
1341
|
+ return
|
|
1342
|
+ }
|
|
1343
|
+
|
|
1344
|
+ template_id := int64(schMapM["template_id"].(float64))
|
|
1345
|
+ sch.TemplateID = template_id
|
|
1346
|
+
|
|
1347
|
+ if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
|
|
1348
|
+ utils.ErrorLog("device_number_name")
|
|
1349
|
+ return
|
|
1350
|
+ }
|
|
1351
|
+
|
|
1352
|
+ device_number_name, _ := schMapM["device_number_name"].(string)
|
|
1353
|
+ if len(device_number_name) == 0 { //分区为空
|
|
1354
|
+ log := models.ExportLog{
|
|
1355
|
+ LogType: 3,
|
|
1356
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1357
|
+ TotalNum: int64(len(total_schedule)),
|
|
1358
|
+ FailNum: 1,
|
|
1359
|
+ SuccessNum: int64(len(schedules)),
|
|
1360
|
+ CreateTime: time.Now().Unix(),
|
|
1361
|
+ UpdateTime: time.Now().Unix(),
|
|
1362
|
+ ExportTime: export_time,
|
|
1363
|
+ Status: 1,
|
|
1364
|
+ }
|
|
1365
|
+ service.CreateExportLog(&log)
|
|
1366
|
+
|
|
1367
|
+ err_log := models.ExportErrLog{
|
|
1368
|
+ LogType: 3,
|
|
1369
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1370
|
+ //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
|
|
1371
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
|
|
1372
|
+
|
|
1373
|
+ Status: 1,
|
|
1374
|
+ CreateTime: time.Now().Unix(),
|
|
1375
|
+ UpdateTime: time.Now().Unix(),
|
|
1376
|
+ ExportTime: export_time,
|
|
1377
|
+ }
|
|
1378
|
+ service.CreateExportErrLog(&err_log)
|
|
1379
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1380
|
+ return
|
|
1381
|
+
|
|
1382
|
+ } else {
|
|
1383
|
+ device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId)
|
|
1384
|
+ if err == nil {
|
|
1385
|
+ if len(device) == 0 { //没查到数据,插入错误日志
|
|
1386
|
+ log := models.ExportLog{
|
|
1387
|
+ LogType: 3,
|
|
1388
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1389
|
+ TotalNum: int64(len(total_schedule)),
|
|
1390
|
+ FailNum: 1,
|
|
1391
|
+ SuccessNum: int64(len(schedules)),
|
|
1392
|
+ CreateTime: time.Now().Unix(),
|
|
1393
|
+ UpdateTime: time.Now().Unix(),
|
|
1394
|
+ ExportTime: export_time,
|
|
1395
|
+ Status: 1,
|
|
1396
|
+ }
|
|
1397
|
+ service.CreateExportLog(&log)
|
|
1398
|
+
|
|
1399
|
+ err_log := models.ExportErrLog{
|
|
1400
|
+ LogType: 3,
|
|
1401
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1402
|
+ ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
|
|
1403
|
+ Status: 1,
|
|
1404
|
+ CreateTime: time.Now().Unix(),
|
|
1405
|
+ UpdateTime: time.Now().Unix(),
|
|
1406
|
+ ExportTime: export_time,
|
|
1407
|
+ }
|
|
1408
|
+ service.CreateExportErrLog(&err_log)
|
|
1409
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1410
|
+ return
|
|
1411
|
+
|
|
1412
|
+ } else if len(device) == 1 {
|
|
1413
|
+ sch.DeviceNumberID = device[0].ID
|
|
1414
|
+
|
|
1415
|
+ } else if len(device) > 1 { //出现重名,插入错误日志
|
|
1416
|
+ log := models.ExportLog{
|
|
1417
|
+ LogType: 3,
|
|
1418
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1419
|
+ TotalNum: int64(len(total_schedule)),
|
|
1420
|
+ FailNum: 1,
|
|
1421
|
+ SuccessNum: int64(len(schedules)),
|
|
1422
|
+ CreateTime: time.Now().Unix(),
|
|
1423
|
+ UpdateTime: time.Now().Unix(),
|
|
1424
|
+ ExportTime: export_time,
|
|
1425
|
+ Status: 1,
|
|
1426
|
+ }
|
|
1427
|
+ service.CreateExportLog(&log)
|
|
1428
|
+
|
|
1429
|
+ err_log := models.ExportErrLog{
|
|
1430
|
+ LogType: 3,
|
|
1431
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1432
|
+ ErrMsg: "出现两个床位号相同的床位",
|
|
1433
|
+ Status: 1,
|
|
1434
|
+ CreateTime: time.Now().Unix(),
|
|
1435
|
+ UpdateTime: time.Now().Unix(),
|
|
1436
|
+ ExportTime: export_time,
|
|
1437
|
+ }
|
|
1438
|
+ service.CreateExportErrLog(&err_log)
|
|
1439
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1440
|
+ return
|
|
1441
|
+
|
|
1442
|
+ }
|
|
1443
|
+ }
|
|
1444
|
+ }
|
|
1445
|
+
|
|
1446
|
+ if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
|
|
1447
|
+ utils.ErrorLog("schedule_week")
|
|
1448
|
+ return
|
|
1449
|
+ }
|
|
1450
|
+ schedule_week, _ := schMapM["schedule_week"].(string)
|
|
1451
|
+ if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
|
|
1452
|
+
|
|
1453
|
+ log := models.ExportLog{
|
|
1454
|
+ LogType: 3,
|
|
1455
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1456
|
+ TotalNum: int64(len(total_schedule)),
|
|
1457
|
+ FailNum: 1,
|
|
1458
|
+ SuccessNum: int64(len(schedules)),
|
|
1459
|
+ CreateTime: time.Now().Unix(),
|
|
1460
|
+ UpdateTime: time.Now().Unix(),
|
|
1461
|
+ ExportTime: export_time,
|
|
1462
|
+ Status: 1,
|
|
1463
|
+ }
|
|
1464
|
+ service.CreateExportLog(&log)
|
|
1465
|
+
|
|
1466
|
+ err_log := models.ExportErrLog{
|
|
1467
|
+ LogType: 3,
|
|
1468
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1469
|
+ //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
|
|
1470
|
+ ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
|
|
1471
|
+
|
|
1472
|
+ Status: 1,
|
|
1473
|
+ CreateTime: time.Now().Unix(),
|
|
1474
|
+ UpdateTime: time.Now().Unix(),
|
|
1475
|
+ ExportTime: export_time,
|
|
1476
|
+ }
|
|
1477
|
+ service.CreateExportErrLog(&err_log)
|
|
1478
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1479
|
+ return
|
|
1480
|
+
|
|
1481
|
+ } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
|
|
1482
|
+
|
|
1483
|
+ log := models.ExportLog{
|
|
1484
|
+ LogType: 3,
|
|
1485
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1486
|
+ TotalNum: int64(len(total_schedule)),
|
|
1487
|
+ FailNum: 1,
|
|
1488
|
+ SuccessNum: int64(len(schedules)),
|
|
1489
|
+ CreateTime: time.Now().Unix(),
|
|
1490
|
+ UpdateTime: time.Now().Unix(),
|
|
1491
|
+ ExportTime: export_time,
|
|
1492
|
+ Status: 1,
|
|
1493
|
+ }
|
|
1494
|
+ service.CreateExportLog(&log)
|
|
1495
|
+
|
|
1496
|
+ err_log := models.ExportErrLog{
|
|
1497
|
+ LogType: 3,
|
|
1498
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1499
|
+ ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
|
|
1500
|
+ Status: 1,
|
|
1501
|
+ CreateTime: time.Now().Unix(),
|
|
1502
|
+ UpdateTime: time.Now().Unix(),
|
|
1503
|
+ ExportTime: export_time,
|
|
1504
|
+ }
|
|
1505
|
+ service.CreateExportErrLog(&err_log)
|
|
1506
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
|
|
1507
|
+ return
|
|
1508
|
+
|
|
1509
|
+ } else {
|
|
1510
|
+ schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
|
|
1511
|
+ sch.Weekday = int8(schedule_week)
|
|
1512
|
+
|
|
1513
|
+ }
|
|
1514
|
+
|
|
1515
|
+ sch.CreateTime = time.Now().Unix()
|
|
1516
|
+ sch.ModifyTime = time.Now().Unix()
|
|
1517
|
+ sch.TreatMode = 1
|
|
1518
|
+ sch.Status = 1
|
|
1519
|
+ sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
|
|
1520
|
+ sch.IsExport = 1
|
|
1521
|
+ schedules = append(schedules, &sch)
|
|
1522
|
+ }
|
|
1523
|
+
|
|
1524
|
+ errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
|
|
1525
|
+
|
|
1526
|
+ if len(schedules) > 0 {
|
|
1527
|
+ err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
|
|
1528
|
+ if err == nil {
|
|
1529
|
+ for _, item := range schedules {
|
|
1530
|
+ service.CreateScheduleTemplate(item)
|
|
1531
|
+ }
|
|
1532
|
+
|
|
1533
|
+ log := models.ExportLog{
|
|
1534
|
+ LogType: 3,
|
|
1535
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1536
|
+ TotalNum: int64(len(total_schedule)),
|
|
1537
|
+ FailNum: int64(len(errLogs)),
|
|
1538
|
+ SuccessNum: int64(len(schedules)),
|
|
1539
|
+ CreateTime: time.Now().Unix(),
|
|
1540
|
+ UpdateTime: time.Now().Unix(),
|
|
1541
|
+ ExportTime: export_time,
|
|
1542
|
+ Status: 1,
|
|
1543
|
+ }
|
|
1544
|
+ service.CreateExportLog(&log)
|
|
1545
|
+
|
|
1546
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
1547
|
+ "msg": "导入成功",
|
|
1548
|
+ "total_num": len(total_schedule),
|
|
1549
|
+ "success_num": len(schedules),
|
|
1550
|
+ "fail_num": int64(len(errLogs)),
|
|
1551
|
+ })
|
|
1552
|
+ } else {
|
|
1553
|
+ log := models.ExportLog{
|
|
1554
|
+ LogType: 3,
|
|
1555
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1556
|
+ TotalNum: int64(len(total_schedule)),
|
|
1557
|
+ FailNum: int64(len(errLogs)),
|
|
1558
|
+ SuccessNum: int64(len(schedules)),
|
|
1559
|
+ CreateTime: time.Now().Unix(),
|
|
1560
|
+ UpdateTime: time.Now().Unix(),
|
|
1561
|
+ ExportTime: export_time,
|
|
1562
|
+ Status: 1,
|
|
1563
|
+ }
|
|
1564
|
+ service.CreateExportLog(&log)
|
|
1565
|
+
|
|
1566
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
1567
|
+ "msg": "导入成功",
|
|
1568
|
+ "total_num": len(total_schedule),
|
|
1569
|
+ "success_num": len(schedules),
|
|
1570
|
+ "fail_num": int64(len(errLogs)),
|
|
1571
|
+ })
|
|
1572
|
+ }
|
|
1573
|
+ } else {
|
|
1574
|
+ log := models.ExportLog{
|
|
1575
|
+ LogType: 3,
|
|
1576
|
+ UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
|
|
1577
|
+ TotalNum: int64(len(total_schedule)),
|
|
1578
|
+ FailNum: int64(len(errLogs)),
|
|
1579
|
+ SuccessNum: int64(len(schedules)),
|
|
1580
|
+ CreateTime: time.Now().Unix(),
|
|
1581
|
+ UpdateTime: time.Now().Unix(),
|
|
1582
|
+ ExportTime: export_time,
|
|
1583
|
+ Status: 1,
|
|
1584
|
+ }
|
|
1585
|
+ service.CreateExportLog(&log)
|
|
1586
|
+
|
|
1587
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
1588
|
+ "msg": "导入成功",
|
|
1589
|
+ "total_num": len(total_schedule),
|
|
1590
|
+ "success_num": len(schedules),
|
|
1591
|
+ "fail_num": int64(len(errLogs)),
|
|
1592
|
+ })
|
|
1593
|
+ }
|
|
1594
|
+ }
|
|
1595
|
+
|
|
1596
|
+}
|
|
1597
|
+
|
|
1598
|
+func (c *ScheduleApiController) GetInitExcelInitDate() {
|
|
1599
|
+
|
|
1600
|
+ thisTime := time.Now()
|
|
1601
|
+ thisTime1 := time.Now()
|
|
1602
|
+ thisTime2 := time.Now()
|
|
1603
|
+
|
|
1604
|
+ thisTime1 = thisTime1.AddDate(0, 0, 7)
|
|
1605
|
+ thisTime2 = thisTime2.AddDate(0, 0, 14)
|
|
1606
|
+
|
|
1607
|
+ weekDay := int(thisTime.Weekday())
|
|
1608
|
+ if weekDay == 0 {
|
|
1609
|
+ weekDay = 7
|
|
1610
|
+ }
|
|
1611
|
+ weekEnd := 7 - weekDay
|
|
1612
|
+ weekStart := weekEnd - 6
|
|
1613
|
+ days := make([]string, 0)
|
|
1614
|
+ for index := weekStart; index <= weekEnd; index++ {
|
|
1615
|
+ theDay := thisTime.AddDate(0, 0, index)
|
|
1616
|
+ days = append(days, theDay.Format("2006-01-02"))
|
|
1617
|
+ }
|
|
1618
|
+
|
|
1619
|
+ weekDay1 := int(thisTime1.Weekday())
|
|
1620
|
+ if weekDay1 == 0 {
|
|
1621
|
+ weekDay1 = 7
|
|
1622
|
+ }
|
|
1623
|
+ weekEnd1 := 7 - weekDay1
|
|
1624
|
+ weekStart1 := weekEnd1 - 6
|
|
1625
|
+ for index := weekStart1; index <= weekEnd1; index++ {
|
|
1626
|
+ theDay := thisTime1.AddDate(0, 0, index)
|
|
1627
|
+ days = append(days, theDay.Format("2006-01-02"))
|
|
1628
|
+ }
|
|
1629
|
+
|
|
1630
|
+ weekDay2 := int(thisTime2.Weekday())
|
|
1631
|
+ if weekDay2 == 0 {
|
|
1632
|
+ weekDay2 = 7
|
|
1633
|
+ }
|
|
1634
|
+ weekEnd2 := 7 - weekDay2
|
|
1635
|
+ weekStart2 := weekEnd2 - 6
|
|
1636
|
+ for index := weekStart2; index <= weekEnd2; index++ {
|
|
1637
|
+ theDay := thisTime2.AddDate(0, 0, index)
|
|
1638
|
+ days = append(days, theDay.Format("2006-01-02"))
|
|
1639
|
+ }
|
|
1640
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
1641
|
+ "days": days,
|
|
1642
|
+ })
|
|
1643
|
+ return
|
|
1644
|
+}
|