| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.basic.dto.CustomerPrivateDto; |
| | | import com.ruoyi.basic.dto.CustomerPrivatePoolDto; |
| | | import com.ruoyi.basic.mapper.CustomerMapper; |
| | | import com.ruoyi.basic.mapper.CustomerPrivatePoolMapper; |
| | | import com.ruoyi.basic.pojo.*; |
| | | import com.ruoyi.basic.mapper.CustomerPrivateMapper; |
| | | import com.ruoyi.basic.service.CustomerFollowUpService; |
| | | import com.ruoyi.basic.service.CustomerPrivateService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.service.CustomerReturnVisitService; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | | * å®¢æ·æ¡£æ¡ æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå
¬å¸ |
| | | * @since 2026-04-17 10:39:09 |
| | | */ |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class CustomerPrivateServiceImpl extends ServiceImpl<CustomerPrivateMapper, CustomerPrivate> implements CustomerPrivateService { |
| | | |
| | | |
| | | @Autowired |
| | | private CustomerPrivatePoolMapper customerPrivatePoolMapper; |
| | | |
| | | @Autowired |
| | | private CustomerFollowUpService customerFollowUpService; |
| | | |
| | | @Autowired |
| | | private CustomerReturnVisitService customerReturnVisitService; |
| | | @Autowired |
| | | private SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | @Autowired |
| | | private CustomerPrivateMapper customerPrivateMapper; |
| | | @Autowired |
| | | private CustomerPrivateService customerPrivateService; |
| | | |
| | | |
| | | @Override |
| | | public Boolean add(CustomerPrivateDto customerPrivateDto) { |
| | | //æ°å¢ç§æµ· å®¢æ· |
| | | this.save(customerPrivateDto); |
| | | //æ°å¢ç§æµ·è®°å½ |
| | | CustomerPrivatePool customerPrivatePool = new CustomerPrivatePool(); |
| | | customerPrivatePool.setCustomerId(customerPrivateDto.getId()); |
| | | customerPrivatePool.setType(0L); |
| | | customerPrivatePool.setBoundId(SecurityUtils.getLoginUser().getUserId()); |
| | | customerPrivatePoolMapper.insert(customerPrivatePool); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Integer delete(List<Long> ids) { |
| | | List<CustomerPrivatePool> customerPrivatePools = customerPrivatePoolMapper.selectList(new QueryWrapper<CustomerPrivatePool>().lambda().in(CustomerPrivatePool::getId, ids)); |
| | | List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(new QueryWrapper<SalesLedger>().lambda().in(SalesLedger::getCustomerId, customerPrivatePools.stream().map(CustomerPrivatePool::getCustomerId).collect(Collectors.toList()))); |
| | | if (!CollectionUtils.isEmpty(salesLedgers)) { |
| | | throw new RuntimeException("å®¢æ·æéå®ååï¼è¯·å
å é¤éå®åå"); |
| | | } |
| | | if (CollectionUtils.isEmpty(customerPrivatePools)) { |
| | | throw new RuntimeException("客æ·ä¸åå¨"); |
| | | } |
| | | customerFollowUpService.remove(new QueryWrapper<CustomerFollowUp>().lambda().in(CustomerFollowUp::getCustomerPrivatePoolId, customerPrivatePools.stream().map(CustomerPrivatePool::getCustomerId).collect(Collectors.toList()))); |
| | | customerReturnVisitService.remove(new QueryWrapper<CustomerReturnVisit>().lambda().in(CustomerReturnVisit::getCustomerPrivatePoolId, customerPrivatePools.stream().map(CustomerPrivatePool::getCustomerId).collect(Collectors.toList()))); |
| | | customerPrivatePools.stream().forEach(customerPrivatePool -> { |
| | | customerPrivatePool.setDeleteFlag(1); |
| | | customerPrivatePoolMapper.updateById(customerPrivatePool); |
| | | }); |
| | | return 1; |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public R importData(MultipartFile file) { |
| | | try { |
| | | List<CustomerPrivate> existingList = customerPrivateService.list(); |
| | | java.util.Set<String> existingCustomerNames = existingList.stream() |
| | | .map(CustomerPrivate::getCustomerName) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | ExcelUtil<CustomerPrivate> util = new ExcelUtil<CustomerPrivate>(CustomerPrivate.class); |
| | | List<CustomerPrivate> userList = util.importExcel(file.getInputStream()); |
| | | if (CollectionUtils.isEmpty(userList)) { |
| | | return R.fail("模æ¿é误æå¯¼å
¥æ°æ®ä¸ºç©º"); |
| | | } |
| | | |
| | | int successCount = 0; |
| | | int skipCount = 0; |
| | | for (CustomerPrivate user : userList) { |
| | | if (existingCustomerNames.contains(user.getCustomerName())) { |
| | | skipCount++; |
| | | continue; |
| | | } |
| | | CustomerPrivateDto customerPrivateDto = new CustomerPrivateDto(); |
| | | BeanUtils.copyProperties(user, customerPrivateDto); |
| | | this.add(customerPrivateDto); |
| | | existingCustomerNames.add(user.getCustomerName()); |
| | | successCount++; |
| | | } |
| | | return R.ok("导å
¥å®æï¼æå" + successCount + "æ¡ï¼è·³è¿éå¤" + skipCount + "æ¡"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return R.fail("导å
¥å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | } |