|
@@ -2,6 +2,7 @@ package Company
|
|
|
|
|
|
import (
|
|
|
"Cold_Api/conf"
|
|
|
+ "Cold_Api/logs"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/cache"
|
|
@@ -61,8 +62,8 @@ func init() {
|
|
|
var err error
|
|
|
redisCache_CompanyNotice, err = cache.NewCache("redis", config)
|
|
|
if err != nil || redisCache_CompanyNotice == nil {
|
|
|
- errMsg := "failed to init redis"
|
|
|
- fmt.Println(errMsg, err)
|
|
|
+ errMsg := "failed to init redis_CompanyNotice"
|
|
|
+ logs.Error(errMsg, err)
|
|
|
panic(errMsg)
|
|
|
}
|
|
|
|
|
@@ -75,13 +76,13 @@ func Redis_CompanyNotice_Set(r CompanyNotice) (err error) {
|
|
|
//json序列化
|
|
|
str, err := json.Marshal(r)
|
|
|
if err != nil {
|
|
|
- fmt.Print(err)
|
|
|
+ logs.Error("json Marshal err", err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
err = redisCache_CompanyNotice.Put(key, str, 2*time.Hour)
|
|
|
if err != nil {
|
|
|
- fmt.Println("set key:", key, ",value:", str, err)
|
|
|
+ logs.Error("set key:", key, ",value:", str, err)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -95,7 +96,11 @@ func Redis_CompanyNotice_Get(key string) (CompanyNotice, bool) {
|
|
|
//println("找到key:",key)
|
|
|
v := redisCache_CompanyNotice.Get(key)
|
|
|
var r CompanyNotice
|
|
|
- json.Unmarshal(v.([]byte), &r)
|
|
|
+ err := json.Unmarshal(v.([]byte), &r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Redis_CompanyNotice_Get", err)
|
|
|
+ return r, false
|
|
|
+ }
|
|
|
|
|
|
return r, true
|
|
|
}
|
|
@@ -104,6 +109,9 @@ func Redis_CompanyNotice_Get(key string) (CompanyNotice, bool) {
|
|
|
}
|
|
|
func Redis_CompanyNotice_DelK(key string) (err error) {
|
|
|
err = redisCache_CompanyNotice.Delete(key)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Redis_CompanyNotice_DelK", err)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -133,7 +141,7 @@ func Read_CompanyNotice_ById(id int) (r CompanyNotice, err error) {
|
|
|
r = CompanyNotice{Id: id}
|
|
|
err = o.Read(&r) // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
+ logs.Error("Read_CompanyNotice_ById", err)
|
|
|
return r, err
|
|
|
}
|
|
|
|
|
@@ -146,7 +154,8 @@ func Add_CompanyNotice(m CompanyNotice) (id int64, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
id, err = o.Insert(&m)
|
|
|
if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
+ logs.Error("Add_CompanyNotice", err)
|
|
|
+ return id, err
|
|
|
}
|
|
|
Redis_CompanyNotice_Set(m)
|
|
|
return
|
|
@@ -160,12 +169,15 @@ func Delete_CompanyNotice_ById(id int) bool {
|
|
|
if err := o.Read(&v); err == nil {
|
|
|
var num int64
|
|
|
v.T_State = 0
|
|
|
- if num, err = o.Update(&v, "T_State"); err == nil {
|
|
|
- fmt.Println("Number of records updated in database:", num)
|
|
|
- key := strconv.Itoa(v.Id)
|
|
|
- Redis_CompanyNotice_DelK(key)
|
|
|
- return true
|
|
|
+ num, err = o.Update(&v, "T_State")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_ById", err)
|
|
|
+ return false
|
|
|
}
|
|
|
+ fmt.Println("Number of records updated in database:", num)
|
|
|
+ key := strconv.Itoa(v.Id)
|
|
|
+ Redis_CompanyNotice_DelK(key)
|
|
|
+ return true
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
@@ -173,12 +185,14 @@ func Delete_CompanyNotice_ById(id int) bool {
|
|
|
// 修改
|
|
|
func Update_CompanyNotice(m CompanyNotice, cols ...string) bool {
|
|
|
o := orm.NewOrm()
|
|
|
- if num, err := o.Update(&m, cols...); err == nil {
|
|
|
- fmt.Println("Number of records updated in database:", num)
|
|
|
- Redis_CompanyNotice_Set(m)
|
|
|
- return true
|
|
|
+ num, err := o.Update(&m, cols...)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Update_CompanyNotice", err)
|
|
|
+ return false
|
|
|
}
|
|
|
- return false
|
|
|
+ fmt.Println("Number of records updated in database:", num)
|
|
|
+ Redis_CompanyNotice_Set(m)
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
// 删除
|
|
@@ -187,22 +201,17 @@ func Delete_CompanyNotice_ByT_pid_All(T_pid int) {
|
|
|
qs := o.QueryTable(new(CompanyNotice))
|
|
|
|
|
|
var r []CompanyNotice
|
|
|
- qs.Filter("T_pid", T_pid).Filter("T_State", 1).All(&r)
|
|
|
+ _, err := qs.Filter("T_pid", T_pid).Filter("T_State", 1).All(&r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_ByT_pid_All", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
for _, v := range r {
|
|
|
v.T_State = 0
|
|
|
if _, err := o.Update(&v, "T_State"); err == nil {
|
|
|
Redis_CompanyNotice_DelK(strconv.Itoa(v.Id))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// 获取全部
|
|
|
-func Read_CompanyNotice_All_1() (r []CompanyNotice) {
|
|
|
- o := orm.NewOrm()
|
|
|
- qs := o.QueryTable(new(CompanyNotice))
|
|
|
- qs.Filter("T_State", 1).All(&r)
|
|
|
- return r
|
|
|
}
|
|
|
|
|
|
// 获取列表
|
|
@@ -220,27 +229,22 @@ func Read_CompanyNotice_List(T_pid int, T_name string, page int, page_z int) (r
|
|
|
offset = int64((page - 1) * page_z)
|
|
|
}
|
|
|
|
|
|
- qs.Limit(conf.Page_size, offset).Filter("T_pid", T_pid).Filter("T_name__icontains", T_name).Filter("T_State", 1).OrderBy("-Id").All(&maps)
|
|
|
- cnt, _ = qs.Filter("T_pid", T_pid).Filter("T_name__icontains", T_name).Filter("T_State", 1).Count()
|
|
|
+ _, err := qs.Limit(conf.Page_size, offset).Filter("T_pid", T_pid).Filter("T_name__icontains", T_name).Filter("T_State", 1).OrderBy("-Id").All(&maps)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Read_CompanyNotice_List", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ cnt, err = qs.Filter("T_pid", T_pid).Filter("T_name__icontains", T_name).Filter("T_State", 1).Count()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Read_CompanyNotice_List Count", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
for _, v := range maps {
|
|
|
r = append(r, CompanyNoticeToCompanyNotice_R(v))
|
|
|
}
|
|
|
return r, cnt
|
|
|
}
|
|
|
|
|
|
-// 获取列表
|
|
|
-func Read_CompanyNotice_ALL_T_pid(T_pid int) (r []CompanyNotice) {
|
|
|
-
|
|
|
- o := orm.NewOrm()
|
|
|
- // 也可以直接使用 Model 结构体作为表名
|
|
|
-
|
|
|
- qs := o.QueryTable(new(CompanyNotice))
|
|
|
-
|
|
|
- qs.Filter("T_pid", T_pid).OrderBy("-Id").Filter("T_State", 1).All(&r)
|
|
|
-
|
|
|
- return r
|
|
|
-}
|
|
|
-
|
|
|
// 获取全部列表
|
|
|
func Read_CompanyNotice_All(T_pid int, T_name string) (r []CompanyNotice_R) {
|
|
|
|
|
@@ -257,7 +261,11 @@ func Read_CompanyNotice_All(T_pid int, T_name string) (r []CompanyNotice_R) {
|
|
|
cond1 = cond1.And("T_name", T_name)
|
|
|
}
|
|
|
|
|
|
- qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&map_r)
|
|
|
+ _, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&map_r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Read_CompanyNotice_All", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
for _, v := range map_r {
|
|
|
r = append(r, CompanyNoticeToCompanyNotice_R(v))
|
|
@@ -272,23 +280,37 @@ func Add_T_Notice_bind(T_sn string, T_id int, T_Notice_id int) (err error) {
|
|
|
o := orm.NewOrm()
|
|
|
v := CompanyNotice{Id: T_Notice_id}
|
|
|
T_Notice_bind := T_sn + strconv.Itoa(T_id) + "|"
|
|
|
- if err = o.Read(&v, "Id"); err == nil {
|
|
|
- v.T_Notice_bind = strings.Replace(v.T_Notice_bind, T_Notice_bind, "", -1)
|
|
|
- v.T_Notice_bind = v.T_Notice_bind + T_Notice_bind
|
|
|
- o.Update(&v, "T_Notice_bind")
|
|
|
+ err = o.Read(&v, "Id")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Add_T_Notice_bind", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ v.T_Notice_bind = strings.Replace(v.T_Notice_bind, T_Notice_bind, "", -1)
|
|
|
+ v.T_Notice_bind = v.T_Notice_bind + T_Notice_bind
|
|
|
+ _, err = o.Update(&v, "T_Notice_bind")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Add_T_Notice_bind", err)
|
|
|
+ return
|
|
|
}
|
|
|
- return err
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func Delete_T_Notice_bind(T_sn string, T_id int, T_Notice_id int) (err error) {
|
|
|
o := orm.NewOrm()
|
|
|
v := CompanyNotice{Id: T_Notice_id}
|
|
|
T_Notice_bind := T_sn + strconv.Itoa(T_id) + "|"
|
|
|
- if err = o.Read(&v, "Id"); err == nil {
|
|
|
- v.T_Notice_bind = strings.Replace(v.T_Notice_bind, T_Notice_bind, "", -1)
|
|
|
- o.Update(&v, "T_Notice_bind")
|
|
|
+ err = o.Read(&v, "Id")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_T_Notice_bind", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ v.T_Notice_bind = strings.Replace(v.T_Notice_bind, T_Notice_bind, "", -1)
|
|
|
+ _, err = o.Update(&v, "T_Notice_bind")
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_T_Notice_bind", err)
|
|
|
+ return
|
|
|
}
|
|
|
- return err
|
|
|
+ return
|
|
|
|
|
|
}
|
|
|
|
|
@@ -310,7 +332,14 @@ func Update_CompanyNotice_Bind_By_T_uuid(T_uuid, T_name string) bool {
|
|
|
Or("T_Notice_message__icontains", T_uuid).
|
|
|
Or("T_Notice_mailbox__icontains", T_uuid))
|
|
|
|
|
|
- qs.SetCond((*orm2.Condition)(cond1)).All(&map_r)
|
|
|
+ _, err := qs.SetCond((*orm2.Condition)(cond1)).All(&map_r)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_Bind_By_T_uuid_T_pid", err)
|
|
|
+ o.Rollback()
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
T_uuid_name := fmt.Sprintf("%s/%s|", T_uuid, T_name)
|
|
|
for _, v := range map_r {
|
|
|
v.T_Notice_wx = Replice_T_Notice_Bind(T_uuid, v.T_Notice_wx, T_uuid_name)
|
|
@@ -318,8 +347,9 @@ func Update_CompanyNotice_Bind_By_T_uuid(T_uuid, T_name string) bool {
|
|
|
v.T_Notice_phone = Replice_T_Notice_Bind(T_uuid, v.T_Notice_phone, T_uuid_name)
|
|
|
v.T_Notice_message = Replice_T_Notice_Bind(T_uuid, v.T_Notice_message, T_uuid_name)
|
|
|
v.T_Notice_mailbox = Replice_T_Notice_Bind(T_uuid, v.T_Notice_mailbox, T_uuid_name)
|
|
|
- _, err := o.Update(&v, "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism")
|
|
|
+ _, err = o.Update(&v, "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism")
|
|
|
if err != nil {
|
|
|
+ logs.Error("Update_CompanyNotice_Bind_By_T_uuid", err)
|
|
|
o.Rollback()
|
|
|
return false
|
|
|
}
|
|
@@ -349,7 +379,12 @@ func Delete_CompanyNotice_Bind_By_T_uuid(T_uuid string) bool {
|
|
|
Or("T_Notice_message__icontains", T_uuid).
|
|
|
Or("T_Notice_mailbox__icontains", T_uuid))
|
|
|
|
|
|
- qs.SetCond((*orm2.Condition)(cond1)).All(&map_r)
|
|
|
+ _, err := qs.SetCond((*orm2.Condition)(cond1)).All(&map_r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_Bind_By_T_uuid_T_pid", err)
|
|
|
+ o.Rollback()
|
|
|
+ return false
|
|
|
+ }
|
|
|
|
|
|
for _, v := range map_r {
|
|
|
v.T_Notice_wx = Replice_T_Notice_Bind(T_uuid, v.T_Notice_wx, "")
|
|
@@ -359,6 +394,7 @@ func Delete_CompanyNotice_Bind_By_T_uuid(T_uuid string) bool {
|
|
|
v.T_Notice_mailbox = Replice_T_Notice_Bind(T_uuid, v.T_Notice_mailbox, "")
|
|
|
_, err := o.Update(&v, "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism")
|
|
|
if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_Bind_By_T_uuid", err)
|
|
|
o.Rollback()
|
|
|
return false
|
|
|
}
|
|
@@ -389,7 +425,12 @@ func Delete_CompanyNotice_Bind_By_T_uuid_T_pid(T_uuid string, T_pids []int) bool
|
|
|
Or("T_Notice_message__icontains", T_uuid).
|
|
|
Or("T_Notice_mailbox__icontains", T_uuid))
|
|
|
|
|
|
- qs.SetCond((*orm2.Condition)(cond1)).All(&map_r)
|
|
|
+ _, err := qs.SetCond((*orm2.Condition)(cond1)).All(&map_r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_Bind_By_T_uuid_T_pid", err)
|
|
|
+ o.Rollback()
|
|
|
+ return false
|
|
|
+ }
|
|
|
|
|
|
for _, v := range map_r {
|
|
|
v.T_Notice_wx = Replice_T_Notice_Bind(T_uuid, v.T_Notice_wx, "")
|
|
@@ -399,6 +440,7 @@ func Delete_CompanyNotice_Bind_By_T_uuid_T_pid(T_uuid string, T_pids []int) bool
|
|
|
v.T_Notice_mailbox = Replice_T_Notice_Bind(T_uuid, v.T_Notice_mailbox, "")
|
|
|
_, err := o.Update(&v, "T_Notice_wx", "T_Notice_wx2", "T_Notice_phone", "T_Notice_message", "T_Notice_mailbox", "T_Notice_mechanism")
|
|
|
if err != nil {
|
|
|
+ logs.Error("Delete_CompanyNotice_Bind_By_T_uuid_T_pid", err)
|
|
|
o.Rollback()
|
|
|
return false
|
|
|
}
|