|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
"hongze/hz_crm_api/controllers"
|
|
|
"hongze/hz_crm_api/models"
|
|
|
"hongze/hz_crm_api/models/company"
|
|
@@ -12,7 +13,8 @@ import (
|
|
|
"hongze/hz_crm_api/models/system"
|
|
|
cygxService "hongze/hz_crm_api/services/cygx"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
- "math"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -139,9 +141,7 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
if startDate == "" {
|
|
|
startDate = "2015-01-01"
|
|
|
}
|
|
|
- if endDate == "" {
|
|
|
- endDate = time.Now().Format(utils.FormatDate)
|
|
|
- }
|
|
|
+
|
|
|
var startSize int
|
|
|
if pageSize <= 0 {
|
|
|
pageSize = utils.PageSize20
|
|
@@ -160,15 +160,28 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
var condition string
|
|
|
var pars []interface{}
|
|
|
|
|
|
+ if endDate != "" {
|
|
|
+ condition += ` AND a.start_date >= ? AND a.start_date <= ? `
|
|
|
+ pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
|
|
|
+ }
|
|
|
+
|
|
|
//条件
|
|
|
if adminId != "" {
|
|
|
condition += ` AND c.seller_id in (` + adminId + `) `
|
|
|
//pars = append(pars, adminId)
|
|
|
- } else {
|
|
|
-
|
|
|
- //根据当前角色来获取查询条件
|
|
|
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
|
|
|
+ }
|
|
|
|
|
|
+ //权益申请销售只能看到自己名下的客户的申请
|
|
|
+ companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lencompanyIds := len(companyIds)
|
|
|
+ if lencompanyIds > 0 {
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
|
|
|
+ pars = append(pars, companyIds)
|
|
|
}
|
|
|
|
|
|
//关键字搜索
|
|
@@ -178,7 +191,7 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
|
|
|
//是否派点
|
|
|
if isAllocation != -1 {
|
|
|
- condition += ` AND a.product_id = ? `
|
|
|
+ condition += ` AND a.is_allocation = ? `
|
|
|
pars = append(pars, isAllocation)
|
|
|
}
|
|
|
|
|
@@ -199,7 +212,7 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
|
|
|
//默认只查询权益 2023-06-01 之后的合同
|
|
|
condition += ` AND c.product_id = ? AND a.start_date > ? `
|
|
|
- pars = append(pars, 2, "2023-01-01")
|
|
|
+ pars = append(pars, 2, "2023-06-01")
|
|
|
|
|
|
mapMoneyPoint := make(map[int]float64)
|
|
|
//研究员姓名查询
|
|
@@ -207,7 +220,7 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
var conditionAllocation string
|
|
|
var parsAllocation []interface{}
|
|
|
|
|
|
- conditionAllocation = " AND real_name = ? "
|
|
|
+ conditionAllocation = " AND real_name = ? AND money != 0 "
|
|
|
parsAllocation = append(parsAllocation, researcherRealName)
|
|
|
allocationCompanyContractList, err := cygx.GetCygxAllocationCompanyContractList(conditionAllocation, parsAllocation)
|
|
|
if err != nil {
|
|
@@ -244,13 +257,14 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- mapCompamy := make(map[int]string)
|
|
|
+ //mapCompamy := make(map[int]string)
|
|
|
listLen := len(list)
|
|
|
if listLen == 0 {
|
|
|
list = make([]*cygx.CompanyContractResp, 0)
|
|
|
} else {
|
|
|
|
|
|
var contractCodes []string
|
|
|
+ var companyContractIds []int
|
|
|
for _, v := range list {
|
|
|
switch v.Source {
|
|
|
case "系统合同":
|
|
@@ -259,40 +273,49 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
v.FormalType = "非标"
|
|
|
}
|
|
|
contractCodes = append(contractCodes, v.ContractCode)
|
|
|
- mapCompamy[v.CompanyId] = strconv.Itoa(v.CompanyContractId)
|
|
|
-
|
|
|
- lencontractCodes := len(contractCodes)
|
|
|
- if lencontractCodes > 0 {
|
|
|
- //获取标准合同的ID,这里上面的查询已经关联了三张表,拆分吧。。。
|
|
|
- condition = ""
|
|
|
- joinStr := ""
|
|
|
- pars = make([]interface{}, 0)
|
|
|
- condition = " AND a.contract_code IN (" + utils.GetOrmInReplace(lencontractCodes) + ") "
|
|
|
- pars = append(pars, contractCodes)
|
|
|
- listContract, err := contract.GetContractList(condition, joinStr, pars, 0, lencontractCodes)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取合同列表失败!"
|
|
|
- br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- mapContractCode := make(map[string]int)
|
|
|
- for _, v := range listContract {
|
|
|
- mapContractCode[v.ContractCode] = v.ContractId
|
|
|
- }
|
|
|
+ companyContractIds = append(companyContractIds, v.CompanyContractId)
|
|
|
+ //mapCompamy[v.CompanyId] = strconv.Itoa(v.CompanyContractId)
|
|
|
+ }
|
|
|
+ lencontractCodes := len(contractCodes)
|
|
|
+ if lencontractCodes > 0 {
|
|
|
+ //获取标准合同的ID,这里上面的查询已经关联了三张表,拆分吧。。。
|
|
|
+ condition = ""
|
|
|
+ joinStr := ""
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = " AND a.contract_code IN (" + utils.GetOrmInReplace(lencontractCodes) + ") "
|
|
|
+ pars = append(pars, contractCodes)
|
|
|
+ listContract, err := contract.GetContractList(condition, joinStr, pars, 0, lencontractCodes)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取合同列表失败!"
|
|
|
+ br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- //合并合同所对应的权限
|
|
|
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(mapCompamy)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
+ mapContractCode := make(map[string]int)
|
|
|
+ for _, v := range listContract {
|
|
|
+ mapContractCode[v.ContractCode] = v.ContractId
|
|
|
+ }
|
|
|
|
|
|
- for _, v := range list {
|
|
|
- v.ContractId = mapContractCode[v.ContractCode]
|
|
|
- v.MoneyPoint = mapMoneyPoint[v.CompanyContractId]
|
|
|
- v.PermissionName = mappermissionName[v.CompanyId]
|
|
|
- }
|
|
|
+ mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds(companyContractIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取合同列表失败!"
|
|
|
+ br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并合同所对应的权限
|
|
|
+ mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range list {
|
|
|
+ v.ContractId = mapContractCode[v.ContractCode]
|
|
|
+ v.MoneyPoint = mapMoneyPoint[v.CompanyContractId]
|
|
|
+ v.PermissionName = mappermissionName[v.CompanyContractId]
|
|
|
+ v.IsGray = mapIsGray[v.CompanyContractId]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -302,10 +325,9 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
Paging: page,
|
|
|
List: list,
|
|
|
}
|
|
|
-
|
|
|
//导出excel
|
|
|
if isExport {
|
|
|
- //IncrementalCompanyListExport(this, dataType, resp, br)
|
|
|
+ CompanyContractListExport(this, resp, br)
|
|
|
return
|
|
|
}
|
|
|
br.Ret = 200
|
|
@@ -314,6 +336,137 @@ func (this *ContractAllocationController) CompanyContractList() {
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
+// CompanyContractListExport 导出Excel
|
|
|
+func CompanyContractListExport(this *ContractAllocationController, resp cygx.CompanyContractListResp, br *models.BaseResponse) {
|
|
|
+ dir, err := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "生成文件失败"
|
|
|
+ br.ErrMsg = "生成文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+
|
|
|
+ sheel, err := xlsxFile.AddSheet("派点导出数据")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sheel.SetColWidth(0, 0, 30)
|
|
|
+ sheel.SetColWidth(1, 1, 15)
|
|
|
+ sheel.SetColWidth(2, 2, 15)
|
|
|
+ sheel.SetColWidth(3, 3, 18)
|
|
|
+
|
|
|
+ titleRow := sheel.AddRow()
|
|
|
+
|
|
|
+ cellA := titleRow.AddCell()
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue("合同编号")
|
|
|
+
|
|
|
+ cellB := titleRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue("转正类型")
|
|
|
+
|
|
|
+ cellC := titleRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue("合同类型")
|
|
|
+
|
|
|
+ cellD := titleRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue("公司名称")
|
|
|
+
|
|
|
+ cellE := titleRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue("所属销售")
|
|
|
+
|
|
|
+ cellF := titleRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue("合同金额")
|
|
|
+
|
|
|
+ cellG := titleRow.AddCell()
|
|
|
+ cellG.SetStyle(style)
|
|
|
+ cellG.SetValue("合同期限")
|
|
|
+
|
|
|
+ cellH := titleRow.AddCell()
|
|
|
+ cellH.SetStyle(style)
|
|
|
+ cellH.SetValue("签约套餐")
|
|
|
+
|
|
|
+ cellI := titleRow.AddCell()
|
|
|
+ cellI.SetStyle(style)
|
|
|
+ cellI.SetValue("状态")
|
|
|
+
|
|
|
+ for _, v := range resp.List {
|
|
|
+ dataRow := sheel.AddRow()
|
|
|
+ dataRow.SetHeight(20)
|
|
|
+
|
|
|
+ cellA := dataRow.AddCell()
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue(v.ContractCode)
|
|
|
+
|
|
|
+ cellB := dataRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue(v.FormalType)
|
|
|
+
|
|
|
+ cellC := dataRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue(v.ContractType)
|
|
|
+
|
|
|
+ cellD := dataRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue(v.CompanyName)
|
|
|
+
|
|
|
+ cellE := dataRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue(v.SellerName)
|
|
|
+
|
|
|
+ cellF := dataRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue(v.Money)
|
|
|
+
|
|
|
+ cellG := dataRow.AddCell()
|
|
|
+ cellG.SetStyle(style)
|
|
|
+ cellG.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
|
|
|
+
|
|
|
+ cellH := dataRow.AddCell()
|
|
|
+ cellH.SetStyle(style)
|
|
|
+ cellH.SetValue(v.PermissionName)
|
|
|
+
|
|
|
+ cellI := dataRow.AddCell()
|
|
|
+ cellI.SetStyle(style)
|
|
|
+ if v.IsAllocation == 1 {
|
|
|
+ cellI.SetValue("已派点")
|
|
|
+ } else {
|
|
|
+ cellI.SetValue("未派点")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存文件失败"
|
|
|
+ br.ErrMsg = "保存文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ downloadFileName := "派点导出数据_" + randStr + ".xlsx"
|
|
|
+ this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
|
|
|
+ defer func() {
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ }()
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "导出成功"
|
|
|
+}
|
|
|
+
|
|
|
// @Title 详情
|
|
|
// @Description 获取详情接口
|
|
|
// @Param CompanyContractId query int true "ID"
|
|
@@ -355,10 +508,6 @@ func (this *ContractAllocationController) CompanyContracDetail() {
|
|
|
|
|
|
//var contractPermissionList []*company.ContractPermissionList
|
|
|
expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
|
|
|
-
|
|
|
- //classifyName := "权益"
|
|
|
-
|
|
|
- //plist := new(company.ContractPermissionList)
|
|
|
hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
|
|
|
if e != nil {
|
|
|
br.Msg = "获取失败"
|
|
@@ -369,7 +518,7 @@ func (this *ContractAllocationController) CompanyContracDetail() {
|
|
|
for _, p := range hasPermissions {
|
|
|
hasMap[p.ChartPermissionId] = p
|
|
|
}
|
|
|
- checkItems := make([]*company.PermissionLookItem, 0)
|
|
|
+
|
|
|
raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
|
|
|
if e != nil {
|
|
|
br.Msg = "获取失败"
|
|
@@ -383,21 +532,14 @@ func (this *ContractAllocationController) CompanyContracDetail() {
|
|
|
if match == nil {
|
|
|
continue
|
|
|
}
|
|
|
- // 升级
|
|
|
- if match.IsUpgrade == 1 {
|
|
|
- n.IsUpgrade = 1
|
|
|
- checkItems = append(checkItems, n)
|
|
|
- continue
|
|
|
- }
|
|
|
+
|
|
|
mapPermissionNameHave[n.PermissionName] = true
|
|
|
// 买方研选(3w/5w)
|
|
|
if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
|
|
|
expensiveYx = match.ExpensiveYx
|
|
|
n.PermissionName += expMap[match.ExpensiveYx]
|
|
|
- checkItems = append(checkItems, n)
|
|
|
continue
|
|
|
}
|
|
|
- checkItems = append(checkItems, n)
|
|
|
}
|
|
|
|
|
|
resp.Money = contractItem.Money / 10000
|
|
@@ -416,21 +558,19 @@ func (this *ContractAllocationController) CompanyContracDetail() {
|
|
|
resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
|
|
|
}
|
|
|
resp.Money = resp.Money - moneyYx
|
|
|
- respItemYx.Proportion = moneyYx
|
|
|
+ respItemYx.Proportion = 0
|
|
|
+ respItemYx.Money = moneyYx
|
|
|
respItemYx.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
|
|
|
respItemYx.List = append(respItemYx.List, &cygx.AllocationRealNameListResp{utils.CHART_PERMISSION_NAME_MF_YANXUAN, 0, moneyYx})
|
|
|
} else {
|
|
|
resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
|
|
|
}
|
|
|
-
|
|
|
sysUserList, err := cygx.GetAskEmailList()
|
|
|
-
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
mapPermissionUser := make(map[string][]*cygx.AllocationRealNameListResp)
|
|
|
|
|
|
var respList []*cygx.AllocationPermissionListResp
|
|
@@ -488,7 +628,24 @@ func (this *ContractAllocationController) CompanyContracDetail() {
|
|
|
respList = append(respList, respItem)
|
|
|
}
|
|
|
}
|
|
|
- resp.List = respList
|
|
|
+ //处理是否置灰
|
|
|
+ mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取合同列表失败!"
|
|
|
+ br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略", "买方研选"}
|
|
|
+ for _, v := range permissionNameArr {
|
|
|
+ for _, v2 := range respList {
|
|
|
+ if v2.ChartPermissionName == v {
|
|
|
+ resp.List = append(resp.List, v2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resp.IsGray = mapIsGray[companyContractId]
|
|
|
+ //resp.List = respList
|
|
|
resp.CompanyContractId = companyContractId
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
@@ -527,6 +684,17 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
|
|
|
br.ErrMsg = "参数错误,id不可为空"
|
|
|
return
|
|
|
}
|
|
|
+ mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取合同列表失败!"
|
|
|
+ br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if mapIsGray[companyContractId] {
|
|
|
+ br.Msg = "超过180天,无法修改!"
|
|
|
+ br.ErrMsg = "超过180天,无法修改,companyContractId :" + strconv.Itoa(companyContractId)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
contractItem, err := company.GetCompanyContractById(companyContractId)
|
|
|
if err != nil {
|
|
@@ -564,7 +732,7 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
|
|
|
if match == nil {
|
|
|
continue
|
|
|
}
|
|
|
- mapPermissionNameHave[n.PermissionName] = true
|
|
|
+
|
|
|
// 买方研选(3w/5w)
|
|
|
if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
|
|
|
if match.ExpensiveYx == 1 {
|
|
@@ -572,6 +740,8 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
|
|
|
} else {
|
|
|
money = money - 3
|
|
|
}
|
|
|
+ } else {
|
|
|
+ mapPermissionNameHave[n.PermissionName] = true
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -591,13 +761,26 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
|
|
|
itemPermission.AdminName = sysUser.RealName
|
|
|
itemPermission.Proportion = v.Proportion
|
|
|
itemPermission.Money = v.Money
|
|
|
- itemPermission.MoneyAvg = moneyAvg
|
|
|
+ if v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
|
|
|
+ itemPermission.MoneyAvg = moneyAvg
|
|
|
+ if v.Money < moneyAvg/2 {
|
|
|
+ br.Msg = "单行业占比值不得低于平均值的一半"
|
|
|
+ br.ErrMsg = "单行业占比值不得低于平均值的一半,Err:" + fmt.Sprint(proportionSum)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
itemPermission.ChartPermissionName = v.ChartPermissionName
|
|
|
itemPermission.CreateTime = time.Now()
|
|
|
itemPermission.ModifyTime = time.Now()
|
|
|
itemsPermission = append(itemsPermission, itemPermission)
|
|
|
+ var userProportionSum float64 // 校验前端传过来的占比使用
|
|
|
|
|
|
for _, v2 := range v.List {
|
|
|
+ if v2.Proportion < -20 {
|
|
|
+ br.Msg = "研究员占比值不得小于总额的-20%"
|
|
|
+ br.ErrMsg = "研究员占比值不得小于总额的20%,Err:" + fmt.Sprint(proportionSum)
|
|
|
+ return
|
|
|
+ }
|
|
|
item := new(cygx.CygxAllocationCompanyContract)
|
|
|
item.CompanyContractId = companyContractId
|
|
|
item.AdminId = sysUser.AdminId
|
|
@@ -609,16 +792,21 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
|
|
|
item.CreateTime = time.Now()
|
|
|
item.ModifyTime = time.Now()
|
|
|
items = append(items, item)
|
|
|
+ proportionSum += v2.Proportion
|
|
|
+ userProportionSum += v2.Proportion
|
|
|
}
|
|
|
- if v.ChartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
|
|
|
- continue
|
|
|
+ //先添加0.2%的精度校验
|
|
|
+ if userProportionSum > (v.Proportion+0.2) || userProportionSum < (v.Proportion-0.2) {
|
|
|
+ br.Msg = "单行业下的研究员比值之和不等于行业占比值"
|
|
|
+ br.ErrMsg = "单行业下的研究员比值之和不等于行业占比值"
|
|
|
+ return
|
|
|
}
|
|
|
- proportionSum += v.Proportion
|
|
|
}
|
|
|
|
|
|
+ //先添加0.5%的精度校验
|
|
|
if proportionSum > 100.5 || proportionSum < 99.5 {
|
|
|
- br.Msg = "操作失败,派点填写信息错误"
|
|
|
- br.ErrMsg = "获取合同信息失败,Err:" + fmt.Sprint(proportionSum)
|
|
|
+ br.Msg = "行业总比值相加不等于100%"
|
|
|
+ br.ErrMsg = "行业总比值相加不等于100%,Err:"
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -666,18 +854,31 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
if startDate == "" {
|
|
|
startDate = "2015-01-01"
|
|
|
}
|
|
|
- if endDate == "" {
|
|
|
- endDate = time.Now().Format(utils.FormatDate)
|
|
|
- }
|
|
|
|
|
|
//是否导出报表
|
|
|
isExport, _ := this.GetBool("IsExport")
|
|
|
|
|
|
var condition string
|
|
|
- var pars []interface{}
|
|
|
|
|
|
+ var pars []interface{}
|
|
|
+ if endDate != "" {
|
|
|
+ condition += ` AND a.start_date >= ? AND a.start_date <= ? `
|
|
|
+ pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
|
|
|
+ }
|
|
|
//根据当前角色来获取查询条件
|
|
|
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
|
|
|
+ //condition, pars = getQueryParams(condition, pars, sysUser, "c.")
|
|
|
+
|
|
|
+ companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lencompanyIds := len(companyIds)
|
|
|
+ if lencompanyIds > 0 {
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
|
|
|
//关键字搜索
|
|
|
if keyword != "" {
|
|
@@ -685,7 +886,7 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
}
|
|
|
|
|
|
//默认只查询权益 2023-06-01 之后的合同
|
|
|
- condition += ` AND c.product_id = ? AND a.start_date > ? `
|
|
|
+ condition += ` AND c.product_id = ? AND a.start_date > ? `
|
|
|
pars = append(pars, 2, "2023-01-01")
|
|
|
|
|
|
//列表页数据
|
|
@@ -695,7 +896,9 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+ //return
|
|
|
var companyContractIds []int
|
|
|
+ companyContractIdBool := make(map[int]bool)
|
|
|
for _, v := range listContract {
|
|
|
companyContractIds = append(companyContractIds, v.CompanyContractId)
|
|
|
}
|
|
@@ -707,8 +910,8 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
mapPermissionMoney := make(map[string]float64)
|
|
|
mapPermissionMoneyAvg := make(map[string]float64)
|
|
|
|
|
|
- totalContract := lenArr //所有的关联合同
|
|
|
- var totalMoney float64 //所有的关联合同的金额 单位万
|
|
|
+ //totalContract := lenArr //所有的关联合同
|
|
|
+ var totalMoney float64 //所有的关联合同的金额 单位万
|
|
|
if lenArr > 0 {
|
|
|
var conditionAllocation string
|
|
|
var parsAllocation []interface{}
|
|
@@ -727,13 +930,14 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
return
|
|
|
}
|
|
|
for _, v := range allocationCompanyContractList {
|
|
|
- if v.Proportion != 0 {
|
|
|
+
|
|
|
+ if v.Proportion != 0 && v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
|
|
|
mapUserAllocation[v.RealName] += 1
|
|
|
mapUserMoney[v.RealName] += v.Money
|
|
|
mapPermissionAllocation[v.ChartPermissionName] += 1
|
|
|
mapPermissionMoney[v.ChartPermissionName] += v.Money
|
|
|
-
|
|
|
totalMoney += v.Money
|
|
|
+ companyContractIdBool[v.CompanyContractId] = true
|
|
|
}
|
|
|
}
|
|
|
for _, v := range allocationCompanyContractPermissionList {
|
|
@@ -748,19 +952,17 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp)
|
|
|
+ mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp) //行业分组 map
|
|
|
|
|
|
for _, v := range sysUserList {
|
|
|
item := new(cygx.AllocationRealNameStatisticsListResp)
|
|
|
item.RealName = v.Name
|
|
|
item.TotalRelatedContract = mapUserAllocation[v.Name]
|
|
|
- item.TotalDispatchPoint = fmt.Sprint(mapUserMoney[v.Name])
|
|
|
+ item.TotalDispatchPoint = utils.SubFloatToString(mapUserMoney[v.Name], 2)
|
|
|
if item.TotalDispatchPoint == "" {
|
|
|
item.TotalDispatchPoint = "0"
|
|
|
}
|
|
|
//组内占比
|
|
|
- //utils.SubFloatToString(val, 4)
|
|
|
- //item.GroupProportion = fmt.Sprint(mapUserMoney[v.Name] / mapPermissionMoney[v.ChartPermissionName] * 100)
|
|
|
if mapUserMoney[v.Name] == 0 {
|
|
|
item.GroupProportion = ""
|
|
|
} else {
|
|
@@ -772,7 +974,11 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
item.GroupProportion += "%"
|
|
|
|
|
|
//部门占比
|
|
|
- item.DepartmentProportion = utils.SubFloatToString(mapUserMoney[v.Name]/totalMoney*100, 2)
|
|
|
+ if totalMoney == 0 {
|
|
|
+ item.DepartmentProportion = ""
|
|
|
+ } else {
|
|
|
+ item.DepartmentProportion = utils.SubFloatToString(mapUserMoney[v.Name]/totalMoney*100, 2)
|
|
|
+ }
|
|
|
if item.DepartmentProportion == "" {
|
|
|
item.DepartmentProportion = "0"
|
|
|
}
|
|
@@ -785,29 +991,31 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
item := new(cygx.AllocationRealNameStatisticsListResp)
|
|
|
item.RealName = "合计"
|
|
|
item.TotalRelatedContract = mapPermissionAllocation[k]
|
|
|
- item.TotalDispatchPoint = fmt.Sprint(mapPermissionMoney[k], "/", mapPermissionMoneyAvg[k])
|
|
|
+ item.TotalDispatchPoint = fmt.Sprint(utils.SubFloatToString(mapPermissionMoney[k], 2), "/", mapPermissionMoneyAvg[k])
|
|
|
item.GroupProportion = "100%"
|
|
|
|
|
|
- // 部门占比
|
|
|
- item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100, 2)
|
|
|
+ //部门占比
|
|
|
+ if totalMoney == 0 {
|
|
|
+ item.DepartmentProportion = ""
|
|
|
+ } else {
|
|
|
+ item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100, 2)
|
|
|
+ }
|
|
|
if item.DepartmentProportion == "" {
|
|
|
item.DepartmentProportion = "0"
|
|
|
}
|
|
|
item.DepartmentProportion += "%"
|
|
|
-
|
|
|
mapPermissionUser[k] = append(mapPermissionUser[k], item)
|
|
|
- var ratio float64 // 使用一个变量作为精度范围, 比如 2 位小数时,精度范围应该为 100
|
|
|
- ratio = math.Pow(10, 2) // 计算精度范围,2 位小数 = 100
|
|
|
+
|
|
|
item = new(cygx.AllocationRealNameStatisticsListResp)
|
|
|
item.RealName = "平均"
|
|
|
- item.TotalRelatedContract = math.Round(mapPermissionAllocation[k]/float64(lenUser)) * ratio / ratio
|
|
|
+ item.TotalRelatedContract = utils.SubFloatToFloat(mapPermissionAllocation[k]/float64(lenUser), 2)
|
|
|
item.TotalDispatchPoint = utils.SubFloatToString(mapPermissionMoney[k]/float64(lenUser), 2)
|
|
|
|
|
|
//组内占比
|
|
|
if mapPermissionMoney[k] == 0 {
|
|
|
item.GroupProportion = ""
|
|
|
} else {
|
|
|
- item.GroupProportion = utils.SubFloatToString(float64(lenUser)/mapPermissionMoney[k]*100, 2)
|
|
|
+ item.GroupProportion = utils.SubFloatToString(1/(float64(len(mapPermissionUser[k])-1))*100, 2)
|
|
|
}
|
|
|
if item.GroupProportion == "" {
|
|
|
item.GroupProportion = "0"
|
|
@@ -815,7 +1023,12 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
item.GroupProportion += "%"
|
|
|
|
|
|
// 部门占比
|
|
|
- item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100/float64(len(mapPermissionUser[k])), 2)
|
|
|
+ if totalMoney == 0 {
|
|
|
+ item.DepartmentProportion = ""
|
|
|
+ } else {
|
|
|
+ item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100/float64(len(mapPermissionUser[k])-1), 2)
|
|
|
+ }
|
|
|
+
|
|
|
if item.DepartmentProportion == "" {
|
|
|
item.DepartmentProportion = "0"
|
|
|
}
|
|
@@ -835,11 +1048,11 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
resp := cygx.CygxAllocationCompanyContractDetailStatisticsResp{
|
|
|
List: list,
|
|
|
}
|
|
|
- resp.TotalContract = totalContract
|
|
|
- resp.TotalMoney = totalMoney
|
|
|
+ resp.TotalContract = len(companyContractIdBool)
|
|
|
+ resp.TotalMoney = utils.SubFloatToFloat(totalMoney, 2)
|
|
|
//导出excel
|
|
|
if isExport {
|
|
|
- //IncrementalCompanyListExport(this, dataType, resp, br)
|
|
|
+ CompanyContractStatisticsExport(this, resp, br)
|
|
|
return
|
|
|
}
|
|
|
br.Ret = 200
|
|
@@ -847,3 +1060,139 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
|
|
|
br.Msg = "获取成功"
|
|
|
br.Data = resp
|
|
|
}
|
|
|
+
|
|
|
+// CompanyContractStatisticsExport 导出Excel
|
|
|
+func CompanyContractStatisticsExport(this *ContractAllocationController, resp cygx.CygxAllocationCompanyContractDetailStatisticsResp, br *models.BaseResponse) {
|
|
|
+ dir, err := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "生成文件失败"
|
|
|
+ br.ErrMsg = "生成文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+
|
|
|
+ sheel, err := xlsxFile.AddSheet("研究员派点统计")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sheel.SetColWidth(0, 0, 30)
|
|
|
+ sheel.SetColWidth(1, 1, 15)
|
|
|
+ sheel.SetColWidth(2, 2, 15)
|
|
|
+ sheel.SetColWidth(3, 3, 18)
|
|
|
+
|
|
|
+ titleRow := sheel.AddRow()
|
|
|
+
|
|
|
+ cellA := titleRow.AddCell()
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue("组别")
|
|
|
+
|
|
|
+ cellB := titleRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue("研究员")
|
|
|
+
|
|
|
+ cellC := titleRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue("关联合同")
|
|
|
+
|
|
|
+ cellD := titleRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue("总派点")
|
|
|
+
|
|
|
+ cellE := titleRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue("组内占比")
|
|
|
+
|
|
|
+ cellF := titleRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue("部门占比")
|
|
|
+
|
|
|
+ for _, v := range resp.List {
|
|
|
+ for k2, v2 := range v.List {
|
|
|
+
|
|
|
+ dataRow := sheel.AddRow()
|
|
|
+ dataRow.SetHeight(20)
|
|
|
+
|
|
|
+ cellA := dataRow.AddCell()
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue(v.ChartPermissionName)
|
|
|
+ if k2 < len(v.List)-1 {
|
|
|
+ cellA.VMerge = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ cellB := dataRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue(v2.RealName)
|
|
|
+
|
|
|
+ cellC := dataRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue(v2.TotalRelatedContract)
|
|
|
+
|
|
|
+ cellD := dataRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue(v2.TotalDispatchPoint)
|
|
|
+
|
|
|
+ cellE := dataRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue(v2.GroupProportion)
|
|
|
+
|
|
|
+ cellF := dataRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue(v2.DepartmentProportion)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ titleRow = sheel.AddRow()
|
|
|
+ cellA = titleRow.AddCell()
|
|
|
+ cellA.HMerge = 1
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue("部门合计")
|
|
|
+
|
|
|
+ cellB = titleRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue("")
|
|
|
+
|
|
|
+ cellC = titleRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue(resp.TotalContract)
|
|
|
+
|
|
|
+ cellD = titleRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue(resp.TotalMoney)
|
|
|
+
|
|
|
+ cellE = titleRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue("-")
|
|
|
+
|
|
|
+ cellF = titleRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue("100%")
|
|
|
+
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存文件失败"
|
|
|
+ br.ErrMsg = "保存文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ downloadFileName := "研究员派点统计_" + randStr + ".xlsx"
|
|
|
+ this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
|
|
|
+ defer func() {
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ }()
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "导出成功"
|
|
|
+}
|