| | |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder) { |
| | | public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing) { |
| | | insOrder.setState(0); |
| | | String code = customMapper.selectById(insOrder.getCompanyId()).getCode2(); |
| | | insOrder.setEntrustCode(giveCode.giveCode("JCZX-" + code + "-", "ins_order", "-", "yyyyMMdd")); |
| | | insOrderMapper.insert(insOrder); |
| | | AtomicInteger count = new AtomicInteger(); |
| | | list.forEach(a -> { |
| | | count.getAndIncrement(); |
| | | a.setId(null); |
| | | a.setInsOrderId(insOrder.getId()); |
| | | if (StrUtil.isEmpty(a.getSampleCode())) { |
| | | a.setSampleCode(giveCode.giveCode("", "ins_sample", "", "yyMMdd")); |
| | | a.setSampleCode(giveCode.giveCode("", "ins_sample", "", "yyMMdd")+"-"+count.get()); |
| | | } |
| | | insSampleMapper.insert(a); |
| | | if (ObjectUtil.isNotEmpty(a.getInsProduct())) { |
| | | addInsProductMethod(a.getId(), a.getInsProduct(), null, 0); |
| | | } |
| | | if(ObjectUtil.isNotEmpty(a.getChildSampleList())){ |
| | | for (SampleProductDto b : a.getChildSampleList()) { |
| | | for (int i = 0; i < b.getNum(); i++) { |
| | | b.setId(null); |
| | | b.setInsOrderId(insOrder.getId()); |
| | | b.setParentId(a.getId()); |
| | | if (StrUtil.isEmpty(b.getSampleCode())) { |
| | | b.setSampleCode(giveCode.giveCode("", "ins_sample", "", "yyMMdd")); |
| | | } |
| | | insSampleMapper.insert(b); |
| | | if (ObjectUtil.isNotEmpty(b.getInsProduct())) { |
| | | addInsProductMethod(b.getId(), b.getInsProduct(), null, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(a.getBushing())) { |
| | | for (BushingDto bushingDto : a.getBushing()) { |
| | |
| | | } |
| | | } |
| | | }); |
| | | for (List<Integer> i : pairing) { |
| | | SampleProductDto sample = JSON.parseObject(JSON.toJSONString(list.get(i.get(0))), SampleProductDto.class); |
| | | sample.setSampleCode(list.get(i.get(0)-1).getSampleCode() + "/" +list.get(i.get(1)-1).getSampleCode()); |
| | | sample.setId(null); |
| | | insSampleMapper.insert(sample); |
| | | InsProduct insProduct = sample.getInsProduct().stream().filter(a -> Objects.equals(a.getInspectionItem(), "熔接损耗")).findFirst().get(); |
| | | insProduct.setId(null); |
| | | insProduct.setInsSampleId(sample.getId()); |
| | | insProductMapper.insert(insProduct); |
| | | } |
| | | return insOrder.getId(); |
| | | } |
| | | |
| | | private void addInsProductMethod(Integer sampleId, List<InsProduct> productList, Integer id, Integer type) { |
| | | for (InsProduct product : productList) { |
| | | if(product.getState()==1){ |
| | | if(product.getState()==1 && !product.getInspectionItem().equals("熔接损耗")){ |
| | | switch (type){ |
| | | case 1: |
| | | product.setInsFibersId(id); |