This commit is contained in:
shuhongfan
2023-09-04 16:40:17 +08:00
commit cf5ac25c14
8267 changed files with 1305066 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
package com.sl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
@EnableRetry
@EnableAsync
@EnableFeignClients
@SpringBootApplication
public class BaseApplication {
public static void main(String[] args) {
SpringApplication.run(BaseApplication.class, args);
}
}

View File

@@ -0,0 +1,58 @@
package com.sl.ms.base.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* xxl-job config
*/
@Configuration
public class XxlJobConfig {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.accessToken:}")
private String accessToken;
@Value("${xxl.job.executor.appname}")
private String appname;
@Value("${xxl.job.executor.address:}")
private String address;
@Value("${xxl.job.executor.ip:}")
private String ip;
@Value("${xxl.job.executor.port:0}")
private int port;
@Value("${xxl.job.executor.logpath:}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays:}")
private int logRetentionDays;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}

View File

@@ -0,0 +1,11 @@
package com.sl.ms.base.constant;
public class WorkConstants {
public static final String WORK_DATE_CONTINUITYS= "连续上班%s天 休息%s天";
public static final String WORK_DATE_WEEKS = "周一 (%s) 周二 (%s) 周三 (%s) 周四 (%s) 周五 (%s) 周六 (%s) 周日 (%s)";
public class WorkStatus{
public static final byte USING = 1;
public static final byte STOP = 2;
}
}

View File

@@ -0,0 +1,69 @@
package com.sl.ms.base.controller.base;
import cn.hutool.core.bean.BeanUtil;
import com.sl.ms.base.domain.base.AreaDto;
import com.sl.ms.base.service.base.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* <p>
* 前端控制器
* 系统日志
* </p>
*/
@Slf4j
@Validated
@RestController
@RequestMapping("/area")
@Api(value = "Area", tags = "行政区域")
public class AreaController {
@Autowired
private AreaService areaService;
/**
* 根据id获取行政区域详情
*
* @param id 行政区域id
* @return 行政区域id
*/
@GetMapping("/{id}")
public AreaDto get(@PathVariable Long id) {
AreaDto areaDto = BeanUtil.toBean(areaService.getById(id), AreaDto.class);
areaDto.setName(areaDto.getShortName());
return areaDto;
}
@GetMapping("/code/{code}")
public AreaDto getByCode(@PathVariable String code) {
AreaDto areaDto = BeanUtil.toBean((areaService.getByCode(code)), AreaDto.class);
areaDto.setName(areaDto.getShortName());
return areaDto;
}
@GetMapping("/children")
@ApiOperation(value = "根据父级id查询子级行政区域")
@ApiImplicitParams({
@ApiImplicitParam(name = "parentId", value = "父级id", required = true, dataTypeClass = Long.class)})
public List<AreaDto> findChildren(@NotNull(message = "父id不能为空!") @RequestParam("parentId") Long parentId) {
return areaService.findChildren(parentId);
}
@GetMapping("/batch")
@ApiOperation(value = "根据id批量查询")
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "id列表", required = true, dataTypeClass = Long.class)})
public List<AreaDto> findBatch(@NotNull(message = "列表不能为空!") @RequestParam("ids") List<Long> ids) {
return areaService.findBatch(ids);
}
}

View File

@@ -0,0 +1,32 @@
package com.sl.ms.base.controller.base;
import com.itheima.auth.sdk.dto.UserDTO;
import com.sl.ms.base.service.base.AuthService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 权限系统对接接口
*/
@Slf4j
@Validated
@RestController
@RequestMapping("auth")
@Api(tags = "权限系统对接接口")
public class AuthController {
@Autowired
private AuthService authService;
@GetMapping("/{id}")
@ApiOperation(value = "根据用户id获得详细信息")
public UserDTO getByUserId(@PathVariable("id") Long id) {
return authService.getByUserId(id);
}
}

View File

@@ -0,0 +1,161 @@
package com.sl.ms.base.controller.base;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sl.ms.base.domain.base.GoodsTypeDto;
import com.sl.ms.base.entity.base.GoodsTypeEntity;
import com.sl.ms.base.entity.truck.TruckTypeGoodsTypeEntity;
import com.sl.ms.base.service.base.GoodsTypeService;
import com.sl.ms.base.service.truck.TruckTypeGoodsTypeService;
import com.sl.ms.base.domain.constants.TruckConstant;
import com.sl.transport.common.util.ObjectUtil;
import com.sl.transport.common.util.PageResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 货物类型 业务
*/
@RestController
@RequestMapping("base/goodsType")
@Slf4j
public class GoodsTypeController {
@Resource
private GoodsTypeService goodsTypeService;
@Resource
private TruckTypeGoodsTypeService truckTypeGoodsTypeService;
/**
* 添加货物类型
*
* @param dto 货物类型信息
* @return 货物类型信息
*/
@PostMapping
public GoodsTypeDto saveGoodsType(@RequestBody GoodsTypeDto dto) {
GoodsTypeEntity goodsTypeEntity = BeanUtil.toBean(dto, GoodsTypeEntity.class);
goodsTypeService.save(goodsTypeEntity);
Long goodsTypeId = goodsTypeEntity.getId();
if (ObjectUtil.isNotEmpty(dto.getTruckTypeIds())) {
truckTypeGoodsTypeService.saveBatch(dto.getTruckTypeIds().stream().map(truckTypeId ->
TruckTypeGoodsTypeEntity.builder().truckTypeId(truckTypeId)
.goodsTypeId(goodsTypeId).build()
).collect(Collectors.toList()));
}
BeanUtil.copyProperties(goodsTypeEntity, dto);
return dto;
}
/**
* 根据id获取货物类型详情
*
* @param id 货物类型id
* @return 货物类型信息
*/
@GetMapping("/{id}")
public GoodsTypeDto fineById(@PathVariable(name = "id") Long id) {
log.info("base --- 获取货物类型详情");
GoodsTypeEntity pdGoodsType = goodsTypeService.getById(id);
log.info("base --- goodsTypeService.getById result:{}", pdGoodsType);
GoodsTypeDto dto = null;
if (ObjectUtil.isNotEmpty(pdGoodsType)) {
dto = BeanUtil.toBean(pdGoodsType, GoodsTypeDto.class);
List<Long> list = truckTypeGoodsTypeService.findAll(null, dto.getId())
.stream().map(TruckTypeGoodsTypeEntity::getTruckTypeId)
.collect(Collectors.toList());
dto.setTruckTypeIds(list);
}
return dto;
}
/**
* 获取货物类型列表
*
* @return 货物类型列表
*/
@GetMapping
public List<GoodsTypeDto> findAll(@RequestParam(name = "ids", required = false) List<Long> ids) {
return goodsTypeService.findAll(ids).stream().map(pdGoodsType -> {
GoodsTypeDto dto = BeanUtil.toBean(pdGoodsType, GoodsTypeDto.class);
dto.setTruckTypeIds(truckTypeGoodsTypeService.findAll(null, dto.getId())
.stream()
.map(TruckTypeGoodsTypeEntity::getTruckTypeId)
.collect(Collectors.toList()));
return dto;
}).collect(Collectors.toList());
}
/**
* 获取分页货物类型数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param name 货物类型名称
* @param truckTypeId 车辆类型Id
* @return 分页结果
*/
@GetMapping("/page")
public PageResponse<GoodsTypeDto> findByPage(
@RequestParam(name = "page") Integer page,
@RequestParam(name = "pageSize") Integer pageSize,
@RequestParam(name = "name", required = false) String name,
@RequestParam(name = "truckTypeId", required = false) Long truckTypeId) {
IPage<GoodsTypeEntity> goodsTypePage = goodsTypeService.findByPage(page, pageSize, name, truckTypeId);
List<GoodsTypeDto> goodsTypeDtoList = goodsTypePage.getRecords().stream().map(goodsType -> {
GoodsTypeDto dto = new GoodsTypeDto();
BeanUtil.copyProperties(goodsType, dto);
dto.setTruckTypeIds(truckTypeGoodsTypeService.findAll(null, dto.getId())
.stream()
.map(TruckTypeGoodsTypeEntity::getTruckTypeId)
.collect(Collectors.toList()));
return dto;
}).collect(Collectors.toList());
return PageResponse.<GoodsTypeDto>builder().items(goodsTypeDtoList).counts(goodsTypePage.getTotal()).page(page).pages(goodsTypePage.getPages()).pageSize(pageSize).build();
}
@GetMapping("/all")
public List<GoodsTypeDto> findAll() {
return goodsTypeService.findAll().stream().map(item -> BeanUtil.toBean(item, GoodsTypeDto.class)).collect(Collectors.toList());
}
/**
* 更新货物类型信息
*
* @param id 货物类型id
* @param dto 货物类型信息
* @return 货物类型信息
*/
@PutMapping("/{id}")
public GoodsTypeDto update(@PathVariable(name = "id") Long id, @RequestBody GoodsTypeDto dto) {
dto.setId(id);
GoodsTypeEntity goodsType = BeanUtil.toBean(dto, GoodsTypeEntity.class);
goodsTypeService.updateById(goodsType);
if (ObjectUtil.isNotEmpty(dto.getTruckTypeIds())) {
truckTypeGoodsTypeService.delete(null, id);
List<TruckTypeGoodsTypeEntity> list = dto.getTruckTypeIds().stream().map(truckTypeId ->
TruckTypeGoodsTypeEntity.builder().truckTypeId(truckTypeId).goodsTypeId(id).build())
.collect(Collectors.toList());
truckTypeGoodsTypeService.saveBatch(list);
}
return dto;
}
/**
* 删除货物类型
*
* @param id 货物类型id
* @return 返回信息
*/
@PutMapping("/{id}/disable")
public void disable(@PathVariable(name = "id") Long id) {
GoodsTypeEntity pdGoodsType = new GoodsTypeEntity();
pdGoodsType.setId(id);
pdGoodsType.setStatus(TruckConstant.DATA_DISABLE_STATUS);
goodsTypeService.updateById(pdGoodsType);
}
}

View File

@@ -0,0 +1,61 @@
package com.sl.ms.base.controller.base;
import com.sl.mq.service.MQService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 通用的消息中间件发送接口
*
* @author zzj
* @version 1.0
*/
@Slf4j
@Validated
@RestController
@RequestMapping("mq")
@Api(tags = "通用的消息中间件")
public class MQController {
@Resource
private MQService mqService;
@PostMapping
@ApiOperation(value = "发送实时消息", notes = "发送实时消息")
@ApiImplicitParams({
@ApiImplicitParam(name = "exchange", value = "交换机", required = true),
@ApiImplicitParam(name = "routingKey", value = "路由key非必须"),
@ApiImplicitParam(name = "msg", value = "消息对象json字符串", required = true)
})
public boolean sendMsg(@RequestParam("exchange") String exchange,
@RequestParam(value = "routingKey", required = false) String routingKey,
@RequestParam("msg") String msg) {
return this.mqService.sendMsg(exchange, routingKey, msg);
}
@PostMapping("delay")
@ApiOperation(value = "发送延迟消息", notes = "发送延迟消息")
@ApiImplicitParams({
@ApiImplicitParam(name = "exchange", value = "交换机", required = true),
@ApiImplicitParam(name = "routingKey", value = "路由key非必须"),
@ApiImplicitParam(name = "msg", value = "消息对象json字符串", required = true),
@ApiImplicitParam(name = "delay", value = "延时时间,单位:毫秒", required = true)
})
public boolean sendMsg(@RequestParam("exchange") String exchange,
@RequestParam(value = "routingKey", required = false) String routingKey,
@RequestParam("msg") String msg,
@RequestParam("delay") int delay) {
return this.mqService.sendMsg(exchange, routingKey, msg, delay);
}
}

View File

@@ -0,0 +1,82 @@
package com.sl.ms.base.controller.base;
import com.sl.ms.base.domain.base.LatestMessageDTO;
import com.sl.ms.base.domain.base.MessageAddDTO;
import com.sl.ms.base.domain.base.MessageDTO;
import com.sl.ms.base.domain.base.MessageQueryDTO;
import com.sl.ms.base.service.base.MessageService;
import com.sl.transport.common.util.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Validated
@RestController
@RequestMapping("/messages")
@Api(value = "Message", tags = "消息相关接口")
public class MessageController {
@Resource
private MessageService messageService;
@ApiOperation(value = "新增消息")
@PostMapping
public void add(@RequestBody MessageAddDTO messageAddDTO) {
messageService.add(messageAddDTO);
}
@ApiOperation(value = "标记已读")
@PutMapping("/{id}")
public void update2Read(@PathVariable("id") Long id) {
messageService.update2Read(id);
}
@ApiOperation(value = "批量已读")
@PutMapping("/batchRead")
public void batchRead(@RequestBody List<Long> ids) {
messageService.batchRead(ids);
}
@ApiOperation(value = "全部已读")
@PutMapping("readAll/{userId}/{contentType}")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", required = true, dataTypeClass = Long.class),
@ApiImplicitParam(name = "contentType", value = "消息类型300快递员端公告301寄件相关消息302签收相关消息303快件取消消息304派件消息", required = true, dataTypeClass = Integer.class)
})
public void readAll(@PathVariable("userId") Long userId,
@PathVariable("contentType") Integer contentType) {
messageService.readAll(userId, contentType);
}
@ApiOperation(value = "查询消息列表")
@GetMapping
public List<MessageDTO> list(@SpringQueryMap MessageQueryDTO messageQueryDTO) {
return messageService.queryList(messageQueryDTO);
}
@ApiOperation(value = "根据类型查询消息数量")
@GetMapping("/countType")
public Integer countType(@SpringQueryMap MessageQueryDTO messageQueryDTO) {
return messageService.countType(messageQueryDTO);
}
@ApiOperation(value = "最新消息查询")
@GetMapping("latestMessage")
public LatestMessageDTO latestMessage(@SpringQueryMap MessageQueryDTO messageQueryDTO) {
return messageService.latestMessage(messageQueryDTO);
}
@ApiOperation(value = "分页查询消息列表")
@GetMapping("/page")
public PageResponse<MessageDTO> page(@SpringQueryMap MessageQueryDTO messageQueryDTO) {
return messageService.pageQuery(messageQueryDTO);
}
}

View File

@@ -0,0 +1,79 @@
package com.sl.ms.base.controller.base;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sl.ms.base.domain.base.WorkPatternAddDTO;
import com.sl.ms.base.domain.base.WorkPatternDTO;
import com.sl.ms.base.domain.base.WorkPatternQueryDTO;
import com.sl.ms.base.domain.base.WorkPatternUpdateDTO;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import com.sl.ms.base.service.base.WorkPatternService;
import com.sl.transport.common.util.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@RequestMapping("work-patterns")
@RestController
@Slf4j
@Api(tags = "工作模式相关接口")
public class WorkPatternController {
@Resource
private WorkPatternService workPatternService;
@GetMapping("all")
@ApiOperation("工作模式列表查询")
public List<WorkPatternDTO> all() {
return workPatternService.all();
}
@GetMapping("page")
@ApiOperation("工作模式列表查询")
public PageResponse<WorkPatternDTO> list(WorkPatternQueryDTO workPatternQueryDTO) {
log.info("workPatternQueryDTO : {}", workPatternQueryDTO);
return workPatternService.page(workPatternQueryDTO);
}
@GetMapping("{id}")
@ApiOperation("根据工作模式id获取工作模式详情")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "工作模式id")
})
public ResponseEntity<WorkPatternDTO> getById(@PathVariable("id") Long id) {
WorkPatternDTO workPatternDTO = workPatternService.findById(id);
return ResponseEntity.ok(workPatternDTO);
}
@DeleteMapping("{id}")
@ApiOperation("工作模式删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "工作模式id")
})
public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
workPatternService.delete(id);
return ResponseEntity.ok(null);
}
@PostMapping
@ApiOperation("新增工作模式")
public ResponseEntity<Void> add(@RequestBody WorkPatternAddDTO workPatternAddDTO) {
workPatternService.add(workPatternAddDTO);
return ResponseEntity.ok(null);
}
@PutMapping("")
@ApiOperation("修改工作模式")
public ResponseEntity<Void> put(@RequestBody WorkPatternUpdateDTO workPatternUpdateDTO){
workPatternService.update(workPatternUpdateDTO);
return ResponseEntity.ok(null);
}
}

View File

@@ -0,0 +1,102 @@
package com.sl.ms.base.controller.base;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.sl.ms.base.domain.base.WorkSchedulingAddDTO;
import com.sl.ms.base.domain.base.WorkSchedulingDTO;
import com.sl.ms.base.domain.base.WorkSchedulingQueryDTO;
import com.sl.ms.base.domain.base.WorkSchedulingUpdateDTO;
import com.sl.ms.base.service.base.WorkSchedulingService;
import com.sl.transport.common.util.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@RequestMapping("work-schedulings")
@Api(tags = "工作排班相关接口")
@RestController
@Slf4j
public class WorkSchedulingController {
@Autowired
private WorkSchedulingService workSchedulingService;
@GetMapping
@ApiOperation("分页查询排班")
public PageResponse<WorkSchedulingDTO> list(WorkSchedulingQueryDTO workSchedulingQueryDTO) {
return workSchedulingService.queryForPage(workSchedulingQueryDTO);
}
@PostMapping("batch")
@ApiOperation("批量新增排班")
public ResponseEntity<Void> batch(@RequestBody List<WorkSchedulingAddDTO> workSchedulingAddDTOList) {
workSchedulingService.batchAdd(workSchedulingAddDTOList);
return ResponseEntity.ok(null);
}
@DeleteMapping("{id}/{operator}")
@ApiOperation("删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "排班id"),
@ApiImplicitParam(name = "operator", value = "操作人")
})
public ResponseEntity<Void> delete(@PathVariable("id") Long id, @PathVariable("operator") Long operator) {
workSchedulingService.delete(id, operator);
return ResponseEntity.ok(null);
}
@ApiOperation("更新排班")
@PutMapping("")
public ResponseEntity<Void> update(@RequestBody WorkSchedulingUpdateDTO workSchedulingUpdateDTO) {
workSchedulingService.update(workSchedulingUpdateDTO);
return ResponseEntity.ok(null);
}
@ApiOperation("根据用户id查询这个月排班计划")
@GetMapping("currentSchedule/{userId}")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id"),
})
public ResponseEntity<WorkSchedulingDTO> currentSchedule(@PathVariable("userId") Long userId) {
return ResponseEntity.ok(workSchedulingService.currentSchedule(userId));
}
@ApiOperation("根据网点id查询该网点所有员工的排班信息")
@GetMapping("todayScheduleByAgencyId/{agencyId}")
@ApiImplicitParams({
@ApiImplicitParam(name = "agencyId", value = "网点id")
})
public ResponseEntity<List<WorkSchedulingDTO>> monthScheduleByAgencyId(@PathVariable("agencyId") Long agencyId) {
return ResponseEntity.ok(workSchedulingService.monthScheduleByAgencyId(agencyId));
}
@ApiOperation("根据快递员/司机id列表或网点id查询当前工作排班")
@GetMapping("todaySchedule/{userType}")
@ApiImplicitParams({
@ApiImplicitParam(name = "userIdList", value = "userId列表可以是快递员id列表也可以是司机id列表"),
@ApiImplicitParam(name = "agencyId", value = "网点id"),
@ApiImplicitParam(name = "userType", value = "用户类型1:员工2快递员3司机"),
@ApiImplicitParam(name = "time", value = "日期"),
})
public ResponseEntity<List<WorkSchedulingDTO>> monthSchedule(
@RequestParam(value = "userIdList", required = false) String userIdList,
@RequestParam(value = "agencyId", required = false) Long agencyId,
@PathVariable("userType") Byte type,
@RequestParam("time") Long time){
List<Long> userIds = ObjectUtil.isNotEmpty(userIdList) ? Arrays.stream(userIdList.split(",")).filter(StrUtil::isNotEmpty).map(Long::parseLong).collect(Collectors.toList()) : new ArrayList<>();
return ResponseEntity.ok(workSchedulingService.monthSchedule(userIds, agencyId, type, LocalDateTimeUtil.of(time)));
}
}

View File

@@ -0,0 +1,207 @@
package com.sl.ms.base.controller.truck;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sl.ms.base.domain.enums.TruckRunStatusEnum;
import com.sl.ms.base.domain.truck.TruckDto;
import com.sl.ms.base.entity.truck.TruckEntity;
import com.sl.ms.base.entity.truck.TruckTypeEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.service.truck.TruckService;
import com.sl.ms.base.service.truck.TruckTypeService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.transport.common.util.PageResponse;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* 车辆业务
*/
@RestController
@RequestMapping("base/truck")
public class TruckController {
@Resource
private TruckService truckService;
@Resource
private TruckDriverService truckDriverService;
@Resource
private TruckTypeService truckTypeService;
/**
* 添加车辆
*
* @param dto 车辆信息
* @return 车辆信息
*/
@PostMapping
public TruckDto saveTruck(@RequestBody TruckDto dto) {
TruckEntity truckEntity = BeanUtil.toBean(dto, TruckEntity.class);
// 車型計算
List<TruckTypeEntity> all = truckTypeService.findAll(Collections.singletonList(dto.getTruckTypeId()));
if (CollUtil.isNotEmpty(all)) {
TruckTypeEntity truckTypeEntity = all.get(0);
if (ObjectUtil.isNotEmpty(truckTypeEntity)) {
truckEntity.setAllowableLoad(truckTypeEntity.getAllowableLoad());
truckEntity.setAllowableVolume(truckTypeEntity.getAllowableVolume());
}
}
truckService.save(truckEntity);
BeanUtil.copyProperties(truckEntity, dto);
return dto;
}
/**
* 根据id获取车辆详情
*
* @param id 车辆id
* @return 车辆信息
*/
@GetMapping("/{id}")
public TruckDto fineById(@PathVariable(name = "id") Long id) {
TruckEntity truckEntity = truckService.getById(id);
if (ObjectUtil.isEmpty(truckEntity)) {
return null;
}
return BeanUtil.toBean(truckEntity, TruckDto.class);
}
/**
* 获取车辆分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param truckTypeId 车辆类型id
* @param licensePlate 车牌号码
* @return 车辆分页数据
*/
@GetMapping("/page")
public PageResponse<TruckDto> findByPage(@RequestParam(name = "page") Integer page,
@RequestParam(name = "pageSize") Integer pageSize,
@RequestParam(name = "truckTypeId", required = false) Long truckTypeId,
@RequestParam(name = "status", required = false) Integer status,
@RequestParam(name = "licensePlate", required = false) String licensePlate) {
IPage<TruckEntity> truckPage = truckService.findByPage(page, pageSize, truckTypeId, status, licensePlate);
List<TruckDto> dtoList = new ArrayList<>();
// 车型
Set<Long> truckTypeSet = new HashSet<>();
truckPage.getRecords().forEach(truckDto -> {
if (ObjectUtil.isNotEmpty(truckDto.getTruckTypeId())) {
truckTypeSet.add(truckDto.getTruckTypeId());
}
});
Map<Long, TruckTypeEntity> truckTypeVOMap = truckTypeService.truckTypeMap(truckTypeSet);
truckPage.getRecords().forEach(pdTruck -> {
TruckDto dto = BeanUtil.toBean(pdTruck, TruckDto.class);
LambdaQueryWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(TruckDriverEntity::getTruckId, dto.getId());
long count = truckDriverService.count(lambdaQueryWrapper);
dto.setDriverNum((int) count);
if (ObjectUtil.isNotEmpty(dto.getTruckTypeId())) {
TruckTypeEntity truckTypeVo = truckTypeVOMap.get(dto.getTruckTypeId());
dto.setTruckTypeName(truckTypeVo.getName());
}
dtoList.add(dto);
});
return PageResponse.<TruckDto>builder().items(dtoList).pageSize(pageSize).page(page).counts(truckPage.getTotal())
.pages(truckPage.getPages()).build();
}
/**
* 获取车辆列表
*
* @param ids 车辆id列表
* @return 车辆列表
*/
@GetMapping
public List<TruckDto> findAll(@RequestParam(name = "ids", required = false) List<Long> ids) {
return truckService.findAll(ids).stream().map(truckEntity -> {
TruckDto dto = BeanUtil.toBean(truckEntity, TruckDto.class);
LambdaQueryWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(TruckDriverEntity::getTruckId, dto.getId());
long count = truckDriverService.count(lambdaQueryWrapper);
dto.setDriverNum((int) count);
return dto;
}).collect(Collectors.toList());
}
/**
* 更新车辆信息
*
* @param id 车辆id
* @param dto 车辆信息
* @return 车辆信息
*/
@PutMapping("/{id}")
public TruckDto update(@PathVariable(name = "id") Long id, @RequestBody TruckDto dto) {
dto.setId(id);
TruckEntity truckEntity = BeanUtil.toBean(dto, TruckEntity.class);
truckService.updateById(truckEntity);
return dto;
}
/**
* 统计车辆数量
*
* @return 车辆数量
*/
@GetMapping("/count")
public Map<Integer, Long> count() {
return truckService.groupByStatus();
}
/**
* 禁用车辆
*
* @param id 车辆id
*/
@PutMapping("/{id}/disable")
public void disable(@PathVariable(name = "id") Long id) {
truckService.stopById(id);
}
/**
* 启用车辆
*
* @param id 车辆id
*/
@PutMapping("/{id}/enable")
public void enable(@PathVariable(name = "id") Long id) {
truckService.workedById(id);
}
/**
* 删除车辆
*
* @param id 车辆id
*/
@PutMapping("/{id}/del")
public void del(@PathVariable(name = "id") Long id) {
truckService.del(id);
}
/**
* 更新车辆状态
* 调用时机 车辆出库
* @param id 车辆id
* @param status 车辆状态枚举
*/
@PutMapping("/updateRunStatus")
public void updateRunStatus(@RequestParam(name = "id") Long id, @RequestParam("status") TruckRunStatusEnum status) {
truckService.updateRunStatus(id, status);
}
}

View File

@@ -0,0 +1,46 @@
package com.sl.ms.base.controller.truck;
import cn.hutool.core.bean.BeanUtil;
import com.sl.ms.base.domain.truck.TruckLicenseDto;
import com.sl.ms.base.entity.truck.TruckLicenseEntity;
import com.sl.ms.base.service.truck.TruckLicenseService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 车辆行驶证业务
*/
@RestController
@RequestMapping("base/truck/license")
public class TruckLicenseController {
@Resource
private TruckLicenseService truckLicenseService;
/**
* 保存车辆行驶证信息
*
* @param dto 车辆行驶证信息
* @return 车辆行驶证信息
*/
@PostMapping
public TruckLicenseDto saveTruckLicense(@RequestBody TruckLicenseDto dto) {
TruckLicenseEntity pdTruckLicenseEntity = BeanUtil.toBean(dto, TruckLicenseEntity.class);
pdTruckLicenseEntity = truckLicenseService.saveTruckLicense(pdTruckLicenseEntity);
BeanUtil.copyProperties(pdTruckLicenseEntity, dto);
return dto;
}
/**
* 根据id获取车辆行驶证详情
*
* @param id 车辆行驶证id
* @return 车辆行驶证信息
*/
@GetMapping("/{id}")
public TruckLicenseDto fineById(@PathVariable(name = "id") Long id) {
TruckLicenseEntity pdTruckLicense = truckLicenseService.getById(id);
return BeanUtil.toBean(pdTruckLicense, TruckLicenseDto.class);
}
}

View File

@@ -0,0 +1,58 @@
package com.sl.ms.base.controller.truck;
import cn.hutool.core.bean.BeanUtil;
import com.sl.ms.base.domain.enums.StatusEnum;
import com.sl.ms.base.domain.truck.TruckPlanDto;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import com.sl.ms.base.service.truck.TruckPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 车辆计划
*/
@Slf4j
@RestController
@RequestMapping("base/plan/")
public class TruckPlanController {
@Resource
private TruckPlanService truckPlanService;
/**
* 获取未分配运输任务的车次计划列表
* @return 未分配运输任务的车次计划列表
*/
@GetMapping("/unassignedPlan/{shardTotal}/{shardIndex}")
public List<TruckPlanDto> pullUnassignedPlan(@PathVariable(name = "shardTotal") Integer shardTotal, @PathVariable(name = "shardIndex") Integer shardIndex) {
// 查询计划
return truckPlanService.pullUnassignedPlan(shardTotal, shardIndex);
}
/**
* 根据ID获取
* @param id 数据库ID
* @return 返回信息
*/
@GetMapping("{id}")
public TruckPlanDto findOne(@PathVariable("id") Long id) {
TruckPlanEntity truckPlanEntity = truckPlanService.getById(id);
return BeanUtil.toBean(truckPlanEntity, TruckPlanDto.class);
}
/**
* 计划完成
* @param currentOrganId 结束机构id
* @param planId 计划ID
* @param truckId 车辆ID
* @param statusEnum 车辆状态枚举
*/
@PutMapping("finished")
void finished(@RequestParam("currentOrganId") Long currentOrganId, @RequestParam("planId") Long planId, @RequestParam("truckId") Long truckId, @RequestParam("statusEnum") StatusEnum statusEnum) {
truckPlanService.finishedPlan(currentOrganId, planId, truckId, statusEnum);
}
}

View File

@@ -0,0 +1,49 @@
package com.sl.ms.base.controller.truck;
import cn.hutool.core.bean.BeanUtil;
import com.sl.ms.base.domain.truck.TruckReturnRegisterDTO;
import com.sl.ms.base.domain.truck.TruckReturnRegisterListDTO;
import com.sl.ms.base.domain.truck.TruckReturnRegisterPageQueryDTO;
import com.sl.ms.base.entity.truck.TruckReturnRegisterEntity;
import com.sl.ms.base.service.truck.TruckReturnRegisterService;
import com.sl.transport.common.util.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 回车登记
*/
@Api(tags = "回车登记")
@RestController
@RequestMapping("base/returnRegister")
@Slf4j
public class TruckReturnRegisterController {
@Resource
private TruckReturnRegisterService truckReturnRegisterService;
@PostMapping
@ApiOperation(value = "新增回车登记", notes = "新增回车登记记录")
public void save(@RequestBody TruckReturnRegisterDTO truckReturnRegisterDTO) {
TruckReturnRegisterEntity truckReturnRegisterEntity = BeanUtil.toBean(truckReturnRegisterDTO, TruckReturnRegisterEntity.class);
truckReturnRegisterService.save(truckReturnRegisterEntity);
}
@PostMapping("pageQuery")
@ApiOperation(value = "分页查询回车登记列表")
public PageResponse<TruckReturnRegisterListDTO> pageQuery(@RequestBody TruckReturnRegisterPageQueryDTO truckReturnRegisterPageQueryDTO) {
return truckReturnRegisterService.pageQuery(truckReturnRegisterPageQueryDTO);
}
@GetMapping("/{id}")
@ApiOperation(value = "根据id查询回车登记详情")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "回车登记id",dataTypeClass = Long.class)})
public TruckReturnRegisterDTO findById(@PathVariable("id") Long id) {
return truckReturnRegisterService.findById(id);
}
}

View File

@@ -0,0 +1,131 @@
package com.sl.ms.base.controller.truck;
import cn.hutool.core.bean.BeanUtil;
import com.sl.ms.base.domain.truck.TransportTripsTruckDriverDto;
import com.sl.ms.base.domain.truck.TruckTripsDto;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import com.sl.ms.base.service.truck.TransportTripsTruckDriverService;
import com.sl.ms.base.service.truck.TruckTripsService;
import com.sl.transport.common.util.ObjectUtil;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 车次
*/
@RestController
@RequestMapping("base/trips")
public class TruckTripsController {
@Resource
private TruckTripsService truckTripsService;
@Resource
private TransportTripsTruckDriverService transportTripsTruckDriverService;
/**
* 添加车次
*
* @param dto 车次信息
* @return 车次信息
*/
@PostMapping
public TruckTripsDto save(@RequestBody TruckTripsDto dto) {
TruckTripsEntity truckTripsEntity = BeanUtil.toBean(dto, TruckTripsEntity.class);
truckTripsService.save(truckTripsEntity);
return dto;
}
/**
* 根据id获取车次详情
*
* @param id 车次id
* @return 车次信息
*/
@GetMapping("/{id}")
public TruckTripsDto fineById(@PathVariable(name = "id") Long id) {
TruckTripsEntity truckTripsEntity = truckTripsService.getById(id);
if (ObjectUtil.isNotEmpty(truckTripsEntity)) {
return BeanUtil.toBean(truckTripsEntity, TruckTripsDto.class);
}
return new TruckTripsDto();
}
/**
* 获取车次列表
*
* @param transportLineId 线路id
* @param ids 车次id列表
* @return 车次列表
*/
@GetMapping
public List<TruckTripsDto> findAll(@RequestParam(name = "transportLineId", required = false) Long transportLineId,
@RequestParam(name = "ids", required = false) List<Long> ids) {
return truckTripsService.findAll(transportLineId, ids)
.stream()
.map(truckTrips -> BeanUtil.toBean(truckTrips, TruckTripsDto.class))
.collect(Collectors.toList());
}
/**
* 更新车次信息
*
* @param id 车次id
* @param dto 车次信息
* @return 车次信息
*/
@PutMapping("/{id}")
public TruckTripsDto update(@PathVariable(name = "id") Long id,
@RequestBody TruckTripsDto dto) {
dto.setId(id);
TruckTripsEntity truckTripsEntity = BeanUtil.toBean(dto, TruckTripsEntity.class);
truckTripsService.updateById(truckTripsEntity);
return dto;
}
/**
* 删除车次信息
*
* @param id 车次信息
*/
@PutMapping("/{id}/disable")
public void disable(@PathVariable(name = "id") Long id) {
truckTripsService.disable(id);
}
/**
* 批量保存车次与车辆和司机关联关系
*
* @param dtoList 车次与车辆和司机关联关系
*/
@PostMapping("{id}/truckDriver")
public void batchSaveTruckDriver(@PathVariable(value = "id", required = false) Long transportTripsId,
@RequestBody List<TransportTripsTruckDriverDto> dtoList) {
transportTripsTruckDriverService.batchSave(transportTripsId, dtoList.stream().map(dto -> {
dto.setTransportTripsId(transportTripsId);
return BeanUtil.toBean(dto, TransportTripsTruckDriverEntity.class);
}).collect(Collectors.toList()));
}
/**
* 获取车次与车辆和司机关联关系列表
*
* @param transportTripsId 车次id
* @param truckId 车辆id
* @param driverId 司机id
* @return 车次与车辆和司机关联关系列表
*/
@GetMapping("truckDriver")
public List<TransportTripsTruckDriverDto> findAllTruckDriverTransportTrips(@RequestParam(name = "transportTripsId", required = false) Long transportTripsId,
@RequestParam(name = "truckId", required = false) Long truckId,
@RequestParam(name = "driverId", required = false) Long driverId) {
return transportTripsTruckDriverService.findAll(transportTripsId, truckId, driverId)
.parallelStream()
.map(transportTripsTruck -> BeanUtil.toBean(transportTripsTruck, TransportTripsTruckDriverDto.class))
.collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,159 @@
package com.sl.ms.base.controller.truck;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sl.ms.base.domain.truck.TruckTypeDto;
import com.sl.ms.base.entity.truck.TruckTypeEntity;
import com.sl.ms.base.entity.truck.TruckTypeGoodsTypeEntity;
import com.sl.ms.base.service.truck.TruckService;
import com.sl.ms.base.service.truck.TruckTypeGoodsTypeService;
import com.sl.ms.base.service.truck.TruckTypeService;
import com.sl.transport.common.util.PageResponse;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 车辆类型 业务
*/
@RestController
@RequestMapping("base/truck/type")
public class TruckTypeController {
@Resource
private TruckTypeService truckTypeService;
@Resource
private TruckTypeGoodsTypeService truckTypeGoodsTypeService;
@Resource
private TruckService truckService;
/**
* 添加车辆类型
*
* @param dto 车辆类型信息
* @return 车辆类型信息
*/
@PostMapping
public TruckTypeDto saveTruckType(@RequestBody TruckTypeDto dto) {
TruckTypeEntity truckTypeEntity = BeanUtil.toBean(dto, TruckTypeEntity.class);
truckTypeService.save(truckTypeEntity);
Long truckTypeId = truckTypeEntity.getId();
//处理与货物类型的关联
if (ObjectUtil.isNotEmpty(dto.getGoodsTypeIds())) {
List<TruckTypeGoodsTypeEntity> list = dto.getGoodsTypeIds()
.stream()
.map(id -> TruckTypeGoodsTypeEntity.builder().goodsTypeId(id).truckTypeId(truckTypeId).build())
.collect(Collectors.toList());
truckTypeGoodsTypeService.saveBatch(list);
}
BeanUtil.copyProperties(truckTypeEntity, dto);
return dto;
}
/**
* 根据id获取车辆类型详情
*
* @param id 车辆类型id
* @return 车辆类型信息
*/
@GetMapping("/{id}")
public TruckTypeDto fineById(@PathVariable(name = "id") String id) {
TruckTypeEntity truckTypeEntity = truckTypeService.getById(id);
TruckTypeDto dto = BeanUtil.toBean(truckTypeEntity, TruckTypeDto.class);
List<Long> list = truckTypeGoodsTypeService.findAll(dto.getId(), null)
.stream()
.map(TruckTypeGoodsTypeEntity::getGoodsTypeId)
.collect(Collectors.toList());
dto.setGoodsTypeIds(list);
return dto;
}
/**
* 获取车辆类型分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param name 车辆类型名称
* @param minAllowableLoad 车辆载重最小值(闭区间)
* @param maxAllowableLoad 车辆载重最大值(开区间)
* @param minAllowableVolume 车辆体积最小值(闭区间)
* @param maxAllowableVolume 车辆体积最小值(开区间)
* @param id 车型id
* @return 车辆类型分页数据
*/
@GetMapping("/page")
public PageResponse<TruckTypeDto> findByPage(@RequestParam(name = "page") Integer page,
@RequestParam(name = "pageSize") Integer pageSize,
@RequestParam(name = "name", required = false) String name,
@RequestParam(name = "minAllowableLoad", required = false) BigDecimal minAllowableLoad,
@RequestParam(name = "maxAllowableLoad", required = false) BigDecimal maxAllowableLoad,
@RequestParam(name = "minAllowableVolume", required = false) BigDecimal minAllowableVolume,
@RequestParam(name = "maxAllowableVolume", required = false) BigDecimal maxAllowableVolume,
@RequestParam(name = "id", required = false) Long id) {
IPage<TruckTypeEntity> pdTruckTypePage = truckTypeService.findByPage(page, pageSize, name, minAllowableLoad, maxAllowableLoad, minAllowableVolume, maxAllowableVolume, id);
List<TruckTypeDto> dtoList = new ArrayList<>();
pdTruckTypePage.getRecords().forEach(truckType -> {
TruckTypeDto dto = BeanUtil.toBean(truckType, TruckTypeDto.class);
List<Long> list = truckTypeGoodsTypeService.findAll(dto.getId(), null).stream().map(TruckTypeGoodsTypeEntity::getGoodsTypeId).collect(Collectors.toList());
dto.setGoodsTypeIds(list);
int size = truckService.countByType(truckType.getId());
dto.setNum(size);
dtoList.add(dto);
});
return PageResponse.<TruckTypeDto>builder().items(dtoList).pageSize(pageSize).page(page).counts(pdTruckTypePage.getTotal()).pages(pdTruckTypePage.getPages()).build();
}
/**
* 获取车辆类型列表
*
* @param ids 车辆类型id
* @return 车辆类型列表
*/
@GetMapping
public List<TruckTypeDto> findAll(@RequestParam(name = "ids", required = false) List<Long> ids) {
return truckTypeService.findAll(ids).stream().map(truckType -> {
TruckTypeDto dto = BeanUtil.toBean(truckType, TruckTypeDto.class);
List<Long> list = truckTypeGoodsTypeService.findAll(dto.getId(), null).stream().map(TruckTypeGoodsTypeEntity::getGoodsTypeId).collect(Collectors.toList());
dto.setGoodsTypeIds(list);
return dto;
}).collect(Collectors.toList());
}
/**
* 更新车辆类型信息
*
* @param id 车辆类型id
* @param dto 车辆类型信息
* @return 车辆类型信息
*/
@PutMapping("/{id}")
public TruckTypeDto update(@PathVariable(name = "id") Long id, @RequestBody TruckTypeDto dto) {
dto.setId(id);
truckTypeService.updateById(BeanUtil.toBean(dto, TruckTypeEntity.class));
//处理与货物类型的关联
if (ObjectUtil.isNotEmpty(dto.getGoodsTypeIds())) {
truckTypeGoodsTypeService.delete(id, null);
//绑定新的关系
truckTypeGoodsTypeService.saveBatch(dto.getGoodsTypeIds().stream().map(goodsTypeId -> TruckTypeGoodsTypeEntity.builder().goodsTypeId(goodsTypeId).truckTypeId(id).build()).collect(Collectors.toList()));
}
return dto;
}
/**
* 删除车辆类型
*
* @param id 车辆类型Id
*/
@PutMapping("/{id}/disable")
public void disable(@PathVariable(name = "id") Long id) {
truckTypeService.disable(id);
}
}

View File

@@ -0,0 +1,143 @@
package com.sl.ms.base.controller.user;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sl.ms.base.domain.user.TruckDriverDto;
import com.sl.ms.base.domain.user.TruckDriverLicenseDto;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.entity.user.TruckDriverLicenseEntity;
import com.sl.ms.base.service.user.TruckDriverLicenseService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.transport.common.util.PageResponse;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 司机相关
*/
@RestController
@RequestMapping("sys/driver")
public class TruckDriverController {
@Resource
private TruckDriverService truckDriverService;
@Resource
private TruckDriverLicenseService truckDriverLicenseService;
/**
* 保存司机基本信息
*
* @param dto 司机基本信息
* @return 返回信息
*/
@PostMapping
public TruckDriverDto saveDriver(@RequestBody TruckDriverDto dto) {
return truckDriverService.saveDriver(dto);
}
/**
* 获取司机基本信息列表
*
* @param userIds 司机id列表
* @return 司机基本信息列表
*/
@GetMapping
public List<TruckDriverDto> findAllDriver(@RequestParam(name = "userIds", required = false) List<Long> userIds) {
return truckDriverService.findAll(userIds)
.stream()
.map(pdTruckDriver -> BeanUtil.toBean(pdTruckDriver, TruckDriverDto.class))
.collect(Collectors.toList());
}
/**
* 获取司机基本信息
*
* @param id 司机id
* @return 司机基本信息
*/
@GetMapping("/{id}")
public TruckDriverDto findOneDriver(@PathVariable(name = "id") Long id) {
TruckDriverEntity truckDriverEntity = truckDriverService.findOne(id);
return BeanUtil.toBean(truckDriverEntity, TruckDriverDto.class);
}
/**
* 保存司机驾驶证信息
*
* @param dto 司机驾驶证信息
* @return 返回信息
*/
@PostMapping("/driverLicense")
public TruckDriverLicenseDto saveDriverLicense(@RequestBody TruckDriverLicenseDto dto) {
TruckDriverLicenseEntity driverLicense = BeanUtil.toBean(dto, TruckDriverLicenseEntity.class);
truckDriverLicenseService.saveOrUpdate(driverLicense);
BeanUtil.copyProperties(driverLicense, dto);
return dto;
}
/**
* 获取司机驾驶证信息
*
* @param id 司机id
* @return 司机驾驶证信息
*/
@GetMapping("/{id}/driverLicense")
public TruckDriverLicenseDto findOneDriverLicense(@PathVariable(name = "id") Long id) {
TruckDriverLicenseEntity driverLicense = truckDriverLicenseService.findOne(id);
return BeanUtil.toBean(driverLicense, TruckDriverLicenseDto.class);
}
/**
* 绑定司机列表
* @param truckId 车辆ID
* @return 司机数量
*/
@GetMapping("/count")
public List<TruckDriverDto> findByTruckId(@RequestParam(name = "truckId", required = false) Long truckId) {
return truckDriverService.findByTruckId(truckId)
.stream()
.map(truckDriverEntity -> BeanUtil.toBean(truckDriverEntity, TruckDriverDto.class))
.collect(Collectors.toList());
}
/**
* 获取司机分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @return 司机分页数据
*/
@GetMapping("/page")
public PageResponse<TruckDriverDto> findByPage(@RequestParam(name = "page") Integer page,
@RequestParam(name = "pageSize") Integer pageSize) {
IPage<TruckDriverEntity> truckPage = truckDriverService.findByPage(page, pageSize);
List<TruckDriverDto> dtoList = truckPage.getRecords()
.stream()
.map(truckDriverEntity -> BeanUtil.toBean(truckDriverEntity, TruckDriverDto.class))
.collect(Collectors.toList());
return PageResponse.<TruckDriverDto>builder()
.items(dtoList)
.pageSize(pageSize)
.page(page)
.counts(truckPage.getTotal())
.pages(truckPage.getPages()).build();
}
@GetMapping("/findAll")
public List<TruckDriverDto> findAll(@RequestParam(name = "ids", required = false) List<Long> ids) {
LambdaQueryWrapper<TruckDriverEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CollUtil.isNotEmpty(ids), TruckDriverEntity::getId, ids);
return truckDriverService.list(wrapper)
.stream()
.map(truckDriver -> BeanUtil.toBean(truckDriver, TruckDriverDto.class))
.collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,83 @@
package com.sl.ms.base.entity.base;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.Data;
import java.io.Serializable;
/**
* <p>
* 实体类
* 行政区域
* </p>
*
*/
@Data
@TableName("sl_area")
public class AreaEntity extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 父级行政区域id
*/
private Long parentId;
/**
* 行政区域名称
*/
private String name;
/**
* 行政区域编码
*/
private String areaCode;
/**
* 城市编码
*/
private String cityCode;
/**
* 合并名称
*/
private String mergerName;
/**
* 简称
*/
private String shortName;
/**
* 邮政编码
*/
private String zipCode;
/**
* 行政区域等级0: 省级 1:市级 2:县级 3:镇级 4:乡村级)
*/
private Integer level;
/**
* 经度
*/
private String lng;
/**
* 纬度
*/
private String lat;
/**
* 拼音
*/
private String pinyin;
/**
* 首字母
*/
private String first;
}

View File

@@ -0,0 +1,44 @@
package com.sl.ms.base.entity.base;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 货物类型表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_goods_type")
public class GoodsTypeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 货物类型名称
*/
private String name;
/**
* 默认重量,单位:千克
*/
private BigDecimal defaultWeight;
/**
* 默认体积,单位:方
*/
private BigDecimal defaultVolume;
/**
* 说明
*/
private String remark;
/**
* 状态 0禁用 1正常
*/
private Integer status;
}

View File

@@ -0,0 +1,75 @@
package com.sl.ms.base.entity.base;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.*;
import java.time.LocalDateTime;
/**
* 消息表
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("sl_message")
public class MessageEntity extends BaseEntity{
private static final long serialVersionUID = 4805339214539835115L;
/**
* 消息标题
*/
private String title;
/**
* 消息内容
*/
private String content;
/**
* 1用户端2司机端3快递员端4后台管理系统
*/
private Integer bussinessType;
/**
* 消息接受者
*/
private Long userId;
/**
* 消息类型300快递员端公告301寄件相关消息302签收相关消息303快件取消消息200司机端公告201司机端系统通知
*/
private Integer contentType;
/**
* 消息是否已读0未读1已读
*/
private Integer isRead;
/**
* 读时间
*/
private LocalDateTime readTime;
/**
* 相关id
*/
private Long relevantId;
/**
* 创建者
*/
private Long createUser;
/**
* 更新者
*/
private Long updateUser;
/**
* 逻辑删除0未删除1已删除
*/
private Integer isDelete;
}

View File

@@ -0,0 +1,27 @@
package com.sl.ms.base.entity.base;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.Data;
@Data
@TableName("sl_work_history_scheduling")
public class WorkHistorySchedulingEntity extends BaseEntity {
private Long userId;
private String name;
private String phone;
private String employeeNumber;
private Integer workDay;
private String workMonth;
private Byte userType;
private Byte workPatternType;
private Long workPatternId;
}

View File

@@ -0,0 +1,53 @@
package com.sl.ms.base.entity.base;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_work_pattern")
public class WorkPatternEntity extends BaseEntity {
private String name;
private Byte userType;
private Byte workPatternType;
private Byte monday;
private Byte tuesday;
private Byte wednesday;
private Byte thursday;
private Byte friday;
private Byte saturday;
private Byte sunday;
private Integer workDayNum;
private Integer restDayNum;
private Byte status;
private Integer workStartMinute1;
private Integer workEndMinute1;
private Long creater;
private Long updater;
private Boolean isDelete;
}

View File

@@ -0,0 +1,36 @@
package com.sl.ms.base.entity.base;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.Data;
import java.time.LocalDateTime;
@TableName("sl_work_scheduling")
@Data
public class WorkSchedulingEntity extends BaseEntity {
private Long userId;
private Byte userType;
private Long agencyId;
private String employeeNumber;
private String name;
private String phone;
private Byte state;
private Long workPatternId;
private LocalDateTime workContinueStartTime;
private Long creater;
private Long updater;
private Boolean isDelete;
}

View File

@@ -0,0 +1,31 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.Data;
/**
* <p>
* 车次与车辆关联表
* </p>
*
* @author itcast
* @since 2019-12-20
*/
@Data
@TableName("sl_truck_trips_truck_driver")
public class TransportTripsTruckDriverEntity extends BaseEntity {
private static final long serialVersionUID = 2060686653575483040L;
/**
* 车辆id
*/
private Long truckId;
/**
* 车次id
*/
private Long transportTripsId;
/**
* 司机id
*/
private Long driverId;
}

View File

@@ -0,0 +1,89 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.ms.base.domain.enums.TruckRunStatusEnum;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 车辆信息表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck")
public class TruckEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 车辆类型id
*/
private Long truckTypeId;
/**
* 品牌
*/
private String brand;
/**
* 车牌号码
*/
private String licensePlate;
/**
* GPS设备id
*/
private String deviceGpsId;
/**
* 准载重量
*/
private BigDecimal allowableLoad;
/**
* 准载体积
*/
private BigDecimal allowableVolume;
/**
* 车辆行驶证信息id
*/
private Long truckLicenseId;
/**
* 状态 0禁用 1正常
*/
private Integer status;
/**
* 运输状态 1启用 2停用
* @see TruckWorkStatusEnum
*/
private Integer workStatus;
/**
* 运输状态 0已到达 1运输中
* @see TruckRunStatusEnum
*/
private Integer runStatus;
//所在机构id
private Long currentOrganId;
/**
* 图片信息
*/
private String picture;
/**
* 满载系数
*/
private Double loadingRatio;
}

View File

@@ -0,0 +1,78 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* 车辆行驶证表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_license")
public class TruckLicenseEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 车辆id
*/
private Long truckId;
/**
* 发动机编号
*/
private String engineNumber;
/**
* 注册时间
*/
private LocalDate registrationDate;
/**
* 国家强制报废日期
*/
private LocalDate mandatoryScrap;
/**
* 检验有效期
*/
private LocalDate expirationDate;
/**
* 整备质量
*/
private BigDecimal overallQuality;
/**
* 核定载质量
*/
private BigDecimal allowableWeight;
/**
* 外廓尺寸
*/
private String outsideDimensions;
/**
* 行驶证有效期
*/
private LocalDate validityPeriod;
/**
* 行驶证号
*/
private String transportCertificateNumber;
/**
* 图片信息
*/
private String picture;
}

View File

@@ -0,0 +1,58 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.ms.base.domain.enums.TruckPlanScheduleStatusEnum;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* 车次与车辆关联表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_plan")
public class TruckPlanEntity extends BaseEntity {
private static final long serialVersionUID = 2060686653575483040L;
/**
* 车辆id
*/
private Long truckId;
/**
* 车次id
*/
private Long transportTripsId;
/**
* 司机id
*/
private String driverIds;
/**
* 计划发车时间
*/
private LocalDateTime planDepartureTime;
/**
* 计划到达时间
*/
private LocalDateTime planArrivalTime;
/**
* 状态
* @see com.sl.ms.base.domain.enums.StatusEnum
*/
private Integer status;
/**
* @see TruckPlanScheduleStatusEnum
*/
private Integer scheduleStatus;
}

View File

@@ -0,0 +1,119 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.ms.base.domain.enums.TruckAccidentTypeEnum;
import com.sl.ms.base.domain.enums.TruckBreakRulesTypeEnum;
import com.sl.ms.base.domain.enums.TruckFaultTypeEnum;
import com.sl.transport.common.entity.BaseEntity;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 回车登记表
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_return_register")
public class TruckReturnRegisterEntity extends BaseEntity {
private static final long serialVersionUID = 9041809464760457223L;
/**
* 主键
*/
private Long id;
/**
* 车辆id
*/
private Long truckId;
/**
* 运输任务id
*/
private Long transportTaskId;
/**
* 出库时间
*/
private LocalDateTime outStorageTime;
/**
* 入库时间
*/
private LocalDateTime intoStorageTime;
/**
* 车辆是否违章1-是0-否
*/
private boolean isBreakRules;
/**
* 违章类型1-闯红灯2-无证驾驶3-超载4-酒后驾驶5-超速行驶
*/
private TruckBreakRulesTypeEnum breakRulesType;
/**
* 违章说明,类型为“其他”时填写
*/
private String breakRulesDescription;
/**
* 罚款金额
*/
private BigDecimal penaltyAmount;
/**
* 扣分
*/
private Integer deductPoints;
/**
* 车辆是否故障1-是0-否
*/
private boolean isFault;
/**
* 车辆是否可用1-是0-否
*/
private Boolean isAvailable = true;
/**
* 故障类型1-发动机启动困难2-不着车3-漏油4-漏水5-照明失灵6-有异响7-排烟异常8-温度异常9-其他
*/
private TruckFaultTypeEnum faultType;
/**
* 故障说明,类型为“其他”时填写
*/
private String faultDescription;
/**
* 故障图片
*/
private String faultImages;
/**
* 车辆是否发生事故1-是0-否
*/
private boolean isAccident;
/**
* 事故类型1-直行事故2-追尾事故3-超车事故4-左转弯事故5-右转弯事故6-弯道事故7-坡道事故8-会车事故9-其他
*/
private TruckAccidentTypeEnum accidentType;
/**
* 事故说明,类型为“其他”时填写
*/
private String accidentDescription;
/**
* 事故图片
*/
private String accidentImages;
}

View File

@@ -0,0 +1,51 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 车次信息表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_trips")
public class TruckTripsEntity extends BaseEntity {
private static final long serialVersionUID = -934311173866081843L;
/**
* 车次名称
*/
private String name;
/**
* 发车时间 分钟
*/
private Integer departureTime;
/**
* 持续时间 分钟
*/
private Integer estimatedTime;
/**
* 所属线路id
*/
private Long transportLineId;
/**
* 周期1为天2为周3为月
*/
private Integer period;
/**
* 状态 0禁用 1正常
*/
private Integer status;
}

View File

@@ -0,0 +1,58 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 车辆类型表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_type")
public class TruckTypeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 车辆类型名称
*/
private String name;
/**
* 准载重量
*/
private BigDecimal allowableLoad;
/**
* 准载体积
*/
private BigDecimal allowableVolume;
/**
* 长
*/
private BigDecimal measureLong;
/**
* 宽
*/
private BigDecimal measureWidth;
/**
* 高
*/
private BigDecimal measureHigh;
/**
* 状态 0禁用 1正常
*/
private Integer status;
}

View File

@@ -0,0 +1,32 @@
package com.sl.ms.base.entity.truck;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 车辆类型与货物类型关联表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_type_goods_type")
public class TruckTypeGoodsTypeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 车辆类型id
*/
private Long truckTypeId;
/**
* 货物类型id
*/
private Long goodsTypeId;
}

View File

@@ -0,0 +1,47 @@
package com.sl.ms.base.entity.user;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 司机表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_driver")
public class TruckDriverEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 车辆id
*/
private Long truckId;
/**
* 用户id来自用户表
*/
private Long userId;
/**
* 年龄
*/
private Integer age;
/**
* 图片
*/
private String picture;
/**
* 驾龄
*/
private Integer drivingAge;
}

View File

@@ -0,0 +1,73 @@
package com.sl.ms.base.entity.user;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sl.transport.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
/**
* 司机驾驶证表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sl_truck_driver_license")
public class TruckDriverLicenseEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 用户id
*/
private Long userId;
/**
* 准驾车型
*/
private String allowableType;
/**
* 初次领证日期
*/
private LocalDate initialCertificateDate;
/**
* 有效期限
*/
private String validPeriod;
/**
* 驾驶证号
*/
private String licenseNumber;
/**
* 驾龄
*/
private Integer driverAge;
/**
* 驾驶证类型
*/
private String licenseType;
/**
* 从业资格证信息
*/
private String qualificationCertificate;
/**
* 入场证信息
*/
private String passCertificate;
/**
* 图片
*/
private String picture;
}

View File

@@ -0,0 +1,81 @@
package com.sl.ms.base.job;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SimpleQuery;
import com.sl.ms.base.entity.base.WorkHistorySchedulingEntity;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.ms.base.mapper.base.WorkSchedulingMapper;
import com.sl.ms.base.service.base.WorkHistorySchedulingService;
import com.sl.ms.base.utils.WorkSchedulingUtils;
import com.sl.transport.common.util.DateUtils;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 历史排班保存
* 每晚凌晨2点执行保存前一天排班数据
* @author wxb
* @version 1.0
*/
@Slf4j
@Component
public class HistoryScheduleJob {
@Resource
private WorkHistorySchedulingService workHistorySchedulingService;
@Resource
private WorkSchedulingMapper workSchedulingMapper;
@XxlJob("historyScheduleJob")
public void execute() {
log.info("historyScheduleJob 执行生成排班历史数据任务!!!");
// 查询当前排班
List<WorkSchedulingEntity> workSchedulingEntities = workSchedulingMapper.selectList(Wrappers.<WorkSchedulingEntity>lambdaQuery().eq(WorkSchedulingEntity::getIsDelete, 0));
// 查询工作模式
List<Long> workPatternIds = workSchedulingEntities.parallelStream().map(WorkSchedulingEntity::getWorkPatternId).distinct().collect(Collectors.toList());
Map<Long, WorkPatternEntity> workPatternEntityMap = SimpleQuery.keyMap(
Wrappers.<WorkPatternEntity>lambdaQuery().in(WorkPatternEntity::getId, workPatternIds),
WorkPatternEntity::getId);
// 补充日期数据
List<WorkHistorySchedulingEntity> workHistorySchedulingEntities = workSchedulingEntities.parallelStream().map(workSchedulingEntity -> {
WorkHistorySchedulingEntity workHistorySchedulingEntity = BeanUtil.toBean(workSchedulingEntity, WorkHistorySchedulingEntity.class);
// 重置ID
workHistorySchedulingEntity.setId(null);
WorkPatternEntity workPatternEntity = workPatternEntityMap.get(workSchedulingEntity.getWorkPatternId());
if (ObjectUtil.isEmpty(workPatternEntity)) {
return null;
}
workHistorySchedulingEntity.setWorkPatternType(workPatternEntity.getWorkPatternType());
// 月 前一天对应的月
String workMonth = LocalDateTimeUtil.format(LocalDateTimeUtil.now().minusDays(1), DateUtils.DEFAULT_MONTH_FORMAT);
workHistorySchedulingEntity.setWorkMonth(workMonth);
// 日 前一天对应的日
int dayOfMonth = LocalDateTimeUtil.now().minusDays(1).getDayOfMonth();
workHistorySchedulingEntity.setWorkDay(dayOfMonth);
// 只保存上班数据
boolean worded = WorkSchedulingUtils.isWorded(workSchedulingEntity, workMonth, dayOfMonth, workPatternEntity, null, true);
if (worded) {
return workHistorySchedulingEntity;
}
return null;
}).filter(ObjectUtil::isNotEmpty).collect(Collectors.toList());
// 落库
workHistorySchedulingService.saveBatch(workHistorySchedulingEntities);
}
}

View File

@@ -0,0 +1,17 @@
package com.sl.ms.base.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.base.AreaEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* 行政区域
* </p>
*
*/
@Mapper
public interface AreaMapper extends BaseMapper<AreaEntity> {
}

View File

@@ -0,0 +1,26 @@
package com.sl.ms.base.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sl.ms.base.entity.base.GoodsTypeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface GoodsTypeMapper extends BaseMapper<GoodsTypeEntity> {
/**
* 获取分页货物类型数据,如果传入 货物类型名称 或 车辆id 时进行条件搜索
*
* @param page 分页参数
* @param goodsTypeName 货物类型名称(非必须)
* @param truckTypeId 车辆id非必须
* @return 分页货物数据
*/
List<GoodsTypeEntity> findByPage(Page<GoodsTypeEntity> page,
@Param("goodsTypeName") String goodsTypeName,
@Param("truckTypeId") Long truckTypeId);
}

View File

@@ -0,0 +1,13 @@
package com.sl.ms.base.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.base.MessageEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 消息表 mapper接口
*/
@Mapper
public interface MessageMapper extends BaseMapper<MessageEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.base.WorkHistorySchedulingEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WorkHistorySchedulingMapper extends BaseMapper<WorkHistorySchedulingEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WorkPatternMapper extends BaseMapper<WorkPatternEntity> {
}

View File

@@ -0,0 +1,14 @@
package com.sl.ms.base.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface WorkSchedulingMapper extends BaseMapper<WorkSchedulingEntity> {
void batchInsert(@Param("entities") List<WorkSchedulingEntity> workSchedulingEntities);
}

View File

@@ -0,0 +1,18 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 车次与车辆关联信息表 Mapper 接口
* </p>
*
* @author itcast
* @since 2019-12-20
*/
@Mapper
public interface TransportTripsTruckDriverMapper extends BaseMapper<TransportTripsTruckDriverEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckLicenseEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckLicenseMapper extends BaseMapper<TruckLicenseEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckMapper extends BaseMapper<TruckEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckPlanMapper extends BaseMapper<TruckPlanEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckReturnRegisterEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckReturnRegisterMapper extends BaseMapper<TruckReturnRegisterEntity> {
}

View File

@@ -0,0 +1,10 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckTripsMapper extends BaseMapper<TruckTripsEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckTypeGoodsTypeEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckTypeGoodsTypeMapper extends BaseMapper<TruckTypeGoodsTypeEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.truck;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.truck.TruckTypeEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckTypeMapper extends BaseMapper<TruckTypeEntity> {
}

View File

@@ -0,0 +1,9 @@
package com.sl.ms.base.mapper.user;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.user.TruckDriverLicenseEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckDriverLicenseMapper extends BaseMapper<TruckDriverLicenseEntity> {
}

View File

@@ -0,0 +1,10 @@
package com.sl.ms.base.mapper.user;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TruckDriverMapper extends BaseMapper<TruckDriverEntity> {
}

View File

@@ -0,0 +1,163 @@
package com.sl.ms.base.mq;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.sl.ms.base.domain.enums.WorkStatusEnum;
import com.sl.ms.base.domain.enums.WorkUserTypeEnum;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.ms.base.service.base.WorkSchedulingService;
import com.sl.transport.common.constant.Constants;
import com.sl.transport.common.util.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* 对于权限管家系统消息的处理
*
* @author zzj
* @version 1.0
*/
@Slf4j
@Component
public class AuthUserMQListener {
@Value("${rabbitmq.exchange}")
private String rabbitmqExchange;
@Value("${role.courier}")
private String courier;
@Value("${role.driver}")
private String driver;
@Resource
private WorkSchedulingService workSchedulingService;
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = Constants.MQ.Queues.AUTH_USER),
exchange = @Exchange(name = "${rabbitmq.exchange}", type = ExchangeTypes.TOPIC),
key = "#"
))
public void listenUserMsg(String msg) {
log.info("接收到消息 -> {}", msg);
JSONObject jsonObject = JSONUtil.parseObj(msg);
String type = jsonObject.getStr("type");
if (!StrUtil.equalsIgnoreCase(type, "USER")) {
//非用户消息
return;
}
String operation = jsonObject.getStr("operation");
// roles mobile id
JSONArray jsonArray = jsonObject.getJSONArray("content");
jsonArray.forEach(v -> {
// 转换结构
WorkSchedulingEntity user = parse((JSONObject) v);
// 处理变更
handlerUserChangeMsg(user, operation);
});
}
/**
* 处理变更
*
* @param entity 排班模型
* @param operation 操作类型
*/
private void handlerUserChangeMsg(WorkSchedulingEntity entity, String operation) {
switch (operation) {
case "ADD": {
entity.setId(IdWorker.getId());
//设置默认值
BeanUtil.setDefault(entity);
workSchedulingService.save(entity);
break;
}
case "UPDATE": {
WorkSchedulingEntity byUserId = workSchedulingService.getByUserId(entity.getUserId());
if (ObjectUtil.isEmpty(byUserId)) {
log.error("不存在的员工");
break;
}
entity.setId(byUserId.getId());
workSchedulingService.updateById(entity);
break;
}
case "DEL": {
WorkSchedulingEntity byUserId = workSchedulingService.getByUserId(entity.getUserId());
if (ObjectUtil.isEmpty(byUserId)) {
log.error("不存在的员工");
break;
}
workSchedulingService.delete(byUserId.getId(), 0L);
break;
}
default:
break;
}
}
/**
* 转换数据
*
* @param content 消息内容
* @return 排班信息
*/
private WorkSchedulingEntity parse(JSONObject content) {
JSONArray roles = content.getJSONArray("roles");
String name = content.getStr("name");
String mobile = content.getStr("mobile");
Long agentId = content.getLong("orgId");
Long id = content.getLong("id");
String account = content.getStr("account");
//设置参数
WorkSchedulingEntity entity = new WorkSchedulingEntity();
entity.setUserId(id);
entity.setAgencyId(agentId);
entity.setName(name);
entity.setPhone(mobile);
entity.setEmployeeNumber(account);
entity.setState(WorkStatusEnum.NOMAL.getStatus());
//判断角色
Byte userType;
if (ObjectUtil.isNotEmpty(roles)) {
if (roles.contains(courier)) {
userType = WorkUserTypeEnum.COURIER.getCode();
} else if (roles.contains(driver)) {
userType = WorkUserTypeEnum.DRIVER.getCode();
} else {
userType = WorkUserTypeEnum.USER.getCode();
}
entity.setUserType(userType);
}
return entity;
}
/**
* 声明交换机,确保交换机一定存在
*/
@Bean
public TopicExchange authUserExchange() {
return new TopicExchange(this.rabbitmqExchange, true, false);
}
}

View File

@@ -0,0 +1,51 @@
package com.sl.ms.base.mq;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sl.ms.base.service.truck.TruckPlanService;
import com.sl.transport.common.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 更新车辆计划调度状态
*
* @author wxb
* @version 1.0
*/
@Slf4j
@Service
public class TruckPlanScheduledMQListener{
@Resource
TruckPlanService truckPlanService;
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = Constants.MQ.Queues.BASE_TRUCK_PLAN_COMPLETE),
exchange = @Exchange(name = Constants.MQ.Exchanges.TRUCK_PLAN, type = ExchangeTypes.TOPIC),
key = Constants.MQ.RoutingKeys.TRUCK_PLAN_COMPLETE
))
public void listenTruckPlanScheduledMsg(String msg) {
log.info("listenTruckPlanScheduledMsg msg {}", msg);
// {"ids":[1,2,3], "created":123456}
JSONObject jsonObject = JSONUtil.parseObj(msg);
if (ObjectUtil.isEmpty(jsonObject)) {
return;
}
JSONArray ids = jsonObject.getJSONArray("ids");
Set<Long> collect = ids.stream().map(Convert::toLong).collect(Collectors.toSet());
truckPlanService.scheduledPlan(collect);
}
}

View File

@@ -0,0 +1,40 @@
package com.sl.ms.base.service.base;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.base.AreaDto;
import com.sl.ms.base.entity.base.AreaEntity;
import java.util.List;
/**
* <p>
* 业务接口
* 行政区域
* </p>
*/
public interface AreaService extends IService<AreaEntity> {
/**
* 根据编码查询行政区域
*
* @param code 行政编码
* @return 行政区域
*/
AreaEntity getByCode(String code);
/**
* 根据父级id查询子级行政区域
*
* @param parentId 父级id
* @return 子级行政区域列表
*/
List<AreaDto> findChildren(Long parentId);
/**
* 根据id批量查询
*
* @param ids id列表
* @return 行政区域列表
*/
List<AreaDto> findBatch(List<Long> ids);
}

View File

@@ -0,0 +1,17 @@
package com.sl.ms.base.service.base;
import com.itheima.auth.sdk.dto.UserDTO;
/**
* 权限系统对接服务
*/
public interface AuthService {
/**
* 根据用户id获得详细信息
*
* @param id 用户id
* @return 用户信息
*/
UserDTO getByUserId(Long id);
}

View File

@@ -0,0 +1,39 @@
package com.sl.ms.base.service.base;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.base.GoodsTypeEntity;
import java.util.List;
/**
* 货物类型表 服务类
*/
public interface GoodsTypeService extends IService<GoodsTypeEntity> {
/**
* 获取分页货物类型数据,如果传入 货物类型名称 或 车辆id 时进行条件搜索
*
* @param page 页码
* @param pageSize 页尺寸
* @param goodsTypeName 货物类型名称(非必须)
* @param truckTypeId 车辆id非必须
* @return 分页货物数据
*/
IPage<GoodsTypeEntity> findByPage(Integer page, Integer pageSize, String goodsTypeName, Long truckTypeId);
/**
* 根据id列表获取货物类型列表
*
* @param ids 货物类型id
* @return 货物类型列表
*/
List<GoodsTypeEntity> findAll(List<Long> ids);
/**
* 查询所有状态可用的货物类型列表
*
* @return 货物类型列表
*/
List<GoodsTypeEntity> findAll();
}

View File

@@ -0,0 +1,77 @@
package com.sl.ms.base.service.base;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.base.LatestMessageDTO;
import com.sl.ms.base.domain.base.MessageAddDTO;
import com.sl.ms.base.domain.base.MessageDTO;
import com.sl.ms.base.domain.base.MessageQueryDTO;
import com.sl.ms.base.entity.base.MessageEntity;
import com.sl.transport.common.util.PageResponse;
import java.util.List;
/**
* 消息表 服务类
*/
public interface MessageService extends IService<MessageEntity> {
/**
* 新增消息
*
* @param messageAddDTO 消息新增对象
*/
void add(MessageAddDTO messageAddDTO);
/**
* 标记已读
*
* @param id 消息id
*/
void update2Read(Long id);
/**
* 批量已读
*
* @param ids 消息id列表
*/
void batchRead(List<Long> ids);
/**
* 全部已读
*
* @param userId 用户id
* @param contentType 消息类型300快递员端公告301寄件相关消息302签收相关消息303快件取消消息200司机端公告201司机端系统通知
*/
void readAll(Long userId, Integer contentType);
/**
* 查询消息列表
*
* @param messageQueryDTO 消息查询对象
* @return 消息列表
*/
List<MessageDTO> queryList(MessageQueryDTO messageQueryDTO);
/**
* 根据类型查询消息数量
*
* @param messageQueryDTO 消息查询对象
* @return 消息条数
*/
Integer countType(MessageQueryDTO messageQueryDTO);
/**
* 最新消息查询
*
* @param messageQueryDTO 消息查询对象
* @return 最新消息对象
*/
LatestMessageDTO latestMessage(MessageQueryDTO messageQueryDTO);
/**
* 分页查询消息列表
*
* @param messageQueryDTO 消息查询对象
* @return 分页数据
*/
PageResponse<MessageDTO> pageQuery(MessageQueryDTO messageQueryDTO);
}

View File

@@ -0,0 +1,11 @@
package com.sl.ms.base.service.base;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.base.WorkHistorySchedulingEntity;
/**
* 历史排班服务
*/
public interface WorkHistorySchedulingService extends IService<WorkHistorySchedulingEntity> {
}

View File

@@ -0,0 +1,51 @@
package com.sl.ms.base.service.base;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.base.WorkPatternAddDTO;
import com.sl.ms.base.domain.base.WorkPatternDTO;
import com.sl.ms.base.domain.base.WorkPatternQueryDTO;
import com.sl.ms.base.domain.base.WorkPatternUpdateDTO;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import com.sl.transport.common.util.PageResponse;
import java.util.List;
/**
* 工作模式服务
*/
public interface WorkPatternService extends IService<WorkPatternEntity> {
/**
* 分页查询工作模式
* @param workPatternQueryDTO 查询条件
* @return 工作模式数据
*/
PageResponse<WorkPatternDTO> page(WorkPatternQueryDTO workPatternQueryDTO);
/**
* 工作模式ID查询
* @param id 工作模式ID
* @return 工作模式
*/
WorkPatternDTO findById(Long id);
/**
* 删除工作模式
* @param id 工作模式ID
*/
void delete(long id);
/**
* 更新工作模式
* @param workPatternUpdateDTO 工作模式
*/
void update(WorkPatternUpdateDTO workPatternUpdateDTO);
/**
* 新增工作模式
* @param workPatternAddDTO 工作模式
*/
void add(WorkPatternAddDTO workPatternAddDTO);
List<WorkPatternDTO> all();
}

View File

@@ -0,0 +1,90 @@
package com.sl.ms.base.service.base;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.base.WorkSchedulingAddDTO;
import com.sl.ms.base.domain.base.WorkSchedulingDTO;
import com.sl.ms.base.domain.base.WorkSchedulingQueryDTO;
import com.sl.ms.base.domain.base.WorkSchedulingUpdateDTO;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.transport.common.util.PageResponse;
import java.time.LocalDateTime;
import java.util.List;
/**
* 排班服务
*/
public interface WorkSchedulingService extends IService<WorkSchedulingEntity> {
/**
* 分页查询排班
* @param workSchedulingQueryDTO 查询条件
* @return 排班
*/
PageResponse<WorkSchedulingDTO> queryForPage(WorkSchedulingQueryDTO workSchedulingQueryDTO);
/**
* 新增排班
* @param workSchedulingAddDTO 排班
*/
void add(WorkSchedulingAddDTO workSchedulingAddDTO);
/**
* 删除排班
* @param id 排班ID
* @param operator 操作人
*/
void delete(Long id, Long operator);
/**
* 批量新增排班
* @param workSchedulingAddDTOList 排班列表
*/
void batchAdd(List<WorkSchedulingAddDTO> workSchedulingAddDTOList);
/**
* 更新排班
* @param workSchedulingUpdateDTO 排班
*/
void update(WorkSchedulingUpdateDTO workSchedulingUpdateDTO);
/**
* 根据用户id查询这个月排班计划
* @param userId 用户ID
* @return 这个月排班计划
*/
WorkSchedulingDTO currentSchedule(Long userId);
/**
* 根据用户id查询
* @param userId 用户ID
* @return 排班数据
*/
WorkSchedulingEntity getByUserId(Long userId);
/**
* 根据网点id查询该网点所有员工的排班信息
* @param agencyId 机构ID
* @return 该网点所有员工的排班信息
*/
List<WorkSchedulingDTO> monthScheduleByAgencyId(Long agencyId);
/**
* 根据快递员/司机id列表或网点id查询当前工作排班
* @param userIds 用户ID
* @param agencyId 机构ID
* @param type 用户类型1:员工2快递员3司机
* @param time 时间
* @return 当前工作排班
*/
List<WorkSchedulingDTO> monthSchedule(List<Long> userIds, Long agencyId, Byte type, LocalDateTime time);
/**
* 获取整个计划(运输任务)期间每一天都上班的司机
* @param driverIds 司机ID列表
* @param planDepartureTime 计划发车时间
* @param planArrivalTime 计划到达时间
* @return 正常上班的司机ID列表
*/
List<Long> getWorkingDrivers(List<Long> driverIds, LocalDateTime planDepartureTime, LocalDateTime planArrivalTime);
}

View File

@@ -0,0 +1,88 @@
package com.sl.ms.base.service.base.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.domain.base.AreaDto;
import com.sl.ms.base.entity.base.AreaEntity;
import com.sl.ms.base.mapper.base.AreaMapper;
import com.sl.ms.base.service.base.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 业务实现类
* 行政区域
*/
@Slf4j
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, AreaEntity> implements AreaService {
/**
* 根据编码查询行政区域
*
* @param code 行政编码
* @return 行政区域
*/
@Override
public AreaEntity getByCode(String code) {
return baseMapper.selectOne(new LambdaQueryWrapper<AreaEntity>().eq(AreaEntity::getAreaCode, code).last(" limit 1"));
}
/**
* 根据父级id查询子级行政区域
*
* @param parentId 父级id
* @return 子级行政区域列表
*/
@Override
public List<AreaDto> findChildren(Long parentId) {
//1.构造查询条件
LambdaQueryWrapper<AreaEntity> queryWrapper = Wrappers.<AreaEntity>lambdaQuery().eq(AreaEntity::getParentId, parentId);
//2.查询子级区域
List<AreaEntity> entities = baseMapper.selectList(queryWrapper);
//3.过滤掉不符合条件的数据(业务要求不要 市辖区 的行政区域信息)
return entities.stream().map(area -> {
if (area.getLevel().equals(2) && "市辖区".equals(area.getName())) {
return null;
}
AreaDto areaDto = BeanUtil.toBean(area, AreaDto.class);
areaDto.setName(areaDto.getShortName());
return areaDto;
}).filter(Objects::nonNull).collect(Collectors.toList());
}
/**
* 根据id批量查询
*
* @param ids id列表
* @return 行政区域列表
*/
@Override
public List<AreaDto> findBatch(List<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return new ArrayList<>();
}
//1.构造查询条件
LambdaQueryWrapper<AreaEntity> queryWrapper = Wrappers.<AreaEntity>lambdaQuery().in(AreaEntity::getId, ids);
//2.查询行政区域列表
List<AreaEntity> entities = baseMapper.selectList(queryWrapper);
//3.封装数据
return entities.stream().map(area -> {
AreaDto areaDto = BeanUtil.toBean(area, AreaDto.class);
areaDto.setName(areaDto.getShortName());
return areaDto;
}).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,68 @@
package com.sl.ms.base.service.base.impl;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.itheima.auth.factory.AuthTemplateFactory;
import com.itheima.auth.sdk.AuthTemplate;
import com.itheima.auth.sdk.common.Result;
import com.itheima.auth.sdk.dto.LoginDTO;
import com.itheima.auth.sdk.dto.UserDTO;
import com.sl.ms.base.service.base.AuthService;
import com.sl.transport.common.exception.SLException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* 权限系统对接服务实现
*/
@Slf4j
@Service
public class AuthServiceImpl implements AuthService {
@Value("${sl.auth.account}")
private String account;
@Value("${sl.auth.password}")
private String password;
@Resource
private AuthTemplate authTemplate;
@Resource
private StringRedisTemplate stringRedisTemplate;
/**
* 根据用户id获得详细信息
*
* @param id 用户id
* @return 用户信息
*/
@Override
public UserDTO getByUserId(Long id) {
//从redis查询token
String redisKey = "AUTHORIZATION";
String token = stringRedisTemplate.opsForValue().get(redisKey);
//如果token不存在则重新登录
if (ObjectUtil.isEmpty(token)) {
Result<LoginDTO> loginDTO = authTemplate.opsForLogin().token(account, password);
if (ObjectUtil.notEqual(loginDTO.getCode(), 0)) {
String errorMsg = CharSequenceUtil.format("登录失败,账号:{},密码:{}", account, password);
throw new SLException(errorMsg);
}
//token存入redis
token = loginDTO.getData().getToken().getToken();
stringRedisTemplate.opsForValue().set(redisKey, token, 1, TimeUnit.HOURS);
log.info("登录结果:{}", JSONUtil.toJsonStr(loginDTO));
}
//根据id查询用户信息
authTemplate = AuthTemplateFactory.get(token);
Result<UserDTO> result = authTemplate.opsForUser().getUserById(id);
return result.getData();
}
}

View File

@@ -0,0 +1,64 @@
package com.sl.ms.base.service.base.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.entity.base.GoodsTypeEntity;
import com.sl.ms.base.mapper.base.GoodsTypeMapper;
import com.sl.ms.base.service.base.GoodsTypeService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 货物类型相关业务
*/
@Service
public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeMapper, GoodsTypeEntity> implements GoodsTypeService {
/**
* 获取分页货物类型数据,如果传入 货物类型名称 或 车辆id 时进行条件搜索
*
* @param page 页码
* @param pageSize 页尺寸
* @param goodsTypeName 货物类型名称(非必须)
* @param truckTypeId 车辆id非必须
* @return 分页货物数据
*/
@Override
public IPage<GoodsTypeEntity> findByPage(Integer page, Integer pageSize, String goodsTypeName, Long truckTypeId) {
Page<GoodsTypeEntity> iPage = new Page<>(page, pageSize);
iPage.setRecords(baseMapper.findByPage(iPage, goodsTypeName, truckTypeId));
return iPage;
}
/**
* 根据id列表获取货物类型列表
*
* @param ids 货物类型id
* @return 货物类型列表
*/
@Override
public List<GoodsTypeEntity> findAll(List<Long> ids) {
LambdaQueryWrapper<GoodsTypeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (CollUtil.isNotEmpty(ids)) {
lambdaQueryWrapper.in(GoodsTypeEntity::getId, ids);
}
lambdaQueryWrapper.eq(GoodsTypeEntity::getStatus, 1);
return super.list(lambdaQueryWrapper);
}
/**
* 查询所有状态可用的货物类型列表
*
* @return 货物类型列表
*/
@Override
public List<GoodsTypeEntity> findAll() {
LambdaQueryWrapper<GoodsTypeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(GoodsTypeEntity::getStatus, 1);
return super.list(lambdaQueryWrapper);
}
}

View File

@@ -0,0 +1,227 @@
package com.sl.ms.base.service.base.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.domain.base.LatestMessageDTO;
import com.sl.ms.base.domain.base.MessageAddDTO;
import com.sl.ms.base.domain.base.MessageDTO;
import com.sl.ms.base.domain.base.MessageQueryDTO;
import com.sl.ms.base.domain.constants.MessageConstants;
import com.sl.ms.base.entity.base.MessageEntity;
import com.sl.ms.base.mapper.base.MessageMapper;
import com.sl.ms.base.service.base.MessageService;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.util.PageResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 消息相关业务
*/
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, MessageEntity> implements MessageService {
/**
* 新增消息
*
* @param messageAddDTO 消息新增对象
*/
@Override
public void add(MessageAddDTO messageAddDTO) {
MessageEntity entity = BeanUtil.toBean(messageAddDTO, MessageEntity.class);
entity.setIsRead(MessageConstants.UNREAD);
entity.setIsDelete(MessageConstants.NOT_DELETED);
this.save(entity);
}
/**
* 标记已读
*
* @param id 消息id
*/
@Override
@Transactional(rollbackFor = {SLException.class, Exception.class})
public void update2Read(Long id) {
//根据id查询消息是否存在
MessageEntity entity = this.getById(id);
if (entity == null) {
throw new SLException("消息不存在");
}
//更新消息已读状态、读时间、更新时间字段
LambdaUpdateWrapper<MessageEntity> updateWrapper = Wrappers.<MessageEntity>lambdaUpdate()
.eq(MessageEntity::getId, id)
.set(MessageEntity::getIsRead, MessageConstants.IS_READ)
.set(MessageEntity::getReadTime, LocalDateTime.now());
this.update(updateWrapper);
}
/**
* 批量已读
*
* @param ids 消息id列表
*/
@Override
public void batchRead(List<Long> ids) {
//id列表为空则不操作
if (CollUtil.isEmpty(ids)) {
return;
}
//根据id查询消息对象
List<MessageEntity> entities = this.listByIds(ids);
//更新消息已读状态和已读时间
entities.forEach(message -> {
message.setIsRead(MessageConstants.IS_READ);
message.setReadTime(LocalDateTime.now());
});
//批量更新
this.updateBatchById(entities);
}
/**
* 全部已读
*
* @param userId 用户id
* @param contentType 消息类型300快递员端公告301寄件相关消息302签收相关消息303快件取消消息200司机端公告201司机端系统通知
*/
@Override
public void readAll(Long userId, Integer contentType) {
//条件查询未读消息
LambdaQueryWrapper<MessageEntity> queryWrapper = Wrappers.<MessageEntity>lambdaQuery()
.eq(ObjectUtil.isNotEmpty(userId), MessageEntity::getUserId, userId)
.eq(ObjectUtil.isNotEmpty(contentType), MessageEntity::getContentType, contentType)
.eq(MessageEntity::getIsRead, MessageConstants.UNREAD);
List<MessageEntity> entities = this.list(queryWrapper);
if (CollUtil.isEmpty(entities)) {
return;
}
//更新消息已读状态、读时间、更新时间字段
entities.forEach(message -> {
message.setIsRead(MessageConstants.IS_READ);
message.setReadTime(LocalDateTime.now());
});
//批量更新
this.updateBatchById(entities);
}
/**
* 查询消息列表
*
* @param messageQueryDTO 消息查询对象
* @return 消息列表
*/
@Override
public List<MessageDTO> queryList(MessageQueryDTO messageQueryDTO) {
//根据功能端、消息类型、用户id、创建时间构造查询条件
LambdaQueryWrapper<MessageEntity> queryWrapper = Wrappers.<MessageEntity>lambdaQuery()
.eq(MessageEntity::getBussinessType, messageQueryDTO.getBussinessType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getContentType()), MessageEntity::getContentType, messageQueryDTO.getContentType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getUserId()), MessageEntity::getUserId, messageQueryDTO.getUserId())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getIsRead()), MessageEntity::getIsRead, messageQueryDTO.getIsRead())
.eq(MessageEntity::getIsDelete, MessageConstants.NOT_DELETED)
//查询近一个月的消息列表
.ge(MessageEntity::getCreated, LocalDateTime.now().plusMonths(-1))
.orderByDesc(MessageEntity::getCreated);
//判断消息列表是否为空不为空将其转换为dto返回
List<MessageEntity> entityList = this.list(queryWrapper);
if (CollUtil.isEmpty(entityList)) {
return Collections.emptyList();
}
return entityList.stream().map(message -> BeanUtil.toBean(message, MessageDTO.class)).collect(Collectors.toList());
}
/**
* 根据类型查询消息数量
*
* @param messageQueryDTO 消息查询对象
* @return 消息条数
*/
@Override
public Integer countType(MessageQueryDTO messageQueryDTO) {
//根据功能端、消息类型、用户id、未读状态构造查询条件
LambdaQueryWrapper<MessageEntity> queryWrapper = Wrappers.<MessageEntity>lambdaQuery()
.eq(MessageEntity::getBussinessType, messageQueryDTO.getBussinessType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getContentType()), MessageEntity::getContentType, messageQueryDTO.getContentType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getUserId()), MessageEntity::getUserId, messageQueryDTO.getUserId())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getIsRead()), MessageEntity::getIsRead, messageQueryDTO.getIsRead());
//消息计数
return (int) this.count(queryWrapper);
}
/**
* 最新消息查询
*
* @param messageQueryDTO 消息查询对象
* @return 最新消息对象
*/
@Override
public LatestMessageDTO latestMessage(MessageQueryDTO messageQueryDTO) {
//根据功能端、消息类型、用户id构造查询条件
LambdaQueryWrapper<MessageEntity> queryWrapper = Wrappers.<MessageEntity>lambdaQuery()
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getBussinessType()), MessageEntity::getBussinessType, messageQueryDTO.getBussinessType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getContentType()), MessageEntity::getContentType, messageQueryDTO.getContentType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getUserId()), MessageEntity::getUserId, messageQueryDTO.getUserId())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getIsRead()), MessageEntity::getIsRead, messageQueryDTO.getIsRead())
.orderByDesc(MessageEntity::getCreated)
.last("LIMIT 1");
//查询出最近一条消息
MessageEntity messageEntity = this.getOne(queryWrapper);
if (ObjectUtil.isEmpty(messageEntity)) {
return null;
}
//entity转为dto
return BeanUtil.toBean(messageEntity, LatestMessageDTO.class);
}
/**
* 分页查询消息列表
*
* @param messageQueryDTO 消息查询对象
* @return 分页数据
*/
@Override
public PageResponse<MessageDTO> pageQuery(MessageQueryDTO messageQueryDTO) {
//根据功能端、消息类型、用户id、创建时间构造查询条件
Page<MessageEntity> iPage = new Page<>(messageQueryDTO.getPage(), messageQueryDTO.getPageSize());
LambdaQueryWrapper<MessageEntity> queryWrapper = Wrappers.<MessageEntity>lambdaQuery()
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getBussinessType()), MessageEntity::getBussinessType, messageQueryDTO.getBussinessType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getContentType()), MessageEntity::getContentType, messageQueryDTO.getContentType())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getUserId()), MessageEntity::getUserId, messageQueryDTO.getUserId())
.eq(ObjectUtil.isNotEmpty(messageQueryDTO.getIsRead()), MessageEntity::getIsRead, messageQueryDTO.getIsRead())
//查询近一个月的消息列表
.ge(MessageEntity::getCreated, LocalDateTime.now().plusMonths(-1))
.eq(MessageEntity::getIsDelete, MessageConstants.NOT_DELETED)
.orderByDesc(MessageEntity::getCreated);
//分页查询
Page<MessageEntity> pageResult = this.page(iPage, queryWrapper);
if (ObjectUtil.isEmpty(pageResult.getRecords())) {
return new PageResponse<>(pageResult);
}
//封装分页数据
return new PageResponse<>(pageResult, MessageDTO.class);
}
}

View File

@@ -0,0 +1,12 @@
package com.sl.ms.base.service.base.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.entity.base.WorkHistorySchedulingEntity;
import com.sl.ms.base.mapper.base.WorkHistorySchedulingMapper;
import com.sl.ms.base.service.base.WorkHistorySchedulingService;
import org.springframework.stereotype.Service;
@Service
public class WorkHistorySchedulingServiceImpl extends ServiceImpl<WorkHistorySchedulingMapper, WorkHistorySchedulingEntity> implements WorkHistorySchedulingService {
}

View File

@@ -0,0 +1,157 @@
package com.sl.ms.base.service.base.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.constant.WorkConstants;
import com.sl.ms.base.domain.base.WorkPatternAddDTO;
import com.sl.ms.base.domain.base.WorkPatternDTO;
import com.sl.ms.base.domain.base.WorkPatternQueryDTO;
import com.sl.ms.base.domain.base.WorkPatternUpdateDTO;
import com.sl.ms.base.domain.enums.WorkPatternEnum;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.ms.base.mapper.base.WorkPatternMapper;
import com.sl.ms.base.service.base.WorkPatternService;
import com.sl.ms.base.service.base.WorkSchedulingService;
import com.sl.ms.base.utils.WorkPatternUtils;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.util.BeanUtil;
import com.sl.transport.common.util.PageResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* 工作模式服务
*/
@Slf4j
@Service
public class WorkPatternServiceImpl extends ServiceImpl<WorkPatternMapper, WorkPatternEntity> implements WorkPatternService {
@Resource
private WorkSchedulingService workSchedulingService;
/**
* 分页查询工作模式
*
* @param workPatternQueryDTO 查询条件
* @return 工作模式数据
*/
@Override
public PageResponse<WorkPatternDTO> page(WorkPatternQueryDTO workPatternQueryDTO) {
WorkPatternMapper workPatternMapper = getBaseMapper();
LambdaQueryWrapper<WorkPatternEntity> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(WorkPatternEntity::getIsDelete, 0);
queryWrapper.orderByDesc(WorkPatternEntity::getCreated);
Page<WorkPatternEntity> page = new Page<>(workPatternQueryDTO.getPage(), workPatternQueryDTO.getPageSize());
IPage<WorkPatternEntity> iPage = workPatternMapper.selectPage(page, queryWrapper);
return PageResponse.of(iPage, WorkPatternDTO.class, (entity, workPatternDTO) -> {
workPatternDTO.setWorkDate(WorkPatternUtils.toWorkDate(entity));
workPatternDTO.setWorkPatternTypeDesc(WorkPatternEnum.desc(entity.getWorkPatternType()));
});
}
/**
* 工作模式ID查询
*
* @param id 工作模式ID
* @return 工作模式
*/
@Override
public WorkPatternDTO findById(Long id) {
WorkPatternEntity workPatternEntity = getBaseMapper().selectById(id);
return BeanUtil.toBean(workPatternEntity, WorkPatternDTO.class, (entity, workPatternDTO) -> {
workPatternDTO.setWorkDate(WorkPatternUtils.toWorkDate(entity));
workPatternDTO.setWorkPatternTypeDesc(WorkPatternEnum.desc(entity.getWorkPatternType()));
});
}
/**
* 删除工作模式
*
* @param id 工作模式ID
*/
@Override
@Transactional(rollbackFor = {SLException.class, Exception.class})
public void delete(long id) {
// 删除限制
long count = workSchedulingService.count(Wrappers.<WorkSchedulingEntity>lambdaQuery().eq(WorkSchedulingEntity::getWorkPatternId, id));
if (count > 0) {
throw new SLException("改工作模式下有排班,请先把排班修改为其他工作模式后删除");
}
int number = getBaseMapper().deleteById(id);
if (number <= 0) {
throw new SLException("工作模式删除失败");
}
}
/**
* 更新工作模式
*
* @param workPatternUpdateDTO 工作模式
*/
@Override
@Transactional(rollbackFor = {SLException.class, Exception.class})
public void update(WorkPatternUpdateDTO workPatternUpdateDTO) {
WorkPatternMapper workPatternMapper = getBaseMapper();
WorkPatternEntity workPatternEntity = BeanUtil.toBean(workPatternUpdateDTO, WorkPatternEntity.class, (origin, entity) -> {
entity.setName(origin.getName());
entity.setUpdated(LocalDateTime.now());
entity.setStatus(WorkConstants.WorkStatus.STOP);
});
int result = workPatternMapper.updateById(workPatternEntity);
if (result <= 0) {
throw new SLException("工作模式更新失败");
}
}
/**
* 新增工作模式
*
* @param workPatternAddDTO 工作模式
*/
@Override
@Transactional(rollbackFor = {SLException.class, Exception.class})
public void add(WorkPatternAddDTO workPatternAddDTO) {
WorkPatternEntity workPatternEntity = BeanUtil.toBean(workPatternAddDTO, WorkPatternEntity.class, (dto, entity) -> {
entity.setId(IdWorker.getId());
entity.setCreater(dto.getOperator());
entity.setUpdater(dto.getOperator());
entity.setCreated(LocalDateTime.now());
entity.setUpdated(LocalDateTime.now());
entity.setStatus(WorkConstants.WorkStatus.USING);
});
BeanUtil.setDefault(workPatternEntity);
int result = getBaseMapper().insert(workPatternEntity);
if (result <= 0) {
throw new SLException("工作模式新增失败");
}
}
@Override
public List<WorkPatternDTO> all() {
return list(
Wrappers.<WorkPatternEntity>lambdaQuery()
.eq(WorkPatternEntity::getIsDelete, 0))
.stream()
.map(v -> BeanUtil.toBean(v, WorkPatternDTO.class))
.collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,443 @@
package com.sl.ms.base.service.base.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SimpleQuery;
import com.google.common.collect.Lists;
import com.sl.ms.base.domain.base.WorkSchedulingAddDTO;
import com.sl.ms.base.domain.base.WorkSchedulingDTO;
import com.sl.ms.base.domain.base.WorkSchedulingQueryDTO;
import com.sl.ms.base.domain.base.WorkSchedulingUpdateDTO;
import com.sl.ms.base.domain.enums.WorkPatternEnum;
import com.sl.ms.base.domain.enums.WorkStatusEnum;
import com.sl.ms.base.domain.enums.WorkUserTypeEnum;
import com.sl.ms.base.entity.base.WorkHistorySchedulingEntity;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.mapper.base.WorkHistorySchedulingMapper;
import com.sl.ms.base.mapper.base.WorkSchedulingMapper;
import com.sl.ms.base.service.base.WorkPatternService;
import com.sl.ms.base.service.base.WorkSchedulingService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.ms.base.utils.WorkSchedulingUtils;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.util.BeanUtil;
import com.sl.transport.common.util.DateUtils;
import com.sl.transport.common.util.PageResponse;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* 排班服务
*/
@Service
public class WorkSchedulingServiceImpl extends ServiceImpl<WorkSchedulingMapper, WorkSchedulingEntity> implements WorkSchedulingService {
@Resource
private WorkHistorySchedulingMapper workHistorySchedulingMapper;
@Resource
private WorkPatternService workPatternService;
@Resource
private TruckDriverService truckDriverService;
/**
* 分页查询排班
*
* @param workSchedulingQueryDTO 查询条件
* @return 排班
*/
@Override
public PageResponse<WorkSchedulingDTO> queryForPage(WorkSchedulingQueryDTO workSchedulingQueryDTO) {
//查询月份
final String queryMonth = StringUtils.isEmpty(workSchedulingQueryDTO.getMonth()) ?
LocalDateTimeUtil.format(LocalDateTimeUtil.now(), DateUtils.DEFAULT_MONTH_FORMAT) :
workSchedulingQueryDTO.getMonth();
boolean isQueryHistory = WorkSchedulingUtils.isQueryHistory(queryMonth); //是否查询历史数据
//查询排班记录
LambdaQueryWrapper<WorkSchedulingEntity> queryWrapper = Wrappers.lambdaQuery();
// 增加查询条件
queryWrapper
.eq(WorkSchedulingEntity::getIsDelete, 0)
.eq(ObjectUtil.isNotEmpty(workSchedulingQueryDTO.getUserType()), WorkSchedulingEntity::getUserType, workSchedulingQueryDTO.getUserType())
.like(ObjectUtil.isNotEmpty(workSchedulingQueryDTO.getName()), WorkSchedulingEntity::getName, workSchedulingQueryDTO.getName())
.like(ObjectUtil.isNotEmpty(workSchedulingQueryDTO.getEmployeeNumber()), WorkSchedulingEntity::getEmployeeNumber, workSchedulingQueryDTO.getEmployeeNumber())
.like(ObjectUtil.isNotEmpty(workSchedulingQueryDTO.getAgencyId()), WorkSchedulingEntity::getAgencyId, workSchedulingQueryDTO.getAgencyId())
.eq(ObjectUtil.isNotEmpty(workSchedulingQueryDTO.getWorkPatternId()), WorkSchedulingEntity::getWorkPatternId, workSchedulingQueryDTO.getWorkPatternId())
.orderByDesc(WorkSchedulingEntity::getCreated);
Page<WorkSchedulingEntity> entityPage = getBaseMapper().selectPage
(new Page<>(workSchedulingQueryDTO.getPage(),
workSchedulingQueryDTO.getPageSize()), queryWrapper);
int dayNumOfQueryMonth = DateUtils.getMonthEndTime(queryMonth).getDayOfMonth();
final Map<String, String> historyMap = new HashMap<>();
List<WorkSchedulingEntity> records = entityPage.getRecords();
if (CollUtil.isEmpty(records)) { //有数据
return PageResponse.of(entityPage, WorkSchedulingDTO.class);
}
if (isQueryHistory) { //查询历史数据
List<Long> userIdList = records.stream().map(WorkSchedulingEntity::getUserId).collect(Collectors.toList());
List<WorkHistorySchedulingEntity> historyEntity = workHistorySchedulingMapper.selectList(
Wrappers.<WorkHistorySchedulingEntity>lambdaQuery()
.eq(WorkHistorySchedulingEntity::getWorkMonth, queryMonth)
.in(WorkHistorySchedulingEntity::getUserId, userIdList)
.between(WorkHistorySchedulingEntity::getWorkDay, 0, dayNumOfQueryMonth)
);
if (CollUtil.isNotEmpty(historyEntity)) {
historyEntity.parallelStream().forEach(entity -> historyMap.put(entity.getUserId() + "" + entity.getWorkDay(), ""));
}
}
// 补充工作模式名称
Map<Long, WorkPatternEntity> patternByIds = getPatternByIds(records);
return PageResponse.of(entityPage, WorkSchedulingDTO.class, (entity, dto) -> {
List<Boolean> workSchedules = new ArrayList<>();
for (int count = 1; count <= dayNumOfQueryMonth; count++) {
workSchedules.add(WorkSchedulingUtils.isWorded(entity, queryMonth, count, patternByIds.get(entity.getWorkPatternId()), historyMap, false));
}
dto.setWorkSchedules(workSchedules);
appenWorkPatten(dto, patternByIds);
});
}
/**
* 新增排班
*
* @param workSchedulingAddDTO 排班
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void add(WorkSchedulingAddDTO workSchedulingAddDTO) {
WorkSchedulingEntity workSchedulingEntity = BeanUtil.toBean(workSchedulingAddDTO, WorkSchedulingEntity.class, (dto, entity) -> {
entity.setId(IdWorker.getId());
entity.setCreater(dto.getOperator());
entity.setUpdater(dto.getOperator());
entity.setCreated(LocalDateTime.now());
entity.setUpdated(LocalDateTime.now());
});
int insert = getBaseMapper().insert(workSchedulingEntity);
if (insert <= 0) {
throw new SLException("新增工作品排班失败");
}
}
/**
* 删除排班
*
* @param id 排班ID
* @param operator 操作人
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id, Long operator) {
WorkSchedulingEntity entity = new WorkSchedulingEntity();
entity.setId(id);
entity.setIsDelete(true);
entity.setUpdater(operator);
if (getBaseMapper().updateById(entity) <= 0) {
throw new SLException("删除操作失败");
}
}
/**
* 批量新增排班
*
* @param workSchedulingAddDTOList 排班列表
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void batchAdd(List<WorkSchedulingAddDTO> workSchedulingAddDTOList) {
if (CollUtil.isEmpty(workSchedulingAddDTOList)) {
return;
}
List<WorkSchedulingEntity> batchAddEntityList = new ArrayList<>();
for (int count = 0; count < workSchedulingAddDTOList.size(); count++) {
WorkSchedulingEntity workSchedulingEntity = BeanUtil.toBean(workSchedulingAddDTOList.get(count), WorkSchedulingEntity.class, (dto, entity) -> {
entity.setId(IdWorker.getId());
entity.setCreater(dto.getOperator());
entity.setUpdater(dto.getOperator());
entity.setCreated(LocalDateTime.now());
entity.setUpdated(LocalDateTime.now());
entity.setUserId(Long.parseLong(entity.getEmployeeNumber()));
entity.setState(WorkStatusEnum.NOMAL.getStatus());
if (dto.getWorkPatternType() == WorkPatternEnum.Continuitys.getType()) {
entity.setWorkContinueStartTime(DateUtils.getStartTime(LocalDateTime.now()));
}
//设置默认值
BeanUtil.setDefault(entity);
});
batchAddEntityList.add(workSchedulingEntity);
if (batchAddEntityList.size() % 500 == 0 || count == workSchedulingAddDTOList.size() - 1) {
getBaseMapper().batchInsert(batchAddEntityList);
}
}
// 导入排班时候 可能司机表里还没有数据
workSchedulingAddDTOList.parallelStream().forEach(v -> {
if (ObjectUtil.notEqual(v.getUserType(), WorkUserTypeEnum.DRIVER.getCode())) {
return;
}
TruckDriverEntity one = truckDriverService.findOne(v.getUserId());
if (ObjectUtil.isEmpty(one)) {
TruckDriverEntity truckDriverEntity = new TruckDriverEntity();
truckDriverEntity.setUserId(v.getUserId());
truckDriverService.save(truckDriverEntity);
}
});
}
/**
* 更新排班
*
* @param workSchedulingUpdateDTO 排班
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void update(WorkSchedulingUpdateDTO workSchedulingUpdateDTO) {
WorkSchedulingMapper workSchedulingMapper = getBaseMapper();
WorkSchedulingEntity entityInDb = workSchedulingMapper.selectById(workSchedulingUpdateDTO.getId());
if (entityInDb == null) {
throw new SLException("无法进行更新");
}
WorkSchedulingEntity workSchedulingEntity = BeanUtil.toBean(workSchedulingUpdateDTO, WorkSchedulingEntity.class, (dto, entity) -> {
entity.setUpdated(LocalDateTime.now());
entity.setUpdater(dto.getOperator());
//如果以前是礼拜制 或者以前无排班,修改连续制,连续制的开始时间为操作当日的开始时间
WorkPatternEntity workPatternEntity = workPatternService.getById(entityInDb.getWorkPatternId());
if (workSchedulingUpdateDTO.getWorkPatternType() == WorkPatternEnum.Continuitys.getType()
&& (ObjectUtil.isEmpty(workPatternEntity) || workPatternEntity.getWorkPatternType() != WorkPatternEnum.Continuitys.getType())) {
entity.setWorkContinueStartTime(DateUtils.getStartTime(LocalDateTime.now()));
}
});
int result = workSchedulingMapper.updateById(workSchedulingEntity);
if (result <= 0) {
throw new SLException("更新操作失败");
}
}
/**
* 根据用户id查询这个月排班计划
*
* @param userId 用户ID
* @return 未来一周排班计划
*/
@Override
public WorkSchedulingDTO currentSchedule(Long userId) {
List<WorkSchedulingEntity> entities = getBaseMapper().
selectByMap(Map.of("user_id", userId, "is_delete", 0));
List<WorkSchedulingDTO> workSchedulingDTOS = getWorkSchedulingDTOS(entities, null);
if (CollUtil.isEmpty(workSchedulingDTOS)) {
return null;
}
return workSchedulingDTOS.get(0);
}
/**
* 根据用户id查询
*
* @param userId 用户ID
* @return 排班数据
*/
@Override
public WorkSchedulingEntity getByUserId(Long userId) {
List<WorkSchedulingEntity> entities = getBaseMapper().
selectByMap(Map.of("user_id", userId, "is_delete", 0));
if (CollUtil.isNotEmpty(entities)) {
return entities.get(0);
}
return null;
}
/**
* 根据网点id查询该网点所有员工的排班信息
*
* @param agencyId 机构ID
* @return 今天工作人员排班
*/
@Override
public List<WorkSchedulingDTO> monthScheduleByAgencyId(Long agencyId) {
List<WorkSchedulingEntity> entities = getBaseMapper().
selectByMap(Map.of("agency_id", agencyId, "is_delete", 0));
return getWorkSchedulingDTOS(entities, null);
}
/**
* 补充工作模式
*
* @param entities 排班信息
* @param time 时间
* @return 排班信息
*/
@Nullable
private List<WorkSchedulingDTO> getWorkSchedulingDTOS(List<WorkSchedulingEntity> entities, LocalDateTime time) {
Map<Long, WorkPatternEntity> patternByIds = getPatternByIds(entities);
if (CollUtil.isNotEmpty(entities)) {
return entities.stream().map(entity -> {
WorkSchedulingDTO parse = parse(entity, time);
return appenWorkPatten(parse, patternByIds);
}).collect(Collectors.toList());
}
return null;
}
/**
* 根据快递员/司机id列表或网点id查询当前工作排班
*
* @param userIds 用户ID
* @param agencyId 机构ID
* @param type 用户类型1:员工2快递员3司机
* @param time 时间
* @return 当前工作排班
*/
@Override
public List<WorkSchedulingDTO> monthSchedule(List<Long> userIds, Long agencyId, Byte type, LocalDateTime time) {
if (CollUtil.isEmpty(userIds) && agencyId == null) {
return Collections.emptyList();
}
LambdaQueryWrapper<WorkSchedulingEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.in(CollUtil.isNotEmpty(userIds), WorkSchedulingEntity::getUserId, userIds)
.eq(ObjectUtil.isNotEmpty(agencyId), WorkSchedulingEntity::getAgencyId, agencyId)
.eq(WorkSchedulingEntity::getUserType, type);
List<WorkSchedulingEntity> entities = getBaseMapper().selectList(queryWrapper);
return getWorkSchedulingDTOS(entities, time);
}
/**
* 补充工作模式信息
*
* @param workSchedulingDTO dto
* @param workPatternEntityMap 工作模型map
* @return 工作模式
*/
private WorkSchedulingDTO appenWorkPatten(WorkSchedulingDTO workSchedulingDTO, Map<Long, WorkPatternEntity> workPatternEntityMap) {
if (CollUtil.isNotEmpty(workPatternEntityMap)) {
WorkPatternEntity workPatternEntity = workPatternEntityMap.get(workSchedulingDTO.getWorkPatternId());
if (ObjectUtil.isNotEmpty(workPatternEntity)) {
workSchedulingDTO.setWorkStartMinute1(workPatternEntity.getWorkStartMinute1());
workSchedulingDTO.setWorkEndMinute1(workPatternEntity.getWorkEndMinute1());
workSchedulingDTO.setWorkPatternName(workPatternEntity.getName());
}
}
return workSchedulingDTO;
}
/**
* 结构转换
*
* @param entity 数据实体
* @param time 未来的某个时间
* @return 工作模式dto
*/
private WorkSchedulingDTO parse(WorkSchedulingEntity entity, LocalDateTime time) {
Map<Long, WorkPatternEntity> patternByIds = getPatternByIds(Lists.newArrayList(entity));
return BeanUtil.toBean(entity, WorkSchedulingDTO.class, (workSchedulingEntity, workSchedulingDTO) -> {
//暂未排班的情况设置为空
if (workSchedulingEntity.getWorkPatternId() == 0) {
workSchedulingDTO.setWorkSchedules(null);
} else {
LocalDateTime startTime = ObjectUtil.isEmpty(time) ? LocalDateTime.now() : time;
int currentDay = startTime.getDayOfMonth();
int monthNumber = DateUtils.getMonthNumber(startTime);
List<Boolean> workList = new ArrayList<>();
for (int count = currentDay; count <= monthNumber; count++) {
boolean worded = WorkSchedulingUtils.isWorded(entity, LocalDateTimeUtil.format(startTime, DateUtils.DEFAULT_MONTH_FORMAT),
count, patternByIds.get(workSchedulingEntity.getWorkPatternId()), null, false);
workList.add(worded);
}
workSchedulingDTO.setWorkSchedules(workList);
}
});
}
/**
* 获取工作模式信息
*
* @param records 排班
* @return 工作模式
*/
private Map<Long, WorkPatternEntity> getPatternByIds(List<WorkSchedulingEntity> records) {
if (CollUtil.isEmpty(records)) {
return new HashMap<>();
}
// 补充工作模式名称
List<Long> workPatternIds = records.stream().map(WorkSchedulingEntity::getWorkPatternId).collect(Collectors.toList());
return SimpleQuery.keyMap(
Wrappers.<WorkPatternEntity>lambdaQuery().in(WorkPatternEntity::getId, workPatternIds),
WorkPatternEntity::getId);
}
/**
* 获取整个计划(运输任务)期间每一天都上班的司机
*
* @param driverIds 司机ID列表
* @param planDepartureTime 计划发车时间
* @param planArrivalTime 计划到达时间
* @return 正常上班的司机ID列表
*/
@Override
public List<Long> getWorkingDrivers(List<Long> driverIds, LocalDateTime planDepartureTime, LocalDateTime planArrivalTime) {
// 查询排班
LambdaQueryWrapper<WorkSchedulingEntity> queryWrapper = Wrappers.<WorkSchedulingEntity>lambdaQuery()
// 司机ID
.in(WorkSchedulingEntity::getUserId, driverIds)
// 用户类型
.eq(WorkSchedulingEntity::getUserType, WorkUserTypeEnum.DRIVER.getCode());
List<WorkSchedulingEntity> list = list(queryWrapper);
Map<Long, WorkPatternEntity> patternByIds = getPatternByIds(list);
// 过滤整个计划(运输任务)期间每一天都上班的司机
List<Long> workUserIds = list.stream().filter(workSchedulingEntity -> {
// 按照一年中365天 天数从小到达遍历 比如 从2020年1月1日 到2020年1月5日
for (LocalDateTime count = planDepartureTime; count.isBefore(planArrivalTime); count = count.plusDays(1)) {
// 转换为一个月的第几天 比如 2020年1月1日 转为月中的个数为 1
int dayOfMonth = count.getDayOfMonth();
String month = LocalDateTimeUtil.format(count, DateUtils.DEFAULT_MONTH_FORMAT);
// 计算这一天的排班情况
boolean worded = WorkSchedulingUtils.isWorded(workSchedulingEntity, month, dayOfMonth, patternByIds.get(workSchedulingEntity.getWorkPatternId()), null, false);
// 如果有不上班的天 那这次计划就不应该包含这位司机
if (!worded) {
return false;
}
}
// 整个计划(运输任务)期间每一天都上班的司机
return true;
}).map(WorkSchedulingEntity::getUserId).collect(Collectors.toList());
if (workUserIds.size() <= 2) {
return workUserIds;
}
return workUserIds.subList(0, 2);
}
}

View File

@@ -0,0 +1,50 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import java.util.List;
/**
* <p>
* 车次与车辆关联信息表 服务类
* </p>
*
* @author itcast
* @since 2019-12-20
*/
public interface TransportTripsTruckDriverService extends IService<TransportTripsTruckDriverEntity> {
/**
* 批量保存车次与车辆关联信息
* @param truckTransportTripsId 车次ID
* @param truckTransportTrips 车次与车辆关联信息
*/
void batchSave(Long truckTransportTripsId, List<TransportTripsTruckDriverEntity> truckTransportTrips);
/**
* 获取车次与车辆关联列表
*
* @param transportTripsId 车次id
* @param truckId 车辆Id
* @param userId 司机id
* @return 车次与车辆关联列表
*/
List<TransportTripsTruckDriverEntity> findAll(Long transportTripsId, Long truckId, Long userId);
/**
* 消除绑定关系
* @param transportTripsId 车次ID
* @param truckId 车辆ID
*/
void delete(Long transportTripsId, Long truckId);
/**
* 检查是否可以删除
*
* @param transportTripsId 车次id
* @param truckId 车辆Id
* @param userId 司机id
* @return 是否可以删除
*/
Boolean canRemove(Long transportTripsId, Long truckId, Long userId);
}

View File

@@ -0,0 +1,19 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.truck.TruckLicenseEntity;
/**
* 车辆行驶证表 服务类
*/
public interface TruckLicenseService extends IService<TruckLicenseEntity> {
/**
* 保存车辆行驶证信息
*
* @param truckLicenseEntity 车辆行驶证信息
* @return 车辆行驶证信息
*/
TruckLicenseEntity saveTruckLicense(TruckLicenseEntity truckLicenseEntity);
}

View File

@@ -0,0 +1,30 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 车次计划任务 服务类
*/
public interface TruckPlanCreateService extends IService<TruckPlanEntity> {
/**
* 创建首次计划 首次关系后台新增 安排司机和车辆给车次时候触发
*
* @param truckPlanEntity 车辆计划
*/
void createPlan(TruckPlanEntity truckPlanEntity);
/**
* 异步创建下一次计划
* 前一次计划完成触发
*
* @param truckId 车辆ID
* @param driverIds 司机ID列表
* @param currentOrganId 当前位置
* @return 异步任务
*/
CompletableFuture<String> createNextPlans(Long truckId, List<Long> driverIds, Long currentOrganId);
}

View File

@@ -0,0 +1,38 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.enums.StatusEnum;
import com.sl.ms.base.domain.truck.TruckPlanDto;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import java.util.List;
import java.util.Set;
/**
* 车次计划任务 服务类
*/
public interface TruckPlanService extends IService<TruckPlanEntity> {
/**
* 获取未分配运输任务的车次计划列表
* @return 未分配运输任务的车次计划列表
* @param shardTotal 总片数
* @param shardIndex 分片
*/
List<TruckPlanDto> pullUnassignedPlan(Integer shardTotal, Integer shardIndex);
/**
* 更新计划状态为已调度 消费MQ更新调度状态
* @param planId 计划ID
*/
void scheduledPlan(Set<Long> planId);
/**
* 计划完成
* @param currentOrganId 结束机构id
* @param planId 计划ID
* @param truckId 车辆ID
* @param statusEnum 车辆状态枚举
*/
void finishedPlan(Long currentOrganId, Long planId, Long truckId, StatusEnum statusEnum);
}

View File

@@ -0,0 +1,29 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.truck.TruckReturnRegisterDTO;
import com.sl.ms.base.domain.truck.TruckReturnRegisterListDTO;
import com.sl.ms.base.domain.truck.TruckReturnRegisterPageQueryDTO;
import com.sl.ms.base.entity.truck.TruckReturnRegisterEntity;
import com.sl.transport.common.util.PageResponse;
/**
* 回车登记 服务类
*/
public interface TruckReturnRegisterService extends IService<TruckReturnRegisterEntity> {
/**
* 分页查询回车登记列表
*
* @param dto 分页查询条件
* @return 回车登记分页结果
*/
PageResponse<TruckReturnRegisterListDTO> pageQuery(TruckReturnRegisterPageQueryDTO dto);
/**
* 根据id查询回车登记详情
*
* @param id 回车登记id
* @return 回车登记详情
*/
TruckReturnRegisterDTO findById(Long id);
}

View File

@@ -0,0 +1,90 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.enums.StatusEnum;
import com.sl.ms.base.domain.enums.TruckRunStatusEnum;
import com.sl.ms.base.entity.truck.TruckEntity;
import java.util.List;
import java.util.Map;
/**
* 车辆信息表 服务类
*/
public interface TruckService extends IService<TruckEntity> {
/**
* 获取车辆分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param truckTypeId 车辆类型id
* @param status 状态
* @param licensePlate 车辆号牌
* @return 线路类型分页数据
*/
IPage<TruckEntity> findByPage(Integer page, Integer pageSize, Long truckTypeId, Integer status, String licensePlate);
/**
* 获取车辆列表
*
* @param ids 车辆id列表
* @return 车辆列表
*/
List<TruckEntity> findAll(List<Long> ids);
/**
* 禁用车辆
*
* @param id 车辆id
*/
void stopById(Long id);
/**
* 更新车辆状态
*
* @param id 车辆ID
* @param status 车辆状态
*/
void updateRunStatus(Long id, TruckRunStatusEnum status);
/**
* 更新当前位置
*
* @param truckId 车辆ID
* @param currentOrganId 当前机构ID
* @param statusEnum {@link StatusEnum}
* @return 是否成功
*/
Boolean updateCurrentOrganId(Long truckId, Long currentOrganId, StatusEnum statusEnum);
/**
* 启用车辆
*
* @param id 车辆ID
*/
void workedById(Long id);
/**
* 状态分组统计
*
* @return 统计车辆信息
*/
Map<Integer, Long> groupByStatus();
/**
* 车型数量
*
* @param typeId 车辆类型ID
* @return 该车型下的车辆数量
*/
Integer countByType(Long typeId);
/**
* 删除
*
* @param id 车辆ID
*/
void del(Long id);
}

View File

@@ -0,0 +1,38 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.truck.OrganIdsDto;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
/**
* 车次信息表 服务类
*/
public interface TruckTripsService extends IService<TruckTripsEntity> {
/**
* 获取车次列表
*
* @param transportLineId 线路id
* @param ids 车次id列表
* @return 车次列表
*/
List<TruckTripsEntity> findAll(Long transportLineId, List<Long> ids);
/**
* 删除车次
*
* @param id 车次ID
*/
void disable(Long id);
/**
* 根据线路ID查询机构
* @param values 线路ID
* @return 机构信息
*/
Map<Long, OrganIdsDto> getOrganIdsByTripsLineId(HashSet<Long> values);
}

View File

@@ -0,0 +1,29 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.truck.TruckTypeGoodsTypeEntity;
import java.util.List;
/**
* 车辆类型与货物类型关联表 服务类
*/
public interface TruckTypeGoodsTypeService extends IService<TruckTypeGoodsTypeEntity> {
/**
* 删除关联关系
*
* @param truckTypeId 车辆类型id
* @param goodsTypeId 货物类型id
*/
void delete(Long truckTypeId, Long goodsTypeId);
/**
* 获取车辆类型与货物类型关联
*
* @param truckTypeId 车辆类型id
* @param goodsTypeId 货物类型id
* @return 车辆类型与货物类型关联
*/
List<TruckTypeGoodsTypeEntity> findAll(Long truckTypeId, Long goodsTypeId);
}

View File

@@ -0,0 +1,53 @@
package com.sl.ms.base.service.truck;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.truck.TruckTypeEntity;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 车辆类型表 服务类
*/
public interface TruckTypeService extends IService<TruckTypeEntity> {
/**
* 获取车辆类型分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param name 车辆类型名称
* @param minAllowableLoad 车辆载重最小值(闭区间)
* @param maxAllowableLoad 车辆载重最大值(开区间)
* @param minAllowableVolume 车辆体积最小值(闭区间)
* @param maxAllowableVolume 车辆体积最小值(开区间)
* @param id 车型id
* @return 车辆类型分页数据
*/
IPage<TruckTypeEntity> findByPage(Integer page, Integer pageSize, String name, BigDecimal minAllowableLoad, BigDecimal maxAllowableLoad, BigDecimal minAllowableVolume, BigDecimal maxAllowableVolume, Long id);
/**
* 获取车辆类型列表
* @param ids 车辆类型ids
* @return 车辆类型列表
*/
List<TruckTypeEntity> findAll(List<Long> ids);
/**
* 删除车辆类型
*
* @param id 车型ID
*/
void disable(Long id);
/**
* 获取map类型车辆类型数据集合
*
* @param truckTypeSet 车辆类型id列表
* @return 执行结果
*/
Map<Long, TruckTypeEntity> truckTypeMap(Set<Long> truckTypeSet);
}

View File

@@ -0,0 +1,146 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.domain.enums.TruckPlanScheduleStatusEnum;
import com.sl.ms.base.domain.enums.TruckPlanStatusEnum;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.mapper.truck.TransportTripsTruckDriverMapper;
import com.sl.ms.base.service.truck.TransportTripsTruckDriverService;
import com.sl.ms.base.service.truck.TruckPlanCreateService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.transport.common.exception.SLException;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 车次与车辆关联信息表 服务实现类
*/
@Service
public class TransportTripsTruckDriverServiceImpl extends ServiceImpl<TransportTripsTruckDriverMapper, TransportTripsTruckDriverEntity>
implements TransportTripsTruckDriverService {
@Autowired
TruckDriverService truckDriverService;
@Autowired
TruckPlanCreateService truckPlanCreateService;
/**
* 批量保存车次与车辆关联信息
* @param truckTransportTripsId 车次ID
* @param truckTransportTripsTruckDriverEntityList 车次与车辆关联信息
*/
@Transactional
@Override
public void batchSave(Long truckTransportTripsId, List<TransportTripsTruckDriverEntity> truckTransportTripsTruckDriverEntityList) {
// 保存车辆和车次关联关系
// 1,清除关系
delete(truckTransportTripsId, null);
List<TransportTripsTruckDriverEntity> saveList = new ArrayList<>();
//遍历传入数据
truckTransportTripsTruckDriverEntityList.forEach(transportTripsTruckDriver -> {
List<TruckDriverEntity> driverEntities = truckDriverService.findByTruckId(transportTripsTruckDriver.getTruckId());
if (CollUtil.isEmpty(driverEntities)) {
throw new SLException(StrUtil.format("请先为该车辆绑定司机"));
}
driverEntities.forEach(truckDriverEntity -> {
TransportTripsTruckDriverEntity saveData = BeanUtil.toBean(transportTripsTruckDriver, TransportTripsTruckDriverEntity.class);
saveData.setDriverId(truckDriverEntity.getUserId());
saveData.setTransportTripsId(truckTransportTripsId);
saveList.add(saveData);
});
// 触发创建首次车辆计划
List<Long> driverIds = driverEntities.stream().map(TruckDriverEntity::getUserId).collect(Collectors.toList());
TruckPlanEntity build = TruckPlanEntity.builder()
.truckId(transportTripsTruckDriver.getTruckId())
.transportTripsId(truckTransportTripsId)
.driverIds(StrUtil.join(",", driverIds))
.status(TruckPlanStatusEnum.NORMAL.getCode())
.build();
truckPlanCreateService.createPlan(build);
});
saveBatch(saveList);
}
/**
* 获取车次与车辆关联列表
*
* @param transportTripsId 车次id
* @param truckId 车辆Id
* @param userId 司机id
* @return 车次与车辆关联列表
*/
@Override
public List<TransportTripsTruckDriverEntity> findAll(Long transportTripsId, Long truckId, Long userId) {
LambdaQueryWrapper<TransportTripsTruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtils.isNotEmpty(transportTripsId)) {
lambdaQueryWrapper.eq(TransportTripsTruckDriverEntity::getTransportTripsId, transportTripsId);
}
if (ObjectUtils.isNotEmpty(truckId)) {
lambdaQueryWrapper.eq(TransportTripsTruckDriverEntity::getTruckId, truckId);
}
if (ObjectUtils.isNotEmpty(userId)) {
lambdaQueryWrapper.eq(TransportTripsTruckDriverEntity::getDriverId, userId);
}
return baseMapper.selectList(lambdaQueryWrapper);
}
/**
* 检查是否可以删除
*
* @param transportTripsId 车次id
* @param truckId 车辆Id
* @param userId 司机id
* @return 是否可以删除
*/
@Override
public Boolean canRemove(Long transportTripsId, Long truckId, Long userId) {
LambdaQueryWrapper<TransportTripsTruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtils.isNotEmpty(transportTripsId)) {
lambdaQueryWrapper.eq(TransportTripsTruckDriverEntity::getTransportTripsId, transportTripsId);
}
if (ObjectUtils.isNotEmpty(truckId)) {
lambdaQueryWrapper.eq(TransportTripsTruckDriverEntity::getTruckId, truckId);
}
if (ObjectUtils.isNotEmpty(userId)) {
lambdaQueryWrapper.eq(TransportTripsTruckDriverEntity::getDriverId, userId);
}
return baseMapper.selectCount(lambdaQueryWrapper) == 0;
}
/**
* 消除绑定关系
* @param transportTripsId 车次ID
* @param truckId 车辆ID
*/
@Transactional
@Override
public void delete(Long transportTripsId, Long truckId) {
// 删除车辆和车次关联关系
LambdaQueryWrapper<TransportTripsTruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ObjectUtils.isNotEmpty(transportTripsId), TransportTripsTruckDriverEntity::getTransportTripsId, transportTripsId)
.eq(ObjectUtils.isNotEmpty(truckId), TransportTripsTruckDriverEntity::getTruckId, truckId);
//清除关系
baseMapper.delete(lambdaQueryWrapper);
// 删除没有被调度的计划
truckPlanCreateService.remove(Wrappers.<TruckPlanEntity>lambdaUpdate()
.eq(ObjectUtils.isNotEmpty(transportTripsId), TruckPlanEntity::getTransportTripsId, transportTripsId)
.eq(ObjectUtils.isNotEmpty(truckId), TruckPlanEntity::getTruckId, truckId)
.eq(TruckPlanEntity::getScheduleStatus, TruckPlanScheduleStatusEnum.UNASSIGNED.getCode()));
}
}

View File

@@ -0,0 +1,46 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.entity.truck.TruckEntity;
import com.sl.ms.base.entity.truck.TruckLicenseEntity;
import com.sl.ms.base.mapper.truck.TruckLicenseMapper;
import com.sl.ms.base.service.truck.TruckLicenseService;
import com.sl.ms.base.service.truck.TruckService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* 车辆行驶证表 服务类
*/
@Service
public class TruckLicenseServiceImpl extends ServiceImpl<TruckLicenseMapper, TruckLicenseEntity> implements TruckLicenseService {
@Resource
private TruckService truckService;
/**
* 保存车辆行驶证信息
*
* @param truckLicenseEntity 车辆行驶证信息
* @return 车辆行驶证信息
*/
@Transactional
@Override
public TruckLicenseEntity saveTruckLicense(TruckLicenseEntity truckLicenseEntity) {
if (truckLicenseEntity.getId() == null) {
super.save(truckLicenseEntity);
// 处理车辆信息中的关联字段
if (ObjectUtil.isNotEmpty(truckLicenseEntity.getTruckId())) {
TruckEntity truckEntity = truckService.getById(truckLicenseEntity.getTruckId());
truckEntity.setTruckLicenseId(truckLicenseEntity.getId());
truckService.updateById(truckEntity);
}
} else {
super.updateById(truckLicenseEntity);
}
return truckLicenseEntity;
}
}

View File

@@ -0,0 +1,177 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SimpleQuery;
import com.sl.ms.base.domain.enums.TruckPlanScheduleStatusEnum;
import com.sl.ms.base.domain.enums.TruckPlanStatusEnum;
import com.sl.ms.base.domain.enums.TruckTripsPeriodEnum;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.mapper.truck.TruckPlanMapper;
import com.sl.ms.base.service.base.WorkSchedulingService;
import com.sl.ms.base.service.truck.TruckPlanCreateService;
import com.sl.ms.base.service.truck.TruckTripsService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@Service
@Slf4j
public class TruckPlanCreateServiceImpl extends ServiceImpl<TruckPlanMapper, TruckPlanEntity>
implements TruckPlanCreateService {
@Resource
private TruckTripsService truckTripsService;
@Resource
private WorkSchedulingService workSchedulingService;
@Resource
private TruckDriverService truckDriverService;
/**
* 创建首次计划 首次关系后台新增 安排司机和车辆给车次时候触发
*
* @param truckPlanEntity 车辆计划
*/
@Override
public void createPlan(TruckPlanEntity truckPlanEntity) {
truckPlanEntity.setScheduleStatus(TruckPlanScheduleStatusEnum.UNASSIGNED.getCode());
// 根据车次周期计算间隔天数
TruckTripsEntity truckTripsEntity = truckTripsService.getById(truckPlanEntity.getTransportTripsId());
// 计划发车时间 车次的发车时间 今日的分钟数
LocalDateTime planDepartureTime = DateUtils.getStartTime(LocalDateTime.now()).plusMinutes(truckTripsEntity.getDepartureTime());
truckPlanEntity.setPlanDepartureTime(planDepartureTime);
// 计划到达时间
LocalDateTime planArrivalTime = truckPlanEntity.getPlanDepartureTime().plusMinutes(truckTripsEntity.getEstimatedTime());
truckPlanEntity.setPlanArrivalTime(planArrivalTime);
// 排班
List<TruckDriverEntity> truckDriverEntities = truckDriverService.findByTruckId(truckPlanEntity.getTruckId());
List<Long> driverIds = truckDriverEntities.stream().map(TruckDriverEntity::getUserId).collect(Collectors.toList());
List<Long> workingDrivers = workSchedulingService.getWorkingDrivers(driverIds, planDepartureTime, planArrivalTime);
if (workingDrivers.size() < 2) {
throw new SLException("车辆至少配置俩名上班的司机才能执行运输任务");
}
// 设置司机
truckPlanEntity.setDriverIds(StrUtil.join(",", workingDrivers));
// 插入一条新数据
super.save(truckPlanEntity);
}
/**
* 异步创建下一次计划
* 前一次计划完成触发
*
* @param truckId 车辆ID
* @param driverIds 司机ID列表
* @param currentOrganId 当前位置
* @return 异步任务
*/
@Override
@Async
public CompletableFuture<String> createNextPlans(Long truckId, List<Long> driverIds, Long currentOrganId) {
// 根据车辆ID获取车次IDs 如果解除了绑定 计划也会被弃用
List<Long> transportTripsIds = SimpleQuery.list(
Wrappers.<TransportTripsTruckDriverEntity>lambdaQuery().eq(TransportTripsTruckDriverEntity::getTruckId, truckId),
TransportTripsTruckDriverEntity::getTransportTripsId);
if (CollectionUtils.isEmpty(transportTripsIds)) {
log.error("选举车次 车次不存在 truckId {} currentOrganId {}", truckId, currentOrganId);
return CompletableFuture.completedFuture("ok");
}
// 创建所有车次的计划
transportTripsIds.stream().distinct().forEach(v -> createNextPlan(truckId, driverIds, v));
// 异步任务返回
return CompletableFuture.completedFuture("ok");
}
/**
* 创建某个节点后续每条线路的计划
*
* @param truckId 车辆ID
* @param driverIds 司机ID列表
* @param transportTripsId 车次ID
*/
private void createNextPlan(Long truckId, List<Long> driverIds, Long transportTripsId) {
// 查询最新一条车次计划
TruckPlanEntity last = getOne(Wrappers.<TruckPlanEntity>lambdaQuery()
.eq(TruckPlanEntity::getTruckId, truckId)
.eq(TruckPlanEntity::getTransportTripsId, transportTripsId)
.orderByDesc(TruckPlanEntity::getPlanDepartureTime)
// 1条
.last("limit 1")
);
TruckPlanEntity truckPlanEntityNew = TruckPlanEntity.builder()
// 车辆id
.truckId(truckId)
// 设置计划状态
.status(TruckPlanStatusEnum.NORMAL.getCode())
// 调度状态
.scheduleStatus(TruckPlanScheduleStatusEnum.UNASSIGNED.getCode())
// 车次id
.transportTripsId(transportTripsId).build();
// 根据车次周期计算间隔天数
TruckTripsEntity truckTripsEntity = truckTripsService.getById(transportTripsId);
// 最后的发车时间
LocalDateTime prePlanDepartureTime = last.getPlanDepartureTime();
// 计划发车时间
LocalDateTime planDepartureTime;
if (truckTripsEntity.getPeriod().equals(TruckTripsPeriodEnum.MONTH.getCode())) {
// 周期为月的情况 循环直到是未来的时间
planDepartureTime = prePlanDepartureTime.plusMonths(1);
while (planDepartureTime.isBefore(LocalDateTime.now())) {
planDepartureTime = prePlanDepartureTime.plusMonths(1);
}
} else {
int day = truckTripsEntity.getPeriod().equals(TruckTripsPeriodEnum.WEEK.getCode()) ? 7 : 1;
// 周期为周 / 日 的情况 循环直到是未来的时间
planDepartureTime = prePlanDepartureTime.plusDays(day);
while (planDepartureTime.isBefore(LocalDateTime.now())) {
planDepartureTime = prePlanDepartureTime.plusDays(day);
}
}
// 按照最新的车次时间设置计划发车时间
LocalDateTime planDepartureTimeNew = DateUtils.getStartTime(planDepartureTime).plusMinutes(truckTripsEntity.getDepartureTime());
truckPlanEntityNew.setPlanDepartureTime(planDepartureTimeNew);
// 计划到达时间
LocalDateTime planArrivalTime = planDepartureTime.plusMinutes(truckTripsEntity.getEstimatedTime());
truckPlanEntityNew.setPlanArrivalTime(planArrivalTime);
// 整合排班
List<Long> workingDrivers = workSchedulingService.getWorkingDrivers(driverIds, planDepartureTime, planArrivalTime);
// 设置司机
truckPlanEntityNew.setDriverIds(StrUtil.join(",", workingDrivers));
// 去重复
long count = count(Wrappers.<TruckPlanEntity>lambdaQuery()
.eq(TruckPlanEntity::getTruckId, truckId)
// .eq(TruckPlanEntity::getDriverId, driverId)
.eq(TruckPlanEntity::getTransportTripsId, transportTripsId)
.between(TruckPlanEntity::getPlanDepartureTime, truckPlanEntityNew.getPlanDepartureTime().minusMinutes(1), truckPlanEntityNew.getPlanDepartureTime().plusMinutes(1))
);
if (count == 0) {
// 插入一条新数据
super.save(truckPlanEntityNew);
}
}
}

View File

@@ -0,0 +1,254 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SimpleQuery;
import com.sl.ms.base.domain.enums.StatusEnum;
import com.sl.ms.base.domain.enums.TruckPlanScheduleStatusEnum;
import com.sl.ms.base.domain.enums.TruckPlanStatusEnum;
import com.sl.ms.base.domain.truck.OrganIdsDto;
import com.sl.ms.base.domain.truck.TruckDto;
import com.sl.ms.base.domain.truck.TruckPlanDto;
import com.sl.ms.base.entity.truck.TruckEntity;
import com.sl.ms.base.entity.truck.TruckPlanEntity;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.mapper.truck.TruckPlanMapper;
import com.sl.ms.base.service.truck.TruckPlanCreateService;
import com.sl.ms.base.service.truck.TruckPlanService;
import com.sl.ms.base.service.truck.TruckService;
import com.sl.ms.base.service.truck.TruckTripsService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.ms.transport.api.DispatchConfigurationFeign;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.domain.DispatchConfigurationDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
* 车次与车辆关联信息表 服务类
*/
@Slf4j
@Service
public class TruckPlanServiceImpl extends ServiceImpl<TruckPlanMapper, TruckPlanEntity>
implements TruckPlanService {
@Resource
TruckService truckService;
@Resource
TruckPlanCreateService truckPlanCreateService;
@Resource
TruckTripsService truckTripsService;
@Resource
private TruckDriverService truckDriverService;
@Resource
private DispatchConfigurationFeign dispatchConfigurationFeign;
/**
* 获取未分配运输任务的车次计划列表
*
* @param shardTotal 总片数
* @param shardIndex 分片
* @return 未分配运输任务的车次计划列表
*/
@Override
public List<TruckPlanDto> pullUnassignedPlan(Integer shardTotal, Integer shardIndex) {
//调度时间配置
Integer dispatchTime = null;
DispatchConfigurationDTO configuration = dispatchConfigurationFeign.findConfiguration();
if (ObjectUtil.isNotEmpty(configuration)) {
dispatchTime = configuration.getDispatchTime();
}
int time = dispatchTime != null ? dispatchTime : 2;
// 分片拉取 保证多个调度器均衡负载
LambdaQueryWrapper<TruckPlanEntity> lambdaQueryWrapper = new LambdaQueryWrapper<TruckPlanEntity>()
// 车辆状态是待分配
.eq(TruckPlanEntity::getScheduleStatus, TruckPlanScheduleStatusEnum.UNASSIGNED.getCode())
// 后俩小时之前
.le(TruckPlanEntity::getPlanDepartureTime, LocalDateTime.now().plusHours(time))
// 状态正常
.eq(TruckPlanEntity::getStatus, TruckPlanStatusEnum.NORMAL.getCode())
// ID取模分片
.apply(" MOD(id, {0}) = {1}", shardTotal, shardIndex)
// 增序
.orderByAsc(TruckPlanEntity::getPlanDepartureTime)
// 最多1000条
.last("limit 1000");
// 查询
List<TruckPlanEntity> records = super.list(lambdaQueryWrapper);
if (CollectionUtils.isEmpty(records)) {
log.error("获取未分配运输任务的车次计划列表 暂无满足条件计划 shardTotal {} shardIndex {}", shardTotal, shardIndex);
return new ArrayList<>();
}
// 补充数据
List<TruckPlanDto> truckPlanDtos = toUnassignedDto(records, shardTotal, shardIndex);
if (CollectionUtils.isEmpty(truckPlanDtos)) {
return new ArrayList<>();
}
// 修改计划调度状态
LambdaUpdateWrapper<TruckPlanEntity> updateWrapper = Wrappers.lambdaUpdate(TruckPlanEntity.class)
// 设置为已分配
.set(TruckPlanEntity::getScheduleStatus, TruckPlanScheduleStatusEnum.ASSIGNED.getCode())
// 条件为待分配 保证不会因为同一shardIndex并发导致数据不一致
.eq(TruckPlanEntity::getScheduleStatus, TruckPlanScheduleStatusEnum.UNASSIGNED.getCode())
// 修改范围
.in(TruckPlanEntity::getId, records.stream().map(TruckPlanEntity::getId).collect(Collectors.toSet()));
// 修改
if (update(updateWrapper)) {
// 返回修改后的数据
return truckPlanDtos;
}
return new ArrayList<>();
}
/**
* 转换结构
*
* @param records 计划数据
* @param shardTotal 总片数
* @param shardIndex 当前片数
* @return 车辆计划DTO
*/
private List<TruckPlanDto> toUnassignedDto(List<TruckPlanEntity> records, Integer shardTotal, Integer shardIndex) {
// 转换为dto
List<TruckPlanDto> truckPlanDtos = records.stream()
.map(truckPlanEntity -> {
TruckPlanDto truckPlanDto = BeanUtil.toBean(truckPlanEntity, TruckPlanDto.class);
String[] split = truckPlanEntity.getDriverIds().split(",");
if (ObjectUtil.isEmpty(split)) {
List<Long> list = Arrays.stream(split).map(Long::valueOf).collect(Collectors.toList());
truckPlanDto.setDriverIds(list);
}
return truckPlanDto;
})
.collect(Collectors.toList());
// 根据车辆ID查询车辆
List<Long> truckIds = truckPlanDtos.parallelStream().map(TruckPlanDto::getTruckId).collect(Collectors.toList());
Map<Long, TruckEntity> longTruckEntityMap = SimpleQuery.keyMap(
Wrappers.<TruckEntity>lambdaQuery().in(TruckEntity::getId, truckIds),
TruckEntity::getId);
if (CollectionUtils.isEmpty(longTruckEntityMap)) {
log.error("获取未分配运输任务的车次计划列表 暂无满足条件车辆 shardTotal {} shardIndex {}", shardTotal, shardIndex);
return new ArrayList<>();
}
// 根据车次ID获取<车次ID,线路ID>map
List<Long> transportTripsIds = truckPlanDtos.parallelStream().map(TruckPlanDto::getTransportTripsId).collect(Collectors.toList());
Map<Long, Long> truckTripsLineMap = SimpleQuery.map(
Wrappers.<TruckTripsEntity>lambdaQuery().in(TruckTripsEntity::getId, transportTripsIds),
TruckTripsEntity::getId,
TruckTripsEntity::getTransportLineId);
if (CollectionUtils.isEmpty(truckTripsLineMap)) {
log.error("获取未分配运输任务的车次计划列表 暂无满足条件线路 shardTotal {} shardIndex {}", shardTotal, shardIndex);
return new ArrayList<>();
}
// 根据线路ID查询起始位置
Map<Long, OrganIdsDto> organIdsMap = truckTripsService.getOrganIdsByTripsLineId(new HashSet<>(truckTripsLineMap.values()));
if (CollectionUtils.isEmpty(organIdsMap)) {
log.error("获取未分配运输任务的车次计划列表 远端暂无满足条件机构ids shardTotal {} shardIndex {}", shardTotal, shardIndex);
return new ArrayList<>();
}
// 合并
truckPlanDtos.parallelStream().forEach(v -> {
// 车辆
TruckEntity truckEntity = longTruckEntityMap.get(v.getTruckId());
v.setTruckDto(BeanUtil.toBean(truckEntity, TruckDto.class));
// 线路ID
Long truckTripsLineId = truckTripsLineMap.get(v.getTransportTripsId());
// 起始位置
OrganIdsDto organIdsDto = organIdsMap.get(truckTripsLineId);
v.setTransportLineId(truckTripsLineId);
if (ObjectUtil.isNotEmpty(organIdsDto)) {
BeanUtil.copyProperties(organIdsDto, v);
}
});
return truckPlanDtos;
}
/**
* 更新计划状态为已调度 消费MQ更新调度状态
*
* @param planIds 计划ID
*/
@Override
public void scheduledPlan(Set<Long> planIds) {
// 修改计划调度状态
LambdaUpdateWrapper<TruckPlanEntity> updateWrapper = Wrappers.lambdaUpdate(TruckPlanEntity.class)
// 设置为已调度
.set(TruckPlanEntity::getScheduleStatus, TruckPlanScheduleStatusEnum.SCHEDULED.getCode())
// 条件为已分配
.eq(TruckPlanEntity::getScheduleStatus, TruckPlanScheduleStatusEnum.ASSIGNED.getCode())
// 修改范围
.in(TruckPlanEntity::getId, planIds);
// 修改
update(updateWrapper);
}
/**
* 计划完成
*
* @param currentOrganId 结束机构id
* @param planId 计划ID
* @param truckId 车辆ID
* @param statusEnum 车辆状态枚举
*/
@Transactional
@Override
public void finishedPlan(Long currentOrganId, Long planId, Long truckId, StatusEnum statusEnum) {
log.info("计划完成 currentOrganId {} planId {} ", currentOrganId, planId);
TruckPlanEntity truckPlanEntity = getById(planId);
if (ObjectUtil.isEmpty(truckPlanEntity)) {
throw new SLException(StrUtil.format("计划不存在currentOrganId {} planId {} ", currentOrganId, planId));
}
// 本次计划完成
truckPlanEntity.setStatus(TruckPlanStatusEnum.ARRIVED.getCode());
boolean updateById = updateById(truckPlanEntity);
if (!updateById) {
log.error("更新计划状态失败 currentOrganId {} planId {} ", currentOrganId, planId);
throw new SLException(StrUtil.format("更新计划状态失败currentOrganId {} planId {} ", currentOrganId, planId));
}
// 设置车辆位置 可能回车登记的车辆 并不是计划中的车辆
Boolean updateCurrentOrganId = truckService.updateCurrentOrganId(truckId, currentOrganId, statusEnum);
if (!updateCurrentOrganId) {
log.error("更新车辆位置失败 currentOrganId {} planId {} ", currentOrganId, planId);
throw new SLException(StrUtil.format("更新车辆位置失败currentOrganId {} planId {} ", currentOrganId, planId));
}
// 构建下一次计划 异步
// 司机应该是和该车关联的所有司机
List<TruckDriverEntity> truckDriverEntities = truckDriverService.findByTruckId(truckPlanEntity.getTruckId());
List<Long> driverIds = truckDriverEntities.stream().map(TruckDriverEntity::getUserId).collect(Collectors.toList());
CompletableFuture<String> nextPlans = truckPlanCreateService.createNextPlans(truckPlanEntity.getTruckId(), driverIds, currentOrganId);
nextPlans.whenComplete((s, throwable) -> {
if (!s.equals("ok")) {
log.info("构建下一次计划 失败 truckPlanEntity {}", truckPlanEntity);
}
});
}
}

View File

@@ -0,0 +1,111 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.domain.truck.TruckReturnRegisterDTO;
import com.sl.ms.base.domain.truck.TruckReturnRegisterListDTO;
import com.sl.ms.base.domain.truck.TruckReturnRegisterPageQueryDTO;
import com.sl.ms.base.entity.truck.TruckEntity;
import com.sl.ms.base.entity.truck.TruckReturnRegisterEntity;
import com.sl.ms.base.mapper.truck.TruckReturnRegisterMapper;
import com.sl.ms.base.service.truck.TruckReturnRegisterService;
import com.sl.ms.base.service.truck.TruckService;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.common.util.PageResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* 回车登记 服务类
*/
@Slf4j
@Service
public class TruckReturnRegisterServiceImpl extends ServiceImpl<TruckReturnRegisterMapper, TruckReturnRegisterEntity> implements TruckReturnRegisterService {
@Resource
private TruckService truckService;
/**
* 分页查询回车登记列表
*
* @param dto 分页查询条件
* @return 回车登记分页结果
*/
@Override
public PageResponse<TruckReturnRegisterListDTO> pageQuery(TruckReturnRegisterPageQueryDTO dto) {
//1. 构造分页查询条件
Page<TruckReturnRegisterEntity> iPage = new Page<>(dto.getPage(), dto.getPageSize());
LambdaQueryWrapper<TruckReturnRegisterEntity> queryWrapper = Wrappers.<TruckReturnRegisterEntity>lambdaQuery()
.like(ObjectUtil.isNotEmpty(dto.getTransportTaskId()), TruckReturnRegisterEntity::getTransportTaskId, dto.getTransportTaskId())
.in(ObjectUtil.isNotEmpty(dto.getTransportTaskIds()), TruckReturnRegisterEntity::getTransportTaskId, dto.getTransportTaskIds())
.between(ObjectUtil.isNotEmpty(dto.getIntoStorageStartTime()), TruckReturnRegisterEntity::getIntoStorageTime, dto.getIntoStorageStartTime(), dto.getIntoStorageEndTime())
.eq(ObjectUtil.isNotEmpty(dto.getIsAvailable()), TruckReturnRegisterEntity::getIsAvailable, dto.getIsAvailable())
.orderByDesc(TruckReturnRegisterEntity::getIntoStorageTime);
//2. 分页查询
Page<TruckReturnRegisterEntity> returnRegisterEntityPage = this.page(iPage, queryWrapper);
// 3.1 分页查询结果为空,直接返回
if (ObjectUtil.isEmpty(returnRegisterEntityPage.getRecords())) {
return new PageResponse<>();
}
// 3.2 分页查询结果不为空,封装返回数据
List<TruckReturnRegisterListDTO> list = this.convertEntity2ListDTO(returnRegisterEntityPage.getRecords());
// 4. 封装分页对象
return PageResponse.<TruckReturnRegisterListDTO>builder()
.page(dto.getPage())
.pageSize(dto.getPageSize())
.pages(returnRegisterEntityPage.getPages())
.counts(returnRegisterEntityPage.getTotal())
.items(list)
.build();
}
/**
* 回车登记实体类转换为TruckReturnRegisterListDTO
*
* @param returnRegisterEntities 实体类
* @return 分页结果列表
*/
private List<TruckReturnRegisterListDTO> convertEntity2ListDTO(List<TruckReturnRegisterEntity> returnRegisterEntities) {
//先根据id批量查询车辆信息
List<Long> truckIds = returnRegisterEntities.stream().map(TruckReturnRegisterEntity::getTruckId).collect(Collectors.toList());
List<TruckEntity> truckEntities = truckService.listByIds(truckIds);
return returnRegisterEntities.stream().map(entity -> {
//根据id查询车辆
Optional<TruckEntity> optional = truckEntities.stream().filter(item -> item.getId().equals(entity.getTruckId())).findFirst();
if (optional.isEmpty()) {
throw new SLException("id为" + entity.getTruckId() + "车辆不存在!");
}
//封装回车登记列表数据
TruckReturnRegisterListDTO truckReturnRegisterListDTO = BeanUtil.toBean(entity, TruckReturnRegisterListDTO.class);
truckReturnRegisterListDTO.setLicensePlate(optional.get().getLicensePlate());
return truckReturnRegisterListDTO;
}).collect(Collectors.toList());
}
/**
* 根据id查询回车登记详情
*
* @param id 回车登记id
* @return 回车登记详情
*/
@Override
public TruckReturnRegisterDTO findById(Long id) {
TruckReturnRegisterEntity entity = this.getById(id);
return BeanUtil.toBean(entity, TruckReturnRegisterDTO.class);
}
}

View File

@@ -0,0 +1,235 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SimpleQuery;
import com.sl.ms.base.domain.enums.StatusEnum;
import com.sl.ms.base.domain.enums.TruckRunStatusEnum;
import com.sl.ms.base.domain.enums.TruckWorkStatusEnum;
import com.sl.ms.base.domain.enums.WorkUserTypeEnum;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import com.sl.ms.base.entity.truck.TruckEntity;
import com.sl.ms.base.entity.truck.TruckLicenseEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.mapper.truck.TruckMapper;
import com.sl.ms.base.service.base.WorkSchedulingService;
import com.sl.ms.base.service.truck.TransportTripsTruckDriverService;
import com.sl.ms.base.service.truck.TruckLicenseService;
import com.sl.ms.base.service.truck.TruckService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.transport.common.exception.SLException;
import com.sl.ms.base.domain.constants.TruckConstant;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车辆信息表 服务类
*/
@Service
public class TruckServiceImpl extends ServiceImpl<TruckMapper, TruckEntity> implements TruckService {
@Resource
private TruckDriverService truckDriverService;
@Resource
private WorkSchedulingService workSchedulingService;
@Resource
private TruckLicenseService truckLicenseService;
@Resource
private TransportTripsTruckDriverService transportTripsTruckDriverService;
/**
* 获取车辆分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param truckTypeId 车辆类型id
* @param status 状态
* @param licensePlate 车辆号牌
* @return 线路类型分页数据
*/
@Override
public IPage<TruckEntity> findByPage(Integer page, Integer pageSize, Long truckTypeId, Integer status, String licensePlate) {
Page<TruckEntity> iPage = new Page<>(page, pageSize);
LambdaQueryWrapper<TruckEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (StrUtil.isNotEmpty(licensePlate)) {
lambdaQueryWrapper.like(TruckEntity::getLicensePlate, licensePlate);
}
if (ObjectUtil.isNotEmpty(truckTypeId)) {
lambdaQueryWrapper.eq(TruckEntity::getTruckTypeId, truckTypeId);
}
if (ObjectUtil.isNotEmpty(status)) {
lambdaQueryWrapper.eq(TruckEntity::getWorkStatus, status);
}
lambdaQueryWrapper.orderByDesc(TruckEntity::getCreated);
return super.page(iPage, lambdaQueryWrapper);
}
/**
* 获取车辆列表
*
* @param ids 车辆id列表
* @return 车辆列表
*/
@Override
public List<TruckEntity> findAll(List<Long> ids) {
LambdaQueryWrapper<TruckEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (CollUtil.isNotEmpty(ids)) {
lambdaQueryWrapper.in(TruckEntity::getId, ids);
}
lambdaQueryWrapper.eq(TruckEntity::getStatus, StatusEnum.NORMAL.getCode());
lambdaQueryWrapper.orderByDesc(TruckEntity::getCreated);
return super.list(lambdaQueryWrapper);
}
/**
* 禁用车辆
*
* @param id 车辆ID
*/
@Override
public void stopById(Long id) {
// 车次绑定 运输任务检查
List<TransportTripsTruckDriverEntity> all = transportTripsTruckDriverService.findAll(null, id, null);
if (all.size() > 0) {
throw new SLException("请先解除车次绑定关系");
}
TruckEntity truckEntity = new TruckEntity();
truckEntity.setId(id);
truckEntity.setWorkStatus(TruckWorkStatusEnum.STOP.getCode());
// 解除司机绑定
truckDriverService.disableTruckId(id);
super.updateById(truckEntity);
}
/**
* 更新车辆状态
*
* @param id 车辆ID
* @param status 车辆状态
*/
@Override
public void updateRunStatus(Long id, TruckRunStatusEnum status) {
TruckEntity truckEntity = new TruckEntity();
truckEntity.setId(id);
truckEntity.setRunStatus(status.getCode());
super.updateById(truckEntity);
}
/**
* 更新当前位置
*
* @param truckId 车辆ID
* @param currentOrganId 当前机构ID
*/
@Override
public Boolean updateCurrentOrganId(Long truckId, Long currentOrganId, StatusEnum statusEnum) {
UpdateWrapper<TruckEntity> wrapper = new UpdateWrapper<>();
wrapper.lambda()
// 更新位置
.set(TruckEntity::getCurrentOrganId, currentOrganId)
// 更新车辆状态
.set(TruckEntity::getRunStatus, TruckRunStatusEnum.ARRIVED.getCode())
// 禁用状态
.set(TruckEntity::getStatus, statusEnum.getCode())
.eq(TruckEntity::getId, truckId);
return super.update(wrapper);
}
/**
* 启用
*
* @param id 车辆ID
*/
@Override
public void workedById(Long id) {
// 车辆信息完整 行驶证照片必须有
TruckEntity truckEntity = getById(id);
if (ObjectUtil.isEmpty(truckEntity) || ObjectUtil.isEmpty(truckEntity.getTruckLicenseId())) {
throw new SLException("车辆行驶证不存在");
}
TruckLicenseEntity truckLicenseEntity = truckLicenseService.getById(truckEntity.getTruckLicenseId());
if (ObjectUtil.isEmpty(truckLicenseEntity) || ObjectUtil.isEmpty(truckLicenseEntity.getPicture())) {
throw new SLException("请上传行驶证照片");
}
// 检查司机绑定关系 有司机2个
List<TruckDriverEntity> driverEntities = truckDriverService.findByTruckId(id);
if (CollUtil.isEmpty(driverEntities) || driverEntities.size() < 2) {
throw new SLException(StrUtil.format("请先绑定2个司机"));
}
List<Long> drivers = driverEntities.parallelStream().map(TruckDriverEntity::getUserId).collect(Collectors.toList());
// 有排班才可以启用
long count = workSchedulingService.count(
Wrappers.<WorkSchedulingEntity>lambdaQuery()
.in(WorkSchedulingEntity::getUserId, drivers)
.eq(WorkSchedulingEntity::getIsDelete, 0)
.eq(WorkSchedulingEntity::getUserType, WorkUserTypeEnum.DRIVER.getCode()));
if (count < 2) {
throw new SLException(StrUtil.format("请先为司机安排排班"));
}
truckEntity.setWorkStatus(TruckWorkStatusEnum.WORKING.getCode());
super.updateById(truckEntity);
}
/**
* 状态分组统计
*
* @return 统计车辆信息
*/
@Override
public Map<Integer, Long> groupByStatus() {
return SimpleQuery.group(Wrappers.lambdaQuery(), TruckEntity::getWorkStatus, Collectors.counting());
}
/**
* 删除
*
* @param id 车辆ID
*/
@Override
public void del(Long id) {
// 检查司机绑定关系
List<TruckDriverEntity> driverEntities = truckDriverService.findByTruckId(id);
if (CollUtil.isNotEmpty(driverEntities)) {
throw new SLException(StrUtil.format("请先解绑该车辆下绑定的司机"));
}
TruckEntity truckEntity = new TruckEntity();
truckEntity.setStatus(TruckConstant.DATA_DISABLE_STATUS);
updateById(truckEntity);
}
/**
* 车型数量
*
* @param typeId 车辆类型ID
* @return 该车型下的车辆数量
*/
@Override
public Integer countByType(Long typeId) {
return SimpleQuery.list(
Wrappers.<TruckEntity>lambdaQuery()
.eq(TruckEntity::getTruckTypeId, typeId)
.eq(TruckEntity::getStatus, StatusEnum.NORMAL.getCode()),
TruckEntity::getId).size();
}
}

View File

@@ -0,0 +1,95 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.domain.truck.OrganIdsDto;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import com.sl.ms.base.mapper.truck.TruckTripsMapper;
import com.sl.ms.base.service.truck.TransportTripsTruckDriverService;
import com.sl.ms.base.service.truck.TruckTripsService;
import com.sl.ms.transport.api.TransportLineFeign;
import com.sl.transport.common.exception.SLException;
import com.sl.ms.base.domain.constants.TruckConstant;
import com.sl.transport.domain.TransportLineDTO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
/**
* 车次信息表 服务类
*/
@Service
public class TruckTripsServiceImpl extends ServiceImpl<TruckTripsMapper, TruckTripsEntity> implements TruckTripsService {
@Resource
TransportLineFeign transportLineFeign;
@Resource
private TransportTripsTruckDriverService transportTripsTruckDriverService;
/**
* 获取车次列表
*
* @param transportLineId 线路id
* @param ids 车次id列表
* @return 车次列表
*/
@Override
public List<TruckTripsEntity> findAll(Long transportLineId, List<Long> ids) {
LambdaQueryWrapper<TruckTripsEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtil.isNotEmpty(transportLineId)) {
lambdaQueryWrapper.eq(TruckTripsEntity::getTransportLineId, transportLineId);
}
if (CollUtil.isNotEmpty(ids)) {
lambdaQueryWrapper.in(TruckTripsEntity::getId, ids);
}
lambdaQueryWrapper.orderByDesc(TruckTripsEntity::getCreated);
lambdaQueryWrapper.eq(TruckTripsEntity::getStatus, TruckConstant.DATA_DEFAULT_STATUS);
return super.list(lambdaQueryWrapper);
}
/**
* 删除车次
*
* @param id 车次ID
*/
@Override
public void disable(Long id) {
// 检查车次绑定关系
Boolean remove = transportTripsTruckDriverService.canRemove(id, null, null);
if (!remove) {
throw new SLException("该车次下存在绑定车辆,请先解除绑定后删除");
}
TruckTripsEntity truckTripsEntity = new TruckTripsEntity();
truckTripsEntity.setId(id);
truckTripsEntity.setStatus(TruckConstant.DATA_DISABLE_STATUS);
baseMapper.updateById(truckTripsEntity);
}
/**
* 根据线路ID查询机构
* @param values 线路ID
* @return 机构信息
*/
@Override
public Map<Long, OrganIdsDto> getOrganIdsByTripsLineId(HashSet<Long> values) {
HashMap<Long, OrganIdsDto> hashMap = new HashMap<>();
List<TransportLineDTO> listR = transportLineFeign.queryByIds(values.toArray(Long[]::new));
listR.forEach(v -> {
OrganIdsDto organIdsDto = new OrganIdsDto();
organIdsDto.setStartOrganId(v.getStartOrganId());
organIdsDto.setEndOrganId(v.getEndOrganId());
hashMap.put(v.getId(), organIdsDto);
});
return hashMap;
}
}

View File

@@ -0,0 +1,62 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.entity.truck.TruckTypeGoodsTypeEntity;
import com.sl.ms.base.mapper.truck.TruckTypeGoodsTypeMapper;
import com.sl.ms.base.service.truck.TruckTypeGoodsTypeService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 车辆类型与货物类型关联表 服务实现类
*/
@Service
public class TruckTypeGoodsTypeServiceImpl extends ServiceImpl<TruckTypeGoodsTypeMapper, TruckTypeGoodsTypeEntity>
implements TruckTypeGoodsTypeService {
/**
* 删除关联关系
*
* @param truckTypeId 车辆类型id
* @param goodsTypeId 货物类型id
*/
@Override
public void delete(Long truckTypeId, Long goodsTypeId) {
LambdaQueryWrapper<TruckTypeGoodsTypeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
boolean canExecute = false;
if (ObjectUtil.isNotEmpty(truckTypeId)) {
lambdaQueryWrapper.eq(TruckTypeGoodsTypeEntity::getTruckTypeId, truckTypeId);
canExecute = true;
}
if (ObjectUtil.isNotEmpty(goodsTypeId)) {
lambdaQueryWrapper.eq(TruckTypeGoodsTypeEntity::getGoodsTypeId, goodsTypeId);
canExecute = true;
}
if (canExecute) {
super.remove(lambdaQueryWrapper);
}
}
/**
* 获取车辆类型与货物类型关联
*
* @param truckTypeId 车辆类型id
* @param goodsTypeId 货物类型id
* @return 车辆类型与货物类型关联
*/
@Override
public List<TruckTypeGoodsTypeEntity> findAll(Long truckTypeId, Long goodsTypeId) {
LambdaQueryWrapper<TruckTypeGoodsTypeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtil.isNotEmpty(truckTypeId)) {
lambdaQueryWrapper.eq(TruckTypeGoodsTypeEntity::getTruckTypeId, truckTypeId);
}
if (ObjectUtil.isNotEmpty(goodsTypeId)) {
lambdaQueryWrapper.eq(TruckTypeGoodsTypeEntity::getGoodsTypeId, goodsTypeId);
}
return super.list(lambdaQueryWrapper);
}
}

View File

@@ -0,0 +1,111 @@
package com.sl.ms.base.service.truck.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.entity.truck.TruckEntity;
import com.sl.ms.base.entity.truck.TruckTypeEntity;
import com.sl.ms.base.mapper.truck.TruckTypeMapper;
import com.sl.ms.base.service.truck.TruckService;
import com.sl.ms.base.service.truck.TruckTypeService;
import com.sl.transport.common.exception.SLException;
import com.sl.ms.base.domain.constants.TruckConstant;
import com.sl.transport.common.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 车辆类型表 服务实现类
*/
@Service
public class TruckTypeServiceImpl extends ServiceImpl<TruckTypeMapper, TruckTypeEntity>
implements TruckTypeService {
@Autowired
private TruckService truckService;
/**
* 获取车辆类型分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @param name 车辆类型名称
* @param minAllowableLoad 车辆载重最小值(闭区间)
* @param maxAllowableLoad 车辆载重最大值(开区间)
* @param minAllowableVolume 车辆体积最小值(闭区间)
* @param maxAllowableVolume 车辆体积最小值(开区间)
* @param id 车型id
* @return 车辆类型分页数据
*/
@Override
public IPage<TruckTypeEntity> findByPage(Integer page, Integer pageSize, String name, BigDecimal minAllowableLoad, BigDecimal maxAllowableLoad, BigDecimal minAllowableVolume, BigDecimal maxAllowableVolume, Long id) {
Page<TruckTypeEntity> iPage = new Page<>(page, pageSize);
LambdaQueryWrapper<TruckTypeEntity> lambdaQueryWrapper = Wrappers.<TruckTypeEntity>lambdaQuery()
.like(CharSequenceUtil.isNotBlank(name), TruckTypeEntity::getName, name)
.like(ObjectUtil.isNotEmpty(id), TruckTypeEntity::getId, id)
.ge(ObjectUtil.isNotEmpty(minAllowableLoad),TruckTypeEntity::getAllowableLoad, minAllowableLoad)
.lt(ObjectUtil.isNotEmpty(maxAllowableLoad),TruckTypeEntity::getAllowableLoad, maxAllowableLoad)
.ge(ObjectUtil.isNotEmpty(minAllowableVolume),TruckTypeEntity::getAllowableVolume, minAllowableVolume)
.lt(ObjectUtil.isNotEmpty(maxAllowableVolume),TruckTypeEntity::getAllowableVolume, maxAllowableVolume)
.eq(TruckTypeEntity::getStatus, TruckConstant.DATA_DEFAULT_STATUS)
.orderByDesc(TruckTypeEntity::getCreated);
return super.page(iPage, lambdaQueryWrapper);
}
/**
* 获取车辆类型列表
*
* @return 车辆类型列表
*/
@Override
public List<TruckTypeEntity> findAll(List<Long> ids) {
LambdaQueryWrapper<TruckTypeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (CollUtil.isNotEmpty(ids)) {
lambdaQueryWrapper.in(TruckTypeEntity::getId, ids);
}
lambdaQueryWrapper.eq(TruckTypeEntity::getStatus, TruckConstant.DATA_DEFAULT_STATUS);
return super.list(lambdaQueryWrapper);
}
/**
* 删除车辆类型
*
* @param id 车型ID
*/
@Override
public void disable(Long id) {
Long count = truckService.getBaseMapper().selectCount(Wrappers.<TruckEntity>lambdaQuery().eq(TruckEntity::getTruckTypeId, id));
if (count > 0) {
throw new SLException(StrUtil.format("车型中有使用的车辆,不可以删除 >>> msg = {}", id));
}
TruckTypeEntity truckType = new TruckTypeEntity();
truckType.setId(id);
truckType.setStatus(TruckConstant.DATA_DISABLE_STATUS);
updateById(truckType);
}
/**
* 获取map类型车辆类型数据集合
*
* @param truckTypeSet 车辆类型id列表
* @return 执行结果
*/
@Override
public Map<Long, TruckTypeEntity> truckTypeMap(Set<Long> truckTypeSet) {
List<TruckTypeEntity> truckTypeDtoList = findAll(new ArrayList<>(truckTypeSet));
return truckTypeDtoList.stream().collect(Collectors.toMap(TruckTypeEntity::getId, vo -> vo));
}
}

View File

@@ -0,0 +1,18 @@
package com.sl.ms.base.service.user;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.entity.user.TruckDriverLicenseEntity;
/**
* 司机驾驶证表 服务类
*/
public interface TruckDriverLicenseService extends IService<TruckDriverLicenseEntity> {
/**
* 获取司机驾驶证信息
*
* @param userId 司机id
* @return 司机驾驶证信息
*/
TruckDriverLicenseEntity findOne(Long userId);
}

View File

@@ -0,0 +1,63 @@
package com.sl.ms.base.service.user;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sl.ms.base.domain.user.TruckDriverDto;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import java.util.List;
/**
* 司机表 服务类
*/
public interface TruckDriverService extends IService<TruckDriverEntity> {
/**
* 获取司机基本信息列表
*
* @param userIds 司机id列表
* @return 司机基本信息列表
*/
List<TruckDriverEntity> findAll(List<Long> userIds);
/**
* 获取司机基本信息
*
* @param userId 司机id
* @return 司机基本信息
*/
TruckDriverEntity findOne(Long userId);
/**
* 绑定司机列表
*
* @param truckId 车辆id
* @return 司机数量
*/
List<TruckDriverEntity> findByTruckId(Long truckId);
/**
* 获取司机分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @return 司机分页数据
*/
IPage<TruckDriverEntity> findByPage(Integer page, Integer pageSize);
/**
* 解除车辆和司机的绑定关系
*
* @param truckId 车辆ID
*/
void disableTruckId(Long truckId);
/**
* 保存
*
* @param dto 司机
* @return 司机
*/
TruckDriverDto saveDriver(TruckDriverDto dto);
}

View File

@@ -0,0 +1,32 @@
package com.sl.ms.base.service.user.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.entity.user.TruckDriverLicenseEntity;
import com.sl.ms.base.mapper.user.TruckDriverLicenseMapper;
import com.sl.ms.base.service.user.TruckDriverLicenseService;
import org.springframework.stereotype.Service;
/**
* 司机驾驶证
*/
@Service
public class TruckDriverLicenseServiceImpl extends ServiceImpl<TruckDriverLicenseMapper, TruckDriverLicenseEntity>
implements TruckDriverLicenseService {
/**
* 获取司机驾驶证信息
*
* @param userId 司机id
* @return 司机驾驶证信息
*/
@Override
public TruckDriverLicenseEntity findOne(Long userId) {
LambdaQueryWrapper<TruckDriverLicenseEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtil.isNotEmpty(userId)) {
lambdaQueryWrapper.eq(TruckDriverLicenseEntity::getUserId, userId);
}
return super.getOne(lambdaQueryWrapper);
}
}

View File

@@ -0,0 +1,162 @@
package com.sl.ms.base.service.user.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.ms.base.domain.user.TruckDriverDto;
import com.sl.ms.base.entity.truck.TransportTripsTruckDriverEntity;
import com.sl.ms.base.entity.truck.TruckTripsEntity;
import com.sl.ms.base.entity.user.TruckDriverEntity;
import com.sl.ms.base.mapper.user.TruckDriverMapper;
import com.sl.ms.base.service.truck.TransportTripsTruckDriverService;
import com.sl.ms.base.service.truck.TruckTripsService;
import com.sl.ms.base.service.user.TruckDriverService;
import com.sl.ms.transport.api.TransportLineFeign;
import com.sl.transport.common.exception.SLException;
import com.sl.transport.domain.TransportLineDTO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 司机相关业务
*/
@Service
public class TruckDriverServiceImpl extends ServiceImpl<TruckDriverMapper, TruckDriverEntity>
implements TruckDriverService {
@Resource
private TransportTripsTruckDriverService transportTripsTruckDriverService;
@Resource
private TransportLineFeign transportLineFeign;
@Resource
private TruckTripsService truckTripsService;
/**
* 获取司机基本信息列表
*
* @param userIds 司机id列表
* @return 司机基本信息列表
*/
@Override
public List<TruckDriverEntity> findAll(List<Long> userIds) {
if (ObjectUtil.isAllEmpty(userIds)) {
return Collections.emptyList();
}
LambdaQueryWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (CollUtil.isNotEmpty(userIds)) {
lambdaQueryWrapper.in(TruckDriverEntity::getUserId, userIds);
}
lambdaQueryWrapper.orderByDesc(TruckDriverEntity::getCreated);
return super.list(lambdaQueryWrapper);
}
/**
* 获取司机基本信息
*
* @param userId 司机id
* @return 司机基本信息
*/
@Override
public TruckDriverEntity findOne(Long userId) {
LambdaQueryWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(TruckDriverEntity::getUserId, userId);
return super.getOne(lambdaQueryWrapper);
}
/**
* 绑定司机列表
*
* @return 司机数量
*/
@Override
public List<TruckDriverEntity> findByTruckId(Long truckId) {
LambdaQueryWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(TruckDriverEntity::getTruckId,truckId);
return list(lambdaQueryWrapper);
}
/**
* 解除车辆和司机的绑定关系
* @param truckId 车辆ID
*/
@Override
public void disableTruckId(Long truckId) {
LambdaUpdateWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaUpdateWrapper<>();
lambdaQueryWrapper.eq(TruckDriverEntity::getTruckId,truckId)
.set(TruckDriverEntity::getTruckId, null);
update(lambdaQueryWrapper);
}
/**
* 保存
* @param dto 司机
* @return 保存结果
*/
@Override
public TruckDriverDto saveDriver(TruckDriverDto dto) {
TruckDriverEntity driver = BeanUtil.toBean(dto, TruckDriverEntity.class);
TruckDriverEntity one = findOne(dto.getUserId());
if (ObjectUtil.isNotEmpty(one)) {
// 检查是否能够解除原有绑定车辆
checkCanBingingTruck(one);
driver.setId(one.getId());
updateById(driver);
} else {
save(driver);
}
BeanUtil.copyProperties(driver, dto);
return dto;
}
/**
* check 是否有车次绑定关系
* @param oldDriver 旧数据
*/
private void checkCanBingingTruck(TruckDriverEntity oldDriver) {
// 如果原有绑定车辆不为空 则需要判断是否能够解除原有车辆绑定关系
if (ObjectUtil.isNotEmpty(oldDriver.getTruckId())) {
// 检查车次绑定关系
List<TransportTripsTruckDriverEntity> all = transportTripsTruckDriverService.findAll(null, oldDriver.getTruckId(), oldDriver.getUserId());
if (all.size() > 0) {
// 不能解除
List<Long> tripsIds = all.parallelStream().map(TransportTripsTruckDriverEntity::getTransportTripsId).distinct().collect(Collectors.toList());
List<TruckTripsEntity> truckTripsEntities = truckTripsService.findAll(null, tripsIds);
List<String> tripsNames = truckTripsEntities.parallelStream().map(TruckTripsEntity::getName).distinct().collect(Collectors.toList());
List<Long> lineIds = truckTripsEntities.parallelStream().map(TruckTripsEntity::getTransportLineId).distinct().collect(Collectors.toList());
List<TransportLineDTO> lineDTOS = transportLineFeign.queryByIds(lineIds.toArray(Long[]::new));
List<String> names = lineDTOS.parallelStream().map(TransportLineDTO::getName).collect(Collectors.toList());
throw new SLException(StrUtil.format("请先解除原有车辆对应的车次绑定关系 详细: 线路名称 {} 车次名称{}", names, tripsNames));
}
}
}
/**
* 获取司机分页数据
*
* @param page 页码
* @param pageSize 页尺寸
* @return 司机分页数据
*/
@Override
public IPage<TruckDriverEntity> findByPage(Integer page, Integer pageSize) {
Page<TruckDriverEntity> iPage = new Page<>(page, pageSize);
LambdaQueryWrapper<TruckDriverEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.orderByDesc(TruckDriverEntity::getCreated);
return super.page(iPage, lambdaQueryWrapper);
}
}

View File

@@ -0,0 +1,21 @@
package com.sl.ms.base.utils;
import com.sl.ms.base.constant.WorkConstants;
import com.sl.ms.base.domain.enums.WorkPatternEnum;
import com.sl.ms.base.entity.base.WorkPatternEntity;
public class WorkPatternUtils {
public static String toWorkDate(WorkPatternEntity entity) {
byte workPatternType = entity.getWorkPatternType();
if (workPatternType == WorkPatternEnum.Weeks.getType()) { //周期制
String workDate = String.format(WorkConstants.WORK_DATE_WEEKS, entity.getMonday(), entity.getTuesday(),
entity.getWednesday(), entity.getThursday(), entity.getFriday(),
entity.getSaturday(), entity.getSunday());
return workDate.replace("1", "").replace("2", "");
} else {
return String.format(WorkConstants.WORK_DATE_CONTINUITYS,
entity.getWorkDayNum(), entity.getRestDayNum());
}
}
}

View File

@@ -0,0 +1,97 @@
package com.sl.ms.base.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.sl.ms.base.domain.enums.WorkPatternEnum;
import com.sl.ms.base.entity.base.WorkPatternEntity;
import com.sl.ms.base.entity.base.WorkSchedulingEntity;
import com.sl.transport.common.util.DateUtils;
import com.sl.transport.common.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Map;
@Slf4j
public class WorkSchedulingUtils {
/**
* 查询列表信息时是否需要查询历史列表
* 当前月份1号查询的时候不需要查询历史数据
* @param queryMonth 月份
* @return 是否需要
*/
public static boolean isQueryHistory(String queryMonth){
LocalDateTime now = LocalDateTimeUtil.now(); //当前时间
String currentMonth = LocalDateTimeUtil.format( now, DateUtils.DEFAULT_MONTH_FORMAT);
int result = queryMonth.compareTo(currentMonth);
if(result > 0) { //查询未来月份不用查询历史记录
return false;
}else if (result == 0) { //当前月份
int dayOfMonth = now.getDayOfMonth();
return dayOfMonth > 1;
}else { //查询以前月份,直接查询历史
return true;
}
}
/**
* 是否上班
* @param workSchedulingEntity 排班数据
* @param month 月
* @param dayOfMonth 日
* @param patternEntity 工作模式
* @param workHistory 历史数据
* @param forceUserWorkPattern 是否强制使用工作模式推断
* @return 是否上班
*/
public static boolean isWorded(WorkSchedulingEntity workSchedulingEntity, String month, int dayOfMonth,
WorkPatternEntity patternEntity, Map<String,String> workHistory, Boolean forceUserWorkPattern){
String nowDay = LocalDateTimeUtil.format(LocalDateTime.now(), DateUtils.DEFAULT_DATE_FORMAT);
String queryDay = String.format("%s-%s", month, dayOfMonth >= 10 ? "" + dayOfMonth : "0" + dayOfMonth);
if(nowDay.compareTo(queryDay) > 0 && !forceUserWorkPattern) { //查询历史数据
return CollUtil.isEmpty(workHistory) ? false : workHistory.containsKey(workSchedulingEntity.getUserId() + "" + dayOfMonth);
}else { //根据排班推断
if (ObjectUtil.isEmpty(patternEntity)) {
// 默认不上班
return false;
}
Byte workPatternType = patternEntity.getWorkPatternType();
if(workPatternType.byteValue() == WorkPatternEnum.Weeks.getType()) { //礼拜制
int dayOfWeek = LocalDateTimeUtil.parse(queryDay,DateUtils.DEFAULT_DATE_FORMAT).getDayOfWeek().getValue();
return isWorked(dayOfWeek, patternEntity);
}else { //连续制
long workContinueStartTime = DateUtils.getStartTime(workSchedulingEntity.getWorkContinueStartTime())
.toEpochSecond(ZoneOffset.of("+8"));
long queryDayStartTime = DateUtils.getStartTime(LocalDateTimeUtil.parse(queryDay, DateUtils.DEFAULT_DATE_FORMAT))
.toEpochSecond(ZoneOffset.of("+8"));
int day = (int)(queryDayStartTime - workContinueStartTime) / (24 * 3600) ; //已经连续工作和休息的天数
int dayNum = patternEntity.getRestDayNum() + patternEntity.getWorkDayNum() == 0 ? 0: day % ( patternEntity.getRestDayNum() + patternEntity.getWorkDayNum()); //连续工作休息n个周期后的第几天
return dayNum < patternEntity.getWorkDayNum(); //dayNum小于等于连续工作天数则今天在上班否则在休息
}
}
}
private static boolean isWorked(int dayOfWeek, WorkPatternEntity entity) {
switch (dayOfWeek) {
case 1 : //周一是否上班
return entity.getMonday() == 1;
case 2: //周二是否上班
return entity.getTuesday() == 1;
case 3: //周三是否上班
return entity.getWednesday() == 1;
case 4: //周四是否上班
return entity.getThursday() == 1;
case 5: //周五是否上班
return entity.getFriday() == 1;
case 6: //周六是否上班
return entity.getSaturday() == 1;
case 7: //周日是否上班
return entity.getSunday() == 1;
default:
return false;
}
}
}

View File

@@ -0,0 +1,7 @@
_ ${spring.application.name} ${application.version}
___ | | ___ __ __ _ __ _ __ ___ ___ ___ Port: ${server.port}
/ __|| | _____ / _ \\ \/ /| '_ \ | '__|/ _ \/ __|/ __| Pid: ${pid} Profile(s): ${AnsiColor.GREEN}${spring.profiles.active}${AnsiColor.DEFAULT}
\__ \| ||_____|| __/ > < | |_) || | | __/\__ \\__ \
|___/|_| \___|/_/\_\| .__/ |_| \___||___/|___/ https://sl-express.itheima.net/
|_|

View File

@@ -0,0 +1,40 @@
server:
port: 18081
tomcat:
uri-encoding: UTF-8
threads:
max: 1000
min-spare: 30
spring:
cloud:
nacos:
username: nacos
password: nacos
server-addr: 192.168.150.101:8848
discovery:
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
ip: 192.168.150.1
config:
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
shared-configs: #共享配置
- data-id: shared-spring-seata.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-rabbitmq.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mysql.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mybatis-plus.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-xxl-job.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-authority.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-redis.yml
group: SHARED_GROUP
refresh: false

View File

@@ -0,0 +1,39 @@
server:
port: 18081
tomcat:
uri-encoding: UTF-8
threads:
max: 1000
min-spare: 30
spring:
cloud:
nacos:
username: nacos
password: vO5/dZ9,iL
server-addr: nacos-service.yjy-public-slwl-java-prod.svc.cluster.local:8848
discovery:
namespace: 92312ba8-1119-440f-81af-c29618df303b
config:
namespace: 92312ba8-1119-440f-81af-c29618df303b
shared-configs: #共享配置
- data-id: shared-spring-seata.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-rabbitmq.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mysql.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mybatis-plus.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-xxl-job.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-authority.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-redis.yml
group: SHARED_GROUP
refresh: false

View File

@@ -0,0 +1,39 @@
server:
port: 18081
tomcat:
uri-encoding: UTF-8
threads:
max: 1000
min-spare: 30
spring:
cloud:
nacos:
username: nacos
password: nacos
server-addr: 192.168.150.101:8848
discovery:
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
config:
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
shared-configs: #共享配置
- data-id: shared-spring-seata.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-rabbitmq.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mysql.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mybatis-plus.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-xxl-job.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-authority.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-redis.yml
group: SHARED_GROUP
refresh: false

View File

@@ -0,0 +1,39 @@
server:
port: 18081
tomcat:
uri-encoding: UTF-8
threads:
max: 1000
min-spare: 30
spring:
cloud:
nacos:
username: nacos
password: nacos
server-addr: nacos-service.yjy-public-slwl-java.svc.cluster.local:8848
discovery:
namespace: 92312ba8-1119-440f-81af-c29618df303b
config:
namespace: 92312ba8-1119-440f-81af-c29618df303b
shared-configs: #共享配置
- data-id: shared-spring-seata.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-rabbitmq.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mysql.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-mybatis-plus.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-xxl-job.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-authority.yml
group: SHARED_GROUP
refresh: false
- data-id: shared-spring-redis.yml
group: SHARED_GROUP
refresh: false

View File

@@ -0,0 +1,27 @@
application:
version: v1.0
logging:
config: classpath:logback-spring.xml
spring:
application:
name: sl-express-ms-base
main:
allow-circular-references: true #允许bean循环依赖
profiles:
active: local
mvc:
pathmatch:
#解决异常swagger Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
#因为Springfox使用的路径匹配是基于AntPathMatcher的而Spring Boot 2.6.X使用的是PathPatternMatcher
matching-strategy: ant_path_matcher
sl:
mq:
enable: true #开启MQ可以注入MQService使用但是必须保证数据库有sl_fail_msg表
swagger:
package-path: com.sl.ms.base.controller
title: 神领物流 - 基础微服务接口文档
description: 该微服务完成车辆、省市区等基础数据的管理。
contact-name: 传智教育·研究院
contact-url: http://www.itcast.cn/
contact-email: yjy@itcast.cn
version: ${application.version}

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--scan: 当此属性设置为true时配置文件如果发生改变将会被重新加载默认值为true。-->
<!--scanPeriod: 设置监测配置文件是否有修改的时间间隔如果没有给出时间单位默认单位是毫秒。当scan为true时此属性生效。默认的时间间隔为1分钟。-->
<!--debug: 当此属性设置为true时将打印出logback内部日志信息实时查看logback运行状态。默认值为false。-->
<configuration debug="false" scan="false" scanPeriod="60 seconds">
<springProperty scope="context" name="appName" source="spring.application.name"/>
<!--文件名-->
<property name="logback.appname" value="${appName}"/>
<!--文件位置-->
<property name="logback.logdir" value="/data/logs"/>
<!-- 定义控制台输出 -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - [%thread] - %-5level - %logger{50} - %msg%n</pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<File>${logback.logdir}/${logback.appname}/${logback.appname}.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logback.logdir}/${logback.appname}/${logback.appname}.%d{yyyy-MM-dd}.log.zip</FileNamePattern>
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
</encoder>
</appender>
<!--evel:用来设置打印级别大小写无关TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF-->
<!--不能设置为INHERITED或者同义词NULL。默认是DEBUG。-->
<root level="INFO">
<appender-ref ref="stdout"/>
</root>
</configuration>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sl.ms.base.mapper.base.GoodsTypeMapper">
<select id="findByPage" resultType="com.sl.ms.base.entity.base.GoodsTypeEntity">
SELECT
goods_type.*
FROM
sl_goods_type goods_type
<if test="truckTypeId != null">
LEFT JOIN sl_truck_type_goods_type truck_type_goods_type
ON truck_type_goods_type.goods_type_id = goods_type.id
</if>
WHERE
goods_type.status = 1
<if test="truckTypeId != null">
AND truck_type_goods_type.truck_type_id = #{truckTypeId}
</if>
<if test="goodsTypeName != null">
AND goods_type.name LIKE concat( '%', '${goodsTypeName}', '%' )
</if>
ORDER BY
goods_type.created DESC
</select>
</mapper>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sl.ms.base.mapper.base.WorkSchedulingMapper">
<insert id="batchInsert" parameterType="java.util.Map">
insert into sl_work_scheduling (id, user_id, user_type,
agency_id, employee_number, name,
phone, state, work_pattern_id,
work_continue_start_time,
creater, created, updater,
updated, is_delete) value
<foreach collection="entities" separator="," item="entity">
(#{entity.id},#{entity.userId},#{entity.userType},
#{entity.agencyId},#{entity.employeeNumber},#{entity.name},
#{entity.phone},#{entity.state},#{entity.workPatternId},
#{entity.workContinueStartTime},
#{entity.creater},#{entity.created},#{entity.updater},
#{entity.updated},#{entity.isDelete})
</foreach>
</insert>
</mapper>

View File

@@ -0,0 +1,20 @@
package com.sl.ms.base.mq;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class AuthUserMQListenerTest {
@Autowired
AuthUserMQListener authUserMQListener;
@Test
void listenUserMsg() {
String s = "{\"type\":\"USER\",\"operation\":\"DEL\",\"content\":[{\"id\":\"1014219558409471937\",\"superior\":\"-1\",\"account\":\"xxxx\",\"name\":\"xxxx\",\"orgId\":\"987327492140340001\",\"orgName\":null,\"stationId\":\"981223703335410625\",\"stationName\":null,\"email\":null,\"mobile\":\"13838383883\",\"sex\":{\"desc\":\"\",\"code\":\"M\"},\"status\":true,\"avatar\":\"\",\"workDescribe\":\"\",\"passwordErrorLastTime\":null,\"passwordErrorNum\":0,\"passwordExpireTime\":null,\"password\":\"e10adc3949ba59abbe56e057f20f883e\",\"lastLoginTime\":null,\"roles\":null,\"roleNames\":null,\"userGroupsNames\":null,\"administrator\":false}]}\n";
authUserMQListener.listenUserMsg(s);
}
}

Some files were not shown because too many files have changed in this diff Show More