123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- package controllers
- import (
- "encoding/json"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company_todo"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/utils"
- "time"
- )
- // CompanyTodoController 客户任务列表
- type CompanyTodoController struct {
- BaseAuthController
- }
- // Add
- // @Title 新增任务
- // @Description 新增任务接口
- // @Param request body company_todo.CompanyTodoAddReq true "type json string"
- // @Success 200 新增成功
- // @router /company_todo/add [post]
- func (this *CompanyTodoController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req company_todo.CompanyTodoAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CompanyId <= 0 {
- br.Msg = "请选择客户"
- br.ErrMsg = "客户ID不能为空"
- return
- }
- if req.Description == "" {
- br.Msg = "任务描述不能为空"
- return
- }
- if req.EndTime == "" {
- br.Msg = "请输入截止日期"
- return
- }
- endTime, err := time.ParseInLocation(utils.FormatDate, req.EndTime, time.Local)
- if err != nil {
- br.Msg = "截止日期格式错误"
- return
- }
- description := utils.TrimStr(req.Description)
- productId := services.GetProductId(this.SysUser.RoleTypeCode)
- if productId == 0 {
- if this.SysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- productId = req.ProductId
- } else {
- br.Msg = "账号角色异常,不允许添加任务"
- return
- }
- }
- // 新增任务
- errMsg, err := services.AddCompanyTodo(req.CompanyId, productId, description, endTime, this.SysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "添加任务失败,err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "提交成功"
- }
- // EditList
- // @Title 获取客户待操作任务列表
- // @Description 获取客户待操作任务列表接口
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} []company_todo.CompanyTodo
- // @router /company_todo/edit_list [get]
- func (this *CompanyTodoController) EditList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "请选择客户"
- return
- }
- productId := services.GetProductId(this.SysUser.RoleTypeCode)
- if productId == 0 && this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- br.Msg = "账号角色异常"
- return
- }
- // 获取进行中的任务信息
- todoList, err := company_todo.GetDoingCompanyTodoList(companyId, productId)
- if err != nil {
- br.Msg = "获取任务信息失败"
- br.ErrMsg = "获取任务信息失败,err:" + err.Error()
- return
- }
- var list []*company_todo.CompanyTodoListItem
- for _, v := range todoList {
- temp := &company_todo.CompanyTodoListItem{
- CompanyTodo: v,
- }
- temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
- if temp.EndTimeStr == "0001-01-01" {
- temp.EndTimeStr = ""
- }
- list = append(list, temp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // List
- // @Title 任务列表
- // @Description 客户任务列表接口
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} []company_todo.CompanyTodo
- // @router /company_todo/list [get]
- func (this *CompanyTodoController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "请选择客户"
- return
- }
- productId := services.GetProductId(this.SysUser.RoleTypeCode)
- if productId == 0 && this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- br.Msg = "账号角色异常"
- return
- }
- // 获取任务信息
- todos, err := company_todo.GetCompanyTodoList(companyId, productId)
- if err != nil {
- br.Msg = "获取任务信息失败"
- br.ErrMsg = "获取任务信息失败,err:" + err.Error()
- return
- }
- var list []*company_todo.CompanyTodoListItem
- for _, v := range todos {
- temp := &company_todo.CompanyTodoListItem{
- CompanyTodo: v,
- }
- temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
- if temp.EndTimeStr == "0001-01-01" {
- temp.EndTimeStr = ""
- }
- list = append(list, temp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // Edit
- // @Title 修改分组
- // @Description 修改分组接口
- // @Param request body system.SysTeamEditReq true "type json string"
- // @Success 200 修改成功
- // @router /company_todo/edit [post]
- func (this *CompanyTodoController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req company_todo.CompanyTodoEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "请选择客户"
- br.ErrMsg = "客户ID不能为空"
- return
- }
- if req.Description == "" {
- br.Msg = "任务描述不能为空"
- return
- }
- if req.EndTime == "" {
- br.Msg = "请输入截止日期"
- return
- }
- endTime, err := time.ParseInLocation(utils.FormatDate, req.EndTime, time.Local)
- if err != nil {
- br.Msg = "截止日期格式错误"
- return
- }
- description := utils.TrimStr(req.Description)
- errMsg, err := services.EditCompanyTodo(req.Id, description, endTime, this.SysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = errMsg + ",Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // Approve
- // @Title 审批任务
- // @Description 审批任务接口
- // @Param request body company_todo.ApproveCompanyTodoReq true "type json string"
- // @Success 200 审批通过
- // @router /company_todo/approve [post]
- func (this *CompanyTodoController) Approve() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req company_todo.ApproveCompanyTodoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,任务编号必传 "
- return
- }
- errMsg, err := services.ApproveCompanyTodo(req.Id, req.Remark, this.SysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = errMsg + ",Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "审核完成"
- }
|