haungxing
1 year ago
18 changed files with 331 additions and 34 deletions
@ -0,0 +1,53 @@ |
|||||||
|
package com.hnac.hzims.ticket.workTicket.controller; |
||||||
|
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; |
||||||
|
import com.hnac.hzims.ticket.workTicket.service.IOfflineTicketService; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName OfflineTicketController |
||||||
|
* @description: 线下工作票管理 |
||||||
|
* @author: hx |
||||||
|
* @create: 2023-09-14 10:36 |
||||||
|
* @Version 4.0 |
||||||
|
**/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/offline/ticket") |
||||||
|
@AllArgsConstructor |
||||||
|
@Api(value = "线下工作票管理") |
||||||
|
public class OfflineTicketController extends BladeController { |
||||||
|
|
||||||
|
private final IOfflineTicketService offlineTicketService; |
||||||
|
|
||||||
|
@PostMapping("/invoicing") |
||||||
|
@ApiOperation("线下工作票开票") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
public R invoicing(@RequestBody WorkTicketInfoDto dto) { |
||||||
|
return R.status(offlineTicketService.invoicing(dto)); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("/licenseOfflineTicket") |
||||||
|
@ApiOperation("线下工作票线下处理") |
||||||
|
@ApiOperationSupport(order = 2) |
||||||
|
public R licenseOfflineTicket(@RequestBody WorkTicketInfoDto dto) { |
||||||
|
return R.status(offlineTicketService.licenseOfflineTicket(dto)); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("/finishOfflineTicket") |
||||||
|
@ApiOperation("线下工作票终结") |
||||||
|
@ApiOperationSupport(order = 3) |
||||||
|
public R finishOfflineTicket(@RequestBody WorkTicketInfoDto dto) { |
||||||
|
return R.status(offlineTicketService.finishOfflineTicket(dto)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
package com.hnac.hzims.ticket.workTicket.service; |
||||||
|
|
||||||
|
import com.hnac.hzims.ticket.workTicket.dto.TicketAccessTaskDto; |
||||||
|
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; |
||||||
|
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
public interface IOfflineTicketService extends BaseService<WorkTicketInfoEntity> { |
||||||
|
|
||||||
|
boolean invoicing(WorkTicketInfoDto dto); |
||||||
|
|
||||||
|
boolean licenseOfflineTicket(WorkTicketInfoDto dto); |
||||||
|
|
||||||
|
boolean finishOfflineTicket(WorkTicketInfoDto dto); |
||||||
|
} |
@ -0,0 +1,206 @@ |
|||||||
|
package com.hnac.hzims.ticket.workTicket.service.impl; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
||||||
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
||||||
|
import com.hnac.hzims.ticket.constants.TicketConstants; |
||||||
|
import com.hnac.hzims.ticket.constants.WorkTicketConstants; |
||||||
|
import com.hnac.hzims.ticket.twoTicket.constant.TicketConstant; |
||||||
|
import com.hnac.hzims.ticket.workTicket.dto.WorkTicketInfoDto; |
||||||
|
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketContentEntity; |
||||||
|
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketFlowEntity; |
||||||
|
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; |
||||||
|
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketSafetyMeasureEntity; |
||||||
|
import com.hnac.hzims.ticket.workTicket.mapper.WorkTicketInfoMapper; |
||||||
|
import com.hnac.hzims.ticket.workTicket.service.IOfflineTicketService; |
||||||
|
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketContentService; |
||||||
|
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketFlowService; |
||||||
|
import com.hnac.hzims.ticket.workTicket.service.IWorkTicketSafetyMeasureService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.log.exception.ServiceException; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.secure.utils.AuthUtil; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.BeanUtil; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springblade.system.user.cache.UserCache; |
||||||
|
import org.springblade.system.user.entity.User; |
||||||
|
import org.springblade.system.user.feign.IUserClient; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.util.Assert; |
||||||
|
|
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.time.YearMonth; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.time.temporal.TemporalAdjusters; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Optional; |
||||||
|
import java.util.concurrent.locks.Lock; |
||||||
|
import java.util.concurrent.locks.ReentrantLock; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName OfflineTicketServiceImpl |
||||||
|
* @description: 线下工作票service类 |
||||||
|
* @author: hx |
||||||
|
* @create: 2023-09-13 14:00 |
||||||
|
* @Version 4.0 |
||||||
|
**/ |
||||||
|
@AllArgsConstructor |
||||||
|
@Service |
||||||
|
@Slf4j |
||||||
|
public class OfflineTicketServiceImpl extends BaseServiceImpl<WorkTicketInfoMapper, WorkTicketInfoEntity> implements IOfflineTicketService { |
||||||
|
private final IStationClient stationClient; |
||||||
|
private final IWorkTicketSafetyMeasureService workTicketSafetyMeasureService; |
||||||
|
private final IWorkTicketContentService contentService; |
||||||
|
private final IUserClient userClient; |
||||||
|
private final IWorkTicketFlowService workTicketFlowService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 线下工作票开票 |
||||||
|
* @param dto 工作票开票内容 |
||||||
|
* @return 开票结果 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean invoicing(WorkTicketInfoDto dto) { |
||||||
|
WorkTicketInfoEntity ticketInfoEntity = BeanUtil.copy(dto,WorkTicketInfoEntity.class); |
||||||
|
ticketInfoEntity.setCode(this.getTicketCode(ticketInfoEntity.getType(),ticketInfoEntity.getSignageCode())); |
||||||
|
ticketInfoEntity.setStatus(WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_OPERATE.getStatus()); |
||||||
|
ticketInfoEntity.setFlowTaskName(WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_OPERATE.getDescription()); |
||||||
|
String userName = this.getLicensorNameByDept(Long.parseLong(AuthUtil.getDeptId())); |
||||||
|
ticketInfoEntity.setStepOperator(userName); |
||||||
|
ticketInfoEntity.setNextStepOperator(userName); |
||||||
|
if(this.save(ticketInfoEntity)) { |
||||||
|
Long ticketId = ticketInfoEntity.getId(); |
||||||
|
// 保存安全措施
|
||||||
|
if(CollectionUtil.isNotEmpty(dto.getWorkTicketSafetyMeasureDtoList())) { |
||||||
|
List<WorkTicketSafetyMeasureEntity> measureList = JSONArray.parseArray(JSON.toJSONString(dto.getWorkTicketSafetyMeasureDtoList()), WorkTicketSafetyMeasureEntity.class); |
||||||
|
measureList.forEach(m -> m.setTicketId(ticketId)); |
||||||
|
workTicketSafetyMeasureService.saveBatch(measureList); |
||||||
|
} |
||||||
|
// 保存工作任务
|
||||||
|
if(CollectionUtil.isNotEmpty(dto.getWorkTicketContentDtoList())) { |
||||||
|
List<WorkTicketContentEntity> contentList = JSONArray.parseArray(JSON.toJSONString(dto.getWorkTicketContentDtoList()), WorkTicketContentEntity.class); |
||||||
|
contentList.forEach(c -> c.setTicketId(ticketId)); |
||||||
|
contentService.saveBatch(contentList); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 线下执行任务 |
||||||
|
* @param dto 工作票传参 |
||||||
|
* @return 执行成功与否 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean licenseOfflineTicket(WorkTicketInfoDto dto) { |
||||||
|
String userName = this.getLicensorNameByDept(Long.parseLong(AuthUtil.getDeptId())); |
||||||
|
LambdaUpdateWrapper<WorkTicketInfoEntity> updateWrapper = Wrappers.<WorkTicketInfoEntity>lambdaUpdate() |
||||||
|
.set(WorkTicketInfoEntity::getStatus, WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_LICENSE.getStatus()) |
||||||
|
.set(WorkTicketInfoEntity::getLicensor, AuthUtil.getUserId()) |
||||||
|
.set(WorkTicketInfoEntity::getLicenseTime, LocalDateTime.now()) |
||||||
|
.set(WorkTicketInfoEntity::getLicenseEndTime, dto.getLicenseEndTime()) |
||||||
|
.set(WorkTicketInfoEntity::getStepOperator, userName) |
||||||
|
.set(WorkTicketInfoEntity::getNextStepOperator, userName) |
||||||
|
.eq(WorkTicketInfoEntity::getId, dto.getId()); |
||||||
|
if(this.update(updateWrapper)) { |
||||||
|
// 添加流程消息
|
||||||
|
WorkTicketFlowEntity flowEntity = new WorkTicketFlowEntity(); |
||||||
|
flowEntity.setTicketId(dto.getId()); |
||||||
|
flowEntity.setFlowCode(WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_OPERATE.getStatus().toString()); |
||||||
|
flowEntity.setFirstValue(dto.getLicenseImgUrls()); |
||||||
|
flowEntity.setSecondValue(dto.getLicenseImgFilenames()); |
||||||
|
workTicketFlowService.save(flowEntity); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 线下许可人许可 |
||||||
|
* @param dto 工作票传参 |
||||||
|
* @return 执行成功与否 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean finishOfflineTicket(WorkTicketInfoDto dto) { |
||||||
|
String userName = this.getLicensorNameByDept(Long.parseLong(AuthUtil.getDeptId())); |
||||||
|
LambdaUpdateWrapper<WorkTicketInfoEntity> updateWrapper = Wrappers.<WorkTicketInfoEntity>lambdaUpdate() |
||||||
|
.set(WorkTicketInfoEntity::getStatus, WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_END.getStatus()) |
||||||
|
.set(WorkTicketInfoEntity::getStepOperator, userName) |
||||||
|
.set(WorkTicketInfoEntity::getNextStepOperator, null) |
||||||
|
.eq(WorkTicketInfoEntity::getId, dto.getId()); |
||||||
|
//添加流程信息
|
||||||
|
if(this.update(updateWrapper)) { |
||||||
|
WorkTicketFlowEntity flowEntity = new WorkTicketFlowEntity(); |
||||||
|
flowEntity.setTicketId(dto.getId()); |
||||||
|
flowEntity.setFlowCode(WorkTicketConstants.FirstWorkTicketStatusEnum.OFFLINE_LICENSE.getStatus().toString()); |
||||||
|
flowEntity.setFirstValue(dto.getFinishImgUrls()); |
||||||
|
flowEntity.setSecondValue(dto.getFinishImgFilenames()); |
||||||
|
workTicketFlowService.save(flowEntity); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取工作票票据编号 |
||||||
|
* @param ticketType 票据类型 |
||||||
|
* @param stationCode 站点编号 |
||||||
|
* @return 工作票票据编号 |
||||||
|
*/ |
||||||
|
private String getTicketCode(String ticketType ,String stationCode) { |
||||||
|
String result = ""; |
||||||
|
String signage = WorkTicketConstants.TicketSignageEnum.getTicketSignageByType(ticketType); |
||||||
|
Assert.isTrue(Func.isNotBlank(signage),() -> { |
||||||
|
throw new ServiceException("获取工作票编号失败!"); |
||||||
|
}); |
||||||
|
StationEntity station = new StationEntity(); |
||||||
|
station.setCode(stationCode); |
||||||
|
R<StationEntity> stationR = stationClient.getOne(station); |
||||||
|
Assert.isTrue(stationR.isSuccess() && ObjectUtil.isNotEmpty(stationR.getData()) && Func.isNotEmpty(stationR.getData().getSignage()),() -> { |
||||||
|
throw new ServiceException("该工作票站点下未获取到两票抬头!"); |
||||||
|
}); |
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMM"); |
||||||
|
String yearMonth = YearMonth.now().format(formatter); |
||||||
|
Lock lock = new ReentrantLock(); |
||||||
|
lock.lock(); |
||||||
|
try { |
||||||
|
LocalDateTime date = LocalDateTime.now(); |
||||||
|
LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0); |
||||||
|
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59); |
||||||
|
List<WorkTicketInfoEntity> ticketList = this.list( |
||||||
|
Wrappers.<WorkTicketInfoEntity>lambdaQuery().eq(WorkTicketInfoEntity::getType, ticketType).eq(WorkTicketInfoEntity::getSignageCode, stationCode) |
||||||
|
.ge(WorkTicketInfoEntity::getCreateTime,firstDay).le(WorkTicketInfoEntity::getCreateTime,lastDay) |
||||||
|
|
||||||
|
); |
||||||
|
String suffix = "-" + String.format(String.format("%03d",ticketList.size()+1)); |
||||||
|
result = stationR.getData().getSignage() + "-" + signage + "-" + yearMonth + "-" + suffix; |
||||||
|
} |
||||||
|
finally { |
||||||
|
lock.unlock(); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取机构下许可人名称 |
||||||
|
* @param deptId 机构ID |
||||||
|
* @return 许可人名称,按逗号分隔 |
||||||
|
*/ |
||||||
|
private String getLicensorNameByDept(Long deptId) { |
||||||
|
R<List<User>> usersR = userClient.relationUserListByRoleAlias(AuthUtil.getTenantId(),deptId, TicketConstants.LICENSOR_ROLE); |
||||||
|
if(usersR.isSuccess() && CollectionUtil.isNotEmpty(usersR.getData())) { |
||||||
|
return usersR.getData().stream().map(User::getId).map(UserCache::getUser).map(User::getName).collect(Collectors.joining(",")); |
||||||
|
} |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue