Commit 624b77e9 authored by Shen's avatar Shen

1.用户地址 修改”添加或修改我的收货地址“接口,改为DTO传入

如果id留空为新增,否则为修改
parent 24f953a3
......@@ -11,6 +11,7 @@ import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.entity.UserEntity;
import io.hmit.modules.serviceOrder.dto.PensionConsigneeAddDTO;
import io.hmit.modules.serviceOrder.dto.PensionConsigneeDTO;
import io.hmit.modules.serviceOrder.service.PensionConsigneeService;
import io.swagger.annotations.Api;
......@@ -98,6 +99,7 @@ public class PensionConsigneeController {
return new Result();
}
@Deprecated
@GetMapping("findByUserId")
@ApiOperation("根据用户id查询用户收货地址")
public Result<List<PensionConsigneeDTO>> findAddressByUserId(@RequestParam("userId") Long userId){
......@@ -105,6 +107,7 @@ public class PensionConsigneeController {
return new Result<List<PensionConsigneeDTO>>().ok(pensionConsigneeDTOList);
}
@Deprecated
@Login
@GetMapping("findMyAddress")
@ApiOperation("查询本人收货地址")
......@@ -121,6 +124,7 @@ public class PensionConsigneeController {
return new Result<List<PensionConsigneeDTO>>().ok(pensionConsigneeDTOList);
}
@Deprecated
@Login
@PostMapping("addMyAddress")
@ApiOperation("添加我的收货地址")
......@@ -140,6 +144,17 @@ public class PensionConsigneeController {
return new Result();
}
@Login
@PostMapping("addMyAddressDTO2")
@ApiOperation(value = "添加或修改我的收货地址",notes = "userId留空")
public Result addMyAddress2(@ApiIgnore @LoginUser UserEntity user,
@RequestBody PensionConsigneeAddDTO dto){
dto.setUserId(user.getId());
pensionConsigneeService.addUserAddress(dto);
return new Result();
}
@Deprecated
@PostMapping("addUserAddress")
@ApiOperation("根据用户Id添加收货地址")
@ApiImplicitParams({
......
......@@ -26,25 +26,25 @@ public class PensionConsigneeAddDTO implements Serializable {
@ApiModelProperty(value = "用户ID")
private Long userId;
@ApiModelProperty(value = "收货人姓名")
@ApiModelProperty(value = "收货人姓名", required = true)
private String consigneeName;
@ApiModelProperty(value = "收货人电话")
@ApiModelProperty(value = "收货人电话", required = true)
private String consigneeMobile;
@ApiModelProperty(value = "省份")
@ApiModelProperty(value = "省份", required = true)
private String consigneeProvince;
@ApiModelProperty(value = "城市")
@ApiModelProperty(value = "城市", required = true)
private String consigneeCity;
@ApiModelProperty(value = "区/县")
@ApiModelProperty(value = "区/县", required = true)
private String consigneeDistrict;
@ApiModelProperty(value = "详细地址")
@ApiModelProperty(value = "详细地址", required = true)
private String consigneeAddress;
@ApiModelProperty(value = "邮编")
@ApiModelProperty(value = "邮编", required = true)
private String consigneeZip;
@ApiModelProperty(value = "是否为默认地址")
......@@ -53,6 +53,9 @@ public class PensionConsigneeAddDTO implements Serializable {
@ApiModelProperty(value = "状态")
private Integer status;
public PensionConsigneeAddDTO() {
}
public PensionConsigneeAddDTO(Long userId, String consigneeName, String consigneeMobile, String consigneeProvince,
String consigneeCity, String consigneeDistrict, String consigneeAddress,
String consigneeZip, Integer ifDefault, Integer status) {
......
package io.hmit.modules.serviceOrder.service;
import io.hmit.common.service.CrudService;
import io.hmit.modules.serviceOrder.dto.PensionConsigneeAddDTO;
import io.hmit.modules.serviceOrder.dto.PensionConsigneeDTO;
import io.hmit.modules.serviceOrder.entity.PensionConsigneeEntity;
......@@ -21,4 +22,6 @@ public interface PensionConsigneeService extends CrudService<PensionConsigneeEnt
void addUserAddress(Map<String, Object> params);
void addUserAddress(PensionConsigneeAddDTO dto);
}
\ No newline at end of file
......@@ -90,4 +90,36 @@ public class PensionConsigneeServiceImpl extends CrudServiceImpl<PensionConsigne
pensionConsigneeDTO.setCreateDate(new Date());
save(pensionConsigneeDTO);
}
@Override
public void addUserAddress(PensionConsigneeAddDTO dto) {
Integer ifDefault = 1;
QueryWrapper<PensionConsigneeEntity> queryWrapper = new QueryWrapper<>();
Long userId = dto.getUserId();
queryWrapper.eq("user_id", userId).eq("if_default", 1);
PensionConsigneeEntity pensionConsigneeEntity = pensionConsigneeDao.selectOne(queryWrapper);
if (pensionConsigneeEntity != null) {
if (dto.getIfDefault() == 0) { //不希望设置为默认地址
ifDefault = 0;
} else { //设为默认地址并将其他地址设置为非默认
pensionConsigneeEntity.setIfDefault(0);
update(ConvertUtils.sourceToTarget(pensionConsigneeEntity, PensionConsigneeDTO.class));
}
}
if (null != dto.getId()) {
PensionConsigneeDTO pensionConsigneeDTO = get(dto.getId());
BeanUtils.copyProperties(dto, pensionConsigneeDTO);
pensionConsigneeDTO.setIfDefault(ifDefault);
update(pensionConsigneeDTO);
} else {
PensionConsigneeDTO pensionConsigneeDTO = new PensionConsigneeDTO();
BeanUtils.copyProperties(dto, pensionConsigneeDTO);
pensionConsigneeDTO.setCreateDate(new Date());
pensionConsigneeDTO.setIfDefault(ifDefault);
pensionConsigneeDTO.setStatus(1);
save(pensionConsigneeDTO);
}
}
}
\ No newline at end of file
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