添加地址表
This commit is contained in:
parent
e47c708421
commit
a47d73cafb
@ -0,0 +1,82 @@
|
||||
package io.modules.sys.controller;
|
||||
|
||||
import io.common.constant.Constant;
|
||||
import io.common.page.PageData;
|
||||
import io.common.utils.Result;
|
||||
import io.common.validator.AssertUtils;
|
||||
import io.common.validator.ValidatorUtils;
|
||||
import io.common.validator.group.AddGroup;
|
||||
import io.common.validator.group.DefaultGroup;
|
||||
import io.common.validator.group.UpdateGroup;
|
||||
import io.modules.item.dto.AddressDTO;
|
||||
import io.modules.item.service.AddressService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("sys/address")
|
||||
@Tag(name="收货地址表")
|
||||
public class AddressController {
|
||||
@Autowired
|
||||
private AddressService addressService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@Parameters({
|
||||
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", in = ParameterIn.QUERY, required = true, ref="int") ,
|
||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", in = ParameterIn.QUERY,required = true, ref="int") ,
|
||||
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段", in = ParameterIn.QUERY, ref="String") ,
|
||||
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref="String")
|
||||
})
|
||||
public Result<PageData<AddressDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
|
||||
PageData<AddressDTO> page = addressService.page(params);
|
||||
return new Result<PageData<AddressDTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
public Result<AddressDTO> get(@PathVariable("id") Long id){
|
||||
AddressDTO data = addressService.get(id);
|
||||
return new Result<AddressDTO>().ok(data);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
public Result save(@RequestBody AddressDTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
||||
addressService.save(dto);
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
public Result update(@RequestBody AddressDTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||||
addressService.update(dto);
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@Operation(summary = "删除")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
Long[] ids = new Long[]{id};
|
||||
//效验数据
|
||||
AssertUtils.isArrayEmpty(ids, "id");
|
||||
addressService.delete(ids);
|
||||
return new Result();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.modules.item.dao;
|
||||
|
||||
|
||||
import io.common.dao.BaseDao;
|
||||
import io.modules.item.entity.AddressEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Mapper
|
||||
public interface AddressDao extends BaseDao<AddressEntity> {
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package io.modules.item.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.media.SchemaProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "收货地址表")
|
||||
public class AddressDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SchemaProperty(name = "编号")
|
||||
private Long id;
|
||||
|
||||
@SchemaProperty(name = "用户编号")
|
||||
private Long userId;
|
||||
|
||||
@SchemaProperty(name = "收货人姓名")
|
||||
private String recipientName;
|
||||
|
||||
@SchemaProperty(name = "详细地址")
|
||||
private String address;
|
||||
|
||||
@SchemaProperty(name = "省份")
|
||||
private String province;
|
||||
|
||||
@SchemaProperty(name = "城市")
|
||||
private String city;
|
||||
|
||||
@SchemaProperty(name = "区域/街道")
|
||||
private String area;
|
||||
|
||||
@SchemaProperty(name = "收货人联系电话")
|
||||
private String phone;
|
||||
|
||||
@SchemaProperty(name = "是否是默认地址")
|
||||
private Integer isDefault;
|
||||
|
||||
@SchemaProperty(name = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package io.modules.item.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Data
|
||||
@TableName("tb_address")
|
||||
public class AddressEntity {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 收货人姓名
|
||||
*/
|
||||
private String recipientName;
|
||||
/**
|
||||
* 详细地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 省份
|
||||
*/
|
||||
private String province;
|
||||
/**
|
||||
* 城市
|
||||
*/
|
||||
private String city;
|
||||
/**
|
||||
* 区域/街道
|
||||
*/
|
||||
private String area;
|
||||
/**
|
||||
* 收货人联系电话
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 是否是默认地址
|
||||
*/
|
||||
private Integer isDefault;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.modules.item.service;
|
||||
|
||||
|
||||
import io.common.service.CrudService;
|
||||
import io.modules.item.dto.AddressDTO;
|
||||
import io.modules.item.entity.AddressEntity;
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
public interface AddressService extends CrudService<AddressEntity, AddressDTO> {
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package io.modules.item.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.common.service.impl.CrudServiceImpl;
|
||||
import io.modules.item.dao.AddressDao;
|
||||
import io.modules.item.dto.AddressDTO;
|
||||
import io.modules.item.entity.AddressEntity;
|
||||
import io.modules.item.service.AddressService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
*
|
||||
* @author Mark #
|
||||
* @since 1.0.0 2025-02-14
|
||||
*/
|
||||
@Service
|
||||
public class AddressServiceImpl extends CrudServiceImpl<AddressDao, AddressEntity, AddressDTO> implements AddressService {
|
||||
|
||||
@Override
|
||||
public QueryWrapper<AddressEntity> getWrapper(Map<String, Object> params){
|
||||
String id = (String)params.get("id");
|
||||
|
||||
QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(StrUtil.isNotBlank(id), "id", id);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -40,6 +40,7 @@ public class ItemServiceImpl extends CrudServiceImpl<ItemDao, ItemEntity, ItemDT
|
||||
public QueryWrapper<ItemEntity> getWrapper(Map<String, Object> params){
|
||||
String title = (String)params.get("title");
|
||||
String status = (String)params.get("status");
|
||||
String view = (String)params.get("view");
|
||||
|
||||
QueryWrapper<ItemEntity> wrapper = new QueryWrapper<>();
|
||||
|
||||
@ -61,6 +62,9 @@ public class ItemServiceImpl extends CrudServiceImpl<ItemDao, ItemEntity, ItemDT
|
||||
}
|
||||
}
|
||||
wrapper.like(StrUtil.isNotBlank(title), "title", title);
|
||||
wrapper.orderByDesc(StrUtil.isNotBlank(view), "view");
|
||||
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,89 @@
|
||||
package io.controller;
|
||||
|
||||
import io.common.constant.Constant;
|
||||
import io.common.page.PageData;
|
||||
import io.common.utils.Result;
|
||||
import io.common.validator.AssertUtils;
|
||||
import io.common.validator.ValidatorUtils;
|
||||
import io.common.validator.group.AddGroup;
|
||||
import io.common.validator.group.DefaultGroup;
|
||||
import io.common.validator.group.UpdateGroup;
|
||||
import io.modules.item.dto.AddressDTO;
|
||||
import io.modules.item.service.AddressService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 收货地址表
|
||||
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api/address")
|
||||
@Tag(name="收货地址表")
|
||||
public class AddressController {
|
||||
@Autowired
|
||||
private AddressService addressService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@Parameters({
|
||||
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", in = ParameterIn.QUERY, required = true, ref="int") ,
|
||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", in = ParameterIn.QUERY,required = true, ref="int") ,
|
||||
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段", in = ParameterIn.QUERY, ref="String") ,
|
||||
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref="String")
|
||||
})
|
||||
public Result<PageData<AddressDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
|
||||
PageData<AddressDTO> page = addressService.page(params);
|
||||
|
||||
return new Result<PageData<AddressDTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
public Result<AddressDTO> get(@PathVariable("id") Long id){
|
||||
AddressDTO data = addressService.get(id);
|
||||
|
||||
return new Result<AddressDTO>().ok(data);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
public Result save(@RequestBody AddressDTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
||||
|
||||
addressService.save(dto);
|
||||
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
public Result update(@RequestBody AddressDTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||||
addressService.update(dto);
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@Operation(summary = "删除")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
Long[] ids = new Long[]{id};
|
||||
//效验数据
|
||||
AssertUtils.isArrayEmpty(ids, "id");
|
||||
addressService.delete(ids);
|
||||
return new Result();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -49,7 +49,8 @@ public class ItemController {
|
||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", in = ParameterIn.QUERY,required = true, ref="int") ,
|
||||
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段", in = ParameterIn.QUERY, ref="String") ,
|
||||
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref="String"),
|
||||
@Parameter(name = "status", description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref="String")
|
||||
@Parameter(name = "status", description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref="String"),
|
||||
@Parameter(name = "view", description = "预览排序", in = ParameterIn.QUERY, ref="String"),
|
||||
})
|
||||
public Result<PageData<ItemDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
|
||||
PageData<ItemDTO> page = itemService.page(params);
|
||||
@ -87,7 +88,6 @@ public class ItemController {
|
||||
List<ItemEntity> list = itemService.score();
|
||||
List<ItemEntity> res = list.stream().map(e -> {
|
||||
e.setImage(uploadUrl + e.getImage());
|
||||
|
||||
return e;
|
||||
}).collect(Collectors.toList());
|
||||
return new Result<List<ItemEntity>>().ok(res);
|
||||
@ -112,6 +112,8 @@ public class ItemController {
|
||||
ItemDTO data = itemService.get(id);
|
||||
data.setImage(uploadUrl + data.getImage());
|
||||
|
||||
data.setView(data.getView() + 1);
|
||||
itemService.update(data);
|
||||
// data.setIsFavorite(userBehaviorService.getIsFavorite(data.getId(),1));
|
||||
return new Result<ItemDTO>().ok(data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user