作者 陈志颖

fix:修复导出素币流水记录

... ... @@ -7,6 +7,7 @@ import (
type ExportTransactionRecordCommand struct {
Ids []int `json:"ids"`
Where map[string]interface{} `json:"where"`
}
func (exportTransactionRecordCommand *ExportTransactionRecordCommand) ValidateCommand() error {
... ...
... ... @@ -1206,12 +1206,13 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
fmt.Printf("员工:%+v\n", len(peopleFound))
if len(peopleFound) > 0 { // 追加素币兑换或撤回素币兑换
// 获取兑换清单员工已兑换素币
personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney
fmt.Print(createExchangeCashPersonCommand.ExchangedSuMoney, "\n")
fmt.Print(personFoundExchangedSuMoney, "\n")
if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币
// 减量
suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
... ...
... ... @@ -181,7 +181,7 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
"isPrincipal": suMoneyTransactionRecord.Operator.IsPrincipal,
},
"recordDescription": suMoneyTransactionRecord.RecordDescription,
"createTime": suMoneyTransactionRecord.CreateTime.Location(),
"createTime": suMoneyTransactionRecord.CreateTime,
}
suMoneyTransactionRecordsFormat = append(suMoneyTransactionRecordsFormat, suMoneyTransactionRecordFormat)
}
... ... @@ -324,7 +324,7 @@ func (suMoneyService *SuMoneyService) ListSuMoneyTransactionRecordById(exportSuM
transactionContext.RollbackTransaction()
}()
if len(exportSuMoneyTransactionRecordCommand.Ids) == 0 {
if len(exportSuMoneyTransactionRecordCommand.Ids) == 0 && exportSuMoneyTransactionRecordCommand.Where == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
}
... ...
... ... @@ -70,12 +70,16 @@ func (repository *SuMoneyTransactionRecordRepository) FindById(queryOptions map[
var suMoneyTransactionRecordModels []*models.SuMoneyTransactionRecord
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)))
//}
if iDs, ok := queryOptions["ids"]; ok {
query = query.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
if iDs, ok := queryOptions["ids"]; ok && len(iDs.([]int)) != 0 {
query = query.Where(`su_money_transaction_record.id IN (?)`, pg.In(iDs.([]int)))
}
if where, ok := queryOptions["where"]; ok && where.(map[string]interface{}) != nil {
if companyId, ok := where.(map[string]interface{})["companyId"]; ok && companyId.(float64) != 0 {
query = query.Where("e.company_id = ?", companyId)
}
}
//query = query.Where(`e.status = ?`, 1)
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, suMoneyTransactionRecords, err
} else {
... ...
... ... @@ -418,6 +418,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
response = utils.ResponseError(controller.Ctx, err)
controller.Data["json"] = response
controller.ServeJSON()
return
}
xlsx, err := excelize.OpenReader(file)
... ... @@ -428,43 +429,46 @@ func (controller *SuMoneyController) ImportExchangeList () {
// 文件行数校验
rows, _ := xlsx.GetRows("Sheet1")
if len(rows) > 302 {
err := fmt.Errorf("%s", "导入行数超过300行")
response = utils.ResponseError(controller.Ctx, err)
controller.Data["json"] = response
controller.ServeJSON()
return
}
// 空行记录
nullLine := make([]interface{}, 0)
//nullLine := make([]interface{}, 0)
// 单元格非空校验
for i, row := range rows {
if i > 2 {
for _, _ = range row {
r2, _ := strconv.ParseFloat(row[2], 64)
if row[0] == "" || row[1] == "" || r2 == 0 {
//row = append(row, "单元格包含空字符")
//nullLine = append(nullLine, row)
}
}
}
}
if len(nullLine) > 0 {
ret = map[string]interface{}{
"successCount": 0,
"fail": map[string]interface{}{
"tableHeader": tableHeader,
"tableData": nullLine,
},
}
response = utils.ResponseData(controller.Ctx, ret)
controller.Data["json"] = response
controller.ServeJSON()
}
// 新增失败记录
//for i, row := range rows {
// if i > 2 {
// for _, _ = range row {
// if len(row) != 3 {
// row = append(row, "null")
// row = append(row, "单元格包含空字符")
// nullLine = append(nullLine, row)
// }
// }
// }
//}
//
//if len(nullLine) > 0 {
// ret = map[string]interface{}{
// "successCount": 0,
// "fail": map[string]interface{}{
// "tableHeader": tableHeader,
// "tableData": nullLine,
// },
// }
// response = utils.ResponseData(controller.Ctx, ret)
// controller.Data["json"] = response
// controller.ServeJSON()
// return
//}
//
//// 新增失败记录
failureDataList := make([]interface{}, 0)
// 新增成功计数
... ... @@ -483,8 +487,8 @@ func (controller *SuMoneyController) ImportExchangeList () {
// 创建兑换素币清单
_, err := cashPoolService.ImportCreateExchangeCashPerson(createExchangeCashPersonCommand)
if err != nil { // 导入失败处理
//rows[i] = append(rows[i], err.Error())
//failureDataList = append(failureDataList, rows[i]) // 导入失败的记录
rows[i] = append(rows[i], err.Error())
failureDataList = append(failureDataList, rows[i]) // 导入失败的记录
} else { // 导入成功处理
successDataCount += 1
}
... ... @@ -502,6 +506,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
response = utils.ResponseData(controller.Ctx, ret)
controller.Data["json"] = response
controller.ServeJSON()
return
}
// 导出素币兑换清单,选择导出(ids),增加导出失败信息
... ...