Browse Source

增加导出报表标头的处理和内容处理

pull/87/head
zhangxin 3 years ago
parent
commit
6f86f2862e
2 changed files with 199 additions and 11 deletions
  1. +44
    -7
      models/log/ArtDemandlst.Response.go
  2. +155
    -4
      services/log/implments/ArtDemandLst.service.impl.go

+ 44
- 7
models/log/ArtDemandlst.Response.go View File

@ -1,5 +1,7 @@
package log
import "LAPP_GAAS_GFrame_BACKEND/grmi"
/******************************************************************************
*
* @Struct Name : ArtDemandLstResponseItem
@ -14,14 +16,49 @@ package log
******************************************************************************/
type ArtDemandLstResponseItem struct {
*ArtDemandLst
ArtDesc string `json:"LOG_ArtDemandLst-ArtDesc"` // 物料描述
UrgencyDegree int `json:"LOG_ArtDemandLst-UrgencyDegree"` // 紧急程度
SurplusDays int64 `json:"LOG_ArtDemandLst-SurplusDays"` // 距离交付天数
ArtDesc string `json:"LOG_ArtDemandLst-ArtDesc"` // 物料描述
UrgencyDegree int `json:"LOG_ArtDemandLst-UrgencyDegree"` // 紧急程度
SurplusDays int64 `json:"LOG_ArtDemandLst-SurplusDays"` // 距离交付天数
}
//TODO 临时结构体 待解决
type ArtDemandLstResponseItemTemp struct {
PlantNr int `xorm:"pk int 'PlantNr'" json:"LOG_ArtDemandLst-PlantNr"`
ArtId string `xorm:"pk nvarchar(40) 'ArtId'" json:"LOG_ArtDemandLst-ArtId"`
DemandTime grmi.DateTime `xorm:"pk datetime2(0) 'DemandTime'" json:"LOG_ArtDemandLst-DemandTime"`
DemandId string `xorm:"nvarchar(40) 'DemandId' not null" json:"LOG_ArtDemandLst-DemandId"`
DemandYear int `xorm:"int 'DemandYear' not null" json:"LOG_ArtDemandLst-DemandYear"`
DemandMonth int `xorm:"int 'DemandMonth' not null" json:"LOG_ArtDemandLst-DemandMonth"`
DemandWeek int `xorm:"int 'DemandWeek' not null" json:"LOG_ArtDemandLst-DemandWeek"`
DemandDate grmi.Date `xorm:"date 'DemandDate' not null" json:"LOG_ArtDemandLst-DemandDate"`
DemandHour int `xorm:"int 'DemandHour' not null" json:"LOG_ArtDemandLst-DemandHour"`
DemandQty float64 `xorm:"float 'DemandQty' not null" json:"LOG_ArtDemandLst-DemandQty"`
QtyUomId string `xorm:"nvarchar(40) 'QtyUomId' not null" json:"LOG_ArtDemandLst-QtyUomId"`
DemandObjId string `xorm:"nvarchar(40) 'DemandObjId' not null" json:"LOG_ArtDemandLst-DemandObjId"`
DemandType string `xorm:"nvarchar(40) 'DemandType' not null" json:"LOG_ArtDemandLst-DemandType"`
Status string `xorm:"int 'Status' not null" json:"LOG_ArtDemandLst-Status"`
DemandSendTime grmi.DateTime `xorm:"datetime 'DemandSendTime'" json:"LOG_ArtDemandLst-DemandSendTime"`
DemandRecieveTime grmi.DateTime `xorm:"datetime 'DemandRecieveTime'" json:"LOG_ArtDemandLst-DemandRecieveTime"`
DemandConfirmTime grmi.DateTime `xorm:"datetime 'DemandConfirmTime'" json:"LOG_ArtDemandLst-DemandConfirmTime"`
DemandCloseTime grmi.DateTime `xorm:"datetime 'DemandCloseTime'" json:"LOG_ArtDemandLst-DemandCloseTime"`
DemandDeliveredQty float64 `xorm:"float 'DemandDeliveredQty' not null" json:"LOG_ArtDemandLst-DemandDeliveredQty"`
DemandCtrlPara1 int `xorm:"int 'DemandCtrlPara1' not null" json:"LOG_ArtDemandLst-DemandCtrlPara1"`
DemandCtrlPara2 int `xorm:"int 'DemandCtrlPara2' not null" json:"LOG_ArtDemandLst-DemandCtrlPara2"`
DemandCtrlPara3 string `xorm:"nvarchar(100) 'DemandCtrlPara3' not null" json:"LOG_ArtDemandLst-DemandCtrlPara3"`
DemandCtrlPara4 string `xorm:"nvarchar(100) 'DemandCtrlPara4' not null" json:"LOG_ArtDemandLst-DemandCtrlPara4"`
DemandCtrlTime1 grmi.DateTime `xorm:"datetime 'DemandCtrlTime1'" json:"LOG_ArtDemandLst-DemandCtrlTime1"`
DemandCtrlTime2 grmi.DateTime `xorm:"datetime 'DemandCtrlTime2'" json:"LOG_ArtDemandLst-DemandCtrlTime2"`
LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"LOG_ArtDemandLst-LastModify"`
LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"LOG_ArtDemandLst-LastUser"`
CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"LOG_ArtDemandLst-CreateTime"`
ArtDesc string `json:"LOG_ArtDemandLst-ArtDesc"` // 物料描述
UrgencyDegree string `json:"LOG_ArtDemandLst-UrgencyDegree"` // 紧急程度
SurplusDays int64 `json:"LOG_ArtDemandLst-SurplusDays"` // 距离交付天数
}
// UrgencyDegree状态值
const (
UrgencyNot int = iota // 0 不紧急 绿色
UrgencyNormal // 1 紧急 黄色
UrgencySerious // 2 延误 红色
)
UrgencyNot int = iota // 0 不紧急 绿色
UrgencyNormal // 1 紧急 黄色
UrgencySerious // 2 延误 红色
)

+ 155
- 4
services/log/implments/ArtDemandLst.service.impl.go View File

@ -369,7 +369,7 @@ func (impl *ArtDemandLstServiceImplement) Select(user *models.Usertab, urlParame
status, exist := urlParameters["status"]
if exist && status == strconv.Itoa(model.AccomplishedStatus) {
if urgency != model.UrgencyNot {
predicate := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.Include, )}
predicate := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.Include)}
predicates = append(predicates, predicate...)
}
} else {
@ -557,16 +557,167 @@ func (impl *ArtDemandLstServiceImplement) ExportExcel(user *models.Usertab, urlP
}
predicates = append(predicates, innerPredicates...)
}
urgencyString, exist := urlParameters["urgency"]
if exist {
urgency, err := strconv.Atoi(urgencyString)
if err == nil {
now := time.Now()
date := now.AddDate(0, 0, 2)
dateString := date.Format(grmi.DateOutFormat)
today := now.Format(grmi.DateOutFormat)
status, exist := urlParameters["status"]
if exist && status == strconv.Itoa(model.AccomplishedStatus) {
if urgency != model.UrgencyNot {
predicate := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.Include)}
predicates = append(predicates, predicate...)
}
} else {
if urgency == model.UrgencyNot {
predicate := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.GreaterThen, dateString)}
predicates = append(predicates, predicate...)
} else if urgency == model.UrgencyNormal {
predicate1 := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.GreaterOrEqual, today)}
predicate2 := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.LessOrEqual, dateString)}
predicates = append(predicates, predicate1...)
predicates = append(predicates, predicate2...)
} else {
predicate := []grmi.Predicate{meta.ArtDemandLst_DemandDate.NewPredicate(grmi.LessThen, today)}
predicates = append(predicates, predicate...)
}
predicate := []grmi.Predicate{meta.ArtDemandLst_Status.NewPredicate(grmi.NotEqual, model.AccomplishedStatus)}
predicates = append(predicates, predicate...)
}
}
}
dao := dal.NewArtDemandLstDAO(session, user.Pid, user.Userid)
year, month, day := time.Now().Date()
var today time.Time
var monthStr string
var dayStr string
if int(month) >= 10 {
monthStr = strconv.Itoa(int(month))
} else {
monthStr = fmt.Sprintf("0%d", int(month))
}
if day >= 10 {
dayStr = strconv.Itoa(day)
} else {
dayStr = fmt.Sprintf("0%d", day)
}
today, err = time.ParseInLocation(grmi.DateOutFormat, fmt.Sprintf("%d-%s-%s", year, monthStr, dayStr), utils.TimezoneLocation)
if err != nil {
return nil, err
}
result, err := dao.Select(predicates, condition.OrderByFields)
if err != nil {
return nil, err
}
temp := make([]interface{}, len(result))
for index, item := range result {
baseDao := baseDal.NewArticleDAO(session, user.Pid, user.Userid)
responseLi := make([]model.ArtDemandLstResponseItemTemp, 0, len(result))
for _, artDemandLst := range result {
data := artDemandLst
var responseItem model.ArtDemandLstResponseItemTemp
if data.Status == model.ReceivedStatus {
responseItem.Status = "接收"
} else if data.Status == model.WaitReceivingStatus {
responseItem.Status = "未接收"
} else if data.Status == model.ConfirmedStatus {
responseItem.Status = "确认交期"
} else if data.Status == model.AccomplishedStatus{
responseItem.Status = "完成答复"
}
responseItem.DemandDate = data.DemandDate
responseItem.ArtId = data.ArtId
responseItem.DemandTime = data.DemandTime
responseItem.DemandType = data.DemandType
responseItem.QtyUomId = data.QtyUomId
responseItem.DemandDeliveredQty = data.DemandDeliveredQty
responseItem.DemandCtrlTime1 = data.DemandCtrlTime1
responseItem.DemandCtrlTime2 = data.DemandCtrlTime2
responseItem.DemandCtrlPara4 = data.DemandCtrlPara4
responseItem.DemandCtrlPara3 = data.DemandCtrlPara3
responseItem.DemandCtrlPara2 = data.DemandCtrlPara2
responseItem.DemandCtrlPara1 = data.DemandCtrlPara1
responseItem.PlantNr = data.PlantNr
responseItem.DemandYear = data.DemandYear
responseItem.DemandMonth = data.DemandMonth
responseItem.DemandWeek = data.DemandWeek
responseItem.DemandHour = data.DemandHour
responseItem.DemandQty = data.DemandQty
responseItem.DemandSendTime = data.DemandSendTime
responseItem.DemandRecieveTime = data.DemandRecieveTime
responseItem.DemandConfirmTime = data.DemandConfirmTime
responseItem.DemandCloseTime = data.DemandCloseTime
responseItem.DemandId = data.DemandId
responseItem.LastModify = data.LastModify
responseItem.LastUser = data.LastUser
responseItem.CreateTime = data.CreateTime
responseItem.DemandObjId = data.DemandObjId
article, err := baseDao.SelectOne(artDemandLst.ArtId)
if err != nil {
return nil, err
}
if article != nil {
responseItem.ArtDesc = article.Descr1
}
if artDemandLst.Status == model.AccomplishedStatus {
responseItem.UrgencyDegree = "不紧急"
responseItem.SurplusDays = 0
} else {
demandDate := artDemandLst.DemandDate.Restore()
days := (demandDate.Unix() - today.Unix()) / 86400
responseItem.SurplusDays = days
if days > 2 {
responseItem.UrgencyDegree = "不紧急"
} else if days >= 0 && days <= 2 {
responseItem.UrgencyDegree = "紧急"
} else {
responseItem.UrgencyDegree = "延误"
}
}
responseLi = append(responseLi, responseItem)
}
temp := make([]interface{}, len(responseLi))
for index, item := range responseLi {
temp[index] = item
}
titleList := make([]string, 0)
//titleList := make([]string, 0)
titleList := []string{
"工厂ID",
"ArtId",
"需求时间",
"需求ID",
"需求年份",
"需求月份",
"需求周",
"需求日期",
"需求时",
"需求数量",
"数量单位",
"需求对象ID",
"需求类型",
"状态",
"需求发送时间",
"需求接收时间",
"需求确认时间",
"需求关闭时间",
"需求发运数量",
"需求控制参数1",
"需求控制参数2",
"需求控制参数3",
"需求控制参数4",
"需求时间参数1",
"需求时间参数2",
"最后修改时间",
"最后操作人",
"创建时间",
"物料描述",
"紧急程度",
"剩余交付天数",
}
filepath, err := grmi.SaveExcelFile(temp, titleList, "供应商需求明细", "供应商需求明细")
if err != nil {
return nil, grmi.NewBusinessError(fmt.Sprintf("导出报表失败,请重试, errors: %s", err.Error()))


Loading…
Cancel
Save