package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
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.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 试卷选题
* 后端接口
* @author
* @email
*/
@RestController
@Controller
@RequestMapping("/exampapertopic")
public class ExampapertopicController {
private static final Logger logger = LoggerFactory.getLogger(ExampapertopicController.class);
private static final String TABLE_NAME = "exampapertopic";
@Autowired
private ExampapertopicService exampapertopicService;
@Autowired
private TokenService tokenService;
@Autowired
private BaoxiuService baoxiuService;//报修
@Autowired
private BianminService bianminService;//便民服务
@Autowired
private ChatService chatService;//投诉管理
@Autowired
private CheweiService cheweiService;//车位
@Autowired
private CheweiOrderService cheweiOrderService;//车位订单
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private ExampaperService exampaperService;//试卷
@Autowired
private ExamquestionService examquestionService;//试题表
@Autowired
private ExamrecordService examrecordService;//考试记录表
@Autowired
private ExamredetailsService examredetailsService;//答题详情表
@Autowired
private ExamrewrongquestionService examrewrongquestionService;//错题表
@Autowired
private FangwuService fangwuService;//房屋
@Autowired
private GonggaoService gonggaoService;//公告
@Autowired
private JiaofeiService jiaofeiService;//缴费
@Autowired
private WeixuiService weixuiService;//维修指派
@Autowired
private YonghuService yonghuService;//用户
@Autowired
private YuangongService yuangongService;//员工
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@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(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
else if("员工".equals(role))
params.put("yuangongId",request.getSession().getAttribute("userId"));
CommonUtil.checkMap(params);
PageUtils page = exampapertopicService.queryPage(params);
//字典表数据转换
List<ExampapertopicView> list =(List<ExampapertopicView>)page.getList();
for(ExampapertopicView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
ExampapertopicEntity exampapertopic = exampapertopicService.selectById(id);
if(exampapertopic !=null){
//entity转view
ExampapertopicView view = new ExampapertopicView();
BeanUtils.copyProperties( exampapertopic , view );//把实体数据重构到view中
//级联表 试卷
//级联表
ExampaperEntity exampaper = exampaperService.selectById(exampapertopic.getExampaperId());
if(exampaper != null){
BeanUtils.copyProperties( exampaper , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表
view.setExampaperId(exampaper.getId());
}
//级联表 试题表
//级联表
ExamquestionEntity examquestion = examquestionService.selectById(exampapertopic.getExamquestionId());
if(examquestion != null){
BeanUtils.copyProperties( examquestion , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表
view.setExamquestionId(examquestion.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody ExampapertopicEntity exampapertopic, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,exampapertopic:{}",this.getClass().getName(),exampapertopic.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
Wrapper<ExampapertopicEntity> queryWrapper = new EntityWrapper<ExampapertopicEntity>()
.eq("exampaper_id", exampapertopic.getExampaperId())
.eq("examquestion_id", exampapertopic.getExamquestionId())
.eq("exampapertopic_number", exampapertopic.getExampapertopicNumber())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
ExampapertopicEntity exampapertopicEntity = exampapertopicService.selectOne(queryWrapper);
if(exampapertopicEntity==null){
exampapertopic.setCreateTime(new Date());
exampapertopicService.insert(exampapertopic);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody ExampapertopicEntity exampapertopic, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,exampapertopic:{}",this.getClass().getName(),exampapertopic.toString());
ExampapertopicEntity oldExampapertopicEntity = exampapertopicService.selectById(exampapertopic.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
exampapertopicService.updateById(exampapertopic);//根据id更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@Requ