领料出库

This commit is contained in:
mashuai 2025-03-06 10:26:16 +08:00
parent cce535a7c1
commit c67af6e590
9 changed files with 310 additions and 7 deletions

View File

@ -73,8 +73,9 @@ public class LeaseApplyInfoController extends BaseController {
//@RequiresPermissions("lease:info:query")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@NotNull(message = "领料任务ID不能为空") @PathVariable("id") Long id,
@RequestParam(value = "keyWord", required = false) String keyWord) {
return success(leaseApplyInfoService.selectLeaseApplyInfoById(id, keyWord));
@RequestParam(value = "keyWord", required = false) String keyWord,
@RequestParam(value = "publishTask", required = false) String publishTask) {
return success(leaseApplyInfoService.selectLeaseApplyInfoById(id, keyWord, publishTask));
}
/**

View File

@ -133,4 +133,12 @@ public interface LeaseApplyDetailsMapper {
* @return
*/
List<LeaseOutVo> selectByMaId(Long maId);
/**
* 根据领料任务id查询领料任务详细
* @param publishTask
* @return
*/
List<LeaseApplyDetails> getDetailsPublish(String publishTask);
}

View File

@ -73,4 +73,11 @@ public interface LeaseApplyInfoMapper {
/** 设置发料单位 防止代码冲突 **/
String getSendUnit(LeaseApplyInfo leaseApplyInfo);
/**
* 查询领用出库数据
* @param leaseApplyInfo
* @return
*/
List<LeaseApplyInfo> selectPublishList(LeaseApplyInfo leaseApplyInfo);
}

View File

@ -24,9 +24,10 @@ public interface ILeaseApplyInfoService {
*
* @param id 领料任务主键
* @param keyword keyword 关键字
* @param publishTask 发布批次
* @return 领料任务
*/
LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword);
LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword, String publishTask);
/**
* 查询领料任务列表

View File

@ -80,7 +80,7 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
* @return 领料任务
*/
@Override
public LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword) {
public LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword, String publishTask) {
try {
LeaseApplyInfo leaseApplyInfo = new LeaseApplyInfo();
leaseApplyInfo.setId(id);
@ -125,6 +125,23 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
}
});
// 走单独的领用详情查询
if (StringUtils.isNotBlank(publishTask)) {
LeaseApplyRequestVo info = new LeaseApplyRequestVo();
// 根据领用批次查询领用详情
List<LeaseApplyDetails> details = leaseApplyDetailsMapper.getDetailsPublish(publishTask);
if (!CollectionUtils.isEmpty(details)) {
for (LeaseApplyDetails detail : details) {
if (detail.getOutNum().compareTo(detail.getAlNum()) == 0) {
detail.setStatus("1");
} else {
detail.setStatus("0");
}
}
info.setLeaseApplyDetailsList(details);
}
return info;
}
return leaseApplyRequestVo;
} catch (Exception e) {
@ -145,16 +162,29 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
public List<LeaseApplyInfo> selectLeaseApplyInfoList(LeaseApplyInfo leaseApplyInfo) {
leaseApplyInfo.setUserId(SecurityUtils.getUserId());
List<LeaseApplyInfo> list = leaseApplyInfoMapper.selectLeaseApplyInfoList(leaseApplyInfo);
if (!CollectionUtils.isEmpty(list)) {
// 如果statusList包含345则为领料出库查询需查询领用出库数据进行拼接
if (leaseApplyInfo.getStatusList() != null && leaseApplyInfo.getStatusList().contains(3)
&& leaseApplyInfo.getStatusList().contains(4) && leaseApplyInfo.getStatusList().contains(5)) {
// 查询领用出库数据
List<LeaseApplyInfo> leaseApplyOutList = leaseApplyInfoMapper.selectPublishList(leaseApplyInfo);
if (!CollectionUtils.isEmpty(leaseApplyOutList)) {
list.addAll(leaseApplyOutList);
}
}
// 使用 Stream API 进行降序排序
List<LeaseApplyInfo> sortedList = list.stream()
.sorted(Comparator.comparing(LeaseApplyInfo::getCreateTime).reversed())
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sortedList)) {
String keyWord = leaseApplyInfo.getKeyWord();
// 如果关键字不为空进行过滤
if (!StringUtils.isBlank(keyWord)) {
list = list.stream()
sortedList = sortedList.stream()
.filter(item -> containsKeyword(item, keyWord))
.collect(Collectors.toList());
}
}
return list;
return sortedList;
}
/**
@ -183,6 +213,59 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
*/
@Override
public AjaxResult insertLeaseApplyInfo(LeaseApplyRequestVo leaseApplyRequestVo) {
/*int result = 0;
if (null == leaseApplyRequestVo.getLeaseApplyInfo()) {
return AjaxResult.error("请先填写领料任务信息");
}
if (CollectionUtil.isEmpty(leaseApplyRequestVo.getLeaseApplyDetailsList())) {
return AjaxResult.error("请先添加领料任务物资明细");
}
leaseApplyRequestVo.getLeaseApplyInfo().setCreateTime(DateUtils.getNowDate());
leaseApplyRequestVo.getLeaseApplyInfo().setCreateBy(SecurityUtils.getUsername());
try {
// 获取 LeaseApplyDetails 列表
List<LeaseApplyDetails> leaseApplyDetailsList = leaseApplyRequestVo.getLeaseApplyDetailsList();
for (LeaseApplyDetails applyDetails : leaseApplyDetailsList) {
if (applyDetails.getCompanyId() == null) {
throw new RuntimeException("未知所属公司领料任务,无法操作!");
}
}
// companyId 进行分组
Map<Long, List<LeaseApplyDetails>> groupedByCompanyId = leaseApplyDetailsList.stream()
.collect(Collectors.groupingBy(LeaseApplyDetails::getCompanyId));
for (Map.Entry<Long, List<LeaseApplyDetails>> entry : groupedByCompanyId.entrySet()) {
Long key = entry.getKey();
List<LeaseApplyDetails> details = entry.getValue();
TmTaskTypeEnum splitType = null;
String taskTypeLabel = null;
// 机具领料任务
if (key == 101) {
splitType = TmTaskTypeEnum.TM_TASK_JJ_LEASE;
taskTypeLabel = MaterialConstants.JJ_LEASE_TASK_TYPE_LABEL;
// 安全工器具领料任务
} else if (key == 102) {
splitType = TmTaskTypeEnum.TM_TASK_SAFE_LEASE;
taskTypeLabel = MaterialConstants.AQ_LEASE_TASK_TYPE_LABEL;
// 宏源领料任务
} else if (key == 309) {
splitType = TmTaskTypeEnum.TM_TASK_HY_LEASE;
taskTypeLabel = MaterialConstants.HY_LEASE_TASK_TYPE_LABEL;
} else {
throw new RuntimeException("未知所属公司领料任务,无法操作!");
}
result += processLeaseTask(leaseApplyRequestVo, splitType, taskTypeLabel);
if (result > 0) {
return insertPurchaseCheckDetails(details, leaseApplyRequestVo.getLeaseApplyInfo().getId());
} else {
return AjaxResult.error("新增任务失败,lease_apply_info表插入0条");
}
}
} catch (DataAccessException e) {
throw new RuntimeException("数据库操作失败:" + e.getMessage());
} catch (Exception e) {
throw new RuntimeException("新增任务失败:" + e.getMessage());
}
return AjaxResult.error("新增任务失败");*/
if (null == leaseApplyRequestVo.getLeaseApplyInfo()) {
return AjaxResult.error("请先填写领料任务信息");
}
@ -236,6 +319,54 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
}
}
/**
* 处理任务
* @param leaseApplyRequestVo
* @param splitType
* @param taskTypeLabel
* @return
*/
/*private int processLeaseTask(LeaseApplyRequestVo leaseApplyRequestVo, TmTaskTypeEnum splitType, String taskTypeLabel) {
int thisMonthMaxOrder = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(),
TmTaskTypeEnum.TM_TASK_LEASE.getTaskTypeId());
String taskCode = genderTaskCode(thisMonthMaxOrder, taskTypeLabel);
TmTask tmTask = new TmTask(null, TmTaskTypeEnum.TM_TASK_LEASE.getTaskTypeId(),
LeaseTaskStatusEnum.LEASE_TASK_TO_PUBLISHED.getStatus(),
leaseApplyRequestVo.getLeaseApplyInfo().getCompanyId(), thisMonthMaxOrder + 1, taskCode);
tmTask.setCreateTime(DateUtils.getNowDate());
tmTask.setCreateBy(SecurityUtils.getUsername());
tmTask.setSplitType(splitType.getTaskTypeId());
tmTaskMapper.insertTmTask(tmTask);
TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(tmTask.getTaskId(), leaseApplyRequestVo.getLeaseApplyInfo().getAgreementId());
tmTaskAgreement.setCreateTime(DateUtils.getNowDate());
tmTaskAgreement.setCreateBy(SecurityUtils.getUsername());
tmTaskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement);
leaseApplyRequestVo.getLeaseApplyInfo().setTaskId(tmTask.getTaskId());
leaseApplyRequestVo.getLeaseApplyInfo().setCode(taskCode);
// 设置审批人为默认的董班长 --防止代码冲突
Long peopleId = leaseApplyInfoMapper.getDirectAuditBy();
leaseApplyRequestVo.getLeaseApplyInfo().setDirectAuditBy(peopleId);
int count = leaseApplyInfoMapper.insertLeaseApplyInfo(leaseApplyRequestVo.getLeaseApplyInfo());
if (!CollectionUtils.isEmpty(leaseApplyRequestVo.getLeaseApplyInfo().getBmFileInfos())) {
leaseApplyRequestVo.getLeaseApplyInfo().getBmFileInfos().forEach(bmFileInfo -> {
bmFileInfo.setTaskType(2);
bmFileInfo.setTaskId(tmTask.getTaskId());
bmFileInfo.setModelId(leaseApplyRequestVo.getLeaseApplyInfo().getId());
bmFileInfo.setFileType(5L);
bmFileInfo.setCreateBy(SecurityUtils.getUsername());
bmFileInfo.setCreateTime(DateUtils.getNowDate());
bmFileInfoMapper.insertBmFileInfo(bmFileInfo);
});
}
return count;
}*/
/**
* 发布任务
*
@ -301,6 +432,12 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
}
}
/**
* 插入领料任务详情数据
* @param leaseApplyDetailsList
* @param parentId
* @return
*/
private AjaxResult insertPurchaseCheckDetails(List<LeaseApplyDetails> leaseApplyDetailsList, Long parentId) {
if (!CollectionUtils.isEmpty(leaseApplyDetailsList)) {
for (LeaseApplyDetails details : leaseApplyDetailsList) {
@ -325,6 +462,13 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
* @param thisMonthMaxOrder 当月最大单号
* @return 任务对象
*/
/*private static String genderTaskCode(Integer thisMonthMaxOrder, String taskType) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date nowDate = DateUtils.getNowDate();
String format = dateFormat.format(nowDate);
String result = format.replace("-", "");
return taskType + result + String.format("-%03d", thisMonthMaxOrder + 1);
}*/
private static String genderTaskCode(Integer thisMonthMaxOrder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date nowDate = DateUtils.getNowDate();
@ -340,6 +484,7 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateLeaseApplyInfo(LeaseApplyRequestVo leaseApplyRequestVo) {
try {
// 提取到局部变量中减少重复代码
@ -385,6 +530,54 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
} catch (Exception e) {
throw new ServiceException("未知异常: " + e.getMessage());
}
/*try {
int result = 0;
// 提取到局部变量中减少重复代码
LeaseApplyInfo leaseApplyInfo = leaseApplyRequestVo.getLeaseApplyInfo();
if (leaseApplyInfo != null && leaseApplyInfo.getId() != null) {
// 去除创建一个新的数组对象直接复用
Long[] ids = {leaseApplyInfo.getId()};
result = leaseApplyInfoMapper.deleteLeaseApplyInfoByIds(ids);
if (result == 0) {
throw new RuntimeException("删除主要任务失败");
}
if (CollectionUtil.isNotEmpty(leaseApplyRequestVo.getLeaseApplyDetailsList())) {
// 业务逻辑代码
result = leaseApplyDetailsMapper.deleteLeaseApplyDetailsByParentIds(ids);
if (result == 0) {
throw new RuntimeException("删除详情任务失败");
}
}
// 查询是否存在文件
BmFileInfo fileInfo = new BmFileInfo();
fileInfo.setTaskId(leaseApplyInfo.getTaskId());
fileInfo.setModelId(leaseApplyInfo.getId());
fileInfo.setTaskType(2);
fileInfo.setFileType(5L);
List<BmFileInfo> bmFileInfos = bmFileInfoMapper.selectBmFileInfoList(fileInfo);
// 删除原有数据
if (!CollectionUtils.isEmpty(bmFileInfos)) {
result = bmFileInfoMapper.deleteBmFileInfoByBizInfo(fileInfo);
if (result == 0) {
throw new RuntimeException("删除文件失败");
}
}
// 重新走新增逻辑
AjaxResult ajaxResult = insertLeaseApplyInfo(leaseApplyRequestVo);
if (!ajaxResult.isSuccess()) {
System.err.println(ajaxResult.get("msg"));
throw new RuntimeException("修改新增数据异常");
}
return true;
}
return false;
} catch (DataAccessException dae) {
throw new ServiceException("数据访问异常: " + dae.getMessage());
} catch (IllegalArgumentException iae) {
throw new ServiceException("非法参数异常: " + iae.getMessage());
} catch (Exception e) {
throw new ServiceException("未知异常: " + e.getMessage());
}*/
}
/**

View File

@ -347,6 +347,26 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
private int updateTaskStatus(LeaseOutDetails record) {
int res = 0;
// 领用任务单独判断
if (StringUtils.isNotBlank(record.getPublishTask())) {
// 根据领用批次查询领用详情
boolean isFinished = true;
List<LeaseApplyDetails> details = leaseApplyDetailsMapper.getDetailsPublish(record.getPublishTask());
if (!CollectionUtils.isEmpty(details)) {
for (LeaseApplyDetails bean : details) {
if (bean.getAlNum().compareTo(bean.getNum()) != 0) {
isFinished = false;
break;
}
}
}
if (isFinished) {
String taskId = leaseApplyInfoMapper.getTaskId(record.getParentId());
// 领用任务状态改为已完成
res = tmTaskMapper.updateTaskStatus(taskId, LeaseTaskStatusEnum.LEASE_TASK_FINISHED.getStatus());
}
return res;
}
// 进行状态判断
List<LeaseApplyDetails> leaseApplyDetailsList = leaseApplyDetailsMapper.getByParentId(record.getParentId());
int i = 0;

View File

@ -413,4 +413,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
GROUP BY lod.type_id, mm.ma_code
ORDER BY lod.create_time DESC
</select>
<select id="getDetailsPublish" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
lpd.id AS id,
lpd.parent_id AS parentId,
mt1.type_name AS maTypeName,
mt.type_name AS typeName,
mt.unit_name AS unitName,
lpd.new_type AS typeId,
IFNULL( lpd.num, 0 ) AS outNum,
IFNULL( SUM( lod.out_num ), 0 ) AS alNum,
lpd.publish_task AS publishTask
FROM
lease_publish_details lpd
LEFT JOIN ma_type mt ON lpd.new_type = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
LEFT JOIN lease_out_details lod ON lpd.parent_id = lod.parent_id
AND lpd.publish_task = lod.publish_task
WHERE
lpd.publish_task = #{publishTask}
GROUP BY
lpd.new_type
</select>
</mapper>

View File

@ -247,4 +247,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join sys_dept sd on su.dept_id = sd.dept_id and sd.del_flag = 0
where su.user_id = #{directAuditBy} and su.del_flag = 0
</select>
<select id="selectPublishList" resultType="com.bonus.common.biz.domain.lease.LeaseApplyInfo">
SELECT
lai.id AS id,
lai.code AS code,
lai.create_by AS createBy,
lai.create_time AS createTime,
sd.dept_name AS impUnitName,
bp.contract_part AS contractPart,
lpd.lease_person AS leasePerson,
lpd.phone AS phone,
lpd.unit_id AS leaseUnitId,
lpd.project_id AS leaseProjectId,
bu.unit_name AS leaseUnit,
bp.pro_name AS leaseProject,
bai.agreement_code AS agreementCode,
tt.task_status AS taskStatus,
sda.dict_label AS taskStatusName,
IFNULL( sum( lpd.num ), 0 ) AS preCountNum,
IFNULL( sum( lod.out_num ), 0 ) AS alNum,
GROUP_CONCAT( mt1.type_name ) AS maTypeNames,
lpd.publish_task AS publishTask
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_info lai ON lai.id = lpd.parent_id
LEFT JOIN tm_task tt ON lai.task_id = tt.task_id
LEFT JOIN lease_out_details lod ON lpd.parent_id = lod.parent_id
AND lpd.publish_task = lod.publish_task
LEFT JOIN bm_unit bu ON bu.unit_id = lpd.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = lpd.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN sys_dict_data sda ON tt.task_status = sda.dict_value
AND sda.dict_type = 'lease_task_status'
LEFT JOIN ma_type mt ON lpd.new_type = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
LEFT JOIN bm_agreement_info bai ON lpd.unit_id = bai.unit_id
AND lpd.project_id = bai.project_id
GROUP BY
lpd.publish_task
ORDER BY
lpd.create_time DESC
</select>
</mapper>

View File

@ -16,6 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="companyId" column="company_id" />
<result property="monthOrder" column="month_order" />
<result property="splitType" column="split_type" />
</resultMap>
<sql id="selectTmTaskVo">
@ -46,6 +47,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="preTaskId != null">pre_task_id,</if>
<if test="taskType != null">task_type,</if>
<if test="splitType != null">split_type,</if>
<if test="taskStatus != null">task_status,</if>
<if test="code != null">`code`,</if>
<if test="monthOrder != null">month_order,</if>
@ -59,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="preTaskId != null">#{preTaskId},</if>
<if test="taskType != null">#{taskType},</if>
<if test="splitType != null">#{splitType},</if>
<if test="taskStatus != null">#{taskStatus},</if>
<if test="code != null">#{code},</if>
<if test="monthOrder != null">#{monthOrder},</if>