| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package com.java110.user.cmd.owner;
- import com.alibaba.fastjson.JSONObject;
- import com.java110.core.annotation.Java110Cmd;
- 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.IOwnerAppUserInnerServiceSMO;
- import com.java110.intf.user.IOwnerCarInnerServiceSMO;
- import com.java110.intf.user.IOwnerV1InnerServiceSMO;
- import com.java110.utils.exception.CmdException;
- import com.java110.utils.util.Assert;
- import com.java110.utils.util.BeanConvertUtil;
- import com.java110.utils.util.ListUtil;
- import com.java110.utils.util.StringUtil;
- import com.java110.vo.ResultVo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.ResponseEntity;
- import java.text.ParseException;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 查询业主车辆
- */
- @Java110Cmd(serviceCode = "owner.queryAppOwnerCars")
- public class QueryAppOwnerCarsCmd extends Cmd {
- @Autowired
- private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
- @Autowired
- private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
- @Autowired
- private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
- @Override
- public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
- super.validatePageInfo(reqJson);
- 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());
- }
- @Override
- public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
- OwnerCarDto ownerCarDto = BeanConvertUtil.covertBean(reqJson, OwnerCarDto.class);
- int total = ownerCarInnerServiceSMOImpl.queryOwnerCarsCount(ownerCarDto);
- // int count = 0;
- List<OwnerCarDto> ownerCarDtos = null;
- if (total > 0) {
- ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
- } else {
- ownerCarDtos = new ArrayList<>();
- }
- int row = reqJson.getIntValue("row");
- ResponseEntity<String> responseEntity = ResultVo.createResponseEntity((int) Math.ceil((double) total / (double) row),
- total, ownerCarDtos);
- context.setResponseEntity(responseEntity);
- }
- }
|