springboot+vue.js仓储调度平台 仓库管理系统 开发纪实
程序员文章站
2024-01-15 22:26:10
...
介绍
最近公司接到一个仓库管理系统的开发,特地再次跟大家分享开发经验
技术栈
前端:vue+elementui+echarts+vuex+websocket
后端:springboot+springSecurity+MybatisPlius+Redis+websocket
系统介绍
基于B/S的仓库管理系统,本系统基于客户->订单->生产->待检->入库->盘点->出库这条企业管理链路开发。整合了springSecurity实现了,用户的认证和权限的管理,整合了Redis在权限认证时使用的redis缓存了权限的用户角色权限的数据。通过MybatisPlus大大提高了了工作效率。使用了快递鸟的第三方接口实现了物流跟踪(免费使用只支持中通、圆通、申通)。
系统运行快照
登录实现代码如下:
/**
*
* @param mobile 前端传的手机号
* @param session 保存验证码的地方
* @return
*/
@GetMapping("/smsCode")
public RespBean sms(@RequestParam("mobile") String mobile, HttpSession session) {
User user=userMapper.loadUserByUsername(mobile);
if (user == null){
return RespBean.error("该手机号未曾注册");
}
SmsCode smsCode = new SmsCode(
RandomStringUtils.randomNumeric(4), 60, mobile);
//TODO 调用短信服务
log.info(smsCode.getCode() + "->" + mobile);
session.setAttribute("sms_key",smsCode);
return RespBean.ok("短信验证码已经发送,1分钟内有效");
}
实现代码如下:
package cn.pqz.emsboot.modules.communication.controller;
import cn.pqz.emsboot.modules.sys.entity.RespBean;
import cn.pqz.emsboot.modules.sys.entity.User;
import cn.pqz.emsboot.modules.sys.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/ws")
public class WebSocketController {
@Autowired
UserService userService;
@GetMapping("/addressBook/")
public RespBean addressBook(@RequestParam("name") String name){
RespBean respBean = null;
try {
QueryWrapper queryWrapper=new QueryWrapper();
queryWrapper.like("name",name);
// queryWrapper.like("username",name);
List<User> userList = userService.list(queryWrapper);
if (userList.size()==0){
QueryWrapper queryWrapper1 = new QueryWrapper();
queryWrapper1.like("username",name);
userList=userService.list(queryWrapper1);
}
respBean=RespBean.ok("",userList);
}catch (Exception e){
e.printStackTrace();
respBean=RespBean.error("通讯录获取失败");
}
return respBean;
}
}
实现代码如下:
/**
* 获取仓库信息
*
* @return
*/
@GetMapping("/myWarehouse")
public RespBean myTransitions() {
RespBean respBean = null;
try {
List<Warehouse> warehouses = warehouseService.myTransitions();
respBean = RespBean.ok("", warehouses);
} catch (Exception e) {
e.printStackTrace();
respBean = RespBean.error("仓库数据获取失败");
}
return respBean;
}
实现代码如下:
/**
* 改变用户状态enable
* @param id
* @param enabled
* @return
*/
@PutMapping("/updateEnabled/{userId}/{userEnabled}")
public RespBean updateEnabled(@PathVariable("userId") Integer id,
@PathVariable("userEnabled") Boolean enabled,
HttpServletRequest request){
RespBean respBean=null;
User user=new User();
user.setId(id);
user.setEnabled(enabled);
// SecurityContextImpl securityContext=(SecurityContextImpl) request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
// Authentication authentication=securityContext.getAuthentication();
// UsernamePasswordAuthenticationToken auth=new UsernamePasswordAuthenticationToken(user,authentication.getCredentials());
// auth.setDetails(authentication.getDetails());
// securityContext.setAuthentication(auth);
Boolean i=userService.updateById(user);
if (i){
respBean=RespBean.ok("更新状态成功");
logger.info("----------用户状态更新成功----------");
}else{
respBean=RespBean.error("更新状态失败");
}
return respBean;
}
@PostMapping("/addUser")
public RespBean addUser(@RequestBody User user){
RespBean respBean=null;
String phone=user.getPhone();
QueryWrapper queryWrapper=new QueryWrapper();
queryWrapper.eq("phone",phone);
User user1=userService.getOne(queryWrapper);
if (!Objects.isNull(user1)){
respBean=RespBean.error(phone+"已经注册");
}else {
int i=userService.addUser(user);
if (i!=0){
respBean=RespBean.ok("添加成功");
}else{
respBean=RespBean.error("添加失败");
}
}
return respBean;
}
实现代码如下:
/**
* 展示用户列表
* @param pageNum
* @param size
* @param query
* @return
*/
@GetMapping("/userList/")
public RespBean userList(@RequestParam("pageNum") Integer pageNum,
@RequestParam("size") Integer size,
@RequestParam("query") String query){
JSONObject obj=new JSONObject();
obj.put("data",userService.userList(pageNum,size,query));
obj.put("total",userService.count(null));
RespBean resp=RespBean.ok("",obj);
// logger.info("----------获取用户列表成功----------");
return resp;
}
实现代码如下:
/**
* 角色列表(更新处理方法)
* @return
*/
@GetMapping("/roleList")
public RespBean roleList(){
RespBean respBean=null;
try{
List<Role> roleList=roleService.getRoleList();
respBean=RespBean.ok("",roleList);
}catch (Exception e){
e.printStackTrace();
respBean=RespBean.error("获取角色列表失败");
}
return respBean;
}
实现代码如下:
/**
* 添加权限
*/
@PostMapping("/staff/addPow")
public RespBean addPow(@RequestBody Menu menu){
RespBean respBean=null;
Boolean i=menuService.save(menu);
if (i){
respBean=RespBean.ok("权限添加成功");
}
else {
respBean=RespBean.error("权限添加失败");
}
return respBean;
}
实现代码如下:
package cn.pqz.emsboot.modules.output.contoller;
import cn.pqz.emsboot.modules.output.entity.OrderList;
import cn.pqz.emsboot.modules.output.service.OrderService;
import cn.pqz.emsboot.modules.sys.entity.RespBean;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/order")
public class OrderController {
@Autowired
private OrderService orderService;
/**
* 获取订单列表
* @param pageNum
* @param size
* @param query
* @return
*/
@GetMapping("/orderList/")
public RespBean orderList(@RequestParam("pageNum") Integer pageNum,
@RequestParam("size") Integer size,
@RequestParam("query") String query){
RespBean respBean=null;
JSONObject obj=new JSONObject();
obj.put("data",orderService.orderList(pageNum,size,query));
obj.put("total",orderService.count());
respBean=RespBean.ok("",obj);
return respBean;
}
/**
* 新建生产远程搜索
* @param name
* @return
*/
@GetMapping("/orders")
public RespBean orders(@RequestParam String name){
RespBean respBean=null;
try{QueryWrapper queryWrapper=new QueryWrapper();
queryWrapper.eq("orderState",1);
queryWrapper.like("name",name);
List<OrderList> orders=orderService.list(queryWrapper);
respBean=RespBean.ok("",orders);
}catch (Exception e){
e.printStackTrace();
respBean=RespBean.error("获取失败");
}
return respBean;
}
@PostMapping("/addOrder")
public RespBean addOrder(@RequestBody JSONObject json){
RespBean respBean=null;
try{
String name=json.getString("name");
Double price=json.getDouble("price");
Integer count=json.getInteger("count");
Integer cid=json.getInteger("clientId");
orderService.addOrder(name,price,count,cid);
respBean=RespBean.ok("新建订单成功");
}catch (Exception e){
e.printStackTrace();
respBean=RespBean.error("新建订单失败");
}
return respBean;
}
/**
* 修改订单
* @param order
* @return
*/
@PutMapping("/editOrder")
public RespBean editOrder(@RequestBody OrderList order){
RespBean respBean=null;
Boolean i=orderService.updateById(order);
if (i){
respBean=RespBean.ok("修改成功");
}else {
respBean=RespBean.error("修改失败");
}
return respBean;
}
@DeleteMapping("/deleteOrder/{id}")
public RespBean deleteOrder(@PathVariable("id") Integer id){
RespBean respBean=null;
Boolean i=orderService.removeById(id);
if (!i){
respBean=RespBean.error("删除失败");
}else {
respBean=RespBean.ok("删除成功");
}
return respBean;
}
}
运行视频
吊炸天springboot+vue.js仓储调度平台 仓库管理系统