package com.controller;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import com.entity.*;
import com.service.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.utils.StringUtil;
import java.lang.reflect.InvocationTargetException;
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.view.GoodsOrderView;
import com.utils.PageUtils;
import com.utils.R;
/**
* 采购调度表
* 后端接口
* @author
* @email
* @date 2021-04-09
*/
@RestController
@Controller
@RequestMapping("/goodsOrder")
public class GoodsOrderController {
private static final Logger logger = LoggerFactory.getLogger(GoodsOrderController.class);
@Autowired
private GoodsOrderService goodsOrderService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;
//级联表service
@Autowired
private FendianService fendianService;
@Autowired
private GongyingshangService gongyingshangService;
// 列表详情的表级联service
@Autowired
private GoodsOrderListService goodsOrderListService;
@Autowired
private YonghuService yonghuService;
@Autowired
private GoodsService goodsService;
@Autowired
private FendianGoodsService fendianGoodsService;
/**
* 后端列表
*/
@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(StringUtil.isNotEmpty(role) && "用户".equals(role)){
params.put("yonghuId",request.getSession().getAttribute("userId"));
}
params.put("orderBy","id");
PageUtils page = goodsOrderService.queryPage(params);
//字典表数据转换
List<GoodsOrderView> list =(List<GoodsOrderView>)page.getList();
for(GoodsOrderView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GoodsOrderEntity goodsOrder = goodsOrderService.selectById(id);
if(goodsOrder !=null){
//entity转view
GoodsOrderView view = new GoodsOrderView();
BeanUtils.copyProperties( goodsOrder , view );//把实体数据重构到view中
//级联表
FendianEntity fendian = fendianService.selectById(goodsOrder.getFendianId());
if(fendian != null){
BeanUtils.copyProperties( fendian , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setFendianId(fendian.getId());
}
//级联表
GongyingshangEntity gongyingshang = gongyingshangService.selectById(goodsOrder.getGongyingshangId());
if(gongyingshang != null){
BeanUtils.copyProperties( gongyingshang , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setGongyingshangId(gongyingshang.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody GoodsOrderEntity goodsOrder, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,goodsOrder:{}",this.getClass().getName(),goodsOrder.toString());
goodsOrder.setInsertTime(new Date());
goodsOrder.setCreateTime(new Date());
goodsOrderService.insert(goodsOrder);
return R.ok();
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody GoodsOrderEntity goodsOrder, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,goodsOrder:{}",this.getClass().getName(),goodsOrder.toString());
goodsOrderService.updateById(goodsOrder);//根据id更新
return R.ok();
}
/**
* 调度
*/
@RequestMapping("/outGoodsOrderList")
public R outGoodsOrderList(@RequestBody Map<String, Object> params,HttpServletRequest request){
logger.debug("outGoodsOrderList方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
Date date = new Date();//当前时间
Integer userId = (Integer) request.getSession().getAttribute("userId");//当前登录人的id
String tableName = (String) request.getSession().getAttribute("tableName");//当前登录人的表名
YonghuEntity yonghuEntity = yonghuService.selectById(userId);//当前登录人的信息
//当前表的表级联查询
// String gongyingshangId = (String) params.get("gongyingshangId"); //供应商
String fendianId = (String) params.get("fendianId"); //分店
if(fendianId == "" || fendianId== null || fendianId == "null"){
return R.error("请选择分店");
}
String goodsOrderName = (String) params.get("goodsOrderName"); // 订单名
HashMap<String, Integer> map = (HashMap<String, Integer>) params.get("map");// id 和 数量
if(map == null || map.size() ==0){
return R.error("添加不能为空");
}else{
Set<String> ids = map.keySet(); // 获取添加数据的ids
List<GoodsEntity> goodsList = goodsService.selectList(new EntityWrapper<GoodsEntity>().in("id", ids));
if(goodsList == null || goodsList.size() ==0 || map.size() != goodsList.size() ){
return R.error("查询物资为空 或者 采购的物资和数据库中不一致,请去列表中查找确认");
}else{
for(GoodsEntity goods : goodsList){
if(goods.getGoodsNumber()-map.get(String.valueOf(goods.getId())) <0){
return R.error(goods.getGoodsName()+"的出库数量小于大于库存数量,请重新确认出库数量");
}
goods.setGoodsNumber(goods.getGoodsNumber()-map.get(String.valueOf(goods.getId())));
}
}
// 查询当前分店的所有库存
List<FendianGoodsEntity> fendianGoodsEntities = fendianGoodsService.selectList(new EntityWrapper<FendianGoodsEntity>().eq("fendian_id",fendianId));
HashMap<Integer, FendianGoodsEntity> fendianGoodsMap = new HashMap<>();
for(FendianGoodsEntity fendianGoods :fendianGoodsEntities){
fendianGoodsMap.put(fendianGoods.getGoodsOnly(),fendianGoods);//以总店id作为key,以对象作为值,用于下面判断
}
List<FendianGoodsEntity> fendianGoodsEntityList = new ArrayList<>();//要更新的分店库存对象
for(GoodsEntity goods:goodsList){
FendianGoodsEntity fendianGoodsEntity = fendianGoodsMap.get(goods.getId());
if(fendianGoodsEntity != null){//�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp的连锁经营商业管理系统 - 编程语言:Java - 数据库:MySQL - 前端技术:JSP、JavaScript (1047个子文件)
pink-violet.css 163KB
yellow-green.css 149KB
bootstrap.min.css 141KB
bootstrap.css 120KB
bootstrap.min.css 98KB
layui.css 73KB
style.css 66KB
animate.css 55KB
ueditor.css 43KB
ueditor.min.css 34KB
font-awesome.min.css 30KB
jquery-ui-1.10.4.custom.min.css 27KB
jquery.treetable.theme.default.css 25KB
animate.css 23KB
entypo-icon.css 23KB
styles.css 22KB
all.css 21KB
font-awesome.css 21KB
video-js.css 21KB
font-awesome.min.css 20KB
all.css 19KB
image.css 18KB
jquery.idealforms.css 17KB
themify-icons.css 16KB
video.css 15KB
layer.css 14KB
square.min.css 14KB
attachment.css 14KB
all.css 14KB
all.css 13KB
all.css 13KB
bootstrap-select.css 13KB
all.css 12KB
dropzone.css 11KB
video-js.min.css 11KB
bootstrap-switch.css 11KB
bootstrap-datetimepicker.min.css 11KB
extra-pages.css 11KB
ladda.min.css 10KB
layui.mobile.css 10KB
tooltipster.css 9KB
calendar.css 9KB
responsive.css 8KB
laydate.css 8KB
laydate.css 7KB
shCoreDefault.css 7KB
social.css 7KB
jquery-jvectormap.css 6KB
clockface.css 6KB
jquery.steps.css 6KB
dripicon.css 5KB
weather-icons.min.css 5KB
footable.core.css 5KB
dataTables.bootstrap4.min.css 5KB
style-responsive.css 5KB
tabelizer.min.css 5KB
datepicker.css 5KB
datepicker.css 5KB
datepicker.css 5KB
footable.standalone.css 5KB
signin.css 5KB
media.css 5KB
family.css 5KB
slidebars.css 4KB
skin-select.css 4KB
scrawl.css 4KB
DT_bootstrap.css 4KB
datepicker.css 4KB
lightbox.css 4KB
bootstrap-timepicker.css 3KB
datepicker.css 3KB
jquery.news-ticker.css 3KB
green.css 3KB
yellow.css 3KB
red.css 3KB
blue.css 3KB
violet.css 3KB
codemirror.css 3KB
bootstrap-colorpicker.css 3KB
maki-icons.css 3KB
jquery.treeview.css 3KB
profile.css 3KB
charts.css 3KB
background.css 2KB
jquery.searchableSelect.css 2KB
bootstrap-wysihtml5.css 2KB
awwwards.css 2KB
jquery.stepy.css 2KB
responsive-table.css 2KB
emotion.css 2KB
jquery.pnotify.default.css 2KB
dialogbase.css 2KB
music.css 2KB
demo.css 1KB
all.css 1KB
polaris.css 1KB
polaris.css 1KB
acc-wizard.min.css 1KB
jquery.easy-pie-chart.css 1KB
futurico.css 1KB
共 1047 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
2401_87496566
- 粉丝: 1077
- 资源: 5282
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功