This commit is contained in:
PQZ 2024-10-23 23:19:06 +08:00
commit 43a059c63c
10 changed files with 403 additions and 63 deletions

View File

@ -0,0 +1,61 @@
package cn.iocoder.yudao.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 维修工单子表配件/项目状态枚举
*
* @author vinjor-m
*/
@AllArgsConstructor
@Getter
public enum TicketsItemStatusEnum {
/**
* 待派工
*/
WAITING_WORK("01","待派工"),
/**
* 施工中
*/
WORKING("02","施工中"),
/**
* 已完成
*/
DONE("03","已完成"),
/**
* 未领料
*/
WAITING_RECEIVE("04","未领料"),
/**
* 已领料
*/
RECEIVED("05","已领料");
/**
* code
*/
private String code;
/**
* 名称
*/
private String name;
/**
* 根据code返回对应的枚举
* @author vinjor-M
* @date 14:23 2024/10/16
* @param code 枚举code
* @return cn.iocoder.yudao.common.SystemEnum
**/
public static TicketsItemStatusEnum getEnumByCode(String code) {
for (TicketsItemStatusEnum roleEnum : TicketsItemStatusEnum.values()) {
if (roleEnum.getCode().equalsIgnoreCase(code)) {
// 找到对应的枚举
return roleEnum;
}
}
throw new IllegalArgumentException("无效的枚举code" + code);
}
}

View File

@ -34,7 +34,6 @@ public class DlRepairTicketsController {
private DlRepairTicketsService dlRepairTicketsService;
/**
* 维修工单表 新增
*
@ -140,7 +139,7 @@ public class DlRepairTicketsController {
@GetMapping("/print/{id}")
@Operation(summary = "维修工单打印")
public void printDocument(HttpServletResponse response, @PathVariable String id) {
dlRepairTicketsService.print(response,id);
dlRepairTicketsService.print(response, id);
}
/**
@ -160,19 +159,19 @@ public class DlRepairTicketsController {
/**
* 分类查询工单分页
*
* @param repairTicketsReqVO 查询对象
* @param pageNo 页码
* @param pageSize 条数
* @author 小李
* @date 16:26 2024/10/12
* @param repairTicketsReqVO 查询对象
* @param pageNo 页码
* @param pageSize 条数
**/
**/
@GetMapping("/pageType")
@Operation(summary = "分类查询工单分页")
public CommonResult<?> getPageType(DlRepairTicketsReqVO repairTicketsReqVO,
@RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
Page<DlRepairTickets> page = new Page<>(pageNo, pageSize);
if(StringUtils.isEmpty(repairTicketsReqVO.getSelectType())){
if (StringUtils.isEmpty(repairTicketsReqVO.getSelectType())) {
//查询类型为空默认查待处理的
repairTicketsReqVO.setSelectType(RepairCons.TICKETS_WAITING);
}
@ -187,20 +186,20 @@ public class DlRepairTicketsController {
**/
@GetMapping("/userRole")
@Operation(summary = "判断登录用户的角色,针对维修工单中的四个角色")
public CommonResult<?> getUserRole(){
public CommonResult<?> getUserRole() {
return success(dlRepairTicketsService.getUserRole());
}
/**
* 接单
*
* @param id 工单ID
* @author 小李
* @date 11:48 2024/10/14
* @param id 工单ID
**/
**/
@GetMapping("/take")
@Operation(summary = "接单")
public CommonResult<?> updateTake(@RequestParam("id") String id){
public CommonResult<?> updateTake(@RequestParam("id") String id) {
dlRepairTicketsService.updateTake(id);
return CommonResult.ok();
}
@ -208,13 +207,13 @@ public class DlRepairTicketsController {
/**
* 指派员工通知施工
*
* @param reqVO 请求对象
* @author 小李
* @date 15:34 2024/10/14
* @param reqVO 请求对象
**/
**/
@PostMapping("/notify")
@Operation(summary = "指派员工,通知施工")
public CommonResult<?> updateRepair(@RequestBody DlRepairTicketsReqVO reqVO){
public CommonResult<?> updateRepair(@RequestBody DlRepairTicketsReqVO reqVO) {
dlRepairTicketsService.updateRepair(reqVO);
return CommonResult.ok();
}
@ -222,13 +221,13 @@ public class DlRepairTicketsController {
/**
* 更新工单状态
*
* @param respVO 请求对象
* @author 小李
* @date 15:46 2024/10/18
* @param respVO 请求对象
**/
**/
@PostMapping("/updateStatus")
@Operation(summary = "更新工单状态")
public CommonResult<?> updateStatus(@RequestBody DlRepairTicketsRespVO respVO){
public CommonResult<?> updateStatus(@RequestBody DlRepairTicketsRespVO respVO) {
dlRepairTicketsService.updateStatus(respVO);
return CommonResult.ok();
}
@ -236,14 +235,14 @@ public class DlRepairTicketsController {
/**
* 配件客户是否可见
*
* @param id 工单ID
* @param show 是否可见
* @author 小李
* @date 21:52 2024/10/18
* @param id 工单ID
* @param show 是否可见
**/
**/
@GetMapping("/show")
@Operation(summary = "配件客户是否可见")
public CommonResult<?> updateShow(@RequestParam("id") String id, @RequestParam("show") String show){
public CommonResult<?> updateShow(@RequestParam("id") String id, @RequestParam("show") String show) {
dlRepairTicketsService.updateShow(id, show);
return CommonResult.ok();
}
@ -252,19 +251,47 @@ public class DlRepairTicketsController {
* 查待总检或待出厂检验的工单
* 维修服务顾问和总检用的
*
* @param repairTicketsReqVO 请求对象
* @param pageNo 页码
* @param pageSize 条数
* @author 小李
* @date 11:40 2024/10/23
* @param repairTicketsReqVO 请求对象
* @param pageNo 页码
* @param pageSize 条数
**/
**/
@GetMapping("/pageByRole")
@Operation(summary = "查待总检或待出厂检验的工单")
public CommonResult<?> getPageByRole(DlRepairTicketsReqVO repairTicketsReqVO,
@RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
Page<DlRepairTickets> page = new Page<>(pageNo, pageSize);
return success(dlRepairTicketsService.getPageByRole(repairTicketsReqVO, page));
}
/**
* 维修总检完成总检
*
* @author 小李
* @date 16:48 2024/10/23
* @param respVO 请求对象
**/
@PostMapping("/inspection")
@Operation(summary = "维修总检完成总检")
public CommonResult<?> inspection(@RequestBody DlRepairTicketsRespVO respVO) {
dlRepairTicketsService.inspection(respVO);
return CommonResult.ok();
}
/**
* 服务顾问上传出厂检验日志
*
* @author 小李
* @date 17:47 2024/10/23
* @param respVO 请求对象
**/
@PostMapping("/confirm")
@Operation(summary = "服务顾问上传出厂检验日志")
public CommonResult<?> confirm(@RequestBody DlRepairTicketsRespVO respVO) {
dlRepairTicketsService.confirm(respVO);
return CommonResult.ok();
}
}

View File

@ -145,4 +145,22 @@ public interface DlRepairTicketsService extends IService<DlRepairTickets> {
* @param repairTicketsReqVO 请求对象
**/
IPage<DlRepairTickets> getPageByRole(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page);
/**
* 维修总检完成总检
*
* @author 小李
* @date 16:48 2024/10/23
* @param respVO 请求对象
**/
void inspection(DlRepairTicketsRespVO respVO);
/**
* 服务顾问上传出厂检验日志
*
* @author 小李
* @date 17:47 2024/10/23
* @param respVO 请求对象
**/
void confirm(DlRepairTicketsRespVO respVO);
}

View File

@ -55,7 +55,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -188,6 +187,13 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
// 新增子表
itemList.forEach(item -> {
item.setTicketId(ticketsRespVO.getId());
if("01".equals(item.getItemType())){
//维修项目,初始状态待派工
item.setItemStatus(TicketsItemStatusEnum.WAITING_WORK.getCode());
}else if("02".equals(item.getItemType())){
//维修配件初始状态待领料
item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
}
});
titemService.saveBatch(itemList);
@ -424,9 +430,15 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
@Override
public IPage<DlRepairTickets> getPageType(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page) {
String userRoleCode = getUserRole();
if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode()) || userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())) {
if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())) {
//维修管理员和总检看所有数据
} else if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
} else if(userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){
//总检
if (RepairCons.TICKETS_WAITING.equals(repairTicketsReqVO.getSelectType())) {
//查待处理的查需要自己处理的否则就是查所有
repairTicketsReqVO.setUserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
}
}else if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
//服务顾问看自己的
repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
} else if (userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())) {
@ -550,7 +562,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
}
/**
* 更新工单状态
* 更新工单状态(针对开始施工施工中记录施工完成)
*
* @param respVO 请求对象
* @author 小李
@ -560,9 +572,9 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
@DSTransactional
public void updateStatus(DlRepairTicketsRespVO respVO) {
// 如果是开始施工但项目还在施工中就不能施工
if (respVO.getRecordType().equals("kssg")){
if (RecordTypeEnum.KSSG.getCode().equals(respVO.getRecordType())){
DlRepairTitem titem = titemService.getById(respVO.getItem().getId());
if (titem.getItemStatus().equals("02")){
if (TicketsItemStatusEnum.WORKING.getCode().equals(titem.getItemStatus())){
throw exception0(500, "选择的项目在施工中,不能重新开始施工");
}
}
@ -572,9 +584,10 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
LambdaUpdateWrapper<DlRepairTickets> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(DlRepairTickets::getId, respVO.getId());
wrapper.set(DlRepairTickets::getTicketsWorkStatus, respVO.getTicketsWorkStatus());
if (ObjectUtil.isNotEmpty(respVO.getIsFinish())) {
wrapper.set(DlRepairTickets::getIsFinish, respVO.getIsFinish());
}
// 这里注掉不能让员工更新工单的状态为完成后面还有总检服务顾问
// if (ObjectUtil.isNotEmpty(respVO.getIsFinish())) {
// wrapper.set(DlRepairTickets::getIsFinish, respVO.getIsFinish());
// }
baseMapper.update(wrapper);
}
if (null != respVO.getItem() && StringUtils.isNotEmpty(respVO.getItem().getItemStatus())) {
@ -603,8 +616,13 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
String message = createMessage(tickets.getNowRepairName(), tickets.getTicketNo(), titem.getItemName(), respVO.getRecordType(), respVO.getFinishType(), respVO.getNextName());
// 通知服务顾问
// 如果员工完成了订单
if (respVO.getRecordType().equals("sgwczj") && respVO.getFinishType().equals("03")) {
repairWorkerService.sentMessage(Long.valueOf(tickets.getAdviserId()), "您有新的工单可以交车");
if (RecordTypeEnum.SGWCZJ.getCode().equals(respVO.getRecordType())&& "03".equals(respVO.getFinishType())) {
repairWorkerService.sentMessage(Long.valueOf(tickets.getAdviserId()), "您有新的工单可以出厂检验");
// 需要把工单的当前操作人移交服务顾问
baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
.setSql("now_repair_id = adviser_id")
.setSql("now_repair_name = adviser_name")
.eq(DlRepairTickets::getId, respVO.getId()));
} else {
repairWorkerService.sentMessage(Long.valueOf(tickets.getAdviserId()), message);
}
@ -616,12 +634,13 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId());
if (CollectionUtil.isEmpty(ids)) return;
// 如果是移交给总检就需要通知总检并让其总检
if (respVO.getRecordType().equals("sgwczj") && respVO.getFinishType().equals("02")) {
if (RecordTypeEnum.SGWCZJ.getCode().equals(respVO.getRecordType()) && "02".equals(respVO.getFinishType())) {
// 工单移交给总检(理论上讲只有一个总检就算有多个这里面也只给一个)
AdminUserRespDTO user = adminUserApi.getUser(ids.get(0));
baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
.set(DlRepairTickets::getNowRepairId, user.getId())
.set(DlRepairTickets::getNowRepairName, user.getNickname())
.set(DlRepairTickets::getTicketsWorkStatus, "05")
.eq(DlRepairTickets::getId, respVO.getId()));
repairWorkerService.sentMessage(user.getId(), "您有新的工单需要总检");
} else {
@ -642,7 +661,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
return result + "上传了工单:" + no + "" + projectName + "项目的维修记录";
// 施工完成
case "sgwczj":
if (ObjectUtil.isNotEmpty(finishType)){
if (ObjectUtil.isNotEmpty(finishType)) {
result = result + "完成了工单:" + no + "" + projectName + "项目";
switch (finishType) {
// 完成并移交下一班组
@ -657,7 +676,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
default:
return "异常消息";
}
}else {
} else {
return result + "部分完成了工单:" + no + "" + projectName + "项目";
}
default:
@ -685,24 +704,72 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
* 查待总检或待出厂检验的工单
* 维修服务顾问和总检用的
*
* @param repairTicketsReqVO 请求对象
* @author 小李
* @date 11:40 2024/10/23
* @param repairTicketsReqVO 请求对象
**/
@Override
public IPage<DlRepairTickets> getPageByRole(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page){
public IPage<DlRepairTickets> getPageByRole(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page) {
String userRoleCode = getUserRole();
// 当前操作人的id
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
// 维修服务顾问
if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){
}else if (userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){
if (userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
repairTicketsReqVO.setNowRepairId(loginUserId);
repairTicketsReqVO.setIsFinish("1");
} else if (userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())) {
// 总检
}else {
repairTicketsReqVO.setNowRepairId(loginUserId);
repairTicketsReqVO.setIsFinish("0");
} else {
return null;
}
// 还是用分类查询不过需要重新构造查询条件 todo
// 还是用分类查询不过需要重新构造查询条件
return baseMapper.getPageType(repairTicketsReqVO, page);
}
/**
* 维修总检完成总检
*
* @author 小李
* @date 16:48 2024/10/23
* @param respVO 请求对象
**/
@Override
@DSTransactional
public void inspection(DlRepairTicketsRespVO respVO){
// 新增日志
repairRecordsService.saveRepairRecord(respVO.getId(), null, RecordTypeEnum.ZJ.getCode(), respVO.getRemark(), respVO.getImage());
// 更新工单
baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
.set(DlRepairTickets::getIsFinish, "1")
.setSql("now_repair_id = adviser_id")
.setSql("now_repair_name = adviser_name")
.eq(DlRepairTickets::getId, respVO.getId())
);
// 通知服务顾问
DlRepairTickets tickets = baseMapper.selectById(respVO.getId());
repairWorkerService.sentMessage(Long.valueOf(tickets.getAdviserId()), "您有新的工单可以出厂检验");
}
/**
* 服务顾问上传出厂检验日志
*
* @author 小李
* @date 17:47 2024/10/23
* @param respVO 请求对象
**/
@Override
public void confirm(DlRepairTicketsRespVO respVO){
// 更新工单状态
baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
.set(DlRepairTickets::getTicketsWorkStatus, "03")
.eq(DlRepairTickets::getId, respVO.getId())
);
// 记录日志
repairRecordsService.saveRepairRecord(respVO.getId(), null, RecordTypeEnum.JSGD.getCode(), respVO.getRemark(), respVO.getImage());
}
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.RepairRoleEnum;
import cn.iocoder.yudao.common.SoStatusEnum;
import cn.iocoder.yudao.common.TicketsItemStatusEnum;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.base.entity.RepairWorker;
@ -40,6 +41,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
@ -224,18 +226,55 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
@DSTransactional
public void auditTicketWares(DlTicketWaresRespVO respVO) {
// 设置单据状态
baseMapper.update(new LambdaUpdateWrapper<DlTicketWares>()
.set(DlTicketWares::getStatus, respVO.getStatus())
.eq(DlTicketWares::getId, respVO.getId())
);
//配件申请单id
String mainId = respVO.getId();
//单据类型现在只有配件申请单 01
String type = respVO.getType();
//单据状态 02 通过 05驳回
String status = respVO.getStatus();
//配件信息
List<DlRepairTitem> repairItemList = respVO.getWares();
DlTicketWares updateObj = this.getById(mainId);
String ticketMainId = updateObj.getTicketId();
updateObj.setStatus(status);
this.updateById(updateObj);
// 如果是通过并且是领料就还需要把配件信息加入到工单中
if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("01")) {
if (ObjectUtil.isNotEmpty(status) && status.equals("02") && type.equals("01")) {
// 更新维修工单
if(null== repairItemList || repairItemList.isEmpty()){
repairItemList = new ArrayList<>();
//配件没传去库里面查需要的配件
LambdaQueryWrapper<DlTwItem> queryWrapper= new LambdaQueryWrapper<DlTwItem>()
.eq(DlTwItem::getTwId,mainId);
List<DlTwItem> applyList = twItemService.list(queryWrapper);
if(!applyList.isEmpty()){
//查配件库
List<RepairWares> waresList = repairWaresService.listByIds(applyList.stream().map(DlTwItem::getWaresId).collect(Collectors.toList()));
Map<String,RepairWares> waresMap =waresList.stream().collect(Collectors.toMap(RepairWares::getId, Function.identity()));
//组装工单子表数据
for (DlTwItem item:applyList){
DlRepairTitem repairTitem = new DlRepairTitem();
repairTitem.setTicketId(ticketMainId);
repairTitem.setItemCount(item.getWaresCount());
repairTitem.setItemName(item.getWaresName());
repairTitem.setItemUnit(waresMap.get(item.getWaresId()).getUnit());
repairTitem.setItemPrice(new BigDecimal(waresMap.get(item.getWaresId()).getPrice()));
//默认不打折为1
repairTitem.setItemDiscount(new BigDecimal(1));
repairTitem.setItemMoney(new BigDecimal(repairTitem.getItemCount()).multiply(repairTitem.getItemPrice()));
//类型是配件
repairTitem.setItemType("02");
repairTitem.setPartId(item.getWaresId());
repairTitem.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
repairItemList.add(repairTitem);
}
}
}
// 计算配件的总价
BigDecimal reduce = respVO.getWares().stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal reduce = repairItemList.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
repairTicketsService.update(new LambdaUpdateWrapper<DlRepairTickets>()
// 工单子项总数量增加上配件的数量
.setSql("count = count + " + respVO.getWares().size())
.setSql("count = count + " + repairItemList.size())
// 工单配件总价
.setSql("part_price = part_price + " + reduce)
// 工单总价
@ -246,18 +285,18 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
.setSql("profit = profit + " + reduce)
// 领料状态
.set(DlRepairTickets::getPartStatus, "02")
.eq(DlRepairTickets::getId, respVO.getTicketId())
.eq(DlRepairTickets::getId, ticketMainId)
);
// 更新维修工单子表
respVO.getWares().forEach(item -> {
repairItemList.forEach(item -> {
// 主表id
item.setTicketId(respVO.getTicketId());
item.setTicketId(ticketMainId);
// 类型为配件
item.setItemType("02");
// 状态为未领料
item.setItemStatus("08");
item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
});
repairTitemService.saveBatch(respVO.getWares());
repairTitemService.saveBatch(repairItemList);
// 发送通过的消息给仓库
RoleReqDTO roleInfo = roleApi.getRoleInfo(RepairRoleEnum.WAREHOUSE.getCode());

View File

@ -226,6 +226,9 @@
</when>
</choose>
</if>
<if test="map.nowRepairId != null and map.nowRepairId != ''">
and drt.now_repair_id = #{map.nowRepairId}
</if>
order by drt.create_time desc
</select>

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.rescue.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.rescue.service.IRescueOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/rescue/bigScree")
public class RescueBigScreeController {
@Autowired
private IRescueOrderInfoService rescueOrderInfoService;
/**
*
* @param type count 数量 money 金额
* @param timeType day month year
* @return
*/
@GetMapping("/getRescueOrderCount")
public CommonResult getRescueOrderCount(String type, String timeType){
return CommonResult.success(rescueOrderInfoService.getRescueOrderCount(type,timeType));
}
}

View File

@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 救援订单Mapper接口
@ -33,5 +34,4 @@ public interface RescueOrderInfoMapper extends BaseMapper<RescueOrderInfo>
*/
public List<RescueOrderInfo> selectRescueOrderInfoList(RescueOrderInfo rescueOrderInfo);
Double avgPartnerScore(@Param("driverId") Long driverId);
}

View File

@ -69,4 +69,12 @@ public interface IRescueOrderInfoService extends IService<RescueOrderInfo>
RescueOrderInfo getOrderByOrderNo(String orderNo);
Map<String, String> payNotify( JSONObject jsonObject);
public void reviewOrder(String rescueId, Integer starLevel, String reviewStr) throws Exception;
/**
*
* @param type count 数量 money 金额
* @param timeType day month year
* @return
*/
List<Map<String, Object>> getRescueOrderCount(String type, String timeType);
}

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.rescue.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.module.rescue.domain.*;
@ -22,6 +25,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
@ -313,4 +317,91 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
driverInfoService.updateById(driverInfo);
}
}
/**
* @param type count 数量 money 金额
* @param timeType day month year
* @return
*/
@Override
public List<Map<String, Object>> getRescueOrderCount(String type, String timeType) {
List<Map<String, Object>> res = new ArrayList<>();
DateTime startTime = DateUtil.date();
DateTime endTime = new DateTime();
List<DateTime> dateList = new ArrayList<>();
switch (timeType) {
case "day":
startTime = DateUtil.beginOfDay(startTime);
endTime = DateUtil.endOfDay(endTime);
dateList = DateUtil.rangeToList(startTime, endTime, DateField.HOUR_OF_DAY);
break;
case "month":
startTime = DateUtil.beginOfMonth(startTime);
endTime = DateUtil.endOfMonth(endTime);
dateList = DateUtil.rangeToList(startTime, endTime, DateField.DAY_OF_MONTH);
break;
case "year":
startTime = DateUtil.beginOfYear(startTime);
endTime = DateUtil.endOfYear(endTime);
dateList = DateUtil.rangeToList(startTime, endTime, DateField.MONTH);
break;
}
LambdaQueryWrapper<RescueOrderInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.between(RescueOrderInfo::getCreateTime, startTime, endTime);
queryWrapper.eq(RescueOrderInfo::getOrderStatus, "3");
List<RescueOrderInfo> list = this.list(queryWrapper);
for (DateTime dateTime : dateList) {
String name = "";
switch (timeType) {
case "day":
name = dateTime.toString("HH:mm");
break;
case "month":
name = dateTime.toString("MM-dd");
break;
case "year":
name = dateTime.toString("YYYY-MM");
break;
}
Map<String, Object> map = new HashMap<>();
DateTime endTime1 = getEndTime(timeType, dateTime);
List<RescueOrderInfo> rescueOrderInfos = filterOrdersByDate(list, dateTime, endTime1);
map.put("name", name);
if ("count".equals(type)) {
long count = rescueOrderInfos.stream().count();
map.put("value", count);
}else if ("money".equals(type)) {
// 使用 stream() 计算总金额并防止空指针异常
long money = rescueOrderInfos.stream()
.filter(Objects::nonNull) // 过滤掉 null 对象
.filter(order -> Objects.nonNull(order.getPayMoney())) // 过滤掉 payMoney null 的对象
.mapToLong(RescueOrderInfo::getPayMoney) // 获取支付金额
.sum(); // 计算总和
//将分转为元
map.put("value", (double)money / 100);
}
res.add(map);
}
return res;
}
public DateTime getEndTime(String timeType, DateTime startTime){
switch (timeType) {
case "day":
return DateUtil.endOfHour(startTime);
case "month":
return DateUtil.endOfDay(startTime);
case "year":
return DateUtil.endOfMonth(startTime);
}
return null;
}
public List<RescueOrderInfo> filterOrdersByDate(List<RescueOrderInfo> orders, Date startDate, Date endDate) {
return orders.stream()
.filter(order -> order.getOrderTime() != null &&
!order.getOrderTime().before(startDate) &&
!order.getOrderTime().after(endDate))
.collect(Collectors.toList());
}
}