contract_allocation.go 36 KB

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