| | |
| | | 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.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.PageParam; |
| | | import com.vincent.rsf.server.manager.entity.Container; |
| | | import com.vincent.rsf.server.manager.service.ContainerService; |
| | | import com.vincent.rsf.server.manager.utils.buildPageRowsUtils; |
| | | 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 javax.servlet.http.HttpServletResponse; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Container, BaseParam> pageParam = new PageParam<>(baseParam, Container.class); |
| | | return R.ok().add(containerService.page(pageParam, pageParam.buildWrapper(true))); |
| | | PageParam<Container, BaseParam> page = containerService.page(pageParam, pageParam.buildWrapper(true)); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(page)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:list')") |
| | | @PostMapping("/container/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(containerService.list()); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(containerService.list())); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:list')") |
| | | @PostMapping({"/container/many/{ids}", "/containers/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(containerService.listByIds(Arrays.asList(ids))); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(containerService.listByIds(Arrays.asList(ids)))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:list')") |
| | | @GetMapping("/container/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(containerService.getById(id)); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(containerService.getById(id))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:save')") |
| | |
| | | @PostMapping("/container/save") |
| | | public R save(@RequestBody Container container) { |
| | | container.setCreateBy(getLoginUserId()); |
| | | container.setCreateTime(new Date()); |
| | | container.setUpdateBy(getLoginUserId()); |
| | | container.setUpdateTime(new Date()); |
| | | if (Objects.isNull(container.getType())) { |
| | | throw new CoolException("容器类型不能为空!!"); |
| | | } |
| | | if (Objects.isNull(container.getUsed())) { |
| | | throw new CoolException("容器使用次数不能为空!!"); |
| | | } |
| | | if (!containerService.save(container)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | | return R.ok("Save Success").add(container); |
| | | return R.ok("Save Success").add(buildPageRowsUtils.rowsMap(container)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:update')") |
| | |
| | | if (!containerService.updateById(container)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | return R.ok("Update Success").add(container); |
| | | return R.ok("Update Success").add(buildPageRowsUtils.rowsMap(container)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:remove')") |
| | | @OperationLog("Delete 库位信息表") |
| | | @PostMapping("/container/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | | List<Container> containers = containerService.list(new LambdaQueryWrapper<Container>().in(Container::getPanrentId, ids)); |
| | | if (containers.isEmpty()) { |
| | | throw new CoolException("当前容器有子容器绑定,不能执行删除操作!!"); |
| | | } |
| | | if (!containerService.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:container:list')") |
| | |
| | | containerService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | return R.ok().add(buildPageRowsUtils.rowsMap(vos)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:container:list')") |
| | | @PostMapping("/container/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(containerService.list(), Container.class), response); |
| | | List<Container> containers = new ArrayList<>(); |
| | | if (!Objects.isNull(map.get("ids"))) { |
| | | containers = containerService.list(new LambdaQueryWrapper<Container>().in(Container::getId, map.get("ids"))); |
| | | } else { |
| | | containers = containerService.list(); |
| | | } |
| | | ExcelUtil.build(ExcelUtil.create(buildPageRowsUtils.rowsMap(containers), Container.class), response); |
| | | } |
| | | |
| | | } |