contract_allocation.go 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/company"
  10. "hongze/hz_crm_api/models/contract"
  11. "hongze/hz_crm_api/models/cygx"
  12. "hongze/hz_crm_api/models/system"
  13. cygxService "hongze/hz_crm_api/services/cygx"
  14. "hongze/hz_crm_api/utils"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // ContractAllocationController 权益合同派单
  22. type ContractAllocationController struct {
  23. controllers.BaseAuthController
  24. }
  25. // getQueryParams 获取基础查询信息
  26. func getQueryParams(condition string, pars []interface{}, sysUser *system.Admin, tableAlias string) (newCondition string, newPars []interface{}) {
  27. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  28. condition += " AND " + tableAlias + "product_id=?"
  29. pars = append(pars, 1)
  30. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  31. condition += " AND " + tableAlias + "product_id=?"
  32. pars = append(pars, 2)
  33. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE {
  34. //超级管理员账户,不做条件限制
  35. } else {
  36. //如果不是研究员,那么去找对应的 部门、小组、销售
  37. if sysUser.Authority == 0 {
  38. //普通用户
  39. condition += " AND " + tableAlias + "seller_id=?"
  40. pars = append(pars, sysUser.AdminId)
  41. } else if sysUser.Authority == 1 {
  42. //部门主管
  43. condition += " AND " + tableAlias + "department_id=?"
  44. pars = append(pars, sysUser.DepartmentId)
  45. } else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  46. //权益小组负责人
  47. condition += " AND " + tableAlias + "group_id=?"
  48. pars = append(pars, sysUser.GroupId)
  49. } else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  50. //ficc销售主管
  51. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  52. if err != nil {
  53. fmt.Println(err.Error())
  54. return
  55. }
  56. var ids []*string
  57. if pid != nil && *pid != 0 {
  58. ids, err = company.GetGroupIdsByParentId(*pid)
  59. if err != nil {
  60. fmt.Println(err.Error())
  61. }
  62. } else {
  63. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  64. if err != nil {
  65. fmt.Println(err.Error())
  66. }
  67. }
  68. var idSlice []string
  69. var sid string
  70. for _, id := range ids {
  71. idSlice = append(idSlice, *id)
  72. }
  73. //加入父级groupId
  74. if *pid > 0 {
  75. idSlice = append(idSlice, strconv.Itoa(*pid))
  76. } else {
  77. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  78. }
  79. sid = strings.Join(idSlice, ",")
  80. condition += " AND " + tableAlias + `group_id IN (` + sid + `) `
  81. fmt.Println("condition:", condition)
  82. //pars = append(pars, sysUser.GroupId)
  83. } else if sysUser.Authority == 4 {
  84. //ficc小组负责人
  85. condition += " AND " + tableAlias + "group_id=?"
  86. pars = append(pars, sysUser.GroupId)
  87. } else {
  88. //不知道什么类型的用户(后面新增的位置类型客户)
  89. condition += " AND " + tableAlias + "seller_id=?"
  90. pars = append(pars, sysUser.AdminId)
  91. }
  92. }
  93. newCondition = condition
  94. newPars = pars
  95. return
  96. }
  97. // @Title 合同列表
  98. // @Description 合同列表接口
  99. // @Param PageSize query int true "每页数据条数"
  100. // @Param CurrentIndex query int true "当前页页码,从1开始"
  101. // @Param Keyword query string true "客户名称"
  102. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  103. // @Param StartDate query string false "开始日期"
  104. // @Param EndDate query string false "结束日期"
  105. // @Param ContractType query string false "合同类型,枚举值:“,`新签合同`,`续约合同`,`补充协议`"
  106. // @Param FormalType query string false "转正类型,枚举值:“,`标准`,`非标`"
  107. // @Param IsExport query bool false "是否导出excel,默认是false"
  108. // @Param ResearcherRealName query string false "研究员姓名"
  109. // @Param IsAllocation query int false "派点状态: -1-默认全部; 0-未派点; 1-已派点"
  110. // @Success 200 {object} cygx.CompanyContractListResp
  111. // @router /allocation/company_contract_list [get]
  112. func (this *ContractAllocationController) CompanyContractList() {
  113. br := new(models.BaseResponse).Init()
  114. defer func() {
  115. this.Data["json"] = br
  116. this.ServeJSON()
  117. }()
  118. sysUser := this.SysUser
  119. if sysUser == nil {
  120. br.Msg = "请登录"
  121. br.ErrMsg = "请登录,SysUser Is Empty"
  122. br.Ret = 408
  123. return
  124. }
  125. pageSize, _ := this.GetInt("PageSize")
  126. currentIndex, _ := this.GetInt("CurrentIndex")
  127. adminId := this.GetString("AdminId")
  128. formalType := this.GetString("FormalType")
  129. contractType := this.GetString("ContractType")
  130. keyword := this.GetString("Keyword")
  131. startDate := this.GetString("StartDate")
  132. endDate := this.GetString("EndDate")
  133. researcherRealName := this.GetString("ResearcherRealName")
  134. isAllocation, _ := this.GetInt("IsAllocation", -1) // CRM 13.9
  135. if startDate == "" {
  136. startDate = "2015-01-01"
  137. }
  138. var startSize int
  139. if pageSize <= 0 {
  140. pageSize = utils.PageSize20
  141. }
  142. if currentIndex <= 0 {
  143. currentIndex = 1
  144. }
  145. startSize = utils.StartIndex(currentIndex, pageSize)
  146. //是否导出报表
  147. isExport, _ := this.GetBool("IsExport")
  148. if isExport {
  149. pageSize = 10000
  150. currentIndex = 1
  151. }
  152. var condition string
  153. var pars []interface{}
  154. if endDate != "" {
  155. condition += ` AND a.start_date >= ? AND a.start_date <= ? `
  156. pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
  157. }
  158. //条件
  159. if adminId != "" {
  160. condition += ` AND c.seller_id in (` + adminId + `) `
  161. //pars = append(pars, adminId)
  162. }
  163. //权益申请销售只能看到自己名下的客户的申请
  164. companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
  165. if err != nil {
  166. br.Msg = "获取失败"
  167. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  168. return
  169. }
  170. lencompanyIds := len(companyIds)
  171. if lencompanyIds > 0 {
  172. condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  173. pars = append(pars, companyIds)
  174. }
  175. //关键字搜索
  176. if keyword != "" {
  177. condition += ` and b.company_name like "%` + keyword + `%" `
  178. }
  179. //是否派点
  180. if isAllocation != -1 {
  181. condition += ` AND a.is_allocation = ? `
  182. pars = append(pars, isAllocation)
  183. }
  184. // 标准非标查询
  185. switch formalType {
  186. case "标准":
  187. condition += ` AND a.source = ? `
  188. pars = append(pars, "系统合同")
  189. case "非标":
  190. condition += ` AND a.source = ? `
  191. pars = append(pars, "上传附件")
  192. }
  193. if contractType != "" {
  194. condition += ` AND a.contract_type = ? `
  195. pars = append(pars, contractType)
  196. }
  197. //默认只查询权益 2023-06-01 之后的合同
  198. condition += ` AND c.product_id = ? AND a.start_date > ? `
  199. pars = append(pars, 2, "2023-05-31")
  200. mapMoneyPoint := make(map[int]float64)
  201. //研究员姓名查询
  202. if researcherRealName != "" {
  203. var conditionAllocation string
  204. var parsAllocation []interface{}
  205. conditionAllocation = " AND real_name = ? AND money != 0 "
  206. parsAllocation = append(parsAllocation, researcherRealName)
  207. allocationCompanyContractList, err := cygx.GetCygxAllocationCompanyContractList(conditionAllocation, parsAllocation)
  208. if err != nil {
  209. br.Msg = "获取失败"
  210. br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractListErr:" + err.Error()
  211. return
  212. }
  213. var companyContractIds []int
  214. for _, v := range allocationCompanyContractList {
  215. companyContractIds = append(companyContractIds, v.CompanyContractId)
  216. mapMoneyPoint[v.CompanyContractId] = v.Money
  217. }
  218. lenCon := len(companyContractIds)
  219. if lenCon == 0 {
  220. condition += ` AND a.company_contract_id = 0 `
  221. } else {
  222. condition += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(lenCon) + `)`
  223. pars = append(pars, companyContractIds)
  224. }
  225. }
  226. var list []*cygx.CompanyContractResp
  227. total, err := cygx.GetCompanyContractCountJoinCompany(condition, pars)
  228. if err != nil && err.Error() != utils.ErrNoRow() {
  229. br.Msg = "获取失败"
  230. br.ErrMsg = "获取失败,Err:" + err.Error()
  231. return
  232. }
  233. //列表页数据
  234. list, err = cygx.GetCompanyContractListJoinCompany(condition, pars, startSize, pageSize)
  235. if err != nil {
  236. br.Msg = "获取失败"
  237. br.ErrMsg = "获取失败,Err:" + err.Error()
  238. return
  239. }
  240. //mapCompamy := make(map[int]string)
  241. listLen := len(list)
  242. if listLen == 0 {
  243. list = make([]*cygx.CompanyContractResp, 0)
  244. } else {
  245. var contractCodes []string
  246. var companyContractIds []int
  247. for _, v := range list {
  248. switch v.Source {
  249. case "系统合同":
  250. v.FormalType = "标准"
  251. case "上传附件":
  252. v.FormalType = "非标"
  253. }
  254. contractCodes = append(contractCodes, v.ContractCode)
  255. companyContractIds = append(companyContractIds, v.CompanyContractId)
  256. //mapCompamy[v.CompanyId] = strconv.Itoa(v.CompanyContractId)
  257. }
  258. lencontractCodes := len(contractCodes)
  259. if lencontractCodes > 0 {
  260. //获取标准合同的ID,这里上面的查询已经关联了三张表,拆分吧。。。
  261. condition = ""
  262. joinStr := ""
  263. pars = make([]interface{}, 0)
  264. condition = " AND a.contract_code IN (" + utils.GetOrmInReplace(lencontractCodes) + ") "
  265. pars = append(pars, contractCodes)
  266. listContract, err := contract.GetContractList(condition, joinStr, pars, 0, lencontractCodes)
  267. if err != nil {
  268. br.Msg = "获取合同列表失败!"
  269. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  270. return
  271. }
  272. mapContractCode := make(map[string]int)
  273. for _, v := range listContract {
  274. mapContractCode[v.ContractCode] = v.ContractId
  275. }
  276. mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds(companyContractIds)
  277. if err != nil {
  278. br.Msg = "获取合同列表失败!"
  279. br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
  280. return
  281. }
  282. //合并合同所对应的权限
  283. mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
  284. if err != nil {
  285. br.Msg = "获取失败"
  286. br.ErrMsg = "获取失败,Err:" + err.Error()
  287. return
  288. }
  289. for _, v := range list {
  290. v.ContractId = mapContractCode[v.ContractCode]
  291. v.MoneyPoint = mapMoneyPoint[v.CompanyContractId]
  292. v.PermissionName = mappermissionName[v.CompanyContractId]
  293. v.IsGray = mapIsGray[v.CompanyContractId]
  294. }
  295. }
  296. }
  297. page := paging.GetPaging(currentIndex, pageSize, total)
  298. resp := cygx.CompanyContractListResp{
  299. Paging: page,
  300. List: list,
  301. }
  302. //导出excel
  303. if isExport {
  304. CompanyContractListExport(this, resp, br)
  305. return
  306. }
  307. br.Ret = 200
  308. br.Success = true
  309. br.Msg = "获取成功"
  310. br.Data = resp
  311. }
  312. // CompanyContractListExport 导出Excel
  313. func CompanyContractListExport(this *ContractAllocationController, resp cygx.CompanyContractListResp, br *models.BaseResponse) {
  314. dir, err := os.Executable()
  315. exPath := filepath.Dir(dir)
  316. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  317. xlsxFile := xlsx.NewFile()
  318. if err != nil {
  319. br.Msg = "生成文件失败"
  320. br.ErrMsg = "生成文件失败"
  321. return
  322. }
  323. style := xlsx.NewStyle()
  324. alignment := xlsx.Alignment{
  325. Horizontal: "center",
  326. Vertical: "center",
  327. WrapText: true,
  328. }
  329. style.Alignment = alignment
  330. style.ApplyAlignment = true
  331. sheel, err := xlsxFile.AddSheet("派点导出数据")
  332. if err != nil {
  333. br.Msg = "新增Sheet失败"
  334. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  335. return
  336. }
  337. sheel.SetColWidth(0, 0, 30)
  338. sheel.SetColWidth(1, 1, 15)
  339. sheel.SetColWidth(2, 2, 15)
  340. sheel.SetColWidth(3, 3, 18)
  341. titleRow := sheel.AddRow()
  342. cellA := titleRow.AddCell()
  343. cellA.SetStyle(style)
  344. cellA.SetValue("合同编号")
  345. cellB := titleRow.AddCell()
  346. cellB.SetStyle(style)
  347. cellB.SetValue("转正类型")
  348. cellC := titleRow.AddCell()
  349. cellC.SetStyle(style)
  350. cellC.SetValue("合同类型")
  351. cellD := titleRow.AddCell()
  352. cellD.SetStyle(style)
  353. cellD.SetValue("公司名称")
  354. cellE := titleRow.AddCell()
  355. cellE.SetStyle(style)
  356. cellE.SetValue("所属销售")
  357. cellF := titleRow.AddCell()
  358. cellF.SetStyle(style)
  359. cellF.SetValue("合同金额")
  360. cellG := titleRow.AddCell()
  361. cellG.SetStyle(style)
  362. cellG.SetValue("合同期限")
  363. cellH := titleRow.AddCell()
  364. cellH.SetStyle(style)
  365. cellH.SetValue("签约套餐")
  366. cellI := titleRow.AddCell()
  367. cellI.SetStyle(style)
  368. cellI.SetValue("状态")
  369. for _, v := range resp.List {
  370. dataRow := sheel.AddRow()
  371. dataRow.SetHeight(20)
  372. cellA := dataRow.AddCell()
  373. cellA.SetStyle(style)
  374. cellA.SetValue(v.ContractCode)
  375. cellB := dataRow.AddCell()
  376. cellB.SetStyle(style)
  377. cellB.SetValue(v.FormalType)
  378. cellC := dataRow.AddCell()
  379. cellC.SetStyle(style)
  380. cellC.SetValue(v.ContractType)
  381. cellD := dataRow.AddCell()
  382. cellD.SetStyle(style)
  383. cellD.SetValue(v.CompanyName)
  384. cellE := dataRow.AddCell()
  385. cellE.SetStyle(style)
  386. cellE.SetValue(v.SellerName)
  387. cellF := dataRow.AddCell()
  388. cellF.SetStyle(style)
  389. cellF.SetValue(v.Money)
  390. cellG := dataRow.AddCell()
  391. cellG.SetStyle(style)
  392. cellG.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
  393. cellH := dataRow.AddCell()
  394. cellH.SetStyle(style)
  395. cellH.SetValue(v.PermissionName)
  396. cellI := dataRow.AddCell()
  397. cellI.SetStyle(style)
  398. if v.IsAllocation == 1 {
  399. cellI.SetValue("已派点")
  400. } else {
  401. cellI.SetValue("未派点")
  402. }
  403. }
  404. err = xlsxFile.Save(downLoadnFilePath)
  405. if err != nil {
  406. br.Msg = "保存文件失败"
  407. br.ErrMsg = "保存文件失败"
  408. return
  409. }
  410. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  411. downloadFileName := "派点导出数据_" + randStr + ".xlsx"
  412. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  413. defer func() {
  414. os.Remove(downLoadnFilePath)
  415. }()
  416. br.Ret = 200
  417. br.Success = true
  418. br.Msg = "导出成功"
  419. }
  420. // @Title 详情
  421. // @Description 获取详情接口
  422. // @Param CompanyContractId query int true "ID"
  423. // @Param ShowDetail query bool false "是否是派点详情展示"
  424. // @Success Ret=200 {object} cygx.CygxAllocationCompanyContractDetailResp
  425. // @router /allocation/detail [get]
  426. func (this *ContractAllocationController) CompanyContracDetail() {
  427. br := new(models.BaseResponse).Init()
  428. defer func() {
  429. this.Data["json"] = br
  430. this.ServeJSON()
  431. }()
  432. AdminUser := this.SysUser
  433. if AdminUser == nil {
  434. br.Msg = "请登录"
  435. br.ErrMsg = "请登录,用户信息为空"
  436. br.Ret = 408
  437. return
  438. }
  439. resp := new(cygx.CygxAllocationCompanyContractDetailResp)
  440. companyContractId, _ := this.GetInt("CompanyContractId")
  441. if companyContractId < 1 {
  442. br.Msg = "请输入详情ID"
  443. return
  444. }
  445. showDetail, _ := this.GetBool("ShowDetail", false)
  446. contractItem, err := company.GetCompanyContractById(companyContractId)
  447. if err != nil {
  448. br.Msg = "获取信息失败"
  449. br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  450. return
  451. }
  452. total, err := cygx.GetCygxAllocationCompanyContractCountByCompanyContractId(companyContractId)
  453. if err != nil {
  454. br.Msg = "获取信息失败"
  455. br.ErrMsg = "获取合同信息失败,GetCygxAllocationCompanyContractCountByCompanyContractId Err:" + err.Error()
  456. return
  457. }
  458. //var contractPermissionList []*company.ContractPermissionList
  459. //expMap := map[int]string{0: "(3w)", 1: "(5w)", 2: "(10w)"} // 买方研选价格
  460. hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
  461. if e != nil {
  462. br.Msg = "获取失败"
  463. br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
  464. return
  465. }
  466. hasMap := make(map[int]*company.CompanyContractPermission)
  467. var pointMoney float64
  468. for _, p := range hasPermissions {
  469. hasMap[p.ChartPermissionId] = p
  470. if p.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  471. pointMoney = 0.2 * p.Points
  472. }
  473. }
  474. raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  475. if e != nil {
  476. br.Msg = "获取失败"
  477. br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  478. return
  479. }
  480. mapPermissionNameHave := make(map[string]bool) // 判断合同是否存在某一行业权限种类
  481. var expensiveYx int
  482. for _, n := range raiPermissions {
  483. match := hasMap[n.ChartPermissionId]
  484. if match == nil {
  485. continue
  486. }
  487. mapPermissionNameHave[n.PermissionName] = true
  488. // 买方研选(3w/5w/10w)
  489. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  490. expensiveYx = match.ExpensiveYx
  491. //n.PermissionName += expMap[match.ExpensiveYx]
  492. continue
  493. }
  494. }
  495. resp.Money = contractItem.Money / 10000
  496. //有研选时,对研选套餐类型做文案处理
  497. respItemYx := new(cygx.AllocationPermissionListResp) // 研选订阅
  498. respItemYxKouDian := new(cygx.AllocationPermissionListResp) // 研选扣点
  499. if mapPermissionNameHave[utils.CHART_PERMISSION_NAME_MF_YANXUAN] || mapPermissionNameHave[utils.YAN_XUAN_KOU_DIAN_BAO_NAME] {
  500. var moneyYx float64
  501. if mapPermissionNameHave[utils.CHART_PERMISSION_NAME_MF_YANXUAN] {
  502. if expensiveYx == 0 {
  503. moneyYx = 3
  504. } else if expensiveYx == 1 {
  505. moneyYx = 5
  506. } else if expensiveYx == 2 {
  507. moneyYx = 10
  508. }
  509. respItemYx.Proportion = 0
  510. respItemYx.Money = moneyYx
  511. respItemYx.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  512. respItemYx.List = append(respItemYx.List, &cygx.AllocationRealNameListResp{utils.CHART_PERMISSION_NAME_MF_YANXUAN, 0, moneyYx})
  513. }
  514. if mapPermissionNameHave[utils.YAN_XUAN_KOU_DIAN_BAO_NAME] {
  515. respItemYxKouDian.Proportion = 0
  516. respItemYxKouDian.Money = pointMoney
  517. respItemYxKouDian.ChartPermissionName = utils.YAN_XUAN_KOU_DIAN_BAO_NAME
  518. respItemYxKouDian.List = append(respItemYxKouDian.List, &cygx.AllocationRealNameListResp{utils.YAN_XUAN_KOU_DIAN_BAO_NAME, 0, pointMoney})
  519. }
  520. resp.TotalPointsContent = fmt.Sprint(resp.Money, "W,", "其中", moneyYx+pointMoney, "w默认归属买方研选,请对剩余", resp.Money-moneyYx-pointMoney, "w按照100%进行比值分配")
  521. if showDetail {
  522. resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
  523. }
  524. resp.Money = resp.Money - moneyYx
  525. } else {
  526. resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
  527. }
  528. sysUserList, err := cygx.GetAskEmailList()
  529. if err != nil {
  530. br.Msg = "获取失败"
  531. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  532. return
  533. }
  534. mapPermissionUser := make(map[string][]*cygx.AllocationRealNameListResp)
  535. var respList []*cygx.AllocationPermissionListResp
  536. if total == 0 {
  537. for _, v := range sysUserList {
  538. if !mapPermissionNameHave[v.ChartPermissionName] {
  539. continue
  540. }
  541. item := new(cygx.AllocationRealNameListResp)
  542. item.RealName = v.Name
  543. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  544. }
  545. for k, v := range mapPermissionUser {
  546. respItem := new(cygx.AllocationPermissionListResp)
  547. respItem.ChartPermissionName = k
  548. respItem.List = v
  549. respList = append(respList, respItem)
  550. }
  551. //研选订阅
  552. if respItemYx.ChartPermissionName != "" {
  553. respList = append(respList, respItemYx)
  554. }
  555. //研选扣点
  556. if respItemYxKouDian.ChartPermissionName != "" {
  557. respList = append(respList, respItemYxKouDian)
  558. }
  559. } else {
  560. listUser, err := cygx.GetCygxAllocationCompanyContractListById(companyContractId)
  561. if err != nil {
  562. br.Msg = "获取失败"
  563. br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractListById Err: " + err.Error()
  564. return
  565. }
  566. for _, v := range listUser {
  567. if showDetail && v.Money == 0 {
  568. continue
  569. }
  570. item := new(cygx.AllocationRealNameListResp)
  571. item.RealName = v.RealName
  572. item.Money = v.Money
  573. item.Proportion = v.Proportion
  574. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  575. }
  576. listPermission, err := cygx.GetCygxAllocationCompanyContractPermissionListById(companyContractId)
  577. if err != nil {
  578. br.Msg = "获取失败"
  579. br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractPermissionListById Err: " + err.Error()
  580. return
  581. }
  582. for _, v := range listPermission {
  583. if showDetail && v.Money == 0 {
  584. continue
  585. }
  586. respItem := new(cygx.AllocationPermissionListResp)
  587. respItem.ChartPermissionName = v.ChartPermissionName
  588. respItem.Money = v.Money
  589. respItem.Proportion = v.Proportion
  590. respItem.List = mapPermissionUser[v.ChartPermissionName]
  591. respList = append(respList, respItem)
  592. }
  593. }
  594. //处理是否置灰
  595. mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
  596. if err != nil {
  597. br.Msg = "获取合同列表失败!"
  598. br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
  599. return
  600. }
  601. permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略", utils.CHART_PERMISSION_NAME_MF_YANXUAN, utils.YAN_XUAN_KOU_DIAN_BAO_NAME}
  602. for _, v := range permissionNameArr {
  603. for _, v2 := range respList {
  604. if v2.ChartPermissionName == v {
  605. resp.List = append(resp.List, v2)
  606. }
  607. }
  608. }
  609. resp.IsGray = mapIsGray[companyContractId]
  610. //resp.List = respList
  611. resp.CompanyContractId = companyContractId
  612. br.Ret = 200
  613. br.Success = true
  614. br.Msg = "获取成功"
  615. br.Data = resp
  616. }
  617. // @Title 更新派点
  618. // @Description 更新派点接口
  619. // @Param request body cygx.AddProductInteriorReq true "type json string"
  620. // @Success 200 {object} "保存成功"
  621. // @router /allocation/update [post]
  622. func (this *ContractAllocationController) CompanyContracUpdate() {
  623. br := new(models.BaseResponse).Init()
  624. defer func() {
  625. this.Data["json"] = br
  626. this.ServeJSON()
  627. }()
  628. sysUser := this.SysUser
  629. if sysUser == nil {
  630. br.Msg = "请登录"
  631. br.ErrMsg = "请登录,SysUser Is Empty"
  632. br.Ret = 408
  633. return
  634. }
  635. var req cygx.UpdateAllocationCompanyContractReq
  636. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  637. if err != nil {
  638. br.Msg = "参数解析异常!"
  639. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  640. return
  641. }
  642. companyContractId := req.CompanyContractId
  643. if companyContractId == 0 {
  644. br.Msg = "参数错误"
  645. br.ErrMsg = "参数错误,id不可为空"
  646. return
  647. }
  648. mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
  649. if err != nil {
  650. br.Msg = "获取合同列表失败!"
  651. br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
  652. return
  653. }
  654. if mapIsGray[companyContractId] {
  655. br.Msg = "超过180天,无法修改!"
  656. br.ErrMsg = "超过180天,无法修改,companyContractId :" + strconv.Itoa(companyContractId)
  657. return
  658. }
  659. contractItem, err := company.GetCompanyContractById(companyContractId)
  660. if err != nil {
  661. br.Msg = "获取信息失败"
  662. br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  663. return
  664. }
  665. money := contractItem.Money / 10000 // 合同金额,万为单位
  666. var moneyAvg float64 // 行业所占合同的平均金额
  667. hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
  668. if e != nil {
  669. br.Msg = "获取失败"
  670. br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
  671. return
  672. }
  673. hasMap := make(map[int]*company.CompanyContractPermission)
  674. for _, p := range hasPermissions {
  675. hasMap[p.ChartPermissionId] = p
  676. }
  677. raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  678. if e != nil {
  679. br.Msg = "获取失败"
  680. br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  681. return
  682. }
  683. mapPermissionNameHave := make(map[string]bool) // 判断合同是否存在某一行业权限种类
  684. for _, n := range raiPermissions {
  685. //只计算,医药、消费、科技、智造、策略、买方研选的
  686. if n.PermissionName != utils.YI_YAO_NAME && n.PermissionName != utils.XIAO_FEI_NAME && n.PermissionName != utils.KE_JI_NAME && n.PermissionName != utils.ZHI_ZAO_NAME && n.PermissionName != utils.CE_LUE_NAME && n.PermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  687. continue
  688. }
  689. match := hasMap[n.ChartPermissionId]
  690. if match == nil {
  691. continue
  692. }
  693. // 买方研选(3w/5w/10W)
  694. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  695. if match.ExpensiveYx == 1 {
  696. money = money - 5
  697. } else if match.ExpensiveYx == 2 {
  698. money = money - 10
  699. } else {
  700. money = money - 3
  701. }
  702. } else {
  703. mapPermissionNameHave[n.PermissionName] = true
  704. }
  705. }
  706. if len(mapPermissionNameHave) > 0 {
  707. moneyAvg = money / float64(len(mapPermissionNameHave))
  708. }
  709. list := req.List
  710. var items []*cygx.CygxAllocationCompanyContract
  711. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  712. var proportionSum float64 // 校验前端传过来的占比使用
  713. for _, v := range list {
  714. itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
  715. itemPermission.CompanyContractId = companyContractId
  716. itemPermission.AdminId = sysUser.AdminId
  717. itemPermission.AdminName = sysUser.RealName
  718. itemPermission.Proportion = v.Proportion
  719. itemPermission.Money = v.Money
  720. if v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  721. itemPermission.MoneyAvg = moneyAvg
  722. if v.Money < moneyAvg/2 {
  723. br.Msg = "单行业占比值不得低于平均值的一半"
  724. br.ErrMsg = "单行业占比值不得低于平均值的一半,Err:" + fmt.Sprint(proportionSum)
  725. return
  726. }
  727. }
  728. itemPermission.ChartPermissionName = v.ChartPermissionName
  729. itemPermission.CreateTime = time.Now()
  730. itemPermission.ModifyTime = time.Now()
  731. itemsPermission = append(itemsPermission, itemPermission)
  732. var userProportionSum float64 // 校验前端传过来的占比使用
  733. for _, v2 := range v.List {
  734. if v2.Proportion < -20 {
  735. br.Msg = "研究员占比值不得小于总额的-20%"
  736. br.ErrMsg = "研究员占比值不得小于总额的20%,Err:" + fmt.Sprint(proportionSum)
  737. return
  738. }
  739. item := new(cygx.CygxAllocationCompanyContract)
  740. item.CompanyContractId = companyContractId
  741. item.AdminId = sysUser.AdminId
  742. item.AdminName = sysUser.RealName
  743. item.Proportion = v2.Proportion
  744. item.Money = v2.Money
  745. item.RealName = v2.RealName
  746. item.ChartPermissionName = v.ChartPermissionName
  747. item.CreateTime = time.Now()
  748. item.ModifyTime = time.Now()
  749. items = append(items, item)
  750. proportionSum += v2.Proportion
  751. userProportionSum += v2.Proportion
  752. }
  753. //先添加0.2%的精度校验
  754. if userProportionSum > (v.Proportion+0.2) || userProportionSum < (v.Proportion-0.2) {
  755. br.Msg = "单行业下的研究员比值之和不等于行业占比值"
  756. br.ErrMsg = "单行业下的研究员比值之和不等于行业占比值"
  757. return
  758. }
  759. }
  760. //先添加0.5%的精度校验
  761. if proportionSum > 100.5 || proportionSum < 99.5 {
  762. br.Msg = "行业总比值相加不等于100%"
  763. br.ErrMsg = "行业总比值相加不等于100%,Err:"
  764. return
  765. }
  766. err = cygx.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
  767. if err != nil {
  768. br.Msg = "操作失败"
  769. br.ErrMsg = "操作失败,AddAndUpdateCygxAllocationCompanyContract Err:" + err.Error()
  770. return
  771. }
  772. br.Ret = 200
  773. br.Success = true
  774. br.IsAddLog = true
  775. br.Msg = "操作成功"
  776. }
  777. // @Title 研究员派点统计
  778. // @Description 研究员派点统计接口
  779. // @Param PageSize query int true "每页数据条数"
  780. // @Param CurrentIndex query int true "当前页页码,从1开始"
  781. // @Param Keyword query string true "客户名称"
  782. // @Param StartDate query string false "开始日期"
  783. // @Param EndDate query string false "结束日期"
  784. // @Param IsExport query bool false "是否导出excel,默认是false"
  785. // @Success 200 {object} cygx.CompanyContractListResp
  786. // @router /allocation/statistics [get]
  787. func (this *ContractAllocationController) CompanyContractStatistics() {
  788. br := new(models.BaseResponse).Init()
  789. defer func() {
  790. this.Data["json"] = br
  791. this.ServeJSON()
  792. }()
  793. sysUser := this.SysUser
  794. if sysUser == nil {
  795. br.Msg = "请登录"
  796. br.ErrMsg = "请登录,SysUser Is Empty"
  797. br.Ret = 408
  798. return
  799. }
  800. keyword := this.GetString("Keyword")
  801. startDate := this.GetString("StartDate")
  802. endDate := this.GetString("EndDate")
  803. if startDate == "" {
  804. startDate = "2015-01-01"
  805. }
  806. //是否导出报表
  807. isExport, _ := this.GetBool("IsExport")
  808. var condition string
  809. var pars []interface{}
  810. if endDate != "" {
  811. condition += ` AND a.start_date >= ? AND a.start_date <= ? `
  812. pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
  813. }
  814. //根据当前角色来获取查询条件
  815. //condition, pars = getQueryParams(condition, pars, sysUser, "c.")
  816. companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
  817. if err != nil {
  818. br.Msg = "获取失败"
  819. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  820. return
  821. }
  822. lencompanyIds := len(companyIds)
  823. if lencompanyIds > 0 {
  824. condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  825. pars = append(pars, companyIds)
  826. }
  827. //关键字搜索
  828. if keyword != "" {
  829. condition += ` and b.company_name like "%` + keyword + `%" `
  830. }
  831. //默认只查询权益 2023-06-01 之后的合同
  832. condition += ` AND c.product_id = ? AND a.start_date > ? `
  833. pars = append(pars, 2, "2023-05-31")
  834. //列表页数据
  835. listContract, err := cygx.GetCompanyContractListJoinCompany(condition, pars, 0, 1000)
  836. if err != nil {
  837. br.Msg = "获取失败"
  838. br.ErrMsg = "获取失败,Err:" + err.Error()
  839. return
  840. }
  841. //return
  842. var companyContractIds []int
  843. companyContractIdBool := make(map[int]bool)
  844. for _, v := range listContract {
  845. companyContractIds = append(companyContractIds, v.CompanyContractId)
  846. }
  847. lenArr := len(companyContractIds)
  848. mapUserAllocation := make(map[string]float64) // 关联合同
  849. mapUserMoney := make(map[string]float64) // 派点金额
  850. mapPermissionAllocation := make(map[string]float64)
  851. mapPermissionMoney := make(map[string]float64)
  852. mapPermissionMoneyAvg := make(map[string]float64)
  853. mapPermissionContract := make(map[string]float64) // 行业关联的合同数量
  854. mapPermissionContractKey := make(map[string]bool) // 行业关联的合同数量键值对
  855. //totalContract := lenArr //所有的关联合同
  856. var totalMoney float64 //所有的关联合同的金额 单位万
  857. if lenArr > 0 {
  858. var conditionAllocation string
  859. var parsAllocation []interface{}
  860. conditionAllocation = ` AND company_contract_id IN(` + utils.GetOrmInReplace(lenArr) + ` ) `
  861. parsAllocation = append(parsAllocation, companyContractIds)
  862. allocationCompanyContractList, err := cygx.GetCygxAllocationCompanyContractList(conditionAllocation, parsAllocation)
  863. if err != nil {
  864. br.Msg = "获取失败"
  865. br.ErrMsg = "获取失败,Err:" + err.Error()
  866. return
  867. }
  868. allocationCompanyContractPermissionList, err := cygx.GetCygxAllocationCompanyContractPermissionList(conditionAllocation, parsAllocation)
  869. if err != nil {
  870. br.Msg = "获取失败"
  871. br.ErrMsg = "获取失败,Err:" + err.Error()
  872. return
  873. }
  874. for _, v := range allocationCompanyContractList {
  875. if v.Proportion != 0 && v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  876. mapUserAllocation[v.RealName] += 1
  877. mapUserMoney[v.RealName] += v.Money
  878. mapPermissionAllocation[v.ChartPermissionName] += 1
  879. mapPermissionMoney[v.ChartPermissionName] += v.Money
  880. totalMoney += v.Money
  881. companyContractIdBool[v.CompanyContractId] = true
  882. //统计单个行业所关的合同数量
  883. if !mapPermissionContractKey[fmt.Sprint("ChartPermissionName_", v.ChartPermissionName, "CompanyContractId_", v.CompanyContractId)] {
  884. mapPermissionContract[v.ChartPermissionName] += 1
  885. mapPermissionContractKey[fmt.Sprint("ChartPermissionName_", v.ChartPermissionName, "CompanyContractId_", v.CompanyContractId)] = true
  886. }
  887. }
  888. }
  889. for _, v := range allocationCompanyContractPermissionList {
  890. mapPermissionMoneyAvg[v.ChartPermissionName] += v.MoneyAvg
  891. }
  892. }
  893. sysUserList, err := cygx.GetAskEmailList()
  894. if err != nil {
  895. br.Msg = "获取失败"
  896. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  897. return
  898. }
  899. mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp) //行业分组 map
  900. for _, v := range sysUserList {
  901. item := new(cygx.AllocationRealNameStatisticsListResp)
  902. item.RealName = v.Name
  903. item.TotalRelatedContract = mapUserAllocation[v.Name]
  904. item.TotalDispatchPoint = utils.SubFloatToString(mapUserMoney[v.Name], 2)
  905. if item.TotalDispatchPoint == "" {
  906. item.TotalDispatchPoint = "0"
  907. }
  908. //组内占比
  909. if mapUserMoney[v.Name] == 0 {
  910. item.GroupProportion = ""
  911. } else {
  912. item.GroupProportion = utils.SubFloatToString(mapUserMoney[v.Name]/mapPermissionMoney[v.ChartPermissionName]*100, 2)
  913. }
  914. if item.GroupProportion == "" {
  915. item.GroupProportion = "0"
  916. }
  917. item.GroupProportion += "%"
  918. //部门占比
  919. if totalMoney == 0 {
  920. item.DepartmentProportion = ""
  921. } else {
  922. item.DepartmentProportion = utils.SubFloatToString(mapUserMoney[v.Name]/totalMoney*100, 2)
  923. }
  924. if item.DepartmentProportion == "" {
  925. item.DepartmentProportion = "0"
  926. }
  927. item.DepartmentProportion += "%"
  928. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  929. }
  930. for k, v := range mapPermissionUser {
  931. lenUser := len(v)
  932. item := new(cygx.AllocationRealNameStatisticsListResp)
  933. item.RealName = "合计"
  934. item.TotalRelatedContract = mapPermissionContract[k]
  935. item.TotalDispatchPoint = fmt.Sprint(utils.SubFloatToString(mapPermissionMoney[k], 2), "/", utils.SubFloatToString(mapPermissionMoneyAvg[k], 2))
  936. item.GroupProportion = "100%"
  937. //部门占比
  938. if totalMoney == 0 {
  939. item.DepartmentProportion = ""
  940. } else {
  941. item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100, 2)
  942. }
  943. if item.DepartmentProportion == "" {
  944. item.DepartmentProportion = "0"
  945. }
  946. item.DepartmentProportion += "%"
  947. mapPermissionUser[k] = append(mapPermissionUser[k], item)
  948. item = new(cygx.AllocationRealNameStatisticsListResp)
  949. item.RealName = "平均"
  950. item.TotalRelatedContract = utils.SubFloatToFloat(mapPermissionAllocation[k]/float64(lenUser), 2)
  951. item.TotalDispatchPoint = utils.SubFloatToString(mapPermissionMoney[k]/float64(lenUser), 2)
  952. //组内占比
  953. if mapPermissionMoney[k] == 0 {
  954. item.GroupProportion = ""
  955. } else {
  956. item.GroupProportion = utils.SubFloatToString(1/(float64(len(mapPermissionUser[k])-1))*100, 2)
  957. }
  958. if item.GroupProportion == "" {
  959. item.GroupProportion = "0"
  960. }
  961. item.GroupProportion += "%"
  962. // 部门占比
  963. if totalMoney == 0 {
  964. item.DepartmentProportion = ""
  965. } else {
  966. item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100/float64(len(mapPermissionUser[k])-1), 2)
  967. }
  968. if item.DepartmentProportion == "" {
  969. item.DepartmentProportion = "0"
  970. }
  971. item.DepartmentProportion += "%"
  972. mapPermissionUser[k] = append(mapPermissionUser[k], item)
  973. }
  974. var list []*cygx.AllocationPermissionStatisticsListResp
  975. permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略"}
  976. for _, v := range permissionNameArr {
  977. item := new(cygx.AllocationPermissionStatisticsListResp)
  978. item.ChartPermissionName = v
  979. item.List = mapPermissionUser[v]
  980. list = append(list, item)
  981. }
  982. resp := cygx.CygxAllocationCompanyContractDetailStatisticsResp{
  983. List: list,
  984. }
  985. resp.TotalContract = len(companyContractIdBool)
  986. resp.TotalMoney = utils.SubFloatToFloat(totalMoney, 2)
  987. //导出excel
  988. if isExport {
  989. CompanyContractStatisticsExport(this, resp, br)
  990. return
  991. }
  992. br.Ret = 200
  993. br.Success = true
  994. br.Msg = "获取成功"
  995. br.Data = resp
  996. }
  997. // CompanyContractStatisticsExport 导出Excel
  998. func CompanyContractStatisticsExport(this *ContractAllocationController, resp cygx.CygxAllocationCompanyContractDetailStatisticsResp, br *models.BaseResponse) {
  999. dir, err := os.Executable()
  1000. exPath := filepath.Dir(dir)
  1001. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1002. xlsxFile := xlsx.NewFile()
  1003. if err != nil {
  1004. br.Msg = "生成文件失败"
  1005. br.ErrMsg = "生成文件失败"
  1006. return
  1007. }
  1008. style := xlsx.NewStyle()
  1009. alignment := xlsx.Alignment{
  1010. Horizontal: "center",
  1011. Vertical: "center",
  1012. WrapText: true,
  1013. }
  1014. style.Alignment = alignment
  1015. style.ApplyAlignment = true
  1016. sheel, err := xlsxFile.AddSheet("研究员派点统计")
  1017. if err != nil {
  1018. br.Msg = "新增Sheet失败"
  1019. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1020. return
  1021. }
  1022. sheel.SetColWidth(0, 0, 30)
  1023. sheel.SetColWidth(1, 1, 15)
  1024. sheel.SetColWidth(2, 2, 15)
  1025. sheel.SetColWidth(3, 3, 18)
  1026. titleRow := sheel.AddRow()
  1027. cellA := titleRow.AddCell()
  1028. cellA.SetStyle(style)
  1029. cellA.SetValue("组别")
  1030. cellB := titleRow.AddCell()
  1031. cellB.SetStyle(style)
  1032. cellB.SetValue("研究员")
  1033. cellC := titleRow.AddCell()
  1034. cellC.SetStyle(style)
  1035. cellC.SetValue("关联合同")
  1036. cellD := titleRow.AddCell()
  1037. cellD.SetStyle(style)
  1038. cellD.SetValue("总派点")
  1039. cellE := titleRow.AddCell()
  1040. cellE.SetStyle(style)
  1041. cellE.SetValue("组内占比")
  1042. cellF := titleRow.AddCell()
  1043. cellF.SetStyle(style)
  1044. cellF.SetValue("部门占比")
  1045. for _, v := range resp.List {
  1046. for k2, v2 := range v.List {
  1047. dataRow := sheel.AddRow()
  1048. dataRow.SetHeight(20)
  1049. cellA := dataRow.AddCell()
  1050. cellA.SetStyle(style)
  1051. cellA.SetValue(v.ChartPermissionName)
  1052. if k2 < len(v.List)-1 {
  1053. cellA.VMerge = 1
  1054. }
  1055. cellB := dataRow.AddCell()
  1056. cellB.SetStyle(style)
  1057. cellB.SetValue(v2.RealName)
  1058. cellC := dataRow.AddCell()
  1059. cellC.SetStyle(style)
  1060. cellC.SetValue(v2.TotalRelatedContract)
  1061. cellD := dataRow.AddCell()
  1062. cellD.SetStyle(style)
  1063. cellD.SetValue(v2.TotalDispatchPoint)
  1064. cellE := dataRow.AddCell()
  1065. cellE.SetStyle(style)
  1066. cellE.SetValue(v2.GroupProportion)
  1067. cellF := dataRow.AddCell()
  1068. cellF.SetStyle(style)
  1069. cellF.SetValue(v2.DepartmentProportion)
  1070. }
  1071. }
  1072. titleRow = sheel.AddRow()
  1073. cellA = titleRow.AddCell()
  1074. cellA.HMerge = 1
  1075. cellA.SetStyle(style)
  1076. cellA.SetValue("部门合计")
  1077. cellB = titleRow.AddCell()
  1078. cellB.SetStyle(style)
  1079. cellB.SetValue("")
  1080. cellC = titleRow.AddCell()
  1081. cellC.SetStyle(style)
  1082. cellC.SetValue(resp.TotalContract)
  1083. cellD = titleRow.AddCell()
  1084. cellD.SetStyle(style)
  1085. cellD.SetValue(resp.TotalMoney)
  1086. cellE = titleRow.AddCell()
  1087. cellE.SetStyle(style)
  1088. cellE.SetValue("-")
  1089. cellF = titleRow.AddCell()
  1090. cellF.SetStyle(style)
  1091. cellF.SetValue("100%")
  1092. err = xlsxFile.Save(downLoadnFilePath)
  1093. if err != nil {
  1094. br.Msg = "保存文件失败"
  1095. br.ErrMsg = "保存文件失败"
  1096. return
  1097. }
  1098. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1099. downloadFileName := "研究员派点统计_" + randStr + ".xlsx"
  1100. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1101. defer func() {
  1102. os.Remove(downLoadnFilePath)
  1103. }()
  1104. br.Ret = 200
  1105. br.Success = true
  1106. br.Msg = "导出成功"
  1107. }