You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.2 KiB
105 lines
3.2 KiB
3 years ago
|
package com.campus.controller;
|
||
|
|
||
|
import com.campus.domain.Goods;
|
||
|
import com.campus.domain.User;
|
||
|
import com.campus.service.CampusService;
|
||
|
import com.campus.utils.JsonData;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
@RestController
|
||
|
@RequestMapping("campus")
|
||
|
public class CampusController {
|
||
|
@Autowired
|
||
|
private CampusService campusService;
|
||
|
|
||
|
//登录
|
||
|
@PostMapping("userlogin")
|
||
|
public Object userlogin(@RequestBody User user)
|
||
|
{
|
||
|
//System.out.println(user);
|
||
|
if(campusService.userLogin(user)) return JsonData.buildSuccess();
|
||
|
else return JsonData.buildError("用户名或密码错误");
|
||
|
}
|
||
|
|
||
|
//添加新用户
|
||
|
@PostMapping("newuser")
|
||
|
public Object newuser(@RequestBody User user)
|
||
|
{
|
||
|
if (!campusService.userLogin(user)) {
|
||
|
if (campusService.newUser(user)) {
|
||
|
return JsonData.buildSuccess();
|
||
|
} else
|
||
|
return JsonData.buildError("注册失败");
|
||
|
}
|
||
|
else return JsonData.buildError("用户名已存在");
|
||
|
}
|
||
|
|
||
|
//更新密码
|
||
|
@PostMapping("userupdate")
|
||
|
public Object userUpdate(@RequestBody User user) {
|
||
|
if (campusService.userUpdate(user)) {
|
||
|
return JsonData.buildSuccess();
|
||
|
} else
|
||
|
return JsonData.buildError("更新失败");
|
||
|
}
|
||
|
|
||
|
//查询用户
|
||
|
@PostMapping("userselect")
|
||
|
public Object userselect(@RequestBody User user) {
|
||
|
if (!campusService.userselect(user).isEmpty()) {
|
||
|
return JsonData.buildSuccess();
|
||
|
}
|
||
|
else return JsonData.buildError("密码错误");
|
||
|
}
|
||
|
|
||
|
//查询物品
|
||
|
@PostMapping("goodslist")
|
||
|
public Object goodslist(@RequestBody Goods goods)
|
||
|
{
|
||
|
List<Goods> goodsList=campusService.goodsSelect(goods);
|
||
|
if(!goodsList.isEmpty())
|
||
|
return JsonData.buildSuccess(goodsList);
|
||
|
else return JsonData.buildError("查询失败!");
|
||
|
}
|
||
|
|
||
|
//更新物品
|
||
|
@PostMapping("goodsupdate")
|
||
|
public Object goodsupdate(@RequestBody Goods goods)
|
||
|
{
|
||
|
if(campusService.goodsUpdate(goods))
|
||
|
return JsonData.buildSuccess();
|
||
|
else return JsonData.buildError("更新失败!");
|
||
|
}
|
||
|
|
||
|
//插入新物品
|
||
|
@PostMapping("goodsinter")
|
||
|
public Object goodsinter(@RequestBody Goods goods)
|
||
|
{
|
||
|
System.out.println(goods);
|
||
|
if(goods.getCommit()!=null&&goods.getImg()!=null&&goods.getPrice()!=null
|
||
|
&&goods.getType()!=null&&goods.getUsername()!=null&&goods.getPhone()!=null)
|
||
|
{
|
||
|
if(campusService.goodsInter(goods))
|
||
|
return JsonData.buildSuccess();
|
||
|
else
|
||
|
return JsonData.buildError("插入失败!");
|
||
|
}
|
||
|
else return JsonData.buildError("信息不完整!");
|
||
|
}
|
||
|
|
||
|
//删除物品
|
||
|
@PostMapping("goodsdelete")
|
||
|
public Object goodsdelete(@RequestBody Goods goods)
|
||
|
{
|
||
|
if(campusService.goodsDelete(goods))
|
||
|
return JsonData.buildSuccess();
|
||
|
else
|
||
|
return JsonData.buildError("删除失败!");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|