| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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.core.factory.GenerateCodeFactory;
- import com.java110.dto.owner.OwnerAppUserDto;
- import com.java110.dto.owner.OwnerCarDto;
- import com.java110.dto.owner.OwnerDto;
- 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.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import java.text.ParseException;
- import java.util.List;
- @Java110Cmd(serviceCode = "owner.appSaveMemberCar")
- public class AppSaveMemberCarCmd 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"));
- 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());
- Assert.jsonObjectHaveKey(reqJson, "communityId", "未包含小区ID");
- Assert.jsonObjectHaveKey(reqJson, "carId", "请求报文中未包含carId");
- Assert.jsonObjectHaveKey(reqJson, "carNum", "请求报文中未包含carNum");
- Assert.jsonObjectHaveKey(reqJson, "carBrand", "请求报文中未包含carBrand");
- Assert.jsonObjectHaveKey(reqJson, "carColor", "未包含carColor");
- //校验车牌号是否存在
- OwnerCarDto ownerCarDto = new OwnerCarDto();
- ownerCarDto.setCommunityId(reqJson.getString("communityId"));
- ownerCarDto.setCarNum(reqJson.getString("carNum"));
- ownerCarDto.setCarTypeCds(new String[]{OwnerCarDto.CAR_TYPE_PRIMARY, OwnerCarDto.CAR_TYPE_MEMBER}); // 临时车除外
- int count = ownerCarInnerServiceSMOImpl.queryOwnerCarsCount(ownerCarDto);
- if (count > 0) {
- throw new IllegalArgumentException("车辆已存在");
- }
- }
- @Override
- @Java110Transactional
- public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
- //校验车牌号是否存在
- OwnerCarDto ownerCarDto = new OwnerCarDto();
- ownerCarDto.setCommunityId(reqJson.getString("communityId"));
- ownerCarDto.setCarTypeCd("1001"); //业主车辆
- ownerCarDto.setCarId(reqJson.getString("carId"));
- ownerCarDto.setOwnerId(reqJson.getString("ownerId"));
- ownerCarDto.setStatusCd("0");
- List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
- if (ListUtil.isNull(ownerCarDtos)) {
- throw new IllegalArgumentException("主车辆不存在");
- }
- JSONObject tmpOwnerCar = JSONObject.parseObject(JSONObject.toJSONString(ownerCarDtos.get(0)));
- tmpOwnerCar.putAll(reqJson);
- tmpOwnerCar.put("startTime", DateUtil.getFormatTimeString(ownerCarDtos.get(0).getStartTime(), DateUtil.DATE_FORMATE_STRING_A));
- tmpOwnerCar.put("endTime", DateUtil.getFormatTimeString(ownerCarDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
- tmpOwnerCar.put("memberId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_carId));
- OwnerCarPo ownerCarPo = BeanConvertUtil.covertBean(tmpOwnerCar, OwnerCarPo.class);
- ownerCarPo.setState(OwnerCarDto.STATE_NORMAL);
- ownerCarPo.setCarTypeCd(OwnerCarDto.CAR_TYPE_MEMBER);
- int flag = ownerCarV1InnerServiceSMOImpl.saveOwnerCar(ownerCarPo);
- if (flag < 1) {
- throw new CmdException("保存车辆属性失败");
- }
- }
- }
|