default.go 33 KB

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