| New file |
| | |
| | | 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.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.owner.OwnerCarDto; |
| | | import com.java110.dto.parking.ParkingSpaceDto; |
| | | import com.java110.intf.community.IParkingSpaceInnerServiceSMO; |
| | | import com.java110.intf.community.IParkingSpaceV1InnerServiceSMO; |
| | | import com.java110.intf.fee.IFeeConfigInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerCarAttrInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerCarInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerCarV1InnerServiceSMO; |
| | | import com.java110.po.car.OwnerCarPo; |
| | | import com.java110.po.ownerCarAttr.OwnerCarAttrPo; |
| | | import com.java110.po.parking.ParkingSpacePo; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.exception.ListenerExecuteException; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Java110Cmd(serviceCode = "owner.saveOwnerCar") |
| | | public class SaveOwnerCarCmd extends Cmd { |
| | | |
| | | |
| | | @Autowired |
| | | private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IParkingSpaceInnerServiceSMO parkingSpaceInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IOwnerCarAttrInnerServiceSMO ownerCarAttrInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IOwnerCarV1InnerServiceSMO ownerCarV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IParkingSpaceV1InnerServiceSMO parkingSpaceV1InnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { |
| | | Assert.jsonObjectHaveKey(reqJson, "communityId", "未包含小区ID"); |
| | | Assert.jsonObjectHaveKey(reqJson, "ownerId", "请求报文中未包含ownerId"); |
| | | Assert.jsonObjectHaveKey(reqJson, "carNum", "请求报文中未包含carNum"); |
| | | Assert.jsonObjectHaveKey(reqJson, "carBrand", "请求报文中未包含carBrand"); |
| | | Assert.jsonObjectHaveKey(reqJson, "carType", "请求报文中未包含carType"); |
| | | Assert.jsonObjectHaveKey(reqJson, "carColor", "未包含carColor"); |
| | | Assert.jsonObjectHaveKey(reqJson, "psId", "未包含psId"); |
| | | Assert.jsonObjectHaveKey(reqJson, "storeId", "未包含storeId"); |
| | | Assert.jsonObjectHaveKey(reqJson, "carNumType", "未包含carNumType"); |
| | | |
| | | Assert.hasLength(reqJson.getString("communityId"), "小区ID不能为空"); |
| | | Assert.hasLength(reqJson.getString("ownerId"), "ownerId不能为空"); |
| | | Assert.hasLength(reqJson.getString("psId"), "psId不能为空"); |
| | | |
| | | if (!"H".equals(reqJson.getString("carNumType")) |
| | | && !"S".equals(reqJson.getString("carNumType"))) { |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "请求报文中sellOrFire值错误 ,出售为S 出租为H"); |
| | | } |
| | | |
| | | //校验车牌号是否存在 |
| | | OwnerCarDto ownerCarDto = new OwnerCarDto(); |
| | | ownerCarDto.setCommunityId(reqJson.getString("communityId")); |
| | | ownerCarDto.setCarNum(reqJson.getString("carNum")); |
| | | int count = ownerCarInnerServiceSMOImpl.queryOwnerCarsCount(ownerCarDto); |
| | | |
| | | if (count > 0) { |
| | | throw new IllegalArgumentException("车辆已存在"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Java110Transactional |
| | | public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { |
| | | JSONObject businessOwnerCar = new JSONObject(); |
| | | businessOwnerCar.putAll(reqJson); |
| | | businessOwnerCar.put("memberId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_carId)); |
| | | if (!reqJson.containsKey("carId") || reqJson.getString("carId").startsWith("-")) { |
| | | businessOwnerCar.put("carId", businessOwnerCar.getString("memberId")); |
| | | } |
| | | OwnerCarPo ownerCarPo = BeanConvertUtil.covertBean(businessOwnerCar, OwnerCarPo.class); |
| | | ownerCarPo.setState(OwnerCarDto.STATE_NORMAL); |
| | | |
| | | //没有指定时为主要车辆 |
| | | if (!reqJson.containsKey("carTypeCd") || StringUtil.isEmpty(reqJson.getString("carTypeCd"))) { |
| | | ownerCarPo.setCarTypeCd(OwnerCarDto.CAR_TYPE_PRIMARY); |
| | | } |
| | | //添加车辆属性 |
| | | dealOwnerCarAttr(reqJson, ownerCarPo); |
| | | int flag = ownerCarV1InnerServiceSMOImpl.saveOwnerCar(ownerCarPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("保存车辆属性失败"); |
| | | } |
| | | |
| | | ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto(); |
| | | parkingSpaceDto.setCommunityId(reqJson.getString("communityId")); |
| | | parkingSpaceDto.setPsId(reqJson.getString("psId")); |
| | | List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto); |
| | | |
| | | if (parkingSpaceDtos == null || parkingSpaceDtos.size() != 1) { |
| | | //throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "未查询到停车位信息" + JSONObject.toJSONString(parkingSpaceDto)); |
| | | return; |
| | | } |
| | | |
| | | parkingSpaceDto = parkingSpaceDtos.get(0); |
| | | |
| | | JSONObject businessParkingSpace = new JSONObject(); |
| | | |
| | | businessParkingSpace.putAll(BeanConvertUtil.beanCovertMap(parkingSpaceDto)); |
| | | businessParkingSpace.put("state", reqJson.getString("carNumType")); |
| | | ParkingSpacePo parkingSpacePo = BeanConvertUtil.covertBean(businessParkingSpace, ParkingSpacePo.class); |
| | | flag = parkingSpaceV1InnerServiceSMOImpl.updateParkingSpace(parkingSpacePo); |
| | | if (flag < 1) { |
| | | throw new CmdException("修改车位状态失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private void dealOwnerCarAttr(JSONObject paramInJson, OwnerCarPo ownerCarPo) { |
| | | |
| | | if (!paramInJson.containsKey("attrs")) { |
| | | return; |
| | | } |
| | | |
| | | JSONArray attrs = paramInJson.getJSONArray("attrs"); |
| | | if (attrs.size() < 1) { |
| | | return; |
| | | } |
| | | JSONObject attr = null; |
| | | int flag = 0; |
| | | for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) { |
| | | attr = attrs.getJSONObject(attrIndex); |
| | | OwnerCarAttrPo ownerCarAttrPo = new OwnerCarAttrPo(); |
| | | ownerCarAttrPo.setAttrId(GenerateCodeFactory.getAttrId()); |
| | | ownerCarAttrPo.setCommunityId(ownerCarPo.getCommunityId()); |
| | | ownerCarAttrPo.setCarId(ownerCarPo.getCarId()); |
| | | ownerCarAttrPo.setSpecCd(attr.getString("specCd")); |
| | | ownerCarAttrPo.setValue(attr.getString("value")); |
| | | flag = ownerCarAttrInnerServiceSMOImpl.saveOwnerCarAttr(ownerCarAttrPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("保存车辆属性失败"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |