forked from rongchao/epmet-cloud-rizhao
				
			
				 18 changed files with 434 additions and 1 deletions
			
			
		@ -0,0 +1,69 @@ | 
				
			|||
package com.epmet.dataaggre.dto.epmetuser.form; | 
				
			|||
 | 
				
			|||
import lombok.AllArgsConstructor; | 
				
			|||
import lombok.Data; | 
				
			|||
import lombok.NoArgsConstructor; | 
				
			|||
 | 
				
			|||
import java.util.Comparator; | 
				
			|||
import java.util.Map; | 
				
			|||
import java.util.Set; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
@NoArgsConstructor | 
				
			|||
@AllArgsConstructor | 
				
			|||
public class ResisByPolicyRulesFormDTO { | 
				
			|||
 | 
				
			|||
    private Integer pageNo = 1; | 
				
			|||
    private Integer pageSize = 20; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 规则map | 
				
			|||
     */ | 
				
			|||
    private Map<String, Set<PolicyRule>> rules; | 
				
			|||
 | 
				
			|||
    @Data | 
				
			|||
    @NoArgsConstructor | 
				
			|||
    @AllArgsConstructor | 
				
			|||
    public static class PolicyRule implements Comparator<Integer> { | 
				
			|||
        private String customerId; | 
				
			|||
        /** | 
				
			|||
         * resi:人员信息,house:房屋信息,stat:统计信息 | 
				
			|||
         */ | 
				
			|||
        private String groupType; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 与上一条的关系;and、or | 
				
			|||
         */ | 
				
			|||
        private String lastLogicalRel; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 查询类型:等于、不等于....;来源于字典表sql_query_type | 
				
			|||
         */ | 
				
			|||
        private String queryType; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 表名;人员信息有值; | 
				
			|||
         */ | 
				
			|||
        private String colTable; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 人员信息存储组件对应的列名;房屋信息存储ic_house表的列名;统计信息应该是定义到字典表,这里存储字典key就行吧 | 
				
			|||
         */ | 
				
			|||
        private String colKey; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 参数值 | 
				
			|||
         */ | 
				
			|||
        private String colVal; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 排序字段;同一group_type升序 | 
				
			|||
         */ | 
				
			|||
        private Integer sort; | 
				
			|||
 | 
				
			|||
        @Override | 
				
			|||
        public int compare(Integer o1, Integer o2) { | 
				
			|||
            return o1.compareTo(o2); | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,21 @@ | 
				
			|||
package com.epmet.dataaggre.dto.epmetuser.result; | 
				
			|||
 | 
				
			|||
import lombok.AllArgsConstructor; | 
				
			|||
import lombok.Data; | 
				
			|||
import lombok.NoArgsConstructor; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
@NoArgsConstructor | 
				
			|||
@AllArgsConstructor | 
				
			|||
public class ResiInfoResultDTO { | 
				
			|||
 | 
				
			|||
    private String name; | 
				
			|||
    private String mobile; | 
				
			|||
    private String idCard; | 
				
			|||
    /** | 
				
			|||
     * 小区全名,包含小区前面的属性,比如网格等 | 
				
			|||
     */ | 
				
			|||
    private String neighborhoodFullName; | 
				
			|||
    private Integer age; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,24 @@ | 
				
			|||
package com.epmet.dataaggre.service; | 
				
			|||
 | 
				
			|||
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; | 
				
			|||
import com.epmet.dataaggre.dto.epmetuser.result.ResiInfoResultDTO; | 
				
			|||
 | 
				
			|||
import java.util.List; | 
				
			|||
import java.util.Set; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 居民的service | 
				
			|||
 */ | 
				
			|||
public interface ResiService { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 政策人员预览 | 
				
			|||
     * @param pageNo | 
				
			|||
     * @param pageSize | 
				
			|||
     * @param resiRule | 
				
			|||
     * @param houseRule | 
				
			|||
     */ | 
				
			|||
    List<ResiInfoResultDTO> listByPolicyRules(Integer pageNo, Integer pageSize, Set<ResisByPolicyRulesFormDTO.PolicyRule> resiRule, | 
				
			|||
                                              Set<ResisByPolicyRulesFormDTO.PolicyRule> houseRule, | 
				
			|||
                                              Set<ResisByPolicyRulesFormDTO.PolicyRule> houseStat); | 
				
			|||
} | 
				
			|||
@ -0,0 +1,74 @@ | 
				
			|||
package com.epmet.dataaggre.service.impl; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.utils.EpmetRequestHolder; | 
				
			|||
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; | 
				
			|||
import com.epmet.dataaggre.dto.epmetuser.result.ResiInfoResultDTO; | 
				
			|||
import com.epmet.dataaggre.entity.govorg.IcHouseEntity; | 
				
			|||
import com.epmet.dataaggre.service.ResiService; | 
				
			|||
import com.epmet.dataaggre.service.epmetuser.EpmetUserService; | 
				
			|||
import com.epmet.dataaggre.service.govorg.GovOrgService; | 
				
			|||
import org.apache.commons.collections4.CollectionUtils; | 
				
			|||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			|||
import org.springframework.stereotype.Service; | 
				
			|||
 | 
				
			|||
import java.util.ArrayList; | 
				
			|||
import java.util.List; | 
				
			|||
import java.util.Set; | 
				
			|||
import java.util.stream.Collectors; | 
				
			|||
 | 
				
			|||
@Service | 
				
			|||
public class ResiServiceImpl implements ResiService { | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private EpmetUserService epmetUserService; | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private GovOrgService govOrgService; | 
				
			|||
 | 
				
			|||
    @Override | 
				
			|||
    public List<ResiInfoResultDTO> listByPolicyRules(Integer pageNo, Integer pageSize, | 
				
			|||
                                  Set<ResisByPolicyRulesFormDTO.PolicyRule> resiRule, | 
				
			|||
                                  Set<ResisByPolicyRulesFormDTO.PolicyRule> houseRule, | 
				
			|||
                                  Set<ResisByPolicyRulesFormDTO.PolicyRule> houseStat) { | 
				
			|||
        String customerId = EpmetRequestHolder.getLoginUserCustomerId(); | 
				
			|||
 | 
				
			|||
        // 结果集
 | 
				
			|||
        List<ResiInfoResultDTO> resultResis = new ArrayList<>(); | 
				
			|||
 | 
				
			|||
        int housePageNo = 0; | 
				
			|||
        do { | 
				
			|||
            // houseIds 为null,说明用户没有指定house和统计的规则,则不应该使用这两项来查询,sql中不应该有这方面的条件
 | 
				
			|||
            List<String> houseIds = null; | 
				
			|||
 | 
				
			|||
            // 拿到房屋id列表,去查询居民列表
 | 
				
			|||
            if (CollectionUtils.isNotEmpty(houseRule) || CollectionUtils.isNotEmpty(houseStat)) { | 
				
			|||
                List<IcHouseEntity> houseEntities = govOrgService.listHousesByRules(houseRule, houseStat, housePageNo, 50); | 
				
			|||
                houseIds = houseEntities.stream().map(icHouseEntity -> icHouseEntity.getId()).collect(Collectors.toList()); | 
				
			|||
            } | 
				
			|||
 | 
				
			|||
            if (houseIds != null && houseIds.size() == 0) { | 
				
			|||
                // 用户使用了房屋和统计相关的条件,但是没查到房屋,我看就没有走下去了的必要了吧..
 | 
				
			|||
                break; | 
				
			|||
            } | 
				
			|||
 | 
				
			|||
            // 查询居民
 | 
				
			|||
            List<ResiInfoResultDTO> resis = epmetUserService.listByPolicyRules(customerId, resiRule, houseIds); | 
				
			|||
            resultResis.addAll(resis); | 
				
			|||
 | 
				
			|||
            // 满了20个,或者查不到居民和房屋了(数据空了),则跳出
 | 
				
			|||
            // 没有用house的条件,没有循环的必要,查一次居民信息即可,跳出
 | 
				
			|||
            if (resultResis.size() >= pageSize || houseIds == null ) { | 
				
			|||
                break; | 
				
			|||
            } | 
				
			|||
 | 
				
			|||
            housePageNo ++; | 
				
			|||
        } while (true); | 
				
			|||
 | 
				
			|||
        // 够了20个,那就截取前20个,否则直接返回
 | 
				
			|||
        if (resultResis.size() > 20) { | 
				
			|||
            return resultResis.subList(0, 20); | 
				
			|||
        } | 
				
			|||
        return resultResis; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,69 @@ | 
				
			|||
package com.epmet.dto.form.resi; | 
				
			|||
 | 
				
			|||
import lombok.AllArgsConstructor; | 
				
			|||
import lombok.Data; | 
				
			|||
import lombok.NoArgsConstructor; | 
				
			|||
 | 
				
			|||
import java.util.Comparator; | 
				
			|||
import java.util.Map; | 
				
			|||
import java.util.Set; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
@NoArgsConstructor | 
				
			|||
@AllArgsConstructor | 
				
			|||
public class HeartResisByPolicyRulesFormDTO { | 
				
			|||
 | 
				
			|||
    private Integer pageNo = 1; | 
				
			|||
    private Integer pageSize = 20; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 规则map | 
				
			|||
     */ | 
				
			|||
    private Set<PolicyRule> rules; | 
				
			|||
 | 
				
			|||
    @Data | 
				
			|||
    @NoArgsConstructor | 
				
			|||
    @AllArgsConstructor | 
				
			|||
    public static class PolicyRule implements Comparator<Integer> { | 
				
			|||
        private String customerId; | 
				
			|||
        /** | 
				
			|||
         * resi:人员信息,house:房屋信息,stat:统计信息 | 
				
			|||
         */ | 
				
			|||
        private String groupType; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 与上一条的关系;and、or | 
				
			|||
         */ | 
				
			|||
        private String lastLogicalRel; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 查询类型:等于、不等于....;来源于字典表sql_query_type | 
				
			|||
         */ | 
				
			|||
        private String queryType; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 表名;人员信息有值; | 
				
			|||
         */ | 
				
			|||
        private String colTable; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 人员信息存储组件对应的列名;房屋信息存储ic_house表的列名;统计信息应该是定义到字典表,这里存储字典key就行吧 | 
				
			|||
         */ | 
				
			|||
        private String colKey; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 参数值 | 
				
			|||
         */ | 
				
			|||
        private String colVal; | 
				
			|||
 | 
				
			|||
        /** | 
				
			|||
         * 排序字段;同一group_type升序 | 
				
			|||
         */ | 
				
			|||
        private Integer sort; | 
				
			|||
 | 
				
			|||
        @Override | 
				
			|||
        public int compare(Integer o1, Integer o2) { | 
				
			|||
            return o1.compareTo(o2); | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue