@ -17,7 +17,9 @@ 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					package  com.epmet.service.impl ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  com.alibaba.fastjson.JSON ;  
			
		
	
		
			
				
					import  com.epmet.commons.mybatis.service.impl.BaseServiceImpl ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.constant.NumConstant ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.constant.StrConstant ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.dto.form.FileCommonDTO ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.exception.EpmetErrorCode ;  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -31,15 +33,16 @@ import com.epmet.commons.tools.utils.ConvertUtils; 
			
		
	
		
			
				
					import  com.epmet.commons.tools.utils.Result ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.utils.ScanContentUtils ;  
			
		
	
		
			
				
					import  com.epmet.constant.EventConstant ;  
			
		
	
		
			
				
					import  com.epmet.dao.ResiEventAttachmentDao  ;  
			
		
	
		
			
				
					import  com.epmet.dao.ResiEventDao  ;  
			
		
	
		
			
				
					import  com.epmet.constant.ResiEventAction  ;  
			
		
	
		
			
				
					import  com.epmet.dao.*  ;  
			
		
	
		
			
				
					import  com.epmet.dto.form.* ;  
			
		
	
		
			
				
					import  com.epmet.dto.result.* ;  
			
		
	
		
			
				
					import  com.epmet.entity.ResiEventAttachmentEntity ;  
			
		
	
		
			
				
					import  com.epmet.entity.ResiEventEntity ;  
			
		
	
		
			
				
					import  com.epmet.entity.* ;  
			
		
	
		
			
				
					import  com.epmet.feign.EpmetUserOpenFeignClient ;  
			
		
	
		
			
				
					import  com.epmet.feign.GovOrgOpenFeignClient ;  
			
		
	
		
			
				
					import  com.epmet.service.ResiEventService ;  
			
		
	
		
			
				
					import  com.github.pagehelper.PageHelper ;  
			
		
	
		
			
				
					import  com.github.pagehelper.PageInfo ;  
			
		
	
		
			
				
					import  lombok.extern.slf4j.Slf4j ;  
			
		
	
		
			
				
					import  org.apache.commons.lang3.StringUtils ;  
			
		
	
		
			
				
					import  org.springframework.beans.factory.annotation.Autowired ;  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -73,6 +76,12 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					    private  EpmetUserOpenFeignClient  epmetUserOpenFeignClient ;  
			
		
	
		
			
				
					    @Autowired  
			
		
	
		
			
				
					    private  ResiEventAttachmentDao  resiEventAttachmentDao ;  
			
		
	
		
			
				
					    @Autowired  
			
		
	
		
			
				
					    private  ResiEventReportOrgDao  resiEventReportOrgDao ;  
			
		
	
		
			
				
					    @Autowired  
			
		
	
		
			
				
					    private  ResiEventMentionDao  resiEventMentionDao ;  
			
		
	
		
			
				
					    @Autowired  
			
		
	
		
			
				
					    private  ResiEventOperationLogDao  resiEventOperationLogDao ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  @Description   群众直报 ( 待处理 、 处理中 、 已办结 ) 列表  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -131,6 +140,7 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					        if ( ! gridInfoRes . success ( ) | | null = = gridInfoRes . getData ( ) ) {  
			
		
	
		
			
				
					            throw  new  RenException ( "网格信息查询异常" ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        ResiEventEntity  resiEventEntity =  ConvertUtils . sourceToTarget ( formDTO , ResiEventEntity . class ) ;  
			
		
	
		
			
				
					        resiEventEntity . setAgencyId ( gridInfoRes . getData ( ) . getParentAgencyId ( ) ) ;  
			
		
	
		
			
				
					        resiEventEntity . setPids ( gridInfoRes . getData ( ) . getPids ( ) ) ;  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -157,16 +167,66 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					            resiEventAttachmentDao . insert ( attachmentEntity ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        //6、插入组织表
  
			
		
	
		
			
				
					        List < ResiEventReportOrgEntity >  orgEntityList = getOrgList ( formDTO . getCustomerId ( ) , resiEventEntity . getId ( ) , formDTO . getOrgList ( ) ) ;  
			
		
	
		
			
				
					        orgEntityList . forEach ( orgEntity - > {  
			
		
	
		
			
				
					            resiEventReportOrgDao . insert ( orgEntity ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        //7、插入艾特人表
  
			
		
	
		
			
				
					        List < ResiEventMentionEntity >  npcList = getNpcList ( formDTO . getCustomerId ( ) , resiEventEntity . getId ( ) , formDTO . getNpcUserList ( ) ) ;  
			
		
	
		
			
				
					        npcList . forEach ( npc - > {  
			
		
	
		
			
				
					            resiEventMentionDao . insert ( npc ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        //8、插入log日志
  
			
		
	
		
			
				
					        ResiEventOperationLogEntity  publishLog = new  ResiEventOperationLogEntity ( ) ;  
			
		
	
		
			
				
					        publishLog . setCustomerId ( formDTO . getCustomerId ( ) ) ;  
			
		
	
		
			
				
					        publishLog . setResiEventId ( resiEventEntity . getId ( ) ) ;  
			
		
	
		
			
				
					        publishLog . setUserId ( formDTO . getUserId ( ) ) ;  
			
		
	
		
			
				
					        publishLog . setUserIdentity ( EventConstant . REPORT_USER ) ;  
			
		
	
		
			
				
					        publishLog . setActionCode ( ResiEventAction . PUBLISH . getCode ( ) ) ;  
			
		
	
		
			
				
					        publishLog . setActionDesc ( ResiEventAction . PUBLISH . getDesc ( ) ) ;  
			
		
	
		
			
				
					        publishLog . setOperateTime ( resiEventEntity . getCreatedTime ( ) ) ;  
			
		
	
		
			
				
					        resiEventOperationLogDao . insert ( publishLog ) ;  
			
		
	
		
			
				
					        //9、返回事件id
  
			
		
	
		
			
				
					        ResiEventIdDTO  resiEventIdDTO = new  ResiEventIdDTO ( ) ;  
			
		
	
		
			
				
					        resiEventIdDTO . setResiEventId ( resiEventEntity . getId ( ) ) ;  
			
		
	
		
			
				
					        return  resiEventIdDTO ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    private  List < ResiEventMentionEntity >  getNpcList ( String  customerId ,  String  resiEventId ,  List < MentionUserFormDTO >  npcUserList )  {  
			
		
	
		
			
				
					        List < ResiEventMentionEntity >  list = new  ArrayList < > ( ) ;  
			
		
	
		
			
				
					        npcUserList . forEach ( npc - > {  
			
		
	
		
			
				
					            ResiEventMentionEntity  mentionEntity = new  ResiEventMentionEntity ( ) ;  
			
		
	
		
			
				
					            mentionEntity . setCustomerId ( customerId ) ;  
			
		
	
		
			
				
					            mentionEntity . setResiEventId ( resiEventId ) ;  
			
		
	
		
			
				
					            mentionEntity . setUserType ( EventConstant . NPC_USER ) ;  
			
		
	
		
			
				
					            mentionEntity . setUserId ( npc . getNpcUserId ( ) ) ;  
			
		
	
		
			
				
					            mentionEntity . setGridId ( npc . getGridId ( ) ) ;  
			
		
	
		
			
				
					            mentionEntity . setAgencyId ( npc . getAgencyId ( ) ) ;  
			
		
	
		
			
				
					            mentionEntity . setPids ( npc . getPids ( ) ) ;  
			
		
	
		
			
				
					            mentionEntity . setReadFlag ( EventConstant . UN_READ ) ;  
			
		
	
		
			
				
					            mentionEntity . setRedDot ( true ) ;  
			
		
	
		
			
				
					            list . add ( mentionEntity ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        return  list ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        return  null ;  
			
		
	
		
			
				
					    private  List < ResiEventReportOrgEntity >  getOrgList ( String  customerId ,  String  resiEventId ,  List < ReportOrgFormDTO >  orgList )  {  
			
		
	
		
			
				
					        List < ResiEventReportOrgEntity >  list = new  ArrayList < > ( ) ;  
			
		
	
		
			
				
					        orgList . forEach ( org - > {  
			
		
	
		
			
				
					            ResiEventReportOrgEntity  entity = ConvertUtils . sourceToTarget ( org , ResiEventReportOrgEntity . class ) ;  
			
		
	
		
			
				
					            entity . setCustomerId ( customerId ) ;  
			
		
	
		
			
				
					            entity . setResiEventId ( resiEventId ) ;  
			
		
	
		
			
				
					            //默认是未读
  
			
		
	
		
			
				
					            entity . setOrgRead ( EventConstant . UN_READ ) ;  
			
		
	
		
			
				
					            entity . setRedDot ( true ) ;  
			
		
	
		
			
				
					            list . add ( entity ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        return  list ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    private  List < ResiEventAttachmentEntity >  getAttList ( String  customerId , String  resiEventId ,  List < FileCommonDTO >  attachmentList )  {  
			
		
	
		
			
				
					        List < ResiEventAttachmentEntity >  list = new  ArrayList < > ( ) ;  
			
		
	
		
			
				
					        int  sort = 1 ;  
			
		
	
		
			
				
					        int  sort =  NumConstant . ONE  ;  
			
		
	
		
			
				
					        for ( FileCommonDTO  img : attachmentList ) {  
			
		
	
		
			
				
					            ResiEventAttachmentEntity  entity = new  ResiEventAttachmentEntity ( ) ;  
			
		
	
		
			
				
					            entity . setCustomerId ( customerId ) ;  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -177,6 +237,7 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					            entity . setAttachmentUrl ( img . getUrl ( ) ) ;  
			
		
	
		
			
				
					            entity . setSort ( sort ) ;  
			
		
	
		
			
				
					            sort + + ;  
			
		
	
		
			
				
					            list . add ( entity ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        return  list ;  
			
		
	
		
			
				
					    }  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -227,6 +288,7 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  撤回事件  
			
		
	
		
			
				
					     *  
			
		
	
		
			
				
					     *  需求描述 : 未处理状态中可撤回上报事件 , 撤回后不在展示列表内 、 @的人大代表或组织已读后按钮消失  
			
		
	
		
			
				
					     *  @param  formDTO  
			
		
	
		
			
				
					     *  @return  void  
			
		
	
		
			
				
					     *  @author  yinzuomei  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -234,9 +296,34 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    @Override  
			
		
	
		
			
				
					    public  void  reCall ( ReCallEventFormDTO  formDTO )  {  
			
		
	
		
			
				
					        // todo
  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        ResiEventEntity  resiEventEntity = baseDao . selectById ( formDTO . getResiEventId ( ) ) ;  
			
		
	
		
			
				
					        if ( null = = resiEventEntity ) {  
			
		
	
		
			
				
					            throw  new  RenException ( String . format ( "根据事件id没有找到记录" , formDTO . getResiEventId ( ) ) ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        // 我自己的发布的才可以删除
  
			
		
	
		
			
				
					        if ( ! formDTO . getUserId ( ) . equals ( resiEventEntity . getReportUserId ( ) ) ) {  
			
		
	
		
			
				
					            log . warn ( "撤回事件入参:" + JSON . toJSONString ( formDTO ) ) ;  
			
		
	
		
			
				
					            throw  new  RenException ( EpmetErrorCode . RESI_EVENT_NOT_MY_REPORTED . getCode ( ) , EpmetErrorCode . RESI_EVENT_NOT_MY_REPORTED . getMsg ( ) ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        // 没有人看到过,才可以删除
  
			
		
	
		
			
				
					        if ( resiEventEntity . getReadFlag ( ) ) {  
			
		
	
		
			
				
					            throw  new  RenException ( EpmetErrorCode . RESI_EVENT_READ . getCode ( ) , EpmetErrorCode . RESI_EVENT_READ . getMsg ( ) ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        resiEventEntity . setLatestOperatedTime ( new  Date ( ) ) ;  
			
		
	
		
			
				
					        resiEventEntity . setRecallFlag ( true ) ;  
			
		
	
		
			
				
					        resiEventEntity . setRecallTime ( resiEventEntity . getLatestOperatedTime ( ) ) ;  
			
		
	
		
			
				
					        //1、更新主表标记已撤回
  
			
		
	
		
			
				
					        baseDao . updateById ( resiEventEntity ) ;  
			
		
	
		
			
				
					        //2、插入log日志
  
			
		
	
		
			
				
					        ResiEventOperationLogEntity  reCallLog = new  ResiEventOperationLogEntity ( ) ;  
			
		
	
		
			
				
					        reCallLog . setCustomerId ( formDTO . getCustomerId ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setResiEventId ( resiEventEntity . getId ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setUserId ( formDTO . getUserId ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setUserIdentity ( EventConstant . REPORT_USER ) ;  
			
		
	
		
			
				
					        reCallLog . setActionCode ( ResiEventAction . RECALL . getCode ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setActionDesc ( ResiEventAction . RECALL . getDesc ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setOperateTime ( resiEventEntity . getLatestOperatedTime ( ) ) ;  
			
		
	
		
			
				
					        resiEventOperationLogDao . insert ( reCallLog ) ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -250,13 +337,30 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    @Override  
			
		
	
		
			
				
					    public  void  chooseResolve ( ChooseResolveFormDTO  formDTO )  {  
			
		
	
		
			
				
					        // todo
  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        ResiEventEntity  resiEventEntity = baseDao . selectById ( formDTO . getResiEventId ( ) ) ;  
			
		
	
		
			
				
					        if ( null = = resiEventEntity ) {  
			
		
	
		
			
				
					            throw  new  RenException ( String . format ( "根据事件id没有找到记录" , formDTO . getResiEventId ( ) ) ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        // 我自己的发布的才可以
  
			
		
	
		
			
				
					        if ( ! formDTO . getUserId ( ) . equals ( resiEventEntity . getReportUserId ( ) ) ) {  
			
		
	
		
			
				
					            throw  new  RenException ( EpmetErrorCode . RESI_EVENT_NOT_MY_REPORTED . getCode ( ) , EpmetErrorCode . RESI_EVENT_NOT_MY_REPORTED . getMsg ( ) ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        if ( ! EventConstant . EVENT_STATUS_CLOSED_CASE . equals ( resiEventEntity . getStatus ( ) ) ) {  
			
		
	
		
			
				
					            throw  new  RenException ( "事件办结后,才可以选择是否解决,当前状态为:" + resiEventEntity . getStatus ( ) ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        resiEventEntity . setResolveStatus ( formDTO . getResolveStatus ( ) ) ;  
			
		
	
		
			
				
					        resiEventEntity . setUpdatedTime ( new  Date ( ) ) ;  
			
		
	
		
			
				
					        baseDao . updateById ( resiEventEntity ) ;  
			
		
	
		
			
				
					        //2、插入log日志
  
			
		
	
		
			
				
					        ResiEventOperationLogEntity  reCallLog = new  ResiEventOperationLogEntity ( ) ;  
			
		
	
		
			
				
					        reCallLog . setCustomerId ( formDTO . getCustomerId ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setResiEventId ( resiEventEntity . getId ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setUserId ( formDTO . getUserId ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setUserIdentity ( EventConstant . REPORT_USER ) ;  
			
		
	
		
			
				
					        reCallLog . setActionCode ( ResiEventAction . CHOOSE_RESOLVE . getCode ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setActionDesc ( ResiEventAction . CHOOSE_RESOLVE . getDesc ( ) ) ;  
			
		
	
		
			
				
					        reCallLog . setOperateTime ( resiEventEntity . getUpdatedTime ( ) ) ;  
			
		
	
		
			
				
					        resiEventOperationLogDao . insert ( reCallLog ) ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -269,11 +373,11 @@ public class ResiEventServiceImpl extends BaseServiceImpl<ResiEventDao, ResiEven 
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    @Override  
			
		
	
		
			
				
					    public  List < MyReportedResultDTO >  queryMyReported ( MyReportedFormDTO  formDTO )  {  
			
		
	
		
			
				
					        // todo
  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        PageInfo < MyReportedResultDTO >  result  =  PageHelper . startPage ( formDTO . getPageNo ( ) ,  
			
		
	
		
			
				
					                formDTO . getPageSize ( ) ) . doSelectPageInfo ( ( )  - >  baseDao . queryMyReported ( formDTO . getUserId ( ) ,  
			
		
	
		
			
				
					                    formDTO . getStatusCondition ( ) ) ) ;  
			
		
	
		
			
				
					        return  result . getList ( ) ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        return  null ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					}