default.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. package db
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/caixw/lib.go/conv"
  6. "github.com/sirupsen/logrus"
  7. "reflect"
  8. "strings"
  9. "youngee_m_api/consts"
  10. "youngee_m_api/model/common_model"
  11. "youngee_m_api/model/gorm_model"
  12. "youngee_m_api/model/http_model"
  13. "youngee_m_api/pack"
  14. "youngee_m_api/util"
  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. }
  402. if !util.IsBlank(value) {
  403. logrus.Println("tag: ", tag)
  404. if tag == "platform_nickname" {
  405. platform_nickname = fmt.Sprintf("%v", value.Interface())
  406. continue
  407. } else if tag == "project_id" {
  408. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  409. } else if tag == "strategy_ids" {
  410. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  411. var strategyIdList []int
  412. for _, strategyId := range strategyIds {
  413. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  414. }
  415. db = db.Where("strategy_id in ?", strategyIdList)
  416. } else {
  417. db = db.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  418. }
  419. }
  420. }
  421. var taskInfos []gorm_model.YoungeeTaskInfo
  422. db = db.Model(gorm_model.YoungeeTaskInfo{})
  423. // 查询总数
  424. var totalTask int64
  425. if err := db.Count(&totalTask).Error; err != nil {
  426. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  427. return nil, 0, err
  428. }
  429. db.Order("task_id").Find(&taskInfos)
  430. // 查询任务id
  431. var taskIds []int
  432. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  433. for _, taskInfo := range taskInfos {
  434. taskIds = append(taskIds, taskInfo.TaskId)
  435. taskMap[taskInfo.TaskId] = taskInfo
  436. }
  437. db1 := GetReadDB(ctx)
  438. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  439. var DefaultReviewInfos []gorm_model.YoungeeContractInfo
  440. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  441. err := db1.Find(&DefaultReviewInfos).Error
  442. if err != nil {
  443. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  444. return nil, 0, err
  445. }
  446. DefaultReviewMap := make(map[int]gorm_model.YoungeeContractInfo)
  447. for _, DefaultReviewInfo := range DefaultReviewInfos {
  448. DefaultReviewMap[conv.MustInt(DefaultReviewInfo.TaskID, 0)] = DefaultReviewInfo
  449. }
  450. // 查询总数
  451. var totalDefaultReview int64
  452. if err := db1.Count(&totalDefaultReview).Error; err != nil {
  453. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  454. return nil, 0, err
  455. }
  456. // 查询该页数据
  457. limit := pageSize
  458. offset := pageSize * pageNum // assert pageNum start with 0
  459. err = db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  460. if err != nil {
  461. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  462. return nil, 0, err
  463. }
  464. var TaskDefaultReviews []*http_model.TaskDefaultReview
  465. var taskDefaultReviews []*http_model.TaskDefaultReviewInfo
  466. var newTaskDefaultReviews []*http_model.TaskDefaultReviewInfo
  467. for _, taskId := range taskIds {
  468. TaskDefaultReview := new(http_model.TaskDefaultReview)
  469. TaskDefaultReview.Talent = taskMap[taskId]
  470. TaskDefaultReview.Default = DefaultReviewMap[taskId]
  471. TaskDefaultReviews = append(TaskDefaultReviews, TaskDefaultReview)
  472. }
  473. taskDefaultReviews = pack.TaskDefaultReviewToTaskInfo(TaskDefaultReviews)
  474. for _, v := range taskDefaultReviews {
  475. if platform_nickname == "" {
  476. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  477. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  478. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  479. } else {
  480. totalTask--
  481. }
  482. }
  483. return newTaskDefaultReviews, totalTask, nil
  484. }
  485. func GetTaskDefaultDataList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskDefaultDataInfo, int64, error) {
  486. db := GetReadDB(ctx)
  487. // 查询Task表信息
  488. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  489. // 根据Project条件过滤
  490. conditionType := reflect.TypeOf(conditions).Elem()
  491. conditionValue := reflect.ValueOf(conditions).Elem()
  492. var platform_nickname string = ""
  493. for i := 0; i < conditionType.NumField(); i++ {
  494. field := conditionType.Field(i)
  495. tag := field.Tag.Get("condition")
  496. value := conditionValue.FieldByName(field.Name)
  497. if tag == "default_status" {
  498. if value.Interface() == int64(3) {
  499. db = db.Where("cur_default_type = 7")
  500. }
  501. continue
  502. } else if !util.IsBlank(value) {
  503. logrus.Println("tag: ", tag)
  504. if tag == "platform_nickname" {
  505. platform_nickname = fmt.Sprintf("%v", value.Interface())
  506. continue
  507. } else if tag == "project_id" {
  508. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  509. } else if tag == "strategy_ids" {
  510. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  511. var strategyIdList []int
  512. for _, strategyId := range strategyIds {
  513. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  514. }
  515. db = db.Where("strategy_id in ?", strategyIdList)
  516. } else {
  517. db = db.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  518. }
  519. }
  520. }
  521. var taskInfos []gorm_model.YoungeeTaskInfo
  522. db = db.Model(gorm_model.YoungeeTaskInfo{})
  523. // 查询总数
  524. var totalTask int64
  525. if err := db.Count(&totalTask).Error; err != nil {
  526. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  527. return nil, 0, err
  528. }
  529. db.Order("task_id").Find(&taskInfos)
  530. // 查询任务id
  531. var taskIds []int
  532. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  533. for _, taskInfo := range taskInfos {
  534. taskIds = append(taskIds, taskInfo.TaskId)
  535. taskMap[taskInfo.TaskId] = taskInfo
  536. }
  537. db1 := GetReadDB(ctx)
  538. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  539. var DefaultDataInfos []gorm_model.YoungeeContractInfo
  540. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  541. err := db1.Find(&DefaultDataInfos).Error
  542. DefaultDataMap := make(map[int]gorm_model.YoungeeContractInfo)
  543. for _, DefaultDataInfo := range DefaultDataInfos {
  544. DefaultDataMap[conv.MustInt(DefaultDataInfo.TaskID, 0)] = DefaultDataInfo
  545. }
  546. var LinkInfos []gorm_model.YounggeeLinkInfo
  547. db2 := GetReadDB(ctx)
  548. db2 = db2.Model(gorm_model.YounggeeLinkInfo{}).Where("task_id IN ? AND is_ok = 1", taskIds).Find(&LinkInfos)
  549. LinkMap := make(map[int]gorm_model.YounggeeLinkInfo)
  550. for _, LinkInfo := range LinkInfos {
  551. LinkMap[conv.MustInt(LinkInfo.TaskID, 0)] = LinkInfo
  552. }
  553. // 查询总数
  554. var totalDefaultData int64
  555. if err := db2.Count(&totalDefaultData).Error; err != nil {
  556. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  557. return nil, 0, err
  558. }
  559. // 查询该页数据
  560. limit := pageSize
  561. offset := pageSize * pageNum // assert pageNum start with 0
  562. err = db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  563. if err != nil {
  564. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  565. return nil, 0, err
  566. }
  567. var TaskDefaultDatas []*http_model.TaskDefaultData
  568. var taskDefaultDatas []*http_model.TaskDefaultDataInfo
  569. var newTaskDefaultDatas []*http_model.TaskDefaultDataInfo
  570. for _, taskId := range taskIds {
  571. TaskDefaultData := new(http_model.TaskDefaultData)
  572. TaskDefaultData.Talent = taskMap[taskId]
  573. TaskDefaultData.Default = DefaultDataMap[taskId]
  574. TaskDefaultData.Link = LinkMap[taskId]
  575. TaskDefaultDatas = append(TaskDefaultDatas, TaskDefaultData)
  576. }
  577. taskDefaultDatas = pack.TaskDefaultDataToTaskInfo(TaskDefaultDatas)
  578. for _, v := range taskDefaultDatas {
  579. if platform_nickname == "" {
  580. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  581. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  582. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  583. } else {
  584. totalTask--
  585. }
  586. }
  587. return newTaskDefaultDatas, totalTask, nil
  588. }
  589. func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatingInfo, int64, error) {
  590. db := GetReadDB(ctx)
  591. var taskIds1 []int
  592. var totalTerminating int64
  593. var TerminatingInfos []gorm_model.YoungeeContractInfo
  594. db = db.Model(gorm_model.YoungeeContractInfo{})
  595. err := db.Where("default_status = 3").Find(&TerminatingInfos).Error
  596. if err != nil {
  597. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  598. return nil, 0, err
  599. }
  600. TerminatingMap := make(map[int]gorm_model.YoungeeContractInfo)
  601. for _, TerminatingInfo := range TerminatingInfos {
  602. taskIds1 = append(taskIds1, TerminatingInfo.TaskID)
  603. TerminatingMap[conv.MustInt(TerminatingInfo.TaskID, 0)] = TerminatingInfo
  604. }
  605. if err := db.Count(&totalTerminating).Error; err != nil {
  606. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  607. return nil, 0, err
  608. }
  609. db1 := GetReadDB(ctx)
  610. // 查询Task表信息
  611. db1 = db1.Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2 and task_id in ?", taskIds1)
  612. // 根据Project条件过滤
  613. conditionType := reflect.TypeOf(conditions).Elem()
  614. conditionValue := reflect.ValueOf(conditions).Elem()
  615. var platform_nickname string = ""
  616. for i := 0; i < conditionType.NumField(); i++ {
  617. field := conditionType.Field(i)
  618. tag := field.Tag.Get("condition")
  619. value := conditionValue.FieldByName(field.Name)
  620. if tag == "default_status" {
  621. if value.Interface() == int64(4) {
  622. db = db.Where("cur_default_type = 9")
  623. }
  624. continue
  625. } else if !util.IsBlank(value) {
  626. logrus.Println("tag: ", tag)
  627. if tag == "platform_nickname" {
  628. platform_nickname = fmt.Sprintf("%v", value.Interface())
  629. continue
  630. } else if tag == "project_id" {
  631. db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  632. } else if tag == "strategy_ids" {
  633. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  634. var strategyIdList []int
  635. for _, strategyId := range strategyIds {
  636. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  637. }
  638. db1 = db1.Where("strategy_id in ?", strategyIdList)
  639. } else {
  640. db1 = db1.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  641. }
  642. }
  643. }
  644. var taskInfos []gorm_model.YoungeeTaskInfo
  645. // db1 = db1.Model(gorm_model.YoungeeTaskInfo{})
  646. // 查询总数
  647. var totalTask int64
  648. if err := db1.Count(&totalTask).Error; err != nil {
  649. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  650. return nil, 0, err
  651. }
  652. db1.Order("task_id").Find(&taskInfos)
  653. // 查询任务id
  654. var taskIds []int
  655. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  656. for _, taskInfo := range taskInfos {
  657. taskIds = append(taskIds, taskInfo.TaskId)
  658. taskMap[taskInfo.TaskId] = taskInfo
  659. }
  660. var misNum int64
  661. if totalTerminating > totalTask {
  662. misNum = totalTerminating - totalTask
  663. } else {
  664. misNum = totalTask - totalTerminating
  665. }
  666. logrus.Println("totalTerminating,totalTalent,misNum:", totalTerminating, totalTask, misNum)
  667. // 查询该页数据
  668. limit := pageSize + misNum
  669. offset := pageSize * pageNum // assert pageNum start with 0
  670. err = db1.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  671. if err != nil {
  672. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  673. return nil, 0, err
  674. }
  675. var TaskTerminatings []*http_model.TaskTerminating
  676. var taskTerminatings []*http_model.TaskTerminatingInfo
  677. var newTaskTerminatings []*http_model.TaskTerminatingInfo
  678. for _, taskId := range taskIds {
  679. TaskTerminating := new(http_model.TaskTerminating)
  680. TaskTerminating.Talent = taskMap[taskId]
  681. TaskTerminating.Default = TerminatingMap[taskId]
  682. TaskTerminatings = append(TaskTerminatings, TaskTerminating)
  683. }
  684. taskTerminatings = pack.TaskTerminatingToTaskInfo(TaskTerminatings)
  685. for _, v := range taskTerminatings {
  686. if platform_nickname == "" {
  687. newTaskTerminatings = append(newTaskTerminatings, v)
  688. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  689. newTaskTerminatings = append(newTaskTerminatings, v)
  690. } else {
  691. totalTask--
  692. }
  693. }
  694. return newTaskTerminatings, totalTask, nil
  695. }
  696. func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatedInfo, int64, error) {
  697. db := GetReadDB(ctx)
  698. // 查询Task表信息
  699. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  700. // 根据Project条件过滤
  701. conditionType := reflect.TypeOf(conditions).Elem()
  702. conditionValue := reflect.ValueOf(conditions).Elem()
  703. var platform_nickname string = ""
  704. for i := 0; i < conditionType.NumField(); i++ {
  705. field := conditionType.Field(i)
  706. tag := field.Tag.Get("condition")
  707. value := conditionValue.FieldByName(field.Name)
  708. if tag == "default_status" {
  709. fmt.Printf("default %+v", value.Interface() == int64(0))
  710. if value.Interface() == int64(5) {
  711. db = db.Where("complete_status = 4")
  712. }
  713. continue
  714. } else if !util.IsBlank(value) {
  715. logrus.Println("tag: ", tag)
  716. if tag == "platform_nickname" {
  717. platform_nickname = fmt.Sprintf("%v", value.Interface())
  718. continue
  719. } else if tag == "project_id" {
  720. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  721. } else if tag == "strategy_ids" {
  722. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  723. var strategyIdList []int
  724. for _, strategyId := range strategyIds {
  725. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  726. }
  727. db = db.Where("strategy_id in ?", strategyIdList)
  728. } else {
  729. db = db.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  730. }
  731. }
  732. }
  733. var taskInfos []gorm_model.YoungeeTaskInfo
  734. db = db.Model(gorm_model.YoungeeTaskInfo{})
  735. // 查询总数
  736. var totalTask int64
  737. if err := db.Count(&totalTask).Error; err != nil {
  738. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  739. return nil, 0, err
  740. }
  741. db.Order("task_id").Find(&taskInfos)
  742. // 查询任务id
  743. var taskIds []int
  744. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  745. for _, taskInfo := range taskInfos {
  746. taskIds = append(taskIds, taskInfo.TaskId)
  747. taskMap[taskInfo.TaskId] = taskInfo
  748. }
  749. db1 := GetReadDB(ctx)
  750. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  751. var TerminatedInfos []gorm_model.YoungeeContractInfo
  752. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  753. err1 := db1.Find(&TerminatedInfos).Error
  754. if err1 != nil {
  755. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql find, err:%+v", err1)
  756. return nil, 0, err1
  757. }
  758. TerminatedMap := make(map[int]gorm_model.YoungeeContractInfo)
  759. for _, TerminatedInfo := range TerminatedInfos {
  760. TerminatedMap[conv.MustInt(TerminatedInfo.TaskID, 0)] = TerminatedInfo
  761. }
  762. // 查询总数
  763. var totalTerminated int64
  764. if err := db1.Count(&totalTerminated).Error; err != nil {
  765. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  766. return nil, 0, err
  767. }
  768. var misNum int64
  769. if totalTerminated > totalTask {
  770. misNum = totalTerminated - totalTask
  771. } else {
  772. misNum = totalTask - totalTerminated
  773. }
  774. logrus.Println("totalTerminated,totalTalent,misNum:", totalTerminated, totalTask, misNum)
  775. // 查询该页数据
  776. limit := pageSize + misNum
  777. offset := pageSize * pageNum // assert pageNum start with 0
  778. err := db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  779. if err != nil {
  780. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  781. return nil, 0, err
  782. }
  783. var TaskTerminateds []*http_model.TaskTerminated
  784. var taskTerminateds []*http_model.TaskTerminatedInfo
  785. var newTaskTerminateds []*http_model.TaskTerminatedInfo
  786. for _, taskId := range taskIds {
  787. TaskTerminated := new(http_model.TaskTerminated)
  788. TaskTerminated.Talent = taskMap[taskId]
  789. TaskTerminated.Default = TerminatedMap[taskId]
  790. TaskTerminateds = append(TaskTerminateds, TaskTerminated)
  791. }
  792. taskTerminateds = pack.TaskTerminatedToTaskInfo(TaskTerminateds)
  793. for _, v := range taskTerminateds {
  794. if platform_nickname == "" {
  795. newTaskTerminateds = append(newTaskTerminateds, v)
  796. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  797. newTaskTerminateds = append(newTaskTerminateds, v)
  798. } else {
  799. totalTask--
  800. }
  801. }
  802. return newTaskTerminateds, totalTask, nil
  803. }