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

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