Commit 487cd38d authored by huangcb's avatar huangcb

承运商接口:查询车辆详情

parent b40c071e
...@@ -146,4 +146,7 @@ public class ErrorMessageComponent { ...@@ -146,4 +146,7 @@ public class ErrorMessageComponent {
private String carrierVehicleEdit1003; private String carrierVehicleEdit1003;
@Value("${error-message.carrier.vehicle.edit.1004}") @Value("${error-message.carrier.vehicle.edit.1004}")
private String carrierVehicleEdit1004; private String carrierVehicleEdit1004;
@Value("${error-message.carrier.vehicle.detail.1001}")
private String carrierVehicleDetail1001;
} }
...@@ -12,5 +12,14 @@ import com.esv.freight.customer.module.carrier.entity.CarrierInfoEntity; ...@@ -12,5 +12,14 @@ import com.esv.freight.customer.module.carrier.entity.CarrierInfoEntity;
*/ */
public interface CarrierInfoService extends IService<CarrierInfoEntity> { public interface CarrierInfoService extends IService<CarrierInfoEntity> {
/**
* description 通过承运商ID获取名称
* param [carrierId]
* return java.lang.String
* author Administrator
* createTime 2020/04/27 13:49
**/
String getCarrierNameById(Long carrierId);
} }
package com.esv.freight.customer.module.carrier.service.impl; package com.esv.freight.customer.module.carrier.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.module.carrier.CarrierConstants;
import com.esv.freight.customer.module.carrier.dao.CarrierInfoDao; import com.esv.freight.customer.module.carrier.dao.CarrierInfoDao;
import com.esv.freight.customer.module.carrier.entity.CarrierInfoEntity; import com.esv.freight.customer.module.carrier.entity.CarrierInfoEntity;
import com.esv.freight.customer.module.carrier.service.CarrierInfoService; import com.esv.freight.customer.module.carrier.service.CarrierInfoService;
...@@ -10,4 +12,18 @@ import org.springframework.stereotype.Service; ...@@ -10,4 +12,18 @@ import org.springframework.stereotype.Service;
@Service("carrierInfoService") @Service("carrierInfoService")
public class CarrierInfoServiceImpl extends ServiceImpl<CarrierInfoDao, CarrierInfoEntity> implements CarrierInfoService { public class CarrierInfoServiceImpl extends ServiceImpl<CarrierInfoDao, CarrierInfoEntity> implements CarrierInfoService {
@Override
public String getCarrierNameById(Long carrierId) {
String carrierName = null;
CarrierInfoEntity carrierInfoEntity = this.baseMapper.selectOne(new QueryWrapper<CarrierInfoEntity>()
.lambda().eq(CarrierInfoEntity::getAccountId, carrierId));
if (null != carrierInfoEntity) {
if (CarrierConstants.CARRIER_TYPE_COMPANY.equals(carrierInfoEntity.getCarrierType())) {
carrierName = carrierInfoEntity.getCarrierFullName();
} else {
carrierName = carrierInfoEntity.getContactor();
}
}
return carrierName;
}
} }
\ No newline at end of file
package com.esv.freight.customer.module.vehicle.controller; package com.esv.freight.customer.module.vehicle.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException; import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.ECode; import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.common.response.EResponse; import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert; import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate; import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.carrier.service.CarrierInfoService;
import com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto;
import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm; import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm;
import com.esv.freight.customer.module.vehicle.form.VehicleQueryForm;
import com.esv.freight.customer.module.vehicle.service.VehicleService; import com.esv.freight.customer.module.vehicle.service.VehicleService;
import com.esv.freight.customer.module.vehicle.vo.VehicleDetailVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -34,11 +41,17 @@ import java.math.BigDecimal; ...@@ -34,11 +41,17 @@ import java.math.BigDecimal;
@Validated @Validated
public class VehicleController { public class VehicleController {
private ErrorMessageComponent errorMessageComponent;
private VehicleService vehicleService; private VehicleService vehicleService;
private CarrierInfoService carrierInfoService;
@Autowired @Autowired
public VehicleController(VehicleService vehicleService) { public VehicleController(ErrorMessageComponent errorMessageComponent, VehicleService vehicleService, CarrierInfoService carrierInfoService) {
this.errorMessageComponent = errorMessageComponent;
this.vehicleService = vehicleService; this.vehicleService = vehicleService;
this.carrierInfoService = carrierInfoService;
} }
/** /**
...@@ -80,4 +93,25 @@ public class VehicleController { ...@@ -80,4 +93,25 @@ public class VehicleController {
vehicleService.updateVehicle(form); vehicleService.updateVehicle(form);
return EResponse.ok(); return EResponse.ok();
} }
/**
* description 获取车辆详情
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/27 14:13
**/
@PostMapping("/detail")
public EResponse detail(@RequestBody @Validated(ValidatorDetail.class) VehicleQueryForm form) throws EException {
VehicleDetailDto dto = vehicleService.getVehicleDetail(form.getId());
if (null == dto) {
throw new EException(1001, errorMessageComponent.getCarrierVehicleDetail1001());
}
VehicleDetailVO vo = new VehicleDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCarrierName(carrierInfoService.getCarrierNameById(dto.getCarrierId()));
vo.setCreateTime(dto.getCreateTime().getTime());
return EResponse.ok(vo);
}
} }
package com.esv.freight.customer.module.vehicle.dao; package com.esv.freight.customer.module.vehicle.dao;
import com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto;
import com.esv.freight.customer.module.vehicle.entity.VehicleEntity; import com.esv.freight.customer.module.vehicle.entity.VehicleEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -13,5 +14,14 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -13,5 +14,14 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface VehicleDao extends BaseMapper<VehicleEntity> { public interface VehicleDao extends BaseMapper<VehicleEntity> {
/**
* description 查询车辆详情
* param [id]
* return com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto
* author Administrator
* createTime 2020/04/27 14:02
**/
VehicleDetailDto selectVehicleDetail(Long id);
} }
package com.esv.freight.customer.module.vehicle.dto;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
import java.util.Date;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/27 13:44
* @version:1.0
*/
@Data
public class VehicleDetailDto {
/**
*
*/
private Long id;
/**
* 租户ID
*/
private Long tenantId;
/**
* 部门ID
*/
private Long departmentId;
/**
* 承运商帐号ID
*/
private Long carrierId;
/**
* 车牌号
*/
private String licenseNumber;
/**
* 车辆状态:1-正常、2-停用
*/
private String vehicleStatus;
/**
* 审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
private Integer auditStatus;
/**
* 入网状态:字典表
*/
private Integer netInStatus;
/**
* 入网时间
*/
private String netInDate;
/**
* 牌照类型(字典表):1-大型汽车号牌、2-小型汽车号牌、3-其他号牌
*/
private Integer licenseType;
/**
* 车牌颜色(字典表):1-蓝色、2-黄色、3-黑色、4-白色、5-绿色、6-农黄色、7-农绿色、8-黄绿色、9-渐变绿、0-其他
*/
private Integer licenseColor;
/**
* 车辆类型(字典表)
*/
private Integer vehicleType;
/**
* 二级车辆类型(字典表)
*/
private Integer vehicleType2;
/**
* 车辆长度(单位毫米)
*/
private Integer vehicleLength;
/**
* 车辆宽度(单位毫米)
*/
private Integer vehicleWidth;
/**
* 车辆高度(单位毫米)
*/
private Integer vehicleHeight;
/**
* 车辆所属(字典表):1-自有车、2-外协车
*/
private Integer vehicleBelong;
/**
* 年审日期
*/
private String yearAuditDate;
/**
* 能源类型(字典表):1-汽油、2-柴油、3-电、4-混合油、5-天然气、6-液化石油气、7-甲醇、8-乙醇、9-太阳能、10-混合动力、99-其他
*/
private Integer energyType;
/**
* 行驶证档案编号
*/
private String vehicleLicenseNumber;
/**
* 核定载质量(吨)
*/
private BigDecimal loadCapacity;
/**
* 总质量(吨)
*/
private BigDecimal totalMass;
/**
* 整备质量(吨)
*/
private BigDecimal unladenMass;
/**
* 车辆所有人
*/
private String vehicleOwner;
/**
* 车辆所有人代码:企业-统一社会信用代码,个人-身份证号码
*/
private String vehicleOwnerCode;
/**
* 使用性质
*/
private String useNature;
/**
* 注册日期
*/
private String registerDate;
/**
* 车辆识别代码
*/
private String vin;
/**
* 品牌型号
*/
private String brandModel;
/**
* 发动机号
*/
private String engineNumber;
/**
* 发证日期
*/
private String vehicleLicenseIssuedDate;
/**
* 检验有效期至
*/
private String vehicleLicenseExpireDate;
/**
* 发证机关
*/
private String vehicleLicenseIssueDepartment;
/**
* 道路运输证号
*/
private String roadCertificateNumber;
/**
* 经营许可证号
*/
private String businessLicenseNumber;
/**
* 经营许可证有效期至
*/
private String businessLicenseExpireDate;
/**
* 车籍地-省份代码
*/
private String vehicleProvinceCode;
/**
* 车籍地-市代码
*/
private String vehicleCityCode;
/**
* 车籍地-区县代码
*/
private String vehicleDistrictCode;
/**
* 是否开通ETC:1-已开通、2-未开通、3-未知
*/
private String etc;
/**
* 上报状态(字典表):0-未上报、1-上报成功、2-上报失败
*/
private Integer uploadState;
/**
* 上报时间
*/
private String uploadTime;
/**
* 删除标识:0-未删除,1-已删除
*/
private Boolean deleted;
/**
* 创建来源:1-平台创建、2-司机创建
*/
private String sourceType;
/**
* 创建者
*/
private String createUser;
/**
* 修改者
*/
private String updateUser;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
/**
* 车头照片URL
*/
private String vehicleHeadUrl;
/**
* 人车合照URL
*/
private String vehicleHeadPersonUrl;
/**
* 行驶证正面URL
*/
private String vehicleLicenseFrontUrl;
/**
* 行驶证背面URL
*/
private String vehicleLicenseBackUrl;
/**
* 道路运输证正面URL
*/
private String roadCertificateFrontUrl;
/**
* 挂靠声明URL
*/
private String attachedStatementUrl;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.module.vehicle.form; package com.esv.freight.customer.module.vehicle.form;
import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotNull;
/** /**
* @description: * @description:
* @project: freight-customer-service * @project: freight-customer-service
...@@ -19,6 +23,7 @@ public class VehicleQueryForm { ...@@ -19,6 +23,7 @@ public class VehicleQueryForm {
/** /**
* *
*/ */
@NotNull(message = "参数id不能为空", groups = {ValidatorDetail.class})
private Long id; private Long id;
/** /**
* 承运商帐号ID * 承运商帐号ID
......
package com.esv.freight.customer.module.vehicle.service; package com.esv.freight.customer.module.vehicle.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto;
import com.esv.freight.customer.module.vehicle.entity.VehicleEntity; import com.esv.freight.customer.module.vehicle.entity.VehicleEntity;
import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm; import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm;
...@@ -31,5 +32,14 @@ public interface VehicleService extends IService<VehicleEntity> { ...@@ -31,5 +32,14 @@ public interface VehicleService extends IService<VehicleEntity> {
**/ **/
Integer updateVehicle(VehicleInfoForm form); Integer updateVehicle(VehicleInfoForm form);
/**
* description 获取车辆详情
* param [id]
* return com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto
* author Administrator
* createTime 2020/04/27 13:56
**/
VehicleDetailDto getVehicleDetail(Long id);
} }
...@@ -11,6 +11,7 @@ import com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity; ...@@ -11,6 +11,7 @@ import com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity;
import com.esv.freight.customer.module.carrier.service.CarrierAccountService; import com.esv.freight.customer.module.carrier.service.CarrierAccountService;
import com.esv.freight.customer.module.vehicle.VehicleConstants; import com.esv.freight.customer.module.vehicle.VehicleConstants;
import com.esv.freight.customer.module.vehicle.dao.VehicleDao; import com.esv.freight.customer.module.vehicle.dao.VehicleDao;
import com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto;
import com.esv.freight.customer.module.vehicle.entity.AttachmentEntity; import com.esv.freight.customer.module.vehicle.entity.AttachmentEntity;
import com.esv.freight.customer.module.vehicle.entity.VehicleAuditHistoryEntity; import com.esv.freight.customer.module.vehicle.entity.VehicleAuditHistoryEntity;
import com.esv.freight.customer.module.vehicle.entity.VehicleEntity; import com.esv.freight.customer.module.vehicle.entity.VehicleEntity;
...@@ -160,4 +161,9 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i ...@@ -160,4 +161,9 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i
return flag; return flag;
} }
@Override
public VehicleDetailDto getVehicleDetail(Long id) {
return this.baseMapper.selectVehicleDetail(id);
}
} }
\ No newline at end of file
package com.esv.freight.customer.module.vehicle.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.vehicle.vo.VehicleDetailVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/27 13:40
* @version:1.0
*/
@Data
public class VehicleDetailVO {
/**
*
*/
private Long id;
/**
* 承运商帐号ID
*/
private Long carrierId;
/**
* 承运商名称
*/
private String carrierName;
/**
* 车牌号
*/
private String licenseNumber;
/**
* 车辆状态:1-正常、2-停用
*/
private String vehicleStatus;
/**
* 审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
private Integer auditStatus;
/**
* 牌照类型(字典表):1-大型汽车号牌、2-小型汽车号牌、3-其他号牌
*/
private Integer licenseType;
/**
* 车牌颜色(字典表):1-蓝色、2-黄色、3-黑色、4-白色、5-绿色、6-农黄色、7-农绿色、8-黄绿色、9-渐变绿、0-其他
*/
private Integer licenseColor;
/**
* 车辆类型(字典表)
*/
private Integer vehicleType;
/**
* 二级车辆类型(字典表)
*/
private Integer vehicleType2;
/**
* 车辆长度(单位毫米)
*/
private Integer vehicleLength;
/**
* 车辆宽度(单位毫米)
*/
private Integer vehicleWidth;
/**
* 车辆高度(单位毫米)
*/
private Integer vehicleHeight;
/**
* 车辆所属(字典表):1-自有车、2-外协车
*/
private Integer vehicleBelong;
/**
* 年审日期
*/
private String yearAuditDate;
/**
* 能源类型(字典表):1-汽油、2-柴油、3-电、4-混合油、5-天然气、6-液化石油气、7-甲醇、8-乙醇、9-太阳能、10-混合动力、99-其他
*/
private Integer energyType;
/**
* 行驶证档案编号
*/
private String vehicleLicenseNumber;
/**
* 核定载质量(吨)
*/
private BigDecimal loadCapacity;
/**
* 总质量(吨)
*/
private BigDecimal totalMass;
/**
* 整备质量(吨)
*/
private BigDecimal unladenMass;
/**
* 车辆所有人
*/
private String vehicleOwner;
/**
* 车辆所有人代码:企业-统一社会信用代码,个人-身份证号码
*/
private String vehicleOwnerCode;
/**
* 使用性质
*/
private String useNature;
/**
* 注册日期
*/
private String registerDate;
/**
* 车辆识别代码
*/
private String vin;
/**
* 品牌型号
*/
private String brandModel;
/**
* 发动机号
*/
private String engineNumber;
/**
* 发证日期
*/
private String vehicleLicenseIssuedDate;
/**
* 检验有效期至
*/
private String vehicleLicenseExpireDate;
/**
* 发证机关
*/
private String vehicleLicenseIssueDepartment;
/**
* 道路运输证号
*/
private String roadCertificateNumber;
/**
* 经营许可证号
*/
private String businessLicenseNumber;
/**
* 经营许可证有效期至
*/
private String businessLicenseExpireDate;
/**
* 车籍地-省份代码
*/
private String vehicleProvinceCode;
/**
* 车籍地-市代码
*/
private String vehicleCityCode;
/**
* 车籍地-区县代码
*/
private String vehicleDistrictCode;
/**
* 是否开通ETC:1-已开通、2-未开通、3-未知
*/
private String etc;
/**
* 上报状态(字典表):0-未上报、1-上报成功、2-上报失败
*/
private Integer uploadState;
/**
* 上报时间
*/
private String uploadTime;
/**
* 删除标识:0-未删除,1-已删除
*/
private Boolean deleted;
/**
* 创建来源:1-平台创建、2-司机创建
*/
private String sourceType;
/**
* 创建者
*/
private String createUser;
/**
* 修改者
*/
private Long createTime;
/**
* 车头照片URL
*/
private String vehicleHeadUrl;
/**
* 人车合照URL
*/
private String vehicleHeadPersonUrl;
/**
* 行驶证正面URL
*/
private String vehicleLicenseFrontUrl;
/**
* 行驶证背面URL
*/
private String vehicleLicenseBackUrl;
/**
* 道路运输证正面URL
*/
private String roadCertificateFrontUrl;
/**
* 挂靠声明URL
*/
private String attachedStatementUrl;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
...@@ -130,4 +130,6 @@ error-message: ...@@ -130,4 +130,6 @@ error-message:
1001: 无效的车辆ID 1001: 无效的车辆ID
1002: 车牌号已存在 1002: 车牌号已存在
1003: 行驶证档案编号已存在 1003: 行驶证档案编号已存在
1004: 道路运输证号已存在 1004: 道路运输证号已存在
\ No newline at end of file detail:
1001: 无效的车辆ID
\ No newline at end of file
...@@ -55,5 +55,13 @@ ...@@ -55,5 +55,13 @@
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
</resultMap> </resultMap>
<!-- 查询车辆详情 -->
<select id="selectVehicleDetail" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto">
select a.*, b.vehicle_head_url, b.vehicle_head_person_url, b.vehicle_license_front_url,
b.vehicle_license_back_url, b.road_certificate_front_url, b.attached_statement_url
from vehicle a, vehicle_attachment b
where a.id = b.vehicle_id
and a.id = #{id}
</select>
</mapper> </mapper>
\ No newline at end of file
package com.esv.freight.customer.module.vehicle.controller;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.BaseTestController;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.module.vehicle.form.VehicleInfoForm;
import com.esv.freight.customer.module.vehicle.form.VehicleQueryForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.vehicle.controller.VehicleControllerTest
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/27 14:20
* @version:1.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback(false)
public class VehicleControllerTest extends BaseTestController {
/**
* 查询车辆详情
**/
@Test
public void a1_detail_success_test() throws Exception {
String url = "/carrier/vehicle/detail";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
Assert.assertTrue(null != result.getJSONObject("data"));
}
/**
* 查询车辆详情:无效的车辆ID
**/
@Test
public void a2_detail_wrong_id_failure_test() throws Exception {
String url = "/carrier/vehicle/detail";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(99999L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1001, result.getIntValue("code"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment