作者 tangxvhui

日常保存

package adapter
// 人员选择列表
type UserItem struct {
Id int64 `json:"id,string"`
Name string `json:"name"`
Level int `json:"level"`
}
... ...
package command
type MarkTaskAnomalyCommand struct {
Id int `json:"id,string"`
CompanyId int `json:"-"`
MarkType string `json:"markType"`
}
... ...
package command
type UserSelectCommand struct {
UserId int `json:"-"`
CompanyId int `json:"-"`
SubLevel int `json:"subLevel"`
}
... ...
... ... @@ -392,7 +392,61 @@ func (srv TaskService) ListTaskAnomaly3(param *command.ListTaskAnomalyCommand) (
return result, nil
}
func (srv TaskService) UserSelect(param *command.UserSelectCommand) []adapter.UserItem {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil
}
if err := transactionContext.StartTransaction(); err != nil {
return nil
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if param.SubLevel == 0 {
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, userList, err := userRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
})
selectList := []adapter.UserItem{}
if err != nil {
return selectList
}
for _, val := range userList {
selectList = append(selectList, adapter.UserItem{
Id: val.Id,
Name: val.Name,
})
}
return selectList
}
userDao := dao.NewUserDao(map[string]interface{}{
"transactionContext": transactionContext,
})
userList, err := userDao.AllChildUser(param.UserId)
selectList := []adapter.UserItem{}
if err != nil {
return selectList
}
for _, val := range userList {
selectList = append(selectList, adapter.UserItem{
Id: int64(val.Id),
Name: val.Name,
Level: val.Level,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return selectList
}
return selectList
}
// 对异常记录的操作标记
func (srv TaskService) MarkTaskAnomaly() error {
return nil
func (srv TaskService) MarkTaskAnomaly(param *command.MarkTaskAnomalyCommand) (map[string]string, error) {
return nil, nil
}
... ...
... ... @@ -301,3 +301,37 @@ func (c *TaskController) TaskAnomalyList2() {
resp, err := srv.ListTaskAnomaly2(paramReq)
c.Response(resp, err)
}
func (c *TaskController) UserSelect() {
srv := service.NewTaskService()
paramReq := &command.UserSelectCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.UserId = int(userReq.UserId)
resp := srv.UserSelect(paramReq)
c.Response(resp, nil)
}
// 点击操作
func (c *TaskController) TaskAnomalyMark() {
srv := service.NewTaskService()
paramReq := &command.MarkTaskAnomalyCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
resp, err := srv.MarkTaskAnomaly(paramReq)
c.Response(resp, err)
}
... ...
... ... @@ -39,6 +39,8 @@ func init() {
web.NSCtrlPost("/task_anomaly/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务
web.NSCtrlPost("/task_anomaly/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务
web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务
web.NSCtrlPost("/task_anomaly/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
web.NSCtrlPost("/task_anomaly/marks", (*controllers.TaskController).TaskAnomalyMark),
)
web.AddNamespace(taskAnomalyNS)
}
... ...