11 changed files with 563 additions and 17 deletions
@ -0,0 +1,24 @@ |
|||||
|
package cc.hiver.core.common.constant; |
||||
|
|
||||
|
/** |
||||
|
* 用户常量 |
||||
|
* |
||||
|
* @author Yazhi Li |
||||
|
*/ |
||||
|
public interface WorkerConstant { |
||||
|
|
||||
|
/** |
||||
|
* 抢单工正常抢单状态 |
||||
|
*/ |
||||
|
Integer WORKER_STATUS_NORMAL = 1; |
||||
|
/** |
||||
|
* 抢单工不可接单状态(押金不足) |
||||
|
*/ |
||||
|
Integer USER_STATUS_LOCK = 2; |
||||
|
|
||||
|
/** |
||||
|
* 抢单工禁用状态(管理员直接禁用) |
||||
|
*/ |
||||
|
Integer USER_STATUS_DISABLE = 3; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
package cc.hiver.core.dao; |
||||
|
|
||||
|
import cc.hiver.core.base.HiverBaseDao; |
||||
|
import cc.hiver.core.entity.Worker; |
||||
|
|
||||
|
public interface WorkerDao extends HiverBaseDao<Worker, String> { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,123 @@ |
|||||
|
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.EqualsAndHashCode; |
||||
|
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; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Data |
||||
|
@Entity |
||||
|
@Accessors(chain = true) |
||||
|
@DynamicInsert |
||||
|
@DynamicUpdate |
||||
|
@Table(name = "t_worker") |
||||
|
@TableName("t_worker") |
||||
|
@ApiModel(value = "抢单工管理") |
||||
|
@EntityListeners(AuditingEntityListener.class) |
||||
|
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"}) |
||||
|
public class Worker implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 抢单工编号 |
||||
|
*/ |
||||
|
@Id |
||||
|
@ApiModelProperty("抢单工编号") |
||||
|
@Column(name = "worker_id", nullable = false) |
||||
|
private String workerId = "W"+SnowFlakeUtil.nextId().toString(); |
||||
|
|
||||
|
/** |
||||
|
* 抢单工名称 |
||||
|
*/ |
||||
|
@ApiModelProperty("抢单工名称") |
||||
|
@Column(name = "worker_name") |
||||
|
private String workerName; |
||||
|
|
||||
|
/** |
||||
|
* 抢单工简介 |
||||
|
*/ |
||||
|
@ApiModelProperty("抢单工简介") |
||||
|
@Column(name = "worker_describe") |
||||
|
private String workerDescribe; |
||||
|
|
||||
|
/** |
||||
|
* 缴押金总额 |
||||
|
*/ |
||||
|
@Column(name = "depo_num") |
||||
|
@ApiModelProperty("缴押金总额") |
||||
|
private Integer depoNum; |
||||
|
|
||||
|
/** |
||||
|
* 押金余额 |
||||
|
*/ |
||||
|
@ApiModelProperty("押金余额") |
||||
|
@Column(name = "depo_bal") |
||||
|
private Integer depoBal; |
||||
|
|
||||
|
/** |
||||
|
* 接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态) |
||||
|
*/ |
||||
|
@Column(name = "worker_status") |
||||
|
@ApiModelProperty("接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态)") |
||||
|
private Integer workerStatus = 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") |
||||
|
private List<Order> order; |
||||
|
|
||||
|
} |
||||
@ -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.Order; |
||||
|
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 = "worker") |
||||
|
public interface WorkerService extends HiverBaseService<Worker, String> { |
||||
|
|
||||
|
/** |
||||
|
* 多条件分页获取抢单工 |
||||
|
* |
||||
|
* @param Worker |
||||
|
* @param searchVo |
||||
|
* @param pageable |
||||
|
* @return |
||||
|
*/ |
||||
|
Page<Worker> findByCondition(Worker worker, SearchVo searchVo, Pageable pageable); |
||||
|
|
||||
|
} |
||||
@ -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.WorkerDao; |
||||
|
import cc.hiver.core.entity.Worker; |
||||
|
import cc.hiver.core.service.WorkerService; |
||||
|
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 WorkerServiceImpl implements WorkerService { |
||||
|
@Autowired |
||||
|
private WorkerDao workerDao; |
||||
|
|
||||
|
@Autowired |
||||
|
private SecurityUtil securityUtil; |
||||
|
|
||||
|
@Override |
||||
|
public WorkerDao getRepository() { |
||||
|
return workerDao; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Page<Worker> findByCondition(Worker worker, SearchVo searchVo, Pageable pageable) { |
||||
|
return workerDao.findAll(new Specification<Worker>() { |
||||
|
@Nullable |
||||
|
@Override |
||||
|
public Predicate toPredicate(Root<Worker> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { |
||||
|
Path<String> workerIdField = root.get("workerId"); |
||||
|
Path<String> workerNameField = root.get("workerName"); |
||||
|
Path<Integer> workerStatusField = root.get("workerStatus"); |
||||
|
Path<String> mobileField = root.get("mobile"); |
||||
|
Path<Date> createTimeField = root.get("createTime"); |
||||
|
|
||||
|
List<Predicate> list = new ArrayList<>(); |
||||
|
|
||||
|
if (StrUtil.isNotBlank(worker.getWorkerId())) { |
||||
|
list.add(cb.equal(workerIdField, worker.getWorkerId())); |
||||
|
} |
||||
|
|
||||
|
// 模糊搜素
|
||||
|
if (StrUtil.isNotBlank(worker.getWorkerName())) { |
||||
|
list.add(cb.like(workerNameField, '%' + worker.getWorkerName() + '%')); |
||||
|
} |
||||
|
|
||||
|
// 状态
|
||||
|
if (worker.getWorkerStatus() != null) { |
||||
|
list.add(cb.equal(workerStatusField, worker.getWorkerStatus())); |
||||
|
} |
||||
|
|
||||
|
// 模糊搜素
|
||||
|
if (StrUtil.isNotBlank(worker.getMobile())) { |
||||
|
list.add(cb.like(mobileField, '%' + worker.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); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
package cc.hiver.core.vo; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("保存 ") |
||||
|
public class WorkerVO { |
||||
|
|
||||
|
/** |
||||
|
* 抢单工编号 |
||||
|
*/ |
||||
|
@NotNull(message = "workerId can not null") |
||||
|
@ApiModelProperty("抢单工编号") |
||||
|
private String workerId; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 抢单工名称 |
||||
|
*/ |
||||
|
@ApiModelProperty("抢单工名称") |
||||
|
private String workerName; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 抢单工简介 |
||||
|
*/ |
||||
|
@ApiModelProperty("抢单工简介") |
||||
|
private String workerDescribe; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 缴押金总额 |
||||
|
*/ |
||||
|
@ApiModelProperty("缴押金总额") |
||||
|
private Integer depoNum; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 押金余额 |
||||
|
*/ |
||||
|
@ApiModelProperty("押金余额") |
||||
|
private Integer depoBal; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态) |
||||
|
*/ |
||||
|
@ApiModelProperty("接单状态 1-可抢单 2-不可接单(押金不足状态) 3-已禁用(手工预置状态)") |
||||
|
private Integer workerStatus; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 订单工创建人 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单工创建人") |
||||
|
private String createBy; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 订单工创建时间 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单工创建时间") |
||||
|
private Date createTime; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 订单工修改人 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单工修改人") |
||||
|
private String updateBy; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 订单工修改时间 |
||||
|
*/ |
||||
|
@ApiModelProperty("订单工修改时间") |
||||
|
private Date updateTime; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 联系方式 |
||||
|
*/ |
||||
|
@ApiModelProperty("联系方式") |
||||
|
private String mobile; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,126 @@ |
|||||
|
package cc.hiver.base.controller.manage; |
||||
|
|
||||
|
import cc.hiver.core.common.constant.UserConstant; |
||||
|
import cc.hiver.core.common.constant.WorkerConstant; |
||||
|
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.Worker; |
||||
|
import cc.hiver.core.service.WorkerService; |
||||
|
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/worker") |
||||
|
@CacheConfig(cacheNames = "worker") |
||||
|
@Transactional |
||||
|
public class WorkerController { |
||||
|
public static final String WORKER = "worker::"; |
||||
|
|
||||
|
@Autowired |
||||
|
private WorkerService workerService; |
||||
|
|
||||
|
@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<Page<Worker>> getByCondition(Worker worker, |
||||
|
SearchVo searchVo, |
||||
|
PageVo pageVo) { |
||||
|
Page<Worker> page = workerService.findByCondition(worker, searchVo, PageUtil.initPage(pageVo)); |
||||
|
return new ResultUtil<Page<Worker>>().setData(page); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
@RequestMapping(value = "/delByIds", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "批量通过ids删除") |
||||
|
public Result delAllByIds(@RequestParam String[] ids) { |
||||
|
for (String id : ids) { |
||||
|
workerService.delete(id); |
||||
|
} |
||||
|
return ResultUtil.success("批量通过id删除数据成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/admin/add", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "创建抢单工") |
||||
|
public Result add(@Valid Worker u, |
||||
|
@RequestParam(required = false) String[] roleIds) { |
||||
|
|
||||
|
Worker worker = workerService.save(u); |
||||
|
|
||||
|
// 发送创建账号消息
|
||||
|
//addMessage.addSendMessage(user.getId());
|
||||
|
return ResultUtil.success("创建成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/admin/edit", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "修改抢单工信息", notes = "需要通过下单编号获取订单信息") |
||||
|
public Result edit(Worker u, |
||||
|
@RequestParam(required = false) String[] roleIds) { |
||||
|
|
||||
|
workerService.update(u); |
||||
|
|
||||
|
return ResultUtil.success("修改成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/admin/disable/{workerId}", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "后台人工禁用抢单工") |
||||
|
public Result disable(@ApiParam("用户唯一id标识") @PathVariable String workerId) { |
||||
|
Worker worker = workerService.get(workerId); |
||||
|
worker.setWorkerStatus(WorkerConstant.USER_STATUS_DISABLE); |
||||
|
workerService.update(worker); |
||||
|
// 手动更新缓存
|
||||
|
//redisTemplate.delete(WORKER + worker.getWorkerId());
|
||||
|
return ResultUtil.success("操作成功"); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/admin/enable/{workerId}", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "后台人工启用抢单工") |
||||
|
public Result enable(@ApiParam("抢单工唯一id标识") @PathVariable String workerId) { |
||||
|
Worker worker = workerService.get(workerId); |
||||
|
//这儿暂时有bug,启用的时候其实需要判定原状态是启用还是不可接单状态,需要进行逻辑判断
|
||||
|
worker.setWorkerStatus(WorkerConstant.WORKER_STATUS_NORMAL); |
||||
|
workerService.update(worker); |
||||
|
// 手动更新缓存
|
||||
|
//redisTemplate.delete(WORKER + worker.getWorkerId());
|
||||
|
return ResultUtil.success("操作成功"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue