zhongrj
2024-02-20 19dd4271eeffa8ae57b8529f8b5e327fbf1b8d97
出租屋查询先调整
3 files modified
183 ■■■■■ changed files
src/main/java/org/springblade/modules/house/mapper/HouseRentalMapper.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/house/mapper/HouseRentalMapper.xml 82 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java 99 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/house/mapper/HouseRentalMapper.java
@@ -44,7 +44,7 @@
     */
    List<HouseRentalTenantVO> selectHouseRentalPage(IPage page,
                                                    @Param("vo") HouseRentalTenantVO houseRental,
                                                    @Param("list") List<String> list,
                                                    @Param("gridCodeList") List<String> gridCodeList,
                                                    @Param("regionChildCodesList") List<String> regionChildCodesList,
                                                    @Param("isAdministrator") Integer isAdministrator);
src/main/java/org/springblade/modules/house/mapper/HouseRentalMapper.xml
@@ -54,18 +54,81 @@
            jczz_house_rental
    </sql>
    <sql id="filterData">
        <if test="isAdministrator==2">
            <choose>
                <when test="vo.roleName != null and vo.roleName != ''">
                    <if test="vo.roleName=='wgy'">
                        <choose>
                            <when test="gridCodeList !=null and gridCodeList.size()>0">
                                and jp.grid_code in
                                <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                            </when>
                            <otherwise>
                                and jp.grid_code in ('')
                            </otherwise>
                        </choose>
                    </if>
                    <if test="vo.roleName=='mj'">
                        <choose>
                            <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                and jpag.community_code in
                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                            </when>
                            <otherwise>
                                and jpag.community_code in ('')
                            </otherwise>
                        </choose>
                    </if>
                </when>
                <otherwise>
                    <choose>
                        <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                            and
                            (
                            jg.grid_code in
                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                #{code}
                            </foreach>
                            or
                            jpag.community_code in
                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                #{code}
                            </foreach>
                            )
                        </when>
                        <otherwise>
                            and
                            (
                            jg.grid_code in ('') or jpag.community_code in in ('')
                            )
                        </otherwise>
                    </choose>
                </otherwise>
            </choose>
        </if>
    </sql>
    <!--自定义列表查询-->
    <select id="selectHouseRentalPage" resultType="org.springblade.modules.house.vo.HouseRentalTenantVO">
        SELECT jhr.*,jda.address_name as houseName,b.tenantName,b.phone,
        SELECT
        jhr.*,
        jh.address as houseName,
        b.tenantName,
        b.phone,
        concat(jh.district_name," ",jh.building," ",unit," ",room) as address,
        case when TIMESTAMPDIFF( MONTH, jhr.rental_time, jhr.due_time )&gt;= 8 then 1
             when TIMESTAMPDIFF( MONTH, jhr.rental_time, jhr.due_time )&lt;4 then 3
             else 2 end as dldType,
        if(jhr.termination_time is null,if(date_format(jhr.due_time,'%Y-%m-%d') >= date_format(now(),'%Y-%m-%d'),0,1),2) as status
        FROM jczz_house_rental jhr
        JOIN jczz_doorplate_address jda ON jda.address_code = jhr.house_code
        JOIN jczz_house jh ON jh.house_code = jhr.house_code and jh.is_deleted = 0
        LEFT JOIN jczz_grid jg on jg.grid_code = jh.grid_code and jg.is_deleted = 0
        LEFT JOIN jczz_police_affairs_grid jpag on jh.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
        LEFT JOIN (
            SELECT jht.housing_rental_id,jht.name as tenantName,jht.phone_number as phone
            FROM jczz_household jht RIGHT JOIN (
@@ -125,20 +188,7 @@
        <if test="vo.startTime != null and vo.startTime != '' and vo.endTime != null and vo.endTime != '' ">
            AND jhr.create_time BETWEEN #{vo.startTime} and #{vo.endTime}
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                    and jg.community_code in
                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
                <otherwise>
                    and jg.community_code in ('')
                </otherwise>
            </choose>
        </if>
        <include refid="filterHouseGrid"/>
        <include refid="filterData"/>
        order by jhr.create_time desc,jhr.id desc
    </select>
src/main/java/org/springblade/modules/house/service/impl/HouseRentalServiceImpl.java
@@ -22,6 +22,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springblade.common.cache.SysCache;
import org.springblade.common.param.CommonParamSet;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.grid.service.IGridService;
@@ -72,21 +73,16 @@
     */
    @Override
    public IPage<HouseRentalTenantVO> selectHouseRentalPage(IPage<HouseRentalTenantVO> page, HouseRentalTenantVO houseRental) {
        List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
        Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2;
        List<String> list = new ArrayList<>();
        if (null!=houseRental.getRoleName() && !houseRental.getRoleName().equals("")){
            if (houseRental.getRoleName().equals("网格员")){
                // 查询对应的房屋地址code
                list = gridService.getAddressCodeListByUserId(AuthUtil.getUserId());
            }
        }
        if (null!=houseRental.getAuditStatus()){
            if (houseRental.getAuditStatus()==0){
                houseRental.setAuditStatus(2);
            }
        }
        List<HouseRentalTenantVO> houseRentalTenantVOS = baseMapper.selectHouseRentalPage(page, houseRental, list,regionChildCodesList,isAdministrator);
        CommonParamSet<Object> commonParamSet = new CommonParamSet<>().invoke(HouseRentalTenantVO.class, houseRental);
        List<HouseRentalTenantVO> houseRentalTenantVOS = baseMapper.selectHouseRentalPage(page, houseRental,
            commonParamSet.getGridCodeList(),
            commonParamSet.getRegionChildCodesList(),
            commonParamSet.getIsAdministrator());
        for (HouseRentalTenantVO houseRentalTenantVO : houseRentalTenantVOS) {
            if(houseRentalTenantVO.getStatus().equals(1)){
                houseRentalTenantVO.setStatus(30);
@@ -127,50 +123,67 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean add(HouseRentalVO houseRentalVO) {
        boolean flag = false;
        houseRentalVO.setCreateUser(AuthUtil.getUserId());
        houseRentalVO.setCreateTime(new Date());
        houseRentalVO.setUpdateUser(AuthUtil.getUserId());
        houseRentalVO.setUpdateTime(new Date());
        // 网格员新增默认是审核通过
        houseRentalVO.setAuditStatus(1);
        if (!Strings.isBlank(houseRentalVO.getRoleName()) && houseRentalVO.getRoleName().equals("居民")){
        // 获取请求头中的角色别名
        String roleName = SpringUtils.getRequestParam("roleName");
        // 居民
        if (!Strings.isBlank(roleName) && roleName.equals("inhabitant")){
            // 待审核
            houseRentalVO.setAuditStatus(0);
        }
        //保存自身
        boolean save = save(houseRentalVO);
        List<String> phoneList = new ArrayList<>();
        List<HouseholdEntity> householdEntityList = new ArrayList<>();
        houseRentalVO.getHouseholdVOList().forEach(e -> {
            e.setHouseCode(houseRentalVO.getHouseCode());
            e.setHousingRentalId(houseRentalVO.getId());
            e.setRelationship(18);
            e.setResidentialStatus(1);
            e.setRoleType(2);
            householdEntityList.add(e);
            phoneList.add(e.getPhoneNumber());
        });
        try {
            // 查询租户是否网格员身份的,给网格员设置居民角色
            IUserService bean = SpringUtils.getBean(IUserService.class);
            String str = "1717429261910528001";
            List<User> list = bean.list(Wrappers.<User>lambdaQuery()
                .in(User::getPhone, phoneList)
                .like(User::getRoleId, str));
            for (User user : list) {
                boolean contains = user.getRoleId().contains("1717429059648606209");
                if (contains) {
                    continue;
                }
                user.setRoleId(user.getRoleId() + ",1717429059648606209");
            }
            bean.updateBatchById(list);
        } catch (Exception e) {
            log.error("保存用户角色为居民:", e);
        }
        boolean saveBatch = iHouseholdService.saveBatch(householdEntityList);
        flag = save(houseRentalVO);
        //保存到住户
        flag = saveHousehold(houseRentalVO, flag);
        return flag;
    }
        return save && saveBatch;
    /**
     * 保存租户信息
     * @param houseRentalVO
     * @param flag
     * @return
     */
    public boolean saveHousehold(HouseRentalVO houseRentalVO, boolean flag) {
        if (flag && houseRentalVO.getHouseholdVOList().size()>0) {
            List<String> phoneList = new ArrayList<>();
            List<HouseholdEntity> householdEntityList = new ArrayList<>();
            houseRentalVO.getHouseholdVOList().forEach(e -> {
                e.setHouseCode(houseRentalVO.getHouseCode());
                e.setHousingRentalId(houseRentalVO.getId());
                e.setRelationship(18);
                e.setResidentialStatus(1);
                e.setRoleType(2);
                householdEntityList.add(e);
                phoneList.add(e.getPhoneNumber());
            });
            try {
                // 查询租户是否网格员身份的,给网格员设置居民角色
                IUserService bean = SpringUtils.getBean(IUserService.class);
                String str = "1717429261910528001";
                List<User> list = bean.list(Wrappers.<User>lambdaQuery()
                    .in(User::getPhone, phoneList)
                    .like(User::getRoleId, str));
                for (User user : list) {
                    boolean contains = user.getRoleId().contains("1717429059648606209");
                    if (contains) {
                        continue;
                    }
                    user.setRoleId(user.getRoleId() + ",1717429059648606209");
                }
                bean.updateBatchById(list);
            } catch (Exception e) {
                log.error("保存用户角色为居民:", e);
            }
            flag  = iHouseholdService.saveBatch(householdEntityList);
        }
        return flag;
    }
    /**