contract_allocation.go 36 KB

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