基于SpringBoot的仓库管理系统-023
一、项目技术栈
Java开发工具:JDK1.8
后端框架:SpringBoot
前端:采用HTML和Vue相结合开发
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是
二、功能介绍
物资管理页面见下图。此页面主要实现物资的增加、修改、删除、查看的功能
公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作
个人信息管理、仓库管理、物资管理、物资类型管理、公告类型管理、公告管理
三、项目视频
基于SpringBoot的仓库管理系统-023
四、功能截图
五、代码实现
公告信息
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 源码需要+V:HadesTYT
*/
@RestController
@Controller
@RequestMapping("/gonggao")
public class GonggaoController {
private static final Logger logger = LoggerFactory.getLogger(GonggaoController.class);
private static final String TABLE_NAME = "gonggao";
@Autowired
private GonggaoService gonggaoService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private LaoshiService laoshiService;//仓库管理员
@Autowired
private WuziService wuziService;//物资
@Autowired
private WuziShenqingService wuziShenqingService;//物资申请
@Autowired
private XueshengService xueshengService;//用户
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("xueshengId",request.getSession().getAttribute("userId"));
else if("仓库管理员".equals(role))
params.put("laoshiId",request.getSession().getAttribute("userId"));
CommonUtil.checkMap(params);
PageUtils page = gonggaoService.queryPage(params);
//字典表数据转换
List<GonggaoView> list =(List<GonggaoView>)page.getList();
for(GonggaoView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GonggaoEntity gonggao = gonggaoService.selectById(id);
if(gonggao !=null){
//entity转view
GonggaoView view = new GonggaoView();
BeanUtils.copyProperties( gonggao , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody GonggaoEntity gonggao, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,gonggao:{}",this.getClass().getName(),gonggao.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
Wrapper<GonggaoEntity> queryWrapper = new EntityWrapper<GonggaoEntity>()
.eq("gonggao_name", gonggao.getGonggaoName())
.eq("gonggao_types", gonggao.getGonggaoTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
GonggaoEntity gonggaoEntity = gonggaoService.selectOne(queryWrapper);
if(gonggaoEntity==null){
gonggao.setInsertTime(new Date());
gonggao.setCreateTime(new Date());
gonggaoService.insert(gonggao);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody GonggaoEntity gonggao, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,gonggao:{}",this.getClass().getName(),gonggao.toString());
GonggaoEntity oldGonggaoEntity = gonggaoService.selectById(gonggao.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
gonggaoService.updateById(gonggao);//根据id更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
List<GonggaoEntity> oldGonggaoList =gonggaoService.selectBatchIds(Arrays.asList(ids));//要删除的数据
gonggaoService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer xueshengId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<GonggaoEntity> gonggaoList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
GonggaoEntity gonggaoEntity = new GonggaoEntity();
// gonggaoEntity.setGonggaoName(data.get(0)); //公告名称 要改的
// gonggaoEntity.setGonggaoTypes(Integer.valueOf(data.get(0))); //公告类型 要改的
// gonggaoEntity.setInsertTime(date);//时间
// gonggaoEntity.setGonggaoContent("");//详情和图片
// gonggaoEntity.setCreateTime(date);//时间
gonggaoList.add(gonggaoEntity);
//把要查询是否重复的字段放入map中
}
//查询是否重复
gonggaoService.insertBatch(gonggaoList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
}
仓库管理员信息
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 源码需要+V:HadesTYT
*/
@RestController
@Controller
@RequestMapping("/laoshi")
public class LaoshiController {
private static final Logger logger = LoggerFactory.getLogger(LaoshiController.class);
private static final String TABLE_NAME = "laoshi";
@Autowired
private LaoshiService laoshiService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private GonggaoService gonggaoService;//公告
@Autowired
private WuziService wuziService;//物资
@Autowired
private WuziShenqingService wuziShenqingService;//物资申请
@Autowired
private XueshengService xueshengService;//用户
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("xueshengId",request.getSession().getAttribute("userId"));
else if("仓库管理员".equals(role))
params.put("laoshiId",request.getSession().getAttribute("userId"));
CommonUtil.checkMap(params);
PageUtils page = laoshiService.queryPage(params);
//字典表数据转换
List<LaoshiView> list =(List<LaoshiView>)page.getList();
for(LaoshiView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
LaoshiEntity laoshi = laoshiService.selectById(id);
if(laoshi !=null){
//entity转view
LaoshiView view = new LaoshiView();
BeanUtils.copyProperties( laoshi , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody LaoshiEntity laoshi, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,laoshi:{}",this.getClass().getName(),laoshi.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
Wrapper<LaoshiEntity> queryWrapper = new EntityWrapper<LaoshiEntity>()
.eq("username", laoshi.getUsername())
.or()
.eq("laoshi_phone", laoshi.getLaoshiPhone())
.or()
.eq("laoshi_id_number", laoshi.getLaoshiIdNumber())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
LaoshiEntity laoshiEntity = laoshiService.selectOne(queryWrapper);
if(laoshiEntity==null){
laoshi.setCreateTime(new Date());
laoshi.setPassword("123456");
laoshiService.insert(laoshi);
return R.ok();
}else {
return R.error(511,"账户或者仓库管理员手机号或者仓库管理员身份证号已经被使用");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody LaoshiEntity laoshi, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,laoshi:{}",this.getClass().getName(),laoshi.toString());
LaoshiEntity oldLaoshiEntity = laoshiService.selectById(laoshi.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
if("".equals(laoshi.getLaoshiPhoto()) || "null".equals(laoshi.getLaoshiPhoto())){
laoshi.setLaoshiPhoto(null);
}
laoshiService.updateById(laoshi);//根据id更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
List<LaoshiEntity> oldLaoshiList =laoshiService.selectBatchIds(Arrays.asList(ids));//要删除的数据
laoshiService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer xueshengId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<LaoshiEntity> laoshiList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
LaoshiEntity laoshiEntity = new LaoshiEntity();
// laoshiEntity.setUsername(data.get(0)); //账户 要改的
// //laoshiEntity.setPassword("123456");//密码
// laoshiEntity.setLaoshiName(data.get(0)); //仓库管理员姓名 要改的
// laoshiEntity.setLaoshiPhone(data.get(0)); //仓库管理员手机号 要改的
// laoshiEntity.setLaoshiIdNumber(data.get(0)); //仓库管理员身份证号 要改的
// laoshiEntity.setLaoshiPhoto("");//详情和图片
// laoshiEntity.setSexTypes(Integer.valueOf(data.get(0))); //性别 要改的
// laoshiEntity.setLaoshiEmail(data.get(0)); //仓库管理员邮箱 要改的
// laoshiEntity.setLaoshiAddress(data.get(0)); //仓库管理员住址 要改的
// laoshiEntity.setCreateTime(date);//时间
laoshiList.add(laoshiEntity);
//把要查询是否重复的字段放入map中
//账户
if(seachFields.containsKey("username")){
List<String> username = seachFields.get("username");
username.add(data.get(0));//要改的
}else{
List<String> username = new ArrayList<>();
username.add(data.get(0));//要改的
seachFields.put("username",username);
}
//仓库管理员手机号
if(seachFields.containsKey("laoshiPhone")){
List<String> laoshiPhone = seachFields.get("laoshiPhone");
laoshiPhone.add(data.get(0));//要改的
}else{
List<String> laoshiPhone = new ArrayList<>();
laoshiPhone.add(data.get(0));//要改的
seachFields.put("laoshiPhone",laoshiPhone);
}
//仓库管理员身份证号
if(seachFields.containsKey("laoshiIdNumber")){
List<String> laoshiIdNumber = seachFields.get("laoshiIdNumber");
laoshiIdNumber.add(data.get(0));//要改的
}else{
List<String> laoshiIdNumber = new ArrayList<>();
laoshiIdNumber.add(data.get(0));//要改的
seachFields.put("laoshiIdNumber",laoshiIdNumber);
}
}
//查询是否重复
//账户
List<LaoshiEntity> laoshiEntities_username = laoshiService.selectList(new EntityWrapper<LaoshiEntity>().in("username", seachFields.get("username")));
if(laoshiEntities_username.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(LaoshiEntity s:laoshiEntities_username){
repeatFields.add(s.getUsername());
}
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
}
//仓库管理员手机号
List<LaoshiEntity> laoshiEntities_laoshiPhone = laoshiService.selectList(new EntityWrapper<LaoshiEntity>().in("laoshi_phone", seachFields.get("laoshiPhone")));
if(laoshiEntities_laoshiPhone.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(LaoshiEntity s:laoshiEntities_laoshiPhone){
repeatFields.add(s.getLaoshiPhone());
}
return R.error(511,"数据库的该表中的 [仓库管理员手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
}
//仓库管理员身份证号
List<LaoshiEntity> laoshiEntities_laoshiIdNumber = laoshiService.selectList(new EntityWrapper<LaoshiEntity>().in("laoshi_id_number", seachFields.get("laoshiIdNumber")));
if(laoshiEntities_laoshiIdNumber.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(LaoshiEntity s:laoshiEntities_laoshiIdNumber){
repeatFields.add(s.getLaoshiIdNumber());
}
return R.error(511,"数据库的该表中的 [仓库管理员身份证号] 字段已经存在 存在数据为:"+repeatFields.toString());
}
laoshiService.insertBatch(laoshiList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 登录
*/
@IgnoreAuth
@RequestMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
LaoshiEntity laoshi = laoshiService.selectOne(new EntityWrapper<LaoshiEntity>().eq("username", username));
if(laoshi==null || !laoshi.getPassword().equals(password))
return R.error("账号或密码不正确");
String token = tokenService.generateToken(laoshi.getId(),username, "laoshi", "仓库管理员");
R r = R.ok();
r.put("token", token);
r.put("role","仓库管理员");
r.put("username",laoshi.getLaoshiName());
r.put("tableName","laoshi");
r.put("userId",laoshi.getId());
return r;
}
/**
* 注册
*/
@IgnoreAuth
@PostMapping(value = "/register")
public R register(@RequestBody LaoshiEntity laoshi, HttpServletRequest request) {
// ValidatorUtils.validateEntity(user);
Wrapper<LaoshiEntity> queryWrapper = new EntityWrapper<LaoshiEntity>()
.eq("username", laoshi.getUsername())
.or()
.eq("laoshi_phone", laoshi.getLaoshiPhone())
.or()
.eq("laoshi_id_number", laoshi.getLaoshiIdNumber())
;
LaoshiEntity laoshiEntity = laoshiService.selectOne(queryWrapper);
if(laoshiEntity != null)
return R.error("账户或者仓库管理员手机号或者仓库管理员身份证号已经被使用");
laoshi.setCreateTime(new Date());
laoshiService.insert(laoshi);
return R.ok();
}
/**
* 重置密码
*/
@GetMapping(value = "/resetPassword")
public R resetPassword(Integer id, HttpServletRequest request) {
LaoshiEntity laoshi = laoshiService.selectById(id);
laoshi.setPassword("123456");
laoshiService.updateById(laoshi);
return R.ok();
}
/**
* 忘记密码
*/
@IgnoreAuth
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request) {
LaoshiEntity laoshi = laoshiService.selectOne(new EntityWrapper<LaoshiEntity>().eq("username", username));
if(laoshi!=null){
laoshi.setPassword("123456");
laoshiService.updateById(laoshi);
return R.ok();
}else{
return R.error("账号不存在");
}
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrLaoshi(HttpServletRequest request){
Integer id = (Integer)request.getSession().getAttribute("userId");
LaoshiEntity laoshi = laoshiService.selectById(id);
if(laoshi !=null){
//entity转view
LaoshiView view = new LaoshiView();
BeanUtils.copyProperties( laoshi , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 退出
*/
@GetMapping(value = "logout")
public R logout(HttpServletRequest request) {
request.getSession().invalidate();
return R.ok("退出成功");
}
}
物资申请
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 源码需要+V:HadesTYT
*/
@RestController
@Controller
@RequestMapping("/wuziShenqing")
public class WuziShenqingController {
private static final Logger logger = LoggerFactory.getLogger(WuziShenqingController.class);
private static final String TABLE_NAME = "wuziShenqing";
@Autowired
private WuziShenqingService wuziShenqingService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private GonggaoService gonggaoService;//公告
@Autowired
private LaoshiService laoshiService;//仓库管理员
@Autowired
private WuziService wuziService;//物资
@Autowired
private XueshengService xueshengService;//用户
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("xueshengId",request.getSession().getAttribute("userId"));
else if("仓库管理员".equals(role))
params.put("laoshiId",request.getSession().getAttribute("userId"));
CommonUtil.checkMap(params);
PageUtils page = wuziShenqingService.queryPage(params);
//字典表数据转换
List<WuziShenqingView> list =(List<WuziShenqingView>)page.getList();
for(WuziShenqingView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
WuziShenqingEntity wuziShenqing = wuziShenqingService.selectById(id);
if(wuziShenqing !=null){
//entity转view
WuziShenqingView view = new WuziShenqingView();
BeanUtils.copyProperties( wuziShenqing , view );//把实体数据重构到view中
//级联表 用户
//级联表
XueshengEntity xuesheng = xueshengService.selectById(wuziShenqing.getXueshengId());
if(xuesheng != null){
BeanUtils.copyProperties( xuesheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "xueshengId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表
view.setXueshengId(xuesheng.getId());
}
//级联表 物资
//级联表
WuziEntity wuzi = wuziService.selectById(wuziShenqing.getWuziId());
if(wuzi != null){
BeanUtils.copyProperties( wuzi , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "xueshengId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表
view.setWuziId(wuzi.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody WuziShenqingEntity wuziShenqing, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,wuziShenqing:{}",this.getClass().getName(),wuziShenqing.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
else if("用户".equals(role)){
wuziShenqing.setWuziShenqingZhuangtaiTypes(1);
wuziShenqing.setXueshengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
}
WuziEntity wuziEntity = wuziService.selectById(wuziShenqing.getWuziId());
if(wuziEntity == null){
return R.error("查不到物资");
}
if(wuziEntity.getWuziKucunNumber()<wuziShenqing.getSheqingNumber())
return R.error("申请数量大于库存数量,请核实后再申请");
wuziShenqing.setInsertTime(new Date());
wuziShenqing.setWuziShenqingYesnoTypes(1);
wuziShenqing.setCreateTime(new Date());
wuziShenqingService.insert(wuziShenqing);
return R.ok();
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody WuziShenqingEntity wuziShenqing, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,wuziShenqing:{}",this.getClass().getName(),wuziShenqing.toString());
WuziShenqingEntity oldWuziShenqingEntity = wuziShenqingService.selectById(wuziShenqing.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
// else if("用户".equals(role))
// wuziShenqing.setXueshengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
wuziShenqingService.updateById(wuziShenqing);//根据id更新
return R.ok();
}
/**
* 审核
*/
@RequestMapping("/shenhe")
public R shenhe(@RequestBody WuziShenqingEntity wuziShenqingEntity, HttpServletRequest request){
logger.debug("shenhe方法:,,Controller:{},,wuziShenqingEntity:{}",this.getClass().getName(),wuziShenqingEntity.toString());
WuziShenqingEntity oldWuziShenqing = wuziShenqingService.selectById(wuziShenqingEntity.getId());//查询原先数据
if(wuziShenqingEntity.getWuziShenqingYesnoTypes() == 2){//通过
wuziShenqingEntity.setWuziShenqingZhuangtaiTypes(3);
WuziEntity wuziEntity = wuziService.selectById(oldWuziShenqing.getWuziId());
if(wuziEntity == null){
return R.error("查不到物资");
}
int balance = wuziEntity.getWuziKucunNumber() - oldWuziShenqing.getSheqingNumber();
if(balance<0)
return R.error("申请数量大于库存数量,请核实后再同意");
wuziEntity.setWuziKucunNumber(balance);
wuziService.updateById(wuziEntity);
}else if(wuziShenqingEntity.getWuziShenqingYesnoTypes() == 3){//拒绝
wuziShenqingEntity.setWuziShenqingZhuangtaiTypes(2);
}
wuziShenqingEntity.setWuziShenqingShenheTime(new Date());//审核时间
wuziShenqingService.updateById(wuziShenqingEntity);//审核
return R.ok();
}
/**
* 归还
*/
@RequestMapping("/guihuan")
public R guihuan(Integer id, HttpServletRequest request){
WuziShenqingEntity oldWuziShenqing = wuziShenqingService.selectById(id);//查询原先数据
WuziEntity wuziEntity = wuziService.selectById(oldWuziShenqing.getWuziId());
if(wuziEntity == null){
return R.error("查不到物资");
}
wuziEntity.setWuziKucunNumber(wuziEntity.getWuziKucunNumber() + oldWuziShenqing.getSheqingNumber());
wuziService.updateById(wuziEntity);
oldWuziShenqing.setWuziShenqingZhuangtaiTypes(4);
wuziShenqingService.updateById(oldWuziShenqing);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
List<WuziShenqingEntity> oldWuziShenqingList =wuziShenqingService.selectBatchIds(Arrays.asList(ids));//要删除的数据
wuziShenqingService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer xueshengId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<WuziShenqingEntity> wuziShenqingList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
WuziShenqingEntity wuziShenqingEntity = new WuziShenqingEntity();
// wuziShenqingEntity.setXueshengId(Integer.valueOf(data.get(0))); //用户 要改的
// wuziShenqingEntity.setWuziId(Integer.valueOf(data.get(0))); //物资 要改的
// wuziShenqingEntity.setWuziShenqingUuidNumber(data.get(0)); //物资申请编号 要改的
// wuziShenqingEntity.setWuziShenqingTypes(Integer.valueOf(data.get(0))); //物资申请类型 要改的
// wuziShenqingEntity.setWuziShenqingContent("");//详情和图片
// wuziShenqingEntity.setInsertTime(date);//时间
// wuziShenqingEntity.setSheqingNumber(Integer.valueOf(data.get(0))); //申请数量 要改的
// wuziShenqingEntity.setYujiguihuanTime(sdf.parse(data.get(0))); //预计归还时间 要改的
// wuziShenqingEntity.setWuziShenqingZhuangtaiTypes(Integer.valueOf(data.get(0))); //申请状态 要改的
// wuziShenqingEntity.setWuziShenqingYesnoTypes(Integer.valueOf(data.get(0))); //审核状态 要改的
// wuziShenqingEntity.setWuziShenqingYesnoText(data.get(0)); //审核意见 要改的
// wuziShenqingEntity.setWuziShenqingShenheTime(sdf.parse(data.get(0))); //审核时间 要改的
// wuziShenqingEntity.setCreateTime(date);//时间
wuziShenqingList.add(wuziShenqingEntity);
//把要查询是否重复的字段放入map中
//物资申请编号
if(seachFields.containsKey("wuziShenqingUuidNumber")){
List<String> wuziShenqingUuidNumber = seachFields.get("wuziShenqingUuidNumber");
wuziShenqingUuidNumber.add(data.get(0));//要改的
}else{
List<String> wuziShenqingUuidNumber = new ArrayList<>();
wuziShenqingUuidNumber.add(data.get(0));//要改的
seachFields.put("wuziShenqingUuidNumber",wuziShenqingUuidNumber);
}
}
//查询是否重复
//物资申请编号
List<WuziShenqingEntity> wuziShenqingEntities_wuziShenqingUuidNumber = wuziShenqingService.selectList(new EntityWrapper<WuziShenqingEntity>().in("wuzi_shenqing_uuid_number", seachFields.get("wuziShenqingUuidNumber")));
if(wuziShenqingEntities_wuziShenqingUuidNumber.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(WuziShenqingEntity s:wuziShenqingEntities_wuziShenqingUuidNumber){
repeatFields.add(s.getWuziShenqingUuidNumber());
}
return R.error(511,"数据库的该表中的 [物资申请编号] 字段已经存在 存在数据为:"+repeatFields.toString());
}
wuziShenqingService.insertBatch(wuziShenqingList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
}
谢谢你的关注和喜欢~
绿泡泡HadesTYT