Przeglądaj źródła

新增出差日历列表接口

tuoling805 2 lat temu
rodzic
commit
aa709c2ec5

+ 61 - 109
controllers/business_trip/business_calendar.go

@@ -1,142 +1,94 @@
 package business_trip
 
 import (
-	"fmt"
 	"hongze/hongze_mobile_admin/models/tables/business_trip"
-	"hongze/hongze_mobile_admin/utils"
-	"time"
+	"strconv"
+	"strings"
 )
 
 // ResearcherReportList
 // @Title 出差日历表
 // @Description 出差日历表接口
-// @Param   AdminId   query   string  true       "用户id"
+// @Param   AdminId   query   int true       "用户id"
+// @Param   TripDate   query   string  true       "日期"
 // @Success 200 {object} roadshow.BusinessTripResp
 // @router /calendar [get]
 func (this *BusinessTrip) BusinessTripCalendar() {
-	//sysUser := this.AdminWx
-	//sysUserId := sysUser.AdminId
+	sysUser := this.AdminWx
+	sysUserId := sysUser.AdminId
 
-	adminId := this.GetString("AdminId")
+	adminId, _ := this.GetInt("AdminId")
+	tripDate := this.GetString("TripDate")
 
-	groupList := make([]*business_trip.BusinessTripCalendarGroup, 0)
-	researcherGroup := new(business_trip.BusinessTripCalendarGroup)
+	var condition string
+	var pars []interface{}
 
-	researcherGroup.GroupId = 1
-	researcherGroup.GroupName = "研究员"
-	researcherGroup.DepartmentId = "1"
-	groupList = append(groupList, researcherGroup)
-
-	sellerGroup := new(business_trip.BusinessTripCalendarGroup)
-	sellerGroup.GroupId = 2
-	sellerGroup.GroupName = "销售"
-	if utils.RunMode == "debug" {
-		sellerGroup.DepartmentId = "2,5"
-	} else {
-		sellerGroup.DepartmentId = "2,4,5,9"
+	if adminId > 0 {
+		condition += ` AND apply_admin_id=? `
+		pars = append(pars, adminId)
 	}
-	groupList = append(groupList, sellerGroup)
 
-	otherGroup := new(business_trip.BusinessTripCalendarGroup)
-	otherGroup.GroupId = 3
-	otherGroup.GroupName = "其他"
-	if utils.RunMode == "debug" {
-		otherGroup.DepartmentId = "3,7"
+	if sysUserId == 66 {
+		condition += ` AND status IN('待审批','已审批') `
 	} else {
-		otherGroup.DepartmentId = "3,6,7,8"
+		condition += ` AND status=? `
+		pars = append(pars, "已审批")
 	}
-	groupList = append(groupList, otherGroup)
 
-	groupLen := len(groupList)
+	if tripDate != "" {
+		condition += ` AND arrive_date>=? `
+		pars = append(pars, tripDate)
 
-	fmt.Println("groupLen:", groupLen)
-	//获取当天周日期
-	nowWeekStart := utils.GetNowWeekMonday().AddDate(0, 0, -2)
-	//nowWeekEnd := utils.GetNowWeekLastDay()
-	//获取下周日期
-	nextWeekStart := utils.GetNextWeekMonday().AddDate(0, 0, -2)
-	nextWeekEnd := utils.GetNextWeekLastDay().AddDate(0, 0, -2)
+		condition += ` AND return_date<=? `
+		pars = append(pars, tripDate)
+	}
 
-	//获取出差信息
-	businessTripList, err := business_trip.GetBusinessTripList(adminId, nowWeekStart.Format(utils.FormatDate), nextWeekEnd.Format(utils.FormatDate))
+	list, err := business_trip.GetBusinessTripApproveList(condition, pars)
 	if err != nil {
-		this.FailWithMessage("获取信息失败!", "获取路演信息失败!,GetBusinessTripList Err:"+err.Error())
+		this.FailWithMessage("获取数据失败!", "获取数据失败,GetBusinessTripApproveList,Err:"+err.Error())
 		return
 	}
 
-	btMap := make(map[int][]*business_trip.BusinessApplyView)
-
-	for _, v := range businessTripList {
-		if findVals, ok := btMap[v.ApplyAdminId]; ok {
-			findVals = append(findVals, v)
-			btMap[v.ApplyAdminId] = findVals
-		} else {
-			items := make([]*business_trip.BusinessApplyView, 0)
-			items = append(items, v)
-			btMap[v.ApplyAdminId] = items
+	approveList := make([]*business_trip.BusinessTripApproveView, 0)
+	listLen := len(list)
+	for i := 0; i < listLen; i++ {
+		item := list[i]
+		approveList = append(approveList, item)
+		dayCount := int(item.ReturnDate.Sub(item.ArriveDate).Hours()/24) + 1
+		list[i].DayTotal = dayCount
+
+		var groupName string
+		switch item.DepartmentTd {
+		case 1:
+			groupName = "研究员"
+		case 2, 4, 5, 9:
+			groupName = "销售"
+		case 3, 6, 7, 8:
+			groupName = "其他"
+		default:
+			groupName = "其他"
 		}
-	}
-
-	for i := 0; i < groupLen; i++ {
-		group := groupList[i]
-		fmt.Println("group:", group.DepartmentId)
-
-		adminList, err := business_trip.GetBusinessTripCalendar(group.DepartmentId)
-		if err != nil {
-			this.FailWithMessage("获取信息失败!", "获取分组信息失败!,GetBusinessTripCalendar Err:"+err.Error())
-			return
-		}
-
-		setAdminList := make([]*business_trip.BusinessTripCalendarAdmin, 0)
-
-		for _, v := range adminList {
-			if findTripList, ok := btMap[v.AdminId]; ok {
-				tripList := make([]*business_trip.BusinessTripCalendar, 0)
-				for i := 0; i < 7; i++ {
-					newDay, _ := time.ParseInLocation(utils.FormatDate, nowWeekStart.AddDate(0, 0, i).Format(utils.FormatDate), time.Local)
-					weekDate := newDay.Format(utils.FormatDate)
-					tripItem := new(business_trip.BusinessTripCalendar)
-					for _, r := range findTripList {
-						startDateT, _ := time.ParseInLocation(utils.FormatDate, r.ArriveDate, time.Local)
-						endDateT, _ := time.ParseInLocation(utils.FormatDate, r.ReturnDate, time.Local)
-						if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
-							tripItem.City = r.City
-							tripItem.BusinessApplyId = r.BusinessApplyId
-							tripItem.Status = r.Status
-						}
-					}
-					tripItem.WeekDate = weekDate
-					tripItem.WeekType = "current"
-					tripItem.Week = newDay.Weekday().String()
-					tripList = append(tripList, tripItem)
+		list[i].GroupName = groupName
+
+		if item.Status == "已审批" && item.PeerPeopleId != "" {
+			peerIdArr := strings.Split(item.PeerPeopleId, ",")
+			peerNameArr := strings.Split(item.PeerPeopleName, ",")
+			for k, v := range peerIdArr {
+				peerId, err := strconv.Atoi(v)
+				if err != nil {
+					this.FailWithMessage("申请失败!", "同行人id失败,Err:"+err.Error())
+					return
 				}
-
-				for i := 0; i < 7; i++ {
-					newDay := nextWeekStart.AddDate(0, 0, i)
-					weekDate := newDay.Format(utils.FormatDate)
-					tripItem := new(business_trip.BusinessTripCalendar)
-					for _, r := range findTripList {
-						startDateT, _ := time.ParseInLocation(utils.FormatDate, r.ArriveDate, time.Local)
-						endDateT, _ := time.ParseInLocation(utils.FormatDate, r.ReturnDate, time.Local)
-						if r != nil && (newDay.Equal(startDateT) || (newDay.Equal(endDateT)) || (newDay.Before(endDateT) && newDay.After(startDateT))) {
-							tripItem.City = r.City
-							tripItem.BusinessApplyId = r.BusinessApplyId
-							tripItem.Status = r.Status
-						}
-					}
-					tripItem.WeekDate = weekDate
-					tripItem.WeekType = "next"
-					tripItem.Week = newDay.Weekday().String()
-					tripList = append(tripList, tripItem)
-				}
-				v.BusinessTripList = tripList
-				setAdminList = append(setAdminList, v)
+				peerItem := new(business_trip.BusinessTripApproveView)
+				peerItem = item
+				peerItem.ApplyAdminId = peerId
+				peerItem.ApplyRealName = peerNameArr[k]
+				peerItem.DayTotal = dayCount
+				approveList = append(approveList, peerItem)
 			}
 		}
-		groupList[i].AdminList = setAdminList
 	}
-	resp := new(business_trip.BusinessTripCalendarResp)
-	resp.GroupList = groupList
-	this.OkDetailed(resp, "获取成功")
+
+	this.OkDetailed(list, "获取成功")
 	return
 }

+ 42 - 0
models/tables/business_trip/business_approve.go

@@ -1,7 +1,49 @@
 package business_trip
 
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
 type BusinessApplyApproveReq struct {
 	BusinessApplyId int    `description:"出差申请id"`
 	ApproveStatus   int    `description:"审批状态:1:通过,2:驳回"`
 	RefuseReason    string `description:"驳回理由"`
 }
+
+type BusinessTripApproveView struct {
+	BusinessApplyId int       `description:"出差申请id"`
+	ApplyAdminId    int       `description:"申请人id"`
+	ApplyRealName   string    `description:"申请人姓名"`
+	ArriveDate      time.Time `description:"到达日期"`
+	ReturnDate      time.Time `description:"返程日期"`
+	Province        string    `description:"目的地省"`
+	City            string    `description:"目的地市"`
+	Reason          string    `description:"出差事由"`
+	Transportation  string    `description:"交通工具"`
+	PeerPeopleId    string    `description:"同行人id"`
+	PeerPeopleName  string    `description:"同行人"`
+	Status          string    `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
+	ApproveId       int       `description:"审批人id"`
+	ApproveName     string    `description:"审批人姓名"`
+	RefuseReason    string    `description:"拒绝理由"`
+	RefuseTime      string    `description:"拒绝时间"`
+	ApproveTime     string    `description:"审批时间"`
+	CreateTime      string    `description:"创建时间"`
+	ModifyTime      string    `description:"修改时间"`
+	DepartmentTd    int       `json:"-"`
+	GroupName       string    `description:"分组"`
+	DayTotal        int       `description:"出差天数"`
+}
+
+func GetBusinessTripApproveList(condition string, pars []interface{}) (list []*BusinessTripApproveView, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT a.*,b.department_id FROM business_apply AS a
+			 INNER JOIN admin AS b ON a.apply_admin_id=b.admin_id `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY a.create_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	return
+}