diff --git a/src/main/java/jty/expressdistributionsystem/DTO/AddresseeDTO.java b/src/main/java/jty/expressdistributionsystem/DTO/AddresseeDTO.java new file mode 100644 index 0000000..a8306b4 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/DTO/AddresseeDTO.java @@ -0,0 +1,14 @@ +package jty.expressdistributionsystem.DTO; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class AddresseeDTO { + @NotNull + private Long goodsId; + + @NotBlank(message = "取件码不能为空") + private String claimCode; +} diff --git a/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java b/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java new file mode 100644 index 0000000..5f8253b --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/DTO/GoodsDTO.java @@ -0,0 +1,29 @@ +package jty.expressdistributionsystem.DTO; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class GoodsDTO { + @NotBlank(message = "请选择快递公司") + private String company; + + @JsonSerialize(using = ToStringSerializer.class) + @NotNull + private Long sendUserId; + + @NotBlank(message = "收件人名字不能为空") + private String getUserName; + + @NotBlank(message = "快递名称不能为空") + private String name; + + @NotBlank(message = "快递重量不能为空") + private String quality; + + @NotBlank(message = "运送地址不能为空") + private String address; +} diff --git a/src/main/java/jty/expressdistributionsystem/DTO/PickUpExpressDTO.java b/src/main/java/jty/expressdistributionsystem/DTO/PickUpExpressDTO.java new file mode 100644 index 0000000..c72e7a9 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/DTO/PickUpExpressDTO.java @@ -0,0 +1,16 @@ +package jty.expressdistributionsystem.DTO; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +@Data +public class PickUpExpressDTO { + @NotBlank(message = "收件人名字不能为空") + private String master; + + @NotBlank(message = "快递码不能为空") + private String expressCode; + + @NotBlank(message = "取件码不能为空") + private String claimCode; +} diff --git a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java index b353e00..8b60919 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/AdminController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/AdminController.java @@ -4,13 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.annotation.Resource; import jty.expressdistributionsystem.DTO.SendMessageDTO; -import jty.expressdistributionsystem.config.MyMetaObjectHandler; import jty.expressdistributionsystem.entity.Message; import jty.expressdistributionsystem.entity.Result; import jty.expressdistributionsystem.entity.User; import jty.expressdistributionsystem.service.MessageService; import jty.expressdistributionsystem.service.UserService; -import jty.expressdistributionsystem.utils.SendMessage; +import jty.expressdistributionsystem.utils.SendMessageUtil; import org.springframework.web.bind.annotation.*; @RestController @@ -62,7 +61,7 @@ public class AdminController { // 管理员发送消息 @PostMapping("/sendMessage") public Result sendMessage(@RequestBody SendMessageDTO sendMessageDTO) { - Message message = SendMessage.sendMessage(sendMessageDTO); + Message message = SendMessageUtil.sendMessage(sendMessageDTO); messageService.save(message); return new Result<>(200, "发送成功", ""); } diff --git a/src/main/java/jty/expressdistributionsystem/controller/UserController.java b/src/main/java/jty/expressdistributionsystem/controller/UserController.java index 2f66c75..cf01613 100644 --- a/src/main/java/jty/expressdistributionsystem/controller/UserController.java +++ b/src/main/java/jty/expressdistributionsystem/controller/UserController.java @@ -1,155 +1,198 @@ package jty.expressdistributionsystem.controller; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.annotation.Resource; -import jty.expressdistributionsystem.DTO.UserLoginByAccountDTO; -import jty.expressdistributionsystem.DTO.UserModifyInfoDTO; -import jty.expressdistributionsystem.DTO.UserModifyPasswordDTO; -import jty.expressdistributionsystem.entity.Result; -import jty.expressdistributionsystem.entity.User; -import jty.expressdistributionsystem.service.UserService; +import jty.expressdistributionsystem.DTO.AddresseeDTO; +import jty.expressdistributionsystem.DTO.GoodsDTO; +import jty.expressdistributionsystem.DTO.PickUpExpressDTO; +import jty.expressdistributionsystem.DTO.SendMessageDTO; +import jty.expressdistributionsystem.entity.*; +import jty.expressdistributionsystem.service.*; +import jty.expressdistributionsystem.utils.ClaimCodeUtil; +import jty.expressdistributionsystem.utils.ExpressCodeUtil; import jty.expressdistributionsystem.utils.GetIdUtil; -import jty.expressdistributionsystem.utils.JwtUtil; -import jty.expressdistributionsystem.utils.Md5Util; -import jty.expressdistributionsystem.utils.ThreadLocalUtil; -import lombok.extern.slf4j.Slf4j; +import jty.expressdistributionsystem.utils.SendMessageUtil; import org.jetbrains.annotations.NotNull; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.core.ValueOperations; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.TimeUnit; +import java.util.List; @RestController @RequestMapping("/user") -@Slf4j public class UserController { @Resource private UserService userService; @Resource - private StringRedisTemplate stringRedisTemplate; - - // 注册 - @PostMapping("/register") - public Result register(@RequestBody @Validated @NotNull User user) { - // 查找用户是否存在 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("user_name", user.getUserName()) - .or() - .eq("account", user.getAccount()) - .or() - .eq("phone", user.getPhone()); - User u = userService.getOne(queryWrapper); - if (u != null) { - return new Result<>(409, "账号或用户名或手机号已存在", ""); - } - // 密码加密 - user.setPassword(Md5Util.getMD5String(user.getPassword())); - // 用户数据入库 - userService.save(user); - return new Result<>(200, "注册成功", ""); + private MessageService messageService; + + @Resource + private RecordsService recordsService; + + @Resource + private CodeService codeService; + + @Resource + private GoodsService goodsService; + + @Resource + private AddressService addressService; + + // 用户给快递员发消息 + @PostMapping("/sendMessage") + public Result sendMessage(@Validated @RequestBody SendMessageDTO sendMessageDTO) { + Message message = SendMessageUtil.sendMessage(sendMessageDTO); + messageService.save(message); + return new Result<>(200, "发送成功", ""); } - // 通过账号登录 - @PostMapping("/loginByAccount") - public Result login(@RequestBody @Validated @NotNull UserLoginByAccountDTO userLoginByAccountDTO) { - // 查询用户是否存在 - Optional optionalUser = Optional.ofNullable(userService.getOne(new QueryWrapper() - .eq("account", userLoginByAccountDTO.getAccount()))); - if (optionalUser.isEmpty() || !Md5Util.getMD5String(userLoginByAccountDTO.getPassword()).equals(optionalUser.get().getPassword())) { - return new Result<>(401, "账号或者密码错误", ""); - } - User user = optionalUser.get(); - if(user.getDisabled() == 1){ - return new Result<>(403, "该账号已被禁用, 请联系管理员", ""); - } - user.setLoginTime(LocalDateTime.now()); - userService.update(user, new UpdateWrapper().eq("id", user.getId())); - // 校验通过 - Map claims = new HashMap<>(); - claims.put("id", user.getId()); - claims.put("account", userLoginByAccountDTO.getAccount()); - // 获取token - String token = JwtUtil.genToken(claims); - // 存放token到redis当中进行持久化存储 - ValueOperations stringStringValueOperations = stringRedisTemplate.opsForValue(); - // 设置过期时间(1天) - stringStringValueOperations.set(token, token, 1, TimeUnit.DAYS); - // 返回token给前端 - return new Result<>(200, "登录成功", token); + // 给快递员点赞 + @PostMapping("/likes") + public Result like(Long id) { + User employee = userService.getById(id); + employee.setLikes(employee.getLikes() + 1); + userService.save(employee); + return new Result<>(200, "点赞成功", ""); } - // 修改个人信息 - @PutMapping("/modify") - public Result modifyInfo(@RequestBody @Validated @NotNull UserModifyInfoDTO userModifyInfoDTO) { - // 获取登录用户id + // 用户查看自己的快递记录 + @GetMapping("/history") + public Result> getHistory(@RequestParam int page, @RequestParam int pageSize) { + if (page <= 0 || pageSize == 0) { + return new Result<>(400, "页码和每页大小必须大于0", null); + } Long id = GetIdUtil.getId(); - User user = userService.getById(id); - // 检查phone和userName是否与当前用户信息一致 - boolean isPhoneSame = user.getPhone().equals(userModifyInfoDTO.getPhone()); - boolean isUserNameSame = user.getUserName().equals(userModifyInfoDTO.getUserName()); - if (isPhoneSame && isUserNameSame) { - return new Result<>(400, "请修改您的信息", ""); + Page pageInfo = new Page<>(page, pageSize); + LambdaQueryWrapper 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 addressee(@Validated @RequestBody @NotNull AddresseeDTO addresseeDTO) { + Long goodsId = addresseeDTO.getGoodsId(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("goods_id", goodsId); + Code code = codeService.getOne(queryWrapper); + // 判断取件码是否输入正确 + if (!code.getClaim().equals(addresseeDTO.getClaimCode())) { + return new Result<>(401, "请输入正确的取件码", ""); } - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (!isPhoneSame) { - queryWrapper.eq("phone", userModifyInfoDTO.getPhone()); - if (userService.getOne(queryWrapper) != null) { - return new Result<>(400, "该手机号已被注册", ""); - } - user.setPhone(userModifyInfoDTO.getPhone()); + QueryWrapper 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 pickUpExpress(@RequestBody @Validated @NotNull PickUpExpressDTO pickUpExpressDTO) { + // 查询快递原主人信息 + QueryWrapper userQueryWrapper = new QueryWrapper<>(); + userQueryWrapper.eq("user_name", pickUpExpressDTO.getMaster()); + User master = userService.getOne(userQueryWrapper); + if (master == null) { + return new Result<>(404, "该用户不存在", ""); } - queryWrapper.clear(); - if (!isUserNameSame) { - queryWrapper.eq("user_name", userModifyInfoDTO.getUserName()); - if (userService.getOne(queryWrapper) != null) { - return new Result<>(400, "该用户名已被使用", ""); - } - user.setUserName(userModifyInfoDTO.getUserName()); + // 查询快递信息 + QueryWrapper goodsQueryWrapper = new QueryWrapper<>(); + goodsQueryWrapper.eq("express_code", pickUpExpressDTO.getExpressCode()); + Goods goods = goodsService.getOne(goodsQueryWrapper); + if (goods == null) { + return new Result<>(404, "快递不存在", ""); } - user.setUpdateTime(null); - userService.updateById(user); - return new Result<>(200, "用户信息修改成功", user); + // 代取 + QueryWrapper 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, "待取成功", ""); } - // 修改个人密码 - @PutMapping("/rePassword") - public Result modifyPassword(@RequestHeader("Authorization") String token, - @RequestBody @Validated @NotNull UserModifyPasswordDTO userModifyPasswordDTO) { - // 判断密码 - if (userModifyPasswordDTO.getOldPassword().equals(userModifyPasswordDTO.getNewPassword())) { - return new Result<>(409, "新密码不得和旧密码一致", ""); - } - if (!userModifyPasswordDTO.getNewPassword().equals(userModifyPasswordDTO.getReNewPassword())) { - return new Result<>(409, "两次输入密码不相同", ""); + // 用户查看消息 + @GetMapping("/getMessage") + public Result> getMessage(@RequestParam int page, @RequestParam int pageSize) { + if (page <= 0 || pageSize == 0) { + return new Result<>(400, "页码和每页大小必须大于0", null); } Long id = GetIdUtil.getId(); - User user = userService.getById(id); - if (!user.getIdentity().equals(userModifyPasswordDTO.getIdentity())) { - return new Result<>(409, "身份证有误", ""); - } - user.setPassword(Md5Util.getMD5String(userModifyPasswordDTO.getNewPassword())); - user.setUpdateTime(null); - userService.updateById(user); - // 删除redis当中的token - stringRedisTemplate.delete(token); - // 删除当前线程的存储信息 - ThreadLocalUtil.remove(); - return new Result<>(200, "密码修改成功, 请重新登陆", ""); + Page messagePage = new Page<>(page, pageSize); + LambdaQueryWrapper 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("/info") - public Result getInfo() { - Long id = GetIdUtil.getId(); - User user = userService.getById(id); - return new Result<>(200, "", user); + // 用户确认查看消息 + @PostMapping("/confirmMessage") + public Result confirmMessage(@RequestParam Long id) { + Records records = recordsService.getById(id); + records.setMark(0); + recordsService.save(records); + return new Result<>(200, "消息查看成功", ""); + } + + // 用户获取自己写过的地址 + @GetMapping("/getAddress") + public Result> listAddress() { + LambdaQueryWrapper
addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); + addressLambdaQueryWrapper.eq(Address::getUserId, GetIdUtil.getId()) + .orderByDesc(Address::getAddress); + List
list = addressService.list(addressLambdaQueryWrapper); + return new Result<>(200, "", list); + } + + // 用户寄件 + @PostMapping("/shipment") + public Result shipmentExpress(@RequestBody @Validated @NotNull GoodsDTO goodsDTO) { + // 判断用户是否存在 + LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); + userLambdaQueryWrapper.eq(User::getUserName, goodsDTO.getGetUserName()); + User getUser = userService.getOne(userLambdaQueryWrapper); + if(getUser == null) { + return new Result<>(404, "用户不存在", null); + } + // 生成快递码 + String expressCode = ExpressCodeUtil.getExpressCode(goodsDTO.getCompany()); + // 生成取件码 + String claimCode = ClaimCodeUtil.getClaimCode(goodsDTO.getCompany()); + Goods goods = new Goods(); + goods.setSendUserId(GetIdUtil.getId()); + goods.setGetUserId(getUser.getId()); + goods.setExpressCode(expressCode); + goods.setName(goodsDTO.getName()); + goods.setQuality(goodsDTO.getQuality()); + goodsService.save(goods); + // 存进历史记录 + Records records = new Records(); + records.setSendUserId(GetIdUtil.getId()); + records.setGetUserId(getUser.getId()); + LambdaQueryWrapper
addressLambdaQueryWrapper = new LambdaQueryWrapper<>(); + addressLambdaQueryWrapper.eq(Address::getAddress, goodsDTO.getAddress()); + Address address = addressService.getOne(addressLambdaQueryWrapper); + records.setAddresseeId(address.getId()); + records.setGoodsId(goods.getId()); + recordsService.save(records); + Code code = new Code(); + code.setClaim(claimCode); + code.setGoodsId(goods.getId()); + codeService.save(code); + return new Result<>(200, "寄件成功", ""); } } diff --git a/src/main/java/jty/expressdistributionsystem/entity/Goods.java b/src/main/java/jty/expressdistributionsystem/entity/Goods.java index d503ef1..512bda3 100644 --- a/src/main/java/jty/expressdistributionsystem/entity/Goods.java +++ b/src/main/java/jty/expressdistributionsystem/entity/Goods.java @@ -30,7 +30,7 @@ public class Goods implements Serializable { @TableField("get_user_id") @JsonSerialize(using = ToStringSerializer.class) @NotNull - private String getUserId; + private Long getUserId; @TableField("express_code") @NotBlank(message = "快递码未生成, 请重新填写信息") diff --git a/src/main/java/jty/expressdistributionsystem/entity/Records.java b/src/main/java/jty/expressdistributionsystem/entity/Records.java index 0018a27..dd1107f 100644 --- a/src/main/java/jty/expressdistributionsystem/entity/Records.java +++ b/src/main/java/jty/expressdistributionsystem/entity/Records.java @@ -1,5 +1,6 @@ package jty.expressdistributionsystem.entity; +import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -37,6 +38,13 @@ public class Records implements Serializable { @NotNull private Long goodsId; - @TableField("create_time") + @TableField("mark") + private Integer mark; + + @TableField("addressee_id") + @JsonSerialize(using = ToStringSerializer.class) + private Long addresseeId; + + @TableField(value = "create_time", fill = FieldFill.INSERT) private LocalDateTime createTime; } diff --git a/src/main/java/jty/expressdistributionsystem/mapper/CodeMapper.java b/src/main/java/jty/expressdistributionsystem/mapper/CodeMapper.java new file mode 100644 index 0000000..2ad692c --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/mapper/CodeMapper.java @@ -0,0 +1,7 @@ +package jty.expressdistributionsystem.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import jty.expressdistributionsystem.entity.Code; + +public interface CodeMapper extends BaseMapper { +} diff --git a/src/main/java/jty/expressdistributionsystem/mapper/RecordsMapper.java b/src/main/java/jty/expressdistributionsystem/mapper/RecordsMapper.java new file mode 100644 index 0000000..0237f20 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/mapper/RecordsMapper.java @@ -0,0 +1,7 @@ +package jty.expressdistributionsystem.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import jty.expressdistributionsystem.entity.Records; + +public interface RecordsMapper extends BaseMapper { +} diff --git a/src/main/java/jty/expressdistributionsystem/service/CodeService.java b/src/main/java/jty/expressdistributionsystem/service/CodeService.java new file mode 100644 index 0000000..73624a1 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/service/CodeService.java @@ -0,0 +1,7 @@ +package jty.expressdistributionsystem.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import jty.expressdistributionsystem.entity.Code; + +public interface CodeService extends IService { +} diff --git a/src/main/java/jty/expressdistributionsystem/service/RecordsService.java b/src/main/java/jty/expressdistributionsystem/service/RecordsService.java new file mode 100644 index 0000000..f0b02f4 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/service/RecordsService.java @@ -0,0 +1,7 @@ +package jty.expressdistributionsystem.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import jty.expressdistributionsystem.entity.Records; + +public interface RecordsService extends IService { +} diff --git a/src/main/java/jty/expressdistributionsystem/service/impl/CodeServiceImpl.java b/src/main/java/jty/expressdistributionsystem/service/impl/CodeServiceImpl.java new file mode 100644 index 0000000..72c9878 --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/service/impl/CodeServiceImpl.java @@ -0,0 +1,11 @@ +package jty.expressdistributionsystem.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import jty.expressdistributionsystem.entity.Code; +import jty.expressdistributionsystem.mapper.CodeMapper; +import jty.expressdistributionsystem.service.CodeService; +import org.springframework.stereotype.Service; + +@Service +public class CodeServiceImpl extends ServiceImpl implements CodeService { +} diff --git a/src/main/java/jty/expressdistributionsystem/service/impl/RecordsServiceImpl.java b/src/main/java/jty/expressdistributionsystem/service/impl/RecordsServiceImpl.java new file mode 100644 index 0000000..f80c25b --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/service/impl/RecordsServiceImpl.java @@ -0,0 +1,11 @@ +package jty.expressdistributionsystem.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import jty.expressdistributionsystem.entity.Records; +import jty.expressdistributionsystem.mapper.RecordsMapper; +import jty.expressdistributionsystem.service.RecordsService; +import org.springframework.stereotype.Service; + +@Service +public class RecordsServiceImpl extends ServiceImpl implements RecordsService { +} diff --git a/src/main/java/jty/expressdistributionsystem/utils/ClaimCodeUtil.java b/src/main/java/jty/expressdistributionsystem/utils/ClaimCodeUtil.java new file mode 100644 index 0000000..c0c758d --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/utils/ClaimCodeUtil.java @@ -0,0 +1,19 @@ +package jty.expressdistributionsystem.utils; + +import org.jetbrains.annotations.NotNull; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +public class ClaimCodeUtil { + public static @NotNull String getClaimCode(String company) { + // 获取当前时间 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String timeStamp = sdf.format(new Date()); + // 生成唯一标识符 + String uniqueId = UUID.randomUUID().toString().replace("-", "").substring(0, 6); + // 将公司名、时间戳和唯一ID组合成取件码 + return company.toUpperCase() + timeStamp + uniqueId; + } +} diff --git a/src/main/java/jty/expressdistributionsystem/utils/ExpressCodeUtil.java b/src/main/java/jty/expressdistributionsystem/utils/ExpressCodeUtil.java new file mode 100644 index 0000000..17b062e --- /dev/null +++ b/src/main/java/jty/expressdistributionsystem/utils/ExpressCodeUtil.java @@ -0,0 +1,18 @@ +package jty.expressdistributionsystem.utils; + +import org.jetbrains.annotations.NotNull; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +public class ExpressCodeUtil { + public static @NotNull String getExpressCode(String company) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String timeStamp = sdf.format(new Date()); + // 生成唯一标识符 + String uniqueId = UUID.randomUUID().toString().replace("-", "").substring(0, 8); + // 将公司名、时间戳和唯一ID组合成快递码 + return company.toUpperCase() + timeStamp + uniqueId; + } +} \ No newline at end of file diff --git a/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java b/src/main/java/jty/expressdistributionsystem/utils/SendMessageUtil.java similarity index 94% rename from src/main/java/jty/expressdistributionsystem/utils/SendMessage.java rename to src/main/java/jty/expressdistributionsystem/utils/SendMessageUtil.java index f0f3e94..ae0a40e 100644 --- a/src/main/java/jty/expressdistributionsystem/utils/SendMessage.java +++ b/src/main/java/jty/expressdistributionsystem/utils/SendMessageUtil.java @@ -4,7 +4,7 @@ import jty.expressdistributionsystem.DTO.SendMessageDTO; import jty.expressdistributionsystem.entity.Message; import org.jetbrains.annotations.NotNull; -public class SendMessage { +public class SendMessageUtil { public static Message sendMessage(@NotNull SendMessageDTO sendMessageDTO) { Long sendId = GetIdUtil.getId();