80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"finclip-app-manager/domain/repository"
|
|
impl "finclip-app-manager/infrastructure/db/repo"
|
|
"finclip-app-manager/infrastructure/utility"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type AppConfigService struct {
|
|
AppOperConfigRepo repository.IAppOperConfigRepo
|
|
}
|
|
|
|
func NewAppConfigService() *AppConfigService {
|
|
return &AppConfigService{
|
|
AppOperConfigRepo: impl.InitAppOperConfigRepo(),
|
|
}
|
|
}
|
|
|
|
type GetOperConfigRsp struct {
|
|
AutoReviewApp int `json:"autoReviewApp"`
|
|
}
|
|
|
|
func (a *AppConfigService) GetOperConfig(ctx context.Context) (GetOperConfigRsp, string) {
|
|
item, err := a.AppOperConfigRepo.Find(ctx)
|
|
//没有不需要返回错误
|
|
if err != nil {
|
|
log.Errorln("a.AppOperConfigRepo.Find err:%s", err.Error())
|
|
}
|
|
|
|
var result GetOperConfigRsp
|
|
result.AutoReviewApp = item.AutoReviewApp
|
|
|
|
return result, utility.OK
|
|
}
|
|
|
|
type UpdateAppOperCofigReq struct {
|
|
AutoReviewApp int `json:"autoReviewApp"`
|
|
}
|
|
|
|
func (a *AppConfigService) UpdateAppOperCofig(ctx context.Context, req UpdateAppOperCofigReq) (string, int) {
|
|
if req.AutoReviewApp != 0 && req.AutoReviewApp != 1 {
|
|
log.Errorln("param err")
|
|
return utility.FS_PARAM_ERR, http.StatusBadRequest
|
|
}
|
|
|
|
log.Debugf("UpdateAppOperCofig:%s\n", utility.InterfaceToJsonString(req))
|
|
|
|
item, err := a.AppOperConfigRepo.Find(ctx)
|
|
|
|
found := true
|
|
if repository.NotFound(err) {
|
|
item.CreateTime = time.Now().UnixNano() / 1e6
|
|
item.UpdateTime = item.CreateTime
|
|
found = false
|
|
} else {
|
|
item.UpdateTime = time.Now().UnixNano() / 1e6
|
|
log.Debugf("UpdateAppOperCofig found\n")
|
|
}
|
|
item.AutoReviewApp = req.AutoReviewApp
|
|
|
|
if found {
|
|
err = a.AppOperConfigRepo.Update(ctx, item)
|
|
if err != nil {
|
|
log.Errorln("a.AppOperConfigRepo.Update err:%s", err.Error())
|
|
return utility.FS_DB_ERR, http.StatusBadRequest
|
|
}
|
|
} else {
|
|
err = a.AppOperConfigRepo.Insert(ctx, item)
|
|
if err != nil {
|
|
log.Errorln("a.AppOperConfigRepo.Insert err:%s", err.Error())
|
|
return utility.FS_DB_ERR, http.StatusBadRequest
|
|
}
|
|
}
|
|
|
|
return utility.OK, http.StatusOK
|
|
}
|