关于数据源为授权车辆、企业车辆的判断(限foton)

int mode = carInfoService.getCompanyCarMode(companyId);

public int getCompanyCarMode(Long companyId) {
        String sql = "select t.id from iov_biz_car_info t join iov_biz_device d on d.iov_biz_car_info_id = t.id and d.is_primary = 1 where d.cbm_mag_company_id = ? and rownum = 1";
        List<Number> create = findBySQL(sql, new Object[] { companyId });
        sql = "select t.id from iov_biz_car_info t join iov_biz_device d on d.iov_biz_car_info_id = t.id and d.is_primary = 1 join iov_biz_l_car_info_company lc on lc.iov_biz_car_info_id =t.id where lc.cbm_mag_company_id = ? and rownum = 1";
        List<Number> link = findBySQL(sql, new Object[] { companyId });
        if (create.size() > 0 && link.size() < 1) {//本企业
            return 1;
        }
        if (create.size() < 1 && link.size() > 0) {//授权
            return 2;
        }
        return 0;
    }

objectList = getService().findCountGroupByProvince(companyId, companyIds, posIds, mode);

public List<Object[]> findCountByProvince(Long companyId, List<Long> companyIds, List<Long> posIds, int carMode) {
        Map<String, Object> params = Maps.newHashMap();
        StringBuilder hql = new StringBuilder();
        hql.append("select t.province, count(distinct t.id) as count from ");
        hql.append(Device.class.getName()).append(" t inner join t.carInfo t10 left join t10.companies t3 ");
        if (CollectionUtils.isNotEmpty(posIds)) {
            hql.append(" join t10.positions t2 ");
        }
        hql.append(" where 1=1 ");
        switch (carMode) {
        case 1:
            hql.append(" and t.company.id in (:companyIds) ");
            params.put("companyIds", companyIds);
            break;
        case 2:
            hql.append(" and t3.id =:companyId ");
            params.put("companyId", companyId);
            break;
        default:
            hql.append(" and (t.company.id in (:companyIds) or t3.id =:companyId)  ");
            params.put("companyId", companyId);
            params.put("companyIds", companyIds);
            break;
        }
        if (CollectionUtils.isNotEmpty(posIds)) {
            hql.append(" and t2.id in (:posIds) ");
            params.put("posIds", posIds);
        }
        hql.append(" and t.primary=1 group by t.province order by count(distinct t.id) desc");
        return findByNamedParam(hql.toString(), params);
    }

 

posted @ 2020-05-19 10:35  蔡徐坤1987  阅读(172)  评论(0编辑  收藏  举报