package com.vincent.rsf.server.manager.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.vincent.rsf.framework.common.Cools; import com.vincent.rsf.framework.common.R; 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.manager.entity.MatnrRestrictionWarehouse; import com.vincent.rsf.server.manager.service.MatnrRestrictionWarehouseService; import com.vincent.rsf.server.system.controller.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import jakarta.servlet.http.HttpServletResponse; import java.util.*; @RestController public class MatnrRestrictionWarehouseController extends BaseController { @Autowired private MatnrRestrictionWarehouseService matnrRestrictionWarehouseService; @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:list')") @PostMapping("/matnrRestrictionWarehouse/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, MatnrRestrictionWarehouse.class); return R.ok().add(matnrRestrictionWarehouseService.page(pageParam, pageParam.buildWrapper(true))); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:list')") @PostMapping("/matnrRestrictionWarehouse/list") public R list(@RequestBody Map map) { return R.ok().add(matnrRestrictionWarehouseService.list()); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:list')") @PostMapping({"/matnrRestrictionWarehouse/many/{ids}", "/matnrRestrictionWarehouses/many/{ids}"}) public R many(@PathVariable Long[] ids) { return R.ok().add(matnrRestrictionWarehouseService.listByIds(Arrays.asList(ids))); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:list')") @GetMapping("/matnrRestrictionWarehouse/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(matnrRestrictionWarehouseService.getById(id)); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:save')") @OperationLog("Create 物料限制") @PostMapping("/matnrRestrictionWarehouse/save") public R save(@RequestBody MatnrRestrictionWarehouse matnrRestrictionWarehouse) { matnrRestrictionWarehouse.setCreateBy(getLoginUserId()); matnrRestrictionWarehouse.setCreateTime(new Date()); matnrRestrictionWarehouse.setUpdateBy(getLoginUserId()); matnrRestrictionWarehouse.setUpdateTime(new Date()); if (!matnrRestrictionWarehouseService.save(matnrRestrictionWarehouse)) { return R.error("Save Fail"); } return R.ok("Save Success").add(matnrRestrictionWarehouse); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:update')") @OperationLog("Update 物料限制") @PostMapping("/matnrRestrictionWarehouse/update") public R update(@RequestBody MatnrRestrictionWarehouse matnrRestrictionWarehouse) { matnrRestrictionWarehouse.setUpdateBy(getLoginUserId()); matnrRestrictionWarehouse.setUpdateTime(new Date()); if (!matnrRestrictionWarehouseService.updateById(matnrRestrictionWarehouse)) { return R.error("Update Fail"); } return R.ok("Update Success").add(matnrRestrictionWarehouse); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:remove')") @OperationLog("Delete 物料限制") @PostMapping("/matnrRestrictionWarehouse/remove/{ids}") public R remove(@PathVariable Long[] ids) { if (!matnrRestrictionWarehouseService.removeByIds(Arrays.asList(ids))) { return R.error("Delete Fail"); } return R.ok("Delete Success").add(ids); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:list')") @PostMapping("/matnrRestrictionWarehouse/query") public R query(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(MatnrRestrictionWarehouse::getId, condition); } matnrRestrictionWarehouseService.page(new Page<>(1, 30), wrapper).getRecords().forEach( item -> vos.add(new KeyValVo(item.getId(), item.getId())) ); return R.ok().add(vos); } @PreAuthorize("hasAuthority('manager:matnrRestrictionWarehouse:list')") @PostMapping("/matnrRestrictionWarehouse/export") public void export(@RequestBody Map map, HttpServletResponse response) throws Exception { ExcelUtil.build(ExcelUtil.create(matnrRestrictionWarehouseService.list(), MatnrRestrictionWarehouse.class), response); } }