| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.Pla; |
| | | import com.zy.asrs.entity.PlaQty; |
| | | import com.zy.asrs.entity.param.GlobleParameter; |
| | | import com.zy.asrs.mapper.PlaMapper; |
| | | import com.zy.asrs.service.PlaQtyService; |
| | | import com.zy.asrs.service.PlaService; |
| | | import com.zy.asrs.utils.SaasUtils; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.system.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service("plaService") |
| | | public class PlaServiceImpl extends ServiceImpl<PlaMapper, Pla> implements PlaService { |
| | | @Autowired |
| | | private PlaQtyService plaQtyService; |
| | | |
| | | public Pla selectByBatchAndPackageNo(String batch, Integer packageNo, String brand) { |
| | | return this.selectOne(new EntityWrapper<Pla>().eq("batch",batch).eq("package_no",packageNo).eq("brand",brand).eq(false,"status","全部出库")); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void queryStock(OrderDetl orderDetl, List<PlaQty> plaQties) { |
| | | |
| | | //筛选条件 批号、包好、熔点、熔指、黄度、不透明度 |
| | | Wrapper<Pla> wrapper = new EntityWrapper<Pla>(); |
| | | if(!Cools.isEmpty(orderDetl.getBatch())){ |
| | | wrapper.eq("batch",orderDetl.getBatch()); |
| | | } |
| | | if(!Cools.isEmpty(orderDetl.getBrand())){ |
| | | wrapper.eq("package_no",orderDetl.getBrand()); |
| | | } |
| | | wrapper.eq("status", GlobleParameter.PLA_STATUS_1); |
| | | wrapper.ge("finger_melting", orderDetl.getFingerMeltingMin()).le("finger_melting", orderDetl.getFingerMeltingMax()); |
| | | wrapper.ge("fusing_point", orderDetl.getFusingPointMin()).le("fusing_point", orderDetl.getFusingPointMax()); |
| | | wrapper.ge("yellowness", orderDetl.getYellownessMin()).le("yellowness", orderDetl.getYellownessMax()); |
| | | wrapper.ge("opacity", orderDetl.getOpacityMin()).le("opacity", orderDetl.getOpacityMax()); |
| | | wrapper.orderBy("pakin_time"); |
| | | |
| | | List<Pla> plas = this.selectList(wrapper); |
| | | //总共的出库的数量(总计出库数量-作业数量) |
| | | if(Cools.isEmpty(orderDetl.getWorkQty())){ |
| | | orderDetl.setWorkQty(0.0); |
| | | } |
| | | Double anfme = orderDetl.getAnfme() - orderDetl.getWorkQty(); |
| | | |
| | | for (Pla pla : plas){ |
| | | //库存数量(剩余重量-库存作业数量) |
| | | Double weightAnfme = pla.getWeightAnfme() - pla.getQtyAnfme(); |
| | | if(weightAnfme <= 0){ |
| | | continue; |
| | | } |
| | | //需要减去此次出库预览其他订单需出库的数量 |
| | | for (PlaQty plaQty : plaQties){ |
| | | if(Cools.eq(plaQty.getBatch(),pla.getBatch()) && plaQty.getPackageNo() == pla.getPackageNo()){ |
| | | weightAnfme -= plaQty.getQtyAnfme(); |
| | | } |
| | | } |
| | | |
| | | if(weightAnfme > anfme){ |
| | | //如果该批次包号剩余重量大于订单明细数量,则返回plaQties |
| | | PlaQty plaQty = new PlaQty(pla.getBatch(),pla.getPackageNo(),orderDetl.getId(),orderDetl.getOrderId(),orderDetl.getOrderNo(),anfme,pla.getLocNo(),new Date()); |
| | | anfme = 0.0; |
| | | plaQties.add(plaQty); |
| | | break; |
| | | }else { |
| | | PlaQty plaQty = new PlaQty(pla.getBatch(),pla.getPackageNo(),orderDetl.getId(),orderDetl.getOrderId(),orderDetl.getOrderNo(),weightAnfme,pla.getLocNo(),new Date()); |
| | | anfme -= weightAnfme; |
| | | plaQties.add(plaQty); |
| | | } |
| | | } |
| | | |
| | | if(anfme > 0){ |
| | | PlaQty plaQty = new PlaQty(orderDetl.getBatch(),Integer.parseInt(orderDetl.getBrand()),orderDetl.getId(),orderDetl.getOrderId(),orderDetl.getOrderNo(),anfme,null,new Date()); |
| | | plaQties.add(plaQty); |
| | | } |
| | | |
| | | } |
| | | |
| | | //退回 |
| | | @Transactional |
| | | public void returned(List<PlaQty> plaQties, User user) { |
| | | plaQties.forEach(plaQty -> { |
| | | PlaQty plaQtyOut = plaQtyService.selectById(plaQty.getId()); |
| | | if(Cools.isEmpty(plaQtyOut.getReturned()) || plaQtyOut.getReturned() == 0){ |
| | | plaQtyOut.setReturned(plaQty.getOrderWeight()); |
| | | }else { |
| | | throw new CoolException("该包物料已退回"); |
| | | //plaQtyOut.setReturned(plaQty.getOrderWeight()+plaQtyOut.getReturned()); |
| | | } |
| | | plaQtyService.updateById(plaQtyOut); |
| | | |
| | | PlaQty plaQtyReturned = new PlaQty(); |
| | | plaQtyReturned.setBatch(plaQtyOut.getBatch()); |
| | | plaQtyReturned.setPackageNo(plaQtyOut.getPackageNo()); |
| | | plaQtyReturned.setCreateTime(new Date()); |
| | | plaQtyReturned.setLocNo(plaQtyOut.getLocNo()); |
| | | plaQtyReturned.setOrderNo(plaQtyOut.getOrderNo()); |
| | | plaQtyReturned.setPakoutTime(Utils.getDateStr(new Date())); |
| | | plaQtyReturned.setBrand(plaQty.getBrand()); |
| | | plaQtyReturned.setOrderWeight(plaQty.getOrderWeight()); |
| | | plaQtyReturned.setTransfer("退回入库"); |
| | | plaQtyReturned.setHandlerBy(user.getUsername()); |
| | | plaQtyReturned.setCustomer(plaQtyOut.getCustomer()); |
| | | plaQtyReturned.setMemo(plaQty.getMemo()); |
| | | plaQtyService.insert(plaQtyReturned); |
| | | |
| | | //直接更新pla的库存 |
| | | Pla pla = this.selectByBatchAndPackageNo(plaQty.getBatch(), plaQty.getPackageNo(),plaQty.getBrand()); |
| | | //pla.setStatus(GlobleParameter.PLA_STATUS_0); |
| | | pla.setModifyTime(new Date()); |
| | | |
| | | pla.setWeightAnfme(pla.getWeightAnfme() + plaQty.getOrderWeight()); |
| | | pla.setStatus(GlobleParameter.PLA_STATUS_1); |
| | | this.updateById(pla); |
| | | |
| | | SaasUtils.insertLog(0,pla.getLocNo(),pla.getBrand(),plaQty.getOrderWeight(),user.getUsername(), |
| | | null,pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop(),null); |
| | | |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void viladate(List<Pla> plas, User user) { |
| | | plas.forEach(pla -> { |
| | | if(!pla.getStatus().equals(GlobleParameter.PLA_STATUS_00)){ |
| | | throw new CoolException("选中的数据不是暂入库状态,请核对状态"); |
| | | } |
| | | pla = this.selectById(pla.getId()); |
| | | pla.setModifyTime(new Date()); |
| | | pla.setStatus(GlobleParameter.PLA_STATUS_0); |
| | | this.updateById(pla); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public List<Pla> selectToHistory() { |
| | | return this.selectList(new EntityWrapper<Pla>().eq("status",GlobleParameter.PLA_STATUS_4)); |
| | | } |
| | | |
| | | @Override |
| | | public Page<Pla> getStockStatisAll(Page<Pla> page) { |
| | | |
| | | List<Pla> plaList; |
| | | Date stime = null; |
| | | Date etime = null; |
| | | Object create_time = page.getCondition().get("create_time"); |
| | | Object brand = page.getCondition().get("brand"); |
| | | Object status = page.getCondition().get("status"); |
| | | String createTime = create_time == null ? null : create_time.toString(); |
| | | if(!Cools.isEmpty(createTime)){ |
| | | String[] dates = createTime.split(" - "); |
| | | stime = DateUtils.convert(dates[0]); |
| | | etime = DateUtils.convert(dates[1]); |
| | | } |
| | | plaList=baseMapper.getStockStatisAll(brand == null ? null:brand.toString(), status == null ? null:status.toString(), stime,etime); |
| | | |
| | | double weightSum = plaList.stream().mapToDouble(Pla::getWeight).sum(); |
| | | |
| | | // 最后一条记录仅供合计重量信息展示 |
| | | Pla pla = new Pla(); |
| | | pla.setBrand("合计"); |
| | | pla.setMatnr(""); |
| | | pla.setWeight(weightSum); |
| | | plaList.add(pla); |
| | | |
| | | page.setRecords(plaList); |
| | | page.setTotal(0); |
| | | return page; |
| | | } |
| | | } |