This commit is contained in:
2022-06-29 11:29:06 +08:00
6 changed files with 685 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
package org.nl.wms.sb.stat.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.annotation.Log;
import org.nl.wms.sb.stat.service.DevicesafetyqtyqueryService;
import org.nl.wms.sb.stat.service.DevicesparepartivtService;
import org.nl.wms.sb.stat.service.dto.DevicesparepartivtDto;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
* @author Liuxy
* @date 2022-06-28
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "备件安全库存查询")
@RequestMapping("/api/devicesafetyqtyquery")
@Slf4j
public class DevicesafetyqtyqueryController {
private final DevicesafetyqtyqueryService devicesafetyqtyqueryService;
@GetMapping
@Log("备件安全库存查询")
@ApiOperation("备件安全库存查询")
//@PreAuthorize("@el.check('devicesparepartivt:list')")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(devicesafetyqtyqueryService.queryAll(whereJson, page), HttpStatus.OK);
}
@PostMapping
@Log("新增备件安全库存查询")
@ApiOperation("新增备件安全库存查询")
//@PreAuthorize("@el.check('devicesparepartivt:add')")
public ResponseEntity<Object> create(@Validated @RequestBody DevicesparepartivtDto dto) {
devicesafetyqtyqueryService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改备件安全库存查询")
@ApiOperation("修改备件安全库存查询")
//@PreAuthorize("@el.check('devicesparepartivt:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody DevicesparepartivtDto dto) {
devicesafetyqtyqueryService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除备件安全库存查询")
@ApiOperation("删除备件安全库存查询")
//@PreAuthorize("@el.check('devicesparepartivt:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
devicesafetyqtyqueryService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@ApiOperation("导出数据")
@GetMapping(value = "/download")
public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException {
devicesafetyqtyqueryService.download(whereJson, response);
}
}

View File

@@ -0,0 +1,76 @@
package org.nl.wms.sb.stat.service;
import org.nl.wms.sb.stat.service.dto.DevicesparepartivtDto;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @author Liuxy
* @description 服务接口
* @date 2022-06-28
**/
public interface DevicesafetyqtyqueryService {
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> queryAll(Map whereJson, Pageable page);
/**
* 查询所有数据不分页
*
* @param whereJson 条件参数
* @return List<DevicesparepartivtDto>
*/
List<DevicesparepartivtDto> queryAll(Map whereJson);
/**
* 根据ID查询
*
* @param stockrecord_id ID
* @return Devicesparepartivt
*/
DevicesparepartivtDto findById(Long stockrecord_id);
/**
* 根据编码查询
*
* @param code code
* @return Devicesparepartivt
*/
DevicesparepartivtDto findByCode(String code);
/**
* 创建
*
* @param dto /
*/
void create(DevicesparepartivtDto dto);
/**
* 编辑
*
* @param dto /
*/
void update(DevicesparepartivtDto dto);
/**
* 多选删除
*
* @param ids /
*/
void deleteAll(Long[] ids);
void download(Map whereJson, HttpServletResponse response) throws IOException;
}

View File

@@ -0,0 +1,197 @@
package org.nl.wms.sb.stat.service.impl;
import cn.hutool.core.date.DateUtil;
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 com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.exception.BadRequestException;
import org.nl.utils.FileUtil;
import org.nl.utils.SecurityUtils;
import org.nl.wms.basedata.master.service.ClassstandardService;
import org.nl.wms.sb.stat.service.DevicesafetyqtyqueryService;
import org.nl.wms.sb.stat.service.DevicesparepartivtService;
import org.nl.wms.sb.stat.service.dto.DevicesparepartivtDto;
import org.nl.wql.WQL;
import org.nl.wql.core.bean.WQLObject;
import org.nl.wql.util.WqlUtil;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* @author Liuxy
* @description 服务实现
* @date 2022-06-28
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class DevicesafetyqtyqueryServiceImpl implements DevicesafetyqtyqueryService {
private final ClassstandardService classstandardService;
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
String material_type_id = MapUtil.getStr(whereJson, "material_type_id");
String class_idStr = (String) whereJson.get("class_idStr");
String material_code = MapUtil.getStr(whereJson, "material_code");
String type = MapUtil.getStr(whereJson, "type");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("type",type);
if (ObjectUtil.isNotEmpty(material_code)) map.put("material_code", "%"+material_code+"%");
//处理物料当前节点的所有子节点
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);
}
JSONObject json = WQL.getWO("EM_DEVICESAFETQTYQUERY001").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "ivt.material_id DESC");
JSONArray content = json.getJSONArray("content");
for (int i = 0; i < content.size(); i++) {
JSONObject jsonObject = content.getJSONObject(i);
if (ObjectUtil.isEmpty(jsonObject.getString("safe_ivt_up"))) jsonObject.put("safe_ivt_up","99999999");
if (ObjectUtil.isEmpty(jsonObject.getString("safe_ivt_down"))) jsonObject.put("safe_ivt_down","0");
}
json.put("content",content);
return json;
}
@Override
public List<DevicesparepartivtDto> queryAll(Map whereJson) {
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONArray arr = wo.query().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(DevicesparepartivtDto.class);
return null;
}
@Override
public DevicesparepartivtDto findById(Long stockrecord_id) {
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = wo.query("stockrecord_id = '" + stockrecord_id + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DevicesparepartivtDto.class);
}
return null;
}
@Override
public DevicesparepartivtDto findByCode(String code) {
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DevicesparepartivtDto.class);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DevicesparepartivtDto dto) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
dto.setStockrecord_id(IdUtil.getSnowflake(1, 1).nextId());
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.insert(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DevicesparepartivtDto dto) {
DevicesparepartivtDto entity = this.findById(dto.getStockrecord_id());
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
for (Long stockrecord_id : ids) {
JSONObject param = new JSONObject();
param.put("stockrecord_id", String.valueOf(stockrecord_id));
param.put("is_delete", "1");
param.put("update_optid", currentUserId);
param.put("update_optname", nickName);
param.put("update_time", now);
wo.update(param);
}
}
@Override
public void download(Map whereJson, HttpServletResponse response) throws IOException {
String material_type_id = MapUtil.getStr(whereJson, "material_type_id");
String class_idStr = (String) whereJson.get("class_idStr");
String material_code = MapUtil.getStr(whereJson, "material_code");
String type = MapUtil.getStr(whereJson, "type");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("type",type);
if (ObjectUtil.isNotEmpty(material_code)) map.put("material_code", "%"+material_code+"%");
//处理物料当前节点的所有子节点
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);
}
JSONArray rows = WQL.getWO("EM_DEVICESAFETQTYQUERY001").addParamMap(map).process().getResultJSONArray(0);
for (int i = 0; i < rows.size(); i++) {
JSONObject jsonObject = rows.getJSONObject(i);
if (ObjectUtil.isEmpty(jsonObject.getString("safe_ivt_up"))) jsonObject.put("safe_ivt_up","99999999");
if (ObjectUtil.isEmpty(jsonObject.getString("safe_ivt_down"))) jsonObject.put("safe_ivt_down","0");
}
List<Map<String, Object>> list = new ArrayList<>();
for (int i = 0; i < rows.size(); i++) {
JSONObject jo = rows.getJSONObject(i);
Map<String, Object> dtl_map = new LinkedHashMap<>();
dtl_map.put("物料编码", jo.getString("material_code"));
dtl_map.put("物料名称", jo.getString("material_name"));
dtl_map.put("物料分类", jo.getString("class_name"));
dtl_map.put("安全库存上限", jo.getString("safe_ivt_up"));
dtl_map.put("安全库存下限", jo.getString("safe_ivt_down"));
dtl_map.put("库存", jo.getString("ivt_qty"));
dtl_map.put("单位", jo.getString("qty_unit_name"));
list.add(dtl_map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@@ -0,0 +1,86 @@
[交易说明]
交易名: 安全库存查询分页查询
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.classIds TYPEAS f_string
输入.material_code TYPEAS s_string
输入.type TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
PAGEQUERY
SELECT
mater.material_code,
mater.material_name,
MAX( class.class_name ) AS class_name,
MAX( saivt.safe_ivt_up ) AS safe_ivt_up,
MAX( saivt.safe_ivt_down ) AS safe_ivt_down,
sum(ivt.ivt_qty) AS ivt_qty,
MAX(ivt.qty_unit_name) AS qty_unit_name
FROM
EM_BI_DeviceSparePartIvt ivt
LEFT JOIN ST_IVT_MaterialSafeIvt saivt ON saivt.material_id = ivt.material_id
LEFT JOIN md_me_materialbase mater ON mater.material_id = ivt.material_id
LEFT JOIN md_pb_classstandard class ON mater.material_type_id = class.class_id
WHERE
1=1
OPTION 输入.classIds <> ""
class.class_id in 输入.classIds
ENDOPTION
OPTION 输入.material_code <> ""
(mater.material_code like 输入.material_code or
mater.material_name like 输入.material_code)
ENDOPTION
OPTION 输入.type = "01"
ivt.ivt_qty > saivt.safe_ivt_up
ENDOPTION
OPTION 输入.type = "02"
ivt.ivt_qty < saivt.safe_ivt_down
ENDOPTION
OPTION 输入.type = "03"
saivt.safe_ivt_up <= ivt.ivt_qty <= saivt.safe_ivt_up
ENDOPTION
group by ivt.material_id
ENDSELECT
ENDPAGEQUERY
ENDIF