Explorar o código

feature(合同报表统计): 业绩指标的回款金额、签约合同金额统计后台接口实现

lk %!s(int64=2) %!d(string=hai) anos
pai
achega
d49bb61159

+ 44 - 0
opms_parent/app/handler/contract/report.go

@@ -0,0 +1,44 @@
+package contract
+
+import (
+	"context"
+
+	"dashoo.cn/common_definition/comm_def"
+	model "dashoo.cn/micro/app/model/contract"
+	service "dashoo.cn/micro/app/service/contract"
+	"github.com/gogf/gf/frame/g"
+)
+
+type ContractReportHandler struct{}
+
+// QueryCollectionNum 业绩指标-回款金额
+func (c *ContractReportHandler) QueryCollectionNum(ctx context.Context, req *model.QueryNumReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("ContractReport.QueryCollectionNum request %#v ", *req)
+	s, err := service.NewContractReportService(ctx)
+	if err != nil {
+		return err
+	}
+	data, err := s.QueryCollectionNum(req.Date)
+	if err != nil {
+		return err
+	}
+
+	rsp.Data = data
+	return nil
+}
+
+// QueryContractNum 业绩指标-签约合同金额
+func (c *ContractReportHandler) QueryContractNum(ctx context.Context, req *model.QueryNumReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("ContractReport.QueryContractNum request %#v ", *req)
+	s, err := service.NewContractReportService(ctx)
+	if err != nil {
+		return err
+	}
+	data, err := s.QueryContractNum(req.Date)
+	if err != nil {
+		return err
+	}
+
+	rsp.Data = data
+	return nil
+}

+ 5 - 0
opms_parent/app/model/contract/report.go

@@ -0,0 +1,5 @@
+package contract
+
+type QueryNumReq struct {
+	Date string `json:"date"`
+}

+ 4 - 4
opms_parent/app/model/work/deliver_order_imp_progress.go

@@ -32,10 +32,10 @@ type DeliverOrderProgressAddReq struct {
 	ProgressContext string      `json:"progressContext" v:"required#请输入任务内容"` // 任务内容
 	StartDate       *gtime.Time `json:"startDate" v:"required#请输入开始时间"`       // 开始时间
 	EndDate         *gtime.Time `json:"endDate" v:"required#请输入结束时间"`         // 结束时间
-	ReaStartDate    *gtime.Time `json:"reaStartDate"`                                // 实际开始时间
-	ReaEndDate      *gtime.Time `json:"reaEndDate"`                                  // 实际结束时间
-	ProgressLevel   string      `json:"progressLevel"`                               // 优先级(10最高 20普通 30较低 )
-	Remark          string      `json:"remark"`                                      // 备注
+	ReaStartDate    *gtime.Time `json:"reaStartDate"`                         // 实际开始时间
+	ReaEndDate      *gtime.Time `json:"reaEndDate"`                           // 实际结束时间
+	ProgressLevel   string      `json:"progressLevel"`                        // 优先级(10最高 20普通 30较低 )
+	Remark          string      `json:"remark"`                               // 备注
 
 }
 

+ 30 - 0
opms_parent/app/service/base.go

@@ -315,6 +315,36 @@ func GetUsersByRoleCode(ctx context.Context, roleCode []string, pageSize ...int)
 	return res, nil
 }
 
+// GetUserListByRoleCode 根据角色编码获取用户列表
+func GetUserListByRoleCode(ctx context.Context, roleCode []string, pageSize ...int) ([]map[string]interface{}, error) {
+	srv := micro_srv.InitMicroSrvClient("User", "micro_srv.auth")
+	defer srv.Close()
+	resp := &comm_def.CommonMsg{}
+	req := &SysUserSearchReq{Roles: roleCode, Status: "10"}
+	if len(pageSize) > 0 {
+		req.PageSize = pageSize[0]
+	}
+	err := srv.Call(ctx, "GetList", req, resp)
+	if err != nil {
+		return nil, myerrors.MicroCallError("根据角色编码获取用户失败")
+	}
+	if resp.Data == nil {
+		return nil, myerrors.TipsError("用户不存在")
+	}
+	data := resp.Data.(map[string]interface{})
+	list := data["list"].([]interface{})
+	var res []map[string]interface{}
+	for _, i := range list {
+		info := i.(map[string]interface{})
+		data := map[string]interface{}{
+			"Id":       gconv.Int(info["Id"]),
+			"NickName": info["NickName"].(string),
+		}
+		res = append(res, data)
+	}
+	return res, nil
+}
+
 // 获取用户权限
 func GetUserDataScope(userId int) (g.Map, error) {
 	srv := micro_srv.InitMicroSrvClient("User", "micro_srv.auth")

+ 172 - 0
opms_parent/app/service/contract/report.go

@@ -0,0 +1,172 @@
+package service
+
+import (
+	"context"
+	dao "dashoo.cn/micro/app/dao/contract"
+	"dashoo.cn/micro/app/model/contract"
+	"dashoo.cn/micro/app/service"
+	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/myerrors"
+	"fmt"
+	"github.com/gogf/gf/frame/g"
+)
+
+type ContractReportService struct {
+	Dao *dao.CtrContractDao
+	*service.ContextService
+}
+
+func NewContractReportService(ctx context.Context) (svc *ContractReportService, err error) {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
+		return nil, err //fmt.Errorf("获取租户码异常:%s", err.Error())
+	}
+
+	svc = new(ContractReportService)
+	if svc.ContextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = dao.NewCtrContractDao(tenant)
+	return svc, nil
+}
+
+type CollectionNumData struct {
+	contract.CtrContractCollection
+	InchargeId   int     `orm:"incharge_id"           json:"inchargeId"`   // 负责人ID
+	InchargeName string  `orm:"incharge_name"         json:"inchargeName"` // 负责人(销售工程师)
+	ProductLine  string  `orm:"product_line"          json:"productLine"`  // 产品线
+	Total        float64 `orm:"total"`                                     // 合计
+}
+
+// QueryCollectionNum 业绩指标-回款金额
+func (s *ContractReportService) QueryCollectionNum(date string) (interface{}, error) {
+	// 获取数据
+	var collectionInfos []*CollectionNumData
+	err := s.Dao.DB.Model("ctr_contract_collection a").InnerJoin("ctr_contract b", "a.contract_id=b.id").Where(fmt.Sprintf("collection_datetime LIKE '%v%%'", date)).Fields("a.*,b.incharge_id,b.incharge_name,b.product_line,SUM(a.collection_amount) total").Group("incharge_id, product_line").Order("incharge_id ASC, product_line ASC").Scan(&collectionInfos)
+	if err != nil {
+		return nil, err
+	}
+	// 获取销售数据
+	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 1000)
+	if err != nil {
+		return nil, err
+	}
+	// BIOBANK CELLSOP LIMS+基因 其他
+	header, data := make([]g.Map, 0), make([]g.Map, 0)
+	header = append(header, g.Map{"prop": "userName", "label": "销售工程师"}, g.Map{"prop": "bio", "label": "BIOBANK"}, g.Map{"prop": "cell", "label": "CELLSOP"}, g.Map{"prop": "lims", "label": "LIMS+基因"}, g.Map{"prop": "other", "label": "其他"}, g.Map{"prop": "total", "label": "合计"})
+
+	user2Collections := make(map[int][]*CollectionNumData, 0)
+	total := float64(0)
+	for _, col := range collectionInfos {
+		if _, ok := user2Collections[col.InchargeId]; !ok {
+			user2Collections[col.InchargeId] = make([]*CollectionNumData, 0)
+		}
+		user2Collections[col.InchargeId] = append(user2Collections[col.InchargeId], col)
+		total += col.Total
+	}
+	// 统计数据
+	for _, user := range userList {
+		bio, cell, lims, other, tot := float64(0), float64(0), float64(0), float64(0), float64(0)
+		if len(user2Collections[user["Id"].(int)]) > 0 {
+			for _, col := range user2Collections[user["Id"].(int)] {
+				tot += col.Total
+				if col.ProductLine == "10" {
+					bio += col.Total
+				} else if col.ProductLine == "20" {
+					cell += col.Total
+				} else if col.ProductLine == "30" {
+					lims += col.Total
+				} else {
+					other += col.Total
+				}
+			}
+		}
+		data = append(data, g.Map{
+			"userName": user["NickName"],
+			"bio":      fmt.Sprintf("%.2f", bio),
+			"cell":     fmt.Sprintf("%.2f", cell),
+			"lims":     fmt.Sprintf("%.2f", lims),
+			"other":    fmt.Sprintf("%.2f", other),
+			"total":    fmt.Sprintf("%.2f", tot),
+		})
+	}
+	data = append(data, g.Map{
+		"userName": "",
+		"bio":      "",
+		"cell":     "",
+		"lims":     "",
+		"other":    "",
+		"total":    fmt.Sprintf("总计:%.2f元", total),
+	})
+
+	return g.Map{"header": header, "data": data}, nil
+}
+
+// QueryContractNum 业绩指标-签约合同金额
+func (s *ContractReportService) QueryContractNum(date string) (interface{}, error) {
+	type ContractNumData struct {
+		contract.CtrContract
+		Total float64 `orm:"total"` // 合计
+	}
+	// 获取数据
+	var contractInfos []*ContractNumData
+	err := s.Dao.Where(fmt.Sprintf("contract_sign_time LIKE '%v%%'", date)).Fields("ctr_contract.*,SUM(contract_amount) total").Group("incharge_id, product_line").Order("incharge_id ASC, product_line ASC").Scan(&contractInfos)
+	if err != nil {
+		return nil, err
+	}
+	// 获取销售数据
+	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 1000)
+	if err != nil {
+		return nil, err
+	}
+	// BIOBANK CELLSOP LIMS+基因 其他
+	header, data := make([]g.Map, 0), make([]g.Map, 0)
+	header = append(header, g.Map{"prop": "userName", "label": "销售工程师"}, g.Map{"prop": "bio", "label": "BIOBANK"}, g.Map{"prop": "cell", "label": "CELLSOP"}, g.Map{"prop": "lims", "label": "LIMS+基因"}, g.Map{"prop": "other", "label": "其他"}, g.Map{"prop": "total", "label": "合计"})
+
+	user2Collections := make(map[int][]*ContractNumData, 0)
+	total := float64(0)
+	for _, col := range contractInfos {
+		if _, ok := user2Collections[col.InchargeId]; !ok {
+			user2Collections[col.InchargeId] = make([]*ContractNumData, 0)
+		}
+		user2Collections[col.InchargeId] = append(user2Collections[col.InchargeId], col)
+		total += col.Total
+	}
+	// 统计数据
+	for _, user := range userList {
+		bio, cell, lims, other, tot := float64(0), float64(0), float64(0), float64(0), float64(0)
+		if len(user2Collections[user["Id"].(int)]) > 0 {
+			for _, col := range user2Collections[user["Id"].(int)] {
+				tot += col.Total
+				if col.ProductLine == "10" {
+					bio += col.Total
+				} else if col.ProductLine == "20" {
+					cell += col.Total
+				} else if col.ProductLine == "30" {
+					lims += col.Total
+				} else {
+					other += col.Total
+				}
+			}
+		}
+		data = append(data, g.Map{
+			"userName": user["NickName"],
+			"bio":      fmt.Sprintf("%.2f", bio),
+			"cell":     fmt.Sprintf("%.2f", cell),
+			"lims":     fmt.Sprintf("%.2f", lims),
+			"other":    fmt.Sprintf("%.2f", other),
+			"total":    fmt.Sprintf("%.2f", tot),
+		})
+	}
+	data = append(data, g.Map{
+		"userName": "",
+		"bio":      "",
+		"cell":     "",
+		"lims":     "",
+		"other":    "",
+		"total":    fmt.Sprintf("总计:%.2f元", total),
+	})
+
+	return g.Map{"header": header, "data": data}, nil
+}

+ 1 - 0
opms_parent/main.go

@@ -72,6 +72,7 @@ func main() {
 	s.RegisterName("CustCustomerInvoiceHeader", new(cust.CustCustomerInvoiceHeaderHandler), "")
 	s.RegisterName("Questionnaire", new(plat.QuestionnaireHandler), "")
 	s.RegisterName("TableColsConfig", new(plat.TableColsConfigHandler), "")
+	s.RegisterName("ContractReport", new(contract.ContractReportHandler), "")
 
 	// 首页
 	s.RegisterName("Home", new(home.HomeHandler), "")