|
@@ -48,7 +48,9 @@ func (this *EntExportAuth) Set() {
|
|
|
if Mysql.ExecTx("设置数据导出权限", func(tx *sql.Tx) bool {
|
|
|
ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, "update entniche_user set export_power=0 where ent_id=? and export_power=1", entId)
|
|
|
ok_2 := Mysql.UpdateOrDeleteBySqlByTx(tx, "update entniche_user set export_power=1 where id in ("+ws+") and ent_id=?", args...)
|
|
|
- return ok_1 > -1 && ok_2 > 0
|
|
|
+ ok_3 := Mysql.UpdateOrDeleteBySqlByTx(tx, `INSERT INTO entniche_export_limit (ent_id,user_id) SELECT ent_id,id AS user_id FROM entniche_user a WHERE id IN (`+ws+`) AND ent_id=? AND NOT EXISTS (SELECT 1 FROM entniche_export_limit b WHERE a.id=b.user_id`, args...)
|
|
|
+ ok_4 := Mysql.UpdateOrDeleteBySqlByTx(tx, `INSERT INTO entniche_export_limit_log (user_id,data_limit,max_nums,TYPE) SELECT user_id,data_limit,max_nums,0 FROM entniche_export_limit WHERE user_id IN (`+ws+`) AND ent_id=?`, args...)
|
|
|
+ return ok_1 > -1 && ok_2 > 0 && ok_3 > -1 && ok_4 > 0
|
|
|
}) {
|
|
|
status = 1
|
|
|
}
|
|
@@ -346,46 +348,89 @@ func (this *EntExportAuth) EntPersonss() {
|
|
|
|
|
|
// 管理员为用户设置每日导出限额
|
|
|
func (this *EntExportAuth) SetLimit() {
|
|
|
- if !R.CheckReqParam(this.ResponseWriter, this.Request, "userId", "limitNum") {
|
|
|
+ if !R.CheckReqParam(this.ResponseWriter, this.Request, "userId") {
|
|
|
return
|
|
|
}
|
|
|
status := 0
|
|
|
- limitNum, _ := this.GetInteger("limitNum")
|
|
|
+ limitNumTemp := this.GetString("limitNum")
|
|
|
+ maxNumsTemp := this.GetString("maxNums")
|
|
|
userId, _ := this.GetInteger("userId")
|
|
|
entId := util.IntAll(this.GetSession("entId"))
|
|
|
limitId, _ := this.GetInteger("limitId")
|
|
|
+ reqType := this.GetString("reqType")
|
|
|
+ var limitNum, maxNums interface{}
|
|
|
+ if limitNumTemp != "" {
|
|
|
+ limitNum = util.IntAll(limitNumTemp)
|
|
|
+ }
|
|
|
+ if maxNumsTemp != "" {
|
|
|
+ maxNums = util.IntAll(maxNumsTemp)
|
|
|
+ }
|
|
|
if limitId != 0 {
|
|
|
//之前设置过限额,现在只需更新
|
|
|
- limit := Mysql.FindOne("entniche_export_limit", map[string]interface{}{"user_id": userId}, "export_nums", "")
|
|
|
+ limit := Mysql.FindOne("entniche_export_limit", map[string]interface{}{"user_id": userId}, "export_nums,remain_nums,surplus_nums", "")
|
|
|
if limit != nil {
|
|
|
- exportNums := util.IntAll((*limit)["export_nums"])
|
|
|
- //计算剩余量
|
|
|
- var remainNums int
|
|
|
- if limitNum <= exportNums {
|
|
|
- remainNums = 0
|
|
|
+ setMap := map[string]interface{}{}
|
|
|
+ if reqType == "maxNums" {
|
|
|
+ setMap["max_nums"] = maxNums
|
|
|
} else {
|
|
|
- remainNums = limitNum - exportNums
|
|
|
- }
|
|
|
- setMap := map[string]interface{}{
|
|
|
- "data_limit": limitNum,
|
|
|
- "remain_nums": remainNums,
|
|
|
+ if limitNum != nil {
|
|
|
+ exportNums := util.IntAll((*limit)["export_nums"])
|
|
|
+ //计算剩余量
|
|
|
+ var remainNums int
|
|
|
+ if util.IntAll(limitNum) <= exportNums {
|
|
|
+ remainNums = 0
|
|
|
+ } else {
|
|
|
+ remainNums = util.IntAll(limitNum) - exportNums
|
|
|
+ }
|
|
|
+ setMap["remain_nums"] = remainNums
|
|
|
+ }
|
|
|
+ setMap["data_limit"] = limitNum
|
|
|
}
|
|
|
- u := Mysql.Update("entniche_export_limit", map[string]interface{}{"user_id": userId}, setMap)
|
|
|
- if u {
|
|
|
+ if Mysql.ExecTx("", func(tx *sql.Tx) bool {
|
|
|
+ if !Mysql.UpdateByTx(tx, "entniche_export_limit", map[string]interface{}{"user_id": userId}, setMap) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ logMap := map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "type": 2,
|
|
|
+ }
|
|
|
+ if reqType == "maxNums" {
|
|
|
+ logMap["max_nums"] = maxNums
|
|
|
+ } else {
|
|
|
+ logMap["data_limit"] = limitNum
|
|
|
+ }
|
|
|
+ if Mysql.InsertByTx(tx, "entniche_export_limit_log", logMap) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) {
|
|
|
status = 1
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
setMap := map[string]interface{}{
|
|
|
"ent_id": entId,
|
|
|
- "data_limit": limitNum,
|
|
|
"user_id": userId,
|
|
|
- "remain_nums": limitNum,
|
|
|
"export_nums": 0,
|
|
|
}
|
|
|
- i := Mysql.Insert("entniche_export_limit", setMap)
|
|
|
- if i > 0 {
|
|
|
+ if reqType == "maxNums" {
|
|
|
+ setMap["max_nums"] = maxNums
|
|
|
+ } else {
|
|
|
+ setMap["data_limit"] = util.IntAll(limitNum)
|
|
|
+ setMap["remain_nums"] = util.IntAll(limitNum)
|
|
|
+ }
|
|
|
+ if Mysql.ExecTx("", func(tx *sql.Tx) bool {
|
|
|
+ if Mysql.InsertByTx(tx, "entniche_export_limit", setMap) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if Mysql.InsertByTx(tx, "entniche_export_limit_log", map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "type": 1,
|
|
|
+ }) <= 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }) {
|
|
|
status = 1
|
|
|
}
|
|
|
}
|
|
@@ -402,7 +447,7 @@ func (this *EntExportAuth) GetList() {
|
|
|
page, _ := this.GetInteger("page")
|
|
|
entId := util.IntAll(this.GetSession("entId"))
|
|
|
if entId != 0 {
|
|
|
- sql := `SELECT a.id,a.name,c.id as user_id,c.name as user_name,c.phone as user_phone,c.mail as user_mail,l.data_limit,l.id as limit_id from entniche_department a
|
|
|
+ sql := `SELECT a.id,a.name,c.id as user_id,c.name as user_name,c.phone as user_phone,c.mail as user_mail,l.data_limit,l.max_nums,l.id as limit_id,e.name as role_name from entniche_department a
|
|
|
INNER JOIN entniche_department_user b on (a.ent_id=? and a.id=b.dept_id)
|
|
|
INNER JOIN entniche_user c on (b.user_id=c.id and c.export_power=1)
|
|
|
LEFT JOIN entniche_export_limit l on (l.user_id = c.id)
|
|
@@ -438,18 +483,17 @@ func (this *EntExportAuth) DeletePerson() {
|
|
|
}
|
|
|
userId, _ := this.GetInteger("userId")
|
|
|
entId := util.IntAll(this.GetSession("entId"))
|
|
|
- if userId != 0 && entId != 0 {
|
|
|
+ status := 0
|
|
|
+ if userId > 0 && entId > 0 {
|
|
|
if Mysql.ExecTx("删除数据导出使用人员", func(tx *sql.Tx) bool {
|
|
|
- ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, "update entniche_user set export_power=0 where ent_id=? and export_power=1 and id = ?", entId, userId)
|
|
|
- ok_2 := Mysql.DeleteByTx(tx, "entniche_export_limit", map[string]interface{}{"ent_id": entId, "user_id": userId})
|
|
|
- log.Println(ok_2, ok_1)
|
|
|
- return ok_1 > -1
|
|
|
+ ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, "update entniche_user set export_power=0 where ent_id=? and export_power=1 and id=?", entId, userId)
|
|
|
+ ok_2 := Mysql.InsertBySqlByTx(tx, "insert into entniche_export_limit_log (user_id,type) values (?,3)", userId)
|
|
|
+ return ok_1 > 0 && ok_2 > 0
|
|
|
}) {
|
|
|
- this.ServeJson(Result{Data: M{"status": 1}})
|
|
|
- return
|
|
|
+ status = 1
|
|
|
}
|
|
|
}
|
|
|
- this.ServeJson(Result{Data: M{"status": 0}})
|
|
|
+ this.ServeJson(Result{Data: M{"status": status}})
|
|
|
return
|
|
|
}
|
|
|
|