|
@@ -11,8 +11,6 @@ import (
|
|
|
cygxService "hongze/hz_crm_api/services/cygx"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
- "strings"
|
|
|
-
|
|
|
//"hongze/hz_crm_api/services"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
//"strings"
|
|
@@ -79,11 +77,7 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
|
|
|
if dataType != "续约客户" {
|
|
|
packageDifference = "" // 只有续约客户才会有值,过滤前端传过来的脏数据
|
|
|
}
|
|
|
- //if startDate == "" || endDate == "" {
|
|
|
- // br.Msg = "获取失败,开始日期或结束日期未传"
|
|
|
- // br.ErrMsg = "获取失败,开始日期或结束日期未传"
|
|
|
- // return
|
|
|
- //}
|
|
|
+
|
|
|
if startDate == "" {
|
|
|
startDate = "2015-01-01"
|
|
|
}
|
|
@@ -139,58 +133,57 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
|
|
|
var conditionConfirm string
|
|
|
var parsConfirm []interface{}
|
|
|
|
|
|
- companyConfirmList, err := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
|
|
|
+ companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- var noRenewedcompanyIds []int //已经确定未续约的公司ID
|
|
|
+ var noRenewedcompanyContractIds []int //已经确定未续约的公司ID
|
|
|
if len(companyConfirmList) == 0 {
|
|
|
- noRenewedcompanyIds = append(noRenewedcompanyIds, 0) // 给一个不存在的ID
|
|
|
+ noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, 0) // 给一个不存在的ID
|
|
|
} else {
|
|
|
for _, v := range companyConfirmList {
|
|
|
- noRenewedcompanyIds = append(noRenewedcompanyIds, v.CompanyId)
|
|
|
+ noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, v.CompanyContractId)
|
|
|
}
|
|
|
}
|
|
|
//是否确认续约 CRM 13.9
|
|
|
- conditionAscribRaiTotal += ` AND ( c.company_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) OR c.product_id = 1 OR a.create_time < '2023-01-01' ) ` // 已确认
|
|
|
- parsAscribeRaiTotal = append(parsAscribeRaiTotal, noRenewedcompanyIds)
|
|
|
+ conditionAscribRaiTotal += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
|
|
|
+ parsAscribeRaiTotal = append(parsAscribeRaiTotal, noRenewedcompanyContractIds)
|
|
|
|
|
|
- conditionAscribRaiToBeTotal += ` AND ( c.company_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) AND c.product_id = 2 AND a.create_time >= '2023-01-01' ) ` // 待确认
|
|
|
- parsAscribeRaiTobeTotal = append(parsAscribeRaiTobeTotal, noRenewedcompanyIds)
|
|
|
+ conditionAscribRaiToBeTotal += ` AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 待确认
|
|
|
+ parsAscribeRaiTobeTotal = append(parsAscribeRaiTobeTotal, noRenewedcompanyContractIds)
|
|
|
|
|
|
if isConfirm != -1 {
|
|
|
if isConfirm == 0 {
|
|
|
- conditionAscribRai += ` AND ( c.company_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) AND c.product_id = 2 AND a.create_time >= '2023-01-01' ) ` // 待确认
|
|
|
+ conditionAscribRai += ` AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 待确认
|
|
|
} else {
|
|
|
- conditionAscribRai += ` AND ( c.company_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `) OR c.product_id = 1 OR a.create_time < '2023-01-01' ) ` // 已确认
|
|
|
+ conditionAscribRai += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
|
|
|
}
|
|
|
- parsAscribeRai = append(parsAscribeRai, noRenewedcompanyIds)
|
|
|
+ parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
|
|
|
}
|
|
|
-
|
|
|
//归因ID CRM 13.9
|
|
|
if companyAscribeId > 0 {
|
|
|
var conditionAscribe string
|
|
|
var parsAscribe []interface{}
|
|
|
conditionAscribe = " AND company_ascribe_id = ? "
|
|
|
parsAscribe = append(parsAscribe, companyAscribeId)
|
|
|
- companyNoRenewedAscribeList, err := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
|
|
|
+ companyNoRenewedAscribeList, err := company.GetCompanyContractNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- var companyIds []int
|
|
|
+ var noRenewedcompanyContractIds []int
|
|
|
if len(companyNoRenewedAscribeList) == 0 {
|
|
|
- companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, 0) // 给一个不存在的ID
|
|
|
} else {
|
|
|
for _, v := range companyNoRenewedAscribeList {
|
|
|
- companyIds = append(companyIds, v.CompanyId)
|
|
|
+ noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, v.CompanyContractId)
|
|
|
}
|
|
|
}
|
|
|
- conditionAscribRai += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
|
|
|
- parsAscribeRai = append(parsAscribeRai, companyIds)
|
|
|
+ conditionAscribRai += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)`
|
|
|
+ parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
|
|
|
}
|
|
|
|
|
|
condition += ` AND c.product_id = ? AND a.status = 1 `
|
|
@@ -292,17 +285,8 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
|
|
|
condition1 := condition
|
|
|
pars1 := pars
|
|
|
|
|
|
- endDateTime, err := time.Parse(utils.FormatDate, endDate)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "结束时间异常"
|
|
|
- br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- //选择的日期加一天的原因是因为:筛选条件是截止到时分秒的,如果要把选择的这一天也统计进去,那么需要在选择的结束日期基础上加上一天
|
|
|
- tryOutEndDate := endDateTime.AddDate(0, 0, 1).Format(utils.FormatDate)
|
|
|
-
|
|
|
- condition1 += ` AND a.start_date >= ? AND a.start_date < ? `
|
|
|
- pars1 = append(pars1, startDate, tryOutEndDate)
|
|
|
+ condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
|
|
|
+ pars1 = append(pars1, startDate, endDate)
|
|
|
//condition1 += ` AND a.operation = ? `
|
|
|
//pars1 = append(pars1, "try_out")
|
|
|
condition1 += ` AND c.status not in ("永续","正式","关闭") `
|
|
@@ -370,13 +354,6 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
|
|
|
total = notRenewalNotTryOut
|
|
|
}
|
|
|
|
|
|
- //total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
|
|
|
- //if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // br.Msg = "获取失败"
|
|
|
- // br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
- // return
|
|
|
- //}
|
|
|
-
|
|
|
//分页total单独计算
|
|
|
total, err = company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
@@ -384,7 +361,7 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ //return
|
|
|
//列表页数据
|
|
|
tmpList, err := models.GetIncrementalCompanyListByOperationRecordMerge(condition1, pars1, startSize, pageSize)
|
|
|
if err != nil {
|
|
@@ -394,18 +371,20 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
|
|
|
}
|
|
|
|
|
|
var ascribecompanyIds []int
|
|
|
+ var companyContractIds []int
|
|
|
for _, item := range tmpList {
|
|
|
//endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
|
|
|
//item.EndDate = endDateTime.Format(utils.FormatDate)
|
|
|
ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
|
|
|
+ companyContractIds = append(companyContractIds, item.CompanyContractId)
|
|
|
}
|
|
|
- //归因标签
|
|
|
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
|
|
|
+ //合同归因标签
|
|
|
+ mapGetCompanyAscribeContent, mapContent := services.GetCompanyContractAscribeContentMap(companyContractIds)
|
|
|
mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
|
|
|
|
|
|
for _, item := range tmpList {
|
|
|
- item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
- item.Content = mapContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
+ item.AscribeContent = mapGetCompanyAscribeContent[item.CompanyContractId]
|
|
|
+ item.Content = mapContent[item.CompanyContractId]
|
|
|
item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
}
|
|
|
|
|
@@ -538,60 +517,9 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
|
|
|
cellSellerName.SetStyle(style)
|
|
|
cellSellerName.SetValue("所属销售")
|
|
|
|
|
|
- permissionMap := make(map[int][]string)
|
|
|
- tmpPermissionMap := make(map[int]map[string][]string)
|
|
|
- companyContractIdList := make([]string, 0)
|
|
|
- for _, v := range resp.List {
|
|
|
- companyContractIdList = append(companyContractIdList, fmt.Sprint(v.CompanyContractId))
|
|
|
- }
|
|
|
- if dataType == "新签客户" || dataType == "续约客户" {
|
|
|
- cellMoney := titleRow.AddCell()
|
|
|
- cellMoney.SetStyle(style)
|
|
|
- cellMoney.SetValue("合同金额")
|
|
|
- cellPermission := titleRow.AddCell()
|
|
|
- cellPermission.SetStyle(style)
|
|
|
- cellPermission.SetValue("合同品种")
|
|
|
-
|
|
|
- //这么大费周章的目的是为了:权益的品种存在主观、客观的区分,如果一个品种既存在主观,又存在客观,那么就展示品种名称,否则就要列出品种名称+主、客观类型
|
|
|
- if len(companyContractIdList) > 0 {
|
|
|
- list, tmpErr := company.GetCompanyContractPermissionListByContractIds(strings.Join(companyContractIdList, ","))
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range list {
|
|
|
- tmpPermissionNameMap, ok := tmpPermissionMap[v.CompanyContractId]
|
|
|
- if ok {
|
|
|
- tmpPermissionNameList, ok2 := tmpPermissionNameMap[v.ChartPermissionName]
|
|
|
- if ok2 {
|
|
|
- tmpPermissionNameList = append(tmpPermissionNameList, v.PermissionRemark)
|
|
|
- } else {
|
|
|
- tmpPermissionNameList = []string{v.PermissionRemark}
|
|
|
- }
|
|
|
- tmpPermissionNameMap[v.ChartPermissionName] = tmpPermissionNameList
|
|
|
- } else {
|
|
|
- tmpPermissionNameMap = make(map[string][]string)
|
|
|
- tmpPermissionNameMap[v.ChartPermissionName] = []string{v.PermissionRemark}
|
|
|
- }
|
|
|
- tmpPermissionMap[v.CompanyContractId] = tmpPermissionNameMap
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for companyContractId, tmpPermissionNameMap := range tmpPermissionMap {
|
|
|
- tmpPermissionName := ``
|
|
|
- tmpPermissionList := []string{}
|
|
|
- for tmpChartPermissionName, tmpChartPermissionNameList := range tmpPermissionNameMap {
|
|
|
- if len(tmpChartPermissionNameList) > 1 {
|
|
|
- tmpPermissionName = tmpChartPermissionName
|
|
|
- } else {
|
|
|
- tmpPermissionName = tmpChartPermissionNameList[0]
|
|
|
- }
|
|
|
- tmpPermissionList = append(tmpPermissionList, tmpPermissionName)
|
|
|
- }
|
|
|
-
|
|
|
- permissionMap[companyContractId] = tmpPermissionList
|
|
|
- }
|
|
|
+ cellMoney := titleRow.AddCell()
|
|
|
+ cellMoney.SetStyle(style)
|
|
|
+ cellMoney.SetValue("合同金额")
|
|
|
|
|
|
cellTime := titleRow.AddCell()
|
|
|
cellTime.SetStyle(style)
|
|
@@ -613,7 +541,9 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
|
|
|
cellContent.SetStyle(style)
|
|
|
cellContent.SetValue("详细原因")
|
|
|
}
|
|
|
-
|
|
|
+ cellPermissionName := titleRow.AddCell()
|
|
|
+ cellPermissionName.SetStyle(style)
|
|
|
+ cellPermissionName.SetValue("签约套餐")
|
|
|
for _, v := range resp.List {
|
|
|
dataRow := sheel.AddRow()
|
|
|
dataRow.SetHeight(20)
|
|
@@ -630,16 +560,11 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
|
|
|
cellDataSellerName.SetStyle(style)
|
|
|
cellDataSellerName.SetValue(v.SellerName)
|
|
|
|
|
|
- if dataType == "新签客户" || dataType == "续约客户" {
|
|
|
- cellDataMoney := dataRow.AddCell()
|
|
|
- cellDataMoney.SetStyle(style)
|
|
|
- cellDataMoney.SetValue(v.Money)
|
|
|
- cellDataPermission := dataRow.AddCell()
|
|
|
- cellDataPermission.SetStyle(style)
|
|
|
- if permissionStrList, ok := permissionMap[v.CompanyContractId]; ok {
|
|
|
- cellDataPermission.SetValue(strings.Join(permissionStrList, ","))
|
|
|
- }
|
|
|
- }
|
|
|
+ //if dataType == "新签客户" || dataType == "续约客户" {
|
|
|
+ cellDataMoney := dataRow.AddCell()
|
|
|
+ cellDataMoney.SetStyle(style)
|
|
|
+ cellDataMoney.SetValue(v.Money)
|
|
|
+ //}
|
|
|
|
|
|
cellDataTime := dataRow.AddCell()
|
|
|
cellDataTime.SetStyle(style)
|
|
@@ -661,7 +586,9 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
|
|
|
cellContent.SetStyle(style)
|
|
|
cellContent.SetValue(v.Content)
|
|
|
}
|
|
|
-
|
|
|
+ cellDataPermissionName := dataRow.AddCell()
|
|
|
+ cellDataPermissionName.SetStyle(style)
|
|
|
+ cellDataPermissionName.SetValue(v.PermissionName)
|
|
|
}
|
|
|
err = xlsxFile.Save(downLoadnFilePath)
|
|
|
if err != nil {
|
|
@@ -670,7 +597,7 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
|
|
|
return
|
|
|
}
|
|
|
randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
- downloadFileName := "增量客户数据_" + randStr + ".xlsx"
|
|
|
+ downloadFileName := dataType + "数据_" + randStr + ".xlsx"
|
|
|
this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
|
|
|
defer func() {
|
|
|
os.Remove(downLoadnFilePath)
|
|
@@ -740,3 +667,531 @@ func (this *StatisticCompanyMergerController) CompanyPreviousDetail() {
|
|
|
br.Msg = "获取成功"
|
|
|
br.Data = resp
|
|
|
}
|
|
|
+
|
|
|
+// @Title 权益行业套餐统计
|
|
|
+// @Description 权益客户统计列表接口
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param Keyword query string true "客户名称"
|
|
|
+// @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
|
|
|
+// @Param StartDate query string false "开始日期"
|
|
|
+// @Param EndDate query string false "结束日期"
|
|
|
+// @Param DataType query string false "报表类型,枚举值:`行业新签`,`行业续约`,`行业未续约`"
|
|
|
+// @Param PermissionName query string false "行业权限名称"
|
|
|
+// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
+// @Success 200 {object} response.IncrementalCompanyListResp
|
|
|
+// @router /merge_company/company_contract_permission/list [get]
|
|
|
+func (this *StatisticCompanyMergerController) CompanyContractPermissionList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+
|
|
|
+ adminId := this.GetString("AdminId")
|
|
|
+ regionType := this.GetString("RegionType")
|
|
|
+ //companyType := this.GetString("CompanyType")
|
|
|
+ dataType := this.GetString("DataType")
|
|
|
+ keyword := this.GetString("Keyword")
|
|
|
+
|
|
|
+ startDate := this.GetString("StartDate")
|
|
|
+ endDate := this.GetString("EndDate")
|
|
|
+ permissionName := this.GetString("PermissionName")
|
|
|
+ if permissionName == "" { //默认所筛选行业为医药
|
|
|
+ permissionName = "医药"
|
|
|
+ }
|
|
|
+
|
|
|
+ //if startDate == "" || endDate == "" {
|
|
|
+ // br.Msg = "获取失败,开始日期或结束日期未传"
|
|
|
+ // br.ErrMsg = "获取失败,开始日期或结束日期未传"
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ if startDate == "" {
|
|
|
+ startDate = "2015-01-01"
|
|
|
+ }
|
|
|
+ if endDate == "" {
|
|
|
+ endDate = time.Now().Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(currentIndex, pageSize)
|
|
|
+
|
|
|
+ //是否导出报表
|
|
|
+ isExport, _ := this.GetBool("IsExport")
|
|
|
+ if isExport {
|
|
|
+ pageSize = 10000
|
|
|
+ currentIndex = 1
|
|
|
+ permissionName = "" //点击下载的时候不做行业筛选
|
|
|
+ }
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ //条件
|
|
|
+ if adminId != "" {
|
|
|
+ condition += ` AND c.seller_id in (` + adminId + `) `
|
|
|
+ //pars = append(pars, adminId)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ //根据当前角色来获取查询条件
|
|
|
+ condition, pars = getQueryParams(condition, pars, sysUser, "c.")
|
|
|
+
|
|
|
+ }
|
|
|
+ if regionType != "" {
|
|
|
+ condition += ` AND b.region_type = ? `
|
|
|
+ pars = append(pars, regionType)
|
|
|
+ }
|
|
|
+
|
|
|
+ //关键字搜索
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` and b.company_name like "%` + keyword + `%" `
|
|
|
+ }
|
|
|
+
|
|
|
+ var conditionAscribRai string // 处理权益未续约客户检索列表SQL查询条件
|
|
|
+ var conditionAscribRaiTotal string // 处理权益未续约客户总量查询条件
|
|
|
+ var parsAscribeRai []interface{}
|
|
|
+ var parsAscribeRaiTotal []interface{} // 处理权益未续约客户总量查询条件
|
|
|
+
|
|
|
+ condition += ` AND c.product_id = ? AND a.status = 1 `
|
|
|
+ pars = append(pars, 2)
|
|
|
+
|
|
|
+ var list []*models.IncrementalList
|
|
|
+ var listPessionGroup []*models.CompanyContractPermissionNameGroupCountResp
|
|
|
+
|
|
|
+ var newCompanyTotal int //新签合同数量
|
|
|
+ var notRenewalCompanyTotal int //未续约客户数已确认
|
|
|
+ var notRenewalCompanyToBeConfirmTotal int //未续约客户数待确认
|
|
|
+ var dataTotal, trialTotal, renewalCompanyTotal int
|
|
|
+ var notRenewalTryOut, notRenewalNotTryOut int
|
|
|
+
|
|
|
+ //if dataType == "行业未续约" {
|
|
|
+ // condition += ` AND a.end_date >= ? AND a.end_date <= ? `
|
|
|
+ // pars = append(pars, startDate, endDate)
|
|
|
+ //} else {
|
|
|
+ // condition += ` AND a.start_date >= ? AND a.start_date <= ? `
|
|
|
+ // pars = append(pars, startDate, endDate)
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //conditionPerssion := condition
|
|
|
+ //parsPerssion := pars
|
|
|
+ //conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','买方研选')`
|
|
|
+ //
|
|
|
+ //listPessionGroup, err := models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
|
|
|
+ //if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ // br.Msg = "获取失败"
|
|
|
+ // br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if permissionName == "" {
|
|
|
+ condition += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','买方研选')`
|
|
|
+ //}
|
|
|
+
|
|
|
+ var err error
|
|
|
+ //新签客户数
|
|
|
+ {
|
|
|
+ condition1 := condition
|
|
|
+ pars1 := pars
|
|
|
+ condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
|
|
|
+ pars1 = append(pars1, startDate, endDate)
|
|
|
+ condition1 += ` AND d.contract_type = ? `
|
|
|
+ pars1 = append(pars1, "行业新签")
|
|
|
+ newCompanyTotal, err = company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if dataType == "行业新签" {
|
|
|
+ conditionPerssion := condition1
|
|
|
+ parsPerssion := pars1
|
|
|
+ conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','买方研选')`
|
|
|
+
|
|
|
+ listPessionGroup, err = models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //行业筛选查询
|
|
|
+ if permissionName != "" {
|
|
|
+ condition1 += ` AND d.permission_name = ? `
|
|
|
+ pars1 = append(pars1, permissionName)
|
|
|
+ }
|
|
|
+
|
|
|
+ total, err := company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //列表页数据
|
|
|
+ tmpList, err := models.GetIncrementalCompanyPermissionList(condition1, pars1, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list = tmpList
|
|
|
+ dataTotal = total
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //续约客户数
|
|
|
+ {
|
|
|
+ condition1 := condition
|
|
|
+ pars1 := pars
|
|
|
+ condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
|
|
|
+ pars1 = append(pars1, startDate, endDate)
|
|
|
+ condition1 += ` AND d.contract_type = ? `
|
|
|
+ pars1 = append(pars1, "行业续约")
|
|
|
+ ////额外条件(续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户)
|
|
|
+ //pars1 = append(pars1, endDate)
|
|
|
+
|
|
|
+ total, err := company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ renewalCompanyTotal = total
|
|
|
+
|
|
|
+ if dataType == "行业续约" {
|
|
|
+ conditionPerssion := condition1
|
|
|
+ parsPerssion := pars1
|
|
|
+ conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','买方研选')`
|
|
|
+
|
|
|
+ listPessionGroup, err = models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //行业筛选查询
|
|
|
+ if permissionName != "" {
|
|
|
+ condition1 += ` AND d.permission_name = ? `
|
|
|
+ pars1 = append(pars1, permissionName)
|
|
|
+ }
|
|
|
+ //列表数据数量
|
|
|
+ total, err := company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //列表页数据
|
|
|
+ tmpList, err := models.GetIncrementalCompanyPermissionList(condition1, pars1, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list = tmpList
|
|
|
+ dataTotal = total
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //return
|
|
|
+
|
|
|
+ //行业未续约
|
|
|
+ {
|
|
|
+ condition1 := condition
|
|
|
+ pars1 := pars
|
|
|
+ condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
|
|
|
+ pars1 = append(pars1, startDate, endDate)
|
|
|
+ condition1 += ` AND c.status not in ("永续","正式","关闭") `
|
|
|
+
|
|
|
+ //未续约数量
|
|
|
+ notRenewalCondition := condition1
|
|
|
+ notRenewalPars := pars1
|
|
|
+ notRenewalCondition += conditionAscribRaiTotal
|
|
|
+ notRenewalPars = append(notRenewalPars, parsAscribeRaiTotal)
|
|
|
+ total, err := company.GetIncrementalNewCompanyProductPermissionCount(notRenewalCondition, notRenewalPars)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ notRenewalCompanyTotal = total
|
|
|
+ condition1 += conditionAscribRai
|
|
|
+ pars1 = append(pars1, parsAscribeRai)
|
|
|
+ if dataType == "行业未续约" {
|
|
|
+ conditionPerssion := condition1
|
|
|
+ parsPerssion := pars1
|
|
|
+ conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','买方研选')`
|
|
|
+
|
|
|
+ listPessionGroup, err = models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //行业筛选查询
|
|
|
+ if permissionName != "" {
|
|
|
+ condition1 += ` AND d.permission_name = ? `
|
|
|
+ pars1 = append(pars1, permissionName)
|
|
|
+ }
|
|
|
+
|
|
|
+ //分页total单独计算
|
|
|
+ total, err = company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //return
|
|
|
+ //列表页数据
|
|
|
+ tmpList, err := models.GetIncrementalCompanyPermissionList(condition1, pars1, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ list = tmpList
|
|
|
+ dataTotal = total
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ listLen := len(list)
|
|
|
+
|
|
|
+ if listLen == 0 {
|
|
|
+ list = make([]*models.IncrementalList, 0)
|
|
|
+ }
|
|
|
+ var companyContractIds []int
|
|
|
+ var companyIds []int
|
|
|
+ for i := 0; i < listLen; i++ {
|
|
|
+ item := list[i]
|
|
|
+ companyContractIds = append(companyContractIds, item.CompanyContractId)
|
|
|
+ companyIds = append(companyIds, item.CompanyId)
|
|
|
+ //新增试用不需要计算剩余日期
|
|
|
+ if dataType != "新增试用" {
|
|
|
+ //剩余可用天数
|
|
|
+ endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
|
|
|
+ endDateTime = endDateTime.AddDate(0, 0, 1)
|
|
|
+ sub := endDateTime.Sub(time.Now())
|
|
|
+ expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
|
|
|
+ list[i].ExpireDay = expireDay
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //行业未续约 需要处理公司对应行业权限下的权限状态
|
|
|
+ if dataType == "行业未续约" {
|
|
|
+ mappermissionNameStatus, err := cygxService.GetCompanyPermissionNameStatusMapByCompanyId(companyIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ v.PermissionNameStatus = mappermissionNameStatus[fmt.Sprint(v.CompanyId, v.PermissionNameExport)]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并合同所对应的权限
|
|
|
+ mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ v.PermissionName = mappermissionName[v.CompanyContractId]
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理展示顺序
|
|
|
+ permissionNameSlice := []string{"医药", "消费", "科技", "智造", "策略", "买方研选"}
|
|
|
+ var itemspermissionNameSlice []*models.CompanyContractPermissionNameGroupCountResp
|
|
|
+ for _, vName := range permissionNameSlice {
|
|
|
+ item := new(models.CompanyContractPermissionNameGroupCountResp)
|
|
|
+ for _, v := range listPessionGroup {
|
|
|
+ if v.PermissionName != vName {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ item.Total = v.Total
|
|
|
+ }
|
|
|
+ item.PermissionName = vName
|
|
|
+ itemspermissionNameSlice = append(itemspermissionNameSlice, item)
|
|
|
+ }
|
|
|
+
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, dataTotal)
|
|
|
+ resp := response.IncrementalCompanyListResp{
|
|
|
+ Paging: page,
|
|
|
+ ListPermissionName: itemspermissionNameSlice,
|
|
|
+ List: list,
|
|
|
+ TrialTotal: trialTotal,
|
|
|
+ NewCompanyTotal: newCompanyTotal,
|
|
|
+ RenewalCompanyTotal: renewalCompanyTotal,
|
|
|
+ NotRenewalCompanyTotal: notRenewalCompanyTotal,
|
|
|
+ NotRenewalCompanyToBeConfirmTotal: notRenewalCompanyToBeConfirmTotal,
|
|
|
+ NotRenewalTryOut: notRenewalTryOut,
|
|
|
+ NotRenewalNotTryOut: notRenewalNotTryOut,
|
|
|
+ }
|
|
|
+ //fmt.Println()
|
|
|
+ //导出excel
|
|
|
+ if isExport {
|
|
|
+ PermissionCompanyListListExport(this, dataType, resp, br)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// PermissionCompanyListListExport 导出增量客户数据报表excel
|
|
|
+func PermissionCompanyListListExport(this *StatisticCompanyMergerController, dataType string, resp response.IncrementalCompanyListResp, 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,
|
|
|
+ }
|
|
|
+ permissionNameSlice := []string{"医药", "消费", "科技", "智造", "策略", "买方研选"}
|
|
|
+
|
|
|
+ mapExport := make(map[string][]*models.IncrementalList)
|
|
|
+ type IncrementalCompanyListExport struct {
|
|
|
+ PermissionName string `description:"权限名"`
|
|
|
+ List []*models.IncrementalList
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range resp.List {
|
|
|
+ if v.PermissionNameExport == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ mapExport[v.PermissionNameExport] = append(mapExport[v.PermissionNameExport], v)
|
|
|
+ }
|
|
|
+
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+
|
|
|
+ for _, vName := range permissionNameSlice {
|
|
|
+ sheel, err := xlsxFile.AddSheet(vName)
|
|
|
+ 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)
|
|
|
+ sheel.SetColWidth(4, 4, 40)
|
|
|
+ sheel.SetColWidth(5, 5, 18)
|
|
|
+
|
|
|
+ //表头
|
|
|
+
|
|
|
+ titleRow := sheel.AddRow()
|
|
|
+
|
|
|
+ cellName := titleRow.AddCell()
|
|
|
+ cellName.SetStyle(style)
|
|
|
+ cellName.SetValue("客户名称")
|
|
|
+
|
|
|
+ cellSellerName := titleRow.AddCell()
|
|
|
+ cellSellerName.SetStyle(style)
|
|
|
+ cellSellerName.SetValue("所属销售")
|
|
|
+
|
|
|
+ cellMoney := titleRow.AddCell()
|
|
|
+ cellMoney.SetStyle(style)
|
|
|
+ cellMoney.SetValue("合同金额")
|
|
|
+
|
|
|
+ cellTime := titleRow.AddCell()
|
|
|
+ cellTime.SetStyle(style)
|
|
|
+ cellTime.SetValue("合同期限")
|
|
|
+
|
|
|
+ cellPermissionName := titleRow.AddCell()
|
|
|
+ cellPermissionName.SetStyle(style)
|
|
|
+ cellPermissionName.SetValue("签约套餐")
|
|
|
+
|
|
|
+ if dataType == "行业未续约" {
|
|
|
+ cellPermissionNameStatus := titleRow.AddCell()
|
|
|
+ cellPermissionNameStatus.SetStyle(style)
|
|
|
+ cellPermissionNameStatus.SetValue("当前行业状态")
|
|
|
+
|
|
|
+ cellCompanyProductStatus := titleRow.AddCell()
|
|
|
+ cellCompanyProductStatus.SetStyle(style)
|
|
|
+ cellCompanyProductStatus.SetValue("当前客户状态")
|
|
|
+ }
|
|
|
+ for _, v := range mapExport[vName] {
|
|
|
+ dataRow := sheel.AddRow()
|
|
|
+ dataRow.SetHeight(20)
|
|
|
+
|
|
|
+ cellDataName := dataRow.AddCell()
|
|
|
+ cellDataName.SetStyle(style)
|
|
|
+ cellDataName.SetValue(v.CompanyName)
|
|
|
+
|
|
|
+ cellDataSellerName := dataRow.AddCell()
|
|
|
+ cellDataSellerName.SetStyle(style)
|
|
|
+ cellDataSellerName.SetValue(v.SellerName)
|
|
|
+
|
|
|
+ cellDataMoney := dataRow.AddCell()
|
|
|
+ cellDataMoney.SetStyle(style)
|
|
|
+ cellDataMoney.SetValue(v.Money)
|
|
|
+
|
|
|
+ cellDataTime := dataRow.AddCell()
|
|
|
+ cellDataTime.SetStyle(style)
|
|
|
+ cellDataTime.SetValue(v.StartDate + "~" + v.EndDate)
|
|
|
+
|
|
|
+ cellDataPermissionName := dataRow.AddCell()
|
|
|
+ cellDataPermissionName.SetStyle(style)
|
|
|
+ cellDataPermissionName.SetValue(v.PermissionName)
|
|
|
+
|
|
|
+ if dataType == "行业未续约" {
|
|
|
+ cellDataPermissionNameStatus := dataRow.AddCell()
|
|
|
+ cellDataPermissionNameStatus.SetStyle(style)
|
|
|
+ cellDataPermissionNameStatus.SetValue(v.PermissionNameStatus)
|
|
|
+
|
|
|
+ cellDataCompanyProductStatus := dataRow.AddCell()
|
|
|
+ cellDataCompanyProductStatus.SetStyle(style)
|
|
|
+ cellDataCompanyProductStatus.SetValue(v.CompanyProductStatus)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存文件失败"
|
|
|
+ br.ErrMsg = "保存文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ downloadFileName := dataType + "数据_" + randStr + ".xlsx"
|
|
|
+ this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
|
|
|
+ defer func() {
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ }()
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "导出成功"
|
|
|
+}
|