add:安全库存设置,安全库存预警

This commit is contained in:
2025-09-01 15:01:42 +08:00
parent b9ec1bc7c7
commit fdb44796c1
10 changed files with 804 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
package org.nl.wms.basedata_manage.controller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.base.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.logging.annotation.Log;
import org.nl.wms.basedata_manage.service.IStIvtMaterialsafeivtService;
import org.nl.wms.basedata_manage.service.dto.StIvtMaterialLsafeIvtDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* <p>
* 安全库存设置 控制层
* </p>
*
* @author Liuxy
* @since 2025-09-01
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/materialsafeivt")
@Slf4j
public class MaterialLasfeController {
@Autowired
private IStIvtMaterialsafeivtService iStIvtMaterialsafeivtService;
@GetMapping
@Log("分页查询")
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
return new ResponseEntity<>(TableDataInfo.build(iStIvtMaterialsafeivtService.queryAll(whereJson, page)), HttpStatus.OK);
}
@PostMapping("/insertSafe")
@Log("保存")
public ResponseEntity<Object> insertSafe(@RequestBody StIvtMaterialLsafeIvtDto dto) {
iStIvtMaterialsafeivtService.insertSafe(dto);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping("/safeIvtWarning")
@Log("安全预警查询")
public ResponseEntity<Object> safeIvtWarning(@RequestParam Map whereJson, PageQuery page) {
return new ResponseEntity<>(TableDataInfo.build(iStIvtMaterialsafeivtService.safeIvtWarning(whereJson, page)), HttpStatus.OK);
}
}

View File

@@ -0,0 +1,45 @@
package org.nl.wms.basedata_manage.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.common.domain.query.PageQuery;
import org.nl.wms.basedata_manage.service.dao.StIvtMaterialsafeivt;
import org.nl.wms.basedata_manage.service.dto.StIvtMaterialLsafeIvtDto;
import org.nl.wms.warehouse_management.service.dto.PieceBoxMstDto;
import java.util.Map;
/**
* <p>
* 物料安全库存设置表 服务类
* </p>
*
* @author Liuxy
* @since 2025-09-01
*/
public interface IStIvtMaterialsafeivtService extends IService<StIvtMaterialsafeivt> {
/**
* 分页查询
*
* @param whereJson : {查询参数}
* @param page : 分页对象
* @return 返回结果
*/
IPage<StIvtMaterialLsafeIvtDto> queryAll(Map whereJson, PageQuery page);
/**
* 安全库存设置
* @param dto dto类
*/
void insertSafe(StIvtMaterialLsafeIvtDto dto);
/**
* 分页查询
*
* @param whereJson : {查询参数}
* @param page : 分页对象
* @return 返回结果
*/
IPage<StIvtMaterialLsafeIvtDto> safeIvtWarning(Map whereJson, PageQuery page);
}

View File

@@ -0,0 +1,66 @@
package org.nl.wms.basedata_manage.service.dao;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* <p>
* 物料安全库存设置表
* </p>
*
* @author Liuxy
* @since 2025-09-01
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("st_ivt_materialsafeivt")
public class StIvtMaterialsafeivt implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 物料标识
*/
@TableId
private String material_id;
/**
* 下限
*/
private BigDecimal safe_ivt_down;
/**
* 上限
*/
private BigDecimal safe_ivt_up;
/**
* 计量单位标识
*/
private String qty_unit_id;
/**
* 计量单位名称
*/
private String qty_unit_name;
/**
* 设置人标识
*/
private String set_id;
/**
* 设置人名称
*/
private String set_name;
/**
* 设置时间
*/
private String set_time;
}

View File

@@ -0,0 +1,37 @@
package org.nl.wms.basedata_manage.service.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.nl.wms.basedata_manage.service.dao.StIvtMaterialsafeivt;
import org.nl.wms.basedata_manage.service.dto.StIvtMaterialLsafeIvtDto;
import java.util.Map;
/**
* <p>
* 物料安全库存设置表 Mapper 接口
* </p>
*
* @author Liuxy
* @since 2025-09-01
*/
public interface StIvtMaterialsafeivtMapper extends BaseMapper<StIvtMaterialsafeivt> {
/**
* 安全库存分页查询
* @param page 分页条件
* @param whereJson 查询条件
* @return IPage<PieceBoxMstDto>
*/
IPage<StIvtMaterialLsafeIvtDto> queryAllByPage(Page<StIvtMaterialLsafeIvtDto> page, @Param("param") Map whereJson);
/**
* 安全库存预警查询
* @param page 分页条件
* @param whereJson 查询条件
* @return IPage<PieceBoxMstDto>
*/
IPage<StIvtMaterialLsafeIvtDto> safeIvtWarning(Page<StIvtMaterialLsafeIvtDto> page, @Param("param") Map whereJson);
}

View File

@@ -0,0 +1,75 @@
<?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">
<mapper namespace="org.nl.wms.basedata_manage.service.dao.mapper.StIvtMaterialsafeivtMapper">
<select id="queryAllByPage" resultType="org.nl.wms.basedata_manage.service.dto.StIvtMaterialLsafeIvtDto">
SELECT
ivt.safe_ivt_down,
ivt.safe_ivt_up,
ivt.qty_unit_id,
ivt.qty_unit_name,
ivt.set_id,
ivt.set_name,
ivt.set_time,
mater.material_id,
mater.material_code,
mater.material_name,
mater.material_spec
FROM
md_me_materialbase mater
LEFT JOIN st_ivt_materialsafeivt ivt ON mater.material_id = ivt.material_id
<where>
1 = 1
<if test="param.material_code != null and param.material_code != ''">
AND
(mater.material_code LIKE #{param.material_code} or
mater.material_name LIKE #{param.material_code} )
</if>
</where>
ORDER BY ivt.set_time Desc
</select>
<select id="safeIvtWarning" resultType="org.nl.wms.basedata_manage.service.dto.StIvtMaterialLsafeIvtDto">
SELECT
ivt.safe_ivt_down,
ivt.safe_ivt_up,
ivt.qty_unit_id,
ivt.qty_unit_name,
ivt.set_id,
ivt.set_name,
ivt.set_time,
pivt.ivt_qty,
mater.material_id,
mater.material_code,
mater.material_name,
mater.material_spec
FROM
md_me_materialbase mater
LEFT JOIN st_ivt_materialsafeivt ivt ON mater.material_id = ivt.material_id
LEFT JOIN (
SELECT
SUM(canuse_qty) AS ivt_qty,
material_id
FROM
md_pb_storagevehicleext
WHERE
1 = 1
GROUP BY material_id
) pivt ON pivt.material_id = mater.material_id
<where>
1 = 1
<if test="param.material_code != null and param.material_code != ''">
AND
(mater.material_code LIKE #{param.material_code} or
mater.material_name LIKE #{param.material_code} )
</if>
<if test="param.is_all != 0 ">
AND
ivt.safe_ivt_down > pivt.ivt_qty
</if>
</where>
ORDER BY ivt.set_time Desc
</select>
</mapper>

View File

@@ -0,0 +1,46 @@
package org.nl.wms.basedata_manage.service.dto;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.nl.wms.basedata_manage.service.dao.StIvtMaterialsafeivt;
import org.nl.wms.warehouse_management.service.dao.StIvtPieceBoxDtl;
import org.nl.wms.warehouse_management.service.dao.StIvtPieceBoxMst;
import java.util.List;
/**
* <p>
* 拼单管理dto
* </p>
*
* @author Liuxy
* @since 2025-09-01
*/
@Data
public class StIvtMaterialLsafeIvtDto extends StIvtMaterialsafeivt {
/**
* 物料编号
*/
private String material_code;
/**
* 物料名称
*/
private String material_name;
/**
* 物料批次
*/
private String material_spec;
/**
* 库存
*/
private String ivt_qty;
/**
* 新增安全设置明细
*/
private List<StIvtMaterialsafeivt> rows;
}

View File

@@ -0,0 +1,99 @@
package org.nl.wms.basedata_manage.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.utils.SecurityUtils;
import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
import org.nl.wms.basedata_manage.service.IStIvtMaterialsafeivtService;
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
import org.nl.wms.basedata_manage.service.dao.StIvtMaterialsafeivt;
import org.nl.wms.basedata_manage.service.dao.mapper.StIvtMaterialsafeivtMapper;
import org.nl.wms.basedata_manage.service.dto.StIvtMaterialLsafeIvtDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
* 物料安全库存设置表 服务实现类
* </p>
*
* @author Liuxy
* @since 2025-09-01
*/
@Service
public class StIvtMaterialsafeivtServiceImpl extends ServiceImpl<StIvtMaterialsafeivtMapper, StIvtMaterialsafeivt> implements IStIvtMaterialsafeivtService {
/**
* 计量单位服务
*/
@Autowired
private IMdPbMeasureunitService iMdPbMeasureunitService;
@Override
public IPage<StIvtMaterialLsafeIvtDto> queryAll(Map whereJson, PageQuery page) {
return this.baseMapper.queryAllByPage(new Page<>(page.getPage() + 1, page.getSize()),
whereJson);
}
@Override
@Transactional
public void insertSafe(StIvtMaterialLsafeIvtDto dto) {
List<StIvtMaterialsafeivt> rows = dto.getRows();
// 判断是否有记录, 有修改,没有新增
List<StIvtMaterialsafeivt> ivtList = this.list(
new QueryWrapper<StIvtMaterialsafeivt>().lambda()
.in(StIvtMaterialsafeivt::getMaterial_id, rows.stream()
.map(StIvtMaterialsafeivt::getMaterial_id)
.collect(Collectors.toList())
)
);
// 计量单位默认重量KG
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getByCode("KG");
List<StIvtMaterialsafeivt> insertList = new ArrayList<>();
List<StIvtMaterialsafeivt> updateList = new ArrayList<>();
for (StIvtMaterialsafeivt dao : rows) {
StIvtMaterialsafeivt queryDao = ivtList.stream()
.filter(row -> row.getMaterial_id().equals(dao.getMaterial_id()))
.findFirst().orElse(null);
if (ObjectUtil.isEmpty(queryDao)) {
// 新增
StIvtMaterialsafeivt insertDao = new StIvtMaterialsafeivt();
insertDao.setMaterial_id(dao.getMaterial_id());
insertDao.setQty_unit_id(unitDao.getMeasure_unit_id());
insertDao.setQty_unit_name(unitDao.getUnit_name());
insertDao.setSafe_ivt_down(dao.getSafe_ivt_down());
insertDao.setSet_id(SecurityUtils.getCurrentUserId());
insertDao.setSet_name(SecurityUtils.getCurrentNickName());
insertDao.setSet_time(DateUtil.now());
insertList.add(insertDao);
} else {
// 修改
queryDao.setSafe_ivt_down(dao.getSafe_ivt_up());
updateList.add(queryDao);
}
this.saveBatch(insertList);
this.updateBatchById(updateList);
}
}
@Override
public IPage<StIvtMaterialLsafeIvtDto> safeIvtWarning(Map whereJson, PageQuery page) {
return this.baseMapper.safeIvtWarning(new Page<>(page.getPage() + 1, page.getSize()),
whereJson);
}
}

View File

@@ -0,0 +1,144 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<el-form
:inline="true"
class="demo-form-inline"
label-position="right"
label-width="90px"
label-suffix=":"
>
<el-form-item label="物料搜索">
<el-input
v-model="query.material_code"
clearable
size="small"
placeholder="物料编码、名称或规格"
style="width: 200px;"
class="filter-item"
/>
</el-form-item>
<rrOperation :crud="crud" />
</el-form>
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission">
<el-button
slot="right"
class="filter-item"
type="success"
icon="el-icon-position"
size="mini"
@click="save"
>
保存
</el-button>
</crudOperation>
<!--表格渲染-->
<el-table
ref="table"
:max-height="590"
v-loading="crud.loading"
:data="crud.data"
size="mini"
style="width: 100%;"
@selection-change="crud.selectionChangeHandler"
>
<el-table-column type="selection" min-width="35" />
<el-table-column prop="material_code" label="物料编码" min-width="150" show-overflow-tooltip />
<el-table-column prop="material_name" label="物料名称" min-width="200" show-overflow-tooltip />
<el-table-column prop="material_spec" label="物料规格" min-width="150" show-overflow-tooltip />
<el-table-column prop="safe_ivt_down" label="安全库存" width="200">
<template slot-scope="scope">
<el-input-number
v-model="crud.data[scope.$index].safe_ivt_down"
size="small"
:controls="false"
controls-position="right"
precision="3"
:min="0"
/>
</template>
</el-table-column>
<el-table-column prop="qty_unit_name" label="单位" />
<el-table-column prop="set_time" label="设置时间" min-width="110" show-overflow-tooltip />
<el-table-column prop="set_name" label="设置人" />
</el-table>
<!--分页组件-->
<pagination />
</div>
</div>
</template>
<script>
import crudMaterialsafeivt from '@/views/wms/basedata/safeivt/materialsafeivt'
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
const defaultForm = {
material_id: null,
safe_ivt_down: null,
safe_ivt_up: null,
qty_unit_id: null,
qty_unit_name: null,
set_id: null,
set_name: null,
set_time: null
}
export default {
name: 'SafeIvt',
components: { pagination, crudOperation, rrOperation },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({
title: '安全库存',
optShow: { reset: true },
url: 'api/materialsafeivt',
idField: 'material_id',
props: {
// 每页数据条数
size: 20
},
sort: 'material_id,desc',
crudMethod: { ...crudMaterialsafeivt }
})
},
data() {
return {
checkrows: [],
permission: {},
rules: {
}
}
},
created() {
},
methods: {
// 钩子在获取表格数据之前执行false 则代表不获取数据
[CRUD.HOOK.beforeRefresh]() {
return true
},
save() {
this.checkrows = this.$refs.table.selection
if (this.checkrows.length === 0) {
this.crud.notify('请勾选需要保存的记录!')
return false
}
const data = {}
data.rows = this.checkrows
crudMaterialsafeivt.insertSafe(data).then(() => {
this.crud.dleChangePage(1)
this.crud.editSuccessNotify()
this.crud.refresh()
})
}
}
}
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,35 @@
import request from '@/utils/request'
export function add(data) {
return request({
url: 'api/materialsafeivt',
method: 'post',
data
})
}
export function del(ids) {
return request({
url: 'api/materialsafeivt/',
method: 'delete',
data: ids
})
}
export function edit(data) {
return request({
url: 'api/materialsafeivt',
method: 'put',
data
})
}
export function insertSafe(data) {
return request({
url: 'api/materialsafeivt/insertSafe',
method: 'post',
data
})
}
export default { add, edit, del, insertSafe }

View File

@@ -0,0 +1,204 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<el-form
size="mini"
:inline="true"
class="demo-form-inline"
label-position="right"
label-width="80px"
label-suffix=":"
>
<el-form-item label="模糊查询">
<el-input
v-model="query.material_code"
clearable
placeholder="编码、名称"
/>
</el-form-item>
<el-form-item label="仅显示预警" label-width="120px">
<el-switch v-model="query.is_all" active-value="1" inactive-value="0" @change="crud.toQuery()"/>
</el-form-item>
<rrOperation />
</el-form>
</div>
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission" />
<!--表格渲染-->
<el-table ref="table" border :cell-style="cellStyle" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column prop="material_code" label="物料编码" />
<el-table-column prop="material_name" label="物料名称" />
<el-table-column prop="material_spec" label="物料规格" />
<el-table-column prop="safe_ivt_down" label="安全库存下限" :formatter="crud.formatNum2" />
<el-table-column prop="ivt_qty" label="库存" :formatter="crud.formatNum2" />
<el-table-column prop="qty_unit_name" label="单位" />
</el-table>
<!--分页组件-->
<pagination />
</div>
</div>
</template>
<script>
import crudMaterialsafeivt from '@/views/wms/basedata/safeivt/materialsafeivt'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { }
export default {
name: 'SafeIvtWarning',
components: { pagination, crudOperation, rrOperation },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({
title: '安全库存预警',
url: 'api/materialsafeivt/safeIvtWarning',
idField: 'material_id',
sort: '',
query: { is_all: '1' },
crudMethod: { ...crudMaterialsafeivt },
optShow: {
add: false,
edit: false,
del: false,
download: false,
reset: true
}
})
},
data() {
return {
permission: {
}
}
},
methods: {
hand(value) {
this.crud.toQuery()
},
cellStyle({ row, column, rowIndex, columnIndex }) {
const safe_ivt_down = parseInt(row.safe_ivt_down)
const ivt_qty = parseInt(row.ivt_qty)
if (column.property === 'ivt_qty') {
if (ivt_qty < safe_ivt_down) {
return 'background: red'
}
}
if (safe_ivt_down <= ivt_qty) {
return ''
}
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep {
.vue-treeselect__menu {
overflow-x: auto !important;
width: 300px;
max-height: 300px !important;
}
.vue-treeselect__label {
overflow: unset;
text-overflow: unset;
}
.vue-treeselect__control {
height: 20px !important;
}
.vue-treeselect__multi-value-item-container,
.vue-treeselect--has-value .vue-treeselect__multi-value {
height: 30px;
line-height: 24px;
padding: 0;
}
.vue-treeselect__limit-tip,
.vue-treeselect--searchable.vue-treeselect--multi.vue-treeselect--has-value
.vue-treeselect__input-container {
padding-top: 0;
}
.vue-treeselect__placeholder,
.vue-treeselect__single-value {
height: 28px;
line-height: 32px;
font-size: small;
color: "#CCCFD6";
}
.vue-treeselect--has-value .vue-treeselect__input {
height: 18px !important;
line-height: 18px !important;
}
.vue-treeselect div,
.vue-treeselect span {
box-sizing: content-box;
}
.vue-treeselect__multi-value-label {
display: block;
width: 140px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.vue-treeselect__value-container {
display: block;
height: 32px;
}
}
</style>