| | |
| | | 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.ListExportHandler; |
| | | import com.vincent.rsf.server.common.service.ListExportService; |
| | | import com.vincent.rsf.server.manager.entity.StockStatistic; |
| | | import com.vincent.rsf.server.manager.enums.TaskStsType; |
| | | import com.vincent.rsf.server.manager.enums.TaskType; |
| | | import com.vincent.rsf.server.manager.service.StockStatisticService; |
| | | import com.vincent.rsf.server.manager.utils.buildPageRowsUtils; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | 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.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | |
| | | @RestController |
| | | public class StockStatisticController extends BaseController { |
| | | |
| | | @Autowired |
| | | private StockStatisticService stockStatisticService; |
| | | @Autowired |
| | | private ListExportService listExportService; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/stockStatistic/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | return R.ok().add(stockStatisticService.page(pageParam, pageParam.buildWrapper(true))); |
| | | PageParam<StockStatistic, BaseParam> page = stockStatisticService.page(pageParam, pageParam.buildWrapper(true)); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | |
| | | public R outStatisticPage(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("id, loc_code, day_time, task_type, task_status, barcode, maktx, matnr_code, batch, SUM(anfme) AS anfme, unit, fields_index, create_time, update_time"); |
| | | wrapper.groupBy("matnr_code, day_time"); |
| | | return R.ok().add(stockStatisticService.page(pageParam, wrapper)); |
| | | QueryWrapper<StockStatistic> wrapper = buildStatisticSummaryWrapper(pageParam); |
| | | PageParam<StockStatistic, BaseParam> page = stockStatisticService.page(pageParam, wrapper); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | |
| | | public R inStatisticPage(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("id, loc_code, day_time, task_type, task_status, barcode, maktx, matnr_code, batch, SUM(anfme) AS anfme, unit, fields_index, create_time, update_time"); |
| | | wrapper.groupBy("matnr_code, day_time"); |
| | | return R.ok().add(stockStatisticService.page(pageParam, wrapper)); |
| | | QueryWrapper<StockStatistic> wrapper = buildStatisticSummaryWrapper(pageParam); |
| | | PageParam<StockStatistic, BaseParam> page = stockStatisticService.page(pageParam, wrapper); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | |
| | | public R inStockItemPage(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("id, loc_code, day_time, task_type, task_status, barcode, maktx, matnr_code, batch, SUM(anfme) anfme, unit, fields_index, create_by, update_by, create_time, update_time"); |
| | | wrapper.groupBy("matnr_code, day_time, task_type, task_status"); |
| | | return R.ok().add(stockStatisticService.page(pageParam, wrapper)); |
| | | QueryWrapper<StockStatistic> wrapper = buildStatisticItemWrapper(pageParam); |
| | | PageParam<StockStatistic, BaseParam> page = stockStatisticService.page(pageParam, wrapper); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | |
| | | public R outStockItemPage(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("id, loc_code, day_time, task_type, task_status, barcode, maktx, matnr_code, batch, SUM(anfme) anfme, unit, fields_index, create_by, update_by, create_time, update_time"); |
| | | wrapper.groupBy("matnr_code, day_time, task_type, task_status"); |
| | | return R.ok().add(stockStatisticService.page(pageParam, wrapper)); |
| | | QueryWrapper<StockStatistic> wrapper = buildStatisticItemWrapper(pageParam); |
| | | PageParam<StockStatistic, BaseParam> page = stockStatisticService.page(pageParam, wrapper); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | |
| | | public R statisticNumPage(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("id, day_time, COUNT( barcode ) `count`, " + |
| | | "SUM( anfme ) anfme," + |
| | | "COUNT(IF (task_type = 1, 0, NULL)) in_anfme_count, " + |
| | | "COUNT(IF ( task_type = 101, 0, NULL)) out_anfme_count, " + |
| | | "SUM( CASE WHEN task_type = 1 THEN anfme ELSE 0 END ) in_anfme," + |
| | | "SUM( CASE WHEN task_type = 101 THEN anfme ELSE 0 END ) out_anfme"); |
| | | wrapper.in("task_type", Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type)).groupBy("day_time"); |
| | | return R.ok().add(stockStatisticService.page(pageParam, wrapper)); |
| | | QueryWrapper<StockStatistic> wrapper = buildStatisticNumWrapper(pageParam); |
| | | PageParam<StockStatistic, BaseParam> page = stockStatisticService.page(pageParam, wrapper); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/stockStatistic/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(stockStatisticService.list()); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.list())); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping({"/stockStatistic/many/{ids}", "/stockStatistics/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(stockStatisticService.listByIds(Arrays.asList(ids))); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/outStatistic/many/{ids}") |
| | | public R outStatisticMany(@PathVariable Long[] ids) { |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/inStatistic/many/{ids}") |
| | | public R inStatisticMany(@PathVariable Long[] ids) { |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/inStatisticItem/many/{ids}") |
| | | public R inStatisticItemMany(@PathVariable Long[] ids) { |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/outStatisticItem/many/{ids}") |
| | | public R outStatisticItemMany(@PathVariable Long[] ids) { |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/statistic/num/many/{ids}") |
| | | public R statisticNumMany(@PathVariable Long[] ids) { |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @GetMapping("/stockStatistic/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(stockStatisticService.getById(id)); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(stockStatisticService.getById(id))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:save')") |
| | |
| | | if (!stockStatisticService.save(stockStatistic)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | | return R.ok("Save Success").add(stockStatistic); |
| | | return R.ok("Save Success").add(buildPageRowsUtils.rowsMap(stockStatistic)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:update')") |
| | |
| | | if (!stockStatisticService.updateById(stockStatistic)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | return R.ok("Update Success").add(stockStatistic); |
| | | return R.ok("Update Success").add(buildPageRowsUtils.rowsMap(stockStatistic)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:remove')") |
| | |
| | | if (!stockStatisticService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("Delete Fail"); |
| | | } |
| | | return R.ok("Delete Success").add(ids); |
| | | return R.ok("Delete Success").add(buildPageRowsUtils.rowsMap(ids)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | |
| | | stockStatisticService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getId())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(vos)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/stockStatistic/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(stockStatisticService.list(), StockStatistic.class), response); |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | createStockStatisticExportHandler("日库存统计报表", pageParam -> pageParam.buildWrapper(true)), |
| | | response |
| | | ); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/inStatistic/export") |
| | | public void inStatisticExport(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | createStockStatisticExportHandler("日入库汇总查询", this::buildStatisticSummaryWrapper), |
| | | response |
| | | ); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/outStatistic/export") |
| | | public void outStatisticExport(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | createStockStatisticExportHandler("日出库汇总查询", this::buildStatisticSummaryWrapper), |
| | | response |
| | | ); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/inStatisticItem/export") |
| | | public void inStatisticItemExport(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | createStockStatisticExportHandler("日入库明细查询", this::buildStatisticItemWrapper), |
| | | response |
| | | ); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/outStatisticItem/export") |
| | | public void outStatisticItemExport(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | createStockStatisticExportHandler("日出库明细查询", this::buildStatisticItemWrapper), |
| | | response |
| | | ); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:stockStatistic:list')") |
| | | @PostMapping("/statistic/num/export") |
| | | public void statisticNumExport(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | listExportService.export( |
| | | map, |
| | | exportMap -> buildParam(exportMap, BaseParam.class), |
| | | createStockStatisticExportHandler("日出入库汇总统计", this::buildStatisticNumWrapper), |
| | | response |
| | | ); |
| | | } |
| | | |
| | | private QueryWrapper<StockStatistic> buildStatisticSummaryWrapper(PageParam<StockStatistic, BaseParam> pageParam) { |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("MIN(id) AS id, day_time, task_type, task_status, " + |
| | | "MAX(maktx) AS maktx, matnr_code, MAX(batch) AS batch, " + |
| | | "SUM(anfme) AS anfme, MAX(unit) AS unit"); |
| | | wrapper.groupBy("day_time, task_type, task_status, matnr_code"); |
| | | return wrapper; |
| | | } |
| | | |
| | | private QueryWrapper<StockStatistic> buildStatisticItemWrapper(PageParam<StockStatistic, BaseParam> pageParam) { |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("MIN(id) AS id, loc_code, day_time, task_type, task_status, barcode, " + |
| | | "MAX(maktx) AS maktx, matnr_code, MAX(batch) AS batch, SUM(anfme) AS anfme, " + |
| | | "MAX(unit) AS unit, create_by, update_by, create_time, update_time"); |
| | | wrapper.groupBy("loc_code, day_time, task_type, task_status, barcode, matnr_code, create_by, update_by, create_time, update_time"); |
| | | return wrapper; |
| | | } |
| | | |
| | | private QueryWrapper<StockStatistic> buildStatisticNumWrapper(PageParam<StockStatistic, BaseParam> pageParam) { |
| | | QueryWrapper<StockStatistic> wrapper = pageParam.buildWrapper(true); |
| | | wrapper.select("MIN(id) AS id, day_time, COUNT(barcode) AS `count`, " + |
| | | "SUM( anfme ) anfme," + |
| | | "COUNT(IF (task_type = 1, 0, NULL)) in_anfme_count, " + |
| | | "COUNT(IF ( task_type = 101, 0, NULL)) out_anfme_count, " + |
| | | "SUM( CASE WHEN task_type = 1 THEN anfme ELSE 0 END ) in_anfme," + |
| | | "SUM( CASE WHEN task_type = 101 THEN anfme ELSE 0 END ) out_anfme"); |
| | | wrapper.in("task_type", Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type)).groupBy("day_time"); |
| | | return wrapper; |
| | | } |
| | | |
| | | private ListExportHandler<StockStatistic, BaseParam> createStockStatisticExportHandler( |
| | | String reportTitle, |
| | | Function<PageParam<StockStatistic, BaseParam>, QueryWrapper<StockStatistic>> wrapperBuilder |
| | | ) { |
| | | return new ListExportHandler<>() { |
| | | @Override |
| | | public List<StockStatistic> listByIds(List<Long> ids) { |
| | | return stockStatisticService.listByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<StockStatistic> listByFilter(Map<String, Object> sanitizedMap, BaseParam baseParam) { |
| | | PageParam<StockStatistic, BaseParam> pageParam = new PageParam<>(baseParam, StockStatistic.class); |
| | | return stockStatisticService.list(wrapperBuilder.apply(pageParam)); |
| | | } |
| | | |
| | | @Override |
| | | public void fillExportFields(List<StockStatistic> records) { |
| | | buildPageRowsUtils.rowsMap(records); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> toExportRow(StockStatistic record, List<ExcelUtil.ExportColumn> columns) { |
| | | return buildStockStatisticExportRow(record, columns); |
| | | } |
| | | |
| | | @Override |
| | | public String defaultReportTitle() { |
| | | return reportTitle; |
| | | } |
| | | }; |
| | | } |
| | | |
| | | private Map<String, Object> buildStockStatisticExportRow(StockStatistic record, List<ExcelUtil.ExportColumn> columns) { |
| | | BeanWrapper beanWrapper = new BeanWrapperImpl(record); |
| | | Map<String, Object> row = new LinkedHashMap<>(); |
| | | row.put("dayTimeText", record.getDayTime()); |
| | | row.put("taskTypeText", record.getTaskType$()); |
| | | row.put("taskStatusText", getTaskStatusText(record.getTaskStatus())); |
| | | row.put("locCode", record.getLocCode()); |
| | | row.put("barcode", record.getBarcode()); |
| | | row.put("matnrCode", record.getMatnrCode()); |
| | | row.put("maktx", record.getMaktx()); |
| | | row.put("batch", record.getBatch()); |
| | | row.put("unit", record.getUnit()); |
| | | row.put("anfme", record.getAnfme()); |
| | | row.put("createByText", record.getCreateBy$()); |
| | | row.put("createTimeText", record.getCreateTime$()); |
| | | row.put("updateByText", record.getUpdateBy$()); |
| | | 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 getTaskStatusText(Integer taskStatus) { |
| | | if (taskStatus == null) { |
| | | return ""; |
| | | } |
| | | for (TaskStsType type : TaskStsType.values()) { |
| | | if (Objects.equals(type.id, taskStatus)) { |
| | | return type.desc; |
| | | } |
| | | } |
| | | return String.valueOf(taskStatus); |
| | | } |
| | | |
| | | } |