kobe6258 7 месяцев назад
Родитель
Сommit
73ddd4b13e

+ 216 - 0
controllers/cutomer_product_risk_mapping.go

@@ -0,0 +1,216 @@
+package controllers
+
+import (
+	"encoding/json"
+	"errors"
+	"eta/eta_mini_crm_ht/models"
+	"eta/eta_mini_crm_ht/models/request"
+	"eta/eta_mini_crm_ht/models/response"
+	"github.com/beego/beego/v2/client/orm"
+	"regexp"
+	"strings"
+)
+
+type CustomerProductRiskMappingController struct {
+	BaseAuthController
+}
+
+// GetMappingList
+// @Title 获取风险等级映射关系
+// @Description 获取风险等级映射关系
+// @Success 200 {object} models.LoginResp
+// @router /mappingList [get]
+func (this *CustomerProductRiskMappingController) GetMappingList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	list, err := models.GetMappingList()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	var viewList []*models.CustomerProductRiskMappingView
+	for _, item := range list {
+		viewList = append(viewList, item.ToView())
+	}
+	resp := new(response.CustomerProductRiskMappingListResp)
+	resp.List = viewList
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// AddMapping
+// @Title 获取产品风险等级
+// @Description  获取产品风险等级
+// @Success 200 {object} models.LoginResp
+// @router /addMapping [post]
+func (this *CustomerProductRiskMappingController) AddMapping() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.CustomerProductRiskMappingListReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "请求参数错误"
+		br.ErrMsg = "解析请求参数异常,Err:" + err.Error()
+		return
+	}
+	if req.CustomerRisk == "" {
+		br.Msg = "客户风险等级为空"
+		br.ErrMsg = "客户风险等级为空"
+		return
+	}
+	if req.ProductRisk == "" {
+		br.Msg = "产品风险等级为空"
+		br.ErrMsg = "产品风险等级为空"
+		return
+	}
+	exist, err := models.CheckCustomerRisk(req.CustomerRisk)
+	if err != nil {
+		br.Msg = "查询客户产品风险等级规则失败"
+		br.ErrMsg = "查询客户产品风险等级规则失败:" + err.Error()
+		return
+	}
+	if !checkCustomerRiskLevel(req.CustomerRisk) {
+		br.Msg = "客户产品风险等级非法"
+		br.ErrMsg = "客户产品风险等级非法:" + req.CustomerRisk
+		return
+	}
+	pdList := strings.Split(req.ProductRisk, ",")
+	for _, pd := range pdList {
+		if !checkProductRiskLevel(pd) {
+			br.Msg = "产品风险等级非法"
+			br.ErrMsg = "产品风险等级非法:" + pd
+			return
+		}
+	}
+	if exist {
+		br.Msg = "该用户风险等级已配置"
+		br.ErrMsg = "该用户风险等级已配置"
+		return
+	}
+	var mapping models.CustomerProductRiskMapping
+	mapping.CustomerRisk = req.CustomerRisk
+	mapping.ProductRisk = req.ProductRisk
+	mapping.Creator = this.SysUser.SysRealName
+	err = mapping.Insert()
+	if err != nil {
+		br.Msg = "新增客户风险等级规则失败"
+		br.ErrMsg = "新增客户风险等级规则失败:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新增成功"
+}
+
+// EditMapping
+// @Title 获取产品风险等级
+// @Description  获取产品风险等级
+// @Success 200 {object} models.LoginResp
+// @router /editMapping [post]
+func (this *CustomerProductRiskMappingController) EditMapping() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.CustomerProductRiskMappingListReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "请求参数错误"
+		br.ErrMsg = "解析请求参数异常,Err:" + err.Error()
+		return
+	}
+	if req.CustomerRisk == "" {
+		br.Msg = "客户风险等级为空"
+		br.ErrMsg = "客户风险等级为空"
+		return
+	}
+	if req.ProductRisk == "" {
+		br.Msg = "产品风险等级为空"
+		br.ErrMsg = "产品风险等级为空"
+		return
+	}
+	mapping, err := models.GetCustomerRiskMapping(req.CustomerRisk)
+	if err != nil {
+		br.Msg = "编辑用户风险等级配置失败"
+		br.ErrMsg = "编辑用户风险等级配置失败:" + err.Error()
+		return
+	}
+	mapping.ProductRisk = req.ProductRisk
+	mapping.Modifier = this.SysUser.SysRealName
+	err = mapping.Update()
+	if err != nil {
+		br.Msg = "编辑客户风险等级规则失败"
+		br.ErrMsg = "编辑客户风险等级规则失败:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "编辑成功"
+}
+
+// DeleteMapping
+// @Title 获取产品风险等级
+// @Description  获取产品风险等级
+// @Success 200 {object} models.LoginResp
+// @router /deleteMapping [post]
+func (this *CustomerProductRiskMappingController) DeleteMapping() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.CustomerProductRiskMappingListReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "请求参数错误"
+		br.ErrMsg = "解析请求参数异常,Err:" + err.Error()
+		return
+	}
+	if req.CustomerRisk == "" {
+		br.Msg = "客户风险等级为空"
+		br.ErrMsg = "客户风险等级为空"
+		return
+	}
+	mapping, err := models.GetCustomerRiskMapping(req.CustomerRisk)
+	if err != nil && errors.Is(err, orm.ErrNoRows) {
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "删除成功"
+	}
+	mapping.IsDeleted = true
+	mapping.Modifier = this.SysUser.SysRealName
+	err = mapping.Delete()
+	if err != nil {
+		br.Msg = "编辑客户风险等级规则失败"
+		br.ErrMsg = "编辑客户风险等级规则失败:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "删除成功"
+}
+
+func checkCustomerRiskLevel(riskLevel string) (exist bool) {
+	pattern := `^C\d+$`
+	matched, _ := regexp.MatchString(pattern, riskLevel)
+	_, err := models.GetCustomerRisk(riskLevel)
+	if err != nil {
+		return false
+	}
+	return matched
+}
+func checkProductRiskLevel(riskLevel string) (exist bool) {
+	pattern := `^R\d+$`
+	matched, _ := regexp.MatchString(pattern, riskLevel)
+	return matched
+}

+ 82 - 0
models/customer_product_risk_mapping.go

@@ -0,0 +1,82 @@
+package models
+
+import (
+	"errors"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CustomerProductRiskMappingView struct {
+	Id           int
+	CustomerRisk string
+	ProductRisk  string
+	Creator      string
+	UpdatedTime  string
+}
+
+func (cp *CustomerProductRiskMapping) ToView() *CustomerProductRiskMappingView {
+	return &CustomerProductRiskMappingView{
+		Id:           cp.Id,
+		CustomerRisk: cp.CustomerRisk,
+		ProductRisk:  cp.ProductRisk,
+		Creator:      cp.Creator,
+		UpdatedTime:  cp.UpdatedTime.Format(time.DateTime),
+	}
+}
+
+type CustomerProductRiskMapping struct {
+	Id           int       `description:"primaryKey;autoIncrement"`
+	CustomerRisk string    `description:"size:10"`                                 // 客户风险
+	ProductRisk  string    `description:"size:10"`                                 // 产品风险
+	Creator      string    `description:"size:10"`                                 //创建人
+	Modifier     string    `description:"size:10"`                                 //修改人
+	IsDeleted    bool      `description:"default:0"`                               // 是否删除
+	CreatedTime  time.Time `description:"default:null"`                            // 创建时间
+	UpdatedTime  time.Time `description:"default:null;onUpdate:CURRENT_TIMESTAMP"` // 更新时间
+}
+
+func GetMappingList() (list []*CustomerProductRiskMapping, err error) {
+	o := orm.NewOrm()
+	sql := "select id, customer_risk,product_risk,creator  from customer_product_risk_mapping where is_deleted= ? ORDER BY CAST(substr(customer_risk,  2) AS UNSIGNED)"
+	_, err = o.Raw(sql, false).QueryRows(&list)
+	return
+}
+
+func CheckCustomerRisk(customerRisk string) (exist bool, err error) {
+	var mapping *CustomerProductRiskMapping
+	o := orm.NewOrm()
+	sql := "select id, customer_risk,product_risk,creator  from customer_product_risk_mapping where customer_risk=? and is_deleted= ?   "
+	err = o.Raw(sql, customerRisk, false).QueryRow(&mapping)
+	if err != nil && !errors.Is(err, orm.ErrNoRows) {
+		return
+	}
+	if errors.Is(err, orm.ErrNoRows) || mapping.Id == 0 {
+		exist = false
+		err = nil
+		return
+	}
+	exist = true
+	return
+}
+func (cp *CustomerProductRiskMapping) Insert() (err error) {
+	cp.CreatedTime = time.Now()
+	o := orm.NewOrm()
+	_, err = o.Insert(cp)
+	return
+}
+func (cp *CustomerProductRiskMapping) Update() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(cp, "product_risk", "modifier")
+	return
+}
+func (cp *CustomerProductRiskMapping) Delete() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(cp, "is_deleted", "modifier")
+	return
+}
+func GetCustomerRiskMapping(customerRisk string) (mapping *CustomerProductRiskMapping, err error) {
+	o := orm.NewOrm()
+	sql := "select id, customer_risk,product_risk,creator  from customer_product_risk_mapping where customer_risk=? and  is_deleted= ? "
+	err = o.Raw(sql, customerRisk, false).QueryRow(&mapping)
+	return
+}

+ 1 - 0
models/db.go

@@ -52,5 +52,6 @@ func init() {
 		new(Report),
 		new(RiskConfig),
 		new(Permission),
+		new(CustomerProductRiskMapping),
 	)
 }

+ 6 - 0
models/request/customer_product_risk_mapping.go

@@ -0,0 +1,6 @@
+package request
+
+type CustomerProductRiskMappingListReq struct {
+	CustomerRisk string
+	ProductRisk  string
+}

+ 7 - 0
models/response/CustomerProductRiskMappingResp.go

@@ -0,0 +1,7 @@
+package response
+
+import "eta/eta_mini_crm_ht/models"
+
+type CustomerProductRiskMappingListResp struct {
+	List []*models.CustomerProductRiskMappingView
+}

+ 6 - 0
models/risk_config.go

@@ -33,6 +33,12 @@ func GetCustomerRiskList() (list []*RiskConfig, err error) {
 	_, err = o.Raw(sql, Customer).QueryRows(&list)
 	return
 }
+func GetCustomerRisk(riskName string) (risk *RiskConfig, err error) {
+	o := orm.NewOrm()
+	sql := "select id, risk_name,risk_type  from risk_config where risk_type= ? and risk_name=?"
+	err = o.Raw(sql, Customer, riskName).QueryRow(&risk)
+	return
+}
 func (r *RiskConfig) ToView() *RiskConfigView {
 	return &RiskConfigView{
 		Id:       r.Id,

+ 36 - 0
routers/commentsRouter.go

@@ -117,6 +117,42 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"],
+        beego.ControllerComments{
+            Method: "AddMapping",
+            Router: `/addMapping`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"],
+        beego.ControllerComments{
+            Method: "DeleteMapping",
+            Router: `/deleteMapping`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"],
+        beego.ControllerComments{
+            Method: "EditMapping",
+            Router: `/editMapping`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:CustomerProductRiskMappingController"],
+        beego.ControllerComments{
+            Method: "GetMappingList",
+            Router: `/mappingList`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:FeedBackController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:FeedBackController"],
         beego.ControllerComments{
             Method: "FeedBackList",

+ 5 - 1
routers/router.go

@@ -69,7 +69,6 @@ func init() {
 		),
 		beego.NSNamespace("/media",
 			beego.NSInclude(
-				//&controllers.ImagePDFController{},
 				&controllers.AudioController{},
 				&controllers.VideoController{},
 			),
@@ -89,6 +88,11 @@ func init() {
 				&controllers.RiskConfigController{},
 			),
 		),
+		beego.NSNamespace("/customer",
+			beego.NSInclude(
+				&controllers.CustomerProductRiskMappingController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }