| package com.zy.asrs.wcs.core.controller; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.zy.asrs.framework.common.Cools; | 
| import com.zy.asrs.framework.common.R; | 
| import com.zy.asrs.wcs.common.annotation.OperationLog; | 
| import com.zy.asrs.wcs.common.domain.BaseParam; | 
| import com.zy.asrs.wcs.common.domain.KeyValVo; | 
| import com.zy.asrs.wcs.common.domain.PageParam; | 
| import com.zy.asrs.wcs.core.entity.Loc; | 
| import com.zy.asrs.wcs.core.service.LocService; | 
| import com.zy.asrs.wcs.system.controller.BaseController; | 
| import com.zy.asrs.wcs.utils.ExcelUtil; | 
| 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 java.util.ArrayList; | 
| import java.util.Arrays; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| @RestController | 
| @RequestMapping("/api") | 
| public class LocController extends BaseController { | 
|   | 
|     @Autowired | 
|     private LocService locService; | 
|   | 
|     @PreAuthorize("hasAuthority('core: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); | 
|         QueryWrapper<Loc> wrapper = new QueryWrapper<>(); | 
|         if (!Cools.isEmpty(baseParam.getCondition())) { | 
|             wrapper.like("loc_no", baseParam.getCondition()); | 
|         } | 
|         return R.ok().add(locService.page(pageParam, wrapper)); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:list')") | 
|     @PostMapping("/loc/list") | 
|     public R list(@RequestBody Map<String, Object> map) { | 
|         return R.ok().add(locService.list()); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:list')") | 
|     @GetMapping("/loc/{id}") | 
|     public R get(@PathVariable("id") Long id) { | 
|         return R.ok().add(locService.getById(id)); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:save')") | 
|     @OperationLog("添加库位") | 
|     @PostMapping("/loc/save") | 
|     public R save(@RequestBody Loc loc) { | 
|         if (!locService.save(loc)) { | 
|             return R.error("添加失败"); | 
|         } | 
|         return R.ok("添加成功"); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:update')") | 
|     @OperationLog("修改库位") | 
|     @PostMapping("/loc/update") | 
|     public R update(@RequestBody Loc loc) { | 
|         if (!locService.updateById(loc)) { | 
|             return R.error("修改失败"); | 
|         } | 
|         return R.ok("修改成功"); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:remove')") | 
|     @OperationLog("删除库位") | 
|     @PostMapping("/loc/remove/{ids}") | 
|     public R remove(@PathVariable Long[] ids) { | 
|         if (!locService.removeByIds(Arrays.asList(ids))) { | 
|             return R.error("删除失败"); | 
|         } | 
|         return R.ok("删除成功"); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:list')") | 
|     @PostMapping("/loc/query") | 
|     public R query(@RequestParam(required = false) String condition) { | 
|         List<KeyValVo> vos = new ArrayList<>(); | 
|         LambdaQueryWrapper<Loc> wrapper = new LambdaQueryWrapper<>(); | 
|         if (!Cools.isEmpty(condition)) { | 
|             wrapper.like(Loc::getLocNo, condition); | 
|         } | 
|         locService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
|                 item -> vos.add(new KeyValVo(item.getId(), item.getLocNo())) | 
|         ); | 
|         return R.ok().add(vos); | 
|     } | 
|   | 
|     @PreAuthorize("hasAuthority('core:loc:list')") | 
|     @PostMapping("/loc/export") | 
|     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
|         ExcelUtil.build(ExcelUtil.create(locService.list(), Loc.class), response); | 
|     } | 
|   | 
| } |