default.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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. return data, nil
  245. }
  246. func BreachHandled(ctx context.Context, pageSize, pageNum int32, req *http_model.BreachHandledRequest, conditions *common_model.BreachHandledConditions) (*http_model.BreachHandledData, error) {
  247. db := GetReadDB(ctx)
  248. var contractInfos []*gorm_model.YoungeeContractInfo
  249. db = db.Model(gorm_model.YoungeeContractInfo{}).Where("default_status = 4 OR default_status = 5")
  250. // 根据Project条件过滤
  251. conditionType := reflect.TypeOf(conditions).Elem()
  252. conditionValue := reflect.ValueOf(conditions).Elem()
  253. for i := 0; i < conditionType.NumField(); i++ {
  254. field := conditionType.Field(i)
  255. tag := field.Tag.Get("condition")
  256. value := conditionValue.FieldByName(field.Name)
  257. if !util.IsBlank(value) {
  258. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  259. }
  260. }
  261. if req.TaskId != 0 {
  262. db = db.Where("task_id = ?", req.TaskId)
  263. }
  264. var findProjectIds []int64
  265. if req.ProjectName != "" {
  266. db1 := GetReadDB(ctx)
  267. db1.Model(gorm_model.ProjectInfo{}).Select("project_id").Where("project_name = ?", req.ProjectName).Find(&findProjectIds)
  268. var findTaskIds []int
  269. db2 := GetReadDB(ctx)
  270. db2.Model(gorm_model.YoungeeTaskInfo{}).Select("task_id").Where("project_id IN ?", findProjectIds).Find(&findTaskIds)
  271. db = db.Where("task_id IN ?", findTaskIds)
  272. }
  273. // 查询总数
  274. var total int64
  275. if err := db.Count(&total).Error; err != nil {
  276. logrus.WithContext(ctx).Errorf("[BreachHandled] error query mysql total, err:%+v", err)
  277. return nil, err
  278. }
  279. // 查询该页数据
  280. limit := pageSize
  281. offset := pageSize * pageNum // assert pageNum start with 0
  282. err := db.Order("terminate_at").Limit(int(limit)).Offset(int(offset)).Find(&contractInfos).Error
  283. if err != nil {
  284. logrus.WithContext(ctx).Errorf("[BreachHandled] error query mysql total, err:%+v", err)
  285. return nil, err
  286. }
  287. var taskIds []int
  288. for _, contractInfo := range contractInfos {
  289. taskIds = append(taskIds, contractInfo.TaskID)
  290. }
  291. taskIds = util.RemoveIntRepByMap(taskIds)
  292. taskIdToProjectMap := make(map[int]int)
  293. taskIdToTalentIdMap := make(map[int]string)
  294. taskIdToTaskInfoMap := make(map[int]gorm_model.YoungeeTaskInfo)
  295. var projectIds []int
  296. for _, taskId := range taskIds {
  297. db1 := GetReadDB(ctx)
  298. var taskInfo gorm_model.YoungeeTaskInfo
  299. db1.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Find(&taskInfo)
  300. taskIdToProjectMap[taskId] = taskInfo.ProjectId
  301. taskIdToTalentIdMap[taskId] = taskInfo.TalentId
  302. taskIdToTaskInfoMap[taskId] = taskInfo
  303. projectIds = append(projectIds, taskInfo.ProjectId)
  304. }
  305. //fmt.Println("TaskID:", taskIds)
  306. //fmt.Println("projectIds:", projectIds)
  307. //fmt.Println("taskIdToProjectMap:", taskIdToProjectMap)
  308. //fmt.Println("taskIdToTalentIdMap:", taskIdToTalentIdMap)
  309. projectIds = util.RemoveIntRepByMap(projectIds)
  310. var enterpriseIds []int64
  311. projectIdToProjectInfoMap := make(map[int64]gorm_model.ProjectInfo)
  312. for _, projectId := range projectIds {
  313. db1 := GetReadDB(ctx)
  314. projectInfo := gorm_model.ProjectInfo{}
  315. db1.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", projectId).Find(&projectInfo)
  316. projectIdToProjectInfoMap[projectInfo.ProjectID] = projectInfo
  317. enterpriseIds = append(enterpriseIds, projectInfo.EnterpriseID)
  318. }
  319. enterpriseIds = util.RemoveRepByMap(enterpriseIds)
  320. //fmt.Println("enterpriseIds:", enterpriseIds)
  321. enterpriseIdToUserId := make(map[int64]int64)
  322. var userIds []int64
  323. for _, enterpriseId := range enterpriseIds {
  324. db1 := GetReadDB(ctx)
  325. var userId int64
  326. db1.Model(gorm_model.Enterprise{}).Select("user_id").Where("enterprise_id = ?", enterpriseId).Find(&userId)
  327. enterpriseIdToUserId[enterpriseId] = userId
  328. userIds = append(userIds, userId)
  329. }
  330. //fmt.Println("projectIdToProjectInfoMap:", projectIdToProjectInfoMap)
  331. //fmt.Println("enterpriseIdToUserId:", enterpriseIdToUserId)
  332. //fmt.Println("userIds:", userIds)
  333. userIdToUserPhone := make(map[int64]string)
  334. for _, userId := range userIds {
  335. db1 := GetReadDB(ctx)
  336. var userPhone string
  337. db1.Model(gorm_model.YounggeeUser{}).Select("phone").Where("id = ?", userId).Find(&userPhone)
  338. userIdToUserPhone[userId] = userPhone
  339. }
  340. //fmt.Println("userIdToUserPhone:", userIdToUserPhone)
  341. talentIdToTalentPhoneMap := make(map[string]string)
  342. for _, v := range taskIdToTalentIdMap {
  343. if len(talentIdToTalentPhoneMap) == 0 {
  344. db1 := GetReadDB(ctx)
  345. var talentPhoneNumber string
  346. db1.Model(gorm_model.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", v).Find(&talentPhoneNumber)
  347. talentIdToTalentPhoneMap[v] = talentPhoneNumber
  348. }
  349. if _, ok := talentIdToTalentPhoneMap[v]; !ok {
  350. db1 := GetReadDB(ctx)
  351. var talentPhoneNumber string
  352. db1.Model(gorm_model.YoungeeTalentInfo{}).Select("talent_phone_number").Where("id = ?", v).Find(&talentPhoneNumber)
  353. talentIdToTalentPhoneMap[v] = talentPhoneNumber
  354. }
  355. }
  356. //fmt.Println("talentIdToTalentPhoneMap:", talentIdToTalentPhoneMap)
  357. var BreachHandledPreviews []*http_model.BreachHandledPreview
  358. for _, contractInfo := range contractInfos {
  359. BreachHandledPreview := new(http_model.BreachHandledPreview)
  360. BreachHandledPreview.ContractId = int32(contractInfo.ContractID)
  361. BreachHandledPreview.ProjectId = int32(taskIdToProjectMap[contractInfo.TaskID])
  362. BreachHandledPreview.UserId = int32(enterpriseIdToUserId[projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].EnterpriseID])
  363. BreachHandledPreview.ProjectName = projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].ProjectName
  364. BreachHandledPreview.UserPhone = userIdToUserPhone[enterpriseIdToUserId[projectIdToProjectInfoMap[int64(taskIdToProjectMap[contractInfo.TaskID])].EnterpriseID]]
  365. BreachHandledPreview.TaskId = int32(contractInfo.TaskID)
  366. BreachHandledPreview.TalentId = taskIdToTalentIdMap[contractInfo.TaskID]
  367. BreachHandledPreview.TalentPhone = talentIdToTalentPhoneMap[taskIdToTalentIdMap[contractInfo.TaskID]]
  368. BreachHandledPreview.TerminateReason = consts.GetBreakType(contractInfo.BreakType)
  369. BreachHandledPreview.HandleResult = consts.GetHandleResult(contractInfo.DefaultStatus)
  370. BreachHandledPreview.HandleAt = conv.MustString(contractInfo.HandleAt, "")[0:19]
  371. BreachHandledPreviews = append(BreachHandledPreviews, BreachHandledPreview)
  372. }
  373. var BreachHandledData http_model.BreachHandledData
  374. BreachHandledData.BreachHandledPreview = BreachHandledPreviews
  375. BreachHandledData.Total = total
  376. return &BreachHandledData, nil
  377. }
  378. func GetTaskDefaultReviewList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskDefaultReviewInfo, int64, error) {
  379. db := GetReadDB(ctx)
  380. // 查询Task表信息
  381. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  382. // 根据Project条件过滤
  383. conditionType := reflect.TypeOf(conditions).Elem()
  384. conditionValue := reflect.ValueOf(conditions).Elem()
  385. var platform_nickname string = ""
  386. for i := 0; i < conditionType.NumField(); i++ {
  387. field := conditionType.Field(i)
  388. tag := field.Tag.Get("condition")
  389. value := conditionValue.FieldByName(field.Name)
  390. if tag == "default_status" {
  391. fmt.Printf("default %+v", value.Interface() == int64(0))
  392. if value.Interface() == int64(0) {
  393. db = db.Where("cur_default_type = 1")
  394. } else if value.Interface() == int64(1) {
  395. db = db.Where("cur_default_type = 3")
  396. } else if value.Interface() == int64(2) {
  397. db = db.Where("cur_default_type = 5")
  398. }
  399. continue
  400. }
  401. if !util.IsBlank(value) {
  402. logrus.Println("tag: ", tag)
  403. if tag == "platform_nickname" {
  404. platform_nickname = fmt.Sprintf("%v", value.Interface())
  405. continue
  406. } else if tag == "project_id" {
  407. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  408. } else if tag == "strategy_ids" {
  409. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  410. var strategyIdList []int
  411. for _, strategyId := range strategyIds {
  412. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  413. }
  414. db = db.Where("strategy_id in ?", strategyIdList)
  415. } else {
  416. db = db.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  417. }
  418. }
  419. }
  420. var taskInfos []gorm_model.YoungeeTaskInfo
  421. db = db.Model(gorm_model.YoungeeTaskInfo{})
  422. // 查询总数
  423. var totalTask int64
  424. if err := db.Count(&totalTask).Error; err != nil {
  425. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  426. return nil, 0, err
  427. }
  428. db.Order("task_id").Find(&taskInfos)
  429. // 查询任务id
  430. var taskIds []int
  431. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  432. for _, taskInfo := range taskInfos {
  433. taskIds = append(taskIds, taskInfo.TaskId)
  434. taskMap[taskInfo.TaskId] = taskInfo
  435. }
  436. db1 := GetReadDB(ctx)
  437. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  438. var DefaultReviewInfos []gorm_model.YoungeeContractInfo
  439. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  440. err := db1.Find(&DefaultReviewInfos).Error
  441. if err != nil {
  442. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  443. return nil, 0, err
  444. }
  445. DefaultReviewMap := make(map[int]gorm_model.YoungeeContractInfo)
  446. for _, DefaultReviewInfo := range DefaultReviewInfos {
  447. DefaultReviewMap[conv.MustInt(DefaultReviewInfo.TaskID, 0)] = DefaultReviewInfo
  448. }
  449. // 查询总数
  450. var totalDefaultReview int64
  451. if err := db1.Count(&totalDefaultReview).Error; err != nil {
  452. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  453. return nil, 0, err
  454. }
  455. // 查询该页数据
  456. limit := pageSize
  457. offset := pageSize * pageNum // assert pageNum start with 0
  458. err = db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  459. if err != nil {
  460. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  461. return nil, 0, err
  462. }
  463. var TaskDefaultReviews []*http_model.TaskDefaultReview
  464. var taskDefaultReviews []*http_model.TaskDefaultReviewInfo
  465. var newTaskDefaultReviews []*http_model.TaskDefaultReviewInfo
  466. for _, taskId := range taskIds {
  467. TaskDefaultReview := new(http_model.TaskDefaultReview)
  468. TaskDefaultReview.Talent = taskMap[taskId]
  469. TaskDefaultReview.Default = DefaultReviewMap[taskId]
  470. TaskDefaultReviews = append(TaskDefaultReviews, TaskDefaultReview)
  471. }
  472. taskDefaultReviews = pack.TaskDefaultReviewToTaskInfo(TaskDefaultReviews)
  473. for _, v := range taskDefaultReviews {
  474. if platform_nickname == "" {
  475. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  476. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  477. newTaskDefaultReviews = append(newTaskDefaultReviews, v)
  478. } else {
  479. totalTask--
  480. }
  481. }
  482. return newTaskDefaultReviews, totalTask, nil
  483. }
  484. func GetTaskDefaultDataList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskDefaultDataInfo, int64, error) {
  485. db := GetReadDB(ctx)
  486. // 查询Task表信息
  487. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  488. // 根据Project条件过滤
  489. conditionType := reflect.TypeOf(conditions).Elem()
  490. conditionValue := reflect.ValueOf(conditions).Elem()
  491. var platform_nickname string = ""
  492. for i := 0; i < conditionType.NumField(); i++ {
  493. field := conditionType.Field(i)
  494. tag := field.Tag.Get("condition")
  495. value := conditionValue.FieldByName(field.Name)
  496. if tag == "default_status" {
  497. if value.Interface() == int64(3) {
  498. db = db.Where("cur_default_type = 7")
  499. }
  500. continue
  501. } else if !util.IsBlank(value) {
  502. logrus.Println("tag: ", tag)
  503. if tag == "platform_nickname" {
  504. platform_nickname = fmt.Sprintf("%v", value.Interface())
  505. continue
  506. } else if tag == "project_id" {
  507. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  508. } else if tag == "strategy_ids" {
  509. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  510. var strategyIdList []int
  511. for _, strategyId := range strategyIds {
  512. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  513. }
  514. db = db.Where("strategy_id in ?", strategyIdList)
  515. } else {
  516. db = db.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  517. }
  518. }
  519. }
  520. var taskInfos []gorm_model.YoungeeTaskInfo
  521. db = db.Model(gorm_model.YoungeeTaskInfo{})
  522. // 查询总数
  523. var totalTask int64
  524. if err := db.Count(&totalTask).Error; err != nil {
  525. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  526. return nil, 0, err
  527. }
  528. db.Order("task_id").Find(&taskInfos)
  529. // 查询任务id
  530. var taskIds []int
  531. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  532. for _, taskInfo := range taskInfos {
  533. taskIds = append(taskIds, taskInfo.TaskId)
  534. taskMap[taskInfo.TaskId] = taskInfo
  535. }
  536. db1 := GetReadDB(ctx)
  537. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  538. var DefaultDataInfos []gorm_model.YoungeeContractInfo
  539. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  540. err := db1.Find(&DefaultDataInfos).Error
  541. DefaultDataMap := make(map[int]gorm_model.YoungeeContractInfo)
  542. for _, DefaultDataInfo := range DefaultDataInfos {
  543. DefaultDataMap[conv.MustInt(DefaultDataInfo.TaskID, 0)] = DefaultDataInfo
  544. }
  545. var LinkInfos []gorm_model.YounggeeLinkInfo
  546. db2 := GetReadDB(ctx)
  547. db2 = db2.Model(gorm_model.YounggeeLinkInfo{}).Where("task_id IN ? AND is_ok = 1", taskIds).Find(&LinkInfos)
  548. LinkMap := make(map[int]gorm_model.YounggeeLinkInfo)
  549. for _, LinkInfo := range LinkInfos {
  550. LinkMap[conv.MustInt(LinkInfo.TaskID, 0)] = LinkInfo
  551. }
  552. // 查询总数
  553. var totalDefaultData int64
  554. if err := db2.Count(&totalDefaultData).Error; err != nil {
  555. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  556. return nil, 0, err
  557. }
  558. // 查询该页数据
  559. limit := pageSize
  560. offset := pageSize * pageNum // assert pageNum start with 0
  561. err = db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  562. if err != nil {
  563. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  564. return nil, 0, err
  565. }
  566. var TaskDefaultDatas []*http_model.TaskDefaultData
  567. var taskDefaultDatas []*http_model.TaskDefaultDataInfo
  568. var newTaskDefaultDatas []*http_model.TaskDefaultDataInfo
  569. for _, taskId := range taskIds {
  570. TaskDefaultData := new(http_model.TaskDefaultData)
  571. TaskDefaultData.Talent = taskMap[taskId]
  572. TaskDefaultData.Default = DefaultDataMap[taskId]
  573. TaskDefaultData.Link = LinkMap[taskId]
  574. TaskDefaultDatas = append(TaskDefaultDatas, TaskDefaultData)
  575. }
  576. taskDefaultDatas = pack.TaskDefaultDataToTaskInfo(TaskDefaultDatas)
  577. for _, v := range taskDefaultDatas {
  578. if platform_nickname == "" {
  579. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  580. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  581. newTaskDefaultDatas = append(newTaskDefaultDatas, v)
  582. } else {
  583. totalTask--
  584. }
  585. }
  586. return newTaskDefaultDatas, totalTask, nil
  587. }
  588. func GetTaskTerminatingList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatingInfo, int64, error) {
  589. db := GetReadDB(ctx)
  590. var taskIds1 []int
  591. var totalTerminating int64
  592. var TerminatingInfos []gorm_model.YoungeeContractInfo
  593. db = db.Model(gorm_model.YoungeeContractInfo{})
  594. err := db.Where("default_status = 3").Find(&TerminatingInfos).Error
  595. if err != nil {
  596. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  597. return nil, 0, err
  598. }
  599. TerminatingMap := make(map[int]gorm_model.YoungeeContractInfo)
  600. for _, TerminatingInfo := range TerminatingInfos {
  601. taskIds1 = append(taskIds1, TerminatingInfo.TaskID)
  602. TerminatingMap[conv.MustInt(TerminatingInfo.TaskID, 0)] = TerminatingInfo
  603. }
  604. if err := db.Count(&totalTerminating).Error; err != nil {
  605. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  606. return nil, 0, err
  607. }
  608. db1 := GetReadDB(ctx)
  609. // 查询Task表信息
  610. db1 = db1.Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2 and task_id in ?", taskIds1)
  611. // 根据Project条件过滤
  612. conditionType := reflect.TypeOf(conditions).Elem()
  613. conditionValue := reflect.ValueOf(conditions).Elem()
  614. var platform_nickname string = ""
  615. for i := 0; i < conditionType.NumField(); i++ {
  616. field := conditionType.Field(i)
  617. tag := field.Tag.Get("condition")
  618. value := conditionValue.FieldByName(field.Name)
  619. if tag == "default_status" {
  620. if value.Interface() == int64(4) {
  621. db = db.Where("cur_default_type = 9")
  622. }
  623. continue
  624. } else if !util.IsBlank(value) {
  625. logrus.Println("tag: ", tag)
  626. if tag == "platform_nickname" {
  627. platform_nickname = fmt.Sprintf("%v", value.Interface())
  628. continue
  629. } else if tag == "project_id" {
  630. db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  631. } else if tag == "strategy_ids" {
  632. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  633. var strategyIdList []int
  634. for _, strategyId := range strategyIds {
  635. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  636. }
  637. db1 = db1.Where("strategy_id in ?", strategyIdList)
  638. } else {
  639. db1 = db1.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  640. }
  641. }
  642. }
  643. var taskInfos []gorm_model.YoungeeTaskInfo
  644. // db1 = db1.Model(gorm_model.YoungeeTaskInfo{})
  645. // 查询总数
  646. var totalTask int64
  647. if err := db1.Count(&totalTask).Error; err != nil {
  648. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  649. return nil, 0, err
  650. }
  651. db1.Order("task_id").Find(&taskInfos)
  652. // 查询任务id
  653. var taskIds []int
  654. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  655. for _, taskInfo := range taskInfos {
  656. taskIds = append(taskIds, taskInfo.TaskId)
  657. taskMap[taskInfo.TaskId] = taskInfo
  658. }
  659. var misNum int64
  660. if totalTerminating > totalTask {
  661. misNum = totalTerminating - totalTask
  662. } else {
  663. misNum = totalTask - totalTerminating
  664. }
  665. logrus.Println("totalTerminating,totalTalent,misNum:", totalTerminating, totalTask, misNum)
  666. // 查询该页数据
  667. limit := pageSize + misNum
  668. offset := pageSize * pageNum // assert pageNum start with 0
  669. err = db1.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  670. if err != nil {
  671. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  672. return nil, 0, err
  673. }
  674. var TaskTerminatings []*http_model.TaskTerminating
  675. var taskTerminatings []*http_model.TaskTerminatingInfo
  676. var newTaskTerminatings []*http_model.TaskTerminatingInfo
  677. for _, taskId := range taskIds {
  678. TaskTerminating := new(http_model.TaskTerminating)
  679. TaskTerminating.Talent = taskMap[taskId]
  680. TaskTerminating.Default = TerminatingMap[taskId]
  681. TaskTerminatings = append(TaskTerminatings, TaskTerminating)
  682. }
  683. taskTerminatings = pack.TaskTerminatingToTaskInfo(TaskTerminatings)
  684. for _, v := range taskTerminatings {
  685. if platform_nickname == "" {
  686. newTaskTerminatings = append(newTaskTerminatings, v)
  687. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  688. newTaskTerminatings = append(newTaskTerminatings, v)
  689. } else {
  690. totalTask--
  691. }
  692. }
  693. return newTaskTerminatings, totalTask, nil
  694. }
  695. func GetTaskTerminatedList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskTerminatedInfo, int64, error) {
  696. db := GetReadDB(ctx)
  697. // 查询Task表信息
  698. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_status = 2")
  699. // 根据Project条件过滤
  700. conditionType := reflect.TypeOf(conditions).Elem()
  701. conditionValue := reflect.ValueOf(conditions).Elem()
  702. var platform_nickname string = ""
  703. for i := 0; i < conditionType.NumField(); i++ {
  704. field := conditionType.Field(i)
  705. tag := field.Tag.Get("condition")
  706. value := conditionValue.FieldByName(field.Name)
  707. if tag == "default_status" {
  708. fmt.Printf("default %+v", value.Interface() == int64(0))
  709. if value.Interface() == int64(5) {
  710. db = db.Where("complete_status = 4")
  711. }
  712. continue
  713. } else if !util.IsBlank(value) {
  714. logrus.Println("tag: ", tag)
  715. if tag == "platform_nickname" {
  716. platform_nickname = fmt.Sprintf("%v", value.Interface())
  717. continue
  718. } else if tag == "project_id" {
  719. db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
  720. } else if tag == "strategy_ids" {
  721. strategyIds := strings.Split(fmt.Sprintf("%v", value.Interface()), ",")
  722. var strategyIdList []int
  723. for _, strategyId := range strategyIds {
  724. strategyIdList = append(strategyIdList, conv.MustInt(strategyId, 0))
  725. }
  726. db = db.Where("strategy_id in ?", strategyIdList)
  727. } else {
  728. db = db.Where(fmt.Sprintf("%s like '%%%v%%'", tag, value.Interface()))
  729. }
  730. }
  731. }
  732. var taskInfos []gorm_model.YoungeeTaskInfo
  733. db = db.Model(gorm_model.YoungeeTaskInfo{})
  734. // 查询总数
  735. var totalTask int64
  736. if err := db.Count(&totalTask).Error; err != nil {
  737. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  738. return nil, 0, err
  739. }
  740. db.Order("task_id").Find(&taskInfos)
  741. // 查询任务id
  742. var taskIds []int
  743. taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
  744. for _, taskInfo := range taskInfos {
  745. taskIds = append(taskIds, taskInfo.TaskId)
  746. taskMap[taskInfo.TaskId] = taskInfo
  747. }
  748. db1 := GetReadDB(ctx)
  749. db1 = db1.Debug().Model(gorm_model.YoungeeContractInfo{})
  750. var TerminatedInfos []gorm_model.YoungeeContractInfo
  751. db1 = db1.Model(gorm_model.YoungeeContractInfo{}).Where("task_id IN ? AND default_status = 1", taskIds)
  752. err1 := db1.Find(&TerminatedInfos).Error
  753. if err1 != nil {
  754. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql find, err:%+v", err1)
  755. return nil, 0, err1
  756. }
  757. TerminatedMap := make(map[int]gorm_model.YoungeeContractInfo)
  758. for _, TerminatedInfo := range TerminatedInfos {
  759. TerminatedMap[conv.MustInt(TerminatedInfo.TaskID, 0)] = TerminatedInfo
  760. }
  761. // 查询总数
  762. var totalTerminated int64
  763. if err := db1.Count(&totalTerminated).Error; err != nil {
  764. logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
  765. return nil, 0, err
  766. }
  767. var misNum int64
  768. if totalTerminated > totalTask {
  769. misNum = totalTerminated - totalTask
  770. } else {
  771. misNum = totalTask - totalTerminated
  772. }
  773. logrus.Println("totalTerminated,totalTalent,misNum:", totalTerminated, totalTask, misNum)
  774. // 查询该页数据
  775. limit := pageSize + misNum
  776. offset := pageSize * pageNum // assert pageNum start with 0
  777. err := db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
  778. if err != nil {
  779. logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
  780. return nil, 0, err
  781. }
  782. var TaskTerminateds []*http_model.TaskTerminated
  783. var taskTerminateds []*http_model.TaskTerminatedInfo
  784. var newTaskTerminateds []*http_model.TaskTerminatedInfo
  785. for _, taskId := range taskIds {
  786. TaskTerminated := new(http_model.TaskTerminated)
  787. TaskTerminated.Talent = taskMap[taskId]
  788. TaskTerminated.Default = TerminatedMap[taskId]
  789. TaskTerminateds = append(TaskTerminateds, TaskTerminated)
  790. }
  791. taskTerminateds = pack.TaskTerminatedToTaskInfo(TaskTerminateds)
  792. for _, v := range taskTerminateds {
  793. if platform_nickname == "" {
  794. newTaskTerminateds = append(newTaskTerminateds, v)
  795. } else if strings.Contains(v.PlatformNickname, platform_nickname) {
  796. newTaskTerminateds = append(newTaskTerminateds, v)
  797. } else {
  798. totalTask--
  799. }
  800. }
  801. return newTaskTerminateds, totalTask, nil
  802. }