default.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. package db
  2. import (
  3. "context"
  4. "fmt"
  5. "reflect"
  6. "strings"
  7. "youngee_m_api/consts"
  8. "youngee_m_api/model/common_model"
  9. "youngee_m_api/model/gorm_model"
  10. "youngee_m_api/model/http_model"
  11. "youngee_m_api/pack"
  12. "youngee_m_api/util"
  13. "github.com/caixw/lib.go/conv"
  14. "github.com/sirupsen/logrus"
  15. )
  16. func CountDefaultNum(ctx context.Context) (error, *http_model.CountNumOfDefaultsResponse) {
  17. db := GetReadDB(ctx)
  18. var contractInfos []gorm_model.YoungeeContractInfo
  19. err := db.Debug().Model(gorm_model.YoungeeContractInfo{}).Where("default_status = 3").Find(&contractInfos).Error
  20. if err != nil {
  21. return err, nil
  22. }
  23. DraftDefaultNum, ScriptDefaultNum, LinkDefaultNum, DataDefaultNum := 0, 0, 0, 0
  24. for _, contractInfo := range contractInfos {
  25. if contractInfo.BreakType == 1 {
  26. ScriptDefaultNum++
  27. } else if contractInfo.BreakType == 2 {
  28. DraftDefaultNum++
  29. } else if contractInfo.BreakType == 3 {
  30. LinkDefaultNum++
  31. } else {
  32. DataDefaultNum++
  33. }
  34. }
  35. data := &http_model.CountNumOfDefaultsResponse{}
  36. data.ScriptDefaultNum = int32(ScriptDefaultNum)
  37. data.DraftDefaultNum = int32(DraftDefaultNum)
  38. data.LinkDefaultNum = int32(LinkDefaultNum)
  39. data.DataDefaultNum = int32(DataDefaultNum)
  40. return nil, data
  41. }
  42. func BreachPending(ctx context.Context, pageSize, pageNum int32, req *http_model.BreachPendingRequest) (*http_model.BreachPendingData, error) {
  43. db := GetReadDB(ctx)
  44. var contractInfos []*gorm_model.YoungeeContractInfo
  45. db = db.Model(gorm_model.YoungeeContractInfo{}).Where("default_status = 3")
  46. if req.DefaultType == 1 || req.DefaultType == 2 {
  47. db = db.Where("break_type = 1 OR break_type = 2")
  48. } else {
  49. db = db.Where("break_type = ?", req.DefaultType)
  50. }
  51. if req.TaskId != 0 {
  52. db = db.Where("task_id = ?", req.TaskId)
  53. }
  54. var findProjectIds []int64
  55. if req.ProjectName != "" {
  56. db1 := GetReadDB(ctx)
  57. db1.Model(gorm_model.ProjectInfo{}).Select("project_id").Where("project_name = ?", req.ProjectName).Find(&findProjectIds)
  58. var findTaskIds []int
  59. db2 := GetReadDB(ctx)
  60. db2.Model(gorm_model.YoungeeTaskInfo{}).Select("task_id").Where("project_id IN ?", findProjectIds).Find(&findTaskIds)
  61. db = db.Where("task_id IN ?", findTaskIds)
  62. }
  63. // 查询总数
  64. var total int64
  65. if err := db.Count(&total).Error; err != nil {
  66. logrus.WithContext(ctx).Errorf("[BreachPending] error query mysql total, err:%+v", err)
  67. return nil, err
  68. }
  69. // 查询该页数据
  70. limit := pageSize
  71. offset := pageSize * pageNum // assert pageNum start with 0
  72. err := db.Order("terminate_at").Limit(int(limit)).Offset(int(offset)).Find(&contractInfos).Error
  73. if err != nil {
  74. logrus.WithContext(ctx).Errorf("[BreachPending] error query mysql total, err:%+v", err)
  75. return nil, err
  76. }
  77. var taskIds []int
  78. for _, contractInfo := range contractInfos {
  79. taskIds = append(taskIds, contractInfo.TaskID)
  80. }
  81. taskIds = util.RemoveIntRepByMap(taskIds)
  82. taskIdToProjectMap := make(map[int]int)
  83. taskIdToTalentIdMap := make(map[int]string)
  84. taskIdToTaskInfoMap := make(map[int]gorm_model.YoungeeTaskInfo)
  85. var projectIds []int
  86. for _, taskId := range taskIds {
  87. db1 := GetReadDB(ctx)
  88. var taskInfo gorm_model.YoungeeTaskInfo
  89. db1.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Find(&taskInfo)
  90. taskIdToProjectMap[taskId] = taskInfo.ProjectId
  91. taskIdToTalentIdMap[taskId] = taskInfo.TalentId
  92. taskIdToTaskInfoMap[taskId] = taskInfo
  93. projectIds = append(projectIds, taskInfo.ProjectId)
  94. }
  95. //fmt.Println("TaskID:", taskIds)
  96. //fmt.Println("projectIds:", projectIds)
  97. //fmt.Println("taskIdToProjectMap:", taskIdToProjectMap)
  98. //fmt.Println("taskIdToTalentIdMap:", taskIdToTalentIdMap)
  99. projectIds = util.RemoveIntRepByMap(projectIds)
  100. var enterpriseIds []int64
  101. projectIdToProjectInfoMap := make(map[int64]gorm_model.ProjectInfo)
  102. for _, projectId := range projectIds {
  103. db1 := GetReadDB(ctx)
  104. projectInfo := gorm_model.ProjectInfo{}
  105. db1.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", projectId).Find(&projectInfo)
  106. projectIdToProjectInfoMap[projectInfo.ProjectID] = projectInfo
  107. enterpriseIds = append(enterpriseIds, projectInfo.EnterpriseID)
  108. }
  109. enterpriseIds = util.RemoveRepByMap(enterpriseIds)
  110. //fmt.Println("enterpriseIds:", enterpriseIds)
  111. enterpriseIdToUserId := make(map[int64]int64)
  112. var userIds []int64
  113. for _, enterpriseId := range enterpriseIds {
  114. db1 := GetReadDB(ctx)
  115. var userId int64
  116. db1.Model(gorm_model.Enterprise{}).Select("user_id").Where("enterprise_id = ?", enterpriseId).Find(&userId)
  117. enterpriseIdToUserId[enterpriseId] = userId
  118. userIds = append(userIds, userId)
  119. }
  120. //fmt.Println("projectIdToProjectInfoMap:", projectIdToProjectInfoMap)
  121. //fmt.Println("enterpriseIdToUserId:", enterpriseIdToUserId)
  122. //fmt.Println("userIds:", userIds)
  123. userIdToUserPhone := make(map[int64]string)
  124. for _, userId := range userIds {
  125. db1 := GetReadDB(ctx)
  126. var userPhone string
  127. db1.Model(gorm_model.YounggeeUser{}).Select("phone").Where("id = ?", userId).Find(&userPhone)
  128. userIdToUserPhone[userId] = userPhone
  129. }
  130. //fmt.Println("userIdToUserPhone:", userIdToUserPhone)
  131. talentIdToTalentPhoneMap := make(map[string]string)
  132. for _, v := range taskIdToTalentIdMap {
  133. if len(talentIdToTalentPhoneMap) == 0 {
  134. db1 := GetReadDB(ctx)
  135. var talentPhoneNumber string
  136. db1.Model(gorm_model.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", v).Find(&talentPhoneNumber)
  137. talentIdToTalentPhoneMap[v] = talentPhoneNumber
  138. }
  139. if _, ok := talentIdToTalentPhoneMap[v]; !ok {
  140. db1 := GetReadDB(ctx)
  141. var talentPhoneNumber string
  142. db1.Model(gorm_model.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", v).Find(&talentPhoneNumber)
  143. talentIdToTalentPhoneMap[v] = talentPhoneNumber
  144. }
  145. }
  146. taskIdToDefaultInfo := make(map[int]string)
  147. if req.DefaultType == 4 {
  148. for _, taskId := range taskIds {
  149. db1 := GetReadDB(ctx)
  150. var link string
  151. db1.Debug().Model(gorm_model.YounggeeLinkInfo{}).Select("link_url").Where("task_id = ? AND is_ok = 1", taskId).Find(&link)
  152. taskIdToDefaultInfo[taskId] = link
  153. }
  154. }
  155. //fmt.Println("talentIdToTalentPhoneMap:", talentIdToTalentPhoneMap)
  156. var BreachPendingPreviews []*http_model.BreachPendingPreview
  157. for _, contractInfo := range contractInfos {
  158. BreachPendingPreview := new(http_model.BreachPendingPreview)
  159. BreachPendingPreview.ContractId = int32(contractInfo.ContractID)
  160. BreachPendingPreview.ProjectId = int32(taskIdToProjectMap[contractInfo.TaskID])
  161. BreachPendingPreview.UserId = int32(enterpriseIdToUserId[projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].EnterpriseID])
  162. BreachPendingPreview.ProjectName = projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].ProjectName
  163. BreachPendingPreview.UserPhone = userIdToUserPhone[enterpriseIdToUserId[projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].EnterpriseID]]
  164. BreachPendingPreview.TaskId = int32(contractInfo.TaskID)
  165. BreachPendingPreview.TalentId = taskIdToTalentIdMap[contractInfo.TaskID]
  166. BreachPendingPreview.TalentPhone = talentIdToTalentPhoneMap[taskIdToTalentIdMap[contractInfo.TaskID]]
  167. BreachPendingPreview.LinkInfo = taskIdToDefaultInfo[contractInfo.TaskID]
  168. BreachPendingPreview.Price = taskIdToTaskInfoMap[contractInfo.TaskID].AllPayment
  169. BreachPendingPreview.SettlementAmount = taskIdToTaskInfoMap[contractInfo.TaskID].SettleAmount
  170. BreachPendingPreview.DefaultAt = conv.MustString(contractInfo.BreakAt, "")[0:19]
  171. BreachPendingPreview.TerminateAt = conv.MustString(contractInfo.TerminateAt, "")[0:19]
  172. BreachPendingPreviews = append(BreachPendingPreviews, BreachPendingPreview)
  173. }
  174. var BreachPendingData http_model.BreachPendingData
  175. BreachPendingData.BreachPendingPreview = BreachPendingPreviews
  176. BreachPendingData.Total = total
  177. return &BreachPendingData, nil
  178. }
  179. func ContractBreach(ctx context.Context, req *http_model.ContractBreachRequest) error {
  180. db := GetReadDB(ctx)
  181. var breakType int
  182. db.Model(gorm_model.YoungeeContractInfo{}).Select("break_type").Where("contract_id IN ?", req.ContractIds).Find(&breakType)
  183. err := db.Debug().Where("contract_id IN ?", req.ContractIds).Updates(&gorm_model.YoungeeContractInfo{DefaultStatus: int(req.DefaultStatus)}).Error
  184. if err != nil {
  185. logrus.WithContext(ctx).Errorf("[BreachPending] error query mysql total, err:%+v", err)
  186. return err
  187. }
  188. var taskId int
  189. db.Model(gorm_model.YoungeeContractInfo{}).Select("task_id").Where("contract_id IN ?", req.ContractIds).Find(&taskId)
  190. if req.DefaultStatus == 5 {
  191. db1 := GetReadDB(ctx)
  192. var projectId, autoDefaultId, feeForm int
  193. db1.Model(gorm_model.YoungeeTaskInfo{}).Select("project_id").Where("task_id = ?", taskId).Find(&projectId)
  194. db2 := GetReadDB(ctx)
  195. db2.Model(gorm_model.ProjectInfo{}).Select("auto_default_id").Where("project_id = ?", projectId).Find(&autoDefaultId)
  196. var rateInfo gorm_model.InfoAutoDefaultHandle
  197. db3 := GetReadDB(ctx)
  198. db3.Model(gorm_model.InfoAutoDefaultHandle{}).Where("auto_default_id = ?", autoDefaultId).Find(&rateInfo)
  199. db4 := GetReadDB(ctx)
  200. db4.Model(gorm_model.YoungeeTaskInfo{}).Select("fee_form").Where("task_id = ?", taskId).Find(&feeForm)
  201. if feeForm == 1 {
  202. if breakType == 1 {
  203. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  204. ErrBreakRate: rateInfo.ScriptReplaceNotUpload, CurDefaultType: 2})
  205. } else if breakType == 2 {
  206. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  207. ErrBreakRate: rateInfo.SketchReplaceNotUpload, CurDefaultType: 4})
  208. } else if breakType == 3 {
  209. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  210. ErrBreakRate: rateInfo.LinkReplaceNotUpload, CurDefaultType: 6})
  211. } else if breakType == 4 {
  212. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  213. ErrBreakRate: rateInfo.DataReplaceNotUpload, CurDefaultType: 8})
  214. }
  215. } else {
  216. if breakType == 1 {
  217. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  218. ErrBreakRate: rateInfo.ScriptOtherNotUpload, CurDefaultType: 2})
  219. } else if breakType == 2 {
  220. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  221. ErrBreakRate: rateInfo.SketchOtherNotUpload, CurDefaultType: 4})
  222. } else if breakType == 3 {
  223. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  224. ErrBreakRate: rateInfo.LinkOtherNotUpload, CurDefaultType: 6})
  225. } else if breakType == 4 {
  226. db4.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{
  227. ErrBreakRate: rateInfo.DataOtherNotUpload, CurDefaultType: 8})
  228. }
  229. }
  230. }
  231. return nil
  232. }
  233. func GetSketchInfoByTaskId(ctx context.Context, request *http_model.GetSketchInfoByTaskIdRequest) (*http_model.SketchInfoResponse, error) {
  234. db := GetReadDB(ctx)
  235. var sketchInfo gorm_model.YounggeeSketchInfo
  236. db.Debug().Model(gorm_model.YounggeeSketchInfo{}).Where("task_id = ? AND is_ok = 1", request.TaskId).Find(&sketchInfo)
  237. db2 := GetReadDB(ctx)
  238. sketchPhotoInfo := gorm_model.YounggeeSketchPhoto{}
  239. db2.Debug().Model(gorm_model.YounggeeSketchPhoto{}).Where("sketch_id = ?", sketchInfo.SketchID).Find(&sketchPhotoInfo)
  240. data := new(http_model.SketchInfoResponse)
  241. data.Type = int32(sketchPhotoInfo.Symbol)
  242. data.PhotoUrl = sketchPhotoInfo.PhotoUrl
  243. data.Content = sketchInfo.Content
  244. data.Title = sketchInfo.Title
  245. return data, nil
  246. }
  247. func BreachHandled(ctx context.Context, pageSize, pageNum int32, req *http_model.BreachHandledRequest, conditions *common_model.BreachHandledConditions) (*http_model.BreachHandledData, error) {
  248. db := GetReadDB(ctx)
  249. var contractInfos []*gorm_model.YoungeeContractInfo
  250. db = db.Model(gorm_model.YoungeeContractInfo{}).Where("default_status = 4 OR default_status = 5")
  251. // 根据Project条件过滤
  252. conditionType := reflect.TypeOf(conditions).Elem()
  253. conditionValue := reflect.ValueOf(conditions).Elem()
  254. for i := 0; i < conditionType.NumField(); i++ {
  255. field := conditionType.Field(i)
  256. tag := field.Tag.Get("condition")
  257. value := conditionValue.FieldByName(field.Name)
  258. if !util.IsBlank(value) {
  259. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  260. }
  261. }
  262. if req.TaskId != 0 {
  263. db = db.Where("task_id = ?", req.TaskId)
  264. }
  265. var findProjectIds []int64
  266. if req.ProjectName != "" {
  267. db1 := GetReadDB(ctx)
  268. db1.Model(gorm_model.ProjectInfo{}).Select("project_id").Where("project_name = ?", req.ProjectName).Find(&findProjectIds)
  269. var findTaskIds []int
  270. db2 := GetReadDB(ctx)
  271. db2.Model(gorm_model.YoungeeTaskInfo{}).Select("task_id").Where("project_id IN ?", findProjectIds).Find(&findTaskIds)
  272. db = db.Where("task_id IN ?", findTaskIds)
  273. }
  274. // 查询总数
  275. var total int64
  276. if err := db.Count(&total).Error; err != nil {
  277. logrus.WithContext(ctx).Errorf("[BreachHandled] error query mysql total, err:%+v", err)
  278. return nil, err
  279. }
  280. // 查询该页数据
  281. limit := pageSize
  282. offset := pageSize * pageNum // assert pageNum start with 0
  283. err := db.Order("terminate_at").Limit(int(limit)).Offset(int(offset)).Find(&contractInfos).Error
  284. if err != nil {
  285. logrus.WithContext(ctx).Errorf("[BreachHandled] error query mysql total, err:%+v", err)
  286. return nil, err
  287. }
  288. var taskIds []int
  289. for _, contractInfo := range contractInfos {
  290. taskIds = append(taskIds, contractInfo.TaskID)
  291. }
  292. taskIds = util.RemoveIntRepByMap(taskIds)
  293. taskIdToProjectMap := make(map[int]int)
  294. taskIdToTalentIdMap := make(map[int]string)
  295. taskIdToTaskInfoMap := make(map[int]gorm_model.YoungeeTaskInfo)
  296. var projectIds []int
  297. for _, taskId := range taskIds {
  298. db1 := GetReadDB(ctx)
  299. var taskInfo gorm_model.YoungeeTaskInfo
  300. db1.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Find(&taskInfo)
  301. taskIdToProjectMap[taskId] = taskInfo.ProjectId
  302. taskIdToTalentIdMap[taskId] = taskInfo.TalentId
  303. taskIdToTaskInfoMap[taskId] = taskInfo
  304. projectIds = append(projectIds, taskInfo.ProjectId)
  305. }
  306. //fmt.Println("TaskID:", taskIds)
  307. //fmt.Println("projectIds:", projectIds)
  308. //fmt.Println("taskIdToProjectMap:", taskIdToProjectMap)
  309. //fmt.Println("taskIdToTalentIdMap:", taskIdToTalentIdMap)
  310. projectIds = util.RemoveIntRepByMap(projectIds)
  311. var enterpriseIds []int64
  312. projectIdToProjectInfoMap := make(map[int64]gorm_model.ProjectInfo)
  313. for _, projectId := range projectIds {
  314. db1 := GetReadDB(ctx)
  315. projectInfo := gorm_model.ProjectInfo{}
  316. db1.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", projectId).Find(&projectInfo)
  317. projectIdToProjectInfoMap[projectInfo.ProjectID] = projectInfo
  318. enterpriseIds = append(enterpriseIds, projectInfo.EnterpriseID)
  319. }
  320. enterpriseIds = util.RemoveRepByMap(enterpriseIds)
  321. //fmt.Println("enterpriseIds:", enterpriseIds)
  322. enterpriseIdToUserId := make(map[int64]int64)
  323. var userIds []int64
  324. for _, enterpriseId := range enterpriseIds {
  325. db1 := GetReadDB(ctx)
  326. var userId int64
  327. db1.Model(gorm_model.Enterprise{}).Select("user_id").Where("enterprise_id = ?", enterpriseId).Find(&userId)
  328. enterpriseIdToUserId[enterpriseId] = userId
  329. userIds = append(userIds, userId)
  330. }
  331. //fmt.Println("projectIdToProjectInfoMap:", projectIdToProjectInfoMap)
  332. //fmt.Println("enterpriseIdToUserId:", enterpriseIdToUserId)
  333. //fmt.Println("userIds:", userIds)
  334. userIdToUserPhone := make(map[int64]string)
  335. for _, userId := range userIds {
  336. db1 := GetReadDB(ctx)
  337. var userPhone string
  338. db1.Model(gorm_model.YounggeeUser{}).Select("phone").Where("id = ?", userId).Find(&userPhone)
  339. userIdToUserPhone[userId] = userPhone
  340. }
  341. //fmt.Println("userIdToUserPhone:", userIdToUserPhone)
  342. talentIdToTalentPhoneMap := make(map[string]string)
  343. for _, v := range taskIdToTalentIdMap {
  344. if len(talentIdToTalentPhoneMap) == 0 {
  345. db1 := GetReadDB(ctx)
  346. var talentPhoneNumber string
  347. db1.Model(gorm_model.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", v).Find(&talentPhoneNumber)
  348. talentIdToTalentPhoneMap[v] = talentPhoneNumber
  349. }
  350. if _, ok := talentIdToTalentPhoneMap[v]; !ok {
  351. db1 := GetReadDB(ctx)
  352. var talentPhoneNumber string
  353. db1.Model(gorm_model.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", v).Find(&talentPhoneNumber)
  354. talentIdToTalentPhoneMap[v] = talentPhoneNumber
  355. }
  356. }
  357. //fmt.Println("talentIdToTalentPhoneMap:", talentIdToTalentPhoneMap)
  358. var BreachHandledPreviews []*http_model.BreachHandledPreview
  359. for _, contractInfo := range contractInfos {
  360. BreachHandledPreview := new(http_model.BreachHandledPreview)
  361. BreachHandledPreview.ContractId = int32(contractInfo.ContractID)
  362. BreachHandledPreview.ProjectId = int32(taskIdToProjectMap[contractInfo.TaskID])
  363. BreachHandledPreview.UserId = int32(enterpriseIdToUserId[projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].EnterpriseID])
  364. BreachHandledPreview.ProjectName = projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].ProjectName
  365. BreachHandledPreview.UserPhone = userIdToUserPhone[enterpriseIdToUserId[projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].EnterpriseID]]
  366. BreachHandledPreview.TaskId = int32(contractInfo.TaskID)
  367. BreachHandledPreview.TalentId = taskIdToTalentIdMap[contractInfo.TaskID]
  368. BreachHandledPreview.TalentPhone = talentIdToTalentPhoneMap[taskIdToTalentIdMap[contractInfo.TaskID]]
  369. BreachHandledPreview.TerminateReason = consts.GetBreakType(contractInfo.BreakType)
  370. BreachHandledPreview.HandleResult = consts.GetHandleResult(contractInfo.DefaultStatus)
  371. BreachHandledPreview.HandleAt = conv.MustString(contractInfo.HandleAt, "")[0:19]
  372. BreachHandledPreviews = append(BreachHandledPreviews, BreachHandledPreview)
  373. }
  374. var BreachHandledData http_model.BreachHandledData
  375. BreachHandledData.BreachHandledPreview = BreachHandledPreviews
  376. BreachHandledData.Total = total
  377. return &BreachHandledData, nil
  378. }
  379. func GetTaskDefaultReviewList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskDefaultReviewInfo, int64, error) {
  380. db := GetReadDB(ctx)
  381. // 查询Task表信息
  382. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  383. // 根据Project条件过滤
  384. conditionType := reflect.TypeOf(conditions).Elem()
  385. conditionValue := reflect.ValueOf(conditions).Elem()
  386. var platform_nickname string = ""
  387. for i := 0; i < conditionType.NumField(); i++ {
  388. field := conditionType.Field(i)
  389. tag := field.Tag.Get("condition")
  390. value := conditionValue.FieldByName(field.Name)
  391. if tag == "default_status" {
  392. fmt.Printf("default %+v", value.Interface() == int64(0))
  393. if value.Interface() == int64(0) {
  394. db = db.Where("cur_default_type = 1")
  395. } else if value.Interface() == int64(1) {
  396. db = db.Where("cur_default_type = 3")
  397. } else if value.Interface() == int64(2) {
  398. db = db.Where("cur_default_type = 5")
  399. }
  400. continue
  401. } else if !util.IsBlank(value) {
  402. if tag == "platform_nickname" {
  403. platform_nickname = fmt.Sprintf("%v", value.Interface())
  404. continue
  405. } else if tag == "project_id" || tag == "strategy_id" {
  406. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  407. }
  408. }
  409. }
  410. var taskInfos []gorm_model.YoungeeTaskInfo
  411. db = db.Model(gorm_model.YoungeeTaskInfo{})
  412. // 查询总数
  413. var totalTask int64
  414. if err := db.Count(&totalTask).Error; err != nil {
  415. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  416. return nil, 0, err
  417. }
  418. db.Order("task_id").Find(&taskInfos)
  419. // 查询任务id
  420. var taskIds []int
  421. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  422. for _, taskInfo := range taskInfos {
  423. taskIds = append(taskIds, taskInfo.TaskId)
  424. taskMap[taskInfo.TaskId] = taskInfo
  425. }
  426. db1 := GetReadDB(ctx)
  427. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  428. var DefaultReviewInfos []gorm_model.YoungeeContractInfo
  429. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  430. err := db1.Find(&DefaultReviewInfos).Error
  431. if err != nil {
  432. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  433. return nil, 0, err
  434. }
  435. DefaultReviewMap := make(map[int]gorm_model.YoungeeContractInfo)
  436. for _, DefaultReviewInfo := range DefaultReviewInfos {
  437. DefaultReviewMap[conv.MustInt(DefaultReviewInfo.TaskID, 0)] = DefaultReviewInfo
  438. }
  439. // 查询总数
  440. var totalDefaultReview int64
  441. if err := db1.Count(&totalDefaultReview).Error; err != nil {
  442. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  443. return nil, 0, err
  444. }
  445. // 查询该页数据
  446. limit := pageSize
  447. offset := pageSize * pageNum // assert pageNum start with 0
  448. err = db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  449. if err != nil {
  450. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  451. return nil, 0, err
  452. }
  453. var TaskDefaultReviews []*http_model.TaskDefaultReview
  454. var taskDefaultReviews []*http_model.TaskDefaultReviewInfo
  455. var newTaskDefaultReviews []*http_model.TaskDefaultReviewInfo
  456. for _, taskId := range taskIds {
  457. TaskDefaultReview := new(http_model.TaskDefaultReview)
  458. TaskDefaultReview.Talent = taskMap[taskId]
  459. TaskDefaultReview.Default = DefaultReviewMap[taskId]
  460. TaskDefaultReviews = append(TaskDefaultReviews, TaskDefaultReview)
  461. }
  462. taskDefaultReviews = pack.TaskDefaultReviewToTaskInfo(TaskDefaultReviews)
  463. for _, v := range taskDefaultReviews {
  464. if platform_nickname == "" {
  465. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  466. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  467. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  468. } else if strings.Contains(conv.MustString(v.TaskID, ""), platform_nickname) {
  469. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  470. } else {
  471. totalTask--
  472. }
  473. }
  474. return newTaskDefaultReviews, totalTask, nil
  475. }
  476. func GetTaskDefaultDataList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskDefaultDataInfo, int64, error) {
  477. db := GetReadDB(ctx)
  478. // 查询Task表信息
  479. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  480. // 根据Project条件过滤
  481. conditionType := reflect.TypeOf(conditions).Elem()
  482. conditionValue := reflect.ValueOf(conditions).Elem()
  483. var platform_nickname string = ""
  484. for i := 0; i < conditionType.NumField(); i++ {
  485. field := conditionType.Field(i)
  486. tag := field.Tag.Get("condition")
  487. value := conditionValue.FieldByName(field.Name)
  488. if tag == "default_status" {
  489. if value.Interface() == int64(3) {
  490. db = db.Where("cur_default_type = 7")
  491. }
  492. continue
  493. } else if !util.IsBlank(value) {
  494. if tag == "platform_nickname" {
  495. platform_nickname = fmt.Sprintf("%v", value.Interface())
  496. continue
  497. } else if tag == "project_id" || tag == "strategy_id" {
  498. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  499. }
  500. }
  501. }
  502. var taskInfos []gorm_model.YoungeeTaskInfo
  503. db = db.Model(gorm_model.YoungeeTaskInfo{})
  504. // 查询总数
  505. var totalTask int64
  506. if err := db.Count(&totalTask).Error; err != nil {
  507. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  508. return nil, 0, err
  509. }
  510. db.Order("task_id").Find(&taskInfos)
  511. // 查询任务id
  512. var taskIds []int
  513. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  514. for _, taskInfo := range taskInfos {
  515. taskIds = append(taskIds, taskInfo.TaskId)
  516. taskMap[taskInfo.TaskId] = taskInfo
  517. }
  518. db1 := GetReadDB(ctx)
  519. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  520. var DefaultDataInfos []gorm_model.YoungeeContractInfo
  521. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  522. err := db1.Find(&DefaultDataInfos).Error
  523. DefaultDataMap := make(map[int]gorm_model.YoungeeContractInfo)
  524. for _, DefaultDataInfo := range DefaultDataInfos {
  525. DefaultDataMap[conv.MustInt(DefaultDataInfo.TaskID, 0)] = DefaultDataInfo
  526. }
  527. var LinkInfos []gorm_model.YounggeeLinkInfo
  528. db2 := GetReadDB(ctx)
  529. db2 = db2.Model(gorm_model.YounggeeLinkInfo{}).Where("task_id IN ? AND is_ok = 1", taskIds).Find(&LinkInfos)
  530. LinkMap := make(map[int]gorm_model.YounggeeLinkInfo)
  531. for _, LinkInfo := range LinkInfos {
  532. LinkMap[conv.MustInt(LinkInfo.TaskID, 0)] = LinkInfo
  533. }
  534. // 查询总数
  535. var totalDefaultData int64
  536. if err := db2.Count(&totalDefaultData).Error; err != nil {
  537. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  538. return nil, 0, err
  539. }
  540. // 查询该页数据
  541. limit := pageSize
  542. offset := pageSize * pageNum // assert pageNum start with 0
  543. err = db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  544. if err != nil {
  545. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  546. return nil, 0, err
  547. }
  548. var TaskDefaultDatas []*http_model.TaskDefaultData
  549. var taskDefaultDatas []*http_model.TaskDefaultDataInfo
  550. var newTaskDefaultDatas []*http_model.TaskDefaultDataInfo
  551. for _, taskId := range taskIds {
  552. TaskDefaultData := new(http_model.TaskDefaultData)
  553. TaskDefaultData.Talent = taskMap[taskId]
  554. TaskDefaultData.Default = DefaultDataMap[taskId]
  555. TaskDefaultData.Link = LinkMap[taskId]
  556. TaskDefaultDatas = append(TaskDefaultDatas, TaskDefaultData)
  557. }
  558. taskDefaultDatas = pack.TaskDefaultDataToTaskInfo(TaskDefaultDatas)
  559. for _, v := range taskDefaultDatas {
  560. if platform_nickname == "" {
  561. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  562. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  563. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  564. } else if strings.Contains(conv.MustString(v.TaskID, ""), platform_nickname) {
  565. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  566. } else {
  567. totalTask--
  568. }
  569. }
  570. return newTaskDefaultDatas, totalTask, nil
  571. }
  572. func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatingInfo, int64, error) {
  573. db := GetReadDB(ctx)
  574. var taskIds1 []int
  575. var totalTerminating int64
  576. var TerminatingInfos []gorm_model.YoungeeContractInfo
  577. db = db.Model(gorm_model.YoungeeContractInfo{})
  578. err := db.Where("default_status = 3").Find(&TerminatingInfos).Error
  579. if err != nil {
  580. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  581. return nil, 0, err
  582. }
  583. TerminatingMap := make(map[int]gorm_model.YoungeeContractInfo)
  584. for _, TerminatingInfo := range TerminatingInfos {
  585. taskIds1 = append(taskIds1, TerminatingInfo.TaskID)
  586. TerminatingMap[conv.MustInt(TerminatingInfo.TaskID, 0)] = TerminatingInfo
  587. }
  588. if err := db.Count(&totalTerminating).Error; err != nil {
  589. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  590. return nil, 0, err
  591. }
  592. db1 := GetReadDB(ctx)
  593. // 查询Task表信息
  594. db1 = db1.Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2 and task_id in ?", taskIds1)
  595. // 根据Project条件过滤
  596. conditionType := reflect.TypeOf(conditions).Elem()
  597. conditionValue := reflect.ValueOf(conditions).Elem()
  598. var platform_nickname string = ""
  599. for i := 0; i < conditionType.NumField(); i++ {
  600. field := conditionType.Field(i)
  601. tag := field.Tag.Get("condition")
  602. value := conditionValue.FieldByName(field.Name)
  603. if tag == "default_status" {
  604. if value.Interface() == int64(4) {
  605. db = db.Where("cur_default_type = 9")
  606. }
  607. continue
  608. } else if !util.IsBlank(value) {
  609. if tag == "platform_nickname" {
  610. platform_nickname = fmt.Sprintf("%v", value.Interface())
  611. continue
  612. } else if tag == "project_id" || tag == "strategy_id" {
  613. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  614. }
  615. }
  616. }
  617. var taskInfos []gorm_model.YoungeeTaskInfo
  618. // db1 = db1.Model(gorm_model.YoungeeTaskInfo{})
  619. // 查询总数
  620. var totalTask int64
  621. if err := db1.Count(&totalTask).Error; err != nil {
  622. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  623. return nil, 0, err
  624. }
  625. db1.Order("task_id").Find(&taskInfos)
  626. // 查询任务id
  627. var taskIds []int
  628. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  629. for _, taskInfo := range taskInfos {
  630. taskIds = append(taskIds, taskInfo.TaskId)
  631. taskMap[taskInfo.TaskId] = taskInfo
  632. }
  633. var misNum int64
  634. if totalTerminating > totalTask {
  635. misNum = totalTerminating - totalTask
  636. } else {
  637. misNum = totalTask - totalTerminating
  638. }
  639. logrus.Println("totalTerminating,totalTalent,misNum:", totalTerminating, totalTask, misNum)
  640. // 查询该页数据
  641. limit := pageSize + misNum
  642. offset := pageSize * pageNum // assert pageNum start with 0
  643. err = db1.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  644. if err != nil {
  645. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  646. return nil, 0, err
  647. }
  648. var TaskTerminatings []*http_model.TaskTerminating
  649. var taskTerminatings []*http_model.TaskTerminatingInfo
  650. var newTaskTerminatings []*http_model.TaskTerminatingInfo
  651. for _, taskId := range taskIds {
  652. TaskTerminating := new(http_model.TaskTerminating)
  653. TaskTerminating.Talent = taskMap[taskId]
  654. TaskTerminating.Default = TerminatingMap[taskId]
  655. TaskTerminatings = append(TaskTerminatings, TaskTerminating)
  656. }
  657. taskTerminatings = pack.TaskTerminatingToTaskInfo(TaskTerminatings)
  658. for _, v := range taskTerminatings {
  659. if platform_nickname == "" {
  660. newTaskTerminatings = append(newTaskTerminatings, v)
  661. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  662. newTaskTerminatings = append(newTaskTerminatings, v)
  663. } else if strings.Contains(conv.MustString(v.TaskID, ""), platform_nickname) {
  664. newTaskTerminatings = append(newTaskTerminatings, v)
  665. } else {
  666. totalTask--
  667. }
  668. }
  669. return newTaskTerminatings, totalTask, nil
  670. }
  671. func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatedInfo, int64, error) {
  672. db := GetReadDB(ctx)
  673. // 查询Task表信息
  674. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  675. // 根据Project条件过滤
  676. conditionType := reflect.TypeOf(conditions).Elem()
  677. conditionValue := reflect.ValueOf(conditions).Elem()
  678. var platform_nickname string = ""
  679. for i := 0; i < conditionType.NumField(); i++ {
  680. field := conditionType.Field(i)
  681. tag := field.Tag.Get("condition")
  682. value := conditionValue.FieldByName(field.Name)
  683. if tag == "default_status" {
  684. fmt.Printf("default %+v", value.Interface() == int64(0))
  685. if value.Interface() == int64(5) {
  686. db = db.Where("complete_status = 4")
  687. }
  688. continue
  689. } else if !util.IsBlank(value) {
  690. if tag == "platform_nickname" {
  691. platform_nickname = fmt.Sprintf("%v", value.Interface())
  692. continue
  693. } else if tag == "project_id" || tag == "strategy_id" {
  694. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  695. }
  696. }
  697. }
  698. var taskInfos []gorm_model.YoungeeTaskInfo
  699. db = db.Model(gorm_model.YoungeeTaskInfo{})
  700. // 查询总数
  701. var totalTask int64
  702. if err := db.Count(&totalTask).Error; err != nil {
  703. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  704. return nil, 0, err
  705. }
  706. db.Order("task_id").Find(&taskInfos)
  707. // 查询任务id
  708. var taskIds []int
  709. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  710. for _, taskInfo := range taskInfos {
  711. taskIds = append(taskIds, taskInfo.TaskId)
  712. taskMap[taskInfo.TaskId] = taskInfo
  713. }
  714. db1 := GetReadDB(ctx)
  715. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  716. var TerminatedInfos []gorm_model.YoungeeContractInfo
  717. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  718. err1 := db1.Find(&TerminatedInfos).Error
  719. if err1 != nil {
  720. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql find, err:%+v", err1)
  721. return nil, 0, err1
  722. }
  723. TerminatedMap := make(map[int]gorm_model.YoungeeContractInfo)
  724. for _, TerminatedInfo := range TerminatedInfos {
  725. TerminatedMap[conv.MustInt(TerminatedInfo.TaskID, 0)] = TerminatedInfo
  726. }
  727. // 查询总数
  728. var totalTerminated int64
  729. if err := db1.Count(&totalTerminated).Error; err != nil {
  730. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  731. return nil, 0, err
  732. }
  733. var misNum int64
  734. if totalTerminated > totalTask {
  735. misNum = totalTerminated - totalTask
  736. } else {
  737. misNum = totalTask - totalTerminated
  738. }
  739. logrus.Println("totalTerminated,totalTalent,misNum:", totalTerminated, totalTask, misNum)
  740. // 查询该页数据
  741. limit := pageSize + misNum
  742. offset := pageSize * pageNum // assert pageNum start with 0
  743. err := db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  744. if err != nil {
  745. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  746. return nil, 0, err
  747. }
  748. var TaskTerminateds []*http_model.TaskTerminated
  749. var taskTerminateds []*http_model.TaskTerminatedInfo
  750. var newTaskTerminateds []*http_model.TaskTerminatedInfo
  751. for _, taskId := range taskIds {
  752. TaskTerminated := new(http_model.TaskTerminated)
  753. TaskTerminated.Talent = taskMap[taskId]
  754. TaskTerminated.Default = TerminatedMap[taskId]
  755. TaskTerminateds = append(TaskTerminateds, TaskTerminated)
  756. }
  757. taskTerminateds = pack.TaskTerminatedToTaskInfo(TaskTerminateds)
  758. for _, v := range taskTerminateds {
  759. if platform_nickname == "" {
  760. newTaskTerminateds = append(newTaskTerminateds, v)
  761. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  762. newTaskTerminateds = append(newTaskTerminateds, v)
  763. } else if strings.Contains(conv.MustString(v.TaskID, ""), platform_nickname) {
  764. newTaskTerminateds = append(newTaskTerminateds, v)
  765. } else {
  766. totalTask--
  767. }
  768. }
  769. return newTaskTerminateds, totalTask, nil
  770. }