修改物料字段 修改计量单位界面 编写物料同步功能

This commit is contained in:
张江玮
2022-12-16 14:53:26 +08:00
parent 0ebcc7c34a
commit 47624946eb
8 changed files with 216 additions and 125 deletions

View File

@@ -3,10 +3,13 @@ package org.nl.wms.basedata.rest;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.logging.annotation.Log;
import org.nl.wms.basedata.eum.MaterOptTypeEnum;
import org.nl.wms.basedata.service.MaterialbaseService;
@@ -90,8 +93,16 @@ public class MaterialbaseController {
@Log("物料同步")
@ApiOperation("物料同步")
//@SaCheckPermission("materialtype:list")
public ResponseEntity<Object> synchronize(@RequestBody Map whereJson) {
materialBaseService.synchronize(whereJson);
public ResponseEntity<Object> synchronize(@RequestBody JSONObject param) {
String start_time = param.getString("start_time");
if (StrUtil.isEmpty(start_time)) {
throw new BadRequestException("开始日期不能为空");
}
String end_time = param.getString("end_time");
if (StrUtil.isEmpty(end_time)) {
throw new BadRequestException("结束日期不能为空");
}
materialBaseService.synchronize(param);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -89,7 +89,7 @@ public interface MaterialbaseService {
*/
JSONObject getMaterOptType(String materOpt_code);
void synchronize(Map whereJson);
void synchronize(JSONObject param);
JSONArray getProductSeries(String parent_class_id);

View File

@@ -37,7 +37,7 @@ public class MaterialbaseDto implements Serializable {
private String english_name;
private long base_unit_id;
private String unit_code;
private long assist_unit_id;
private String base_unit_name;

View File

@@ -7,6 +7,8 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -14,8 +16,18 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.system.domain.Dict;
import org.nl.modules.system.domain.DictDetail;
import org.nl.modules.system.service.DictDetailService;
import org.nl.modules.system.service.DictService;
import org.nl.modules.system.service.ParamService;
import org.nl.modules.system.service.dto.DictDetailDto;
import org.nl.modules.system.service.dto.DictSmallDto;
import org.nl.modules.system.service.impl.DictDetailServiceImpl;
import org.nl.modules.system.service.impl.ParamServiceImpl;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.basedata.eum.MaterOptTypeEnum;
import org.nl.wms.basedata.service.ClassstandardService;
@@ -42,61 +54,20 @@ public class MaterialbaseServiceImpl implements MaterialbaseService {
private final ClassstandardService classstandardService;
//private final WmsToErpService wmsToErpService;
private final ParamService paramService;
private final DictDetailService dictDetailService;
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
String search = MapUtil.getStr(whereJson, "search");
//物料限制的时候使用,初始化页面
String class_idStr = MapUtil.getStr(whereJson, "class_idStr");
String material_type_id = MapUtil.getStr(whereJson, "material_type_id");
String class_code = MapUtil.getStr(whereJson, "class_code");
String ids = MapUtil.getStr(whereJson, "ids");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("search", search);
if (!StrUtil.isEmpty(search)) {
//处理转义字符
if (search.contains("\\")) {
search = search.replace("\\", "\\\\\\");
}
map.put("search", "%" + search + "%");
}
//处理物料当前节点的所有子节点
if (!StrUtil.isEmpty(material_type_id)) {
map.put("material_type_id", material_type_id);
String classIds = classstandardService.getChildIdStr(material_type_id);
map.put("classIds", classIds);
} else if (ObjectUtil.isNotEmpty(class_idStr)) {
String classIds = classstandardService.getAllChildIdStr(class_idStr);
map.put("classIds", classIds);
}
if (!StrUtil.isEmpty(class_code)) {
map.put("class_code", class_code + "%");
}
StringBuffer where = new StringBuffer();
if (StrUtil.isNotEmpty(ids)) {
ids = ids.replaceAll("\'", "");
String[] strs = ids.split(",");
where.append("(");
for (int i = 0; i < strs.length; ) {
where.append("class.class_code like '" + strs[i] + "%'");
i++;
if (i < strs.length) {
where.append(" or ");
}
}
where.append(")");
map.put("idssql", where.toString());
} else {
map.put("idssql", "1=1");
}
JSONObject jo = WQL.getWO("QMD_ME_MATERIAL").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "material_id");
return jo;
return WQL.getWO("QMD_ME_MATERIAL").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "material_id");
}
@Override
@@ -216,9 +187,80 @@ public class MaterialbaseServiceImpl implements MaterialbaseService {
}
@Override
public void synchronize(Map whereJson) {
/* wmsToErpService.getClassInfo(null);
wmsToErpService.getMaterialInfo(null);*/
public void synchronize(JSONObject param) {
// 获取 mes 地址,拼接请求地址
String material_uri = paramService.findByCode("mes_url").getValue() + "api/mes/material";
HttpResponse response = HttpRequest
.post(material_uri)
.body(param.toJSONString())
.execute();
if (response.getStatus() != 200) {
throw new BadRequestException("与 MES 通信错误");
}
JSONObject response_body = JSON.parseObject(response.body());
if (ObjectUtil.isEmpty(response_body)) {
throw new BadRequestException("MES 响应为空");
}
if (!response_body.getString("status").equals("200")) {
throw new BadRequestException(response_body.getString("message"));
}
// 进行计量单位与物料的更新
JSONArray data = response_body.getJSONArray("data");
WQLObject unit_table = WQLObject.getWQLObject("md_pb_measureunit");
WQLObject material_table = WQLObject.getWQLObject("md_me_materialbase");
Long user_id = SecurityUtils.getCurrentUserId();
String nick_name = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
for (Object o : data) {
JSONObject material = (JSONObject) o;
// 查询是否存在这个计量单位
String unit_code = material.getString("unit_code");
JSONObject unit = unit_table
.query("unit_code = '" + unit_code + "'")
.uniqueResult(0);
if (ObjectUtil.isEmpty(unit)) {
// 如果不存在则添加
material.put("measure_unit_id", IdUtil.getSnowflake(1L, 1L));
material.put("is_used", "1");
material.put("create_id", user_id);
material.put("create_name", nick_name);
material.put("create_time", now);
unit_table.insert(material);
} else {
// 如果存在则修改
unit.put("unit_name", material.getString("unit_name"));
unit.put("update_optid", user_id);
unit.put("update_optname", nick_name);
unit.put("update_time", now);
unit_table.update(unit);
}
// 查询是否存在这个物料
String material_code = material.getString("material_code");
JSONObject existMaterial = material_table
.query("material_code = '" + material_code + "'")
.uniqueResult(0);
if (ObjectUtil.isEmpty(existMaterial)) {
// 如果不存在则添加
material.put("material_id", IdUtil.getSnowflake(1L, 1L));
material.put("is_used", "1");
material.put("create_id", user_id);
material.put("create_name", nick_name);
material.put("create_time", now);
material_table.insert(material);
} else {
// 如果存在则修改
existMaterial.put("material_name", material.getString("material_name"));
existMaterial.put("unit_code", unit_code);
existMaterial.put("update_optid", user_id);
existMaterial.put("update_optname", nick_name);
existMaterial.put("update_time", now);
material_table.update(existMaterial);
}
}
}
@Override

View File

@@ -15,9 +15,6 @@
#################################################
输入.flag TYPEAS s_string
输入.search TYPEAS s_string
输入.class_code TYPEAS s_string
输入.idssql TYPEAS f_string
输入.classIds TYPEAS f_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
@@ -44,36 +41,25 @@
IF 输入.flag = "1"
PAGEQUERY
SELECT
mb.*,
class.class_code,
class.class_name,
unit_name,
'50' as standard_weight,
unit_name as base_unit_id_name,
class2.class_code as product_series_code,
class2.class_name as product_series_name
material.material_id,
material.material_code,
material.material_name,
material.unit_code,
unit.unit_name AS 'unit_name',
material.is_used,
material.create_name,
material.create_time
FROM
md_me_materialbase mb
LEFT JOIN MD_PB_ClassStandard class ON class.class_id = mb.material_type_id
LEFT JOIN md_pb_measureunit unit ON unit.measure_unit_id = mb.base_unit_id
left join MD_PB_ClassStandard class2 on class2.class_id =mb.product_series
md_me_materialbase material
LEFT JOIN md_pb_measureunit unit ON material.unit_code = unit.unit_code
WHERE
mb.is_delete = '0'
and 输入.idssql
OPTION 输入.search <> ""
(
mb.material_code like 输入.search
OR
mb.material_name like 输入.search
)
ENDOPTION
OPTION 输入.class_code <> ""
class.class_code like 输入.class_code
ENDOPTION
OPTION 输入.classIds <> ""
class.class_id in 输入.classIds
ENDOPTION
material.is_delete = '0'
OPTION 输入.search <> ""
(
material.material_code LIKE CONCAT ( '%', 输入.search, '%' )
OR material.material_name LIKE CONCAT ( '%', 输入.search, '%' )
)
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF

View File

@@ -3,7 +3,7 @@
<!--工具栏-->
<div class="head-container">
<el-row>
<el-col :span="8">
<el-col v-if="false" :span="8">
<el-row>
<el-col :span="7">
<span style="line-height:36px;text-align: center">物料类别</span>
@@ -43,7 +43,7 @@
type="success"
icon="el-icon-position"
size="mini"
@click="synchronize()"
@click="show_sync_dialog = true"
>
同步
</el-button>
@@ -54,7 +54,7 @@
:before-close="crud.cancelCU"
:visible.sync="crud.status.cu > 0"
:title="crud.status.title"
width="1200px"
width="400px"
>
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="110px">
<el-row>
@@ -63,20 +63,48 @@
<el-input v-model="form.material_code" style="width: 200px;" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="物料名称" prop="material_name">
<el-input v-model="form.material_name" style="width: 200px;" />
</el-form-item>
</el-col>
<el-col :span="8">
</el-row>
<el-row>
<el-col :span="16">
<el-form-item label="是否启用" prop="is_used">
<el-radio v-model="form.is_used" label="0">否</el-radio>
<el-radio v-model="form.is_used" label="1">是</el-radio>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item label="计量单位" prop="unit_code">
<el-select
v-model="form.unit_code"
placeholder="请选择"
style="width: 200px;"
>
<el-option
v-for="item in measure_unit"
:key="item.measure_unit_id"
:label="item.unit_name"
:value="item.unit_code"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row v-if="false">
<el-col v-if="false" :span="8">
<el-form-item label="规格" prop="material_spec">
<label slot="label">规&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格</label>
<el-input v-model="form.material_spec" style="width: 200px;" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="型号" prop="material_model">
<label slot="label">型&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
@@ -100,7 +128,7 @@
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-row v-if="false">
<el-col :span="8">
<el-form-item label="产品系列">
<treeselect
@@ -118,16 +146,10 @@
<el-input-number v-model="form.standing_time" :controls="false" :min="0" label="分钟" style="width: 200px;" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="是否启用" prop="is_used">
<el-radio v-model="form.is_used" label="0">否</el-radio>
<el-radio v-model="form.is_used" label="1">是</el-radio>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
@@ -142,12 +164,12 @@
>
<el-table-column prop="material_code" label="物料编码" width="160" />
<el-table-column prop="material_name" label="物料名称" width="180" show-overflow-tooltip />
<el-table-column prop="material_spec" label="物料规格" width="140" />
<el-table-column prop="material_model" label="物料型号" />
<el-table-column prop="class_name" label="物料分类" width="140" />
<el-table-column v-if="false" prop="material_spec" label="物料规格" width="140" />
<el-table-column v-if="false" prop="material_model" label="物料型号" />
<el-table-column v-if="false" prop="class_name" label="物料分类" width="140" />
<el-table-column prop="unit_name" label="计量单位" />
<el-table-column prop="standing_time" label="静置时间分钟" width="130px" />
<el-table-column prop="product_series_name" label="系列" />
<el-table-column v-if="false" prop="standing_time" label="静置时间分钟" width="130px" />
<el-table-column v-if="false" prop="product_series_name" label="系列" />
<el-table-column label="启用" align="center" prop="is_used">
<template slot-scope="scope">
<el-switch
@@ -160,8 +182,8 @@
/>
</template>
</el-table-column>
<el-table-column prop="update_optname" label="修改" />
<el-table-column prop="update_time" label="修改时间" width="135" />
<el-table-column prop="create_name" label="创建" />
<el-table-column prop="create_time" label="创建时间" width="135" />
<el-table-column
v-permission="['admin','Materialbase:edit','Materialbase:del']"
fixed="right"
@@ -177,6 +199,33 @@
</template>
</el-table-column>
</el-table>
<!--同步对话框-->
<el-dialog
:visible.sync="show_sync_dialog"
width="400px"
>
<el-form
:inline="true"
class="demo-form-inline"
label-position="right"
label-width="80px"
label-suffix=":"
>
<el-form-item label="同步时间">
<el-date-picker
v-model="sync_time"
type="daterange"
value-format="yyyy-MM-dd"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="show_sync_dialog = false">取 消</el-button>
<el-button type="primary" @click="synchronize()">确 定</el-button>
</div>
</el-dialog>
<!--分页组件-->
<pagination />
</div>
@@ -203,7 +252,7 @@ const defaultForm = {
material_spec: null,
material_model: null,
english_name: null,
base_unit_id: null,
unit_code: null,
approve_fileno: null,
print_no: null,
material_type_id: null,
@@ -223,7 +272,7 @@ const defaultForm = {
update_optname: null,
update_time: null,
is_used_time: null,
is_used: null,
is_used: '1',
is_delete: null,
ext_id: null,
material_height_type: null,
@@ -254,6 +303,8 @@ export default {
measure_unit: [],
productSeries: [],
permission: {},
show_sync_dialog: false,
sync_time: '',
rules: {
material_id: [
{ required: true, message: '不能为空', trigger: 'blur' }
@@ -264,9 +315,6 @@ export default {
material_name: [
{ required: true, message: '物料名称不能为空', trigger: 'blur' }
],
material_type_id: [
{ required: true, message: '物料分类不能为空', trigger: 'blur' }
],
create_id: [
{ required: true, message: '不能为空', trigger: 'blur' }
],
@@ -278,6 +326,9 @@ export default {
],
material_height_type: [
{ required: true, message: '不能为空', trigger: 'blur' }
],
unit_code: [
{ required: true, message: '计量单位不能为空', trigger: 'blur' }
]
}
}
@@ -344,22 +395,23 @@ export default {
crudClassstandard.getClassSuperior(id).then(res => {
const data = res.content
that.buildTree(data)
if (type == '02') {
if (type === '02') {
that.classes2 = data
}
if (type == '03') {
if (type === '03') {
that.classes3 = data
}
})
},
synchronize() {
this.fullscreenLoading = true
crudMaterialbase.synchronize(this.crud.query).then(res => {
this.fullscreenLoading = false
crudMaterialbase.synchronize({ start_time: this.sync_time[0], end_time: this.sync_time[1] }).then(res => {
this.show_sync_dialog = false
this.sync_time = ''
this.crud.notify('同步成功!', CRUD.NOTIFICATION_TYPE.SUCCESS)
}).catch(() => {
this.fullscreenLoading = false
this.show_sync_dialog = false
})
console.log(this.sync_time)
},
queryClassId() {
const param = {

View File

@@ -17,16 +17,16 @@
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="编码" prop="unit_code">
<el-form-item label="单位编码" prop="unit_code">
<el-input v-model="form.unit_code" style="width: 370px;" />
</el-form-item>
<el-form-item label="名称" prop="unit_name">
<el-form-item label="单位名称" prop="unit_name">
<el-input v-model="form.unit_name" style="width: 370px;" />
</el-form-item>
<el-form-item label="外部标识" prop="ext_id">
<el-form-item v-if="false" label="外部标识" prop="ext_id">
<el-input v-model="form.ext_id" style="width: 370px;" />
</el-form-item>
<el-form-item label="数据精度" prop="qty_precision">
<el-form-item v-if="false" label="数据精度" prop="qty_precision">
<!-- <el-input v-model="form.qty_precision" style="width: 370px;" />-->
<el-input-number v-model="form.qty_precision" :min="1" :max="6" label="描述文字" style="width: 150px;" @change="handleChange" />
</el-form-item>
@@ -36,7 +36,7 @@
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
@@ -44,9 +44,9 @@
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column prop="unit_code" label="编码" />
<el-table-column prop="unit_name" label="名称" />
<el-table-column prop="qty_precision" label="数据精度" />
<el-table-column prop="update_optname" label="修改者" />
<el-table-column prop="update_time" label="修改时间" width="135" />
<el-table-column v-if="false" prop="qty_precision" label="数据精度" />
<el-table-column prop="create_name" label="创建人" />
<el-table-column prop="create_time" label="创建时间" width="135" />
<el-table-column prop="is_used" label="启用 ">
<template slot-scope="scope">
<el-switch