| | |
| | | package com.aps.core.service.impl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.core.utils.poi.ExcelUtil; |
| | | import com.aps.common.security.utils.DictUtils; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.core.domain.ApsGasPipelinePrediction; |
| | | import com.aps.core.domain.ApsMaterialProductGroupManagement; |
| | | import com.aps.core.mapper.ApsMaterialProductGroupManagementMapper; |
| | | import com.aps.core.service.IApsMaterialProductGroupManagementService; |
| | | import io.micrometer.common.util.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import lombok.SneakyThrows; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 物料产品组数据管理Service业务层处理 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | * @date 2025-05-19 |
| | | */ |
| | | @Service |
| | | public class ApsMaterialProductGroupManagementServiceImpl implements IApsMaterialProductGroupManagementService |
| | | { |
| | | public class ApsMaterialProductGroupManagementServiceImpl implements IApsMaterialProductGroupManagementService { |
| | | @Autowired |
| | | private ApsMaterialProductGroupManagementMapper apsMaterialProductGroupManagementMapper; |
| | | |
| | | /** |
| | | * 查询物料产品组数据管理 |
| | | * |
| | | * |
| | | * @param id 物料产品组数据管理主键 |
| | | * @return 物料产品组数据管理 |
| | | */ |
| | | @Override |
| | | public ApsMaterialProductGroupManagement selectApsMaterialProductGroupManagementById(Long id) |
| | | { |
| | | public ApsMaterialProductGroupManagement selectApsMaterialProductGroupManagementById(Long id) { |
| | | return apsMaterialProductGroupManagementMapper.selectApsMaterialProductGroupManagementById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询物料产品组数据管理列表 |
| | | * |
| | | * |
| | | * @param apsMaterialProductGroupManagement 物料产品组数据管理 |
| | | * @return 物料产品组数据管理 |
| | | */ |
| | | @Override |
| | | public List<ApsMaterialProductGroupManagement> selectApsMaterialProductGroupManagementList(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement) |
| | | { |
| | | public List<ApsMaterialProductGroupManagement> selectApsMaterialProductGroupManagementList(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement) { |
| | | return apsMaterialProductGroupManagementMapper.selectApsMaterialProductGroupManagementList(apsMaterialProductGroupManagement); |
| | | } |
| | | |
| | | /** |
| | | * 新增物料产品组数据管理 |
| | | * |
| | | * |
| | | * @param apsMaterialProductGroupManagement 物料产品组数据管理 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertApsMaterialProductGroupManagement(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement) |
| | | { |
| | | public int insertApsMaterialProductGroupManagement(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement) { |
| | | apsMaterialProductGroupManagement.setId(IdUtil.getSnowflakeNextId()); |
| | | apsMaterialProductGroupManagement.setCreateBy(SecurityUtils.getUsername()); |
| | | apsMaterialProductGroupManagement.setCreateTime(DateUtils.getNowDate()); |
| | |
| | | |
| | | /** |
| | | * 修改物料产品组数据管理 |
| | | * |
| | | * |
| | | * @param apsMaterialProductGroupManagement 物料产品组数据管理 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateApsMaterialProductGroupManagement(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement) |
| | | { |
| | | public int updateApsMaterialProductGroupManagement(ApsMaterialProductGroupManagement apsMaterialProductGroupManagement) { |
| | | apsMaterialProductGroupManagement.setUpdateTime(DateUtils.getNowDate()); |
| | | apsMaterialProductGroupManagement.setUpdateBy(SecurityUtils.getUsername()); |
| | | return apsMaterialProductGroupManagementMapper.updateApsMaterialProductGroupManagement(apsMaterialProductGroupManagement); |
| | |
| | | |
| | | /** |
| | | * 批量删除物料产品组数据管理 |
| | | * |
| | | * |
| | | * @param ids 需要删除的物料产品组数据管理主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteApsMaterialProductGroupManagementByIds(Long[] ids) |
| | | { |
| | | public int deleteApsMaterialProductGroupManagementByIds(Long[] ids) { |
| | | return apsMaterialProductGroupManagementMapper.deleteApsMaterialProductGroupManagementByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 删除物料产品组数据管理信息 |
| | | * |
| | | * |
| | | * @param id 物料产品组数据管理主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteApsMaterialProductGroupManagementById(Long id) |
| | | { |
| | | public int deleteApsMaterialProductGroupManagementById(Long id) { |
| | | return apsMaterialProductGroupManagementMapper.deleteApsMaterialProductGroupManagementById(id); |
| | | } |
| | | |
| | | @SneakyThrows |
| | | @Override |
| | | public int batchInsertApsMaterialProductGroupManagement(MultipartFile file) { |
| | | Workbook workbook = WorkbookFactory.create(file.getInputStream()); |
| | | ExcelUtil<ApsMaterialProductGroupManagement> util = new ExcelUtil<>(ApsMaterialProductGroupManagement.class); |
| | | List<ApsMaterialProductGroupManagement> list = util.importExcel(file.getInputStream()); |
| | | DictUtils.CacheValue cacheValue = DictUtils.getCacheValue("aps_factory"); |
| | | DictUtils.CacheValue cacheDomain = DictUtils.getCacheValue("aps_domain"); |
| | | Set<String> keys = new HashSet<>(); |
| | | list.forEach(item -> { |
| | | item.setId(IdUtil.getSnowflakeNextId()); |
| | | item.setDomain(cacheDomain.get(item.getDomain())); |
| | | item.setFactory(cacheValue.get(item.getFactory())); |
| | | item.setCreateBy(SecurityUtils.getUsername()); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | }); |
| | | for (int i = list.size() - 1; i >= 0; --i) { |
| | | list.get(i).setKey(null); |
| | | if (!keys.contains(list.get(i).getKey())) { |
| | | keys.add(list.get(i).getKey()); |
| | | } else { |
| | | list.remove(i); |
| | | } |
| | | } |
| | | |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | int rows = sheet.getLastRowNum(); |
| | | if (rows > 0) { |
| | | List<ApsMaterialProductGroupManagement> list = new ArrayList<>(); |
| | | |
| | | /*数据列从1开始*/ |
| | | for (int i = 1; i <= rows; i++) { |
| | | Row row = sheet.getRow(i); |
| | | if (row.getCell(0) == null) { |
| | | continue; |
| | | } |
| | | String materialCode = row.getCell(0).getStringCellValue(); |
| | | if (StringUtils.isEmpty(materialCode)){ |
| | | continue; |
| | | } |
| | | String materialType = row.getCell(1).getStringCellValue(); |
| | | String domain = row.getCell(2).getStringCellValue(); |
| | | String isMain = row.getCell(3).getStringCellValue(); |
| | | String factory = row.getCell(4).getStringCellValue(); |
| | | if (StringUtils.isNotBlank(materialType) && |
| | | StringUtils.isNotBlank(domain) && |
| | | StringUtils.isNotBlank(isMain) && |
| | | StringUtils.isNotBlank(factory)) { |
| | | ApsMaterialProductGroupManagement item = new ApsMaterialProductGroupManagement(); |
| | | item.setId(IdUtil.getSnowflakeNextId()); |
| | | item.setFactory(factory); |
| | | item.setDomain(domain); |
| | | item.setMaterialType(materialType); |
| | | item.setMaterialCode(materialCode); |
| | | item.setIsMain(isMain); |
| | | item.setCreateBy(SecurityUtils.getUsername()); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | list.add(item); |
| | | if (!list.isEmpty()) { |
| | | Set<String> facCodeKey = apsMaterialProductGroupManagementMapper.selectByFacOrMaterial(keys); |
| | | if (!facCodeKey.isEmpty()) { |
| | | Iterator<ApsMaterialProductGroupManagement> it = list.iterator(); |
| | | while (it.hasNext()) { |
| | | ApsMaterialProductGroupManagement item = it.next(); |
| | | if (facCodeKey.contains(item.getKey())) { |
| | | LambdaUpdateWrapper<ApsMaterialProductGroupManagement> wrapper = new LambdaUpdateWrapper<>(); |
| | | wrapper.eq(ApsMaterialProductGroupManagement::getFactory, item.getFactory()); |
| | | wrapper.eq(ApsMaterialProductGroupManagement::getMaterialCode, item.getMaterialCode()); |
| | | item.setCreateBy(null); |
| | | item.setCreateTime(null); |
| | | item.setId(null); |
| | | item.setUpdateBy(SecurityUtils.getUsername()); |
| | | item.setUpdateTime(new Timestamp(System.currentTimeMillis())); |
| | | apsMaterialProductGroupManagementMapper.update(item, wrapper); |
| | | it.remove(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!list.isEmpty()) { |
| | | apsMaterialProductGroupManagementMapper.insert(list); |
| | | } |
| | | return list.size(); |
| | | } |
| | | return 0; |
| | | return list.size(); |
| | | |
| | | } |
| | | } |