contract_allocation.go 36 KB

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