parent
1be12ec0bf
commit
f137fb6937
@ -0,0 +1,306 @@
|
||||
package com.example.flower.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.example.flower.entity.Class;
|
||||
import com.example.flower.entity.Discount;
|
||||
import com.example.flower.entity.Flower;
|
||||
import com.example.flower.service.ClassService;
|
||||
import com.example.flower.service.DiscountService;
|
||||
import com.example.flower.service.FlowerService;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.example.flower.unit.JWTUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/discount")
|
||||
public class DiscountController {
|
||||
@Resource
|
||||
private DiscountService discountService;
|
||||
@Resource
|
||||
private FlowerService flowerService;
|
||||
@Resource
|
||||
private ClassService classService;
|
||||
|
||||
@PostMapping("/list") //discountList获取所有优惠信息列表
|
||||
public JSONObject discountList(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
int page=param.getIntValue("page");
|
||||
int page_size=param.getIntValue("page_size");
|
||||
|
||||
List<Discount> discountList = discountService.discountList(page,page_size).getList();
|
||||
|
||||
jsonObject1.put("page_number", discountService.discountList(page,page_size).getPages());
|
||||
jsonObject1.put("total",discountService.discountList(page,page_size).getTotal());
|
||||
|
||||
int size=discountList.size();
|
||||
|
||||
JSONObject[] objects = new JSONObject[size];
|
||||
for(int i = 0;i<size;i++){
|
||||
objects[i]=new JSONObject();
|
||||
objects[i].put("discount_id", discountList.get(i).getDiscount_id());
|
||||
objects[i].put("discount_name",discountList.get(i).getDiscount_name());
|
||||
objects[i].put("discount_num", discountList.get(i).getDiscount_num());
|
||||
if(discountList.get(i).getDiscount_f_id() != 0)
|
||||
objects[i].put("discount_f_id", flowerService.flowerInfo(discountList.get(i).getDiscount_f_id()).getFlower_name());
|
||||
else
|
||||
objects[i].put("discount_f_id",0);
|
||||
if(discountList.get(i).getDiscount_c_id() != 0)
|
||||
objects[i].put("discount_c_id", classService.classInfo(discountList.get(i).getDiscount_c_id()).getClass_name());
|
||||
else
|
||||
objects[i].put("discount_c_id",0);
|
||||
objects[i].put("discount_start_time", discountList.get(i).getDiscount_start_time());
|
||||
objects[i].put("discount_end_time", discountList.get(i).getDiscount_end_time());
|
||||
}
|
||||
jsonObject1.put("discounts",objects);
|
||||
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","token认证成功!" );
|
||||
jsonObject.put("data",jsonObject1);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/query") //discountListByQuery查询优惠套餐信息列表
|
||||
public JSONObject discountListByQuery(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
int page=param.getIntValue("page");
|
||||
int page_size=param.getIntValue("page_size");
|
||||
String discount_name = param.getString("discount_name");
|
||||
|
||||
List<Discount> discountList = discountService.discountListByQuery(page,page_size,discount_name).getList();
|
||||
|
||||
jsonObject1.put("page_number", discountService.discountListByQuery(page,page_size,discount_name).getPages());
|
||||
jsonObject1.put("total",discountService.discountListByQuery(page,page_size,discount_name).getTotal());
|
||||
|
||||
int size=discountList.size();
|
||||
|
||||
JSONObject[] objects = new JSONObject[size];
|
||||
for(int i = 0;i<size;i++){
|
||||
objects[i]=new JSONObject();
|
||||
objects[i].put("discount_id", discountList.get(i).getDiscount_id());
|
||||
objects[i].put("discount_name",discountList.get(i).getDiscount_name());
|
||||
objects[i].put("discount_num", discountList.get(i).getDiscount_num());
|
||||
if(discountList.get(i).getDiscount_f_id() != 0)
|
||||
objects[i].put("discount_f_id", flowerService.flowerInfo(discountList.get(i).getDiscount_f_id()).getFlower_name());
|
||||
else
|
||||
objects[i].put("discount_f_id",0);
|
||||
if(discountList.get(i).getDiscount_c_id() != 0)
|
||||
objects[i].put("discount_c_id", classService.classInfo(discountList.get(i).getDiscount_c_id()).getClass_name());
|
||||
else
|
||||
objects[i].put("discount_c_id",0);
|
||||
objects[i].put("discount_start_time", discountList.get(i).getDiscount_start_time());
|
||||
objects[i].put("discount_end_time", discountList.get(i).getDiscount_end_time());
|
||||
}
|
||||
jsonObject1.put("discounts",objects);
|
||||
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","token认证成功!" );
|
||||
jsonObject.put("data",jsonObject1);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/add") //discountAdd添加优惠套餐
|
||||
public JSONObject discountAdd(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Discount discount = new Discount();
|
||||
discount.setDiscount_name(param.getString("discount_name"));
|
||||
discount.setDiscount_num(param.getIntValue("discount_num"));
|
||||
discount.setDiscount_f_id(param.getIntValue("discount_f_id"));
|
||||
discount.setDiscount_c_id(param.getIntValue("discount_c_id"));
|
||||
discount.setDiscount_start_time(param.getString("discount_start_time"));
|
||||
discount.setDiscount_end_time(param.getString("discount_end_time"));
|
||||
|
||||
discountService.discountAdd(discount);
|
||||
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","成功" );
|
||||
jsonObject.put("discount_id",discount.getDiscount_id());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/deletePer") //discountDeletePer删除单个优惠套餐
|
||||
public JSONObject discountDeletePer(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
int flag = discountService.discountDeletePer(param.getIntValue("discount_id"));
|
||||
if(flag==1){
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","成功" );
|
||||
}
|
||||
else {
|
||||
jsonObject.put("code",403 );
|
||||
jsonObject.put("msg","删除失败" );
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/deleteMul") //discountDeleteMul批量删除优惠套餐
|
||||
public JSONObject discountDeleteMul(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
//获取请求参数
|
||||
JSONArray discount_ids = param.getJSONArray("discount_ids");
|
||||
|
||||
int [] ids = new int[discount_ids.size()];
|
||||
|
||||
//把userid中的数据进行类型转换并存入到int数组中
|
||||
for (int i = 0; i < discount_ids.size(); i++) {
|
||||
ids[i] = Integer.parseInt(discount_ids.getString(i));
|
||||
}
|
||||
|
||||
int result = discountService.discountDeleteMul(ids);
|
||||
if(result == ids.length){
|
||||
jsonObject.put("code",200);
|
||||
jsonObject.put("msg","批量删除成功,删除了"+result+"条优惠套餐数据");
|
||||
}else{
|
||||
jsonObject.put("code",403);
|
||||
jsonObject.put("msg","批量删除失败,删除了"+result+"条优惠套餐数据");
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/info") //discountInfo获取优惠套餐信息
|
||||
public JSONObject discountInfo(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
int discount_id = param.getIntValue("discount_id");
|
||||
Discount discount = discountService.discountInfo(discount_id);
|
||||
|
||||
if(discount!=null){
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("discount_id",discount.getDiscount_id());
|
||||
jsonObject1.put("discount_name",discount.getDiscount_name());
|
||||
jsonObject1.put("discount_num",discount.getDiscount_num());
|
||||
jsonObject1.put("discount_f_id",discount.getDiscount_f_id());
|
||||
jsonObject1.put("discount_c_id",discount.getDiscount_c_id());
|
||||
jsonObject1.put("discount_start_time",discount.getDiscount_start_time());
|
||||
jsonObject1.put("discount_end_time",discount.getDiscount_end_time());
|
||||
|
||||
jsonObject.put("code",200);
|
||||
jsonObject.put("msg","成功");
|
||||
jsonObject.put("data",jsonObject1);
|
||||
|
||||
}
|
||||
else{
|
||||
jsonObject.put("code",403);
|
||||
jsonObject.put("msg","获取优惠套餐信息失败");
|
||||
jsonObject.put("data",null);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/modify") //discountModify修改优惠套餐
|
||||
public JSONObject discountModify(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Discount discount = new Discount();
|
||||
discount.setDiscount_id(param.getIntValue("discount_id"));
|
||||
discount.setDiscount_name(param.getString("discount_name"));
|
||||
discount.setDiscount_num(param.getIntValue("discount_num"));
|
||||
discount.setDiscount_f_id(param.getIntValue("discount_f_id"));
|
||||
discount.setDiscount_c_id(param.getIntValue("discount_c_id"));
|
||||
discount.setDiscount_start_time(param.getString("discount_start_time"));
|
||||
discount.setDiscount_end_time(param.getString("discount_end_time"));
|
||||
|
||||
int flag = discountService.discountModify(discount);
|
||||
if(flag==1){
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","修改成功" );
|
||||
}
|
||||
else{
|
||||
jsonObject.put("code",403 );
|
||||
jsonObject.put("msg","修改失败" );
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/cascade") //级联选择器目录获取
|
||||
public JSONObject cascade(@RequestHeader String Authorization) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
JSONObject[] cascade = new JSONObject[3];
|
||||
cascade[0] = new JSONObject();
|
||||
cascade[0].put("value",0);
|
||||
cascade[0].put("label","全部商品");
|
||||
|
||||
cascade[1] = new JSONObject();
|
||||
cascade[1].put("value",-1);
|
||||
cascade[1].put("label","按商品");
|
||||
List<Flower> flowerList = flowerService.flowerList(1,100).getList();
|
||||
JSONObject[] objects1 = new JSONObject[flowerList.size()];
|
||||
for(int i = 0;i<flowerList.size();i++){
|
||||
objects1[i]=new JSONObject();
|
||||
objects1[i].put("value", flowerList.get(i).getFlower_id());
|
||||
objects1[i].put("label", flowerList.get(i).getFlower_name());
|
||||
}
|
||||
cascade[1].put("children",objects1);
|
||||
|
||||
cascade[2] = new JSONObject();
|
||||
cascade[2].put("value",-2);
|
||||
cascade[2].put("label","按种类");
|
||||
List<Class> classList = classService.classList(1,100).getList();
|
||||
JSONObject[] objects2 = new JSONObject[classList.size()];
|
||||
for(int i = 0;i<classList.size();i++){
|
||||
objects2[i]=new JSONObject();
|
||||
objects2[i].put("value", classList.get(i).getClass_id());
|
||||
objects2[i].put("label", classList.get(i).getClass_name());
|
||||
}
|
||||
cascade[2].put("children",objects2);
|
||||
|
||||
jsonObject.put("code",200);
|
||||
jsonObject.put("msg","获取级联菜单成功");
|
||||
jsonObject.put("cascade",cascade);
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue