派单2.0
This commit is contained in:
@ -8,7 +8,11 @@ import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.patch.domain.bo.PdMasterProgressReq;
|
||||
import org.dromara.patch.domain.vo.PdMasterProgressVo;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.vo.SysUserVo;
|
||||
import org.dromara.system.service.ISysUserService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
@ -38,36 +42,41 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
public class PdMasterController extends BaseController {
|
||||
|
||||
private final IPdMasterService pdMasterService;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
/**
|
||||
* 新增进度详情
|
||||
* 获取当前用户对应部门下的所有用户
|
||||
*/
|
||||
@SaCheckPermission("patch:master:edit")
|
||||
@PostMapping("/progress")
|
||||
public R<Void> addProgress(@Validated @RequestBody PdMasterProgressVo progress) {
|
||||
if (progress.getSlaveId() == null) {
|
||||
throw new ServiceException("slaveId不能为空,无法更新进度");
|
||||
}
|
||||
// 将slaveId的值赋给updateBy
|
||||
progress.setUpdateBy(progress.getSlaveId());
|
||||
// 如果需要,也可以将slaveName赋给updateByName
|
||||
progress.setUpdateByName(progress.getSlaveName());
|
||||
return toAjax(pdMasterService.addProgress(progress));
|
||||
@SaCheckPermission("patch:master:findThis")
|
||||
@GetMapping("/findThis")
|
||||
public R<List<SysUser>> findThis() {
|
||||
return R.ok(userService.findThis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改进度详情
|
||||
* 新增进度详情
|
||||
*/
|
||||
@SaCheckPermission("patch:master:edit")
|
||||
@PutMapping("/progress")
|
||||
public R<Void> editProgress(@Validated @RequestBody PdMasterProgressVo progress) {
|
||||
return toAjax(pdMasterService.editProgress(progress));
|
||||
@SaCheckPermission("patch:master:progress")
|
||||
@PostMapping("/progress")
|
||||
public R<Void> addProgress(@Validated @RequestBody PdMasterProgressReq progress) {
|
||||
return toAjax(pdMasterService.addProgress(progress));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 修改进度详情
|
||||
// */
|
||||
// @SaCheckPermission("patch:master:editProgress")
|
||||
// @PutMapping("/editProgress")
|
||||
// public R<Void> editProgress(@Validated @RequestBody PdMasterProgressVo progress) {
|
||||
// return toAjax(pdMasterService.editProgress(progress));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除进度详情
|
||||
*/
|
||||
@SaCheckPermission("patch:master:remove")
|
||||
@DeleteMapping("/progress/{id}")
|
||||
@SaCheckPermission("patch:master:removeProgress")
|
||||
@DeleteMapping("/removeProgress/{id}")
|
||||
public R<Void> removeProgress(@PathVariable Long id) {
|
||||
return toAjax(pdMasterService.removeProgress(id));
|
||||
}
|
||||
@ -78,8 +87,8 @@ public class PdMasterController extends BaseController {
|
||||
* @param masterId 派单主表ID
|
||||
* @return 进度详情列表
|
||||
*/
|
||||
@SaCheckPermission("patch:master:query")
|
||||
@GetMapping("/progress/{masterId}")
|
||||
@SaCheckPermission("patch:master:getProgressList")
|
||||
@GetMapping("/getProgressList/{masterId}")
|
||||
public R<List<PdMasterProgressVo>> getProgressList(
|
||||
@NotNull(message = "主表ID不能为空")
|
||||
@PathVariable Long masterId) {
|
||||
|
@ -41,6 +41,5 @@ public class PdMasterSon extends BaseEntity {
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
private Long updateBy;
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ public class PdMasterUser extends BaseEntity {
|
||||
@TableId(type = IdType.INPUT)
|
||||
private Long ordersid;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 执行人id
|
||||
*/
|
||||
|
@ -68,5 +68,15 @@ public class PdMasterBo extends BaseEntity {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 执行人
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 执行人姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package org.dromara.patch.domain.bo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author 铁憨憨
|
||||
* @Date 2025/8/20 20:52
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class PdMasterProgressReq implements Serializable {
|
||||
/**
|
||||
* 进度ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 主表任务ID
|
||||
*/
|
||||
private Long ordersId;
|
||||
|
||||
/**
|
||||
* 进度
|
||||
*/
|
||||
private String progress;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
// /**
|
||||
// * 执行人ID
|
||||
// */
|
||||
// @NotNull(message = "执行人不能你为空")
|
||||
// private Long slaveId;
|
||||
//
|
||||
// /**
|
||||
// * 执行人名字
|
||||
// */
|
||||
// private String slaveName;
|
||||
}
|
@ -45,6 +45,4 @@ public class PdMasterProgressVo {
|
||||
* 执行人名字
|
||||
*/
|
||||
private String slaveName;
|
||||
private Long updateBy; // 新增字段
|
||||
private String updateByName; // 新增字段
|
||||
}
|
||||
|
@ -84,5 +84,17 @@ public class PdMasterVo implements Serializable {
|
||||
@ExcelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 子用户ID
|
||||
*/
|
||||
@ExcelProperty(value = "子用户ID")
|
||||
private Long slaveid;
|
||||
|
||||
/**
|
||||
* 子用户
|
||||
*/
|
||||
@ExcelProperty(value = "子用户")
|
||||
private String slaveName;
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.dromara.patch.domain.PdMaster;
|
||||
import org.dromara.patch.domain.bo.PdMasterProgressReq;
|
||||
import org.dromara.patch.domain.dto.ProgressDetailDto;
|
||||
import org.dromara.patch.domain.vo.PdMasterProgressVo;
|
||||
import org.dromara.patch.domain.vo.PdMasterVo;
|
||||
@ -23,7 +24,7 @@ public interface PdMasterMapper extends BaseMapperPlus<PdMaster, PdMasterVo> {
|
||||
List<PdMasterProgressVo> selectProgressByMasterId(@Param("masterId") Long masterId);
|
||||
|
||||
// 新增进度详情
|
||||
int insertProgress(@Param("progress") PdMasterProgressVo progress);
|
||||
int insertProgress(@Param("progress") PdMasterProgressReq progress);
|
||||
|
||||
// 修改进度详情
|
||||
int updateProgress(@Param("progress") PdMasterProgressVo progress);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dromara.patch.service;
|
||||
|
||||
import org.dromara.patch.domain.bo.PdMasterProgressReq;
|
||||
import org.dromara.patch.domain.vo.PdMasterProgressVo;
|
||||
import org.dromara.patch.domain.vo.PdMasterVo;
|
||||
import org.dromara.patch.domain.bo.PdMasterBo;
|
||||
@ -22,7 +23,7 @@ public interface IPdMasterService extends IService<PdMaster>{
|
||||
void validEntityBeforeSave(PdMaster entity);
|
||||
|
||||
// 新增进度
|
||||
Boolean addProgress(PdMasterProgressVo progress);
|
||||
Boolean addProgress(PdMasterProgressReq progress);
|
||||
|
||||
// 修改进度
|
||||
Boolean editProgress(PdMasterProgressVo progress);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.dromara.patch.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
@ -9,8 +11,15 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.translation.annotation.Translation;
|
||||
import org.dromara.patch.domain.PdMasterSon;
|
||||
import org.dromara.patch.domain.PdMasterUser;
|
||||
import org.dromara.patch.domain.bo.PdMasterProgressReq;
|
||||
import org.dromara.patch.domain.vo.PdMasterProgressVo;
|
||||
import org.dromara.patch.enums.TaskStatusEnum;
|
||||
import org.dromara.patch.service.IPdMasterSonService;
|
||||
import org.dromara.patch.service.IPdMasterUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.dromara.patch.domain.bo.PdMasterBo;
|
||||
import org.dromara.patch.domain.vo.PdMasterVo;
|
||||
@ -18,11 +27,10 @@ import org.dromara.patch.domain.PdMaster;
|
||||
import org.dromara.patch.mapper.PdMasterMapper;
|
||||
import org.dromara.patch.service.IPdMasterService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 派单Service业务层处理
|
||||
@ -36,6 +44,10 @@ public class PdMasterServiceImpl extends ServiceImpl<PdMasterMapper, PdMaster> i
|
||||
|
||||
private final PdMasterMapper baseMapper;
|
||||
|
||||
private final IPdMasterSonService pdMasterSonService;
|
||||
|
||||
private final IPdMasterUserService pdMasterUserService;
|
||||
|
||||
@Override
|
||||
public void validEntityBeforeSave(PdMaster entity) {
|
||||
// 如果有ID(更新操作),计算总进度
|
||||
@ -61,35 +73,44 @@ public class PdMasterServiceImpl extends ServiceImpl<PdMasterMapper, PdMaster> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addProgress(PdMasterProgressVo progress) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean addProgress(PdMasterProgressReq progress) {
|
||||
//获取当前用户,判断是否是这条数据的执行人
|
||||
Long userId = LoginHelper.getUserId();
|
||||
//获取这条数据的执行人
|
||||
PdMasterUser one = pdMasterUserService.getOne(new LambdaQueryWrapper<PdMasterUser>().eq(PdMasterUser::getOrdersid, progress.getOrdersId()));
|
||||
if (one == null) {
|
||||
throw new RuntimeException("执行人未找到!");
|
||||
}
|
||||
if (!Objects.equals(userId, one.getSlaveid())){
|
||||
throw new RuntimeException("执行人不匹配!");
|
||||
}
|
||||
if (progress.getOrdersId() == null) {
|
||||
throw new ServiceException("主表ID不能为空");
|
||||
}
|
||||
if (baseMapper.selectById(progress.getOrdersId()) == null) {
|
||||
throw new ServiceException("派单主表不存在");
|
||||
}
|
||||
|
||||
// 新增进度到pd_master_son表
|
||||
boolean success = baseMapper.insertProgress(progress) > 0;
|
||||
|
||||
if (success) {
|
||||
// 同时向pd_master_user表插入数据
|
||||
// 这里假设progress对象中有updateBy字段,如果没有需要从其他地方获取
|
||||
Long updateBy = progress.getUpdateBy(); // 需要确保PdMasterProgressVo有这个字段
|
||||
String updateByName = progress.getUpdateByName(); // 需要确保PdMasterProgressVo有这个字段
|
||||
|
||||
if (updateBy != null) {
|
||||
// 检查是否已存在关联记录
|
||||
int count = baseMapper.countMasterUser(progress.getOrdersId(), updateBy);
|
||||
if (count == 0) {
|
||||
// 不存在则插入
|
||||
baseMapper.insertMasterUser(progress.getOrdersId(), updateBy, updateByName);
|
||||
}
|
||||
PdMasterSon pdMasterSon = BeanUtil.copyProperties(progress, PdMasterSon.class);
|
||||
if (pdMasterSonService.save(pdMasterSon)) {
|
||||
//判断数据是否百分之百
|
||||
List<PdMasterSon> list = pdMasterSonService.list(new LambdaQueryWrapper<PdMasterSon>().eq(PdMasterSon::getOrdersId, progress.getOrdersId()));
|
||||
BigDecimal bigDecimal = new BigDecimal("0");
|
||||
for (PdMasterSon masterSon : list) {
|
||||
bigDecimal = bigDecimal.add(new BigDecimal(masterSon.getProgress()));
|
||||
}
|
||||
|
||||
updateMasterCompletionProgress(progress.getOrdersId());
|
||||
//bigDecimal是否为100,100变更数据状态
|
||||
if (bigDecimal.compareTo(new BigDecimal("100")) == 0){
|
||||
//更新主表状态
|
||||
PdMaster pdMaster = baseMapper.selectById(progress.getOrdersId());
|
||||
pdMaster.setTaskStatus(TaskStatusEnum.FINISHED.getValue());
|
||||
pdMaster.setAct(new Date());
|
||||
baseMapper.updateById(pdMaster);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return success;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public Boolean editProgress(PdMasterProgressVo progress) {
|
||||
@ -153,7 +174,17 @@ public class PdMasterServiceImpl extends ServiceImpl<PdMasterMapper, PdMaster> i
|
||||
*/
|
||||
@Override
|
||||
public PdMasterVo queryById(Long id){
|
||||
return baseMapper.selectVoById(id);
|
||||
//1、获取基础数据
|
||||
PdMasterVo pdMasterVo = baseMapper.selectVoById(id);
|
||||
//2、查询下面的用户
|
||||
LambdaQueryWrapper<PdMasterUser> eq = new LambdaQueryWrapper<PdMasterUser>().eq(PdMasterUser::getOrdersid, pdMasterVo.getId());
|
||||
PdMasterUser one = pdMasterUserService.getOne(eq);
|
||||
if (one == null) {
|
||||
throw new ServiceException("子用户不存在");
|
||||
}
|
||||
pdMasterVo.setSlaveid(one.getSlaveid());
|
||||
pdMasterVo.setSlaveName(one.getSlaveName());
|
||||
return pdMasterVo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,6 +198,15 @@ public class PdMasterServiceImpl extends ServiceImpl<PdMasterMapper, PdMaster> i
|
||||
public TableDataInfo<PdMasterVo> queryPageList(PdMasterBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<PdMaster> lqw = buildQueryWrapper(bo);
|
||||
Page<PdMasterVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
//获取当前主数据下面的进度百分比
|
||||
result.getRecords().forEach(item -> {
|
||||
List<PdMasterSon> list = pdMasterSonService.list(new LambdaQueryWrapper<PdMasterSon>().eq(PdMasterSon::getOrdersId, item.getId()));
|
||||
BigDecimal bigDecimal = new BigDecimal("0");
|
||||
for (PdMasterSon pdMasterSon : list) {
|
||||
bigDecimal = bigDecimal.add(new BigDecimal(pdMasterSon.getProgress()));
|
||||
}
|
||||
item.setCompletionProgress(bigDecimal+"%");
|
||||
});
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@ -204,11 +244,18 @@ public class PdMasterServiceImpl extends ServiceImpl<PdMasterMapper, PdMaster> i
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(PdMasterBo bo) {
|
||||
//1、新增数据
|
||||
PdMaster add = MapstructUtils.convert(bo, PdMaster.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
//2、增加子用户
|
||||
PdMasterUser pdMasterUser = new PdMasterUser();
|
||||
pdMasterUser.setOrdersid(add.getId());
|
||||
pdMasterUser.setSlaveid(bo.getUserId());
|
||||
pdMasterUser.setSlaveName(bo.getUserName());
|
||||
pdMasterUserService.save(pdMasterUser);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
@ -221,9 +268,21 @@ public class PdMasterServiceImpl extends ServiceImpl<PdMasterMapper, PdMaster> i
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(PdMasterBo bo) {
|
||||
//1、修改数据
|
||||
PdMaster update = MapstructUtils.convert(bo, PdMaster.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
if (baseMapper.updateById(update) > 0){
|
||||
//2、删除子用户
|
||||
pdMasterUserService.remove(new LambdaQueryWrapper<PdMasterUser>().eq(PdMasterUser::getOrdersid, bo.getId()));
|
||||
//3、新增子用户
|
||||
PdMasterUser pdMasterUser = new PdMasterUser();
|
||||
pdMasterUser.setOrdersid(update.getId());
|
||||
pdMasterUser.setSlaveid(bo.getUserId());
|
||||
pdMasterUser.setSlaveName(bo.getUserName());
|
||||
pdMasterUserService.save(pdMasterUser);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,21 +5,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<mapper namespace="org.dromara.patch.mapper.PdMasterMapper">
|
||||
<select id="selectProgressByMasterId" resultType="org.dromara.patch.domain.vo.PdMasterProgressVo">
|
||||
SELECT
|
||||
s.id,
|
||||
s.orders_id as ordersId,
|
||||
s.progress,
|
||||
s.remark,
|
||||
s.update_time as updateTime,
|
||||
u.slaveid as slaveId,
|
||||
u.slave_name as slaveName
|
||||
a.*,b.slave_name
|
||||
FROM
|
||||
pd_master m
|
||||
INNER JOIN pd_master_user u ON m.id = u.ordersid
|
||||
INNER JOIN pd_master_son s ON m.id = s.orders_id
|
||||
pd_master_son as a
|
||||
LEFT JOIN pd_master_user as b on b.ordersid =a.orders_id
|
||||
WHERE
|
||||
m.id = #{masterId}
|
||||
ORDER BY
|
||||
s.update_time DESC
|
||||
orders_id = #{masterId}
|
||||
</select>
|
||||
|
||||
<!-- 新增进度详情 -->
|
||||
@ -41,11 +32,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<delete id="deleteProgressById">
|
||||
DELETE FROM pd_master_son WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
|
||||
<select id="selectTotalProgressByMasterId" resultType="java.lang.Double">
|
||||
SELECT COALESCE(SUM(CAST(REPLACE(progress, '%', '') AS DECIMAL(5,2))), 0)
|
||||
FROM pd_master_son
|
||||
WHERE orders_id = #{masterId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectProgressById" resultType="org.dromara.patch.domain.vo.PdMasterProgressVo">
|
||||
SELECT id, orders_id as ordersId, progress, remark, update_time as updateTime, update_by as updateBy
|
||||
FROM pd_master_son
|
||||
|
Reference in New Issue
Block a user