|
|
|
@ -14,6 +14,7 @@ import jty.expressdistributionsystem.utils.ClaimCodeUtil;
|
|
|
|
|
import jty.expressdistributionsystem.utils.ExpressCodeUtil;
|
|
|
|
|
import jty.expressdistributionsystem.utils.GetIdUtil;
|
|
|
|
|
import jty.expressdistributionsystem.utils.SendMessageUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@ -22,6 +23,7 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/user")
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class UserController {
|
|
|
|
|
@Resource
|
|
|
|
|
private UserService userService;
|
|
|
|
@ -51,87 +53,44 @@ public class UserController {
|
|
|
|
|
|
|
|
|
|
// 给快递员点赞
|
|
|
|
|
@PostMapping("/likes")
|
|
|
|
|
public Result<String> like(Long id) {
|
|
|
|
|
public Result<String> like(@RequestParam Long id) {
|
|
|
|
|
User employee = userService.getById(id);
|
|
|
|
|
employee.setLikes(employee.getLikes() + 1);
|
|
|
|
|
userService.save(employee);
|
|
|
|
|
userService.updateById(employee);
|
|
|
|
|
return new Result<>(200, "点赞成功", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户查看自己的快递记录
|
|
|
|
|
@GetMapping("/history")
|
|
|
|
|
public Result<Page<Records>> getHistory(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
|
// 用户查看发给别人消息
|
|
|
|
|
@GetMapping("/sendToMessage")
|
|
|
|
|
public Result<Page<Message>> sendToMessage(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
|
if (page <= 0 || pageSize == 0) {
|
|
|
|
|
return new Result<>(400, "页码和每页大小必须大于0", null);
|
|
|
|
|
}
|
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
|
Page<Records> pageInfo = new Page<>(page, pageSize);
|
|
|
|
|
LambdaQueryWrapper<Records> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(Records::getSendUserId, id);
|
|
|
|
|
queryWrapper.orderByDesc(Records::getCreateTime);
|
|
|
|
|
recordsService.page(pageInfo, queryWrapper);
|
|
|
|
|
return new Result<>(200, "", pageInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户收件
|
|
|
|
|
@PostMapping("/addressee")
|
|
|
|
|
public Result<String> addressee(@Validated @RequestBody @NotNull AddresseeDTO addresseeDTO) {
|
|
|
|
|
Long goodsId = addresseeDTO.getGoodsId();
|
|
|
|
|
QueryWrapper<Code> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("goods_id", goodsId);
|
|
|
|
|
Code code = codeService.getOne(queryWrapper);
|
|
|
|
|
// 判断取件码是否输入正确
|
|
|
|
|
if (!code.getClaim().equals(addresseeDTO.getClaimCode())) {
|
|
|
|
|
return new Result<>(401, "请输入正确的取件码", "");
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
recordsQueryWrapper.eq("goods_id", goodsId);
|
|
|
|
|
Records records = recordsService.getOne(recordsQueryWrapper);
|
|
|
|
|
records.setMark(1);
|
|
|
|
|
// 设置取件人
|
|
|
|
|
records.setAddresseeId(GetIdUtil.getId());
|
|
|
|
|
recordsService.save(records);
|
|
|
|
|
return new Result<>(200, "取件成功", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户代取快递
|
|
|
|
|
@PostMapping("/pickUp")
|
|
|
|
|
public Result<String> pickUpExpress(@RequestBody @Validated @NotNull PickUpExpressDTO pickUpExpressDTO) {
|
|
|
|
|
// 查询快递原主人信息
|
|
|
|
|
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
userQueryWrapper.eq("user_name", pickUpExpressDTO.getMaster());
|
|
|
|
|
User master = userService.getOne(userQueryWrapper);
|
|
|
|
|
if (master == null) {
|
|
|
|
|
return new Result<>(404, "该用户不存在", "");
|
|
|
|
|
}
|
|
|
|
|
// 查询快递信息
|
|
|
|
|
QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
goodsQueryWrapper.eq("express_code", pickUpExpressDTO.getExpressCode());
|
|
|
|
|
Goods goods = goodsService.getOne(goodsQueryWrapper);
|
|
|
|
|
if (goods == null) {
|
|
|
|
|
return new Result<>(404, "快递不存在", "");
|
|
|
|
|
}
|
|
|
|
|
// 代取
|
|
|
|
|
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
recordsQueryWrapper.eq("goods_id", goods.getId());
|
|
|
|
|
Records records = recordsService.getOne(recordsQueryWrapper);
|
|
|
|
|
records.setMark(1);
|
|
|
|
|
records.setAddresseeId(GetIdUtil.getId());
|
|
|
|
|
recordsService.save(records);
|
|
|
|
|
return new Result<>(200, "待取成功", "");
|
|
|
|
|
log.info("当前登录用户的id: {}", id);
|
|
|
|
|
Page<Message> messagePage = new Page<>(page, pageSize);
|
|
|
|
|
LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
// 添加查询条件
|
|
|
|
|
messageLambdaQueryWrapper.eq(Message::getSendUserId, id);
|
|
|
|
|
// 排序条件:先按 mark 对应值排序,然后按时间排序
|
|
|
|
|
messageLambdaQueryWrapper.orderByDesc(Message::getMark) // mark 值大的排前面
|
|
|
|
|
.orderByDesc(Message::getCreateTime); // 时间新的排前面
|
|
|
|
|
messageService.page(messagePage, messageLambdaQueryWrapper);
|
|
|
|
|
return new Result<>(200, "获取成功", messagePage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户查看消息
|
|
|
|
|
@GetMapping("/getMessage")
|
|
|
|
|
public Result<Page<Message>> getMessage(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
|
// 用户查看别人发给自己的消息
|
|
|
|
|
@GetMapping("/getFromMessage")
|
|
|
|
|
public Result<Page<Message>> getFromMessage(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
|
if (page <= 0 || pageSize == 0) {
|
|
|
|
|
return new Result<>(400, "页码和每页大小必须大于0", null);
|
|
|
|
|
}
|
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
|
log.info("当前登录用户的id: {}", id);
|
|
|
|
|
Page<Message> messagePage = new Page<>(page, pageSize);
|
|
|
|
|
LambdaQueryWrapper<Message> messageLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
// 添加查询条件
|
|
|
|
|
messageLambdaQueryWrapper.eq(Message::getSendUserId, id);
|
|
|
|
|
messageLambdaQueryWrapper.eq(Message::getGetUserId, id);
|
|
|
|
|
// 排序条件:先按 mark 对应值排序,然后按时间排序
|
|
|
|
|
messageLambdaQueryWrapper.orderByDesc(Message::getMark) // mark 值大的排前面
|
|
|
|
|
.orderByDesc(Message::getCreateTime); // 时间新的排前面
|
|
|
|
@ -142,12 +101,26 @@ public class UserController {
|
|
|
|
|
// 用户确认查看消息
|
|
|
|
|
@PostMapping("/confirmMessage")
|
|
|
|
|
public Result<String> confirmMessage(@RequestParam Long id) {
|
|
|
|
|
Records records = recordsService.getById(id);
|
|
|
|
|
records.setMark(0);
|
|
|
|
|
recordsService.save(records);
|
|
|
|
|
Message message = messageService.getById(id);
|
|
|
|
|
message.setMark(0);
|
|
|
|
|
messageService.updateById(message);
|
|
|
|
|
return new Result<>(200, "消息查看成功", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户新建快递地址
|
|
|
|
|
@PostMapping("/addAddress")
|
|
|
|
|
public Result<String> addAddress(@RequestBody @NotNull Address address) {
|
|
|
|
|
// 查询快递地址是否已经存在
|
|
|
|
|
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
addressLambdaQueryWrapper.eq(Address::getAddress, address.getAddress());
|
|
|
|
|
Address getAddress = addressService.getOne(addressLambdaQueryWrapper);
|
|
|
|
|
if (getAddress != null) {
|
|
|
|
|
return new Result<>(409, "该地址已存在", "");
|
|
|
|
|
}
|
|
|
|
|
addressService.save(address);
|
|
|
|
|
return new Result<>(200, "地址创建成功", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户获取自己写过的地址
|
|
|
|
|
@GetMapping("/getAddress")
|
|
|
|
|
public Result<List<Address>> listAddress() {
|
|
|
|
@ -158,6 +131,21 @@ public class UserController {
|
|
|
|
|
return new Result<>(200, "", list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户查看自己的发送快递记录
|
|
|
|
|
@GetMapping("/history")
|
|
|
|
|
public Result<Page<Records>> getHistory(@RequestParam int page, @RequestParam int pageSize) {
|
|
|
|
|
if (page <= 0 || pageSize == 0) {
|
|
|
|
|
return new Result<>(400, "页码和每页大小必须大于0", null);
|
|
|
|
|
}
|
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
|
Page<Records> pageInfo = new Page<>(page, pageSize);
|
|
|
|
|
LambdaQueryWrapper<Records> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(Records::getSendUserId, id);
|
|
|
|
|
queryWrapper.orderByDesc(Records::getCreateTime);
|
|
|
|
|
recordsService.page(pageInfo, queryWrapper);
|
|
|
|
|
return new Result<>(200, "", pageInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户寄件
|
|
|
|
|
@PostMapping("/shipment")
|
|
|
|
|
public Result<String> shipmentExpress(@RequestBody @Validated @NotNull GoodsDTO goodsDTO) {
|
|
|
|
@ -165,9 +153,16 @@ public class UserController {
|
|
|
|
|
LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
userLambdaQueryWrapper.eq(User::getUserName, goodsDTO.getGetUserName());
|
|
|
|
|
User getUser = userService.getOne(userLambdaQueryWrapper);
|
|
|
|
|
if(getUser == null) {
|
|
|
|
|
if (getUser == null) {
|
|
|
|
|
return new Result<>(404, "用户不存在", null);
|
|
|
|
|
}
|
|
|
|
|
// 判断地址是否存在
|
|
|
|
|
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddress());
|
|
|
|
|
Address address = addressService.getOne(addressLambdaQueryWrapper);
|
|
|
|
|
if (address == null) {
|
|
|
|
|
return new Result<>(404, "地址不存在", null);
|
|
|
|
|
}
|
|
|
|
|
// 生成快递码
|
|
|
|
|
String expressCode = ExpressCodeUtil.getExpressCode(goodsDTO.getCompany());
|
|
|
|
|
// 生成取件码
|
|
|
|
@ -183,11 +178,9 @@ public class UserController {
|
|
|
|
|
Records records = new Records();
|
|
|
|
|
records.setSendUserId(GetIdUtil.getId());
|
|
|
|
|
records.setGetUserId(getUser.getId());
|
|
|
|
|
LambdaQueryWrapper<Address> addressLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddress());
|
|
|
|
|
Address address = addressService.getOne(addressLambdaQueryWrapper);
|
|
|
|
|
records.setAddresseeId(address.getId());
|
|
|
|
|
records.setAddressId(address.getId());
|
|
|
|
|
records.setGoodsId(goods.getId());
|
|
|
|
|
records.setExpressId(goodsDTO.getExpressId());
|
|
|
|
|
recordsService.save(records);
|
|
|
|
|
Code code = new Code();
|
|
|
|
|
code.setClaim(claimCode);
|
|
|
|
@ -195,4 +188,60 @@ public class UserController {
|
|
|
|
|
codeService.save(code);
|
|
|
|
|
return new Result<>(200, "寄件成功", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户收件
|
|
|
|
|
@PostMapping("/addressee")
|
|
|
|
|
public Result<String> addressee(@Validated @RequestBody @NotNull AddresseeDTO addresseeDTO) {
|
|
|
|
|
// 判断是不是自己的快递
|
|
|
|
|
Long goodsId = addresseeDTO.getGoodsId();
|
|
|
|
|
Goods goods = goodsService.getById(goodsId);
|
|
|
|
|
if (goods.getGetUserId().compareTo(GetIdUtil.getId()) != 0) {
|
|
|
|
|
return new Result<>(401, "签收他人快递请选择代取功能", "");
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<Code> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("goods_id", goodsId);
|
|
|
|
|
Code code = codeService.getOne(queryWrapper);
|
|
|
|
|
// 判断取件码是否输入正确
|
|
|
|
|
if (!code.getClaim().equals(addresseeDTO.getClaimCode())) {
|
|
|
|
|
return new Result<>(401, "请输入正确的取件码", "");
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
recordsQueryWrapper.eq("goods_id", goodsId);
|
|
|
|
|
Records records = recordsService.getOne(recordsQueryWrapper);
|
|
|
|
|
records.setMark(1);
|
|
|
|
|
// 设置取件人
|
|
|
|
|
records.setAddresseeId(GetIdUtil.getId());
|
|
|
|
|
recordsService.updateById(records);
|
|
|
|
|
return new Result<>(200, "取件成功", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用户代取快递
|
|
|
|
|
@PostMapping("/pickUp")
|
|
|
|
|
public Result<String> pickUpExpress(@RequestBody @Validated @NotNull PickUpExpressDTO pickUpExpressDTO) {
|
|
|
|
|
// 查询快递原主人信息
|
|
|
|
|
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
userQueryWrapper.eq("user_name", pickUpExpressDTO.getMaster());
|
|
|
|
|
User master = userService.getOne(userQueryWrapper);
|
|
|
|
|
if (master == null) {
|
|
|
|
|
return new Result<>(404, "该用户不存在", "");
|
|
|
|
|
}
|
|
|
|
|
// 查询快递信息
|
|
|
|
|
QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
goodsQueryWrapper.eq("express_code", pickUpExpressDTO.getExpressCode());
|
|
|
|
|
Goods goods = goodsService.getOne(goodsQueryWrapper);
|
|
|
|
|
if (goods == null) {
|
|
|
|
|
return new Result<>(404, "快递不存在", "");
|
|
|
|
|
}
|
|
|
|
|
// 代取
|
|
|
|
|
QueryWrapper<Records> recordsQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
recordsQueryWrapper.eq("goods_id", goods.getId());
|
|
|
|
|
Records records = recordsService.getOne(recordsQueryWrapper);
|
|
|
|
|
if(records.getMark() == 1) {
|
|
|
|
|
return new Result<>(500, "快递已被签收", "");
|
|
|
|
|
}
|
|
|
|
|
records.setMark(1);
|
|
|
|
|
records.setAddresseeId(GetIdUtil.getId());
|
|
|
|
|
recordsService.updateById(records);
|
|
|
|
|
return new Result<>(200, "代取成功", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|