package com.controller;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.OrdersEntity;
import com.service.OrdersService;
import com.entity.YingyuanshangpinEntity;
import com.entity.view.YingyuanshangpinView;
import com.service.YingyuanshangpinService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.CommonUtil;
import java.io.IOException;
import com.service.StoreupService;
import com.entity.StoreupEntity;
/**
* 影院商品
* 后端接口
* @author
* @email
* @date 2023-03-13 18:19:24
*/
@RestController
@RequestMapping("/yingyuanshangpin")
public class YingyuanshangpinController {
@Autowired
private YingyuanshangpinService yingyuanshangpinService;
@Autowired
private StoreupService storeupService;
@Autowired
private OrdersService ordersService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,YingyuanshangpinEntity yingyuanshangpin,
@RequestParam(required = false) Double pricestart,
@RequestParam(required = false) Double priceend,
HttpServletRequest request){
EntityWrapper<YingyuanshangpinEntity> ew = new EntityWrapper<YingyuanshangpinEntity>();
if(pricestart!=null) ew.ge("price", pricestart);
if(priceend!=null) ew.le("price", priceend);
PageUtils page = yingyuanshangpinService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yingyuanshangpin), params), params));
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,YingyuanshangpinEntity yingyuanshangpin,
@RequestParam(required = false) Double pricestart,
@RequestParam(required = false) Double priceend,
HttpServletRequest request){
EntityWrapper<YingyuanshangpinEntity> ew = new EntityWrapper<YingyuanshangpinEntity>();
if(pricestart!=null) ew.ge("price", pricestart);
if(priceend!=null) ew.le("price", priceend);
PageUtils page = yingyuanshangpinService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yingyuanshangpin), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/lists")
public R list( YingyuanshangpinEntity yingyuanshangpin){
EntityWrapper<YingyuanshangpinEntity> ew = new EntityWrapper<YingyuanshangpinEntity>();
ew.allEq(MPUtil.allEQMapPre( yingyuanshangpin, "yingyuanshangpin"));
return R.ok().put("data", yingyuanshangpinService.selectListView(ew));
}
/**
* 查询
*/
@RequestMapping("/query")
public R query(YingyuanshangpinEntity yingyuanshangpin){
EntityWrapper< YingyuanshangpinEntity> ew = new EntityWrapper< YingyuanshangpinEntity>();
ew.allEq(MPUtil.allEQMapPre( yingyuanshangpin, "yingyuanshangpin"));
YingyuanshangpinView yingyuanshangpinView = yingyuanshangpinService.selectView(ew);
return R.ok("查询影院商品成功").put("data", yingyuanshangpinView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
YingyuanshangpinEntity yingyuanshangpin = yingyuanshangpinService.selectById(id);
yingyuanshangpin.setClicknum(yingyuanshangpin.getClicknum()+1);
yingyuanshangpin.setClicktime(new Date());
yingyuanshangpinService.updateById(yingyuanshangpin);
return R.ok().put("data", yingyuanshangpin);
}
/**
* 前端详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
YingyuanshangpinEntity yingyuanshangpin = yingyuanshangpinService.selectById(id);
yingyuanshangpin.setClicknum(yingyuanshangpin.getClicknum()+1);
yingyuanshangpin.setClicktime(new Date());
yingyuanshangpinService.updateById(yingyuanshangpin);
return R.ok().put("data", yingyuanshangpin);
}
/**
* 赞或踩
*/
@RequestMapping("/thumbsup/{id}")
public R vote(@PathVariable("id") String id,String type){
YingyuanshangpinEntity yingyuanshangpin = yingyuanshangpinService.selectById(id);
if(type.equals("1")) {
yingyuanshangpin.setThumbsupnum(yingyuanshangpin.getThumbsupnum()+1);
} else {
yingyuanshangpin.setCrazilynum(yingyuanshangpin.getCrazilynum()+1);
}
yingyuanshangpinService.updateById(yingyuanshangpin);
return R.ok("投票成功");
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody YingyuanshangpinEntity yingyuanshangpin, HttpServletRequest request){
yingyuanshangpin.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(yingyuanshangpin);
yingyuanshangpinService.insert(yingyuanshangpin);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody YingyuanshangpinEntity yingyuanshangpin, HttpServletRequest request){
yingyuanshangpin.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(yingyuanshangpin);
yingyuanshangpinService.insert(yingyuanshangpin);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@Transactional
public R update(@RequestBody YingyuanshangpinEntity yingyuanshangpin, HttpServletRequest request){
//ValidatorUtils.validateEntity(yingyuanshangpin);
yingyuanshangpinService.updateById(yingyuanshangpin);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
yingyuanshangpinService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.a