package com.java110.user.cmd.owner;
|
|
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.owner.OwnerAppUserDto;
|
import com.java110.dto.owner.OwnerCarDto;
|
import com.java110.dto.owner.OwnerDto;
|
import com.java110.intf.user.*;
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
import java.text.ParseException;
|
import java.util.List;
|
|
@Java110Cmd(serviceCode = "owner.appDeleteMemberCar")
|
public class AppDeleteMemberCarCmd extends Cmd {
|
|
@Autowired
|
private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
|
|
@Autowired
|
private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
|
|
@Autowired
|
private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
|
|
@Autowired
|
private IOwnerCarV1InnerServiceSMO ownerCarV1InnerServiceSMOImpl;
|
|
@Override
|
public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
|
String userId = context.getReqHeaders().get("user-id");
|
|
OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
|
ownerAppUserDto.setUserId(userId);
|
ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
|
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());
|
Assert.jsonObjectHaveKey(reqJson, "carMemberId", "请求报文中未包含carMemberId");
|
Assert.jsonObjectHaveKey(reqJson, "communityId", "请求报文中未包含communityId");
|
|
|
OwnerCarDto ownerCarDto = new OwnerCarDto();
|
ownerCarDto.setMemberId(reqJson.getString("carMemberId"));
|
ownerCarDto.setCommunityId(reqJson.getString("communityId"));
|
ownerCarDto.setOwnerId(reqJson.getString("ownerId"));
|
ownerCarDto.setCarTypeCds(new String[]{OwnerCarDto.CAR_TYPE_PRIMARY, OwnerCarDto.CAR_TYPE_MEMBER}); // 临时车除外
|
List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
|
|
Assert.listOnlyOne(ownerCarDtos, "当前未找到需要删除车辆");
|
}
|
|
@Override
|
@Java110Transactional
|
public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
|
OwnerCarPo ownerCarPo = new OwnerCarPo();
|
ownerCarPo.setCommunityId(reqJson.getString("communityId"));
|
ownerCarPo.setMemberId(reqJson.getString("carMemberId"));
|
int flag = ownerCarV1InnerServiceSMOImpl.deleteOwnerCar(ownerCarPo);
|
if (flag < 1) {
|
throw new IllegalArgumentException("删除车辆出错");
|
}
|
}
|
}
|