Blame view

service-user/src/main/java/com/java110/user/cmd/owner/ChangeOwnerCarCmd.java 3.37 KB
88e030b7   王彪总   init project
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
  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.OwnerCarDto;
  import com.java110.dto.owner.OwnerDto;
  import com.java110.intf.user.IOwnerCarV1InnerServiceSMO;
  import com.java110.intf.user.IOwnerInnerServiceSMO;
  import com.java110.po.car.OwnerCarPo;
  import com.java110.utils.exception.CmdException;
  import com.java110.utils.util.Assert;
  import com.java110.utils.util.DateUtil;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  
  import java.util.Date;
  import java.util.List;
  
  @Java110Cmd(serviceCode = "owner.changeCarOwner")
  public class ChangeOwnerCarCmd extends Cmd {
  
      private static final Logger logger = LoggerFactory.getLogger(ChangeOwnerCarCmd.class);
  
      @Autowired
      private IOwnerCarV1InnerServiceSMO ownerCarV1InnerServiceSMOImpl;
  
      @Autowired
      private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
  
      @Override
      public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
          Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区ID");
          Assert.hasKeyAndValue(reqJson, "memberId", "请求报文中未包含carId");
          Assert.hasKeyAndValue(reqJson, "newOwnerId", "请求报文中未包含newOwnerId");
      }
  
      @Override
      @Java110Transactional
      public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
          String communityId = reqJson.getString("communityId");
          String memberId = reqJson.getString("memberId");
          String newOwnerId = reqJson.getString("newOwnerId");
  
          OwnerCarDto ownerCarDto = new OwnerCarDto();
          ownerCarDto.setMemberId(memberId);
          ownerCarDto.setCommunityId(communityId);
          List<OwnerCarDto> ownerCarDtos = ownerCarV1InnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
  
          if (ownerCarDtos == null || ownerCarDtos.isEmpty()) {
              throw new IllegalArgumentException("车辆不存在或不属于当前小区");
          }
  
          String oldOwnerId = ownerCarDtos.get(0).getOwnerId();
          if (oldOwnerId.equals(newOwnerId)) {
              throw new IllegalArgumentException("新业主与原业主相同,无需修改");
          }
  
          OwnerDto ownerDto = new OwnerDto();
          ownerDto.setOwnerId(newOwnerId);
          ownerDto.setCommunityId(communityId);
          List<OwnerDto> owners = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
  
          if (owners == null || owners.isEmpty()) {
              throw new IllegalArgumentException("新业主不存在或不属于当前小区");
          }
  
          OwnerCarPo ownerCarPo = new OwnerCarPo();
          ownerCarPo.setMemberId(memberId);
          ownerCarPo.setOwnerId(newOwnerId);
  
          int flag = ownerCarV1InnerServiceSMOImpl.updateOwnerCar(ownerCarPo);
          if (flag < 1) {
              throw new CmdException("修改车辆业主失败");
          }
  
          logger.info("车辆业主变更成功: carId={}, oldOwnerId={}, newOwnerId={}, operatorTime={}",
                  memberId, oldOwnerId, newOwnerId, DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_A));
      }
  }