AppSaveMemberCarCmd.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.java110.user.cmd.owner;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.java110.core.annotation.Java110Cmd;
  4. import com.java110.core.annotation.Java110Transactional;
  5. import com.java110.core.context.ICmdDataFlowContext;
  6. import com.java110.core.event.cmd.Cmd;
  7. import com.java110.core.event.cmd.CmdEvent;
  8. import com.java110.core.factory.GenerateCodeFactory;
  9. import com.java110.dto.owner.OwnerAppUserDto;
  10. import com.java110.dto.owner.OwnerCarDto;
  11. import com.java110.dto.owner.OwnerDto;
  12. import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
  13. import com.java110.intf.user.IOwnerCarInnerServiceSMO;
  14. import com.java110.intf.user.IOwnerCarV1InnerServiceSMO;
  15. import com.java110.intf.user.IOwnerV1InnerServiceSMO;
  16. import com.java110.po.car.OwnerCarPo;
  17. import com.java110.utils.exception.CmdException;
  18. import com.java110.utils.util.*;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import java.text.ParseException;
  21. import java.util.List;
  22. @Java110Cmd(serviceCode = "owner.appSaveMemberCar")
  23. public class AppSaveMemberCarCmd extends Cmd {
  24. @Autowired
  25. private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
  26. @Autowired
  27. private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
  28. @Autowired
  29. private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
  30. @Autowired
  31. private IOwnerCarV1InnerServiceSMO ownerCarV1InnerServiceSMOImpl;
  32. @Override
  33. public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  34. String userId = context.getReqHeaders().get("user-id");
  35. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  36. ownerAppUserDto.setUserId(userId);
  37. ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
  38. ownerAppUserDto.setMemberId(reqJson.getString("memberId"));
  39. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  40. if (ListUtil.isNull(ownerAppUserDtos)) {
  41. throw new CmdException("未绑定业主");
  42. }
  43. String memberId = "";
  44. for (OwnerAppUserDto tmpOwnerAppUserDto : ownerAppUserDtos) {
  45. if ("-1".equals(tmpOwnerAppUserDto.getMemberId())) {
  46. continue;
  47. }
  48. memberId = tmpOwnerAppUserDto.getMemberId();
  49. }
  50. if (StringUtil.isEmpty(memberId)) {
  51. throw new CmdException("未绑定业主");
  52. }
  53. OwnerDto ownerDto = new OwnerDto();
  54. ownerDto.setCommunityId(reqJson.getString("communityId"));
  55. ownerDto.setMemberId(memberId);
  56. List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
  57. Assert.listOnlyOne(ownerDtos, "业主不存在");
  58. reqJson.put("ownerId", ownerDtos.get(0).getOwnerId());
  59. Assert.jsonObjectHaveKey(reqJson, "communityId", "未包含小区ID");
  60. Assert.jsonObjectHaveKey(reqJson, "carId", "请求报文中未包含carId");
  61. Assert.jsonObjectHaveKey(reqJson, "carNum", "请求报文中未包含carNum");
  62. Assert.jsonObjectHaveKey(reqJson, "carBrand", "请求报文中未包含carBrand");
  63. Assert.jsonObjectHaveKey(reqJson, "carColor", "未包含carColor");
  64. //校验车牌号是否存在
  65. OwnerCarDto ownerCarDto = new OwnerCarDto();
  66. ownerCarDto.setCommunityId(reqJson.getString("communityId"));
  67. ownerCarDto.setCarNum(reqJson.getString("carNum"));
  68. ownerCarDto.setCarTypeCds(new String[]{OwnerCarDto.CAR_TYPE_PRIMARY, OwnerCarDto.CAR_TYPE_MEMBER}); // 临时车除外
  69. int count = ownerCarInnerServiceSMOImpl.queryOwnerCarsCount(ownerCarDto);
  70. if (count > 0) {
  71. throw new IllegalArgumentException("车辆已存在");
  72. }
  73. }
  74. @Override
  75. @Java110Transactional
  76. public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  77. //校验车牌号是否存在
  78. OwnerCarDto ownerCarDto = new OwnerCarDto();
  79. ownerCarDto.setCommunityId(reqJson.getString("communityId"));
  80. ownerCarDto.setCarTypeCd("1001"); //业主车辆
  81. ownerCarDto.setCarId(reqJson.getString("carId"));
  82. ownerCarDto.setOwnerId(reqJson.getString("ownerId"));
  83. ownerCarDto.setStatusCd("0");
  84. List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
  85. if (ListUtil.isNull(ownerCarDtos)) {
  86. throw new IllegalArgumentException("主车辆不存在");
  87. }
  88. JSONObject tmpOwnerCar = JSONObject.parseObject(JSONObject.toJSONString(ownerCarDtos.get(0)));
  89. tmpOwnerCar.putAll(reqJson);
  90. tmpOwnerCar.put("startTime", DateUtil.getFormatTimeString(ownerCarDtos.get(0).getStartTime(), DateUtil.DATE_FORMATE_STRING_A));
  91. tmpOwnerCar.put("endTime", DateUtil.getFormatTimeString(ownerCarDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
  92. tmpOwnerCar.put("memberId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_carId));
  93. OwnerCarPo ownerCarPo = BeanConvertUtil.covertBean(tmpOwnerCar, OwnerCarPo.class);
  94. ownerCarPo.setState(OwnerCarDto.STATE_NORMAL);
  95. ownerCarPo.setCarTypeCd(OwnerCarDto.CAR_TYPE_MEMBER);
  96. int flag = ownerCarV1InnerServiceSMOImpl.saveOwnerCar(ownerCarPo);
  97. if (flag < 1) {
  98. throw new CmdException("保存车辆属性失败");
  99. }
  100. }
  101. }