package com.java110.community.cmd.floor;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.java110.core.annotation.Java110Cmd;
|
import com.java110.core.context.ICmdDataFlowContext;
|
import com.java110.core.event.cmd.AbstractServiceCmdListener;
|
import com.java110.core.event.cmd.CmdEvent;
|
import com.java110.dto.FloorDto;
|
import com.java110.intf.community.IFloorInnerServiceSMO;
|
import com.java110.utils.exception.CmdException;
|
import com.java110.utils.util.Assert;
|
import com.java110.utils.util.BeanConvertUtil;
|
import com.java110.vo.api.ApiFloorDataVo;
|
import com.java110.vo.api.ApiFloorVo;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.http.ResponseEntity;
|
|
import java.util.List;
|
|
@Java110Cmd(serviceCode = "floor.queryFloors")
|
public class QueryFloorsCmd extends AbstractServiceCmdListener {
|
|
@Autowired
|
private IFloorInnerServiceSMO floorInnerServiceSMOImpl;
|
|
@Override
|
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
|
Assert.jsonObjectHaveKey(reqJson, "page", "请求中未包含page信息");
|
Assert.jsonObjectHaveKey(reqJson, "row", "请求中未包含row信息");
|
Assert.jsonObjectHaveKey(reqJson, "communityId", "请求中未包含communityId信息");
|
Assert.isInteger(reqJson.getString("page"), "page不是有效数字");
|
Assert.isInteger(reqJson.getString("row"), "row不是有效数字");
|
}
|
|
@Override
|
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
|
//int page = reqJson.getInteger("page");
|
int row = reqJson.getInteger("row");
|
//String communityId = reqJson.getString("communityId");
|
|
ApiFloorVo apiFloorVo = new ApiFloorVo();
|
|
//查询总记录数
|
int total = floorInnerServiceSMOImpl.queryFloorsCount(BeanConvertUtil.covertBean(reqJson, FloorDto.class));
|
apiFloorVo.setTotal(total);
|
if (total > 0) {
|
List<FloorDto> floorDtoList = floorInnerServiceSMOImpl.queryFloors(BeanConvertUtil.covertBean(reqJson, FloorDto.class));
|
apiFloorVo.setApiFloorDataVoList(BeanConvertUtil.covertBeanList(floorDtoList, ApiFloorDataVo.class));
|
}
|
|
apiFloorVo.setRecords((int) Math.ceil((double) total / (double) row));
|
|
ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiFloorVo), HttpStatus.OK);
|
cmdDataFlowContext.setResponseEntity(responseEntity);
|
}
|
}
|