|  | @ -199,44 +199,46 @@ public class SubscribeServiceImpl implements SubscribeService { | 
			
		
	
		
		
			
				
					|  |  | 		personalTemplateDTO.setKeyWords(keywords); |  |  | 		personalTemplateDTO.setKeyWords(keywords); | 
			
		
	
		
		
			
				
					|  |  | 		personalTemplateDTO.setType(formDTO.getType()); |  |  | 		personalTemplateDTO.setType(formDTO.getType()); | 
			
		
	
		
		
			
				
					|  |  | 		personalTemplateService.save(personalTemplateDTO); |  |  | 		personalTemplateService.save(personalTemplateDTO); | 
			
		
	
		
		
			
				
					
					|  |  | 		//获取客户列表
 |  |  | 		if (formDTO.getIsSync()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		List<PaCustomerDTO> customerList = paCustomerService.getCustomerListByTestId(authInfo.getCustomerId()); |  |  | 			//获取客户列表
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		List<String> customerNames = new ArrayList<>(); |  |  | 			List<PaCustomerDTO> customerList = paCustomerService.getCustomerListByTestId(authInfo.getCustomerId()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 		if (null != customerList && customerList.size() > NumConstant.ZERO) { |  |  | 			List<String> customerNames = new ArrayList<>(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 			for (PaCustomerDTO paCustomerDTO : customerList) { |  |  | 			if (null != customerList && customerList.size() > NumConstant.ZERO) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				//获取小程序调用令牌
 |  |  | 				for (PaCustomerDTO paCustomerDTO : customerList) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				AuthorizationInfoDTO authDTO = authorizationInfoDao.getAuthInfoByCustomer(paCustomerDTO.getId(), authInfo.getClientType()); |  |  | 					//获取小程序调用令牌
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				if (null == authDTO) { |  |  | 					AuthorizationInfoDTO authDTO = authorizationInfoDao.getAuthInfoByCustomer(paCustomerDTO.getId(), authInfo.getClientType()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 					log.error("客户[" + paCustomerDTO.getCustomerName() + "]未授权"); |  |  | 					if (null == authDTO) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 					customerNames.add(paCustomerDTO.getCustomerName()); |  |  | 						log.error("客户[" + paCustomerDTO.getCustomerName() + "]未授权"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 					continue; |  |  | 						customerNames.add(paCustomerDTO.getCustomerName()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				} |  |  | 						continue; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				WxResult<String> wxResult1 =  wxMaSubscribeService.addTemplate(authDTO.getAuthorizerAccessToken(), request); |  |  | 					} | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				if (!wxResult1.success()) { |  |  | 					WxResult<String> wxResult1 =  wxMaSubscribeService.addTemplate(authDTO.getAuthorizerAccessToken(), request); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 					log.error("客户[" + paCustomerDTO.getCustomerName() + "]添加模板失败,原因:" + wxResult1.getErrorCode() + wxResult1.getErrorMsg()); |  |  | 					if (!wxResult1.success()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 					customerNames.add(paCustomerDTO.getCustomerName()); |  |  | 						log.error("客户[" + paCustomerDTO.getCustomerName() + "]添加模板失败,原因:" + wxResult1.getErrorCode() + wxResult1.getErrorMsg()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 					continue; |  |  | 						customerNames.add(paCustomerDTO.getCustomerName()); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 						continue; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					String tmplId = wxResult1.getData(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					PersonalTemplateDTO templateDTO = new PersonalTemplateDTO(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setCustomerId(paCustomerDTO.getId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setClientType(authInfo.getClientType()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setAppId(authDTO.getAuthorizerAppid()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setPid(priTmplId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setPriTmplId(tmplId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setTid(formDTO.getTid()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setKeyIds(keyIds); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setTitle(formDTO.getTitle()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setSceneDesc(formDTO.getSceneDesc()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setKeyWords(keywords); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setType(formDTO.getType()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					personalTemplateService.save(templateDTO); | 
			
		
	
		
		
			
				
					|  |  | 				} |  |  | 				} | 
			
		
	
		
		
			
				
					|  |  | 				String tmplId = wxResult1.getData(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				PersonalTemplateDTO templateDTO = new PersonalTemplateDTO(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setCustomerId(paCustomerDTO.getId()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setClientType(authInfo.getClientType()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setAppId(authDTO.getAuthorizerAppid()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setPid(priTmplId); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setPriTmplId(tmplId); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setTid(formDTO.getTid()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setKeyIds(keyIds); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setTitle(formDTO.getTitle()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setSceneDesc(formDTO.getSceneDesc()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setKeyWords(keywords); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				templateDTO.setType(formDTO.getType()); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				personalTemplateService.save(templateDTO); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 		} |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  | 		if (customerNames.size() > NumConstant.ZERO) { |  |  | 			if (customerNames.size() > NumConstant.ZERO) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 			String names = String.join(",", customerNames); |  |  | 				String names = String.join(",", customerNames); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 			throw new RenException("客户[" + names + "]添加模板失败"); |  |  | 				throw new RenException("客户[" + names + "]添加模板失败"); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 		} |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  | 	} | 
			
		
	
	
		
		
			
				
					|  | @ -348,7 +350,6 @@ public class SubscribeServiceImpl implements SubscribeService { | 
			
		
	
		
		
			
				
					|  |  | 				log.error("居民端同步失败:" + wxResult.getErrorCode() + wxResult.getErrorMsg()); |  |  | 				log.error("居民端同步失败:" + wxResult.getErrorCode() + wxResult.getErrorMsg()); | 
			
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 		}); |  |  | 		}); | 
			
		
	
		
		
			
				
					|  |  | 		resultDTO.setResiList(resiList); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 		AuthorizationInfoDTO workAuthDTO = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), "work"); |  |  | 		AuthorizationInfoDTO workAuthDTO = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), "work"); | 
			
		
	
		
		
			
				
					|  |  | 		if (null == workAuthDTO) { |  |  | 		if (null == workAuthDTO) { | 
			
		
	
	
		
		
			
				
					|  | @ -371,10 +372,100 @@ public class SubscribeServiceImpl implements SubscribeService { | 
			
		
	
		
		
			
				
					|  |  | 				log.error("工作端同步失败:" + wxResult.getErrorCode() + wxResult.getErrorMsg()); |  |  | 				log.error("工作端同步失败:" + wxResult.getErrorCode() + wxResult.getErrorMsg()); | 
			
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 		}); |  |  | 		}); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | //		resultDTO.setResiList(resiList.stream().filter(item -> formDTO.getSync().equals(item.getState())).collect(Collectors.toList()));
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | //		resultDTO.setWorkList(workList.stream().filter(item -> formDTO.getSync().equals(item.getState())).collect(Collectors.toList()));
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		resultDTO.setResiList(resiList); | 
			
		
	
		
		
			
				
					|  |  | 		resultDTO.setWorkList(workList); |  |  | 		resultDTO.setWorkList(workList); | 
			
		
	
		
		
			
				
					|  |  | 		return resultDTO; |  |  | 		return resultDTO; | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	/** | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * 同步单一模板到所有客户 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @param formDTO | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @return void | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @author zhaoqifeng | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @date 2021/1/11 14:49 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	@Override | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	public void initAll(InitAllFormDTO formDTO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		AuthorizationInfoDTO authInfo = authorizationInfoDao.selectInfoByAppId(formDTO.getAppId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		PersonalTemplateDTO publicDTO = personalTemplateService.get(formDTO.getTempId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		//获取客户列表
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		List<PaCustomerDTO> customerList = paCustomerService.getCustomerListByTestId(authInfo.getCustomerId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		List<String> customerNames = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		if (null != customerList && customerList.size() > NumConstant.ZERO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			for (PaCustomerDTO paCustomerDTO : customerList) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				PersonalTemplateDTO personalTemplateDTO = personalTemplateService.getTempByPid(paCustomerDTO.getId(), publicDTO.getPriTmplId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				if (null != personalTemplateDTO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					//获取小程序调用令牌
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					AuthorizationInfoDTO authDTO = authorizationInfoDao.getAuthInfoByCustomer(paCustomerDTO.getId(), authInfo.getClientType()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					List<String> keyIds = Arrays.asList(publicDTO.getKeyIds().split(",")); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					List<Integer> keyIdList = keyIds.stream().map(Integer::parseInt).collect(Collectors.toList()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					WxAddTemplateReq request = new WxAddTemplateReq(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					request.setTid(publicDTO.getTid()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					request.setKidList(keyIdList); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					request.setSceneDesc(publicDTO.getSceneDesc()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					WxResult<String> wxResult =  wxMaSubscribeService.addTemplate(authInfo.getAuthorizerAccessToken(), request); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					if (null == authDTO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 						log.error("客户[" + paCustomerDTO.getCustomerName() + "]未授权"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 						customerNames.add(paCustomerDTO.getCustomerName()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 						continue; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					String tmplId = wxResult.getData(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					PersonalTemplateDTO templateDTO = new PersonalTemplateDTO(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setCustomerId(paCustomerDTO.getId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setClientType(authInfo.getClientType()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setAppId(authDTO.getAuthorizerAppid()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setPid(publicDTO.getPriTmplId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setPriTmplId(tmplId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setTid(publicDTO.getTid()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setKeyIds(publicDTO.getKeyIds()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setTitle(publicDTO.getTitle()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setSceneDesc(publicDTO.getSceneDesc()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setKeyWords(publicDTO.getKeyWords()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					templateDTO.setType(publicDTO.getType()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					personalTemplateService.save(templateDTO); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		if (customerNames.size() > NumConstant.ZERO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			String names = String.join(",", customerNames); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			log.error("客户[" + names + "]添加模板失败"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	/** | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * 删除客户模板 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @param formDTO | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @return void | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @author zhaoqifeng | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 * @date 2021/1/11 14:54 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	 */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	@Override | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	public void delPersonalTemp(DelPersonalTempFormDTO formDTO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		if (null == authInfo) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			throw new RenException("未授权或token已过期"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		formDTO.getTempIdList().forEach(tempId -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			PersonalTemplateDTO dto = personalTemplateService.get(tempId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			WxDelTemplateReq request = new WxDelTemplateReq(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			request.setPriTmplId(dto.getPriTmplId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			WxResult wxResult =  wxMaSubscribeService.delTemplate(authInfo.getAuthorizerAccessToken(), request); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			if (!wxResult.success()) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			personalTemplateService.deleteById(dto.getId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		}); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	private WxGetCategoryResult getCategoryResult(String accessToken) { |  |  | 	private WxGetCategoryResult getCategoryResult(String accessToken) { | 
			
		
	
		
		
			
				
					|  |  | 		WxResult<WxGetCategoryResult> wxResult =  wxMaSubscribeService.getCategory(accessToken); |  |  | 		WxResult<WxGetCategoryResult> wxResult =  wxMaSubscribeService.getCategory(accessToken); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | 
 |