123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548 |
- package roadshow
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mobile_admin/controllers"
- "hongze/hongze_mobile_admin/models"
- "hongze/hongze_mobile_admin/models/roadshow"
- "hongze/hongze_mobile_admin/models/tables/admin"
- "hongze/hongze_mobile_admin/services"
- "hongze/hongze_mobile_admin/services/rs"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "strings"
- "time"
- )
- //日历
- type CalendarController struct {
- controllers.BaseAuth
- }
- // @Title 新增路演活动接口
- // @Description 新增路演活动接口
- // @Param request body rs.AddActivityReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /add [post]
- func (this *CalendarController) Add() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_ACTIVITY_WX_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
- return
- }
- var req roadshow.AddActivityReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if len(req.ResearcherList) <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- researcherMap := make(map[int]string)
- var checkIsAdd []string
- //var tipMsg string
- for _, v := range req.ResearcherList {
- if v.ResearcherId <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.ResearcherName == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
- return
- }
- if v.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
- return
- }
- if v.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
- return
- }
- if v.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
- return
- }
- if v.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if v.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- startDateTime := v.StartDate + " " + v.StartTime
- endDateTime := v.EndDate + " " + v.EndTime
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
- return
- }
- if realName, ok := researcherMap[v.ResearcherId]; ok {
- this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
- return
- }
- researcherMap[v.ResearcherId] = v.ResearcherName
- //同步上海数据
- researcherInfo, err := admin.GetAdminWxById(v.ResearcherId)
- if err != nil {
- this.FailWithMessage("研究员异常", "获取研究员异常,Err:"+err.Error())
- return
- }
- _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
- //校验事项时间冲突
- {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- //校验活动时间冲突
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendar!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- if len(checkIsAdd) > 0 {
- this.FailWithMessage(strings.Join(checkIsAdd, ",")+" 时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- rsCalendar := new(roadshow.RsCalendar)
- rsCalendar.SysUserId = sysUser.AdminId
- rsCalendar.SysUserRealName = sysUser.RealName
- rsCalendar.ActivityType = req.ActivityType
- rsCalendar.RoadshowType = req.RoadshowType
- rsCalendar.RoadshowPlatform = req.RoadshowPlatform
- rsCalendar.CompanyId = req.CompanyId
- rsCalendar.CompanyName = req.CompanyName
- rsCalendar.Province = req.Province
- rsCalendar.ProvinceCode = req.ProvinceCode
- rsCalendar.City = req.City
- rsCalendar.CityCode = req.CityCode
- rsCalendar.Theme = req.Theme
- rsCalendar.CooperationName = req.CooperationName
- rsCalendar.CreateTime = time.Now()
- rsCalendar.ModifyTime = time.Now()
- rsCalendar.ActivityCategory = req.ActivityCategory
- rsCalendar.Source = 0
- rsCalendar.Title = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
- rsCalendarId, err := roadshow.AddRsCalendar(rsCalendar)
- if err != nil {
- this.FailWithMessage("保存失败", "保存日历活动信息失败!Err:"+err.Error())
- return
- }
- //if researcherId != 99 {
- for k, v := range req.ResearcherList {
- researcher := new(roadshow.RsCalendarResearcher)
- researcher.RsCalendarId = int(rsCalendarId)
- researcher.ResearcherId = v.ResearcherId
- researcher.ResearcherName = v.ResearcherName
- researcher.StartDate = v.StartDate
- researcher.EndDate = v.EndDate
- researcher.StartTime = v.StartTime
- researcher.EndTime = v.EndTime
- researcher.StartWeek = v.StartWeek
- researcher.EndWeek = v.EndWeek
- researcher.CreateTime = time.Now()
- researcher.ModifyTime = time.Now()
- researcher.ResearcherSort = k + 1
- if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
- researcher.Status = 1
- } else {
- researcher.Status = 2
- }
- rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
- if err != nil {
- this.FailWithMessage("保存失败", "保存日历活动-研究员信息失败!Err:"+err.Error())
- return
- }
- rsCalendar.RsCalendarId = int(rsCalendarId)
- researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
- go rs.CalendarToSH(*rsCalendar, *researcher)
- //模板消息通知
- {
- go func() {
- sysAdmin, _ := admin.GetAdminWxById(v.ResearcherId)
- if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
- first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
- keyword1 := sysUser.RealName
- keyword2 := "--"
- keyword3 := time.Now().Format(utils.FormatDateTime)
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- var keyword4 string
- if req.ActivityType == "路演" {
- keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- } else {
- keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- }
- remark := "请尽快完成审批"
- wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
- openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
- if len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
- }
- }
- }()
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // CalendarList
- // @Title 我的日历列表
- // @Description 我的日历列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query int true "1:待接受,2:包含,已接受,已拒绝,已删除"
- // @Success 200 {object} rs.CalendarListResp
- // @router /calendar/list [get]
- func (this *CalendarController) CalendarList() {
- adminItem := this.AdminWx
- status, _ := this.GetInt("Status")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize10
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- condition += ` AND b.researcher_id=?`
- pars = append(pars, adminItem.AdminId)
- condition += ` AND a.activity_type IN('路演','公开会议') `
- if status == 1 {
- condition += ` AND b.status=?`
- pars = append(pars, 1)
- } else {
- condition += ` AND b.status IN(2,3,4)`
- }
- resp := new(roadshow.CalendarListResp)
- total, err := roadshow.GetCalendarListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetCalendarList(condition, pars, status, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
- return
- }
- resp.Paging = page
- resp.List = dataList
- this.OkDetailed(resp, "获取成功")
- }
- // Accept
- // @Description 接受路演活动接口
- // @Param request body rs.AcceptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /accept [post]
- func (this *CalendarController) Accept() {
- //adminItem:=this.AdminWx
- var req roadshow.AcceptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误!", "RsCalendarId 或 RsCalendarResearcherId 小于等于0:")
- return
- }
- rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarById Err:"+err.Error())
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById Err:"+err.Error())
- return
- }
- if rsCalendarResearcher.Status == 2 {
- this.FailWithMessage("已接受,不可重复操作!", "")
- return
- } else if rsCalendarResearcher.Status == 3 {
- this.FailWithMessage("已拒绝,不可进行接受操作!", "")
- return
- } else if rsCalendarResearcher.Status == 4 {
- this.FailWithMessage("已删除,不可进行接受操作!", "")
- return
- } else if rsCalendarResearcher.Status == 5 {
- this.FailWithMessage("已撤回,不可进行接受操作!", "")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 2
- updateParams["modify_time"] = time.Now()
- updateParams["approve_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "UpdateCalendarResearcher Err:"+err.Error())
- return
- }
- //模板消息通知
- {
- if rsCalendar != nil {
- sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
- first := "【" + this.AdminWx.RealName + "】接受了你的【" + rsCalendar.ActivityType + "】申请"
- var keyword1 string
- if rsCalendar.ActivityType == "路演" {
- keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
- } else {
- keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
- }
- keyword2 := "已接受"
- remark := ""
- if sysAdmin.Mobile != "" {
- go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
- }
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 拒绝路演活动接口
- // @Description 拒绝路演活动接口
- // @Param request body rs.RefuseReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /refuse [post]
- func (this *CalendarController) Refuse() {
- //adminItem:=this.AdminWx
- var req roadshow.RefuseReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
- return
- }
- rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarById,Err:"+err.Error())
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById,Err:"+err.Error())
- return
- }
- if rsCalendarResearcher.Status == 2 {
- this.FailWithMessage("已接受,不可进行拒绝操作!", "")
- return
- } else if rsCalendarResearcher.Status == 3 {
- this.FailWithMessage("已拒绝,不可进行重复操作!", "")
- return
- } else if rsCalendarResearcher.Status == 4 {
- this.FailWithMessage("已删除,不可进行拒绝操作!", "")
- return
- } else if rsCalendarResearcher.Status == 5 {
- this.FailWithMessage("已撤回,不可进行拒绝操作!", "")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 3
- updateParams["refuse_reason"] = req.RefuseReason
- updateParams["refuse_time"] = time.Now()
- updateParams["modify_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- // 拒绝后需要删除上海的日程
- go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
- //模板消息通知
- {
- if rsCalendar != nil {
- sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
- first := "【" + this.AdminWx.RealName + "】拒绝了你的【" + rsCalendar.ActivityType + "】申请"
- var keyword1 string
- if rsCalendar.ActivityType == "路演" {
- keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
- } else {
- keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
- }
- keyword2 := "已拒绝"
- remark := req.RefuseReason
- if sysAdmin.Mobile != "" {
- go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
- }
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 日历详情
- // @Description 日历详情接口
- // @Param RsCalendarId query int true "路演活动id"
- // @Param RsCalendarResearcherId query int true "活动研究员id"
- // @Success 200 {object} rs.CalendarDetailResp
- // @router /calendar/detail [get]
- func (this *CalendarController) CalendarDetail() {
- //adminItem:=this.AdminWx
- //roleTypeCode := adminItem.RoleTypeCode
- rsCalendarId, _ := this.GetInt("RsCalendarId")
- rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
- if rsCalendarId <= 0 || rsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误", "rsCalendarId 或 rsCalendarResearcherId")
- return
- }
- calendarItem, err := roadshow.GetRsCalendarById(rsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(rsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- companyDetailView := new(roadshow.CompanyDetailView)
- if calendarItem != nil && calendarItem.CompanyId > 0 {
- companyId := calendarItem.CompanyId
- companyProductItem, err := models.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- permissionList, err := models.GetCompanyProductReportPermissionList(companyId, 1)
- if err != nil {
- this.FailWithMessage("搜索客户权限失败", "搜索客户权限失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- var permissionArr []string
- for _, v := range permissionList {
- permissionArr = append(permissionArr, v.PermissionName)
- }
- readNum := companyProductItem.ViewTotal
- companyDetailView.CompanyId = companyProductItem.CompanyId
- companyDetailView.CompanyName = companyProductItem.CompanyName
- companyDetailView.Status = companyProductItem.Status
- companyDetailView.IndustryId = companyProductItem.IndustryId
- companyDetailView.IndustryName = companyProductItem.IndustryName
- companyDetailView.PermissionName = strings.Join(permissionArr, "/")
- companyDetailView.ReportReadTotal = readNum //ficc报告-累计阅读次数
- }
- resp := new(roadshow.CalendarDetailResp)
- resp.RsCalendarItem = calendarItem
- resp.RsCalendarResearcherItem = rsCalendarResearcherItem
- resp.CompanyDetail = companyDetailView
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 事项列表
- // @Description 事项列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} rs.MattersListResp
- // @router /matters/list [get]
- func (this *CalendarController) MattersList() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize10
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, sysUser.AdminId)
- resp := new(roadshow.MattersListResp)
- total, err := roadshow.GetMattersListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersListCount,Err:"+err.Error())
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersList,Err:"+err.Error())
- return
- }
- resp.Paging = page
- resp.List = dataList
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 新增事项接口
- // @Description 新增事项接口
- // @Param request body rs.AddMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/add [post]
- func (this *CalendarController) MattersAdd() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
- return
- }
- var req roadshow.AddMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
- return
- }
- if req.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
- return
- }
- if req.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
- return
- }
- if req.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
- return
- }
- if req.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if req.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if req.MatterContent == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- startDateTime := req.StartDate + " " + req.StartTime
- endDateTime := req.EndDate + " " + req.EndTime
- //校验事项时间冲突
- {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- }
- //校验活动时间冲突--待接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- //校验活动时间冲突--已接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
- return
- }
- item := new(roadshow.RsMatters)
- item.SysUserId = sysUser.AdminId
- item.SysUserRealName = sysUser.RealName
- item.StartDate = req.StartDate
- item.EndDate = req.EndDate
- item.StartTime = req.StartTime
- item.EndTime = req.EndTime
- item.StartWeek = req.StartWeek
- item.EndWeek = req.EndWeek
- item.MatterContent = req.MatterContent
- item.Status = 1
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- id, err := roadshow.AddRsMatters(item)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败,AddRsMatters Err:"+err.Error())
- return
- }
- item.RsMattersId = int(id)
- go rs.MatterToSH(*item)
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 修改事项接口
- // @Description 修改事项接口
- // @Param request body rs.UpdateMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/update [post]
- func (this *CalendarController) MattersUpdate() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!")
- return
- }
- var req roadshow.UpdateMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
- return
- }
- updateParams := make(map[string]interface{})
- if req.RsMattersId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误")
- return
- }
- if req.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期")
- return
- } else {
- updateParams["start_date"] = req.StartDate
- }
- if req.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期")
- return
- } else {
- updateParams["end_date"] = req.EndDate
- }
- if req.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间")
- return
- } else {
- updateParams["start_time"] = req.StartTime
- }
- if req.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间")
- return
- } else {
- updateParams["end_time"] = req.EndTime
- }
- if req.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周")
- return
- } else {
- updateParams["start_week"] = req.StartWeek
- }
- if req.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周")
- return
- } else {
- updateParams["end_week"] = req.EndWeek
- }
- if req.MatterContent == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员")
- return
- } else {
- updateParams["matter_content"] = req.MatterContent
- }
- startDateTime := req.StartDate + " " + req.StartTime
- endDateTime := req.EndDate + " " + req.EndTime
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
- return
- }
- matterItem, err := roadshow.GetMattersById(req.RsMattersId)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败,GetMattersById,Err:"+err.Error())
- return
- }
- //校验事项时间冲突
- {
- if matterItem != nil && (matterItem.StartDate != req.StartDate ||
- matterItem.StartTime != req.StartTime ||
- matterItem.EndDate != req.EndDate ||
- matterItem.EndTime != req.EndTime) {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- this.FailWithMessage("时间冲突,已存在时间段内的事项!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- }
- }
- //校验活动时间冲突--待接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- //校验活动时间冲突--待接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("时间冲突,已存在时间段内的活动!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- whereParams := make(map[string]interface{})
- whereParams["rs_matters_id"] = req.RsMattersId
- updateParams["modify_time"] = time.Now()
- err = roadshow.UpdateRsMatters(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!UpdateRsMatters:"+err.Error())
- return
- }
- go rs.UpdateSHCalendarByMatter(req)
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 删除事项接口
- // @Description 删除事项接口
- // @Param request body rs.DeleteMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/delete [post]
- func (this *CalendarController) MattersDelete() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- var req roadshow.DeleteMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsMattersId <= 0 {
- this.FailWithMessage("参数错误", "参数错误")
- return
- }
- err = roadshow.DeleteRsMatters(req.RsMattersId)
- if err != nil {
- this.FailWithMessage("保存失败", "保存失败!DeleteRsMatters:"+err.Error())
- return
- }
- go rs.DeleteSHMatter(req.RsMattersId)
- this.OkDetailed(nil, "删除成功")
- }
- func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
- var title string
- switch activityType {
- case "内部会议":
- title = "内部会议"
- case "公开会议", "路演":
- if roadshowType == "线上" {
- title = roadshowType + activityType + roadshowPlatform
- } else {
- title = roadshowType + activityType + province + city
- }
- case "报告电话会":
- title = activityCategory + "电话会"
- }
- return title
- }
- // @Title 编辑路演活动接口
- // @Description编辑路演活动接口
- // @Param request body rs.EditActivityReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edit [post]
- func (this *CalendarController) Edit() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_ACTIVITY_WX_EDIT_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
- return
- }
- var req roadshow.EditActivityReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 {
- this.FailWithMessage("参数错误", "参数错误,RsCalendarId<=0")
- return
- }
- if req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误", "参数错误,RsCalendarResearcherId<=0")
- return
- }
- if req.ActivityType == "" {
- this.FailWithMessage("请选择活动类型", "请选择活动类型")
- return
- }
- if len(req.ResearcherList) <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- researcherMap := make(map[int]string)
- var checkIsAdd []string
- for _, v := range req.ResearcherList {
- if v.ResearcherId <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.ResearcherName == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
- return
- }
- if v.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
- return
- }
- if v.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
- return
- }
- if v.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
- return
- }
- if v.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if v.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if realName, ok := researcherMap[v.ResearcherId]; ok {
- this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
- return
- }
- researcherMap[v.ResearcherId] = v.ResearcherName
- startDateTime := v.StartDate + " " + v.StartTime
- endDateTime := v.EndDate + " " + v.EndTime
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
- return
- }
- /*
- 时间冲突时,提示:xxx时间已被占用
- 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
- */
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
- var isAdd bool
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- isAdd = true
- } else {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:"+err.Error())
- return
- }
- }
- var rsCalendarResearcherId int
- if rsCalendarResearcherItem == nil {
- isAdd = true
- } else {
- rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
- }
- //同步上海数据
- researcherInfo, err := admin.GetAdminById(v.ResearcherId)
- if err != nil {
- this.FailWithMessage("研究员异常!", "研究员异常")
- return
- }
- _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
- //校验事项时间冲突
- {
- if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
- rsCalendarResearcherItem.StartTime != v.StartTime ||
- rsCalendarResearcherItem.EndDate != v.EndDate ||
- rsCalendarResearcherItem.EndTime != v.EndTime)) {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- //校验活动时间冲突
- {
- if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
- rsCalendarResearcherItem.StartTime != v.StartTime ||
- rsCalendarResearcherItem.EndDate != v.EndDate ||
- rsCalendarResearcherItem.EndTime != v.EndTime)) {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- }
- if len(checkIsAdd) > 0 {
- this.FailWithMessage(strings.Join(checkIsAdd, ",")+"时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- if rsCalendarItem == nil {
- this.FailWithMessage("保存失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- calendarWhereParams := make(map[string]interface{})
- calendarUpdateParams := make(map[string]interface{})
- calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
- if req.ActivityType != "" {
- calendarUpdateParams["activity_type"] = req.ActivityType
- }
- if req.RoadshowType != "" {
- calendarUpdateParams["roadshow_type"] = req.RoadshowType
- }
- if req.RoadshowPlatform != "" {
- calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
- }
- if req.CompanyId > 0 {
- calendarUpdateParams["company_id"] = req.CompanyId
- }
- if req.CompanyName != "" {
- calendarUpdateParams["company_name"] = req.CompanyName
- }
- if req.ActivityCategory != "" {
- calendarUpdateParams["activity_category"] = req.ActivityCategory
- }
- if req.Theme != "" {
- calendarUpdateParams["theme"] = req.Theme
- }
- if req.CooperationName != "" {
- calendarUpdateParams["cooperation_name"] = req.CooperationName
- }
- if req.Province != "" {
- calendarUpdateParams["province"] = req.Province
- }
- if req.City != "" {
- calendarUpdateParams["city"] = req.City
- }
- calendarUpdateParams["modify_time"] = time.Now()
- calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
- err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!UpdateRsCalendar:"+err.Error())
- return
- }
- //newResearcherMap := make(map[int]string)
- go rs.UpdateSHCalendar(req)
- existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!GetRsCalendarResearcherByCalendarId:"+err.Error())
- return
- }
- existResearcherMap := make(map[int]string)
- for _, ev := range existList {
- existResearcherMap[ev.ResearcherId] = ev.ResearcherName
- }
- if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
- for k, v := range req.ResearcherList {
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- calendarResearcherWhereParams := make(map[string]interface{})
- calendarResearcherUpdateParams := make(map[string]interface{})
- calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
- calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
- if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
- calendarResearcherUpdateParams["status"] = 1
- }
- calendarResearcherUpdateParams["start_date"] = v.StartDate
- calendarResearcherUpdateParams["end_date"] = v.EndDate
- calendarResearcherUpdateParams["start_time"] = v.StartTime
- calendarResearcherUpdateParams["end_time"] = v.EndTime
- calendarResearcherUpdateParams["start_week"] = v.StartWeek
- calendarResearcherUpdateParams["end_week"] = v.EndWeek
- calendarResearcherUpdateParams["refuse_reason"] = ""
- calendarResearcherUpdateParams["refuse_time"] = nil
- calendarResearcherUpdateParams["delete_reason"] = ""
- calendarResearcherUpdateParams["approve_time"] = nil
- calendarResearcherUpdateParams["researcher_sort"] = k + 1
- calendarResearcherUpdateParams["modify_time"] = time.Now()
- calendarResearcherUpdateParams["create_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- if req.EditType == 2 {
- //模板消息通知
- go func() {
- sysAdmin, _ := admin.GetAdminById(v.ResearcherId)
- if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
- first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
- keyword1 := sysUser.RealName
- keyword2 := "--"
- keyword3 := time.Now().Format(utils.FormatDateTime)
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- var keyword4 string
- if req.ActivityType == "路演" {
- keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- } else {
- keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- }
- remark := "请尽快完成审批"
- wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
- openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
- if len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
- }
- }
- }()
- }
- }
- } else {
- err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!DeleteRsCalendarResearcher:"+err.Error())
- return
- }
- for k, v := range req.ResearcherList {
- researcher := new(roadshow.RsCalendarResearcher)
- researcher.RsCalendarId = req.RsCalendarId
- researcher.ResearcherId = v.ResearcherId
- researcher.ResearcherName = v.ResearcherName
- researcher.StartDate = v.StartDate
- researcher.EndDate = v.EndDate
- researcher.StartTime = v.StartTime
- researcher.EndTime = v.EndTime
- researcher.StartWeek = v.StartWeek
- researcher.EndWeek = v.EndWeek
- researcher.CreateTime = time.Now()
- researcher.ModifyTime = time.Now()
- researcher.ResearcherSort = k + 1
- if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
- researcher.Status = 1
- } else {
- researcher.Status = 2
- }
- rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存日历活动-研究员信息失败!Err:"+err.Error())
- return
- }
- go func() {
- sysAdmin, _ := admin.GetAdminById(v.ResearcherId)
- if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
- first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
- keyword1 := sysUser.RealName
- keyword2 := "--"
- keyword3 := time.Now().Format(utils.FormatDateTime)
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- var keyword4 string
- if req.ActivityType == "路演" {
- keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- } else {
- keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- }
- remark := "请尽快完成审批"
- wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
- openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
- if len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
- }
- }
- }()
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // ResearcherList
- // @Title 研究员列表
- // @Description 研究员列表接口
- // @Success 200 {object} rs.ResearcherGroup
- // @router /researcher/list [get]
- func (this *CalendarController) ResearcherList() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- group, err := roadshow.GetResearcherGroup()
- if err != nil {
- this.FailWithMessage("获取信息失败!", "获取分组信息失败!Err:"+err.Error())
- return
- }
- researcherList, err := roadshow.GetResearcher()
- groupMap := make(map[int][]*roadshow.Researcher)
- for _, v := range researcherList {
- if v.RoleTypeCode == "ficc_admin" {
- findItems := groupMap[1]
- findItems = append(findItems, v)
- groupMap[1] = findItems
- } else {
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, v)
- groupMap[v.GroupId] = findItems
- }
- }
- }
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- }
- this.OkDetailed(group, "获取成功")
- }
- // @Title 撤回路演活动接口
- // @Description 撤回路演活动接口
- // @Param request body rs.AcceptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /back [post]
- func (this *CalendarController) Back() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- var req roadshow.AcceptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
- return
- }
- _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- if rsCalendarResearcher.Status == 2 {
- this.FailWithMessage("已接受,不可进行撤回操作!", "已接受,不可进行撤回操作!")
- return
- } else if rsCalendarResearcher.Status == 3 {
- this.FailWithMessage("已拒绝,不可进行撤回操作!", "已拒绝,不可进行撤回操作!")
- return
- } else if rsCalendarResearcher.Status == 4 {
- this.FailWithMessage("已删除,不可进行撤回操作!", "已删除,不可进行撤回操作!")
- return
- } else if rsCalendarResearcher.Status == 5 {
- this.FailWithMessage("已撤回,不可进行重复操作!", "已撤回,不可进行重复操作!")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 5
- updateParams["modify_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- //撤回后,需要删除该日程
- go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- this.OkDetailed(nil, "撤回成功")
- }
- // @Title 删除路演活动接口
- // @Description 删除路演活动接口
- // @Param request body rs.DeleteReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /delete [post]
- func (this *CalendarController) Delete() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- var req roadshow.DeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
- return
- }
- rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
- err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("删除失败!", "删除失败!DeleteCalendar:"+err.Error())
- return
- }
- } else {
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 4
- updateParams["delete_reason"] = req.DeleteReason
- updateParams["modify_time"] = time.Now()
- updateParams["delete_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("删除失败!", "删除失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- }
- //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
- //待接受、已接受的情况,需要同步删除上海那边的日程
- if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
- go rs.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
- }
- //模板消息通知
- {
- go func() {
- if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
- sysAdmin, _ := admin.GetAdminById(rsCalendarResearcherItem.ResearcherId)
- first := "【" + sysUser.RealName + "】删除了你的【路演】安排"
- var keyword1 string
- if rsCalendarItem.ActivityType == "路演" {
- keyword1 = rsCalendarItem.CompanyName + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
- } else {
- keyword1 = rsCalendarItem.Theme + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
- }
- keyword2 := "已删除"
- remark := req.DeleteReason
- wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(rsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
- openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
- if len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
- }
- }
- }()
- }
- this.OkDetailed(nil, "删除成功")
- }
- // ResearcherList
- // @Title 获取报告电话会类型
- // @Description 获取报告电话会类型接口
- // @Success 200 {object} rs.ResearcherGroup
- // @router /activity/type/list [get]
- func (this *CalendarController) ActivityTypeList() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- // 获取所有的分类
- list, err := rs.GetAllActivityType()
- if err != nil {
- this.FailWithMessage("获取活动类型列表失败", "获取活动类型列表失败,Err:"+err.Error())
- return
- }
- this.OkDetailed(list, "获取成功")
- }
|