contract_allocation.go 35 KB

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