天天看点

ABP框架按条件导出

web层

.js导出事件:

//导出为excel文档

$('#btn-export').click(function () {

//得到查询的参数

var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的

ProcessSteps_RecordId: $("#ProcessSteps_RecordId").val(),

OperationModeId: $("#OperationModeId").val(),

ScanCodeProduce: $("#ScanCodeProduce").val(),

ReceiveValue: $("#ReceiveValue").val(),

IsOK: $("#IsOK").val(),

SerialNumber: $("#SerialNumber").val(),

OperationCategory: $("#OperationCategory").val(),

StationId: $("#StationName").val(),

LineId: $("#LineName").val(),

MinTime: $("#MinTime1").val(),

MaxTime: $("#MaxTime1").val()

};

layer.load(0, {

shade: [0.3, '#000'] //0.1透明度的白色背景

});

_processSteps_Detail_RecordService

.getProcessSteps_Detail_RecordToExcel(temp)

.done(function (result) {

layer.closeAll('loading');

app.downloadTempFile(result);

});

});

注释:

‘#’后面的字符是HTML里的Id名

temp 里面是条件(这个将传给Application层的方法),getProcessSteps_Detail_RecordToExcel(temp)方法是对应的Application层的方法。

Application层

接口:

Task<FileDto> GetProcessSteps_Detail_RecordToExcel(GetProcessSteps_Detail_RecordInput input);

方法:

public async Task<FileDto> GetProcessSteps_Detail_RecordToExcel(GetProcessSteps_Detail_RecordInput input)

{

var OperationCategoryDir = DictionaryDto.OperationCategoryDir;

var IsOKDir = DictionaryDto.IsOKDir;

//初步过滤

var query = from pdr in _processSteps_Detail_RecordRepository.GetAll()

join ed in _EnumDictRepository.GetAll() on pdr.OperationModeId equals ed.Id

join pr in _processSteps_RecordRepository.GetAll() on pdr.ProcessSteps_RecordId equals pr.Id

join p in _ProcessStepsRepository.GetAll() on pr.ProcessStepsId equals p.Id

join s in _StationRepository.GetAll() on p.StationId equals s.Id

join l in _LineRepository.GetAll() on s.LineId equals l.Id

orderby pdr.Id descending

select new ProcessSteps_Detail_RecordListDto()

{

Id = pdr.Id,

LineId = l.Id,

};

query = query

.WhereIf(!(input.LineId == "0"), u => u.LineId == LineId)

;

var list = query.ToList();

var fileDto = _processSteps_Detail_RecordListExcelExporter.ExportProcessSteps_Detail_RecordToFile(list);

return fileDto;

}

注释:方法对应接口

转载于:https://www.cnblogs.com/Prode/p/11285909.html