| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.MatCode; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.entity.param.OpenApiStockOutParam; |
| | | import com.zy.asrs.entity.result.PakoutVo; |
| | | import com.zy.asrs.entity.result.StoPreTab; |
| | | import com.zy.asrs.service.LocDetlService; |
| | | import com.zy.asrs.service.MatCodeService; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.model.LocDetlDto; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by vincent on 2021/3/19 |
| | |
| | | @RequestMapping("/open/api") |
| | | public class OpenController { |
| | | |
| | | private boolean pickSite = false; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private MatCodeService matCodeService; |
| | | @Autowired |
| | | private WorkService workService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | @PostMapping("/stockOut/prew") |
| | | @Transactional |
| | |
| | | boolean error = false; |
| | | for (OpenApiStockOutParam param : params) { |
| | | Double sumAnfme = Optional.ofNullable(locDetlService.getSumAnfme(param.getMatnr())).orElse(0.0D); |
| | | double lack = 0.0D; |
| | | if (sumAnfme < param.getAnfme()) { |
| | | lack = param.getAnfme() - sumAnfme; |
| | | if (!error) { |
| | | error = true; |
| | | } |
| | | MatCode mat = matCodeService.selectById(param.getMatnr()); |
| | | // 视图对象 |
| | | StoPreTab tab = new StoPreTab(); |
| | | tab.setTitle(param.getMatnr() + (mat==null?"": "(" + mat.getMatName() + ")")); |
| | | tab.setMatnr(param.getMatnr()); |
| | | tab.setMaktx((mat==null?"": "(" + mat.getMatName() + ")")); |
| | | tab.setAnfme(param.getTotal()); |
| | | tab.setLocNo("缺货"); |
| | | tab.setTotal(lack); |
| | | tab.setReduce(lack); |
| | | tab.setRemQty(0.0D); |
| | | tab.setPrior(false); |
| | | tab.setPrior$("×"); |
| | | tab.setType(0); |
| | | result.add(tab); |
| | | |
| | | errorMsg.append(mat == null ? param.getMatnr() : mat.getMatName()).append("库存不足,缺货数量:").append(param.getAnfme() - sumAnfme).append("</br>"); |
| | | continue; |
| | | // continue; |
| | | } |
| | | List<LocDetl> locDetls = locDetlService.selectPakoutByRule(param.getMatnr()); |
| | | double issued = Optional.ofNullable(param.getAnfme()).orElse(0.0D) ; |
| | | double anfme = issued; |
| | | double issued = Optional.of(param.getAnfme() - lack).orElse(0.0D) ; |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | // 视图对象 |
| | |
| | | } |
| | | |
| | | } |
| | | if (error) { |
| | | return R.error().add(errorMsg.toString()); |
| | | } |
| | | return R.ok().add(result); |
| | | // if (error) { |
| | | // return R.error(errorMsg.toString()); |
| | | // } |
| | | return R.ok(errorMsg).add(result); |
| | | } |
| | | |
| | | @PostMapping("/stockOut") |
| | | @Transactional |
| | | public R stockOut(@RequestBody List<OpenApiStockOutParam> params){ |
| | | List<PakoutVo> result = new ArrayList<>(); |
| | | if (!Cools.isEmpty(params)) { |
| | | for (OpenApiStockOutParam param : params) { |
| | | // 推荐货位补仓工作档防重 |
| | | if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("packed", param.getAllotNo()).le("wrk_sts", 14)) > 0) { |
| | | throw new CoolException("当前补仓任务正在执行,请耐心等待"); |
| | | } |
| | | Double sumAnfme = Optional.ofNullable(locDetlService.getSumAnfme(param.getMatnr())).orElse(0.0D); |
| | | if (!Cools.isEmpty(param.getAllotNo()) && sumAnfme < param.getAnfme()) { |
| | | throw new CoolException("立库库存不足,缺货数量:" + (param.getAnfme() - sumAnfme)); |
| | | } |
| | | double lack = 0.0D; |
| | | if (sumAnfme < param.getAnfme()) { |
| | | throw new CoolException(param.getMatnr() + "物料数量不足,缺货数量:" + (param.getAnfme() - sumAnfme)); |
| | | lack = param.getAnfme() - sumAnfme; |
| | | PakoutVo pakoutVo = new PakoutVo(); |
| | | pakoutVo.setLocNo("缺货"); |
| | | pakoutVo.setAnfme(lack); |
| | | pakoutVo.setMatnr(param.getMatnr()); |
| | | // pakoutVo.setZpallet("param.getZpallet()"); |
| | | result.add(pakoutVo); |
| | | |
| | | // throw new CoolException(param.getMatnr() + "物料数量不足,缺货数量:" + (param.getAnfme() - sumAnfme)); |
| | | } |
| | | |
| | | List<LocDetl> locDetls = locDetlService.selectPakoutByRule(param.getMatnr()); |
| | | double issued = Optional.of(param.getAnfme()-lack).orElse(0.0D) ; |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | // 生成出库工作档 |
| | | |
| | | int priorCount = jdbcTemplate.queryForObject("select isnull(count(*),0) from man_prior where 1=1 and matnr = '" + param.getMatnr() + "'", Integer.class); |
| | | |
| | | // 全板 |
| | | if (issued>=locDetl.getAnfme()) { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(103); |
| | | List<LocDetlDto> detlDtos = new ArrayList<>(); |
| | | LocDetlDto dto = new LocDetlDto(); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setCount(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued); |
| | | detlDtos.add(dto); |
| | | workService.stockOut(staNo, detlDtos, 101, 9527L, param.getAllotNo(), Cools.isEmpty(param.getAllotNo()), null); |
| | | // 拣料 |
| | | } else { |
| | | |
| | | if (priorCount > 0) { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(103); |
| | | List<LocDetlDto> detlDtos = new ArrayList<>(); |
| | | LocDetlDto dto = new LocDetlDto(); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setCount(locDetl.getAnfme()); |
| | | detlDtos.add(dto); |
| | | workService.stockOut(staNo, detlDtos, 101, 9527L, param.getAllotNo(), Cools.isEmpty(param.getAllotNo()), locDetl.getAnfme()-issued); |
| | | } else { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(pickSite?113:109); |
| | | List<LocDetlDto> detlDtos = new ArrayList<>(); |
| | | LocDetlDto dto = new LocDetlDto(); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setCount(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued); |
| | | detlDtos.add(dto); |
| | | workService.stockOut(staNo, detlDtos, 103, 9527L, param.getAllotNo(), Cools.isEmpty(param.getAllotNo()), null); |
| | | } |
| | | |
| | | } |
| | | |
| | | PakoutVo pakoutVo = new PakoutVo(); |
| | | pakoutVo.setLocNo(locDetl.getLocNo()); |
| | | pakoutVo.setAnfme(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued); |
| | | pakoutVo.setMatnr(locDetl.getMatnr()); |
| | | pakoutVo.setZpallet(locDetl.getZpallet()); |
| | | result.add(pakoutVo); |
| | | |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | pickSite = !pickSite; |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | @PostMapping("/available/take/site") |
| | | @Transactional |
| | | public R availableTakeSite(){ |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | List<Integer> outSite = basDevpService.getAvailableOutSite(101); |
| | | for (Integer siteId : outSite) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("siteId", siteId); |
| | | map.put("desc", siteId + "(全板出库口)"); |
| | | result.add(map); |
| | | } |
| | | List<Integer> pickOutSite = basDevpService.getAvailableOutSite(103); |
| | | for (Integer siteId : pickOutSite) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("siteId", siteId); |
| | | map.put("desc", siteId + "(拣料出库口)"); |
| | | result.add(map); |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | @PostMapping("/get/asrsLocDetl") |
| | | @Transactional |
| | | public R queryLocDetl(String matnr) { |
| | | List<LocDetl> locDetls = locDetlService.getAsrsLocDetl(matnr); |
| | | return R.ok().add(locDetls); |
| | | } |
| | | |
| | | @PostMapping("/stockOut/locMode") |
| | | @Transactional |
| | | public R stockOutLocMode(@RequestBody List<OpenApiStockOutParam> params){ |
| | | List<PakoutVo> result = new ArrayList<>(); |
| | | if (!Cools.isEmpty(params)) { |
| | | for (OpenApiStockOutParam param : params) { |
| | | // 推荐货位补仓工作档防重 |
| | | if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("packed", param.getAllotNo()).le("wrk_sts", 14)) > 0) { |
| | | throw new CoolException("当前补仓任务正在执行,请耐心等待"); |
| | | } |
| | | Double sumAnfme = Optional.ofNullable(locDetlService.getSumAnfme(param.getMatnr())).orElse(0.0D); |
| | | if (!Cools.isEmpty(param.getAllotNo()) && sumAnfme < param.getAnfme()) { |
| | | throw new CoolException("立库库存不足,缺货数量:" + (param.getAnfme() - sumAnfme)); |
| | | } |
| | | double lack = 0.0D; |
| | | if (sumAnfme < param.getAnfme()) { |
| | | lack = param.getAnfme() - sumAnfme; |
| | | PakoutVo pakoutVo = new PakoutVo(); |
| | | pakoutVo.setLocNo("缺货"); |
| | | pakoutVo.setAnfme(lack); |
| | | pakoutVo.setMatnr(param.getMatnr()); |
| | | // pakoutVo.setZpallet("param.getZpallet()"); |
| | | result.add(pakoutVo); |
| | | |
| | | // throw new CoolException(param.getMatnr() + "物料数量不足,缺货数量:" + (param.getAnfme() - sumAnfme)); |
| | | } |
| | | |
| | | // 根据立库库位码去获取立库信息 |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", param.getLocNo())); |
| | | if (locDetls.size() == 0) { |
| | | throw new CoolException("未查询到库位信息!"); |
| | | } |
| | | double issued = Optional.of(param.getAnfme()-lack).orElse(0.0D) ; |
| | | for (LocDetl locDetl : locDetls) { |
| | | // 生成出库工作档 |
| | | |
| | | Integer locNoNum = locDetlService.countLocNoNum(locDetl.getLocNo()); |
| | | // 全板 |
| | | if (locNoNum == 1) { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(103); |
| | | List<LocDetlDto> detlDtos = new ArrayList<>(); |
| | | LocDetlDto dto = new LocDetlDto(); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setCount(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued); |
| | | detlDtos.add(dto); |
| | | workService.stockOut(staNo, detlDtos, 101, 9527L, param.getAllotNo(), Cools.isEmpty(param.getAllotNo()), null); |
| | | } else { // 拣料 |
| | | BasDevp staNo = basDevpService.checkSiteStatus(107); |
| | | List<LocDetlDto> detlDtos = new ArrayList<>(); |
| | | LocDetlDto dto = new LocDetlDto(); |
| | | dto.setLocDetl(locDetl); |
| | | dto.setCount(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued); |
| | | detlDtos.add(dto); |
| | | workService.stockOut(staNo, detlDtos, 103, 9527L, param.getAllotNo(), Cools.isEmpty(param.getAllotNo()), null); |
| | | } |
| | | PakoutVo pakoutVo = new PakoutVo(); |
| | | pakoutVo.setLocNo(locDetl.getLocNo()); |
| | | pakoutVo.setAnfme(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued); |
| | | pakoutVo.setMatnr(locDetl.getMatnr()); |
| | | pakoutVo.setZpallet(locDetl.getZpallet()); |
| | | result.add(pakoutVo); |
| | | |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | return R.ok(); |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | |
| | | } |