| | |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.annotation.OperationLog; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.KeyValVo; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.common.service.AsyncListExportTaskService; |
| | | import com.vincent.rsf.server.common.service.ListExportHandler; |
| | | import com.vincent.rsf.server.common.service.ListExportService; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.utils.FileServerUtil; |
| | | import com.vincent.rsf.server.common.utils.OptimisticLockUtils; |
| | | import com.vincent.rsf.server.manager.controller.params.LocMastInitParam; |
| | | import com.vincent.rsf.server.manager.controller.params.LocModifyParams; |
| | |
| | | import com.vincent.rsf.server.manager.service.LocService; |
| | | import com.vincent.rsf.server.manager.utils.buildPageRowsUtils; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import com.vincent.rsf.server.system.entity.ExportTask; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanWrapper; |
| | | import org.springframework.beans.BeanWrapperImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import jakarta.validation.Valid; |
| | | import java.io.File; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Api(tags = "库位信息") |
| | | @RestController |
| | | public class LocController extends BaseController { |
| | | private static final String EXPORT_RESOURCE_KEY = "loc"; |
| | | private static final String EXPORT_DEFAULT_REPORT_TITLE = "库位报表"; |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | |
| | | @Autowired |
| | | private ListExportService listExportService; |
| | | |
| | | @Autowired |
| | | private AsyncListExportTaskService asyncListExportTaskService; |
| | | |
| | | private final ListExportHandler<Loc, BaseParam> locExportHandler = new ListExportHandler<>() { |
| | | @Override |
| | | public List<Loc> listByIds(List<Long> ids) { |
| | | return locService.listByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<Loc> listByFilter(Map<String, Object> sanitizedMap, BaseParam baseParam) { |
| | | PageParam<Loc, BaseParam> pageParam = new PageParam<>(baseParam, Loc.class); |
| | | return locService.list(pageParam.buildWrapper(true, getLocSortedFields())); |
| | | } |
| | | |
| | | @Override |
| | | public void fillExportFields(List<Loc> records) { |
| | | buildPageRowsUtils.rowsMap(records); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> toExportRow(Loc record, List<ExcelUtil.ExportColumn> columns) { |
| | | return buildLocExportRow(record, columns); |
| | | } |
| | | |
| | | @Override |
| | | public String defaultReportTitle() { |
| | | return EXPORT_DEFAULT_REPORT_TITLE; |
| | | } |
| | | }; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:list')") |
| | | @PostMapping("/loc/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Loc, BaseParam> pageParam = new PageParam<>(baseParam, Loc.class); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("row"); |
| | | list.add("col"); |
| | | list.add("lev"); |
| | | PageParam<Loc, BaseParam> page = locService.page(pageParam, pageParam.buildWrapper(true,list)); |
| | | PageParam<Loc, BaseParam> page = locService.page(pageParam, pageParam.buildWrapper(true, getLocSortedFields())); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(vos)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:list')") |
| | | @PreAuthorize("hasAuthority('manager:loc:export')") |
| | | @ApiOperation("库位导出") |
| | | @PostMapping("/loc/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | List<Loc> locs = new ArrayList<>(); |
| | | if (Objects.isNull(map.get("ids"))) { |
| | | locs = locService.list(); |
| | | } else { |
| | | locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getStatus, 1)); |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | locExportHandler, |
| | | response |
| | | ); |
| | | } |
| | | ExcelUtil.build(ExcelUtil.create(buildPageRowsUtils.rowsMap(locs), Loc.class), response); |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:export')") |
| | | @PostMapping("/loc/export/async") |
| | | public R createAsyncExportTask(@RequestBody Map<String, Object> map) { |
| | | ExportTask task = asyncListExportTaskService.createTask( |
| | | EXPORT_RESOURCE_KEY, |
| | | EXPORT_DEFAULT_REPORT_TITLE, |
| | | map, |
| | | getTenantId(), |
| | | getLoginUserId() |
| | | ); |
| | | asyncListExportTaskService.executeAsync( |
| | | task.getId(), |
| | | EXPORT_RESOURCE_KEY, |
| | | new HashMap<>(map), |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | locExportHandler |
| | | ); |
| | | return R.ok("导出任务已创建").add(buildPageRowsUtils.rowsMap(task)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:export')") |
| | | @GetMapping("/loc/export/task/{taskId}") |
| | | public R getExportTask(@PathVariable("taskId") Long taskId) { |
| | | ExportTask task = asyncListExportTaskService.getTask( |
| | | taskId, |
| | | EXPORT_RESOURCE_KEY, |
| | | getTenantId(), |
| | | getLoginUserId() |
| | | ); |
| | | if (task == null) { |
| | | return R.error("导出任务不存在"); |
| | | } |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(task)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:export')") |
| | | @GetMapping("/loc/export/task/{taskId}/download") |
| | | public void downloadExportTask( |
| | | @PathVariable("taskId") Long taskId, |
| | | HttpServletResponse response, |
| | | HttpServletRequest request |
| | | ) { |
| | | File file = asyncListExportTaskService.getDownloadFile( |
| | | taskId, |
| | | EXPORT_RESOURCE_KEY, |
| | | getTenantId(), |
| | | getLoginUserId() |
| | | ); |
| | | FileServerUtil.preview(file, true, file.getName(), null, null, response, request); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:loc:update')") |
| | |
| | | return locService.initLocs(param, getLoginUserId()); |
| | | } |
| | | |
| | | private List<String> getLocSortedFields() { |
| | | return Arrays.asList("row", "col", "lev"); |
| | | } |
| | | |
| | | private Map<String, Object> buildLocExportRow(Loc record, List<ExcelUtil.ExportColumn> columns) { |
| | | BeanWrapper beanWrapper = new BeanWrapperImpl(record); |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("warehouseName", record.getWarehouseId$()); |
| | | row.put("areaName", record.getAreaId$()); |
| | | row.put("typeIdsText", record.getTypeIds$()); |
| | | row.put("useStatus", normalizeExportText(record.getUseStatus$())); |
| | | row.put("flagLogicText", toYesNoText(record.getFlagLogic())); |
| | | row.put("flagLabelMangeText", toYesNoText(record.getFlagLabelMange())); |
| | | row.put("status", record.getStatus$()); |
| | | row.put("updateTimeText", record.getUpdateTime$()); |
| | | |
| | | for (ExcelUtil.ExportColumn column : columns) { |
| | | if (row.containsKey(column.getSource())) { |
| | | continue; |
| | | } |
| | | if (beanWrapper.isReadableProperty(column.getSource())) { |
| | | row.put(column.getSource(), beanWrapper.getPropertyValue(column.getSource())); |
| | | } |
| | | } |
| | | |
| | | return row; |
| | | } |
| | | |
| | | private String toYesNoText(Object value) { |
| | | if (value == null) { |
| | | return ""; |
| | | } |
| | | if (Objects.equals(value, 1) || Objects.equals(value, (short) 1) || Objects.equals(value, true)) { |
| | | return "是"; |
| | | } |
| | | if (Objects.equals(value, 0) || Objects.equals(value, (short) 0) || Objects.equals(value, false)) { |
| | | return "否"; |
| | | } |
| | | return String.valueOf(value); |
| | | } |
| | | |
| | | private String normalizeExportText(String value) { |
| | | return value == null ? "" : value.trim(); |
| | | } |
| | | |
| | | } |