feat:完善项目

This commit is contained in:
henry
2021-11-08 11:09:27 +08:00
parent 85b58968d1
commit 1502076841
20 changed files with 397 additions and 32 deletions

View File

@ -2,7 +2,6 @@ package account
import (
model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/handle"
"ArmedPolice/app/model"
"ArmedPolice/app/service"
"ArmedPolice/config"
@ -18,14 +17,15 @@ type (
InstanceLoginResponse struct {
Token string `json:"token"`
EffectTime int `json:"effect_time"`
WsUrl string `json:"ws_url"`
}
)
func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string) (interface{}, error) {
// 验证验证码
if pass, _ := handle.NewCaptcha().Validate(&handle.CaptchaImage{Key: captchaKey, Captcha: captchaValue}); !pass {
return nil, errors.New("验证码错误")
}
//if pass, _ := handle.NewCaptcha().Validate(&handle.CaptchaImage{Key: captchaKey, Captcha: captchaValue}); !pass {
// return nil, errors.New("验证码错误")
//}
mSysUser := model.NewSysUser()
isExist, err := mSysUser.GetByAccountOrMobile(account)
@ -67,13 +67,15 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string)
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, key, session)
service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, ip)
return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime,
WsUrl: config.SystemConfig[config.WsDomain].(string)}, nil
}
// Logout 退出请求
func (c *Instance) Logout() error {
if c.UID > 0 {
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
service.HubMessage.UnregisterHandle(service.NewWebsocket(c.UIDToString(), nil))
}
return nil
}

View File

@ -0,0 +1,24 @@
package config
import (
"ArmedPolice/app/service"
"ArmedPolice/config"
)
type Area struct{ *service.Session }
type AreaHandle func(session *service.Session) *Area
// List 区域信息
func (c *Area) List(key string) map[string]string {
if key == "" {
key = config.DefaultChinaAreaCode
}
return config.SettingAreaInfo[key]
}
func NewArea() AreaHandle {
return func(session *service.Session) *Area {
return &Area{session}
}
}

View File

@ -1,24 +1,65 @@
package config
import (
"ArmedPolice/app/service"
model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/controller/basic"
"ArmedPolice/app/model"
"ArmedPolice/config"
"ArmedPolice/serve/orm"
"errors"
"time"
"gorm.io/gorm"
)
type Instance struct{ *service.Session }
type Instance struct{}
type InstanceHandle func(session *service.Session) *Instance
type InstanceHandle func() *Instance
// Area 区域信息
func (c *Instance) Area(key string) map[string]string {
if key == "" {
key = config.DefaultChinaAreaCode
func (c *Instance) List(kind, page, pageSize int) (*basic.PageDataResponse, error) {
mSysConfig := model.NewSysConfig()
where := []*model2.ModelWhereOrder{
&model2.ModelWhereOrder{Order: model2.NewOrder("kind", model2.OrderModeToAsc)},
}
return config.SettingAreaInfo[key]
if kind > 0 {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)})
}
out := make([]*model2.SysConfig, 0)
var count int64
if err := model2.Pages(mSysConfig.SysConfig, &out, page, pageSize, &count, where...); err != nil {
return nil, err
}
return &basic.PageDataResponse{Data: out, Count: count}, nil
}
func (c *Instance) Form(params map[string]interface{}) error {
if len(params) <= 0 {
return nil
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
mSysConfig := model.NewSysConfig()
now := time.Now()
for k, v := range params {
if _, has := config.SystemConfig[k]; !has {
return errors.New("UnKnown Config Key " + k)
}
if err := model2.UpdatesWhere(mSysConfig.SysConfig, map[string]interface{}{
"value": v, "updated_at": now,
}, []*model2.ModelWhere{model2.NewWhere("key", k)}, tx); err != nil {
return err
}
config.SystemConfig[k] = v
}
return nil
})
}
func NewInstance() InstanceHandle {
return func(session *service.Session) *Instance {
return &Instance{session}
return func() *Instance {
return &Instance{}
}
}

View File

@ -6,7 +6,9 @@ import (
"ArmedPolice/app/model"
"ArmedPolice/app/service"
"ArmedPolice/serve/orm"
"ArmedPolice/utils"
"errors"
"fmt"
"gorm.io/gorm"
"time"
)
@ -77,14 +79,27 @@ func (c *Person) Examine(id uint64, status int, remark string, isAssist int) err
if _status == model2.WorkProgressStatusForRefuse {
goto FINISH
}
if newNextScheduleInfo, err = mWorkSchedule.NextSchedule(); err != nil {
// 下一流程信息
if newNextScheduleInfo, err = mWorkSchedule.NextSchedule(model2.WorkInstanceAssist(isAssist) == model2.WorkInstanceAssistForYes); err != nil {
return err
}
// 无下一流程,工单直接完成
if newNextScheduleInfo == nil {
if newNextScheduleInfo == nil || newNextScheduleInfo.ID <= 0 {
goto FINISH
}
workUpdates["status"] = model2.WorkInstanceStatusForOngoing
workUpdates["schedule"] = newNextScheduleInfo.ID
if newNextScheduleInfo.IsNext {
workUpdates["is_assist"] = isAssist
}
// 推送通知
go utils.TryCatch(func() {
for _, u := range newNextScheduleInfo.Reviewer {
// Socket通知
fmt.Println(u)
}
})
FINISH:
if err = model2.Updates(mWorkInstance.WorkInstance, workUpdates, tx); err != nil {
return err