Browse Source

opt: 仓库基础->仓库权限 Mybatis优化

master
liejiu946 3 weeks ago
parent
commit
6d96c40e06
  1. 118
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/rest/UserStorController.java
  2. 100
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/service/UserStorService.java
  3. 398
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/service/impl/UserStorServiceImpl.java
  4. 60
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/controller/UserStorController.java
  5. 54
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/UserStorService.java
  6. 24
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dao/UserStor.java
  7. 18
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dao/mapper/UserStorMapper.java
  8. 19
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dao/mapper/UserStorMapper.xml
  9. 17
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dto/UserStorDto.java
  10. 203
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/impl/UserStorServiceImpl.java

118
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/rest/UserStorController.java

@ -1,59 +1,59 @@
package org.nl.wms.basedata.st.rest; //package org.nl.wms.basedata.st.rest;
//
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.annotation.Log; //import org.nl.modules.logging.annotation.Log;
import org.nl.wms.basedata.st.service.UserStorService; //import org.nl.wms.basedata.st.service.UserStorService;
import org.springframework.data.domain.Pageable; //import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; //import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; //import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; //import org.springframework.web.bind.annotation.*;
//
import java.util.Map; //import java.util.Map;
//
@RestController //@RestController
@RequiredArgsConstructor //@RequiredArgsConstructor
//
@RequestMapping("/api/userStor") //@RequestMapping("/api/userStor")
@Slf4j //@Slf4j
public class UserStorController { //public class UserStorController {
private final UserStorService userStorService; // private final UserStorService userStorService;
//
@GetMapping // @GetMapping
@Log("查询用户信息") // @Log("查询用户信息")
//
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) { // public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(userStorService.pageQuery(whereJson, page), HttpStatus.OK); // return new ResponseEntity<>(userStorService.pageQuery(whereJson, page), HttpStatus.OK);
} // }
//
@PostMapping("/queryUserStor") // @PostMapping("/queryUserStor")
@Log("查询用户对应仓库") // @Log("查询用户对应仓库")
//
public ResponseEntity<Object> queryUserStor(@RequestBody JSONObject whereJson) { // public ResponseEntity<Object> queryUserStor(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(userStorService.queryUserStor(whereJson), HttpStatus.OK); // return new ResponseEntity<>(userStorService.queryUserStor(whereJson), HttpStatus.OK);
} // }
//
@PostMapping("/save") // @PostMapping("/save")
@Log("保存用户仓库信息") // @Log("保存用户仓库信息")
//
public ResponseEntity<Object> save(@RequestBody JSONObject whereJson) { // public ResponseEntity<Object> save(@RequestBody JSONObject whereJson) {
userStorService.save(whereJson); // userStorService.save(whereJson);
return new ResponseEntity<>(HttpStatus.OK); // return new ResponseEntity<>(HttpStatus.OK);
} // }
//
@PostMapping("/getUserStor") // @PostMapping("/getUserStor")
@Log("获取人员对应下拉框-普通下拉框") // @Log("获取人员对应下拉框-普通下拉框")
//
public ResponseEntity<Object> getUserStor() { // public ResponseEntity<Object> getUserStor() {
return new ResponseEntity<>(userStorService.getUserStor(), HttpStatus.OK); // return new ResponseEntity<>(userStorService.getUserStor(), HttpStatus.OK);
} // }
//
@PostMapping("/getSect") // @PostMapping("/getSect")
@Log("获取人员对应下拉框-多级下拉框") // @Log("获取人员对应下拉框-多级下拉框")
//
public ResponseEntity<Object> getSect(@RequestBody JSONObject whereJson) { // public ResponseEntity<Object> getSect(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(userStorService.getSect(whereJson), HttpStatus.OK); // return new ResponseEntity<>(userStorService.getSect(whereJson), HttpStatus.OK);
} // }
//
} //}

100
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/service/UserStorService.java

@ -1,50 +1,50 @@
package org.nl.wms.basedata.st.service; //package org.nl.wms.basedata.st.service;
//
import com.alibaba.fastjson.JSONArray; //import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
import org.nl.wms.basedata.st.storattr.service.dao.Storattr; //import org.nl.wms.basedata.st.storattr.service.dao.Storattr;
import org.springframework.data.domain.Pageable; //import org.springframework.data.domain.Pageable;
//
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
//
public interface UserStorService { //public interface UserStorService {
/** // /**
* 查询数据分页 // * 查询数据分页
* // *
* @param whereJson 条件 // * @param whereJson 条件
* @param page 分页参数 // * @param page 分页参数
* @return Map<String, Object> // * @return Map<String, Object>
*/ // */
Map<String, Object> pageQuery(Map whereJson, Pageable page); // Map<String, Object> pageQuery(Map whereJson, Pageable page);
//
/** // /**
* 查询用户对应仓库 // * 查询用户对应仓库
* // *
* @param whereJson / // * @param whereJson /
*/ // */
JSONArray queryUserStor(JSONObject whereJson); // JSONArray queryUserStor(JSONObject whereJson);
//
/** // /**
* 保存 // * 保存
* // *
* @param whereJson / // * @param whereJson /
*/ // */
void save(JSONObject whereJson); // void save(JSONObject whereJson);
//
/** // /**
* 获取人员对应下拉框 普通下拉框 // * 获取人员对应下拉框 普通下拉框
*/ // */
List<Storattr> getUserStor(); // List<Storattr> getUserStor();
//
/** // /**
* 获取人员对应下拉框 多级下拉框 // * 获取人员对应下拉框 多级下拉框
*/ // */
JSONObject getSect(JSONObject whereJson); // JSONObject getSect(JSONObject whereJson);
//
/** // /**
* 获取用户下所有仓库List // * 新,获取用户下所有仓库List
* @return // * @return
*/ // */
List<String> getUserStorInStor(); // List<String> getUserStorInStor();
} //}

398
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/service/impl/UserStorServiceImpl.java

@ -1,199 +1,199 @@
package org.nl.wms.basedata.st.service.impl; //package org.nl.wms.basedata.st.service.impl;
//
import cn.hutool.core.util.ObjectUtil; //import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; //import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray; //import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; //import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.nl.common.utils.SecurityUtils; //import org.nl.common.utils.SecurityUtils;
import org.nl.modules.wql.WQL; //import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject; //import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil; //import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.basedata.st.service.UserStorService; //import org.nl.wms.basedata.st.service.UserStorService;
import org.nl.wms.basedata.st.storattr.service.dao.Storattr; //import org.nl.wms.basedata.st.storattr.service.dao.Storattr;
import org.nl.wms.basedata.st.storattr.service.dao.mapper.StorattrMapper; //import org.nl.wms.basedata.st.storattr.service.dao.mapper.StorattrMapper;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; //import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
import java.util.*; //import java.util.*;
//
/** ///**
* PC端出入库新增 // * PC端出入库新增
*/ // */
@Service //@Service
@RequiredArgsConstructor //@RequiredArgsConstructor
@Slf4j //@Slf4j
public class UserStorServiceImpl implements UserStorService { //public class UserStorServiceImpl implements UserStorService {
@Autowired // @Autowired
private StorattrMapper storattrMapper; // private StorattrMapper storattrMapper;
@Override // @Override
public Map<String, Object> pageQuery(Map whereJson, Pageable page) { // public Map<String, Object> pageQuery(Map whereJson, Pageable page) {
HashMap<String, String> map = new HashMap<>(whereJson); // HashMap<String, String> map = new HashMap<>(whereJson);
map.put("flag", "3"); // map.put("flag", "3");
if (StrUtil.isNotEmpty(map.get("blurry"))) { // if (StrUtil.isNotEmpty(map.get("blurry"))) {
map.put("blurry", "%" + map.get("blurry") + "%"); // map.put("blurry", "%" + map.get("blurry") + "%");
} // }
JSONObject jo = WQL.getWO("QST_STOR_ATTR").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "username desc"); // JSONObject jo = WQL.getWO("QST_STOR_ATTR").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "username desc");
return jo; // return jo;
} // }
//
@Override // @Override
public JSONArray queryUserStor(JSONObject whereJson) { // public JSONArray queryUserStor(JSONObject whereJson) {
String user_id = whereJson.getString("user_id"); // String user_id = whereJson.getString("user_id");
JSONArray rows = WQLObject.getWQLObject("st_ivt_userstor").query("user_id = '" + user_id + "'").getResultJSONArray(0); // JSONArray rows = WQLObject.getWQLObject("st_ivt_userstor").query("user_id = '" + user_id + "'").getResultJSONArray(0);
return rows; // return rows;
} // }
//
@Override // @Override
public void save(JSONObject whereJson) { // public void save(JSONObject whereJson) {
JSONObject jo = whereJson.getJSONObject("jo"); // JSONObject jo = whereJson.getJSONObject("jo");
JSONArray rows = whereJson.getJSONArray("rows"); // JSONArray rows = whereJson.getJSONArray("rows");
//
String user_id = jo.getString("user_id"); // String user_id = jo.getString("user_id");
//
WQLObject.getWQLObject("st_ivt_userstor").delete("user_id ='" + user_id + "'"); // WQLObject.getWQLObject("st_ivt_userstor").delete("user_id ='" + user_id + "'");
for (int i = 0; i < rows.size(); i++) { // for (int i = 0; i < rows.size(); i++) {
JSONObject row = rows.getJSONObject(i); // JSONObject row = rows.getJSONObject(i);
String stor_id = row.getString("stor_id"); // String stor_id = row.getString("stor_id");
JSONObject user_stor = new JSONObject(); // JSONObject user_stor = new JSONObject();
user_stor.put("stor_id", stor_id); // user_stor.put("stor_id", stor_id);
user_stor.put("user_id", user_id); // user_stor.put("user_id", user_id);
WQLObject.getWQLObject("st_ivt_userstor").insert(user_stor); // WQLObject.getWQLObject("st_ivt_userstor").insert(user_stor);
} // }
} // }
//
@Override // @Override
public List<Storattr> getUserStor() { // public List<Storattr> getUserStor() {
/* // /*
* 获取人员对应仓库下拉框公共方法 普通下拉框 // * 获取人员对应仓库下拉框公共方法 普通下拉框
*/ // */
String currentUserId = SecurityUtils.getCurrentUserId(); // String currentUserId = SecurityUtils.getCurrentUserId();
//
WQLObject userStorTab = WQLObject.getWQLObject("st_ivt_userstor"); // WQLObject userStorTab = WQLObject.getWQLObject("st_ivt_userstor");
//
JSONArray userStorArr = userStorTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0); // JSONArray userStorArr = userStorTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0);
// 将仓库id拼成字符串 // // 将仓库id拼成字符串
Set<String> set = new HashSet<>(); // Set<String> set = new HashSet<>();
for (int i = 0; i < userStorArr.size(); i++) { // for (int i = 0; i < userStorArr.size(); i++) {
JSONObject json = userStorArr.getJSONObject(i); // JSONObject json = userStorArr.getJSONObject(i);
set.add(json.getString("stor_id")); // set.add(json.getString("stor_id"));
} // }
//
// 查询仓库下拉框 // // 查询仓库下拉框
List<Storattr> resultJSONArray = new ArrayList<Storattr>(); // List<Storattr> resultJSONArray = new ArrayList<Storattr>();
if (set.size()>0) { // if (set.size()>0) {
resultJSONArray =storattrMapper.selectList( Wrappers.lambdaQuery(Storattr.class) // resultJSONArray =storattrMapper.selectList( Wrappers.lambdaQuery(Storattr.class)
.eq(Storattr::getIs_delete, "0") // .eq(Storattr::getIs_delete, "0")
.eq(Storattr::getIs_used, "1").in(Storattr::getStor_id,set) // .eq(Storattr::getIs_used, "1").in(Storattr::getStor_id,set)
); // );
} // }
return resultJSONArray; // return resultJSONArray;
} // }
//
@Override // @Override
public JSONObject getSect(JSONObject whereJson) { // public JSONObject getSect(JSONObject whereJson) {
/* // /*
* 获取人员对应仓库下拉框公共方法 多级下拉框 // * 获取人员对应仓库下拉框公共方法 多级下拉框
*/ // */
JSONArray new_ja = new JSONArray(); // JSONArray new_ja = new JSONArray();
HashMap<String, String> stor_map = new HashMap<>(); // HashMap<String, String> stor_map = new HashMap<>();
stor_map.put("flag", "2"); // stor_map.put("flag", "2");
stor_map.put("stor_id", whereJson.getString("stor_id")); // stor_map.put("stor_id", whereJson.getString("stor_id"));
//
//获取人员对应的仓库 // //获取人员对应的仓库
String in_stor_id = this.getInStor(); // String in_stor_id = this.getInStor();
if (ObjectUtil.isNotEmpty(in_stor_id)) { // if (ObjectUtil.isNotEmpty(in_stor_id)) {
stor_map.put("in_stor_id", in_stor_id); // stor_map.put("in_stor_id", in_stor_id);
} // }
//
JSONArray stor_ja = WQL.getWO("QST_STOR_ATTR").addParamMap(stor_map).process().getResultJSONArray(0); // JSONArray stor_ja = WQL.getWO("QST_STOR_ATTR").addParamMap(stor_map).process().getResultJSONArray(0);
for (int i = 0; i < stor_ja.size(); i++) { // for (int i = 0; i < stor_ja.size(); i++) {
JSONObject stor_jo = stor_ja.getJSONObject(i); // JSONObject stor_jo = stor_ja.getJSONObject(i);
JSONObject stor_cas = new JSONObject(); // JSONObject stor_cas = new JSONObject();
stor_cas.put("value", stor_jo.getString("stor_id")); // stor_cas.put("value", stor_jo.getString("stor_id"));
stor_cas.put("label", stor_jo.getString("stor_name")); // stor_cas.put("label", stor_jo.getString("stor_name"));
HashMap<String, String> map = new HashMap<>(); // HashMap<String, String> map = new HashMap<>();
map.put("flag", "2"); // map.put("flag", "2");
map.put("stor_id", stor_jo.getString("stor_id")); // map.put("stor_id", stor_jo.getString("stor_id"));
JSONArray ja = WQL.getWO("QST_SECT_ATTR").addParamMap(map).process().getResultJSONArray(0); // JSONArray ja = WQL.getWO("QST_SECT_ATTR").addParamMap(map).process().getResultJSONArray(0);
if (ja.size() > 0) { // if (ja.size() > 0) {
JSONArray sect_ja = new JSONArray(); // JSONArray sect_ja = new JSONArray();
for (int j = 0; j < ja.size(); j++) { // for (int j = 0; j < ja.size(); j++) {
JSONObject sect_jo = ja.getJSONObject(j); // JSONObject sect_jo = ja.getJSONObject(j);
JSONObject sect_cas = new JSONObject(); // JSONObject sect_cas = new JSONObject();
sect_cas.put("value", sect_jo.getString("sect_id")); // sect_cas.put("value", sect_jo.getString("sect_id"));
sect_cas.put("label", sect_jo.getString("sect_name")); // sect_cas.put("label", sect_jo.getString("sect_name"));
sect_ja.add(sect_cas); // sect_ja.add(sect_cas);
} // }
stor_cas.put("children", sect_ja); // stor_cas.put("children", sect_ja);
} // }
new_ja.add(stor_cas); // new_ja.add(stor_cas);
} // }
JSONObject jo = new JSONObject(); // JSONObject jo = new JSONObject();
jo.put("content", new_ja); // jo.put("content", new_ja);
return jo; // return jo;
} // }
//
//
@Override // @Override
public List<String> getUserStorInStor() { // public List<String> getUserStorInStor() {
/* // /*
* 获取人员对应仓库下拉框公共方法 普通下拉框 // * 获取人员对应仓库下拉框公共方法 普通下拉框
*/ // */
String currentUserId = SecurityUtils.getCurrentUserId(); // String currentUserId = SecurityUtils.getCurrentUserId();
//
WQLObject userStorTab = WQLObject.getWQLObject("st_ivt_userstor"); // WQLObject userStorTab = WQLObject.getWQLObject("st_ivt_userstor");
//
JSONArray userStorArr = userStorTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0); // JSONArray userStorArr = userStorTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0);
// 将仓库id拼成字符串 // // 将仓库id拼成字符串
List<String> set = new ArrayList<>(); // List<String> set = new ArrayList<>();
for (int i = 0; i < userStorArr.size(); i++) { // for (int i = 0; i < userStorArr.size(); i++) {
JSONObject json = userStorArr.getJSONObject(i); // JSONObject json = userStorArr.getJSONObject(i);
set.add(json.getString("stor_id")); // set.add(json.getString("stor_id"));
} // }
return set; // return set;
} // }
/** // /**
* 获取仓库拼接公共方法 // * 获取仓库拼接公共方法
* // *
* @return in_stor_id / // * @return in_stor_id /
*/ // */
public String getInStor() { // public String getInStor() {
String currentUserId = SecurityUtils.getCurrentUserId().toString(); // String currentUserId = SecurityUtils.getCurrentUserId().toString();
WQLObject userStorTab = WQLObject.getWQLObject("st_ivt_userstor"); // WQLObject userStorTab = WQLObject.getWQLObject("st_ivt_userstor");
//
JSONArray userStorArr = userStorTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0); // JSONArray userStorArr = userStorTab.query("user_id = '" + currentUserId + "'").getResultJSONArray(0);
int size = userStorArr.size(); // int size = userStorArr.size();
// 将仓库id拼成字符串 // // 将仓库id拼成字符串
String in_stor_id = ""; // String in_stor_id = "";
//
for (int i = 0; i < userStorArr.size(); i++) { // for (int i = 0; i < userStorArr.size(); i++) {
JSONObject json = userStorArr.getJSONObject(i); // JSONObject json = userStorArr.getJSONObject(i);
//
if (size == 1) { // if (size == 1) {
// 如果只有一条记录 // // 如果只有一条记录
in_stor_id = "('" + json.getString("stor_id") + "')"; // in_stor_id = "('" + json.getString("stor_id") + "')";
} else { // } else {
if (i == 0) { // if (i == 0) {
// 第一条记录拼接 // // 第一条记录拼接
in_stor_id = "('" + json.getString("stor_id") + "','"; // in_stor_id = "('" + json.getString("stor_id") + "','";
} else { // } else {
if ((size - 1) == i) { // if ((size - 1) == i) {
// 最后一条记录拼接 // // 最后一条记录拼接
in_stor_id += json.getString("stor_id") + "')"; // in_stor_id += json.getString("stor_id") + "')";
} else { // } else {
in_stor_id += json.getString("stor_id") + "','"; // in_stor_id += json.getString("stor_id") + "','";
} // }
} // }
} // }
} // }
//
if (ObjectUtil.isEmpty(in_stor_id)) { // if (ObjectUtil.isEmpty(in_stor_id)) {
in_stor_id = "('')"; // in_stor_id = "('')";
} // }
return in_stor_id; // return in_stor_id;
} // }
//
} //}

60
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/controller/UserStorController.java

@ -0,0 +1,60 @@
package org.nl.wms.basedata.st.userstor.controller;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.domain.query.PageQuery;
import org.nl.modules.logging.annotation.Log;
import org.nl.wms.basedata.st.userstor.service.UserStorService;
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/userStor")
@Slf4j
public class UserStorController {
private final UserStorService userStorService;
@GetMapping
@Log("查询用户信息")
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
return new ResponseEntity<>(userStorService.pageQuery(whereJson, page), HttpStatus.OK);
}
@PostMapping("/queryUserStor")
@Log("查询用户对应仓库")
public ResponseEntity<Object> queryUserStor(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(userStorService.queryUserStor(whereJson), HttpStatus.OK);
}
@PostMapping("/save")
@Log("保存用户仓库信息")
public ResponseEntity<Object> save(@RequestBody JSONObject whereJson) {
userStorService.save(whereJson);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/getUserStor")
@Log("获取人员对应下拉框-普通下拉框")
public ResponseEntity<Object> getUserStor() {
return new ResponseEntity<>(userStorService.getUserStor(), HttpStatus.OK);
}
@PostMapping("/getSect")
@Log("获取人员对应下拉框-多级下拉框")
public ResponseEntity<Object> getSect(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(userStorService.getSect(whereJson), HttpStatus.OK);
}
}

54
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/UserStorService.java

@ -0,0 +1,54 @@
package org.nl.wms.basedata.st.userstor.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.common.domain.query.PageQuery;
import org.nl.wms.basedata.st.storattr.service.dao.Storattr;
import org.nl.wms.basedata.st.userstor.service.dao.UserStor;
import org.nl.wms.basedata.st.userstor.service.dto.UserStorDto;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
public interface UserStorService extends IService<UserStor> {
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> pageQuery(Map whereJson, PageQuery page);
/**
* 查询用户对应仓库
*
* @param whereJson /
*/
List<UserStor> queryUserStor(JSONObject whereJson);
/**
* 保存
*
* @param whereJson /
*/
void save(JSONObject whereJson);
/**
* 获取人员对应下拉框 普通下拉框
*/
List<Storattr> getUserStor();
/**
* 获取人员对应下拉框 多级下拉框
*/
JSONObject getSect(JSONObject whereJson);
/**
* 获取用户下所有仓库List
* @return
*/
List<Long> getUserStorInStor();
}

24
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dao/UserStor.java

@ -0,0 +1,24 @@
package org.nl.wms.basedata.st.userstor.service.dao;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.nl.common.base.BaseDTO;
import org.nl.system.service.user.dao.SysUser;
import java.io.Serializable;
@Data
@TableName("st_ivt_userstor")
public class UserStor implements Serializable {
/**
* 防止精度丢失
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long stor_id;
private Long user_id;
}

18
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dao/mapper/UserStorMapper.java

@ -0,0 +1,18 @@
package org.nl.wms.basedata.st.userstor.service.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.nl.wms.basedata.st.userstor.service.dao.UserStor;
import org.nl.wms.basedata.st.userstor.service.dto.UserStorDto;
@Mapper
public interface UserStorMapper extends BaseMapper<UserStor> {
/**
* 分页查询
* @param blurry
* @return
*/
IPage<UserStorDto> pageQuery(@Param("blurry") String blurry, @Param("page") IPage<UserStorDto> page);
}

19
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dao/mapper/UserStorMapper.xml

@ -0,0 +1,19 @@
<?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.st.userstor.service.dao.mapper.UserStorMapper">
<select id="pageQuery" resultType="org.nl.wms.basedata.st.userstor.service.dto.UserStorDto">
SELECT sys_user.* , dept.name
FROM sys_user sys_user
LEFT JOIN sys_user_dept sdept ON sdept.user_id = sys_user.user_id
LEFT JOIN sys_dept dept ON dept.dept_id = sdept.dept_id
<where>
sys_user.is_used = '1'
<if test="blurry != null">
and (username like #{blurry} or person_name like #{blurry})
</if>
</where>
order by username desc
</select>
</mapper>

17
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/dto/UserStorDto.java

@ -0,0 +1,17 @@
package org.nl.wms.basedata.st.userstor.service.dto;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.nl.system.service.user.dao.SysUser;
import java.io.Serializable;
@Data
public class UserStorDto extends SysUser implements Serializable {
/**
* 部门名称
*/
private String name;
}

203
lms/nladmin-system/src/main/java/org/nl/wms/basedata/st/userstor/service/impl/UserStorServiceImpl.java

@ -0,0 +1,203 @@
package org.nl.wms.basedata.st.userstor.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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.nl.common.domain.query.PageQuery;
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.system.service.user.dto.SysUserDetail;
import org.nl.wms.basedata.st.sectattr.service.SectattrService;
import org.nl.wms.basedata.st.sectattr.service.dao.Sectattr;
import org.nl.wms.basedata.st.sectattr.service.dao.mapper.SectattrMapper;
import org.nl.wms.basedata.st.storattr.service.dao.Storattr;
import org.nl.wms.basedata.st.storattr.service.dao.mapper.StorattrMapper;
import org.nl.wms.basedata.st.userstor.service.UserStorService;
import org.nl.wms.basedata.st.userstor.service.dao.UserStor;
import org.nl.wms.basedata.st.userstor.service.dao.mapper.UserStorMapper;
import org.nl.wms.basedata.st.userstor.service.dto.UserStorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* PC端出入库新增
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class UserStorServiceImpl extends ServiceImpl<UserStorMapper, UserStor> implements UserStorService {
@Autowired
private StorattrMapper storattrMapper;
@Autowired
private UserStorMapper userStorMapper;
@Autowired
private SectattrMapper sectattrMapper;
@Override
public Map<String, Object> pageQuery(Map whereJson, PageQuery page) {
HashMap<String, String> map = new HashMap<>(whereJson);
IPage<UserStorDto> pages = new Page<>(page.getPage() + 1, page.getSize());
IPage<UserStorDto> userStorList = userStorMapper.pageQuery(map.get("blurry"),pages);
JSONObject jsonObject = new JSONObject();
jsonObject.put("totalElements", userStorList.getTotal());
jsonObject.put("content", userStorList.getRecords());
return jsonObject;
}
@Override
public List<UserStor> queryUserStor(JSONObject whereJson) {
return userStorMapper.selectList(Wrappers.lambdaQuery(UserStor.class).eq(UserStor::getUser_id,whereJson.getString("user_id")));
}
@Override
public void save(JSONObject whereJson) {
JSONObject jo = whereJson.getJSONObject("jo");
JSONArray rows = whereJson.getJSONArray("rows");
String user_id = jo.getString("user_id");
userStorMapper.delete(Wrappers.lambdaQuery(UserStor.class).eq(UserStor::getUser_id,user_id));
for (int i = 0; i < rows.size(); i++) {
JSONObject row = rows.getJSONObject(i);
String stor_id = row.getString("stor_id");
UserStor userStor = new UserStor();
userStor.setStor_id(Long.valueOf(stor_id));
userStor.setUser_id(Long.valueOf(user_id));
userStorMapper.insert(userStor);
}
}
@Override
public List<Storattr> getUserStor() {
/*
* 获取人员对应仓库下拉框公共方法 普通下拉框
*/
String currentUserId = SecurityUtils.getCurrentUserId();
List<UserStor> userStorArr = userStorMapper.selectList(Wrappers.lambdaQuery(UserStor.class).eq(UserStor::getUser_id,currentUserId));
// 将仓库id拼成字符串
Set<Long> set = userStorArr.stream().map(UserStor::getStor_id).collect(Collectors.toSet());
// 查询仓库下拉框
List<Storattr> resultJSONArray = new ArrayList<Storattr>();
if (!set.isEmpty()) {
resultJSONArray =storattrMapper.selectList( Wrappers.lambdaQuery(Storattr.class)
.eq(Storattr::getIs_delete, "0")
.eq(Storattr::getIs_used, "1").in(Storattr::getStor_id,set)
);
}
return resultJSONArray;
}
@Override
public JSONObject getSect(JSONObject whereJson) {
/*
* 获取人员对应仓库下拉框公共方法 多级下拉框
*/
JSONArray new_ja = new JSONArray();
//获取人员对应的仓库
List<Long> in_stor_id = this.getUserStorInStor();
List<Storattr> stor_ja = storattrMapper.selectList(Wrappers.lambdaQuery(Storattr.class)
.eq(Storattr::getIs_delete, "0")
.eq(Storattr::getIs_used, "1")
.eq(ObjectUtil.isNotEmpty(whereJson.getString("stor_id")),Storattr::getStor_id,whereJson.getString("stor_id"))
.in(ObjectUtil.isNotEmpty(in_stor_id),Storattr::getStor_id,in_stor_id));
for (Storattr stor_jo : stor_ja) {
JSONObject stor_cas = new JSONObject();
stor_cas.put("value", stor_jo.getStor_id());
stor_cas.put("label", stor_jo.getStor_name());
List<Sectattr> ja = sectattrMapper.selectList(Wrappers.lambdaQuery(Sectattr.class)
.apply("is_delete = {0} ", "0")
.eq(Sectattr::getIs_used, "1")
.eq(ObjectUtil.isNotEmpty(stor_jo.getStor_id()), Sectattr::getStor_id, stor_jo.getStor_id()));
if (!ja.isEmpty()) {
JSONArray sect_ja = new JSONArray();
for (Sectattr sect_jo : ja) {
JSONObject sect_cas = new JSONObject();
sect_cas.put("value", sect_jo.getSect_id());
sect_cas.put("label", sect_jo.getSect_name());
sect_ja.add(sect_cas);
}
stor_cas.put("children", sect_ja);
}
new_ja.add(stor_cas);
}
JSONObject jo = new JSONObject();
jo.put("content", new_ja);
return jo;
}
/**
* 获取仓库拼接公共方法
* return List<Long>
*/
@Override
public List<Long> getUserStorInStor() {
/*
* 获取人员对应仓库下拉框公共方法 普通下拉框
*/
String currentUserId = SecurityUtils.getCurrentUserId();
return userStorMapper.selectList(Wrappers.lambdaQuery(UserStor.class).eq(UserStor::getUser_id,currentUserId)).stream()
.map(UserStor::getStor_id)
.collect(Collectors.toList());
}
/**
* 获取仓库拼接公共方法
* 应用于WQL中的 in函数更改成MybatisPlus后可使用getUserStorInStor
* @return in_stor_id /
*/
public String getInStor() {
String currentUserId = SecurityUtils.getCurrentUserId();
List<UserStor> userStorArr = userStorMapper.selectList(Wrappers.lambdaQuery(UserStor.class).eq(UserStor::getUser_id,currentUserId));
int size = userStorArr.size();
// 将仓库id拼成字符串
String in_stor_id = "";
for (int i = 0; i < userStorArr.size(); i++) {
UserStor json = userStorArr.get(i);
if (size == 1) {
// 如果只有一条记录
in_stor_id = "('" + json.getStor_id() + "')";
} else {
if (i == 0) {
// 第一条记录拼接
in_stor_id = "('" + json.getStor_id() + "','";
} else {
if ((size - 1) == i) {
// 最后一条记录拼接
in_stor_id += json.getStor_id() + "')";
} else {
in_stor_id += json.getStor_id() + "','";
}
}
}
}
if (ObjectUtil.isEmpty(in_stor_id)) {
in_stor_id = "('')";
}
return in_stor_id;
}
}
Loading…
Cancel
Save