contract_allocation.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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)"} // 买方研选价格
  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. for _, p := range hasPermissions {
  468. hasMap[p.ChartPermissionId] = p
  469. }
  470. raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  471. if e != nil {
  472. br.Msg = "获取失败"
  473. br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  474. return
  475. }
  476. mapPermissionNameHave := make(map[string]bool) // 判断合同是否存在某一行业权限种类
  477. var expensiveYx int
  478. for _, n := range raiPermissions {
  479. match := hasMap[n.ChartPermissionId]
  480. if match == nil {
  481. continue
  482. }
  483. mapPermissionNameHave[n.PermissionName] = true
  484. // 买方研选(3w/5w)
  485. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  486. expensiveYx = match.ExpensiveYx
  487. n.PermissionName += expMap[match.ExpensiveYx]
  488. continue
  489. }
  490. }
  491. resp.Money = contractItem.Money / 10000
  492. //有研选时,对研选套餐类型做文案处理
  493. respItemYx := new(cygx.AllocationPermissionListResp)
  494. if mapPermissionNameHave[utils.CHART_PERMISSION_NAME_MF_YANXUAN] {
  495. var moneyYx float64
  496. if expensiveYx == 0 {
  497. moneyYx = 3
  498. }
  499. if expensiveYx == 1 {
  500. moneyYx = 5
  501. }
  502. resp.TotalPointsContent = fmt.Sprint(resp.Money, "W,", "其中", moneyYx, "w默认归属买方研选,请对剩余", resp.Money-moneyYx, "w按照100%进行比值分配")
  503. if showDetail {
  504. resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
  505. }
  506. resp.Money = resp.Money - moneyYx
  507. respItemYx.Proportion = 0
  508. respItemYx.Money = moneyYx
  509. respItemYx.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  510. respItemYx.List = append(respItemYx.List, &cygx.AllocationRealNameListResp{utils.CHART_PERMISSION_NAME_MF_YANXUAN, 0, moneyYx})
  511. } else {
  512. resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
  513. }
  514. sysUserList, err := cygx.GetAskEmailList()
  515. if err != nil {
  516. br.Msg = "获取失败"
  517. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  518. return
  519. }
  520. mapPermissionUser := make(map[string][]*cygx.AllocationRealNameListResp)
  521. var respList []*cygx.AllocationPermissionListResp
  522. if total == 0 {
  523. for _, v := range sysUserList {
  524. if !mapPermissionNameHave[v.ChartPermissionName] {
  525. continue
  526. }
  527. item := new(cygx.AllocationRealNameListResp)
  528. item.RealName = v.Name
  529. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  530. }
  531. for k, v := range mapPermissionUser {
  532. respItem := new(cygx.AllocationPermissionListResp)
  533. respItem.ChartPermissionName = k
  534. respItem.List = v
  535. respList = append(respList, respItem)
  536. }
  537. if respItemYx.ChartPermissionName != "" {
  538. respList = append(respList, respItemYx)
  539. }
  540. } else {
  541. listUser, err := cygx.GetCygxAllocationCompanyContractListById(companyContractId)
  542. if err != nil {
  543. br.Msg = "获取失败"
  544. br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractListById Err: " + err.Error()
  545. return
  546. }
  547. for _, v := range listUser {
  548. if showDetail && v.Money == 0 {
  549. continue
  550. }
  551. item := new(cygx.AllocationRealNameListResp)
  552. item.RealName = v.RealName
  553. item.Money = v.Money
  554. item.Proportion = v.Proportion
  555. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  556. }
  557. listPermission, err := cygx.GetCygxAllocationCompanyContractPermissionListById(companyContractId)
  558. if err != nil {
  559. br.Msg = "获取失败"
  560. br.ErrMsg = "获取失败,GetCygxAllocationCompanyContractPermissionListById Err: " + err.Error()
  561. return
  562. }
  563. for _, v := range listPermission {
  564. if showDetail && v.Money == 0 {
  565. continue
  566. }
  567. respItem := new(cygx.AllocationPermissionListResp)
  568. respItem.ChartPermissionName = v.ChartPermissionName
  569. respItem.Money = v.Money
  570. respItem.Proportion = v.Proportion
  571. respItem.List = mapPermissionUser[v.ChartPermissionName]
  572. respList = append(respList, respItem)
  573. }
  574. }
  575. //处理是否置灰
  576. mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
  577. if err != nil {
  578. br.Msg = "获取合同列表失败!"
  579. br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
  580. return
  581. }
  582. permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略", "买方研选"}
  583. for _, v := range permissionNameArr {
  584. for _, v2 := range respList {
  585. if v2.ChartPermissionName == v {
  586. resp.List = append(resp.List, v2)
  587. }
  588. }
  589. }
  590. resp.IsGray = mapIsGray[companyContractId]
  591. //resp.List = respList
  592. resp.CompanyContractId = companyContractId
  593. br.Ret = 200
  594. br.Success = true
  595. br.Msg = "获取成功"
  596. br.Data = resp
  597. }
  598. // @Title 更新派点
  599. // @Description 更新派点接口
  600. // @Param request body cygx.AddProductInteriorReq true "type json string"
  601. // @Success 200 {object} "保存成功"
  602. // @router /allocation/update [post]
  603. func (this *ContractAllocationController) CompanyContracUpdate() {
  604. br := new(models.BaseResponse).Init()
  605. defer func() {
  606. this.Data["json"] = br
  607. this.ServeJSON()
  608. }()
  609. sysUser := this.SysUser
  610. if sysUser == nil {
  611. br.Msg = "请登录"
  612. br.ErrMsg = "请登录,SysUser Is Empty"
  613. br.Ret = 408
  614. return
  615. }
  616. var req cygx.UpdateAllocationCompanyContractReq
  617. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  618. if err != nil {
  619. br.Msg = "参数解析异常!"
  620. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  621. return
  622. }
  623. companyContractId := req.CompanyContractId
  624. if companyContractId == 0 {
  625. br.Msg = "参数错误"
  626. br.ErrMsg = "参数错误,id不可为空"
  627. return
  628. }
  629. mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
  630. if err != nil {
  631. br.Msg = "获取合同列表失败!"
  632. br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
  633. return
  634. }
  635. if mapIsGray[companyContractId] {
  636. br.Msg = "超过180天,无法修改!"
  637. br.ErrMsg = "超过180天,无法修改,companyContractId :" + strconv.Itoa(companyContractId)
  638. return
  639. }
  640. contractItem, err := company.GetCompanyContractById(companyContractId)
  641. if err != nil {
  642. br.Msg = "获取信息失败"
  643. br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  644. return
  645. }
  646. money := contractItem.Money / 10000 // 合同金额,万为单位
  647. var moneyAvg float64 // 行业所占合同的平均金额
  648. hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
  649. if e != nil {
  650. br.Msg = "获取失败"
  651. br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
  652. return
  653. }
  654. hasMap := make(map[int]*company.CompanyContractPermission)
  655. for _, p := range hasPermissions {
  656. hasMap[p.ChartPermissionId] = p
  657. }
  658. raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  659. if e != nil {
  660. br.Msg = "获取失败"
  661. br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  662. return
  663. }
  664. mapPermissionNameHave := make(map[string]bool) // 判断合同是否存在某一行业权限种类
  665. for _, n := range raiPermissions {
  666. //只计算,医药、消费、科技、智造、策略、买方研选的
  667. 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 {
  668. continue
  669. }
  670. match := hasMap[n.ChartPermissionId]
  671. if match == nil {
  672. continue
  673. }
  674. // 买方研选(3w/5w)
  675. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  676. if match.ExpensiveYx == 1 {
  677. money = money - 5
  678. } else {
  679. money = money - 3
  680. }
  681. } else {
  682. mapPermissionNameHave[n.PermissionName] = true
  683. }
  684. }
  685. if len(mapPermissionNameHave) > 0 {
  686. moneyAvg = money / float64(len(mapPermissionNameHave))
  687. }
  688. list := req.List
  689. var items []*cygx.CygxAllocationCompanyContract
  690. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  691. var proportionSum float64 // 校验前端传过来的占比使用
  692. for _, v := range list {
  693. itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
  694. itemPermission.CompanyContractId = companyContractId
  695. itemPermission.AdminId = sysUser.AdminId
  696. itemPermission.AdminName = sysUser.RealName
  697. itemPermission.Proportion = v.Proportion
  698. itemPermission.Money = v.Money
  699. if v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  700. itemPermission.MoneyAvg = moneyAvg
  701. if v.Money < moneyAvg/2 {
  702. br.Msg = "单行业占比值不得低于平均值的一半"
  703. br.ErrMsg = "单行业占比值不得低于平均值的一半,Err:" + fmt.Sprint(proportionSum)
  704. return
  705. }
  706. }
  707. itemPermission.ChartPermissionName = v.ChartPermissionName
  708. itemPermission.CreateTime = time.Now()
  709. itemPermission.ModifyTime = time.Now()
  710. itemsPermission = append(itemsPermission, itemPermission)
  711. var userProportionSum float64 // 校验前端传过来的占比使用
  712. for _, v2 := range v.List {
  713. if v2.Proportion < -20 {
  714. br.Msg = "研究员占比值不得小于总额的-20%"
  715. br.ErrMsg = "研究员占比值不得小于总额的20%,Err:" + fmt.Sprint(proportionSum)
  716. return
  717. }
  718. item := new(cygx.CygxAllocationCompanyContract)
  719. item.CompanyContractId = companyContractId
  720. item.AdminId = sysUser.AdminId
  721. item.AdminName = sysUser.RealName
  722. item.Proportion = v2.Proportion
  723. item.Money = v2.Money
  724. item.RealName = v2.RealName
  725. item.ChartPermissionName = v.ChartPermissionName
  726. item.CreateTime = time.Now()
  727. item.ModifyTime = time.Now()
  728. items = append(items, item)
  729. proportionSum += v2.Proportion
  730. userProportionSum += v2.Proportion
  731. }
  732. //先添加0.2%的精度校验
  733. if userProportionSum > (v.Proportion+0.2) || userProportionSum < (v.Proportion-0.2) {
  734. br.Msg = "单行业下的研究员比值之和不等于行业占比值"
  735. br.ErrMsg = "单行业下的研究员比值之和不等于行业占比值"
  736. return
  737. }
  738. }
  739. //先添加0.5%的精度校验
  740. if proportionSum > 100.5 || proportionSum < 99.5 {
  741. br.Msg = "行业总比值相加不等于100%"
  742. br.ErrMsg = "行业总比值相加不等于100%,Err:"
  743. return
  744. }
  745. err = cygx.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
  746. if err != nil {
  747. br.Msg = "操作失败"
  748. br.ErrMsg = "操作失败,AddAndUpdateCygxAllocationCompanyContract Err:" + err.Error()
  749. return
  750. }
  751. br.Ret = 200
  752. br.Success = true
  753. br.IsAddLog = true
  754. br.Msg = "操作成功"
  755. }
  756. // @Title 研究员派点统计
  757. // @Description 研究员派点统计接口
  758. // @Param PageSize query int true "每页数据条数"
  759. // @Param CurrentIndex query int true "当前页页码,从1开始"
  760. // @Param Keyword query string true "客户名称"
  761. // @Param StartDate query string false "开始日期"
  762. // @Param EndDate query string false "结束日期"
  763. // @Param IsExport query bool false "是否导出excel,默认是false"
  764. // @Success 200 {object} cygx.CompanyContractListResp
  765. // @router /allocation/statistics [get]
  766. func (this *ContractAllocationController) CompanyContractStatistics() {
  767. br := new(models.BaseResponse).Init()
  768. defer func() {
  769. this.Data["json"] = br
  770. this.ServeJSON()
  771. }()
  772. sysUser := this.SysUser
  773. if sysUser == nil {
  774. br.Msg = "请登录"
  775. br.ErrMsg = "请登录,SysUser Is Empty"
  776. br.Ret = 408
  777. return
  778. }
  779. keyword := this.GetString("Keyword")
  780. startDate := this.GetString("StartDate")
  781. endDate := this.GetString("EndDate")
  782. if startDate == "" {
  783. startDate = "2015-01-01"
  784. }
  785. //是否导出报表
  786. isExport, _ := this.GetBool("IsExport")
  787. var condition string
  788. var pars []interface{}
  789. if endDate != "" {
  790. condition += ` AND a.start_date >= ? AND a.start_date <= ? `
  791. pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
  792. }
  793. //根据当前角色来获取查询条件
  794. //condition, pars = getQueryParams(condition, pars, sysUser, "c.")
  795. companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
  796. if err != nil {
  797. br.Msg = "获取失败"
  798. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  799. return
  800. }
  801. lencompanyIds := len(companyIds)
  802. if lencompanyIds > 0 {
  803. condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  804. pars = append(pars, companyIds)
  805. }
  806. //关键字搜索
  807. if keyword != "" {
  808. condition += ` and b.company_name like "%` + keyword + `%" `
  809. }
  810. //默认只查询权益 2023-06-01 之后的合同
  811. condition += ` AND c.product_id = ? AND a.start_date > ? `
  812. pars = append(pars, 2, "2023-05-31")
  813. //列表页数据
  814. listContract, err := cygx.GetCompanyContractListJoinCompany(condition, pars, 0, 1000)
  815. if err != nil {
  816. br.Msg = "获取失败"
  817. br.ErrMsg = "获取失败,Err:" + err.Error()
  818. return
  819. }
  820. //return
  821. var companyContractIds []int
  822. companyContractIdBool := make(map[int]bool)
  823. for _, v := range listContract {
  824. companyContractIds = append(companyContractIds, v.CompanyContractId)
  825. }
  826. lenArr := len(companyContractIds)
  827. mapUserAllocation := make(map[string]float64) // 关联合同
  828. mapUserMoney := make(map[string]float64) // 派点金额
  829. mapPermissionAllocation := make(map[string]float64)
  830. mapPermissionMoney := make(map[string]float64)
  831. mapPermissionMoneyAvg := make(map[string]float64)
  832. //totalContract := lenArr //所有的关联合同
  833. var totalMoney float64 //所有的关联合同的金额 单位万
  834. if lenArr > 0 {
  835. var conditionAllocation string
  836. var parsAllocation []interface{}
  837. conditionAllocation = ` AND company_contract_id IN(` + utils.GetOrmInReplace(lenArr) + ` ) `
  838. parsAllocation = append(parsAllocation, companyContractIds)
  839. allocationCompanyContractList, err := cygx.GetCygxAllocationCompanyContractList(conditionAllocation, parsAllocation)
  840. if err != nil {
  841. br.Msg = "获取失败"
  842. br.ErrMsg = "获取失败,Err:" + err.Error()
  843. return
  844. }
  845. allocationCompanyContractPermissionList, err := cygx.GetCygxAllocationCompanyContractPermissionList(conditionAllocation, parsAllocation)
  846. if err != nil {
  847. br.Msg = "获取失败"
  848. br.ErrMsg = "获取失败,Err:" + err.Error()
  849. return
  850. }
  851. for _, v := range allocationCompanyContractList {
  852. if v.Proportion != 0 && v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  853. mapUserAllocation[v.RealName] += 1
  854. mapUserMoney[v.RealName] += v.Money
  855. mapPermissionAllocation[v.ChartPermissionName] += 1
  856. mapPermissionMoney[v.ChartPermissionName] += v.Money
  857. totalMoney += v.Money
  858. companyContractIdBool[v.CompanyContractId] = true
  859. }
  860. }
  861. for _, v := range allocationCompanyContractPermissionList {
  862. mapPermissionMoneyAvg[v.ChartPermissionName] += v.MoneyAvg
  863. }
  864. }
  865. sysUserList, err := cygx.GetAskEmailList()
  866. if err != nil {
  867. br.Msg = "获取失败"
  868. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  869. return
  870. }
  871. mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp) //行业分组 map
  872. for _, v := range sysUserList {
  873. item := new(cygx.AllocationRealNameStatisticsListResp)
  874. item.RealName = v.Name
  875. item.TotalRelatedContract = mapUserAllocation[v.Name]
  876. item.TotalDispatchPoint = utils.SubFloatToString(mapUserMoney[v.Name], 2)
  877. if item.TotalDispatchPoint == "" {
  878. item.TotalDispatchPoint = "0"
  879. }
  880. //组内占比
  881. if mapUserMoney[v.Name] == 0 {
  882. item.GroupProportion = ""
  883. } else {
  884. item.GroupProportion = utils.SubFloatToString(mapUserMoney[v.Name]/mapPermissionMoney[v.ChartPermissionName]*100, 2)
  885. }
  886. if item.GroupProportion == "" {
  887. item.GroupProportion = "0"
  888. }
  889. item.GroupProportion += "%"
  890. //部门占比
  891. if totalMoney == 0 {
  892. item.DepartmentProportion = ""
  893. } else {
  894. item.DepartmentProportion = utils.SubFloatToString(mapUserMoney[v.Name]/totalMoney*100, 2)
  895. }
  896. if item.DepartmentProportion == "" {
  897. item.DepartmentProportion = "0"
  898. }
  899. item.DepartmentProportion += "%"
  900. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  901. }
  902. for k, v := range mapPermissionUser {
  903. lenUser := len(v)
  904. item := new(cygx.AllocationRealNameStatisticsListResp)
  905. item.RealName = "合计"
  906. item.TotalRelatedContract = mapPermissionAllocation[k]
  907. item.TotalDispatchPoint = fmt.Sprint(utils.SubFloatToString(mapPermissionMoney[k], 2), "/", utils.SubFloatToString(mapPermissionMoneyAvg[k], 2))
  908. item.GroupProportion = "100%"
  909. //部门占比
  910. if totalMoney == 0 {
  911. item.DepartmentProportion = ""
  912. } else {
  913. item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100, 2)
  914. }
  915. if item.DepartmentProportion == "" {
  916. item.DepartmentProportion = "0"
  917. }
  918. item.DepartmentProportion += "%"
  919. mapPermissionUser[k] = append(mapPermissionUser[k], item)
  920. item = new(cygx.AllocationRealNameStatisticsListResp)
  921. item.RealName = "平均"
  922. item.TotalRelatedContract = utils.SubFloatToFloat(mapPermissionAllocation[k]/float64(lenUser), 2)
  923. item.TotalDispatchPoint = utils.SubFloatToString(mapPermissionMoney[k]/float64(lenUser), 2)
  924. //组内占比
  925. if mapPermissionMoney[k] == 0 {
  926. item.GroupProportion = ""
  927. } else {
  928. item.GroupProportion = utils.SubFloatToString(1/(float64(len(mapPermissionUser[k])-1))*100, 2)
  929. }
  930. if item.GroupProportion == "" {
  931. item.GroupProportion = "0"
  932. }
  933. item.GroupProportion += "%"
  934. // 部门占比
  935. if totalMoney == 0 {
  936. item.DepartmentProportion = ""
  937. } else {
  938. item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100/float64(len(mapPermissionUser[k])-1), 2)
  939. }
  940. if item.DepartmentProportion == "" {
  941. item.DepartmentProportion = "0"
  942. }
  943. item.DepartmentProportion += "%"
  944. mapPermissionUser[k] = append(mapPermissionUser[k], item)
  945. }
  946. var list []*cygx.AllocationPermissionStatisticsListResp
  947. permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略"}
  948. for _, v := range permissionNameArr {
  949. item := new(cygx.AllocationPermissionStatisticsListResp)
  950. item.ChartPermissionName = v
  951. item.List = mapPermissionUser[v]
  952. list = append(list, item)
  953. }
  954. resp := cygx.CygxAllocationCompanyContractDetailStatisticsResp{
  955. List: list,
  956. }
  957. resp.TotalContract = len(companyContractIdBool)
  958. resp.TotalMoney = utils.SubFloatToFloat(totalMoney, 2)
  959. //导出excel
  960. if isExport {
  961. CompanyContractStatisticsExport(this, resp, br)
  962. return
  963. }
  964. br.Ret = 200
  965. br.Success = true
  966. br.Msg = "获取成功"
  967. br.Data = resp
  968. }
  969. // CompanyContractStatisticsExport 导出Excel
  970. func CompanyContractStatisticsExport(this *ContractAllocationController, resp cygx.CygxAllocationCompanyContractDetailStatisticsResp, br *models.BaseResponse) {
  971. dir, err := os.Executable()
  972. exPath := filepath.Dir(dir)
  973. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  974. xlsxFile := xlsx.NewFile()
  975. if err != nil {
  976. br.Msg = "生成文件失败"
  977. br.ErrMsg = "生成文件失败"
  978. return
  979. }
  980. style := xlsx.NewStyle()
  981. alignment := xlsx.Alignment{
  982. Horizontal: "center",
  983. Vertical: "center",
  984. WrapText: true,
  985. }
  986. style.Alignment = alignment
  987. style.ApplyAlignment = true
  988. sheel, err := xlsxFile.AddSheet("研究员派点统计")
  989. if err != nil {
  990. br.Msg = "新增Sheet失败"
  991. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  992. return
  993. }
  994. sheel.SetColWidth(0, 0, 30)
  995. sheel.SetColWidth(1, 1, 15)
  996. sheel.SetColWidth(2, 2, 15)
  997. sheel.SetColWidth(3, 3, 18)
  998. titleRow := sheel.AddRow()
  999. cellA := titleRow.AddCell()
  1000. cellA.SetStyle(style)
  1001. cellA.SetValue("组别")
  1002. cellB := titleRow.AddCell()
  1003. cellB.SetStyle(style)
  1004. cellB.SetValue("研究员")
  1005. cellC := titleRow.AddCell()
  1006. cellC.SetStyle(style)
  1007. cellC.SetValue("关联合同")
  1008. cellD := titleRow.AddCell()
  1009. cellD.SetStyle(style)
  1010. cellD.SetValue("总派点")
  1011. cellE := titleRow.AddCell()
  1012. cellE.SetStyle(style)
  1013. cellE.SetValue("组内占比")
  1014. cellF := titleRow.AddCell()
  1015. cellF.SetStyle(style)
  1016. cellF.SetValue("部门占比")
  1017. for _, v := range resp.List {
  1018. for k2, v2 := range v.List {
  1019. dataRow := sheel.AddRow()
  1020. dataRow.SetHeight(20)
  1021. cellA := dataRow.AddCell()
  1022. cellA.SetStyle(style)
  1023. cellA.SetValue(v.ChartPermissionName)
  1024. if k2 < len(v.List)-1 {
  1025. cellA.VMerge = 1
  1026. }
  1027. cellB := dataRow.AddCell()
  1028. cellB.SetStyle(style)
  1029. cellB.SetValue(v2.RealName)
  1030. cellC := dataRow.AddCell()
  1031. cellC.SetStyle(style)
  1032. cellC.SetValue(v2.TotalRelatedContract)
  1033. cellD := dataRow.AddCell()
  1034. cellD.SetStyle(style)
  1035. cellD.SetValue(v2.TotalDispatchPoint)
  1036. cellE := dataRow.AddCell()
  1037. cellE.SetStyle(style)
  1038. cellE.SetValue(v2.GroupProportion)
  1039. cellF := dataRow.AddCell()
  1040. cellF.SetStyle(style)
  1041. cellF.SetValue(v2.DepartmentProportion)
  1042. }
  1043. }
  1044. titleRow = sheel.AddRow()
  1045. cellA = titleRow.AddCell()
  1046. cellA.HMerge = 1
  1047. cellA.SetStyle(style)
  1048. cellA.SetValue("部门合计")
  1049. cellB = titleRow.AddCell()
  1050. cellB.SetStyle(style)
  1051. cellB.SetValue("")
  1052. cellC = titleRow.AddCell()
  1053. cellC.SetStyle(style)
  1054. cellC.SetValue(resp.TotalContract)
  1055. cellD = titleRow.AddCell()
  1056. cellD.SetStyle(style)
  1057. cellD.SetValue(resp.TotalMoney)
  1058. cellE = titleRow.AddCell()
  1059. cellE.SetStyle(style)
  1060. cellE.SetValue("-")
  1061. cellF = titleRow.AddCell()
  1062. cellF.SetStyle(style)
  1063. cellF.SetValue("100%")
  1064. err = xlsxFile.Save(downLoadnFilePath)
  1065. if err != nil {
  1066. br.Msg = "保存文件失败"
  1067. br.ErrMsg = "保存文件失败"
  1068. return
  1069. }
  1070. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1071. downloadFileName := "研究员派点统计_" + randStr + ".xlsx"
  1072. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1073. defer func() {
  1074. os.Remove(downLoadnFilePath)
  1075. }()
  1076. br.Ret = 200
  1077. br.Success = true
  1078. br.Msg = "导出成功"
  1079. }