Commit 47e0b594 authored by Shen's avatar Shen

1.用户地址 添加接口

2.admin模块中bug修复
parent 7424b565
......@@ -19,7 +19,7 @@ import java.util.Date;
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("pension_consignee")
public class PensionConsigneeEntity extends BaseEntity {
public class PensionConsigneeEntity {
private static final long serialVersionUID = 1L;
@TableId
......
......@@ -63,6 +63,7 @@ public class PensionConsigneeController {
return new Result<PensionConsigneeDTO>().ok(data);
}
@Deprecated
@PostMapping
@ApiOperation("保存")
public Result save(@RequestBody PensionConsigneeDTO dto){
......@@ -74,6 +75,7 @@ public class PensionConsigneeController {
return new Result();
}
@Deprecated
@PutMapping
@ApiOperation("修改")
public Result update(@RequestBody PensionConsigneeDTO dto){
......@@ -85,6 +87,7 @@ public class PensionConsigneeController {
return new Result();
}
@Deprecated
@DeleteMapping
@ApiOperation("删除")
public Result delete(@RequestBody Long[] ids){
......@@ -106,10 +109,34 @@ public class PensionConsigneeController {
@Login
@GetMapping("findMyAddress")
@ApiOperation("查询本人收货地址")
public Result<List<PensionConsigneeDTO>> findMyAddress(@ApiIgnore @LoginUser UserEntity user){
log.info("user={}", user);
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
}) //TODO 分页
public Result<List<PensionConsigneeDTO>> findMyAddress(@ApiIgnore @LoginUser UserEntity user,
@ApiIgnore @RequestParam Map<String, Object> params){
List<PensionConsigneeDTO> pensionConsigneeDTOList = pensionConsigneeService.findByUserId(user.getId());
return new Result<List<PensionConsigneeDTO>>().ok(pensionConsigneeDTOList);
}
@PostMapping("addUserAddress")
@ApiOperation("根据用户Id添加收货地址")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", required = true, dataType="long") ,
@ApiImplicitParam(name = "username", value = "用户姓名", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "mobile", value = "用户手机号", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "province", value = "省份", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "city", value = "城市", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "district", value = "区县", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "address", value = "详细地址", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "zip", value = "邮编", paramType = "query",required = true, dataType="String") ,
@ApiImplicitParam(name = "ifDefault", value = "是否默认,传0则非默认,1则设为为默认,用户第一个地址传0或1均为即为默认地址", paramType = "query",required = true, dataType="int") ,
})
public Result addUserAddress(@ApiIgnore @RequestParam Map<String, Object> params){
pensionConsigneeService.addUserAddress(params);
return new Result();
}
}
\ No newline at end of file
package io.hmit.modules.serviceOrder.dto;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
*
* @author zsh 408538940@qq.com
* @since 1.0.0 2021-05-06
*/
@Data
@ApiModel(value = "用户地址添加")
public class PensionConsigneeAddDTO implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Long id;
@ApiModelProperty(value = "用户ID")
private Long userId;
@ApiModelProperty(value = "收货人姓名")
private String consigneeName;
@ApiModelProperty(value = "收货人电话")
private String consigneeMobile;
@ApiModelProperty(value = "省份")
private String consigneeProvince;
@ApiModelProperty(value = "城市")
private String consigneeCity;
@ApiModelProperty(value = "区/县")
private String consigneeDistrict;
@ApiModelProperty(value = "详细地址")
private String consigneeAddress;
@ApiModelProperty(value = "邮编")
private String consigneeZip;
@ApiModelProperty(value = "是否为默认地址")
private Integer ifDefault;
@ApiModelProperty(value = "状态")
private Integer status;
public PensionConsigneeAddDTO(Long userId, String consigneeName, String consigneeMobile, String consigneeProvince,
String consigneeCity, String consigneeDistrict, String consigneeAddress,
String consigneeZip, Integer ifDefault, Integer status) {
this.userId = userId;
this.consigneeName = consigneeName;
this.consigneeMobile = consigneeMobile;
this.consigneeProvince = consigneeProvince;
this.consigneeCity = consigneeCity;
this.consigneeDistrict = consigneeDistrict;
this.consigneeAddress = consigneeAddress;
this.consigneeZip = consigneeZip;
this.ifDefault = ifDefault;
this.status = status;
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import io.hmit.modules.serviceOrder.dto.PensionConsigneeDTO;
import io.hmit.modules.serviceOrder.entity.PensionConsigneeEntity;
import java.util.List;
import java.util.Map;
/**
*
......@@ -16,4 +17,6 @@ public interface PensionConsigneeService extends CrudService<PensionConsigneeEnt
List<PensionConsigneeDTO> findByUserId(Long userId);
void addUserAddress(Map<String, Object> params);
}
\ No newline at end of file
......@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.modules.serviceOrder.dao.PensionConsigneeDao;
import io.hmit.modules.serviceOrder.dto.PensionConsigneeAddDTO;
import io.hmit.modules.serviceOrder.dto.PensionConsigneeDTO;
import io.hmit.modules.serviceOrder.entity.PensionConsigneeEntity;
import io.hmit.modules.serviceOrder.service.PensionConsigneeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -43,4 +45,28 @@ public class PensionConsigneeServiceImpl extends CrudServiceImpl<PensionConsigne
List<PensionConsigneeEntity> platformPayInfoEntityList = pensionConsigneeDao.selectList(queryWrapper);
return ConvertUtils.sourceToTarget(platformPayInfoEntityList, PensionConsigneeDTO.class);
}
@Override
public void addUserAddress(Map<String, Object> params) {
Integer ifDefault = 1;
QueryWrapper<PensionConsigneeEntity> queryWrapper = new QueryWrapper<>();
Long userId = Long.parseLong(params.get("userId").toString());
queryWrapper.eq("user_id", userId).eq("if_default", 1);
PensionConsigneeEntity pensionConsigneeEntity = pensionConsigneeDao.selectOne(queryWrapper);
if (pensionConsigneeEntity != null) {
if (Integer.parseInt(params.get("ifDefault").toString()) == 0) { //不希望设置为默认地址
ifDefault = 0;
} else { //设为默认地址并将其他地址设置为非默认
pensionConsigneeEntity.setIfDefault(0);
update(ConvertUtils.sourceToTarget(pensionConsigneeEntity, PensionConsigneeDTO.class));
}
}
PensionConsigneeAddDTO addressDTO = new PensionConsigneeAddDTO(userId, params.get("username").toString()
,params.get("mobile").toString(), params.get("province").toString(), params.get("city").toString(), params.get("district").toString(),
params.get("address").toString(), params.get("zip").toString(), ifDefault, 1);
PensionConsigneeDTO pensionConsigneeDTO = new PensionConsigneeDTO();
BeanUtils.copyProperties(addressDTO, pensionConsigneeDTO);
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