| | |
| | | package com.zy.asrs.wms.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | 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.wms.asrs.entity.*; |
| | | import com.zy.asrs.wms.asrs.entity.enums.LocStsType; |
| | | import com.zy.asrs.wms.asrs.mapper.LocDetlMapper; |
| | | import com.zy.asrs.wms.asrs.service.LocDetlFieldService; |
| | | import com.zy.asrs.wms.asrs.service.LocService; |
| | | import com.zy.asrs.wms.asrs.service.MatFieldService; |
| | | import com.zy.asrs.wms.common.annotation.OperationLog; |
| | | import com.zy.asrs.wms.common.domain.BaseParam; |
| | | import com.zy.asrs.wms.common.domain.KeyValVo; |
| | | import com.zy.asrs.wms.common.domain.PageParam; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.service.LocDetlService; |
| | | import com.zy.asrs.wms.system.controller.BaseController; |
| | | import com.zy.asrs.wms.utils.ExcelUtil; |
| | |
| | | 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; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class LocDetlController extends BaseController { |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private MatFieldService matFieldService; |
| | | @Autowired |
| | | private LocDetlFieldService locDetlFieldService; |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @PostMapping("/locDetl/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<LocDetl, BaseParam> pageParam = new PageParam<>(baseParam, LocDetl.class); |
| | | return R.ok().add(locDetlService.page(pageParam, pageParam.buildWrapper(true))); |
| | | PageParam<ViewLocDetl, BaseParam> pageParam = new PageParam<>(baseParam, ViewLocDetl.class); |
| | | PageParam<ViewLocDetl, BaseParam> data = locDetlService.getPage(pageParam, pageParam.buildWrapper(true)); |
| | | return R.ok().add(data); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @PostMapping("/locDetl/outPage") |
| | | public R outPage(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<ViewLocDetl, BaseParam> pageParam = new PageParam<>(baseParam, ViewLocDetl.class); |
| | | |
| | | QueryWrapper<ViewLocDetl> queryWrapper = pageParam.buildWrapper(true); |
| | | List<Long> locIds = locService.listBySts(LocStsType.F.val()); |
| | | if (locIds.isEmpty()) { |
| | | locIds.add(-1L); |
| | | } |
| | | queryWrapper.in("loc_id", locIds); |
| | | PageParam<ViewLocDetl, BaseParam> data = locDetlService.getPage(pageParam, queryWrapper); |
| | | return R.ok().add(data); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @PostMapping("/locDetl/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(locDetlService.list()); |
| | | List<LocDetl> list = locDetlService.getLocDetlList(map); |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @PostMapping("/locDetl/listByIds") |
| | | public R listByIds(@RequestBody List<Long> ids) { |
| | | List<LocDetl> list = locDetlService.listByIds(ids); |
| | | List<LocDetl> locDetls = locDetlService.parseLocDetl(list); |
| | | return R.ok().add(locDetls); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @GetMapping("/locDetl/locId/{locId}") |
| | | public R list(@PathVariable("locId") Long locId) { |
| | | List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, locId)); |
| | | List<LocDetl> locDetls = locDetlService.parseLocDetl(list); |
| | | return R.ok().add(locDetls); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @GetMapping("/locDetl/locNo/{locNo}") |
| | | public R list(@PathVariable("locNo") String locNo) { |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, locNo)); |
| | | if (loc == null) { |
| | | return R.error("库位不存在"); |
| | | } |
| | | List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, loc.getId())); |
| | | List<LocDetl> locDetls = locDetlService.parseLocDetl(list); |
| | | return R.ok().add(locDetls); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:save')") |
| | | @OperationLog("批量插入库存明细") |
| | | @PostMapping("/locDetl/batchAdd") |
| | | public R save(@RequestBody List<LocDetl> locDetls) { |
| | | |
| | | return R.ok().add(locDetls); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:save')") |
| | | @OperationLog("添加库存明细") |
| | | @PostMapping("/locDetl/save") |
| | | public R save(@RequestBody LocDetl locDetl) { |
| | | if (!locDetlService.save(locDetl)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | |
| | | //插入库存明细字段 |
| | | List<MatField> matFields = matFieldService.list(new LambdaQueryWrapper<MatField>().eq(MatField::getUnique, 1)); |
| | | for (MatField matField : matFields) { |
| | | LocDetlField locDetlField = new LocDetlField(); |
| | | locDetlField.setDetlId(locDetl.getId()); |
| | | locDetlField.setFieldId(matField.getId()); |
| | | locDetlField.setName(matField.getName()); |
| | | locDetlFieldService.save(locDetlField); |
| | | } |
| | | |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:update')") |
| | | @OperationLog("修改库存明细") |
| | | @PostMapping("/locDetl/update") |
| | | public R update(@RequestBody LocDetl locDetl) { |
| | | public R update(@RequestBody HashMap<String,Object> param) { |
| | | LocDetl locDetl = JSON.parseObject(JSON.toJSONString(param), LocDetl.class, Feature.DisableCircularReferenceDetect); |
| | | //设置扩展字段 |
| | | setLocDetlField(param, locDetl); |
| | | |
| | | if (!locDetlService.updateById(locDetl)) { |
| | | return R.error("修改失败"); |
| | | } |
| | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @PostMapping("/locDetl/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(locDetlService.list(), LocDetl.class), response); |
| | | List<LocDetl> locDetls = locDetlService.parseLocDetl(locDetlService.list()); |
| | | List<MatField> locFields = matFieldService.getLocFields(); |
| | | ExcelUtil.build(ExcelUtil.create(locDetls, LocDetl.class, locFields), response); |
| | | } |
| | | |
| | | private void setLocDetlField(HashMap<String, Object> param, LocDetl locDetl) { |
| | | //获取扩展字段 |
| | | List<MatField> matFields = matFieldService.list(new LambdaQueryWrapper<MatField>().eq(MatField::getFieldType, 1)); |
| | | for (MatField matField : matFields) { |
| | | if (param.containsKey(matField.getName())) { |
| | | LocDetlField fieldValue = locDetlFieldService.getOne(new LambdaQueryWrapper<LocDetlField>() |
| | | .eq(LocDetlField::getDetlId, locDetl.getId()) |
| | | .eq(LocDetlField::getFieldId, matField.getId())); |
| | | if (fieldValue == null) { |
| | | fieldValue = new LocDetlField(); |
| | | fieldValue.setDetlId(locDetl.getId()); |
| | | fieldValue.setFieldId(matField.getId()); |
| | | fieldValue.setName(matField.getName()); |
| | | fieldValue.setValue(param.get(matField.getName()).toString()); |
| | | locDetlFieldService.save(fieldValue); |
| | | }else { |
| | | fieldValue.setValue(param.get(matField.getName()).toString()); |
| | | locDetlFieldService.updateById(fieldValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |