doum
3 天以前 3c7399c25c0f35c8aa7cb6af1935e31d1a3f0102
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.doumee.service.business.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwElectricalActionsMapper;
import com.doumee.dao.business.model.YwElectrical;
import com.doumee.dao.business.model.YwElectricalActions;
import com.doumee.service.business.YwElectricalActionsService;
import com.doumee.service.business.YwElectricalBizService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Objects;
 
/**
 * 电表远程操作记录 Service 实现
 */
@Service
public class YwElectricalActionsServiceImpl implements YwElectricalActionsService {
 
    @Autowired
    private YwElectricalActionsMapper ywElectricalActionsMapper;
    @Autowired
    private YwElectricalBizService ywElectricalBizService;
 
    @Override
    public PageData<YwElectricalActions> findPage(PageWrap<YwElectricalActions> pageWrap) {
        IPage<YwElectricalActions> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        YwElectricalActions model = pageWrap.getModel() == null ? new YwElectricalActions() : pageWrap.getModel();
        Utils.MP.blankToNull(model);
 
        MPJLambdaWrapper<YwElectricalActions> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(YwElectricalActions.class)
                .selectAs(YwElectrical::getName, YwElectricalActions::getElectricalName)
                .selectAs(YwElectrical::getAddress, YwElectricalActions::getElectricalAddress)
                .leftJoin(YwElectrical.class, YwElectrical::getId, YwElectricalActions::getElectricalId)
                .eq(YwElectricalActions::getIsdeleted, Constants.ZERO);
 
        if (model.getActionType() != null) {
            queryWrapper.eq(YwElectricalActions::getActionType, model.getActionType());
        }
        if (model.getElectricalId() != null) {
            queryWrapper.eq(YwElectricalActions::getElectricalId, model.getElectricalId());
        }
        if (model.getOperateTimeBegin() != null) {
            queryWrapper.ge(YwElectricalActions::getCreateDate, Utils.Date.getStart(model.getOperateTimeBegin()));
        }
        if (model.getOperateTimeEnd() != null) {
            queryWrapper.le(YwElectricalActions::getCreateDate, Utils.Date.getEnd(model.getOperateTimeEnd()));
        }
 
        queryWrapper.orderByDesc(YwElectricalActions::getId);
        IPage<YwElectricalActions> result = ywElectricalActionsMapper.selectJoinPage(page, YwElectricalActions.class, queryWrapper);
        return PageData.from(result);
    }
 
    @Override
    public String queryAsyncResult(Integer id) {
        if (id == null) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        YwElectricalActions act = ywElectricalActionsMapper.selectById(id);
        if (act == null || Objects.equals(act.getIsdeleted(), Constants.ONE)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "操作记录不存在");
        }
        if (!Objects.equals(act.getStatus(), Constants.ZERO)) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "仅处理中记录可查询");
        }
        if (StringUtils.isBlank(act.getOprId())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "缺少任务 ID");
        }
        return ywElectricalBizService.syncAsyncActionStatus(act.getOprId().trim());
    }
}