contract_allocation.go 35 KB

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