作者 陈志颖

fix:修改活动列表搜索

... ... @@ -3,10 +3,15 @@ package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"time"
)
type SearchExchangeCashActivityCommand struct {
ActivityName string `json:"activityName"` // 兑换现金活动名称
ActivityNameMatch string `json:"activityNameMatch"` // 兑换现金活动名称
CompanyId int64 `json:"companyId"` // 公司id
Deadline time.Time `json:"deadline,omitempty"` // 截止时间筛选
Offset int `json:"offset,omitempty"` // 查询偏移量
Limit int `json:"limit,omitempty"` // 查询限制条目
}
func (searchExchangeCashActivityCommand *SearchExchangeCashActivityCommand) ValidateCommand() error {
... ...
... ... @@ -8,8 +8,8 @@ import (
// 获取兑换现金活动列表
type ListExchangeCashActivityQuery struct {
CompanyId int64 `json:"companyId"` // 公司id
ExchangeCashActivityNameMatch string `json:"exchangeCashActivityNameMatch,omitempty"` // 活动名称匹配
Deadline string `json:"deadline,omitempty"` // 截止时间筛选
ActivityNameMatch string `json:"activityNameMatch,omitempty"` // 活动名称匹配
//Deadline time.Time `json:"deadline,omitempty"` // 截止时间筛选
Offset int `json:"offset,omitempty"` // 查询偏移量
Limit int `json:"limit,omitempty"` // 查询限制条目
}
... ...
... ... @@ -277,7 +277,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
var timeNow = time.Now()
var deadline = createExchangeCashActivityCommand.Deadline
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
newActivity := &domain.ExchangeCashActivity{
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
... ... @@ -285,7 +285,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
ExchangedCash: 0,
ExchangedSuMoney: 0,
//Deadline: time.Date(deadline.Year(), deadline.Month(), deadline.Day(), deadline.Hour(), deadline.Minute(), deadline.Second(), 0, time.Local),
Deadline: createExchangeCashActivityCommand.Deadline,
Deadline: deadline,
CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算活动截止倒计时
Rate: createExchangeCashActivityCommand.ExchangeRate,
CreateTime: time.Now(),
... ... @@ -349,7 +349,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
var deadlines []interface{}
for _, activity := range activities {
deadlines = append(deadlines, activity.Deadline.Format("2006-01-02"))
deadlines = append(deadlines, activity.Deadline)
}
if len(deadlines) == 0 {
... ... @@ -362,6 +362,71 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
}
}
// 搜索兑换现金活动
func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityCommand *command.SearchExchangeCashActivityCommand) (interface{}, error) {
if err := activityCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var exchangeActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeActivityRepository = value
}
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(activityCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, activity := range activities {
var t1 = time.Now()
var t2 = activity.Deadline
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
ExchangeCashActivityId: activity.ActivityId,
CountDown: int64(t2.Sub(t1).Hours() / 24),
Deadline: activity.Deadline,
}
// 倒计时结束
if t2.Before(t1) {
updateExchangeCashActivity.CountDown = 0
updateExchangeCashActivity.Deadline = activity.Deadline
}
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
_, err := exchangeActivityRepository.Save(activity)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"activities": activities,
}, nil
}
}
// 返回兑换现金活动列表
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
... ... @@ -391,10 +456,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, activity := range activities {
var timeNow = time.Now()
var deadline = activity.Deadline
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
//var timeNow = time.Now()
//var deadline = activity.Deadline
//var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
//var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
var t1 = time.Now()
var t2 = activity.Deadline
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
ExchangeCashActivityId: activity.ActivityId,
... ...
... ... @@ -108,6 +108,7 @@ type TaskStatus interface {
RejectReceiver(task *Task) error
}
// 待发布的任务
type UnReleasedStatus struct{}
func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) error {
... ... @@ -433,6 +434,7 @@ func (status *UnderwayStatus) RejectReceiver(task *Task) error {
return nil
}
// 代验收的任务
type UnAcceptanceStatus struct{}
func (status *UnAcceptanceStatus) Update(task *Task, data map[string]interface{}) error {
... ... @@ -580,6 +582,7 @@ func (status *ClosedStatus) RejectReceiver(task *Task) error {
return fmt.Errorf("已关闭的任务不允许驳回任务领取人")
}
// 待确认任务
type UnConfirmedStatus struct{}
func (status *UnConfirmedStatus) Update(task *Task, data map[string]interface{}) error {
... ... @@ -635,6 +638,49 @@ func (status *UnConfirmedStatus) RejectReceiver(task *Task) error {
return nil
}
// TODO 已过期任务
type ExpiredStatus struct{}
func (status ExpiredStatus) Update(task *Task, data map[string]interface{}) error {
panic("implement me")
}
func (status ExpiredStatus) Release(task *Task) error {
panic("implement me")
}
func (status ExpiredStatus) Rob(task *Task, receiver *EmployeeInfo) error {
panic("implement me")
}
func (status ExpiredStatus) Bib(task *Task, bidder *EmployeeInfo) error {
panic("implement me")
}
func (status ExpiredStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo, plannedCompletionTime time.Time) error {
panic("implement me")
}
func (status ExpiredStatus) ApplyComplete(task *Task) error {
panic("implement me")
}
func (status ExpiredStatus) Off(task *Task) error {
panic("implement me")
}
func (status ExpiredStatus) Acceptance(task *Task, participators []*EmployeeInfo, suMoney float64, taskPercentage []*TaskPercentageItem, referenceResourceScore []*ReferenceResourceItem, solveReport string, solvePictureUrls []string, actualCompletionTime time.Time) error {
panic("implement me")
}
func (status ExpiredStatus) ConfirmTask(task *Task, plannedCompletionTime time.Time) error {
panic("implement me")
}
func (status ExpiredStatus) RejectReceiver(task *Task) error {
panic("implement me")
}
type TaskRepository interface {
Save(task *Task) (*Task, error)
Remove(task *Task) (*Task, error)
... ...
... ... @@ -41,7 +41,8 @@ func (dao *TaskDao) UpdateExpiredPlannedCompletionTimeBidTask() error {
query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo").
Set("task.task_type = ", domain.TASK_STATUS_EXPIRED).
Where("task.planned_completion_time > ?", currentDay).
Where(`task.task_type =?`, domain.TASK_TYPE_BID)
Where(`task.task_type = ?`, domain.TASK_TYPE_BID).
Where(`task.task_status = ?`, domain.TASK_STATUS_UNCLAIMED)
if _, err := query.Update(); err != nil {
return err
}
... ...
... ... @@ -84,19 +84,20 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where(`exchange_cash_activity.company_id = ?`, companyId)
}
if exchangeCashActivityNameMatch, ok := queryOptions["exchangeCashActivityNameMatch"]; ok && (exchangeCashActivityNameMatch != "") {
query = query.Where(`exchange_cash_activity.activity_name LIKE ?`, fmt.Sprintf("%%%s%%", exchangeCashActivityNameMatch.(string)))
if activityNameMatch, ok := queryOptions["activityNameMatch"]; ok && (activityNameMatch != "") {
query = query.Where(`exchange_cash_activity.activity_name LIKE ?`, fmt.Sprintf("%%%s%%", activityNameMatch.(string)))
}
//if deadline, ok := queryOptions["deadline"]; ok && !deadline.(time.Time).IsZero() {
// query = query.Where(`exchange_cash_activity.deadline > ?`, deadline)
//}
if deadlineStr, ok := queryOptions["deadline"]; ok && (deadlineStr.(string) != "") {
var layout string = "2006-01-02"
deadline, _:= time.Parse(layout, deadlineStr.(string))
var t = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
query = query.Where(`exchange_cash_activity.deadline > ?`, t)
if deadline, ok := queryOptions["deadline"]; ok && !deadline.(time.Time).IsZero() {
//var layout string = "2006-01-02"
////deadline, _:= time.Parse(layout, deadlineStr.(string))
//deadline, _:= time.ParseInLocation(layout, deadlineStr.(string), time.Local)
//fmt.Print(deadline, "\n")
//var t = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
//fmt.Print(t, "\n")
query = query.Where(`exchange_cash_activity.deadline > ?`, deadline)
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
... ...
... ... @@ -71,7 +71,7 @@ func (repository *SuMoneyTransactionRecordRepository) FindById(queryOptions map[
suMoneyTransactionRecords := make([]*domain.SuMoneyTransactionRecord, 0)
query := tx.Model(&suMoneyTransactionRecordModels)
if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 {
query = query.Where("su_money_transaction_record.id IN (?)", pg.In(iDs.([]int)))
query = query.Where(`su_money_transaction_record.id IN (?)`, pg.In(iDs.([]int)))
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, suMoneyTransactionRecords, err
... ...
... ... @@ -317,6 +317,9 @@ func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *model
case domain.TASK_STATUS_UNCONFIRMED:
currentStatus = &domain.UnConfirmedStatus{}
break
case domain.TASK_STATUS_EXPIRED:
currentStatus = &domain.ExpiredStatus{}
break
}
return &domain.Task{
TaskId: taskModel.Id,
... ...
... ... @@ -138,7 +138,6 @@ func (controller *SuMoneyController) CashInput() {
func (controller *SuMoneyController) GetCashPool() {
cashPoolService := service.NewCashPoolService(nil)
getCashPoolQuery := &query.GetCashPoolQuery{}
//json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), getCashPoolQuery)
companyId, _ := controller.GetInt64("companyId")
getCashPoolQuery.CompanyId = companyId
data, err := cashPoolService.GetCashPool(getCashPoolQuery)
... ... @@ -152,6 +151,22 @@ func (controller *SuMoneyController) GetCashPool() {
controller.ServeJSON()
}
// 搜索返回兑换活动列表
func (controller *SuMoneyController) SearchExchangeActivities () {
cashPoolService := service.NewCashPoolService(nil)
searchExchangeCashActivityCommand := &command.SearchExchangeCashActivityCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchExchangeCashActivityCommand)
data, err := cashPoolService.SearchExchangeCashActivity(searchExchangeCashActivityCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
// 返回兑换活动列表
func (controller *SuMoneyController) ListExchangeActivities () {
cashPoolService := service.NewCashPoolService(nil)
... ... @@ -159,9 +174,7 @@ func (controller *SuMoneyController) ListExchangeActivities () {
companyId, _ := controller.GetInt64("companyId")
listExchangeCashActivityQuery.CompanyId = companyId
exchangeCashActivityNameMatch := controller.GetString("activityNameMatch")
listExchangeCashActivityQuery.ExchangeCashActivityNameMatch = exchangeCashActivityNameMatch
deadline := controller.GetString("deadline")
listExchangeCashActivityQuery.Deadline = deadline
listExchangeCashActivityQuery.ActivityNameMatch = exchangeCashActivityNameMatch
offset, _ := controller.GetInt("offset")
listExchangeCashActivityQuery.Offset = offset
limit, _ := controller.GetInt("limit")
... ... @@ -629,6 +642,7 @@ func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
case float64:
f.SetCellValue("Sheet1", sheetPosition, vv.(float64))
break
// TODO 时间类型和格式转换
case time.Time:
f.SetCellValue("Sheet1", sheetPosition, vv)
break
... ...
... ... @@ -27,6 +27,7 @@ func init() {
beego.Router("/cash-pool/activity", &controllers.SuMoneyController{}, "Post:CreateExchangeActivities") // 新增兑换活动
beego.Router("/cash-pool/activity/:activityId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeActivities") // 删除兑换活动
beego.Router("/cash-pool/activity/deadline-list", &controllers.SuMoneyController{}, "Get:ListDeadline") // 返回兑换活动截止时间列表
beego.Router("/cash-pool/activity/search-activity", &controllers.SuMoneyController{}, "Post:SearchExchangeActivities") // 搜索兑换活动列表
/********************************************素币兑换清单*************************************/
beego.Router("/cash-pool/activity/exchange-list", &controllers.SuMoneyController{}, "Get:ListExchangeList") // 返回素币兑换清单
... ...