QueryAppOwnerCarsCmd.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.context.ICmdDataFlowContext;
  5. import com.java110.core.event.cmd.Cmd;
  6. import com.java110.core.event.cmd.CmdEvent;
  7. import com.java110.dto.owner.OwnerAppUserDto;
  8. import com.java110.dto.owner.OwnerCarDto;
  9. import com.java110.dto.owner.OwnerDto;
  10. import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
  11. import com.java110.intf.user.IOwnerCarInnerServiceSMO;
  12. import com.java110.intf.user.IOwnerV1InnerServiceSMO;
  13. import com.java110.utils.exception.CmdException;
  14. import com.java110.utils.util.Assert;
  15. import com.java110.utils.util.BeanConvertUtil;
  16. import com.java110.utils.util.ListUtil;
  17. import com.java110.utils.util.StringUtil;
  18. import com.java110.vo.ResultVo;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.http.ResponseEntity;
  21. import java.text.ParseException;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. /**
  25. * 查询业主车辆
  26. */
  27. @Java110Cmd(serviceCode = "owner.queryAppOwnerCars")
  28. public class QueryAppOwnerCarsCmd extends Cmd {
  29. @Autowired
  30. private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
  31. @Autowired
  32. private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
  33. @Autowired
  34. private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
  35. @Override
  36. public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  37. super.validatePageInfo(reqJson);
  38. String userId = context.getReqHeaders().get("user-id");
  39. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  40. ownerAppUserDto.setUserId(userId);
  41. ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
  42. ownerAppUserDto.setMemberId(reqJson.getString("memberId"));
  43. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  44. if (ListUtil.isNull(ownerAppUserDtos)) {
  45. throw new CmdException("未绑定业主");
  46. }
  47. String memberId = "";
  48. for (OwnerAppUserDto tmpOwnerAppUserDto : ownerAppUserDtos) {
  49. if ("-1".equals(tmpOwnerAppUserDto.getMemberId())) {
  50. continue;
  51. }
  52. memberId = tmpOwnerAppUserDto.getMemberId();
  53. }
  54. if (StringUtil.isEmpty(memberId)) {
  55. throw new CmdException("未绑定业主");
  56. }
  57. OwnerDto ownerDto = new OwnerDto();
  58. ownerDto.setCommunityId(reqJson.getString("communityId"));
  59. ownerDto.setMemberId(memberId);
  60. List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
  61. Assert.listOnlyOne(ownerDtos, "业主不存在");
  62. reqJson.put("ownerId", ownerDtos.get(0).getOwnerId());
  63. }
  64. @Override
  65. public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  66. OwnerCarDto ownerCarDto = BeanConvertUtil.covertBean(reqJson, OwnerCarDto.class);
  67. int total = ownerCarInnerServiceSMOImpl.queryOwnerCarsCount(ownerCarDto);
  68. // int count = 0;
  69. List<OwnerCarDto> ownerCarDtos = null;
  70. if (total > 0) {
  71. ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
  72. } else {
  73. ownerCarDtos = new ArrayList<>();
  74. }
  75. int row = reqJson.getIntValue("row");
  76. ResponseEntity<String> responseEntity = ResultVo.createResponseEntity((int) Math.ceil((double) total / (double) row),
  77. total, ownerCarDtos);
  78. context.setResponseEntity(responseEntity);
  79. }
  80. }