From 031f3061e0665707fb1c5641cd79f10152efc1cc Mon Sep 17 00:00:00 2001 From: Houpn Date: Thu, 10 Aug 2023 15:34:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=9C=AC=E5=9C=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=87=B3=E6=9C=AC=E5=9C=B0repository=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E4=B8=8D=E8=BF=9B=E8=A1=8C=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/common/constant/CourierConstant.java | 24 ++++ .../java/cc/hiver/core/dao/CourierDao.java | 9 ++ .../java/cc/hiver/core/entity/Courier.java | 130 +++++++++++++++++ .../java/cc/hiver/core/entity/Worker.java | 4 +- .../cc/hiver/core/service/CourierService.java | 29 ++++ .../core/serviceimpl/CourierServiceImpl.java | 91 ++++++++++++ .../admin/ExpressCompanyController.java | 90 ++++++++++++ .../cc/hiver/app/dao/ExpressCompanyDao.java | 32 +++++ .../cc/hiver/app/entity/ExpressCompany.java | 68 +++++++++ .../cc/hiver/app/entity/LogiticsCompany.java | 1 + .../app/service/ExpressCompanyService.java | 43 ++++++ .../ExpressCompanyServiceImpl.java | 86 +++++++++++ .../controller/manage/CourierController.java | 135 ++++++++++++++++++ .../controller/manage/WorkerController.java | 13 +- 14 files changed, 752 insertions(+), 3 deletions(-) create mode 100644 hiver-core/src/main/java/cc/hiver/core/common/constant/CourierConstant.java create mode 100644 hiver-core/src/main/java/cc/hiver/core/dao/CourierDao.java create mode 100644 hiver-core/src/main/java/cc/hiver/core/entity/Courier.java create mode 100644 hiver-core/src/main/java/cc/hiver/core/service/CourierService.java create mode 100644 hiver-core/src/main/java/cc/hiver/core/serviceimpl/CourierServiceImpl.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ExpressCompanyController.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ExpressCompanyDao.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ExpressCompany.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ExpressCompanyService.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ExpressCompanyServiceImpl.java create mode 100644 hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/CourierController.java diff --git a/hiver-core/src/main/java/cc/hiver/core/common/constant/CourierConstant.java b/hiver-core/src/main/java/cc/hiver/core/common/constant/CourierConstant.java new file mode 100644 index 00000000..77f1bf6b --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/common/constant/CourierConstant.java @@ -0,0 +1,24 @@ +package cc.hiver.core.common.constant; + +/** + * 用户常量 + * + * @author Yazhi Li + */ +public interface CourierConstant { + + /** + * 抢单工正常抢单状态 + */ + Integer COURIER_STATUS_NORMAL = 1; + /** + * 抢单工不可接单状态(押金不足) + */ + Integer COURIER_STATUS_LOCK = 2; + + /** + * 抢单工禁用状态(管理员直接禁用) + */ + Integer COURIER_STATUS_DISABLE = 3; + +} diff --git a/hiver-core/src/main/java/cc/hiver/core/dao/CourierDao.java b/hiver-core/src/main/java/cc/hiver/core/dao/CourierDao.java new file mode 100644 index 00000000..c82d8a01 --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/dao/CourierDao.java @@ -0,0 +1,9 @@ +package cc.hiver.core.dao; + +import cc.hiver.core.base.HiverBaseDao; +import cc.hiver.core.entity.Courier; +import cc.hiver.core.entity.Worker; + +public interface CourierDao extends HiverBaseDao { + +} \ No newline at end of file diff --git a/hiver-core/src/main/java/cc/hiver/core/entity/Courier.java b/hiver-core/src/main/java/cc/hiver/core/entity/Courier.java new file mode 100644 index 00000000..61db9b0e --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/entity/Courier.java @@ -0,0 +1,130 @@ +package cc.hiver.core.entity; + +import cc.hiver.core.common.utils.SnowFlakeUtil; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@Data +@Entity +@Accessors(chain = true) +@DynamicInsert +@DynamicUpdate +@Table(name = "t_courier") +@TableName("t_courier") +@ApiModel(value = "快递员管理") +@EntityListeners(AuditingEntityListener.class) +@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"}) +public class Courier implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 抢单工编号 + */ + @Id + @ApiModelProperty("快递员编号") + @Column(name = "courier_id", nullable = false) + private String courierId = "K"+SnowFlakeUtil.nextId().toString(); + + /** + * 抢单工名称 + */ + @ApiModelProperty("快递员名称") + @Column(name = "courier_name") + private String courierName; + + /** + * 抢单工简介 + */ + @ApiModelProperty("快递员简介") + @Column(name = "courier_describe") + private String courierDescribe; + + /** + * 缴押金总额 + */ + @Column(name = "depo_num") + @ApiModelProperty("当次缴纳") + private Integer depoNum = 0; + + /** + * 押金余额 + */ + @ApiModelProperty("押金余额") + @Column(name = "depo_bal") + private Integer depoBal = 0; + + /** + * 接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态) + */ + @Column(name = "courier_status") + @ApiModelProperty("接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态)") + private Integer courierStatus = 1; + + + @ApiModelProperty("快递员创建人") + @CreatedBy + @TableField(fill = FieldFill.INSERT) + private String createBy; + + @CreatedDate + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("快递员创建时间") + private Date createTime; + + @ApiModelProperty("快递员修改人") + @LastModifiedBy + @TableField(fill = FieldFill.UPDATE) + private String updateBy; + + @LastModifiedDate + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "快递员修改时间") + @TableField(fill = FieldFill.UPDATE) + private Date updateTime; + + /** + * 联系方式 + */ + @Column(name = "mobile") + @ApiModelProperty("联系方式") + private String mobile; + + + /** + * 订单与抢单工映射关系 + * + * 多端中的列键值《外键》指向一端 一对多的单向关联,我们还是推荐使用一张中间表来建立关系。 + */ + /*@OneToMany(targetEntity = Order.class,mappedBy = "orderByWorker",cascade = CascadeType.ALL,fetch = FetchType.EAGER) + private List order;*/ + + /** + * 区域 + */ + @Column(name = "region") + @ApiModelProperty("办公区域") + private String region; + +} diff --git a/hiver-core/src/main/java/cc/hiver/core/entity/Worker.java b/hiver-core/src/main/java/cc/hiver/core/entity/Worker.java index 99fdc0ec..83e915d7 100644 --- a/hiver-core/src/main/java/cc/hiver/core/entity/Worker.java +++ b/hiver-core/src/main/java/cc/hiver/core/entity/Worker.java @@ -64,14 +64,14 @@ public class Worker implements Serializable { */ @Column(name = "depo_num") @ApiModelProperty("缴押金总额") - private Integer depoNum; + private Integer depoNum = 0; /** * 押金余额 */ @ApiModelProperty("押金余额") @Column(name = "depo_bal") - private Integer depoBal; + private Integer depoBal = 0; /** * 接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态) diff --git a/hiver-core/src/main/java/cc/hiver/core/service/CourierService.java b/hiver-core/src/main/java/cc/hiver/core/service/CourierService.java new file mode 100644 index 00000000..ffa5947b --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/service/CourierService.java @@ -0,0 +1,29 @@ +package cc.hiver.core.service; + +import cc.hiver.core.base.HiverBaseService; +import cc.hiver.core.common.vo.SearchVo; +import cc.hiver.core.entity.Courier; +import cc.hiver.core.entity.Worker; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +/** + * 用户接口 + * + * @author Houpn + */ +@CacheConfig(cacheNames = "courier") +public interface CourierService extends HiverBaseService { + + /** + * 多条件分页获取快递员 + * + * @param Courier + * @param searchVo + * @param pageable + * @return + */ + Page findByCondition(Courier courier, SearchVo searchVo, Pageable pageable); + +} diff --git a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/CourierServiceImpl.java b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/CourierServiceImpl.java new file mode 100644 index 00000000..a965c07c --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/CourierServiceImpl.java @@ -0,0 +1,91 @@ +package cc.hiver.core.serviceimpl; + +import cc.hiver.core.common.utils.SecurityUtil; +import cc.hiver.core.common.vo.SearchVo; +import cc.hiver.core.dao.CourierDao; +import cc.hiver.core.entity.Courier; +import cc.hiver.core.service.CourierService; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.lang.Nullable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.criteria.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 用户接口实现 + * + * @author houpn + */ +@Slf4j +@Service +@Transactional +public class CourierServiceImpl implements CourierService { + @Autowired + private CourierDao courierDao; + + @Autowired + private SecurityUtil securityUtil; + + @Override + public CourierDao getRepository() { + return courierDao; + } + + @Override + public Page findByCondition(Courier courier, SearchVo searchVo, Pageable pageable) { + return courierDao.findAll(new Specification() { + @Nullable + @Override + public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { + Path courierIdField = root.get("courierId"); + Path courierNameField = root.get("courierName"); + Path courierStatusField = root.get("courierStatus"); + Path mobileField = root.get("mobile"); + Path createTimeField = root.get("createTime"); + + List list = new ArrayList<>(); + + if (StrUtil.isNotBlank(courier.getCourierId())) { + list.add(cb.equal(courierIdField, courier.getCourierId())); + } + + // 模糊搜素 + if (StrUtil.isNotBlank(courier.getCourierName())) { + list.add(cb.like(courierNameField, '%' + courier.getCourierName() + '%')); + } + + // 状态 + if (courier.getCourierStatus() != null) { + list.add(cb.equal(courierStatusField, courier.getCourierStatus())); + } + + // 模糊搜素 + if (StrUtil.isNotBlank(courier.getMobile())) { + list.add(cb.like(mobileField, '%' + courier.getMobile() + '%')); + } + // 创建时间 + if (StrUtil.isNotBlank(searchVo.getStartDate()) && StrUtil.isNotBlank(searchVo.getEndDate())) { + Date start = DateUtil.parse(searchVo.getStartDate()); + Date end = DateUtil.parse(searchVo.getEndDate()); + list.add(cb.between(createTimeField, start, DateUtil.endOfDay(end))); + } + + // 数据权限 + + Predicate[] arr = new Predicate[list.size()]; + cq.where(list.toArray(arr)); + return null; + } + }, pageable); + } +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ExpressCompanyController.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ExpressCompanyController.java new file mode 100644 index 00000000..af76cd51 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ExpressCompanyController.java @@ -0,0 +1,90 @@ +/* +Copyright [2022] [https://hiver.cc] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ +package cc.hiver.app.controller.admin; + +import cc.hiver.app.entity.ExpressCompany; +import cc.hiver.app.entity.LogiticsCompany; +import cc.hiver.app.service.ExpressCompanyService; +import cc.hiver.app.service.LogiticsCompanyService; +import cc.hiver.core.common.utils.PageUtil; +import cc.hiver.core.common.utils.ResultUtil; +import cc.hiver.core.common.vo.PageVo; +import cc.hiver.core.common.vo.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author houpn + */ +@Slf4j +@RestController +@Api(tags = "快递公司管理接口") +@RequestMapping(value = "/hiver/app/express") +public class ExpressCompanyController { + @Autowired + private ExpressCompanyService companyService; + + @RequestMapping(value = "/getAll", method = RequestMethod.GET) + @ApiOperation(value = "获取全部数据") + public Result> getAll() { + List list = companyService.getAll(); + return new ResultUtil>().setData(list); + } + + @RequestMapping(value = "/add", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "添加") + public Result add(ExpressCompany company) { + if (companyService.findByCompanyName(company.getCompanyName()) != null) { + return ResultUtil.error("公司名称已经存在"); + } + companyService.save(company); + return ResultUtil.success("添加成功"); + } + + @RequestMapping(value = "/edit", method = RequestMethod.PUT) + @ResponseBody + @ApiOperation(value = "编辑") + public Result edit(ExpressCompany company) { + companyService.update(company); + return ResultUtil.success("编辑成功"); + } + + @RequestMapping(value = "/delByIds", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "通过id删除") + public Result delAllByIds(@RequestParam String[] ids) { + for (String id : ids) { + ExpressCompany company = companyService.get(id); + companyService.delete(id); + } + return ResultUtil.success("删除成功"); + } + + @RequestMapping(value = "/getByCondition", method = RequestMethod.GET) + @ApiOperation(value = "多条件分页获取公司列表") + public Result> getByCondition(ExpressCompany company, + PageVo pageVo) { + Page page = companyService.findByCondition(company, PageUtil.initPage(pageVo)); + return new ResultUtil>().setData(page); + } +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ExpressCompanyDao.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ExpressCompanyDao.java new file mode 100644 index 00000000..6949a554 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ExpressCompanyDao.java @@ -0,0 +1,32 @@ +/* +Copyright [2022] [https://hiver.cc] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ +package cc.hiver.app.dao; + +import cc.hiver.app.entity.ExpressCompany; +import cc.hiver.core.base.HiverBaseDao; + +/** + * @author houpn + */ +public interface ExpressCompanyDao extends HiverBaseDao { + /** + * 通过公司名称获得记录 + * + * @param companyName + * @return + */ + ExpressCompany findByCompanyName(String companyName); +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ExpressCompany.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ExpressCompany.java new file mode 100644 index 00000000..894ab6a6 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ExpressCompany.java @@ -0,0 +1,68 @@ +/* +Copyright [2022] [https://hiver.cc] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ +package cc.hiver.app.entity; + +import cc.hiver.core.base.HiverBaseEntity; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * 公司实体类 + * + * @author Yazhi Li + */ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@Table(name = "t_ecompany") +@TableName("t_ecompany") +@ApiModel(value = "公司信息") +public class ExpressCompany extends HiverBaseEntity { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "公司名称") + private String companyName; + + @ApiModelProperty(value = "公司电话") + private String companyTel; + + @ApiModelProperty(value = "公司邮箱") + private String companyEmail; + + @ApiModelProperty(value = "所在地区") + private String companyAddress; + + @ApiModelProperty(value = "详细地址") + private String companyStreet; + + @ApiModelProperty(value = "联系人") + private String contacts; + + @ApiModelProperty(value = "联系人手机号") + private String mobile; + + @ApiModelProperty(value = "办公区域") + private String region; + +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/LogiticsCompany.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/LogiticsCompany.java index 6e43e888..311d0145 100644 --- a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/LogiticsCompany.java +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/LogiticsCompany.java @@ -64,4 +64,5 @@ public class LogiticsCompany extends HiverBaseEntity { @ApiModelProperty(value = "办公区域") private String region; + } diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ExpressCompanyService.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ExpressCompanyService.java new file mode 100644 index 00000000..50ce90bf --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ExpressCompanyService.java @@ -0,0 +1,43 @@ +/* +Copyright [2022] [https://hiver.cc] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ +package cc.hiver.app.service; + +import cc.hiver.app.entity.ExpressCompany; +import cc.hiver.core.base.HiverBaseService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +/** + * @author Yazhi Li + */ +public interface ExpressCompanyService extends HiverBaseService { + /** + * 多条件获取 + * + * @param company + * @param pageable + * @return + */ + Page findByCondition(ExpressCompany company, Pageable pageable); + + /** + * 通过公司名称获得记录 + * + * @param companyName + * @return + */ + ExpressCompany findByCompanyName(String companyName); +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ExpressCompanyServiceImpl.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ExpressCompanyServiceImpl.java new file mode 100644 index 00000000..d5656f19 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ExpressCompanyServiceImpl.java @@ -0,0 +1,86 @@ +/* +Copyright [2022] [https://hiver.cc] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ +package cc.hiver.app.serviceimpl; + +import cc.hiver.app.dao.ExpressCompanyDao; +import cc.hiver.app.entity.ExpressCompany; +import cc.hiver.app.service.ExpressCompanyService; +import cc.hiver.core.base.HiverBaseDao; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.lang.Nullable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.criteria.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author houpn + */ +@Slf4j +@Service +@Transactional +public class ExpressCompanyServiceImpl implements ExpressCompanyService { + @Autowired + private ExpressCompanyDao companyDao; + + @Override + public HiverBaseDao getRepository() { + return companyDao; + } + + @Override + public Page findByCondition(ExpressCompany company, Pageable pageable) { + return companyDao.findAll(new Specification() { + @Nullable + @Override + public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { + Path companyNameField = root.get("companyName"); + Path contactsField = root.get("contacts"); + Path mobileField = root.get("mobile"); + + List list = new ArrayList<>(); + + if (StrUtil.isNotBlank(company.getCompanyName())) { + list.add(cb.like(companyNameField, '%' + company.getCompanyName() + '%')); + } + + if (StrUtil.isNotBlank(company.getContacts())) { + list.add(cb.like(contactsField, '%' + company.getContacts() + '%')); + } + + if (StrUtil.isNotBlank(company.getMobile())) { + list.add(cb.like(mobileField, '%' + company.getMobile() + '%')); + } + + Predicate[] arr = new Predicate[list.size()]; + cq.where(list.toArray(arr)); + return null; + } + }, pageable); + } + + @Override + public ExpressCompany findByCompanyName(String companyName) { + return companyDao.findByCompanyName(companyName); + } +} diff --git a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/CourierController.java b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/CourierController.java new file mode 100644 index 00000000..7f0febe9 --- /dev/null +++ b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/CourierController.java @@ -0,0 +1,135 @@ +package cc.hiver.base.controller.manage; + +import cc.hiver.core.common.constant.CourierConstant; +import cc.hiver.core.common.redis.RedisTemplateHelper; +import cc.hiver.core.common.utils.PageUtil; +import cc.hiver.core.common.utils.ResultUtil; +import cc.hiver.core.common.utils.SecurityUtil; +import cc.hiver.core.common.vo.PageVo; +import cc.hiver.core.common.vo.Result; +import cc.hiver.core.common.vo.SearchVo; +import cc.hiver.core.dao.mapper.DeleteMapper; +import cc.hiver.core.entity.Courier; +import cc.hiver.core.service.CourierService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.data.domain.Page; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.validation.Valid; + +/** + * 订单工管理接口 + * + * @author houpn + */ +@Slf4j +@RestController +@Api(tags = "订单工接口") +@RequestMapping("/hiver/courier") +@CacheConfig(cacheNames = "courier") +@Transactional +public class CourierController { + public static final String courier = "courier::"; + + @Autowired + private CourierService courierService; + + @Autowired + private DeleteMapper deleteMapper; + + @Autowired + private RedisTemplateHelper redisTemplate; + + @Autowired + private SecurityUtil securityUtil; + + @PersistenceContext + private EntityManager entityManager; + + + + + @RequestMapping(value = "/getByCondition", method = RequestMethod.GET) + @ApiOperation(value = "多条件分页获取订单列表") + public Result> getByCondition(Courier courier, + SearchVo searchVo, + PageVo pageVo) { + Page page = courierService.findByCondition(courier, searchVo, PageUtil.initPage(pageVo)); + return new ResultUtil>().setData(page); + } + + + + @RequestMapping(value = "/delByIds", method = RequestMethod.POST) + @ApiOperation(value = "批量通过ids删除") + public Result delAllByIds(@RequestParam String[] ids) { + for (String id : ids) { + courierService.delete(id); + } + return ResultUtil.success("批量通过id删除数据成功"); + } + + @RequestMapping(value = "/admin/add", method = RequestMethod.POST) + @ApiOperation(value = "创建快递员") + public Result add(@Valid Courier u, + @RequestParam(required = false) String[] roleIds) { + + //更新余额,重置当次应缴 + u.setDepoBal(u.getDepoBal() + u.getDepoNum()); + u.setDepoNum(0); + + courierService.save(u); + + // 发送创建账号消息 + //addMessage.addSendMessage(user.getId()); + return ResultUtil.success("创建成功"); + } + + @RequestMapping(value = "/admin/edit", method = RequestMethod.POST) + @ApiOperation(value = "修改快递员信息", notes = "需要通过下单编号获取订单信息") + public Result edit(Courier u, + @RequestParam(required = false) String[] roleIds) { + //修改快递员信息时如涉及到充值押金情况,需要更新余额且重置应缴 + if(u.getDepoNum()>0){ + Courier courier = courierService.findById(u.getCourierId()); + u.setDepoBal(courier.getDepoBal() + u.getDepoNum()); + u.setDepoNum(0); + } + + courierService.update(u); + + return ResultUtil.success("修改成功"); + } + + @RequestMapping(value = "/admin/disable/{courierId}", method = RequestMethod.POST) + @ApiOperation(value = "后台人工禁用快递员") + public Result disable(@ApiParam("用户唯一id标识") @PathVariable String courierId) { + Courier courier = courierService.get(courierId); + courier.setCourierStatus(CourierConstant.COURIER_STATUS_DISABLE); + courierService.update(courier); + // 手动更新缓存 + //redisTemplate.delete(courier + courier.getcourierId()); + return ResultUtil.success("操作成功"); + } + + @RequestMapping(value = "/admin/enable/{courierId}", method = RequestMethod.POST) + @ApiOperation(value = "后台人工启用快递员") + public Result enable(@ApiParam("快递员唯一id标识") @PathVariable String courierId) { + Courier courier = courierService.get(courierId); + //这儿暂时有bug,启用的时候其实需要判定原状态是启用还是不可接单状态,需要进行逻辑判断 + courier.setCourierStatus(CourierConstant.COURIER_STATUS_NORMAL); + courierService.update(courier); + // 手动更新缓存 + //redisTemplate.delete(courier + courier.getcourierId()); + return ResultUtil.success("操作成功"); + } + +} diff --git a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/WorkerController.java b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/WorkerController.java index 606e0c10..9757101d 100644 --- a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/WorkerController.java +++ b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/WorkerController.java @@ -10,6 +10,7 @@ import cc.hiver.core.common.vo.PageVo; import cc.hiver.core.common.vo.Result; import cc.hiver.core.common.vo.SearchVo; import cc.hiver.core.dao.mapper.DeleteMapper; +import cc.hiver.core.entity.Courier; import cc.hiver.core.entity.Worker; import cc.hiver.core.service.WorkerService; import io.swagger.annotations.Api; @@ -83,7 +84,11 @@ public class WorkerController { public Result add(@Valid Worker u, @RequestParam(required = false) String[] roleIds) { - Worker worker = workerService.save(u); + //更新余额,重置当次应缴 + u.setDepoBal(u.getDepoBal() + u.getDepoNum()); + u.setDepoNum(0); + + workerService.save(u); // 发送创建账号消息 //addMessage.addSendMessage(user.getId()); @@ -95,6 +100,12 @@ public class WorkerController { public Result edit(Worker u, @RequestParam(required = false) String[] roleIds) { + //修改抢单工信息时如涉及到充值押金情况,需要更新余额且重置应缴 + if(u.getDepoNum()>0){ + Worker worker = workerService.findById(u.getWorkerId()); + u.setDepoBal(worker.getDepoBal() + u.getDepoNum()); + u.setDepoNum(0); + } workerService.update(u); return ResultUtil.success("修改成功");