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.
99 lines
2.9 KiB
99 lines
2.9 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.Building;
|
|
import com.yanzhen.entity.User;
|
|
import com.yanzhen.service.BuildingService;
|
|
import com.yanzhen.service.UserService;
|
|
import com.yanzhen.utils.Result;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.Map;
|
|
|
|
//BuildingController控制类
|
|
@RestController
|
|
@RequestMapping("/building")
|
|
public class BuildingController {
|
|
|
|
//注入实例
|
|
//注入BuildingService实例
|
|
@Autowired
|
|
private BuildingService buildingService;
|
|
@Autowired
|
|
private UserService userService;
|
|
//创建楼宇对象
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Building building){
|
|
//调用服务类create方法
|
|
int flag = buildingService.create(building);
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
// 删除楼宇
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//调用服务类delete方法
|
|
int flag = buildingService.delete(ids);
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
// 更新楼宇信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Building building){
|
|
//调用服务类update方法
|
|
int flag = buildingService.update(building);
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//返回失败信息
|
|
return Result.fail();
|
|
}
|
|
}
|
|
|
|
//删除信息
|
|
@GetMapping("detail")
|
|
//根据id删除信息
|
|
public Building detail(Integer id){
|
|
//返回信息
|
|
return buildingService.detail(id);
|
|
}
|
|
|
|
// 调用服务层--获取用户详情
|
|
@PostMapping("query")
|
|
//查询用户详细信息并且分页显示
|
|
public Map<String,Object> query(@RequestBody Building building, HttpServletRequest request){
|
|
// 从请求中获取用户信息
|
|
User param = (User)request.getAttribute("user");
|
|
//创建对象
|
|
User loginUser = userService.detail(param.getId());
|
|
//判断用户是否是用户
|
|
if(loginUser.getType() == 1){
|
|
//设置当前用户id
|
|
building.setUserId(loginUser.getId());
|
|
}
|
|
//创建分页对象
|
|
PageInfo<Building> pageInfo = buildingService.query(building);
|
|
// 遍历查询结果中的每个楼宇
|
|
pageInfo.getList().forEach(entity->{
|
|
//在服务器中获取用户id
|
|
User user = userService.detail(entity.getUserId());
|
|
// 将用户信息应用到楼宇对象中
|
|
entity.setUser(user);
|
|
});
|
|
//返回成功标识
|
|
return Result.ok(pageInfo);
|
|
}
|
|
} |