作者 tangxvhui

bug 修复

@@ -259,7 +259,8 @@ func (c *AuditController) ChanceReserveTypeList() { @@ -259,7 +259,8 @@ func (c *AuditController) ChanceReserveTypeList() {
259 msg = protocol.BadRequestParam("1") 259 msg = protocol.BadRequestParam("1")
260 return 260 return
261 } 261 }
262 - list := serveaudit.GetReserveTypeLsit(param.PageIndex, param.PageSize) 262 + companyId := c.GetCompanyId()
  263 + list := serveaudit.GetReserveTypeLsit(param.PageIndex, param.PageSize, companyId)
263 msg = protocol.NewReturnResponse(list, nil) 264 msg = protocol.NewReturnResponse(list, nil)
264 return 265 return
265 } 266 }
@@ -281,11 +282,12 @@ func (c *AuditController) EditReserveType() { @@ -281,11 +282,12 @@ func (c *AuditController) EditReserveType() {
281 msg = protocol.BadRequestParam("1") 282 msg = protocol.BadRequestParam("1")
282 return 283 return
283 } 284 }
  285 + companyId := c.GetCompanyId()
284 var err error 286 var err error
285 if param.Id == 0 { 287 if param.Id == 0 {
286 - err = serveaudit.AddReserveType(param.Name) 288 + err = serveaudit.AddReserveType(param.Name, companyId)
287 } else { 289 } else {
288 - err = serveaudit.EditReserveType(param.Id, param.Name) 290 + err = serveaudit.EditReserveType(param.Id, param.Name, companyId)
289 } 291 }
290 msg = protocol.NewReturnResponse(nil, err) 292 msg = protocol.NewReturnResponse(nil, err)
291 return 293 return
@@ -307,7 +309,8 @@ func (c *AuditController) DeleteReserveType() { @@ -307,7 +309,8 @@ func (c *AuditController) DeleteReserveType() {
307 msg = protocol.BadRequestParam("1") 309 msg = protocol.BadRequestParam("1")
308 return 310 return
309 } 311 }
310 - err := serveaudit.DeleteReserveType(param.Id) 312 + companyId := c.GetCompanyId()
  313 + err := serveaudit.DeleteReserveType(param.Id, companyId)
311 msg = protocol.NewReturnResponse(nil, err) 314 msg = protocol.NewReturnResponse(nil, err)
312 return 315 return
313 } 316 }
@@ -47,3 +47,20 @@ func DeleteChanceReserveType(id int) (err error) { @@ -47,3 +47,20 @@ func DeleteChanceReserveType(id int) (err error) {
47 _, err = o.Delete(m) 47 _, err = o.Delete(m)
48 return err 48 return err
49 } 49 }
  50 +
  51 +func GetChanceReserveTypeById(id int) (m *ChanceReserveType, err error) {
  52 + o := orm.NewOrm()
  53 + m = &ChanceReserveType{Id: id}
  54 + err = o.Read(m)
  55 + return m, err
  56 +}
  57 +func HasChanceReserveTypeName(name string, companyid int64, notId int) bool {
  58 + var bl bool
  59 + o := orm.NewOrm()
  60 + bl = o.QueryTable(&ChanceReserveType{}).
  61 + Filter("name", name).
  62 + Filter("company_id", companyid).
  63 + Exclude("id", notId).
  64 + Exist()
  65 + return bl
  66 +}
@@ -128,6 +128,8 @@ var errmessge ErrorMap = map[string]string{ @@ -128,6 +128,8 @@ var errmessge ErrorMap = map[string]string{
128 "10128": "自查内容维度最多输入30个字段", 128 "10128": "自查内容维度最多输入30个字段",
129 "10129": "存在自查内容时只能进行或签设置", 129 "10129": "存在自查内容时只能进行或签设置",
130 "10130": "同一级的自查内容不能重复", 130 "10130": "同一级的自查内容不能重复",
  131 + "10131": "储备池分类名称已存在",
  132 + "10132": "无法删除已使用的储备池分类",
131 } 133 }
132 134
133 //错误码转换 ,兼容需要 135 //错误码转换 ,兼容需要
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 "github.com/astaxie/beego/orm" 8 "github.com/astaxie/beego/orm"
9 ) 9 )
10 10
11 -func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceReserveTypeList { 11 +func GetReserveTypeLsit(pageIndex int, pageSize int, companyid int64) protocol.ResponseChanceReserveTypeList {
12 rsp := protocol.ResponseChanceReserveTypeList{ 12 rsp := protocol.ResponseChanceReserveTypeList{
13 ResponsePageInfo: protocol.ResponsePageInfo{ 13 ResponsePageInfo: protocol.ResponsePageInfo{
14 TotalPage: 0, 14 TotalPage: 0,
@@ -22,7 +22,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese @@ -22,7 +22,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese
22 err error 22 err error
23 ) 23 )
24 o := orm.NewOrm() 24 o := orm.NewOrm()
25 - cnt, err = o.QueryTable(&models.ChanceReserveType{}).Count() 25 + cnt, err = o.QueryTable(&models.ChanceReserveType{}).Filter("company_id", companyid).Count()
26 if err != nil { 26 if err != nil {
27 log.Error("获取chance_reserve_type记录数失败,err:%s", err) 27 log.Error("获取chance_reserve_type记录数失败,err:%s", err)
28 return rsp 28 return rsp
@@ -32,6 +32,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese @@ -32,6 +32,7 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese
32 } 32 }
33 first := (pageIndex - 1) * pageSize 33 first := (pageIndex - 1) * pageSize
34 _, err = o.QueryTable(&models.ChanceReserveType{}). 34 _, err = o.QueryTable(&models.ChanceReserveType{}).
  35 + Filter("company_id", companyid).
35 OrderBy("-create_at"). 36 OrderBy("-create_at").
36 Limit(pageSize, first). 37 Limit(pageSize, first).
37 All(&allData) 38 All(&allData)
@@ -50,9 +51,14 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese @@ -50,9 +51,14 @@ func GetReserveTypeLsit(pageIndex int, pageSize int) protocol.ResponseChanceRese
50 return rsp 51 return rsp
51 } 52 }
52 53
53 -func AddReserveType(name string) error { 54 +func AddReserveType(name string, companyid int64) error {
  55 + has := models.HasChanceReserveTypeName(name, companyid, 0)
  56 + if has {
  57 + return protocol.NewErrWithMessage("10131")
  58 + }
54 m := &models.ChanceReserveType{ 59 m := &models.ChanceReserveType{
55 - Name: name, 60 + Name: name,
  61 + CompanyId: companyid,
56 } 62 }
57 _, err := models.AddChanceReserveType(m) 63 _, err := models.AddChanceReserveType(m)
58 if err != nil { 64 if err != nil {
@@ -61,20 +67,49 @@ func AddReserveType(name string) error { @@ -61,20 +67,49 @@ func AddReserveType(name string) error {
61 return nil 67 return nil
62 } 68 }
63 69
64 -func EditReserveType(id int, name string) error {  
65 - m := &models.ChanceReserveType{  
66 - Id: id,  
67 - Name: name, 70 +func EditReserveType(id int, name string, companyid int64) error {
  71 + has := models.HasChanceReserveTypeName(name, companyid, id)
  72 + if has {
  73 + return protocol.NewErrWithMessage("10131")
  74 + }
  75 + m := &models.ChanceReserveType{}
  76 + var err error
  77 + m, err = models.GetChanceReserveTypeById(id)
  78 + if err != nil {
  79 + log.Error("获取chance_resersve_type数据失败,err:%s", err)
  80 + return protocol.NewErrWithMessage("1")
  81 + }
  82 + if m.CompanyId != companyid {
  83 + log.Error("chance_resersve_type数据对应公司错误")
  84 + return protocol.NewErrWithMessage("1")
68 } 85 }
69 - err := models.UpdateChanceReserveType(m, []string{"Name"}) 86 + m.Name = name
  87 + err = models.UpdateChanceReserveType(m, []string{"Name"})
70 if err != nil { 88 if err != nil {
71 log.Error("更新储备池类似失败,err:%s", err) 89 log.Error("更新储备池类似失败,err:%s", err)
72 } 90 }
73 return nil 91 return nil
74 } 92 }
75 93
76 -func DeleteReserveType(id int) error {  
77 - err := models.DeleteChanceReserveType(id) 94 +func DeleteReserveType(id int, companyid int64) error {
  95 + m := &models.ChanceReserveType{}
  96 + var err error
  97 + m, err = models.GetChanceReserveTypeById(id)
  98 + if err != nil {
  99 + log.Error("获取chance_resersve_type数据失败,err:%s", err)
  100 + return protocol.NewErrWithMessage("1")
  101 + }
  102 + if m.CompanyId != companyid {
  103 + log.Error("chance_resersve_type数据对应公司错误")
  104 + return protocol.NewErrWithMessage("1")
  105 + }
  106 + //是否可以被删除
  107 + o := orm.NewOrm()
  108 + has := o.QueryTable(&models.Chance{}).Filter("reserve_type_id", id).Exist()
  109 + if has {
  110 + return protocol.NewErrWithMessage("10132")
  111 + }
  112 + err = models.DeleteChanceReserveType(id)
78 if err != nil { 113 if err != nil {
79 log.Error("删除储备池类似失败,err:%s", err) 114 log.Error("删除储备池类似失败,err:%s", err)
80 } 115 }