fix:用户设备
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
package org.nl.wms.basedata.st.rest;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.modules.logging.annotation.Log;
|
||||||
|
import org.nl.wms.basedata.st.service.UserAreaService;
|
||||||
|
import org.nl.wms.basedata.st.service.UserDeviceService;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
|
||||||
|
@RequestMapping("/api/userDevice")
|
||||||
|
@Slf4j
|
||||||
|
public class UserDeviceController {
|
||||||
|
private final UserDeviceService userDeviceService;
|
||||||
|
|
||||||
|
@PostMapping("/queryUserDevice")
|
||||||
|
@Log("查询用户对应区域")
|
||||||
|
|
||||||
|
public ResponseEntity<Object> queryUserArea(@RequestBody JSONObject whereJson) {
|
||||||
|
return new ResponseEntity<>(userDeviceService.queryUserDevice(whereJson), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/save")
|
||||||
|
@Log("保存用户仓库信息")
|
||||||
|
|
||||||
|
public ResponseEntity<Object> save(@RequestBody JSONObject whereJson) {
|
||||||
|
userDeviceService.save(whereJson);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.nl.wms.basedata.st.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface UserDeviceService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户对应仓库
|
||||||
|
*
|
||||||
|
* @param whereJson /
|
||||||
|
*/
|
||||||
|
JSONArray queryUserDevice(JSONObject whereJson);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
*
|
||||||
|
* @param whereJson /
|
||||||
|
*/
|
||||||
|
void save(JSONObject whereJson);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package org.nl.wms.basedata.st.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.nl.common.utils.SecurityUtils;
|
||||||
|
import org.nl.modules.wql.WQL;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
|
import org.nl.modules.wql.util.WqlUtil;
|
||||||
|
import org.nl.wms.basedata.st.service.UserAreaService;
|
||||||
|
import org.nl.wms.basedata.st.service.UserDeviceService;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PC端出入库新增
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class UserDeviceServiceImpl implements UserDeviceService {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONArray queryUserDevice(JSONObject whereJson) {
|
||||||
|
String user_id = whereJson.getString("user_id");
|
||||||
|
JSONArray rows = WQLObject.getWQLObject("st_ivt_userdevice").query("user_id = '" + user_id + "'").getResultJSONArray(0);
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(JSONObject whereJson) {
|
||||||
|
JSONObject jo = whereJson.getJSONObject("jo");
|
||||||
|
JSONArray rows = whereJson.getJSONArray("rows");
|
||||||
|
|
||||||
|
String user_id = jo.getString("user_id");
|
||||||
|
|
||||||
|
WQLObject.getWQLObject("st_ivt_userdevice").delete("user_id ='" + user_id + "'");
|
||||||
|
for (int i = 0; i < rows.size(); i++) {
|
||||||
|
JSONObject row = rows.getJSONObject(i);
|
||||||
|
String region_code = row.getString("region_code");
|
||||||
|
JSONObject user_device = new JSONObject();
|
||||||
|
user_device.put("region_code", region_code);
|
||||||
|
user_device.put("user_id", user_id);
|
||||||
|
WQLObject.getWQLObject("st_ivt_userdevice").insert(user_device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInArea() {
|
||||||
|
String currentUserId = SecurityUtils.getCurrentUserId().toString();
|
||||||
|
WQLObject userdeviceTab = WQLObject.getWQLObject("st_ivt_userdevice");
|
||||||
|
|
||||||
|
JSONArray userStorArr = userdeviceTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0);
|
||||||
|
int size = userStorArr.size();
|
||||||
|
// 将仓库id拼成字符串
|
||||||
|
String in_stor_id = "";
|
||||||
|
|
||||||
|
for (int i = 0; i < userStorArr.size(); i++) {
|
||||||
|
JSONObject json = userStorArr.getJSONObject(i);
|
||||||
|
|
||||||
|
if (size == 1) {
|
||||||
|
// 如果只有一条记录
|
||||||
|
in_stor_id = "('" + json.getString("region_code") + "')";
|
||||||
|
} else {
|
||||||
|
if (i == 0) {
|
||||||
|
// 第一条记录拼接
|
||||||
|
in_stor_id = "('" + json.getString("region_code") + "','";
|
||||||
|
} else {
|
||||||
|
if ((size - 1) == i) {
|
||||||
|
// 最后一条记录拼接
|
||||||
|
in_stor_id += json.getString("region_code") + "')";
|
||||||
|
} else {
|
||||||
|
in_stor_id += json.getString("region_code") + "','";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(in_stor_id)) {
|
||||||
|
in_stor_id = "('')";
|
||||||
|
}
|
||||||
|
return in_stor_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user