作者 tangxvhui

bug 修复

... ... @@ -259,7 +259,8 @@ func (c *AuditController) ChanceReserveTypeList() {
msg = protocol.BadRequestParam("1")
return
}
list := serveaudit.GetReserveTypeLsit(param.PageIndex, param.PageSize)
companyId := c.GetCompanyId()
list := serveaudit.GetReserveTypeLsit(param.PageIndex, param.PageSize, companyId)
msg = protocol.NewReturnResponse(list, nil)
return
}
... ... @@ -281,11 +282,12 @@ func (c *AuditController) EditReserveType() {
msg = protocol.BadRequestParam("1")
return
}
companyId := c.GetCompanyId()
var err error
if param.Id == 0 {
err = serveaudit.AddReserveType(param.Name)
err = serveaudit.AddReserveType(param.Name, companyId)
} else {
err = serveaudit.EditReserveType(param.Id, param.Name)
err = serveaudit.EditReserveType(param.Id, param.Name, companyId)
}
msg = protocol.NewReturnResponse(nil, err)
return
... ... @@ -307,7 +309,8 @@ func (c *AuditController) DeleteReserveType() {
msg = protocol.BadRequestParam("1")
return
}
err := serveaudit.DeleteReserveType(param.Id)
companyId := c.GetCompanyId()
err := serveaudit.DeleteReserveType(param.Id, companyId)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -47,3 +47,20 @@ func DeleteChanceReserveType(id int) (err error) {
_, err = o.Delete(m)
return err
}
func GetChanceReserveTypeById(id int) (m *ChanceReserveType, err error) {
o := orm.NewOrm()
m = &ChanceReserveType{Id: id}
err = o.Read(m)
return m, err
}
func HasChanceReserveTypeName(name string, companyid int64, notId int) bool {
var bl bool
o := orm.NewOrm()
bl = o.QueryTable(&ChanceReserveType{}).
Filter("name", name).
Filter("company_id", companyid).
Exclude("id", notId).
Exist()
return bl
}
... ...
... ... @@ -128,6 +128,8 @@ var errmessge ErrorMap = map[string]string{
"10128": "自查内容维度最多输入30个字段",
"10129": "存在自查内容时只能进行或签设置",
"10130": "同一级的自查内容不能重复",
"10131": "储备池分类名称已存在",
"10132": "无法删除已使用的储备池分类",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -8,7 +8,7 @@ import (
"github.com/astaxie/beego/orm"
)
func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceReserveTypeList {
func GetReserveTypeLsit(pageIndex int, pageSize int, companyid int64) protocol.ResponseChanceReserveTypeList {
rsp := protocol.ResponseChanceReserveTypeList{
ResponsePageInfo: protocol.ResponsePageInfo{
TotalPage: 0,
... ... @@ -22,7 +22,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&models.ChanceReserveType{}).Count()
cnt, err = o.QueryTable(&models.ChanceReserveType{}).Filter("company_id", companyid).Count()
if err != nil {
log.Error("获取chance_reserve_type记录数失败,err:%s", err)
return rsp
... ... @@ -32,6 +32,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese
}
first := (pageIndex - 1) * pageSize
_, err = o.QueryTable(&models.ChanceReserveType{}).
Filter("company_id", companyid).
OrderBy("-create_at").
Limit(pageSize, first).
All(&allData)
... ... @@ -50,9 +51,14 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese
return rsp
}
func AddReserveType(name string) error {
func AddReserveType(name string, companyid int64) error {
has := models.HasChanceReserveTypeName(name, companyid, 0)
if has {
return protocol.NewErrWithMessage("10131")
}
m := &models.ChanceReserveType{
Name: name,
Name: name,
CompanyId: companyid,
}
_, err := models.AddChanceReserveType(m)
if err != nil {
... ... @@ -61,20 +67,49 @@ func AddReserveType(name string) error {
return nil
}
func EditReserveType(id int, name string) error {
m := &models.ChanceReserveType{
Id: id,
Name: name,
func EditReserveType(id int, name string, companyid int64) error {
has := models.HasChanceReserveTypeName(name, companyid, id)
if has {
return protocol.NewErrWithMessage("10131")
}
m := &models.ChanceReserveType{}
var err error
m, err = models.GetChanceReserveTypeById(id)
if err != nil {
log.Error("获取chance_resersve_type数据失败,err:%s", err)
return protocol.NewErrWithMessage("1")
}
if m.CompanyId != companyid {
log.Error("chance_resersve_type数据对应公司错误")
return protocol.NewErrWithMessage("1")
}
err := models.UpdateChanceReserveType(m, []string{"Name"})
m.Name = name
err = models.UpdateChanceReserveType(m, []string{"Name"})
if err != nil {
log.Error("更新储备池类似失败,err:%s", err)
}
return nil
}
func DeleteReserveType(id int) error {
err := models.DeleteChanceReserveType(id)
func DeleteReserveType(id int, companyid int64) error {
m := &models.ChanceReserveType{}
var err error
m, err = models.GetChanceReserveTypeById(id)
if err != nil {
log.Error("获取chance_resersve_type数据失败,err:%s", err)
return protocol.NewErrWithMessage("1")
}
if m.CompanyId != companyid {
log.Error("chance_resersve_type数据对应公司错误")
return protocol.NewErrWithMessage("1")
}
//是否可以被删除
o := orm.NewOrm()
has := o.QueryTable(&models.Chance{}).Filter("reserve_type_id", id).Exist()
if has {
return protocol.NewErrWithMessage("10132")
}
err = models.DeleteChanceReserveType(id)
if err != nil {
log.Error("删除储备池类似失败,err:%s", err)
}
... ...