Merge branch 'dev-tangxvhui' of http://gitlab.fjmaimaimai.com/allied-creation/pe…
…rformance into dev-tangxvhui
正在显示
9 个修改的文件
包含
396 行增加
和
43 行删除
@@ -239,3 +239,11 @@ func CreateTaskIgnoreRepository(options map[string]interface{}) domain.TaskIgnor | @@ -239,3 +239,11 @@ func CreateTaskIgnoreRepository(options map[string]interface{}) domain.TaskIgnor | ||
239 | } | 239 | } |
240 | return repository.NewTaskIgnoreRepository(transactionContext) | 240 | return repository.NewTaskIgnoreRepository(transactionContext) |
241 | } | 241 | } |
242 | + | ||
243 | +func CreateTaskRecordRepository(options map[string]interface{}) domain.TaskRecordRepository { | ||
244 | + var transactionContext *pg.TransactionContext | ||
245 | + if value, ok := options["transactionContext"]; ok { | ||
246 | + transactionContext = value.(*pg.TransactionContext) | ||
247 | + } | ||
248 | + return repository.NewTaskRecordRepository(transactionContext) | ||
249 | +} |
@@ -4,20 +4,17 @@ import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | @@ -4,20 +4,17 @@ import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
4 | 4 | ||
5 | //保存员工填写评估内容 | 5 | //保存员工填写评估内容 |
6 | type SaveAssessInfoCommand struct { | 6 | type SaveAssessInfoCommand struct { |
7 | - AssessId int `json:"assessId"` // | ||
8 | - ExecutorId int `json:"executorId"` //填写人的id | ||
9 | - CompanyId int `json:"companyId"` //公司id | ||
10 | - AssessContent []domain.AssessContent `json:"assessContent"` | 7 | + AssessId int `json:"assessId" comment:"ID"` |
8 | + ExecutorId int `json:"executorId" comment:"填写人ID"` | ||
9 | + CompanyId int `json:"companyId" comment:"公司ID"` | ||
10 | + AssessContent []domain.AssessContent `json:"assessContent" comment:"填写内容"` | ||
11 | } | 11 | } |
12 | 12 | ||
13 | -//type AssessContent struct { | ||
14 | -// Category string `json:"category"` | ||
15 | -// Name string `json:"name"` | ||
16 | -// Value string `json:"value"` | ||
17 | -// Remark []RemarkText `json:"remark"` | ||
18 | -//} | ||
19 | -// | ||
20 | -//type RemarkText struct { | ||
21 | -// Title string `json:"title"` | ||
22 | -// RemarkText string `json:"remarkText"` | ||
23 | -//} | 13 | +// SaveSelfAssessCommand 保存自评填写内容 |
14 | +type SaveSelfAssessCommand struct { | ||
15 | + AssessId int `json:"assessId" comment:"ID"` | ||
16 | + ExecutorId int `json:"executorId" comment:"填写人ID"` | ||
17 | + CompanyId int `json:"companyId" comment:"公司ID"` | ||
18 | + AssessContent []domain.AssessContent `json:"assessContent" comment:"填写内容"` | ||
19 | + AssessTaskStages []domain.AssessTaskStage `json:"assessTaskStages" comment:"里程碑内容"` | ||
20 | +} |
@@ -2,11 +2,12 @@ package service | @@ -2,11 +2,12 @@ package service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role" | ||
6 | "sort" | 5 | "sort" |
7 | "strconv" | 6 | "strconv" |
8 | "time" | 7 | "time" |
9 | 8 | ||
9 | + service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role" | ||
10 | + | ||
10 | "github.com/linmadan/egglib-go/core/application" | 11 | "github.com/linmadan/egglib-go/core/application" |
11 | "github.com/linmadan/egglib-go/utils/tool_funs" | 12 | "github.com/linmadan/egglib-go/utils/tool_funs" |
12 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 13 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
@@ -373,7 +374,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf( | @@ -373,7 +374,7 @@ func (srv StaffAssessServeice) createStaffAssessSelf( | ||
373 | assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ | 374 | assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ |
374 | "transactionContext": transactionContext, | 375 | "transactionContext": transactionContext, |
375 | }) | 376 | }) |
376 | - beginDay := assessTemp.BeginTime.Format("2006-01-02") | 377 | + beginDay := assessTemp.BeginTime.Local().Format("2006-01-02") |
377 | _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf}) | 378 | _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSelf}) |
378 | if err != nil { | 379 | if err != nil { |
379 | return nil, err | 380 | return nil, err |
@@ -419,7 +420,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper( | @@ -419,7 +420,7 @@ func (srv StaffAssessServeice) createStaffAssessSupper( | ||
419 | assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ | 420 | assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{ |
420 | "transactionContext": transactionContext, | 421 | "transactionContext": transactionContext, |
421 | }) | 422 | }) |
422 | - beginDay := assessTemp.BeginTime.Format("2006-01-02") | 423 | + beginDay := assessTemp.BeginTime.Local().Format("2006-01-02") |
423 | _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper}) | 424 | _, assessListOld, err := assessRepo.Find(map[string]interface{}{"cycleId": assessTemp.CycleId, "beginDay": beginDay, "types": domain.AssessSuper}) |
424 | if err != nil { | 425 | if err != nil { |
425 | return nil, err | 426 | return nil, err |
@@ -1118,6 +1119,135 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | @@ -1118,6 +1119,135 @@ func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoComma | ||
1118 | }, nil | 1119 | }, nil |
1119 | } | 1120 | } |
1120 | 1121 | ||
1122 | +// SaveSelfAssess 提交自评评估内容 | ||
1123 | +func (srv StaffAssessServeice) SaveSelfAssess(in *command.SaveSelfAssessCommand) (map[string]interface{}, error) { | ||
1124 | + transactionContext, err := factory.ValidateStartTransaction(in) | ||
1125 | + if err != nil { | ||
1126 | + return nil, err | ||
1127 | + } | ||
1128 | + defer func() { | ||
1129 | + transactionContext.RollbackTransaction() | ||
1130 | + }() | ||
1131 | + | ||
1132 | + assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
1133 | + // 获取员工的评估 | ||
1134 | + assessData, err := assessReps.FindOne(map[string]interface{}{"id": in.AssessId}) | ||
1135 | + if err != nil { | ||
1136 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error()) | ||
1137 | + } | ||
1138 | + // 检查截止时间 | ||
1139 | + endTimeInt := assessData.EndTime.Unix() | ||
1140 | + if endTimeInt < time.Now().Unix() { | ||
1141 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "当前环节已过截止时间,提交后无法修改内容") | ||
1142 | + } | ||
1143 | + // 检查执行人 | ||
1144 | + if assessData.CompanyId != in.CompanyId || assessData.Executor.UserId != in.ExecutorId { | ||
1145 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "当前用户不是评估的执行人") | ||
1146 | + } | ||
1147 | + assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
1148 | + | ||
1149 | + //待更新的评估填写信息 | ||
1150 | + var assessContentList []*domain.StaffAssessContent | ||
1151 | + // 已完成 | ||
1152 | + _, assessContentList, err = assessContentRepo.Find(map[string]interface{}{"staffAssessId": assessData.Id}) | ||
1153 | + if err != nil { | ||
1154 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error()) | ||
1155 | + } | ||
1156 | + | ||
1157 | + if len(assessContentList) == 0 { | ||
1158 | + // 未完成获取评估内容 | ||
1159 | + assessContentList, err = srv.getAssessInfoUncompletedV2(transactionContext, assessData) | ||
1160 | + if err != nil { | ||
1161 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error()) | ||
1162 | + } | ||
1163 | + } | ||
1164 | + | ||
1165 | + // 处理提交上来的数据 | ||
1166 | + paramContentMap := map[string]domain.AssessContent{} | ||
1167 | + for i, v := range in.AssessContent { | ||
1168 | + key := fmt.Sprintf("%s-%s", v.Category, v.Name) | ||
1169 | + paramContentMap[key] = in.AssessContent[i] | ||
1170 | + } | ||
1171 | + //更新的评估填写信息 | ||
1172 | + for _, v := range assessContentList { | ||
1173 | + key := fmt.Sprintf("%s-%s", v.Category, v.Name) | ||
1174 | + item, ok := paramContentMap[key] | ||
1175 | + if !ok { | ||
1176 | + continue | ||
1177 | + } | ||
1178 | + if assessData.Types == domain.AssessSelf { | ||
1179 | + // 每日自评需要检查必填项 | ||
1180 | + if v.Required == domain.NodeRequiredYes && len(item.Value) == 0 { | ||
1181 | + return nil, application.ThrowError(application.BUSINESS_ERROR, v.Category+"-"+v.Name+":必填项") | ||
1182 | + } | ||
1183 | + } | ||
1184 | + | ||
1185 | + v.Value = item.Value | ||
1186 | + if len(item.Value) > 0 { | ||
1187 | + // 转换填入的评估值 | ||
1188 | + err = v.TransformValue() | ||
1189 | + if err != nil { | ||
1190 | + return nil, application.ThrowError(application.BUSINESS_ERROR, v.Category+"-"+v.Name+":"+err.Error()) | ||
1191 | + } | ||
1192 | + } | ||
1193 | + for ii := range v.Remark { | ||
1194 | + for _, vvv := range item.Remark { | ||
1195 | + if v.Remark[ii].Title == vvv.Title { | ||
1196 | + v.Remark[ii].RemarkText = vvv.RemarkText | ||
1197 | + break | ||
1198 | + } | ||
1199 | + } | ||
1200 | + } | ||
1201 | + } | ||
1202 | + | ||
1203 | + //保存信息 | ||
1204 | + for i := range assessContentList { | ||
1205 | + _, err = assessContentRepo.Save(assessContentList[i]) | ||
1206 | + if err != nil { | ||
1207 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估填写内容"+err.Error()) | ||
1208 | + } | ||
1209 | + } | ||
1210 | + assessData.Status = domain.StaffAssessCompleted | ||
1211 | + assessData.UpdatedAt = time.Now() | ||
1212 | + _, err = assessReps.Save(assessData) | ||
1213 | + if err != nil { | ||
1214 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error()) | ||
1215 | + } | ||
1216 | + | ||
1217 | + // 删除缓存 | ||
1218 | + cacheRepository := factory.CreateStaffAssessCacheRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
1219 | + if _, caches, err := cacheRepository.Find(map[string]interface{}{"assessId": assessData.Id, "limit": 1}); err != nil { | ||
1220 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1221 | + } else { | ||
1222 | + for i := range caches { | ||
1223 | + if err = cacheRepository.Remove(caches[i].Id); err != nil { | ||
1224 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1225 | + } | ||
1226 | + } | ||
1227 | + } | ||
1228 | + | ||
1229 | + if len(in.AssessTaskStages) > 0 { | ||
1230 | + tsIds := make([]int, 0) | ||
1231 | + for i := range in.AssessTaskStages { | ||
1232 | + tsId := in.AssessTaskStages[i].TaskStageId | ||
1233 | + if tsId > 0 { | ||
1234 | + tsIds = append(tsIds, tsId) | ||
1235 | + } | ||
1236 | + } | ||
1237 | + | ||
1238 | + } | ||
1239 | + // 里程碑记录 | ||
1240 | + //taskRecordRepository := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
1241 | + //taskRecordRepository.Find() | ||
1242 | + | ||
1243 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
1244 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1245 | + } | ||
1246 | + return map[string]interface{}{ | ||
1247 | + "assessId": assessData.Id, | ||
1248 | + }, nil | ||
1249 | +} | ||
1250 | + | ||
1121 | // 获取员工的上级是谁 | 1251 | // 获取员工的上级是谁 |
1122 | func (srv StaffAssessServeice) getStaffSuper(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) { | 1252 | func (srv StaffAssessServeice) getStaffSuper(transactionContext application.TransactionContext, targetUser domain.User) ([]*domain.User, error) { |
1123 | if targetUser.ParentId == 0 { | 1253 | if targetUser.ParentId == 0 { |
@@ -957,8 +957,7 @@ func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAsses | @@ -957,8 +957,7 @@ func (srv StaffAssessServeice) SelectAssessInviteUserV2(param *query.SelectAsses | ||
957 | } | 957 | } |
958 | 958 | ||
959 | // 获取未完成的员工评估内容 | 959 | // 获取未完成的员工评估内容 |
960 | -func (srv StaffAssessServeice) getAssessInfoUncompletedV2(transactionContext application.TransactionContext, | ||
961 | - assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) { | 960 | +func (srv StaffAssessServeice) getAssessInfoUncompletedV2(transactionContext application.TransactionContext, assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) { |
962 | evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{ | 961 | evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{ |
963 | "transactionContext": transactionContext, | 962 | "transactionContext": transactionContext, |
964 | }) | 963 | }) |
@@ -1390,7 +1390,7 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command. | @@ -1390,7 +1390,7 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command. | ||
1390 | TargetUserName: v.TargetUser.UserName, | 1390 | TargetUserName: v.TargetUser.UserName, |
1391 | TargetUserId: v.TargetUser.UserId, | 1391 | TargetUserId: v.TargetUser.UserId, |
1392 | EvaluationStatus: string(v.Status), | 1392 | EvaluationStatus: string(v.Status), |
1393 | - EndTime: v.EndTime.Format("2006-01-02 15:04:05"), | 1393 | + EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"), |
1394 | TotalScoreSelf: "", | 1394 | TotalScoreSelf: "", |
1395 | Department: "", | 1395 | Department: "", |
1396 | Position: "", | 1396 | Position: "", |
@@ -1420,7 +1420,7 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command. | @@ -1420,7 +1420,7 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command. | ||
1420 | result["endTime"] = "" | 1420 | result["endTime"] = "" |
1421 | result["uncompleted_number"] = 0 | 1421 | result["uncompleted_number"] = 0 |
1422 | if len(evaluationList) > 0 { | 1422 | if len(evaluationList) > 0 { |
1423 | - result["endTime"] = evaluationList[0].EndTime.Format("2006-01-02 15:04:05") | 1423 | + result["endTime"] = evaluationList[0].EndTime.Local().Format("2006-01-02 15:04:05") |
1424 | result["uncompleted_number"] = cntUn | 1424 | result["uncompleted_number"] = cntUn |
1425 | } | 1425 | } |
1426 | return result, nil | 1426 | return result, nil |
@@ -1801,10 +1801,9 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer | @@ -1801,10 +1801,9 @@ func (srv *SummaryEvaluationService) ListAllEvaluationFinish(param *command.Quer | ||
1801 | 1801 | ||
1802 | //获取评估列表信息 | 1802 | //获取评估列表信息 |
1803 | condition1 := map[string]interface{}{ | 1803 | condition1 := map[string]interface{}{ |
1804 | - "cycleId": param.CycleId, | ||
1805 | - "types": int(domain.EvaluationFinish), | ||
1806 | - "limit": limit, | ||
1807 | - "beginTime": time.Now(), | 1804 | + "cycleId": param.CycleId, |
1805 | + "types": int(domain.EvaluationFinish), | ||
1806 | + "limit": limit, | ||
1808 | } | 1807 | } |
1809 | if offset > 0 { | 1808 | if offset > 0 { |
1810 | condition1["offset"] = offset | 1809 | condition1["offset"] = offset |
@@ -4,12 +4,13 @@ import "time" | @@ -4,12 +4,13 @@ import "time" | ||
4 | 4 | ||
5 | // StaffAssessCache 填写评估数据(缓存暂未提交) | 5 | // StaffAssessCache 填写评估数据(缓存暂未提交) |
6 | type StaffAssessCache struct { | 6 | type StaffAssessCache struct { |
7 | - Id int64 `json:"id,string" comment:"ID"` | ||
8 | - AssessId int64 `json:"assessId,string" comment:"评估项ID"` | ||
9 | - AssessContent []AssessContent `json:"assessContent" comment:"评估项提交数据"` | ||
10 | - CreatedAt time.Time `json:"createdAt" comment:"创建时间"` | ||
11 | - UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` | ||
12 | - DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | 7 | + Id int64 `json:"id,string" comment:"ID"` |
8 | + AssessId int64 `json:"assessId,string" comment:"评估项ID"` | ||
9 | + AssessContent []AssessContent `json:"assessContent" comment:"评估项提交数据"` | ||
10 | + AssessTaskStages []AssessTaskStage `json:"assessTaskStages" comment:"里程碑内容"` | ||
11 | + CreatedAt time.Time `json:"createdAt" comment:"创建时间"` | ||
12 | + UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` | ||
13 | + DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | ||
13 | } | 14 | } |
14 | 15 | ||
15 | type AssessContent struct { | 16 | type AssessContent struct { |
@@ -24,6 +25,15 @@ type RemarkText struct { | @@ -24,6 +25,15 @@ type RemarkText struct { | ||
24 | RemarkText string `json:"remarkText"` | 25 | RemarkText string `json:"remarkText"` |
25 | } | 26 | } |
26 | 27 | ||
28 | +type AssessTaskStage struct { | ||
29 | + Category string `json:"category"` | ||
30 | + Name string `json:"name"` | ||
31 | + TaskStageId int `json:"taskStageId" comment:"里程碑ID"` | ||
32 | + Status TaskStageState `json:"status" comment:"里程碑完成情况"` | ||
33 | + AssistLevel int `json:"assistLevel" comment:"上级辅导情况"` | ||
34 | + AssistContent string `json:"assistContent" comment:"上级辅导内容"` | ||
35 | +} | ||
36 | + | ||
27 | type StaffAssessCacheRepository interface { | 37 | type StaffAssessCacheRepository interface { |
28 | Save(param *StaffAssessCache) (*StaffAssessCache, error) | 38 | Save(param *StaffAssessCache) (*StaffAssessCache, error) |
29 | Remove(id int64) error | 39 | Remove(id int64) error |
@@ -2,16 +2,34 @@ package domain | @@ -2,16 +2,34 @@ package domain | ||
2 | 2 | ||
3 | import "time" | 3 | import "time" |
4 | 4 | ||
5 | -// 任务反馈情况记录 | 5 | +const ( |
6 | + AssistLevel1 int = 1 // 未辅导 | ||
7 | + AssistLevel2 int = 2 // 已辅导-辅导对里程碑无作用 | ||
8 | + AssistLevel3 int = 3 // 已辅导-辅导对里程碑作用一般 | ||
9 | + AssistLevel4 int = 4 // 已辅导-辅导对里程碑作用很好 | ||
10 | +) | ||
11 | + | ||
12 | +// TaskRecord 任务反馈情况记录 | ||
6 | type TaskRecord struct { | 13 | type TaskRecord struct { |
7 | - Id int // id | ||
8 | - CreatedAt time.Time // | ||
9 | - UpdatedAt time.Time // | ||
10 | - StaffAssessId int // 每日评估的id | ||
11 | - TaskId int // 里程碑任务的id | ||
12 | - Name string // 任务名称 | ||
13 | - Alias string // 任务别名 | ||
14 | - TaskLeader TaskLeader // 里程碑完成情况填写人 | ||
15 | - Rating int // 上级辅导情况 | ||
16 | - RatingContent string // 上级辅导内容 | 14 | + Id int `json:"id,string" comment:"ID"` |
15 | + CompanyId int `json:"companyId,string" comment:"公司ID"` | ||
16 | + StaffAssessId int `json:"staffAssessId,string" comment:"每日评估的ID"` | ||
17 | + TaskId int `json:"taskId,string" comment:"里程碑任务的ID"` | ||
18 | + TaskName string `json:"taskName" comment:"任务名称"` | ||
19 | + TaskAlias string `json:"taskAlias" comment:"任务别名"` | ||
20 | + TaskLeader TaskLeader `json:"taskLeader" comment:"任务负责人"` | ||
21 | + AssistLevel int `json:"assistLevel" comment:"上级辅导情况"` | ||
22 | + AssistContent string `json:"assistContent" comment:"上级辅导内容"` | ||
23 | + TaskStages []TaskStage `json:"taskStages" comment:"里程碑列表"` | ||
24 | + TaskStageCheck TaskStage `json:"taskStageCheck" comment:"提交的里程碑"` | ||
25 | + CreatedAt time.Time `json:"createdAt" comment:"创建时间"` | ||
26 | + UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"` | ||
27 | + DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"` | ||
28 | +} | ||
29 | + | ||
30 | +type TaskRecordRepository interface { | ||
31 | + Insert(t *TaskRecord) (*TaskRecord, error) | ||
32 | + Remove(t *TaskRecord) (*TaskRecord, error) | ||
33 | + FindOne(queryOptions map[string]interface{}) (*TaskRecord, error) | ||
34 | + Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error) | ||
17 | } | 35 | } |
pkg/infrastructure/pg/models/task_record.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +// 任务阶段 | ||
9 | +type TaskRecord struct { | ||
10 | + tableName struct{} `comment:"评估项目" pg:"task_record"` | ||
11 | + Id int `comment:"ID" pg:"pk:id"` | ||
12 | + CompanyId int `comment:"公司ID"` | ||
13 | + StaffAssessId int `comment:"每日评估的ID"` | ||
14 | + TaskId int `comment:"里程碑任务的ID"` | ||
15 | + TaskName string `comment:"任务名称"` | ||
16 | + TaskAlias string `comment:"任务别名"` | ||
17 | + TaskLeader domain.TaskLeader `comment:"任务负责人"` | ||
18 | + AssistLevel int `comment:"上级辅导情况"` | ||
19 | + AssistContent string `comment:"上级辅导内容"` | ||
20 | + TaskStages []domain.TaskStage `comment:"里程碑列表"` | ||
21 | + TaskStageCheck domain.TaskStage `comment:"提交的里程碑"` | ||
22 | + CreatedAt time.Time `comment:"创建时间"` | ||
23 | + UpdatedAt time.Time `comment:"更新时间"` | ||
24 | + DeletedAt *time.Time `comment:"删除时间"` | ||
25 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "github.com/go-pg/pg/v10" | ||
7 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" | ||
11 | + "time" | ||
12 | +) | ||
13 | + | ||
14 | +type TaskRecordRepository struct { | ||
15 | + transactionContext *pgTransaction.TransactionContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewTaskRecordRepository(transactionContext *pgTransaction.TransactionContext) *TaskRecordRepository { | ||
19 | + return &TaskRecordRepository{transactionContext: transactionContext} | ||
20 | +} | ||
21 | + | ||
22 | +func (repo *TaskRecordRepository) TransformToDomain(m *models.TaskRecord) domain.TaskRecord { | ||
23 | + return domain.TaskRecord{ | ||
24 | + Id: m.Id, | ||
25 | + CompanyId: m.CompanyId, | ||
26 | + StaffAssessId: m.StaffAssessId, | ||
27 | + TaskId: m.TaskId, | ||
28 | + TaskName: m.TaskName, | ||
29 | + TaskAlias: m.TaskAlias, | ||
30 | + TaskLeader: m.TaskLeader, | ||
31 | + AssistLevel: m.AssistLevel, | ||
32 | + AssistContent: m.AssistContent, | ||
33 | + TaskStages: m.TaskStages, | ||
34 | + TaskStageCheck: m.TaskStageCheck, | ||
35 | + CreatedAt: m.CreatedAt.Local(), | ||
36 | + UpdatedAt: m.UpdatedAt.Local(), | ||
37 | + DeletedAt: m.DeletedAt, | ||
38 | + } | ||
39 | +} | ||
40 | + | ||
41 | +func (repo *TaskRecordRepository) TransformToModel(d *domain.TaskRecord) models.TaskRecord { | ||
42 | + return models.TaskRecord{ | ||
43 | + Id: d.Id, | ||
44 | + CompanyId: d.CompanyId, | ||
45 | + StaffAssessId: d.StaffAssessId, | ||
46 | + TaskId: d.TaskId, | ||
47 | + TaskName: d.TaskName, | ||
48 | + TaskAlias: d.TaskAlias, | ||
49 | + TaskLeader: d.TaskLeader, | ||
50 | + AssistLevel: d.AssistLevel, | ||
51 | + AssistContent: d.AssistContent, | ||
52 | + TaskStages: d.TaskStages, | ||
53 | + TaskStageCheck: d.TaskStageCheck, | ||
54 | + CreatedAt: d.CreatedAt, | ||
55 | + UpdatedAt: d.UpdatedAt, | ||
56 | + DeletedAt: d.DeletedAt, | ||
57 | + } | ||
58 | +} | ||
59 | + | ||
60 | +func (repo *TaskRecordRepository) nextIdentify() (int64, error) { | ||
61 | + return utils.NewSnowflakeId() | ||
62 | +} | ||
63 | + | ||
64 | +func (repo *TaskRecordRepository) Insert(d *domain.TaskRecord) (*domain.TaskRecord, error) { | ||
65 | + var isCreate = d.Id == 0 | ||
66 | + if isCreate { | ||
67 | + id, err := repo.nextIdentify() | ||
68 | + if err != nil { | ||
69 | + return d, err | ||
70 | + } | ||
71 | + d.Id = int(id) | ||
72 | + d.CreatedAt = time.Now() | ||
73 | + d.UpdatedAt = d.CreatedAt | ||
74 | + } else { | ||
75 | + d.UpdatedAt = time.Now() | ||
76 | + } | ||
77 | + m := repo.TransformToModel(d) | ||
78 | + tx := repo.transactionContext.PgTx | ||
79 | + var err error | ||
80 | + if isCreate { | ||
81 | + _, err = tx.Model(&m).Returning("id").Insert() | ||
82 | + } else { | ||
83 | + _, err = tx.Model(&m).Returning("id").WherePK().Update() // 更新和删除必须增加条件 | ||
84 | + } | ||
85 | + if err != nil { | ||
86 | + return nil, err | ||
87 | + } | ||
88 | + d.Id = m.Id | ||
89 | + return d, nil | ||
90 | +} | ||
91 | + | ||
92 | +func (repo *TaskRecordRepository) Remove(d *domain.TaskRecord) (*domain.TaskRecord, error) { | ||
93 | + tx := repo.transactionContext.PgTx | ||
94 | + nowTime := time.Now() | ||
95 | + m := repo.TransformToModel(d) | ||
96 | + m.DeletedAt = &nowTime | ||
97 | + if _, err := tx.Model(&m).WherePK().Update(); err != nil { | ||
98 | + return d, err | ||
99 | + } | ||
100 | + return d, nil | ||
101 | +} | ||
102 | + | ||
103 | +func (repo *TaskRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskRecord, error) { | ||
104 | + tx := repo.transactionContext.PgTx | ||
105 | + m := new(models.TaskRecord) | ||
106 | + query := tx.Model(m) | ||
107 | + query.Where("deleted_at isnull") | ||
108 | + if id, ok := queryOptions["id"]; ok { | ||
109 | + query.Where("id=?", id) | ||
110 | + } | ||
111 | + if err := query.First(); err != nil { | ||
112 | + if errors.Is(err, pg.ErrNoRows) { | ||
113 | + return nil, fmt.Errorf("没有此资源") | ||
114 | + } else { | ||
115 | + return nil, err | ||
116 | + } | ||
117 | + } | ||
118 | + u := repo.TransformToDomain(m) | ||
119 | + return &u, nil | ||
120 | +} | ||
121 | + | ||
122 | +func (repo *TaskRecordRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskRecord, error) { | ||
123 | + tx := repo.transactionContext.PgTx | ||
124 | + var m []*models.TaskRecord | ||
125 | + query := tx.Model(&m).Where("deleted_at isnull") | ||
126 | + | ||
127 | + if v, ok := queryOptions["ids"]; ok { | ||
128 | + query.Where("id in(?)", pg.In(v)) | ||
129 | + } | ||
130 | + | ||
131 | + if v, ok := queryOptions["notId"]; ok { | ||
132 | + query.Where("id != ?", v) | ||
133 | + } | ||
134 | + | ||
135 | + if v, ok := queryOptions["name"].(string); ok && len(v) > 0 { | ||
136 | + query.Where("name LIKE ?", v) | ||
137 | + } | ||
138 | + | ||
139 | + if v, ok := queryOptions["companyId"]; ok { | ||
140 | + query.Where("company_id = ?", v) | ||
141 | + } | ||
142 | + | ||
143 | + //if v, ok := queryOptions["state"]; ok && v.(int) >= 0 { | ||
144 | + // query.Where("state = ?", v) | ||
145 | + //} | ||
146 | + | ||
147 | + if v, ok := queryOptions["limit"].(int64); ok { | ||
148 | + query.Limit(int(v)) | ||
149 | + } | ||
150 | + if v, ok := queryOptions["offset"].(int64); ok { | ||
151 | + query.Offset(int(v)) | ||
152 | + } | ||
153 | + | ||
154 | + //// 按创建时间降序 | ||
155 | + //query.Order("created_at DESC") | ||
156 | + | ||
157 | + count, err := query.SelectAndCount() | ||
158 | + if err != nil { | ||
159 | + return 0, nil, err | ||
160 | + } | ||
161 | + var arrays []*domain.TaskRecord | ||
162 | + for _, v := range m { | ||
163 | + d := repo.TransformToDomain(v) | ||
164 | + arrays = append(arrays, &d) | ||
165 | + } | ||
166 | + return count, arrays, nil | ||
167 | +} |
-
请 注册 或 登录 后发表评论