|  |  | @ -17,37 +17,48 @@ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.modules.partymember.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.FieldConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.StrConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerOrgRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerStaffRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.bean.GridInfoCache; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.security.dto.TokenDto; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ExcelPoiUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.CustomerGridDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.GridOptionFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.GovOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.modules.partymember.dao.IcPartymemberStyleDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.modules.partymember.entity.IcPartymemberStyleEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.modules.partymember.entity.IcPartymemberStyleImageEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.modules.partymember.excel.IcPartymemberStyleImportExcel; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.modules.partymember.service.IcPartymemberStyleImageService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.modules.partymember.service.IcPartymemberStyleService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.resi.partymember.dto.partymember.IcPartymemberStyleDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.resi.partymember.dto.partymember.form.PartyMemberStyleFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageInfo; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.collections4.CollectionUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import javax.annotation.Resource; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Date; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  | import javax.servlet.http.HttpServletResponse; | 
			
		
	
		
			
				
					|  |  |  | import java.io.IOException; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | import java.util.concurrent.atomic.AtomicInteger; | 
			
		
	
		
			
				
					|  |  |  | import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -57,11 +68,14 @@ import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  |  * @author generator generator@elink-cn.com | 
			
		
	
		
			
				
					|  |  |  |  * @since v1.0.0 2021-11-18 | 
			
		
	
		
			
				
					|  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymemberStyleDao, IcPartymemberStyleEntity> implements IcPartymemberStyleService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |     private IcPartymemberStyleImageService icPartymemberStyleImageService; | 
			
		
	
		
			
				
					|  |  |  |     @Resource | 
			
		
	
		
			
				
					|  |  |  |     private GovOrgOpenFeignClient govOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<IcPartymemberStyleDTO> page(Map<String, Object> params) { | 
			
		
	
	
		
			
				
					|  |  | @ -179,4 +193,87 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymember | 
			
		
	
		
			
				
					|  |  |  |         return new PageData<>(dtoList, pageInfo.getTotal()); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 导入数据 | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * @Param tokenDto | 
			
		
	
		
			
				
					|  |  |  |      * @Param response | 
			
		
	
		
			
				
					|  |  |  |      * @Param file | 
			
		
	
		
			
				
					|  |  |  |      * @Return | 
			
		
	
		
			
				
					|  |  |  |      * @Author zhaoqifeng | 
			
		
	
		
			
				
					|  |  |  |      * @Date 2021/11/29 11:01 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException { | 
			
		
	
		
			
				
					|  |  |  |         ExcelImportResult<IcPartymemberStyleImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartymemberStyleImportExcel.class); | 
			
		
	
		
			
				
					|  |  |  |         List<IcPartymemberStyleImportExcel> failList = importResult.getFailList(); | 
			
		
	
		
			
				
					|  |  |  |         //存放错误数据行号
 | 
			
		
	
		
			
				
					|  |  |  |         List<Integer> numList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { | 
			
		
	
		
			
				
					|  |  |  |             for (IcPartymemberStyleImportExcel entity : failList) { | 
			
		
	
		
			
				
					|  |  |  |                 //打印失败的行 和失败的信息
 | 
			
		
	
		
			
				
					|  |  |  |                 log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); | 
			
		
	
		
			
				
					|  |  |  |                 numList.add(entity.getRowNum()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<IcPartymemberStyleImportExcel> result = importResult.getList(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         //获取组织下网格信息
 | 
			
		
	
		
			
				
					|  |  |  |         GridOptionFormDTO formDTO = new GridOptionFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         formDTO.setAgencyId(staffInfoCache.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         Result<List<CustomerGridDTO>> gridOptionResult =  govOrgOpenFeignClient.getGridIListByAgency(staffInfoCache.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         if (!gridOptionResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(gridOptionResult.getCode(), gridOptionResult.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> gridMap = gridOptionResult.getData().stream().collect(Collectors.toMap(CustomerGridDTO::getGridName, CustomerGridDTO::getId)); | 
			
		
	
		
			
				
					|  |  |  |         //1.数据校验 只允许导入当前组织下的网格的数据
 | 
			
		
	
		
			
				
					|  |  |  |         //网格名称不一样的数据舍弃
 | 
			
		
	
		
			
				
					|  |  |  |         Iterator<IcPartymemberStyleImportExcel> iterator = result.iterator(); | 
			
		
	
		
			
				
					|  |  |  |         while (iterator.hasNext()) { | 
			
		
	
		
			
				
					|  |  |  |             IcPartymemberStyleImportExcel obj = iterator.next(); | 
			
		
	
		
			
				
					|  |  |  |             if (null == gridMap.get(obj.getGridName().trim())) { | 
			
		
	
		
			
				
					|  |  |  |                 numList.add(obj.getRowNum()); | 
			
		
	
		
			
				
					|  |  |  |                 log.warn(String.format("不是当前组织下可导入的数据,网格名称->%s,行号->%s", obj.getGridName(), obj.getRowNum())); | 
			
		
	
		
			
				
					|  |  |  |                 iterator.remove(); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(result)) { | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<IcPartymemberStyleImageEntity> imageList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         List<IcPartymemberStyleEntity> list = result.stream().map(item -> { | 
			
		
	
		
			
				
					|  |  |  |             IcPartymemberStyleEntity entity = new IcPartymemberStyleEntity(); | 
			
		
	
		
			
				
					|  |  |  |             entity.setId(UUID.randomUUID().toString().replace("-", "")); | 
			
		
	
		
			
				
					|  |  |  |             entity.setCustomerId(tokenDto.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             entity.setAgencyId(staffInfoCache.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             entity.setGridId(gridMap.get(item.getGridName())); | 
			
		
	
		
			
				
					|  |  |  |             entity.setName(item.getName()); | 
			
		
	
		
			
				
					|  |  |  |             entity.setMainDeed(item.getMainDeed()); | 
			
		
	
		
			
				
					|  |  |  |             AtomicInteger i = new AtomicInteger(); | 
			
		
	
		
			
				
					|  |  |  |             if (StringUtils.isNotBlank(item.getImageUrl())) { | 
			
		
	
		
			
				
					|  |  |  |                 Arrays.asList(item.getImageUrl().split(StrConstant.COMMA)).forEach(url -> { | 
			
		
	
		
			
				
					|  |  |  |                     IcPartymemberStyleImageEntity urlEntity = new IcPartymemberStyleImageEntity(); | 
			
		
	
		
			
				
					|  |  |  |                     urlEntity.setImageUrl(url); | 
			
		
	
		
			
				
					|  |  |  |                     urlEntity.setCustomerId(tokenDto.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |                     urlEntity.setStyleId(entity.getId()); | 
			
		
	
		
			
				
					|  |  |  |                     urlEntity.setSort(i.getAndIncrement()); | 
			
		
	
		
			
				
					|  |  |  |                     imageList.add(urlEntity); | 
			
		
	
		
			
				
					|  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             return entity; | 
			
		
	
		
			
				
					|  |  |  |         }).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         insertBatch(list); | 
			
		
	
		
			
				
					|  |  |  |         icPartymemberStyleImageService.insertBatch(imageList); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         String str = String.format("共%s条,成功导入%s条。", numList.size() + result.size(), numList.size() + result.size() - numList.size()); | 
			
		
	
		
			
				
					|  |  |  |         if (numList.size() > NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             Collections.sort(numList); | 
			
		
	
		
			
				
					|  |  |  |             String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、")); | 
			
		
	
		
			
				
					|  |  |  |             log.warn(str + "第" + subList + "行未成功!"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } |