From 302254bcbb35300edece00434d2bf9a34e28e4c0 Mon Sep 17 00:00:00 2001 From: cxy <1276771477@qq.com> Date: Thu, 21 Nov 2024 22:15:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BA=BB=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/dataSources.xml | 12 + .../src/main/java/com/backend/anno/State.java | 21 ++ .../backend/controller/ExpressController.java | 99 +++----- .../com/backend/mapper/ExpressMapper.java | 29 +-- .../main/java/com/backend/pojo/Express.java | 30 ++- .../main/java/com/backend/pojo/PageBean.java | 16 ++ .../main/java/com/backend/pojo/Result.java | 1 + .../src/main/java/com/backend/pojo/User.java | 2 - .../com/backend/service/ExpressService.java | 20 +- .../service/impl/ExpressServiceImpl.java | 41 ++-- .../backend/validaion/StateValidation.java | 16 ++ .../src/main/resources/application-dev.yml | 3 +- .../com.backend.mapper/ExpressMapper.xml | 13 ++ .../main/resources/mapper/ExpressMapper.xml | 13 ++ frontend/src/View/Home.vue | 22 +- frontend/src/View/Layout.vue | 171 +++++++++++++- frontend/src/View/Login.vue | 9 +- .../View/{user => express}/ExpressForm.vue | 0 frontend/src/View/express/ExpressList.vue | 218 ++++++++++++++++++ frontend/src/View/user/ExpressList.vue | 153 ------------ frontend/src/View/user/MyInfo.vue | 68 ++++-- frontend/src/View/user/UserInfo.vue | 7 - frontend/src/api/express.js | 19 ++ frontend/src/api/user.js | 1 + frontend/src/router.js | 6 +- frontend/src/stores/index.js | 28 +-- 26 files changed, 699 insertions(+), 319 deletions(-) create mode 100644 backend/src/main/java/com/backend/anno/State.java create mode 100644 backend/src/main/java/com/backend/pojo/PageBean.java create mode 100644 backend/src/main/java/com/backend/validaion/StateValidation.java create mode 100644 backend/src/main/resources/com.backend.mapper/ExpressMapper.xml create mode 100644 backend/src/main/resources/mapper/ExpressMapper.xml rename frontend/src/View/{user => express}/ExpressForm.vue (100%) create mode 100644 frontend/src/View/express/ExpressList.vue delete mode 100644 frontend/src/View/user/ExpressList.vue create mode 100644 frontend/src/api/express.js diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 24738f4..8eb01ec 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -13,5 +13,17 @@ $ProjectFileDir$ + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + + + + + + $ProjectFileDir$ + \ No newline at end of file diff --git a/backend/src/main/java/com/backend/anno/State.java b/backend/src/main/java/com/backend/anno/State.java new file mode 100644 index 0000000..6b817fc --- /dev/null +++ b/backend/src/main/java/com/backend/anno/State.java @@ -0,0 +1,21 @@ +package com.backend.anno; + +import com.backend.validaion.StateValidation; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = {StateValidation.class}) +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface State { + + String message() default "state参数的值只能是已签收、未签收"; + + Class[] groups() default {}; + + Class[] payload() default {}; + +} diff --git a/backend/src/main/java/com/backend/controller/ExpressController.java b/backend/src/main/java/com/backend/controller/ExpressController.java index 6c54daa..714b3bb 100644 --- a/backend/src/main/java/com/backend/controller/ExpressController.java +++ b/backend/src/main/java/com/backend/controller/ExpressController.java @@ -2,16 +2,18 @@ package com.backend.controller; import com.backend.pojo.Express; +import com.backend.pojo.PageBean; import com.backend.pojo.Result; import com.backend.service.ExpressService; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; +import org.apache.ibatis.annotations.Delete; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; import java.util.Date; @RestController @@ -25,79 +27,40 @@ public class ExpressController { @Autowired private StringRedisTemplate stringRedisTemplate; - @PostMapping("/addexpress") - public Result addexpress( - @Pattern(regexp = "^[A-Za-z0-9]{10,20}$") final String expressid, // 快递ID,长度10-20字符,字母或数字 - @Pattern(regexp = "^\\S{2,30}$") final String sename, // 发件人姓名,长度2-30字符,不能有空白 - @Pattern(regexp = "^[0-9]{11}$") final String sephone, // 发件人电话,11位数字 - @Pattern(regexp = "^\\S{5,100}$") final String seaddress, // 发件人地址,长度5-100字符 - @Pattern(regexp = "^\\S{2,30}$") final String rename, // 收件人姓名,长度2-30字符,不能有空白 - @Pattern(regexp = "^[0-9]{11}$") final String rephone, // 收件人电话,11位数字 - @Pattern(regexp = "^\\S{5,100}$") final String readdress, // 收件人地址,长度5-100字符 - @Pattern(regexp = "^[0-1]$") final Integer issign, // 是否签收,0或1 - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") final Date signtime // 签收时间,格式yyyy-MM-dd HH:mm:ss - ) { - final Express existexpress = expressService.findExpressById(expressid); - if (existexpress== null) { - expressService.insert(expressid, sename, sephone, seaddress, rename, rephone, readdress, issign, signtime); - return Result.success(); - } else { - return Result.error("该快递单号已存在"); - } + @PostMapping + public Result add( + @RequestBody @Validated(Express.Add.class) Express express){ + expressService.add(express); + return Result.success(); } - @PostMapping("/updateexpress") - public Result updateExpress( - @Pattern(regexp = "^[A-Za-z0-9]{10,20}$") final String expressid, // 快递ID,长度10-20字符,字母或数字 - @Pattern(regexp = "^\\S{2,30}$") final String sename, // 发件人姓名,长度2-30字符,不能有空白 - @Pattern(regexp = "^[0-9]{11}$") final String sephone, // 发件人电话,11位数字 - @Pattern(regexp = "^\\S{5,100}$") final String seaddress, // 发件人地址,长度5-100字符 - @Pattern(regexp = "^\\S{2,30}$") final String rename, // 收件人姓名,长度2-30字符,不能有空白 - @Pattern(regexp = "^[0-9]{11}$") final String rephone, // 收件人电话,10位数字 - @Pattern(regexp = "^\\S{5,100}$") final String readdress, // 收件人地址,长度5-100字符 - @Pattern(regexp = "^[0-1]$") final Integer issign, // 是否签收,0或1 - @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") final Date signtime // 签收时间,格式yyyy-MM-dd HH:mm:ss + @GetMapping + public Result> list(final String expressid, + final String sename, + final String sephone, + final String seaddress, + final String rename, + final String rephone, + final String readdress, + final String issign, + final LocalDateTime signtime ) { - Express express = new Express(); - express.setExpressid(expressid); - express.setSename(sename); - express.setSephone(sephone); - express.setSeaddress(seaddress); - express.setRename(rename); - express.setRephone(rephone); - express.setReaddress(readdress); - express.setIssigned(issign); - express.setSigntime(signtime); + final PageBean expresslist = expressService.list(expressid, sename, sephone, seaddress, + rename, rephone, readdress, issign, signtime); + return Result.success(expresslist); + } + @PutMapping + public Result update( + @RequestBody @Validated(Express.Update.class) Express express) { expressService.update(express); - - return Result.success(express); + return Result.success(); } - @PostMapping("/deleteexpress") - public Result deleteExpress( - @Pattern(regexp = "^[A-Za-z0-9]{10,20}$") final String expressid - ) { - final Express express = expressService.findExpressById(expressid); - if(express!= null){ - expressService.delete(express); + @DeleteMapping + public Result delete(@NotNull final Integer id) { + expressService.delete(id); return Result.success(); - } else { - return Result.error("快递单号为空或者不存在"); - } } - @PostMapping("/getexpress") - public Result getExpress( - @Pattern(regexp = "^[A-Za-z0-9]{10,20}$") final String expressid - ) { - final Express express = expressService.findExpressById(expressid); - if(express != null){ - return Result.success(express); - } else { - return Result.error("快递单号为空或者不存在"); - } - } - - } diff --git a/backend/src/main/java/com/backend/mapper/ExpressMapper.java b/backend/src/main/java/com/backend/mapper/ExpressMapper.java index e37ad66..43a82d7 100644 --- a/backend/src/main/java/com/backend/mapper/ExpressMapper.java +++ b/backend/src/main/java/com/backend/mapper/ExpressMapper.java @@ -2,27 +2,28 @@ package com.backend.mapper; import com.backend.pojo.Express; import org.apache.ibatis.annotations.*; - -import java.util.Date; +import java.time.LocalDateTime; +import java.util.List; @Mapper public interface ExpressMapper { - @Select("SELECT * FROM express_info WHERE expressid = #{expressid}") - Express findExpressById(String expressid); - - @Insert("INSERT INTO express_info(expressid, sename, sephone, seaddress, rename, rephone, readdress, issign, signtime) " + - "VALUES(#{expressid}, #{sename}, #{sephone}, #{seaddress}, #{rename}, #{rephone}, #{readdress}, #{issign} , #{signtime})") - void add(final String expressid, final String sename, final String sephone, - final String seaddress, final String rename, final String rephone, - final String readdress, final Integer isSign, final Date signtime); + @Insert("INSERT INTO express_info(expressid, sename, sephone, seaddress, rename, rephone, readdress, issigned, signtime) " + + "VALUES(#{expressid}, #{sename}, #{sephone}, #{seaddress}, #{rename}, #{rephone}, #{readdress}, #{issigned} , #{signtime})") + void add(final Express express); @Update("UPDATE express_info SET expressid = #{expressid}, sename = #{sename}," + - " seaddress = #{seaddress}, rename = #{rename}, readdress = #{readdress}, isSign = #{isSign} WHERE expressid = #{expressid}") - void update(Express express); + " seaddress = #{seaddress}, rename = #{rename}, readdress = #{readdress}, isSigned = #{isSigned} WHERE id = #{id}") + void update(final Express express); + + @Delete("DELETE FROM express_info WHERE id = #{id}") + void delete(final Integer id); - @Delete("DELETE FROM express_info WHERE expressid = #{expressid}") - void delete(Express express); + List list( final Integer id, final String sename, + final String sephone, final String seaddress, + final String rename, final String rephone, + final String readdress, final String issigned, + final LocalDateTime signtime); } diff --git a/backend/src/main/java/com/backend/pojo/Express.java b/backend/src/main/java/com/backend/pojo/Express.java index 17162cf..68192d3 100644 --- a/backend/src/main/java/com/backend/pojo/Express.java +++ b/backend/src/main/java/com/backend/pojo/Express.java @@ -1,21 +1,41 @@ package com.backend.pojo; -import com.fasterxml.jackson.annotation.JsonFormat; +import com.backend.anno.State; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.groups.Default; import lombok.Data; -import java.util.Date; +import java.time.LocalDateTime; @Data public class Express { + @NotNull + private Integer id; + @NotNull private String expressid; + @NotEmpty private String sename; + @NotEmpty private String sephone; + @NotEmpty private String seaddress; + @NotEmpty private String rename; + @NotEmpty private String rephone; + @NotEmpty private String readdress; - private Integer issigned; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy年MM月dd日") - private Date signtime; + @State + private String issigned; + @NotNull + private LocalDateTime signtime; + public interface Add extends Default { + + } + + public interface Update extends Default{ + + } } diff --git a/backend/src/main/java/com/backend/pojo/PageBean.java b/backend/src/main/java/com/backend/pojo/PageBean.java new file mode 100644 index 0000000..fff1748 --- /dev/null +++ b/backend/src/main/java/com/backend/pojo/PageBean.java @@ -0,0 +1,16 @@ +package com.backend.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +//分页返回结果对象 +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PageBean { + private Long total;//总条数 + private List items;//当前页数据集合 +} diff --git a/backend/src/main/java/com/backend/pojo/Result.java b/backend/src/main/java/com/backend/pojo/Result.java index e242b7e..b3655db 100644 --- a/backend/src/main/java/com/backend/pojo/Result.java +++ b/backend/src/main/java/com/backend/pojo/Result.java @@ -25,4 +25,5 @@ public class Result { public static Result error(String message) { return new Result<>(1, message, null); } + } diff --git a/backend/src/main/java/com/backend/pojo/User.java b/backend/src/main/java/com/backend/pojo/User.java index 8ddc6ac..d2cefb4 100644 --- a/backend/src/main/java/com/backend/pojo/User.java +++ b/backend/src/main/java/com/backend/pojo/User.java @@ -1,8 +1,6 @@ package com.backend.pojo; - import com.fasterxml.jackson.annotation.JsonIgnore; -import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; diff --git a/backend/src/main/java/com/backend/service/ExpressService.java b/backend/src/main/java/com/backend/service/ExpressService.java index 72da867..f0e0407 100644 --- a/backend/src/main/java/com/backend/service/ExpressService.java +++ b/backend/src/main/java/com/backend/service/ExpressService.java @@ -1,18 +1,26 @@ package com.backend.service; import com.backend.pojo.Express; +import com.backend.pojo.PageBean; +import java.time.LocalDateTime; import java.util.Date; public interface ExpressService { - Express findExpressById(final String expressId); - void insert(final String expressId, - final String sename, final String sephone, final String seaddress, - final String rename, final String rephone, final String readdress, - final Integer issign, final Date signtime); + void add(final Express express); void update(final Express express); - void delete(final Express express); + void delete(Integer id); + + PageBean list(final String expressid, + final String sename, + final String sephone, + final String seaddress, + final String rename, + final String rephone, + final String readdress, + final String issign, + final LocalDateTime signtime); } diff --git a/backend/src/main/java/com/backend/service/impl/ExpressServiceImpl.java b/backend/src/main/java/com/backend/service/impl/ExpressServiceImpl.java index df30ef0..f34eb6e 100644 --- a/backend/src/main/java/com/backend/service/impl/ExpressServiceImpl.java +++ b/backend/src/main/java/com/backend/service/impl/ExpressServiceImpl.java @@ -1,13 +1,16 @@ package com.backend.service.impl; - import com.backend.mapper.ExpressMapper; import com.backend.pojo.Express; +import com.backend.pojo.PageBean; import com.backend.service.ExpressService; +import com.backend.utils.ThreadLocalUtil; +import com.github.pagehelper.Page; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Date; +import java.time.LocalDateTime; +import java.util.Map; @Service public class ExpressServiceImpl implements ExpressService { @@ -15,29 +18,39 @@ public class ExpressServiceImpl implements ExpressService { @Autowired private ExpressMapper expressMapper; - @Override - public Express findExpressById(String expressid) { - return expressMapper.findExpressById(expressid); - } @Override - public void insert(final String expressId, - final String sename, final String sephone, final String seaddress, - final String rename, final String rephone, final String readdress, - final Integer issign, final Date signtime) { - expressMapper.add(expressId, sename, sephone, seaddress, rename, rephone, readdress, issign, signtime); + public void add(Express express) { + final Map map = ThreadLocalUtil.get(); + final Integer id = (Integer) map.get("id"); + express.setId(id); + expressMapper.add(express); } @Override - public void update(Express express) { + public void update(final Express express) { expressMapper.update(express); } @Override - public void delete(final Express express) { - expressMapper.delete(express); + public void delete(final Integer id) { + expressMapper.delete(id); } + @Override + public PageBean list(String expressid, String sename, String sephone, String seaddress, String rename, String rephone, String readdress, String issigned, LocalDateTime signtime) { + final PageBean pageBean = new PageBean<>(); + final Map map = ThreadLocalUtil.get(); + final Integer id = (Integer) map.get("id"); + final Page expressList = (Page) expressMapper.list(id, sename, + sephone, seaddress, + rename, rephone, + readdress, issigned, + signtime); + pageBean.setTotal(expressList.getTotal()); + pageBean.setItems(expressList.getResult()); + return pageBean; + } diff --git a/backend/src/main/java/com/backend/validaion/StateValidation.java b/backend/src/main/java/com/backend/validaion/StateValidation.java new file mode 100644 index 0000000..970499d --- /dev/null +++ b/backend/src/main/java/com/backend/validaion/StateValidation.java @@ -0,0 +1,16 @@ +package com.backend.validaion; + +import com.backend.anno.State; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class StateValidation implements ConstraintValidator { + + @Override + public boolean isValid(final String value, final ConstraintValidatorContext constraintValidatorContext) { + if (value == null) { + return false; + } + return value.equals("已签收") || value.equals("未签收"); + } +} diff --git a/backend/src/main/resources/application-dev.yml b/backend/src/main/resources/application-dev.yml index bb0cf30..0b1fde6 100644 --- a/backend/src/main/resources/application-dev.yml +++ b/backend/src/main/resources/application-dev.yml @@ -13,4 +13,5 @@ mybatis: map-underscore-to-camel-case: true #mybatis: # mapper-locations: classpath:./mapper/*.xml -# type-aliases-package: com.backend.pojo \ No newline at end of file +# type-aliases-package: com.backend.pojo + diff --git a/backend/src/main/resources/com.backend.mapper/ExpressMapper.xml b/backend/src/main/resources/com.backend.mapper/ExpressMapper.xml new file mode 100644 index 0000000..16885fa --- /dev/null +++ b/backend/src/main/resources/com.backend.mapper/ExpressMapper.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/backend/src/main/resources/mapper/ExpressMapper.xml b/backend/src/main/resources/mapper/ExpressMapper.xml new file mode 100644 index 0000000..16885fa --- /dev/null +++ b/backend/src/main/resources/mapper/ExpressMapper.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/frontend/src/View/Home.vue b/frontend/src/View/Home.vue index ecd54a8..718ff20 100644 --- a/frontend/src/View/Home.vue +++ b/frontend/src/View/Home.vue @@ -31,10 +31,10 @@

卓越城市服务

「批发市场」寄递方案

满足多重寄递需求灵活高效价更优

-
- - -
+ + + +
@@ -98,15 +98,25 @@ + \ No newline at end of file + .el-footer { + display: flex; + align-items: center; + justify-content: center; + font-size: 14px; + color: #ccccd6; + } +} + diff --git a/frontend/src/View/Login.vue b/frontend/src/View/Login.vue index 90a53f8..eb21b9f 100644 --- a/frontend/src/View/Login.vue +++ b/frontend/src/View/Login.vue @@ -125,7 +125,7 @@ const login = async () => { ElMessage.success(result.message ? result.message : '登录成功') tokenStore.setToken(result.data) - router.push('index') + router.push('Layout') } } @@ -136,21 +136,16 @@ const clearRegisterData = () => { rePassword: '' } } - - - - diff --git a/frontend/src/View/user/ExpressList.vue b/frontend/src/View/user/ExpressList.vue deleted file mode 100644 index dcf612f..0000000 --- a/frontend/src/View/user/ExpressList.vue +++ /dev/null @@ -1,153 +0,0 @@ - - - - - \ No newline at end of file diff --git a/frontend/src/View/user/MyInfo.vue b/frontend/src/View/user/MyInfo.vue index b6ad80a..424506e 100644 --- a/frontend/src/View/user/MyInfo.vue +++ b/frontend/src/View/user/MyInfo.vue @@ -1,4 +1,3 @@ -