| | |
| | | package com.yuanchu.limslaboratory.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.yuanchu.limslaboratory.pojo.Product; |
| | | import com.yuanchu.limslaboratory.mapper.ProductMapper; |
| | | import com.yuanchu.limslaboratory.service.ProductService; |
| | |
| | | private ProductMapper productMapper; |
| | | |
| | | @Override |
| | | public List<Product> selectProductByMaterialId(int materialId) { |
| | | return productMapper.selectProductByMaterialId(materialId); |
| | | } |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Override |
| | | public Integer addProductInformation(Product product) { |
| | | return productMapper.insert(product); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getListProductInformation(Integer materialId) { |
| | | LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(Product::getMaterialId, materialId); |
| | | wrapper.select(Product::getId, Product::getName, Product::getFather); |
| | | wrapper.groupBy(Product::getFather); |
| | | List<Map<String, Object>> products = productMapper.selectMaps(wrapper); |
| | | for (Map<String, Object> product:products){ |
| | | if (!ObjectUtils.isEmpty(product.get("father"))){ |
| | | product.remove("name"); |
| | | product.remove("id"); |
| | | LambdaQueryWrapper<Product> wrapper1 = new LambdaQueryWrapper<>(); |
| | | wrapper1.eq(Product::getFather, product.get("father")); |
| | | wrapper1.select(Product::getId, Product::getName); |
| | | List<Map<String, Object>> maps = productMapper.selectMaps(wrapper1); |
| | | product.put("sonProduct", maps); |
| | | } |
| | | } |
| | | for (Map<String, Object> product:products){ |
| | | System.out.println(product); |
| | | } |
| | | return products; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getProductInformation(Integer productId) { |
| | | Map<String, Object> productMap = productMapper.getProductInformation(productId); |
| | | String userName = userService.selectByUserId((Integer) productMap.get("user_id")); |
| | | productMap.remove("user_id"); |
| | | productMap.put("userName", userName); |
| | | return productMap; |
| | | } |
| | | |
| | | @Override |
| | | public Integer deleteProductInformation(Integer productId) { |
| | | LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>(); |
| | | LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>(); |
| | | wrapper.eq(Product::getId, productId); |
| | | return productMapper.delete(wrapper); |
| | | wrapper.set(Product::getState, 0); |
| | | return productMapper.update(new Product(), wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteProductEqMaterialId(List<String> materialListId) { |
| | | for (String materialId : materialListId){ |
| | | LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(Product::getMaterialId, materialId); |
| | | wrapper.select(Product::getId); |
| | | List<Product> products = productMapper.selectList(wrapper); |
| | | List<Integer> productDeleteId = new ArrayList<>(); |
| | | for (Product product : products){ |
| | | productDeleteId.add(product.getId()); |
| | | } |
| | | productMapper.deleteBatchIds(productDeleteId); |
| | | public void MaterialIdDeleteProduct(List<String> deleteMaterialId) { |
| | | for (String materialId : deleteMaterialId){ |
| | | LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<>(); |
| | | wrapper.eq(Product::getId, materialId); |
| | | wrapper.set(Product::getState, 0); |
| | | productMapper.update(new Product(), wrapper); |
| | | } |
| | | } |
| | | } |