代码草稿-设备视图

controller

	@ApiOperation("设备视图列表")
    @ApiImplicitParam(name = "Authorization", paramType = "header", required = true)
    @UserLoginRequired
    @GetMapping("search/meter-view")
    public Rs<Page<MeterVo>> searchMeterViewList(
            @ApiParam(value = "设备版本id:1个人版, 2机构版,不传则表示全部") @RequestParam(value = "publicationId", required = false) Integer publicationId,
            @ApiParam(value = "设备类型,不传则表示全部") @RequestParam(value = "meterTypeId", required = false) Integer meterTypeId,
            @ApiParam(value = "设备号") @RequestParam(value = "number", required = false) String number,
            @ApiParam(value = "绑定套餐ID,不传则表示全部") @RequestParam(value = "servicePackageId", required = false) Integer servicePackageId,
            @ApiParam(value = "服务团队ID,不传则表示全部") @RequestParam(value = "serviceTeamId", required = false) Integer serviceTeamId,
            @ApiParam(value = "绑定状态:1未绑定,2已绑定,不传则表示全部") @RequestParam(value = "usage", required = false) Integer usage,
            @ApiParam(value = "检测状态:0未检测,1已检测,不传则表示全部") @RequestParam(value = "checkStatus", required = false) Integer checkStatus,
            @ApiParam(value = "绑定客户端ID,不传则表示全部") @RequestParam(value = "clientId", required = false) String clientId,
            @ApiParam(value = "使用者ID") @RequestParam(value = "customerId", required = false) String customerId,
            @ApiParam(value = "登记批次") @RequestParam(value = "batchId", required = false) Integer batchId,
            @ApiParam(value = "标签") @RequestParam(value = "labelIds", required = false) String labelIds,
            @ApiParam(value = "设备状态:1-启用,2-停用") @RequestParam(value = "status", required = false) Integer status,
            PageParam pageParam
    ) {
        UserAccount userAccount = currentUserAccount();
        return Rs.success(meterService.searchMeterViewList(userAccount, publicationId, meterTypeId, number, servicePackageId, serviceTeamId, usage, checkStatus,
                clientId, customerId, batchId, labelIds, status, pageParam.getCurrent(), pageParam.getPageSize()));
    }

service

	/**
     * 设备试图列表
     * @param publicationId 设备版本id
     * @param meterTypeId 设备类型
     * @param number 设备号
     * @param servicePackageId 绑定套餐ID
     * @param serviceTeamId 服务团队ID
     * @param usage 绑定状态
     * @param checkStatus 检测状态
     * @param clientId 绑定客户端ID
     * @param customerId 使用者ID
     * @param batchId 登记批次
     * @param labelIds 标签列表
     * @param status 设备状态
     * @param page 当前页
     * @param size 页大小
     * @return 设备试图列表
     */

    Opt<Page<MeterVo>> searchMeterViewList( UserAccount userAccount, Integer publicationId, Integer meterTypeId, String number, Integer servicePackageId, Integer serviceTeamId,
                                           Integer usage, Integer checkStatus, String clientId, String customerId, Integer batchId, String labelIds,
                                           Integer status, Integer page, Integer size);

serviceImpl

	@Override
    public Opt<Page<MeterVo>> searchMeterViewList(UserAccount userAccount, Integer publicationId, Integer meterTypeId, String number, Integer servicePackageId, Integer serviceTeamId,
                                                  Integer usage, Integer checkStatus, String clientId, String customerId, Integer batchId,
                                                  String labelIds, Integer status, Integer current, Integer size ) {
        if (current == null) {
            current = 1;
        }
        if (size == null) {
            size = 30;
        }


        StopWatch watch = new StopWatch();
        watch.start("task1");
//        List<MeterEntity> entityList = meterDao.pageMeter(publicationId, meterTypeId, number, servicePackageId, serviceTeamId,
//                usage,checkStatus,clientId, customerId, batchId, labelIds, status, current, size);
        IPage<MeterEntity> entityIPage = meterDao.searchMeterView2(status,publicationId, meterTypeId,  servicePackageId, serviceTeamId,
                usage,checkStatus,clientId, customerId, batchId,number, labelIds, current, size);
        watch.stop();
        log.info("stopWatch--task1:{}", watch.getTotalTimeSeconds());

        List<MeterVo> voList = new ArrayList<>();
        watch.start("task2");
        for (MeterEntity entity : entityIPage.getRecords()) {
            MeterVo meterVo = extractMeterNew(entity);
            voList.add(meterVo);
        }
        watch.stop();
        log.info("stopWatch--task2:{}", watch.getTotalTimeSeconds());

        return Opt.some(new Page<>(voList, (int) entityIPage.getTotal(), (int) entityIPage.getCurrent(), (int) entityIPage.getSize(), (int) entityIPage.getPages()));
    }

extractMeterNew-serviceImpl

	private MeterVo extractMeterNew(MeterEntity entity) {
        
        if (entity == null) {
            return null;
        }
        MeterVo result = new MeterVo();
        BeanUtil.copyProperties(entity, result, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//        result.setMeterModel(meterManagementService.getMeterModel(entity.getMeterModelId()).some());
        result.setMeterModel(meterManagementService.getMeterModelById(entity.getMeterModelId()).some());

//        result.setTenant(tenantService.getTenantInfoById(entity.getTenantId()).some());

        result.setRegisterTime(DateUtil.STANDARD_24H_FORMATTER.format(entity.getRegisterTime()));
        result.setUpdateTime(DateUtil.STANDARD_24H_FORMATTER.format(entity.getUpdateTime()));
        result.setFirstCheckTime(entity.getFirstCheckTime() == null ? null : DateUtil.STANDARD_YMD_HM_FORMATTER.format(entity.getFirstCheckTime()));


        // 检测状态
        if (result.getFirstCheckTime() != null) {
            result.setCheckStatus(1);
        } else {
            result.setCheckStatus(0);
        }
        result.setRecentCheckTime(entity.getRecentCheckTime() == null ? null : DateUtil.STANDARD_YMD_HM_FORMATTER.format(entity.getRecentCheckTime()));
        if (result.getMeterModel().getId() == METER_MODEL_ID) {
            // 是睡眠床垫
            result.setMeterTypeInt(1);
        }

        StopWatch watch = new StopWatch();
        if (entity.getClientType() != null) {
            result.setClient(clientService.getByClientTypeAndClientId(entity.getClientType(), entity.getClientId()).some());
        } else {
            // 没有定义客户端, 采用默认客户端(第一个小程序)
//            String tenantId = String.valueOf(result.getTenant().getId());
            List<Client> clientList = clientTenantService.listByTenantId("", ClientEnum.WECHAT_MA).some();
            if (clientList != null && !clientList.isEmpty()) {
                result.setClient(clientList.get(0));
            }
        }
        if (entity.getNoticeClientType() != null) {
            result.setNoticeClient(clientService.getByClientTypeAndClientId(entity.getNoticeClientType(), entity.getNoticeClientId()).some());
        } else {
            result.setNoticeClient(result.getClient());
        }

        if (!StringUtils.isEmpty(entity.getLabelIds())) {
            result.setLabels(Arrays.stream(entity.getLabelIds().split(",")).map(l -> labelService.getLabel(String.valueOf(entity.getTenantId()), Integer.valueOf(l)).some()).filter(Objects::nonNull).collect(Collectors.toList()));
        }

        result.setChannel(dictService.get(String.valueOf(entity.getTenantId()), DictCategoryEnum.METER_CHANNEL.getCategory(), entity.getChannelId(), null, null));

        if (entity.getServicePackageId() != null) {
//            result.setServicePackage(servePackageService.packageSummary(String.valueOf(entity.getTenantId()), entity.getServicePackageId()).some());
            result.setServicePackage(servePackageService.packageById(String.valueOf(entity.getTenantId()), entity.getServicePackageId()).some());
        }

        if (entity.getServiceTeamId() != null) {
            result.setServiceTeam(serviceTeamService.getServiceTeamById1(entity.getServiceTeamId(), entity.getStatus()).some());
        }

        if (!StringUtils.isEmpty(entity.getOperatorId())) {
            result.setOperator(userManagementService.getUserInfoSummaryById(entity.getOperatorId()).some());
        }

//        watch.start("setMaintainCustomerInfo");
//        if (!StringUtils.isEmpty(entity.getMaintainCustomer())) {
//            result.setMaintainCustomerInfo(customerInfoService.getCustomerInfo(String.valueOf(entity.getTenantId()), entity.getMaintainCustomer()).some());
//        }
//        watch.stop();
//        log.info("stopWatch--setMaintainCustomerInfo:{}", watch.getTotalTimeSeconds());

        // 设备使用者
        Opt<List<MeterButton>> meterButtonListOpt = getMeterBinder(entity.getTenantId()+"", entity.getId());
        if (meterButtonListOpt.getSome() != null && !meterButtonListOpt.getSome().isEmpty()) {
            // 有使用者时则为已绑定
            result.setUsage(2);
//            meterButtonListOpt.getSome().forEach(meterButton -> {
//                if (result.getMeterModel().getType().getId() == 5) {
//                    // 腕表 首次检测时间 & 检测次数
                    meterButton.setCheckTimes(watchService.getCheckTimes(String.valueOf(entity.getTenantId()), entity.getNumber(), meterButton.getCustomer().getId()));
                    LocalDateTime firstTime = watchService.getFirstCheckTime(String.valueOf(entity.getTenantId()), entity.getNumber(), meterButton.getCustomer().getId());
                    if (firstTime != null) {
                        meterButton.setFirstCheckTime(DateUtil.STANDARD_YMD_HM_FORMATTER.format(firstTime));
                    }
//                } else {
//                    // 首次检测时间 & 检测次数
                    meterButton.setCheckTimes(customerMeterMeasurementDao.countCheckTimesByMeterAndCustomer(meterButton.getMeterId(), meterButton.getCustomer().getId()));
                    CustomerMeterMeasurementEntity customerMeterMeasurementEntity = customerMeterMeasurementDao.getFirstCheck(meterButton.getMeterId(), meterButton.getCustomer().getId());
                    if (customerMeterMeasurementEntity != null) {
                        meterButton.setFirstCheckTime(DateUtil.STANDARD_YMD_HM_FORMATTER.format(customerMeterMeasurementEntity.getOptTime()));
                    }
//                }
//            });
            result.setMeterButtonList(meterButtonListOpt.getSome());
        } else {
            result.setUsage(1);
        }
        return result;
    }

dao

IPage<MeterEntity> searchMeterView2( Integer status, Integer publicationId, Integer meterTypeId, Integer servicePackageId, Integer serviceTeamId,
                                       Integer usage, Integer checkStatus, String clientId, String customerId, Integer batchId, String number,
                                       String labelIds, Integer page, Integer size);

daoImpl

	@Override
    public IPage<MeterEntity> searchMeterView2(Integer status, Integer publicationId, Integer meterTypeId, Integer servicePackageId, Integer serviceTeamId,
                                              Integer usage, Integer checkStatus, String clientId, String customerId, Integer batchId, String number,
                                              String labelIds, Integer page, Integer size ) {
        page = page == null ? 1 : page;
        size = size == null ? 1000 : size;
        return baseMapper.searchMeterView2(new Page<>(page, size), status, publicationId, meterTypeId, servicePackageId, serviceTeamId, usage, checkStatus, clientId, batchId, number, labelIds, customerId);
    }

mapper

IPage<MeterEntity> searchMeterView2(Page<MeterEntity> page,
	   @Param("status") Integer status,
	   @Param("publicationId") Integer publicationId,
	   @Param("meterTypeId") Integer meterTypeId,
	   @Param("servicePackageId") Integer servicePackageId,
	   @Param("serviceTeamId") Integer serviceTeamId,
	   @Param("usage") Integer usage,
	   @Param("checkStatus") Integer checkStatus,
	   @Param("clientId") String clientId,
	   @Param("batchId") Integer batchId,
	   @Param("number") String number,
	   @Param("labelIds") String labelIds,
	   @Param("customerId") String customerId);

xml

<select id="searchMeterView2" resultMap="BaseResultMap">
        SELECT m.* FROM meter m
        LEFT JOIN meter_model mm ON m.meter_model_id = mm.id
        <if test="customerId != null and customerId != ''">
            LEFT JOIN customer_meter cm ON cm.meter_id = m.id
        </if>
        WHERE 1 = 1
        <if test="customerId != null and customerId != ''">
            AND cm.customer_id = #{customerId}
        </if>
        <if test="status != null">
            AND m.status = #{status}
        </if>
        <if test="publicationId != null">
            AND m.publication_id = #{publicationId}
        </if>
        <if test="meterTypeId != null">
            AND mm.meter_type_id = #{meterTypeId}
        </if>
        <if test="servicePackageId != null">
            AND m.service_package_id = #{servicePackageId}
        </if>
        <if test="serviceTeamId != null">
            AND m.service_team_id = #{serviceTeamId}
        </if>
        <if test="usage != null">
            and m.`usage` = #{usage}
        </if>
        <if test="checkStatus != null">
            AND m.check_status = #{checkStatus}
        </if>
        <if test="clientId != null">
            AND m.client_id = #{clientId}
        </if>
        <if test="batchId != null">
            AND m.batch_id = #{batchId}
        </if>
        <if test="number != null and number != ''">
            AND m.number like concat('%', #{number}, '%')
        </if>
        <if test="labelIds != null and labelIds != ''">
            AND FIND_IN_SET(#{labelIds}, m.label_ids)
        </if>
        ORDER BY update_time DESC

    </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值