| | |
| | | package org.springblade.modules.yw.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.yw.entity.FirmInfo; |
| | | import org.springblade.modules.yw.entity.SuppliesEntity; |
| | | import org.springblade.modules.yw.excel.SuppliesExcel; |
| | | import org.springblade.modules.yw.service.IFirmInfoService; |
| | | import org.springblade.modules.yw.vo.SuppliesVO; |
| | | import org.springblade.modules.yw.mapper.SuppliesMapper; |
| | | import org.springblade.modules.yw.service.ISuppliesService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 物资库表 服务实现类 |
| | |
| | | @Service |
| | | public class SuppliesServiceImpl extends ServiceImpl<SuppliesMapper, SuppliesEntity> implements ISuppliesService { |
| | | |
| | | @Autowired |
| | | private IFirmInfoService firmInfoService; |
| | | |
| | | @Override |
| | | public IPage<SuppliesVO> selectSuppliesPage(IPage<SuppliesVO> page, SuppliesVO supplies) { |
| | | return page.setRecords(baseMapper.selectSuppliesPage(page, supplies)); |
| | | } |
| | | |
| | | /** |
| | | * 导入物资仓库信息 |
| | | * @param data |
| | | * @param isCovered |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String importSupplies(List<SuppliesExcel> data, boolean isCovered) { |
| | | for (SuppliesExcel suppliesExcel : data) { |
| | | SuppliesEntity suppliesEntity = Objects.requireNonNull(BeanUtil.copy(suppliesExcel, SuppliesEntity.class)); |
| | | // 查询对应的企业id |
| | | suppliesEntity.setFirmId(getFirmId(suppliesExcel)); |
| | | // 判断是否已存在 |
| | | Long id = isSave(suppliesEntity); |
| | | // 已存在 |
| | | if (null!=id){ |
| | | if (isCovered){ |
| | | // 覆盖-更新 |
| | | suppliesEntity.setId(id); |
| | | updateById(suppliesEntity); |
| | | continue; |
| | | } |
| | | } |
| | | // 插入 |
| | | save(suppliesEntity); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 判断仓库是否已存在 |
| | | * @param suppliesEntity |
| | | * @return |
| | | */ |
| | | private Long isSave(SuppliesEntity suppliesEntity) { |
| | | QueryWrapper<SuppliesEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("firm_id",suppliesEntity.getFirmId()) |
| | | .eq("name",suppliesEntity.getName()) |
| | | .eq("is_deleted",0); |
| | | SuppliesEntity one = getOne(wrapper); |
| | | if (null!=one){ |
| | | return one.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 查询企业id |
| | | * @param suppliesExcel |
| | | * @return |
| | | */ |
| | | private Long getFirmId(SuppliesExcel suppliesExcel) { |
| | | QueryWrapper<FirmInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name",suppliesExcel.getFirmName()) |
| | | .eq("is_deleted",0); |
| | | FirmInfo one = firmInfoService.getOne(wrapper); |
| | | if (null!=one){ |
| | | return one.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | } |