出入库的脏数据处理

This commit is contained in:
Administrator 2023-05-27 11:57:12 +08:00
parent 549cd7d54d
commit e5fac47526
3 changed files with 114 additions and 10 deletions

View File

@ -1,8 +1,14 @@
package com.zhgd.xmgl.modules.gt.mapper; package com.zhgd.xmgl.modules.gt.mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zhgd.xmgl.modules.gt.entity.GtMaterialPointCheckIntoWarehouseDetail; import com.zhgd.xmgl.modules.gt.entity.GtMaterialPointCheckIntoWarehouseDetail;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @Description: 出入库的物料详情 * @Description: 出入库的物料详情
@ -13,4 +19,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface GtMaterialPointCheckIntoWarehouseDetailMapper extends BaseMapper<GtMaterialPointCheckIntoWarehouseDetail> { public interface GtMaterialPointCheckIntoWarehouseDetailMapper extends BaseMapper<GtMaterialPointCheckIntoWarehouseDetail> {
List<GtMaterialPointCheckIntoWarehouseDetail> getCheckIntoWarehouseDetails(List<Integer> typeList, @Param(Constants.WRAPPER) QueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> uniqueIntoWarehouseDetailQueryWrapper);
} }

View File

@ -1,4 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhgd.xmgl.modules.gt.mapper.GtMaterialPointCheckIntoWarehouseDetailMapper"> <mapper namespace="com.zhgd.xmgl.modules.gt.mapper.GtMaterialPointCheckIntoWarehouseDetailMapper">
<select id="getCheckIntoWarehouseDetails"
resultType="com.zhgd.xmgl.modules.gt.entity.GtMaterialPointCheckIntoWarehouseDetail">
select wd.*
from gt_material_point_check_into_warehouse_detail wd
inner join gt_material_in_out_warehouse iow on iow.id = wd.gt_material_in_out_warehouse_id
${ew.customSqlSegment}
</select>
</mapper> </mapper>

View File

@ -14,6 +14,7 @@ import com.zhgd.xmgl.modules.gt.entity.GtMaterialInOutWarehouse;
import com.zhgd.xmgl.modules.gt.entity.GtMaterialPointCheckIntoWarehouseDetail; import com.zhgd.xmgl.modules.gt.entity.GtMaterialPointCheckIntoWarehouseDetail;
import com.zhgd.xmgl.modules.gt.entity.GtMaterialWarehouseDetail; import com.zhgd.xmgl.modules.gt.entity.GtMaterialWarehouseDetail;
import com.zhgd.xmgl.modules.gt.mapper.GtMaterialInOutWarehouseMapper; import com.zhgd.xmgl.modules.gt.mapper.GtMaterialInOutWarehouseMapper;
import com.zhgd.xmgl.modules.gt.mapper.GtMaterialPointCheckIntoWarehouseDetailMapper;
import com.zhgd.xmgl.modules.gt.mapper.GtMaterialWarehouseDetailMapper; import com.zhgd.xmgl.modules.gt.mapper.GtMaterialWarehouseDetailMapper;
import com.zhgd.xmgl.modules.gt.service.IGtMaterialInOutWarehouseService; import com.zhgd.xmgl.modules.gt.service.IGtMaterialInOutWarehouseService;
import com.zhgd.xmgl.modules.gt.service.IGtMaterialPointCheckIntoWarehouseDetailService; import com.zhgd.xmgl.modules.gt.service.IGtMaterialPointCheckIntoWarehouseDetailService;
@ -25,6 +26,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -39,6 +41,8 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialInOutWarehouseMapper, GtMaterialInOutWarehouse> implements IGtMaterialInOutWarehouseService { public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialInOutWarehouseMapper, GtMaterialInOutWarehouse> implements IGtMaterialInOutWarehouseService {
@Autowired
private GtMaterialPointCheckIntoWarehouseDetailMapper gtMaterialPointCheckIntoWarehouseDetailMapper;
@Autowired @Autowired
IGtMaterialPointCheckIntoWarehouseDetailService materialPointCheckIntoWarehouseDetailService; IGtMaterialPointCheckIntoWarehouseDetailService materialPointCheckIntoWarehouseDetailService;
@Autowired @Autowired
@ -79,9 +83,16 @@ public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialI
if (Objects.equals(gtMaterialInOutWarehouse.getType(), 10)) { if (Objects.equals(gtMaterialInOutWarehouse.getType(), 10)) {
//用料入库 //用料入库
saveGtMaterialWarehouseDetail(gtMaterialInOutWarehouse); saveGtMaterialWarehouseDetail(gtMaterialInOutWarehouse);
} else if (Objects.equals(gtMaterialInOutWarehouse.getType(), 20)) { } else {
//出库 List<GtMaterialPointCheckIntoWarehouseDetail> materialList = gtMaterialInOutWarehouse.getMaterialList();
useStock(gtMaterialInOutWarehouse.getMaterialList()); if (Objects.equals(gtMaterialInOutWarehouse.getType(), 20)) {
//出库
useStock(materialList);
} else if (Objects.equals(gtMaterialInOutWarehouse.getType(), 15)) {
//退库
materialList = getReverseGtMaterialPointCheckIntoWarehouseDetails(materialList);
useStock(materialList);
}
} }
result.success("添加成功!"); result.success("添加成功!");
} catch (Exception e) { } catch (Exception e) {
@ -136,7 +147,40 @@ public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialI
.eq(GtMaterialWarehouseDetail::getName, one.getName()) .eq(GtMaterialWarehouseDetail::getName, one.getName())
.eq(GtMaterialWarehouseDetail::getUnit, one.getUnit()) .eq(GtMaterialWarehouseDetail::getUnit, one.getUnit())
.eq(GtMaterialWarehouseDetail::getSpecification, one.getSpecification()) .eq(GtMaterialWarehouseDetail::getSpecification, one.getSpecification())
.eq(GtMaterialWarehouseDetail::getUnitPrice, one.getUnitPrice()); .eq(GtMaterialWarehouseDetail::getUnitPrice, one.getUnitPrice())
.eq(GtMaterialWarehouseDetail::getProjectSn, one.getProjectSn());
return queryWrapper;
}
/**
* 获取确定唯一库存的出入库详情的物料的品名的查询
*
* @param one
* @return
*/
private LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> getUniqueIntoWarehouseDetailLambdaQueryWrapper(GtMaterialPointCheckIntoWarehouseDetail one) {
LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> queryWrapper = new LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail>()
.eq(GtMaterialPointCheckIntoWarehouseDetail::getName, one.getName())
.eq(GtMaterialPointCheckIntoWarehouseDetail::getUnit, one.getUnit())
.eq(GtMaterialPointCheckIntoWarehouseDetail::getSpecification, one.getSpecification())
.eq(GtMaterialPointCheckIntoWarehouseDetail::getUnitPrice, one.getUnitPrice())
.eq(GtMaterialPointCheckIntoWarehouseDetail::getProjectSn, one.getProjectSn());
return queryWrapper;
}
/**
* 获取确定唯一库存的出入库详情的物料的品名的查询添加别名
*
* @param one
* @return
*/
private QueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> getUniqueIntoWarehouseDetailQueryWrapper(GtMaterialPointCheckIntoWarehouseDetail one, String alias) {
QueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> queryWrapper = new QueryWrapper<GtMaterialPointCheckIntoWarehouseDetail>()
.eq(alias + ReflectionUtil.getFieldNameToUlc(GtMaterialPointCheckIntoWarehouseDetail::getName), one.getName())
.eq(alias + ReflectionUtil.getFieldNameToUlc(GtMaterialPointCheckIntoWarehouseDetail::getUnit), one.getUnit())
.eq(alias + ReflectionUtil.getFieldNameToUlc(GtMaterialPointCheckIntoWarehouseDetail::getSpecification), one.getSpecification())
.eq(alias + ReflectionUtil.getFieldNameToUlc(GtMaterialPointCheckIntoWarehouseDetail::getUnitPrice), one.getUnitPrice())
.eq(alias + ReflectionUtil.getFieldNameToUlc(GtMaterialPointCheckIntoWarehouseDetail::getProjectSn), one.getProjectSn());
return queryWrapper; return queryWrapper;
} }
@ -153,6 +197,9 @@ public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialI
materialPointCheckIntoWarehouseDetailService.remove(queryWrapper); materialPointCheckIntoWarehouseDetailService.remove(queryWrapper);
saveMaterialPointCheckIntoWarehouseDetail(gtMaterialInOutWarehouse); saveMaterialPointCheckIntoWarehouseDetail(gtMaterialInOutWarehouse);
//删除空的没有入库出库的物料的库存表的物料详情的数据
deleteNotIntoMaterialDetailFromWarehouseDetail(gtMaterialInOutWarehouse.getType(), oldPointDetails);
handleGtMaterialWarehouseDetail(oldPointDetails, gtMaterialInOutWarehouse); handleGtMaterialWarehouseDetail(oldPointDetails, gtMaterialInOutWarehouse);
result.success("修改成功!"); result.success("修改成功!");
} }
@ -160,6 +207,26 @@ public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialI
return result; return result;
} }
/**
* 删除空的没有入库出库的物料的库存表的物料详情的数据
*
* @param deletePointDetails
*/
private void deleteNotIntoMaterialDetailFromWarehouseDetail(Integer type, List<GtMaterialPointCheckIntoWarehouseDetail> deletePointDetails) {
//10用料入库15退库管理20点验出库
if (isIntoWarehouseDetail(type) && CollUtil.isNotEmpty(deletePointDetails)) {
for (GtMaterialPointCheckIntoWarehouseDetail oldPointDetail : deletePointDetails) {
QueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> uniqueIntoWarehouseDetailQueryWrapper = getUniqueIntoWarehouseDetailQueryWrapper(oldPointDetail, "wd.");
List<Integer> typeList = Arrays.asList(10, 15, 20);
uniqueIntoWarehouseDetailQueryWrapper.in("iow." + ReflectionUtil.getFieldNameToUlc(GtMaterialInOutWarehouse::getType), typeList);
List<GtMaterialPointCheckIntoWarehouseDetail> gtMaterialPointCheckIntoWarehouseDetails = gtMaterialPointCheckIntoWarehouseDetailMapper.getCheckIntoWarehouseDetails(typeList, uniqueIntoWarehouseDetailQueryWrapper);
if (CollUtil.isEmpty(gtMaterialPointCheckIntoWarehouseDetails)) {
gtMaterialWarehouseDetailMapper.delete(getUniqueWarehouseDetailLambdaQueryWrapper(oldPointDetail));
}
}
}
}
@Override @Override
public Result<GtMaterialInOutWarehouse> delete(String id) { public Result<GtMaterialInOutWarehouse> delete(String id) {
JSONObject jsonObject = JSON.parseObject(id, JSONObject.class); JSONObject jsonObject = JSON.parseObject(id, JSONObject.class);
@ -171,19 +238,41 @@ public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialI
} else { } else {
removeById(id); removeById(id);
List<GtMaterialPointCheckIntoWarehouseDetail> oldPointDetails = materialPointCheckIntoWarehouseDetailService.list(getPointCheckIntoWarehouseDetailRelationLambdaQueryWrapper(gtMaterialInOutWarehouse)); Integer type = gtMaterialInOutWarehouse.getType();
if (Objects.equals(gtMaterialInOutWarehouse.getType(), 20)) { List<GtMaterialPointCheckIntoWarehouseDetail> oldPointDetails = null;
//出库 if (isIntoWarehouseDetail(type)) {
oldPointDetails = getReverseGtMaterialPointCheckIntoWarehouseDetails(oldPointDetails); oldPointDetails = materialPointCheckIntoWarehouseDetailService.list(getPointCheckIntoWarehouseDetailRelationLambdaQueryWrapper(gtMaterialInOutWarehouse));
if (Objects.equals(type, 20)) {
//出库
oldPointDetails = getReverseGtMaterialPointCheckIntoWarehouseDetails(oldPointDetails);
}
useStock(oldPointDetails);
} }
useStock(oldPointDetails);
LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> queryWrapper = getPointCheckIntoWarehouseDetailRelationLambdaQueryWrapper(gtMaterialInOutWarehouse); LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> queryWrapper = getPointCheckIntoWarehouseDetailRelationLambdaQueryWrapper(gtMaterialInOutWarehouse);
materialPointCheckIntoWarehouseDetailService.remove(queryWrapper); materialPointCheckIntoWarehouseDetailService.remove(queryWrapper);
deleteNotIntoMaterialDetailFromWarehouseDetail(type, oldPointDetails);
} }
return result; return result;
} }
/**
* 是否进入库存管理表
*
* @return
*/
private boolean isIntoWarehouseDetail(Integer type) {
List<Integer> typeList = Arrays.asList(10, 15, 20);
return type != null && typeList.contains(type);
}
/**
* 获取出入库单号对应的物料详情
*
* @param gtMaterialInOutWarehouse
* @return
*/
private LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> getPointCheckIntoWarehouseDetailRelationLambdaQueryWrapper(GtMaterialInOutWarehouse gtMaterialInOutWarehouse) { private LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> getPointCheckIntoWarehouseDetailRelationLambdaQueryWrapper(GtMaterialInOutWarehouse gtMaterialInOutWarehouse) {
LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> queryWrapper = new LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail>() LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail> queryWrapper = new LambdaQueryWrapper<GtMaterialPointCheckIntoWarehouseDetail>()
.eq(GtMaterialPointCheckIntoWarehouseDetail::getGtMaterialInOutWarehouseId, gtMaterialInOutWarehouse.getId()); .eq(GtMaterialPointCheckIntoWarehouseDetail::getGtMaterialInOutWarehouseId, gtMaterialInOutWarehouse.getId());
@ -197,7 +286,8 @@ public class GtMaterialInOutWarehouseServiceImpl extends ServiceImpl<GtMaterialI
* @param gtMaterialInOutWarehouseEntity * @param gtMaterialInOutWarehouseEntity
*/ */
private void handleGtMaterialWarehouseDetail(List<GtMaterialPointCheckIntoWarehouseDetail> oldPointDetails, GtMaterialInOutWarehouse gtMaterialInOutWarehouseEntity) { private void handleGtMaterialWarehouseDetail(List<GtMaterialPointCheckIntoWarehouseDetail> oldPointDetails, GtMaterialInOutWarehouse gtMaterialInOutWarehouseEntity) {
if (Objects.equals(gtMaterialInOutWarehouseEntity.getType(), 10)) { if (Objects.equals(gtMaterialInOutWarehouseEntity.getType(), 10) ||
Objects.equals(gtMaterialInOutWarehouseEntity.getType(), 15)) {
//入库 //入库
useStock(oldPointDetails); useStock(oldPointDetails);
saveGtMaterialWarehouseDetail(gtMaterialInOutWarehouseEntity); saveGtMaterialWarehouseDetail(gtMaterialInOutWarehouseEntity);