优化部分代码与采购、领料关联配件库
This commit is contained in:
parent
b87ddecee6
commit
24b48a181f
@ -126,8 +126,7 @@ public class RepairWaresController {
|
|||||||
@GetMapping("/getByName")
|
@GetMapping("/getByName")
|
||||||
@Operation(summary = "根据名称获取最新的数据")
|
@Operation(summary = "根据名称获取最新的数据")
|
||||||
public CommonResult<?> getWaresByName(@RequestParam("name") String name) {
|
public CommonResult<?> getWaresByName(@RequestParam("name") String name) {
|
||||||
List<RepairWares> list = waresService.list(new LambdaQueryWrapper<RepairWares>().eq(RepairWares::getName, name));
|
return success(waresService.getWaresByName(name));
|
||||||
return success(list.stream().max(Comparator.comparing(RepairWares::getCreateTime)).orElse(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,5 +102,7 @@ public class RepairWares extends TenantBaseDO {
|
|||||||
private String status;
|
private String status;
|
||||||
/**数据来源*/
|
/**数据来源*/
|
||||||
private String dataForm;
|
private String dataForm;
|
||||||
|
/** 进价 */
|
||||||
|
private String purPrice;
|
||||||
|
|
||||||
}
|
}
|
@ -28,4 +28,11 @@ public interface RepairWaresMapper extends BaseMapper<RepairWares> {
|
|||||||
**/
|
**/
|
||||||
IPage<RepairWaresRespVO> queryListPage(@Param("entity") RepairWaresPageReqVO pageReqVO, Page<RepairWaresRespVO> page);
|
IPage<RepairWaresRespVO> queryListPage(@Param("entity") RepairWaresPageReqVO pageReqVO, Page<RepairWaresRespVO> page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名称获取最新的数据
|
||||||
|
*
|
||||||
|
* @author 小李
|
||||||
|
* @date 18:03 2024/9/25
|
||||||
|
**/
|
||||||
|
RepairWaresRespVO getWaresByName(@Param("name") String name);
|
||||||
}
|
}
|
@ -53,4 +53,11 @@ public interface RepairWaresService extends IService<RepairWares> {
|
|||||||
**/
|
**/
|
||||||
IPage<RepairWaresRespVO> getWaresPage(RepairWaresPageReqVO pageReqVO, Page<RepairWaresRespVO> page);
|
IPage<RepairWaresRespVO> getWaresPage(RepairWaresPageReqVO pageReqVO, Page<RepairWaresRespVO> page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名称获取最新的数据
|
||||||
|
*
|
||||||
|
* @author 小李
|
||||||
|
* @date 18:03 2024/9/25
|
||||||
|
**/
|
||||||
|
RepairWaresRespVO getWaresByName(String name);
|
||||||
}
|
}
|
@ -89,4 +89,15 @@ public class RepairWaresServiceImpl extends ServiceImpl<RepairWaresMapper, Repai
|
|||||||
return waresMapper.queryListPage(pageReqVO, page);
|
return waresMapper.queryListPage(pageReqVO, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名称获取最新的数据
|
||||||
|
*
|
||||||
|
* @author 小李
|
||||||
|
* @date 18:03 2024/9/25
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public RepairWaresRespVO getWaresByName(String name){
|
||||||
|
return waresMapper.getWaresByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ import cn.iocoder.yudao.common.RepairErrorCodeConstants;
|
|||||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import cn.iocoder.yudao.module.company.entity.Company;
|
import cn.iocoder.yudao.module.company.entity.Company;
|
||||||
import cn.iocoder.yudao.module.company.service.CompanyService;
|
import cn.iocoder.yudao.module.company.service.CompanyService;
|
||||||
|
import cn.iocoder.yudao.module.project.entity.RepairWares;
|
||||||
|
import cn.iocoder.yudao.module.project.service.RepairWaresService;
|
||||||
import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSo;
|
import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSo;
|
||||||
import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSoi;
|
import cn.iocoder.yudao.module.stockOperate.entity.DlRepairSoi;
|
||||||
import cn.iocoder.yudao.module.stockOperate.mapper.DlRepairSoMapper;
|
import cn.iocoder.yudao.module.stockOperate.mapper.DlRepairSoMapper;
|
||||||
@ -18,14 +20,18 @@ import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|||||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
|
||||||
@ -48,6 +54,10 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
@Resource
|
@Resource
|
||||||
private CompanyService companyService;
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private RepairWaresService waresService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 采购单/领料单 新增
|
* 采购单/领料单 新增
|
||||||
* @author 小李
|
* @author 小李
|
||||||
@ -65,7 +75,9 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
if (ObjectUtil.isNotEmpty(dept)){
|
if (ObjectUtil.isNotEmpty(dept)){
|
||||||
repairSoRespVO.setCorpId(dept.getCorpId());
|
repairSoRespVO.setCorpId(dept.getCorpId());
|
||||||
Company company = companyService.getById(dept.getCorpId());
|
Company company = companyService.getById(dept.getCorpId());
|
||||||
repairSoRespVO.setCorpName(company.getCorpName());
|
if (ObjectUtil.isNotEmpty(company)){
|
||||||
|
repairSoRespVO.setCorpName(company.getCorpName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增主表
|
// 新增主表
|
||||||
@ -76,9 +88,31 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
|
|||||||
}
|
}
|
||||||
repairSoRespVO.getGoodsList().forEach(item -> {
|
repairSoRespVO.getGoodsList().forEach(item -> {
|
||||||
item.setSoId(repairSoRespVO.getId());
|
item.setSoId(repairSoRespVO.getId());
|
||||||
item.setSoiType(repairSoRespVO.getSoType());
|
// item.setSoiType(repairSoRespVO.getSoType());
|
||||||
});
|
});
|
||||||
repairSoiService.saveBatch(repairSoRespVO.getGoodsList());
|
repairSoiService.saveBatch(repairSoRespVO.getGoodsList());
|
||||||
|
|
||||||
|
// 操作配件库存表
|
||||||
|
// 获取所有需要操作的数据
|
||||||
|
List<DlRepairSoi> goodsList = repairSoRespVO.getGoodsList();
|
||||||
|
List<String> ids = goodsList.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList());
|
||||||
|
List<RepairWares> repairWares = waresService.listByIds(ids);
|
||||||
|
// 更新库存和进价
|
||||||
|
List<RepairWares> newWares = repairWares.stream().map(item -> {
|
||||||
|
// 取数据
|
||||||
|
DlRepairSoi repairSoi = goodsList.stream().filter(i -> i.getGoodsId().equals(item.getId())).collect(Collectors.toList()).get(0);
|
||||||
|
// 设置新值
|
||||||
|
// 如果是采购入库,数量+,如果是领料出库,数量-
|
||||||
|
// 01, 03 是采购 02 是领料
|
||||||
|
BigDecimal count = new BigDecimal(repairSoi.getGoodsCount());
|
||||||
|
RepairWares wares = new RepairWares();
|
||||||
|
wares.setId(item.getId());
|
||||||
|
wares.setStock("02".equals(repairSoRespVO.getSoType()) ? item.getStock().subtract(count) : item.getStock().add(count));
|
||||||
|
// 更新进价
|
||||||
|
wares.setPurPrice(repairSoi.getGoodsPrice().toString());
|
||||||
|
return wares;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
waresService.updateBatchById(newWares);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,4 +30,18 @@
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
drw.create_time DESC
|
drw.create_time DESC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getWaresByName" resultType="cn.iocoder.yudao.module.project.vo.RepairWaresRespVO">
|
||||||
|
SELECT
|
||||||
|
drw.*,
|
||||||
|
dbt.`name` AS typeName,
|
||||||
|
dbw.`name` AS warehouseName,
|
||||||
|
GROUP_CONCAT( bc.corp_name ) AS corpNames
|
||||||
|
FROM
|
||||||
|
dl_repair_wares drw
|
||||||
|
LEFT JOIN base_company bc ON FIND_IN_SET( bc.id, drw.corp_id ) > 0
|
||||||
|
LEFT JOIN dl_base_type dbt ON drw.type = dbt.id AND dbt.deleted = 0
|
||||||
|
LEFT JOIN dl_base_warehouse dbw ON drw.warehouse = dbw.id AND dbw.deleted = 0
|
||||||
|
where drw.name = #{name} order by drw.create_time desc limit 1
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user