chengf
2025-07-17 7f3372fe96d927debd388a0cb285a45e6b952296
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.java110.user.cmd.owner;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.IotDataDto;
import com.java110.dto.owner.OwnerAppUserDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.owner.OwnerDto;
import com.java110.intf.job.IIotInnerServiceSMO;
import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.intf.user.IOwnerCarV1InnerServiceSMO;
import com.java110.intf.user.IOwnerV1InnerServiceSMO;
import com.java110.po.car.OwnerCarPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.ListUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
 
import java.text.ParseException;
import java.util.List;
 
/**
 * 业主自己修改车牌号
 */
@Java110Cmd(serviceCode = "owner.appEditSelfCarNum")
public class AppEditSelfCarNumCmd extends Cmd {
 
    @Autowired
    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
 
    @Autowired
    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
 
    @Autowired
    private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
 
    @Autowired
    private IIotInnerServiceSMO iotInnerServiceSMOImpl;
 
    @Autowired
    private IOwnerCarV1InnerServiceSMO ownerCarV1InnerServiceSMOImpl;
 
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        Assert.hasKeyAndValue(reqJson, "carId", "未包含carId");
        Assert.hasKeyAndValue(reqJson, "carNum", "未包含carNum");
        Assert.hasKeyAndValue(reqJson, "newCarNum", "未包含newCarNum");
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含communityId");
 
        String userId = context.getReqHeaders().get("user-id");
 
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setUserId(userId);
        ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
        ownerAppUserDto.setMemberId(reqJson.getString("memberId"));
        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
 
        if (ListUtil.isNull(ownerAppUserDtos)) {
            throw new CmdException("未绑定业主");
        }
 
        String memberId = "";
        for (OwnerAppUserDto tmpOwnerAppUserDto : ownerAppUserDtos) {
            if ("-1".equals(tmpOwnerAppUserDto.getMemberId())) {
                continue;
            }
            memberId = tmpOwnerAppUserDto.getMemberId();
        }
 
        if (StringUtil.isEmpty(memberId)) {
            throw new CmdException("未绑定业主");
        }
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(reqJson.getString("communityId"));
        ownerDto.setMemberId(memberId);
        List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
 
        Assert.listOnlyOne(ownerDtos, "业主不存在");
 
        reqJson.put("ownerId", ownerDtos.get(0).getOwnerId());
    }
 
    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
 
        OwnerCarDto ownerCarDto = new OwnerCarDto();
        ownerCarDto.setCarId(reqJson.getString("carId"));
        ownerCarDto.setOwnerId(reqJson.getString("ownerId"));
        ownerCarDto.setCarNum(reqJson.getString("carNum"));
 
        List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
 
        if (ListUtil.isNull(ownerCarDtos)) {
            throw new CmdException("车辆不存在");
        }
 
        //todo 校验车辆是否场外
        if (hasInParkingArea(ownerCarDtos.get(0).getCarNum(), ownerCarDtos.get(0).getAreaNum(), ownerCarDtos.get(0).getCommunityId())) {
            throw new CmdException(ownerCarDtos.get(0).getCarNum() + "车在场,请先出场");
        }
        //todo 校验新车辆是否场外
        if (hasInParkingArea(reqJson.getString("newCarNum"), ownerCarDtos.get(0).getAreaNum(), ownerCarDtos.get(0).getCommunityId())) {
            throw new CmdException(ownerCarDtos.get(0).getCarNum() + "车在场,请先出场");
        }
 
        OwnerCarPo ownerCarPo = new OwnerCarPo();
        ownerCarPo.setMemberId(ownerCarDtos.get(0).getMemberId());
        ownerCarPo.setCarId(ownerCarDtos.get(0).getCarId());
        ownerCarPo.setCarNum(reqJson.getString("newCarNum"));
        ownerCarPo.setCommunityId(reqJson.getString("communityId"));
 
 
        ownerCarV1InnerServiceSMOImpl.updateOwnerCar(ownerCarPo);
 
    }
 
    private boolean hasInParkingArea(String carNum, String areaNum, String communityId) {
 
        JSONObject paramIn = new JSONObject();
        paramIn.put("communityId", communityId);
        paramIn.put("page", 1);
        paramIn.put("row", 1);
        paramIn.put("paNum", areaNum);
        paramIn.put("carNum",carNum);
 
        ResultVo resultVo = iotInnerServiceSMOImpl.postIotData(new IotDataDto("listCarInParkingAreaBmoImpl", paramIn));
 
        if (resultVo.getCode() != ResultVo.CODE_OK) {
            return true;
        }
 
        JSONArray data = (JSONArray) resultVo.getData();
 
        if (ListUtil.isNull(data)) {
            return false;
        }
 
        return true;
    }
}