springboot vue家居商城系统源码和论文

当今社会进入了科技进步、经济社会快速发展的新时代。国际信息和学术交流也不断加强,计算机技术对经济社会发展和人民生活改善的影响也日益突出,人类的生存和思考方式也产生了变化。传统购物方式采取了人工的管理方法,但这种管理方法存在着许多弊端,比如效率低下、安全性低以及信息传输的不准确等,同时由于购物管理信息系统中会形成众多的个人文档和信息系统数据,通过人工方法对购物信息进行集中管理会形成检索、更改和维护等较为麻烦的管理问题,同时由于当下人们对购物管理的需求也日益高涨,各级单位需要继续开展全新的改革以满足时代的需求。根据此问题,研发一套Home F家居系统,既能够大大提高信息的检索、变更与维护的工作效率,也能够方便信息系统的管理运用,从而减少信息管理成本,提高效率。

Home F家居系统采用B/S架构、前后端分离以及MVC模型进行设计,并采用Java语言以及 SpringBoot框架进行开发。本系统主要设计并完成了用户注册、登录购买家具过程、个人信息修改等,商家添加家具信息、对家具进行发货,管理员对商家管理、用户管理、家具分类管理、家具管理、交流论坛、系统管理等功能进行维护与管理。该系统操作简单,界面设计简单,不仅能基本满足目前网上商城的日常管理工作,而且能有效降低人员成本和时间成本,为网上商城工作提供方便。

关键词Home F家居系统B/S 架构SpringBoot框架

springboot vue家居商城系统源码和论文809

演示视频:

springboo vue基于Hadoop技术下的校园二手交易系统源码和答辩PPT论文【包调试运行】

Abstract

Today's society has entered a new era of scientific and technological progress and rapid economic and social development. International information and academic exchanges have also been strengthened. The impact of computer technology on economic and social development and the improvement of people's lives has become increasingly prominent. The way of human survival and thinking has also changed. The traditional shopping method adopts the manual management method, but this management method has many drawbacks, such as low efficiency, low security and inaccurate information transmission. At the same time, because many personal documents and information system data will be formed in the shopping management information system, centralized management of shopping information through manual methods will result in more troublesome management problems such as retrieval, change and maintenance, At the same time, due to the growing demand for shopping management, all levels of units need to continue to carry out new reforms to meet the needs of the times. According to this problem, the development of a Home F home system can not only greatly improve the efficiency of information retrieval, change and maintenance, but also facilitate the management and application of information systems, thereby reducing information management costs and improving efficiency.

The Home F home system is designed with B/S architecture, front and rear end separation and MVC model, and is developed with Java language and SpringBoot framework. This system mainly designs and completes the user registration, login, furniture purchase process, personal information modification, etc. The business adds furniture information, ships furniture, and the administrator maintains and manages the business management, user management, furniture classification management, furniture management, communication forum, system management and other functions. The system is simple in operation and interface design, which can not only basically meet the daily management of the current online shopping mall, but also effectively reduce the cost of personnel and time, providing convenience for the online shopping mall.

Key words: Home F home system; B/S architecture; SpringBoot Framework


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 DanganService danganService;//学生档案
    @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 FalvfaguiService falvfaguiService;//法律法规
    @Autowired
    private FalvfaguiCollectionService falvfaguiCollectionService;//法律法规收藏
    @Autowired
    private FalvfaguiLiuyanService falvfaguiLiuyanService;//法律法规留言
    @Autowired
    private FenxiService fenxiService;//就业分析
    @Autowired
    private ForumService forumService;//论坛
    @Autowired
    private GongsiService gongsiService;//企业
    @Autowired
    private JianliService jianliService;//简历
    @Autowired
    private LaoshiService laoshiService;//老师
    @Autowired
    private ToudiService toudiService;//简历投递
    @Autowired
    private XinwenService xinwenService;//新闻资讯
    @Autowired
    private XinwenCollectionService xinwenCollectionService;//新闻资讯收藏
    @Autowired
    private XinwenLiuyanService xinwenLiuyanService;//新闻资讯留言
    @Autowired
    private XinxiService xinxiService;//学生信息
    @Autowired
    private XuanchuanService xuanchuanService;//宣传
    @Autowired
    private YonghuService yonghuService;//学生
    @Autowired
    private ZhaopinService zhaopinService;//职位招聘
    @Autowired
    private ZhaopinCollectionService zhaopinCollectionService;//职位收藏
    @Autowired
    private ZhaopinLiuyanService zhaopinLiuyanService;//招聘咨询
    @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("gongsiId",request.getSession().getAttribute("userId"));
        else if("老师".equals(role))
            params.put("laoshiId",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"});//把级联的数据添加到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"});//把级联的数据添加到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(@RequestBody Integer[] ids, HttpServletRequest request){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        List<ExampapertopicEntity> oldExampapertopicList =exampapertopicService.selectBatchIds(Arrays.asList(ids));//要删除的数据
        exampapertopicService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName, HttpServletRequest request){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
        try {
            List<ExampapertopicEntity> exampapertopicList = new ArrayList<>();//上传的东西
            Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
            Date date = new Date();
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return R.error(511,"该文件没有后缀");
            }else{
                String suffix = fileName.substring(lastIndexOf);
                if(!".xls".equals(suffix)){
                    return R.error(511,"只支持后缀为xls的excel文件");
                }else{
                    URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
                    File file = new File(resource.getFile());
                    if(!file.exists()){
                        return R.error(511,"找不到上传文件,请联系管理员");
                    }else{
                        List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
                        dataList.remove(0);//删除第一行,因为第一行是提示
                        for(List<String> data:dataList){
                            //循环
                            ExampapertopicEntity exampapertopicEntity = new ExampapertopicEntity();
//                            exampapertopicEntity.setExampaperId(Integer.valueOf(data.get(0)));   //试卷 要改的
//                            exampapertopicEntity.setExamquestionId(Integer.valueOf(data.get(0)));   //试题 要改的
//                            exampapertopicEntity.setExampapertopicNumber(Integer.valueOf(data.get(0)));   //试题分数 要改的
//                            exampapertopicEntity.setCreateTime(date);//时间
                            exampapertopicList.add(exampapertopicEntity);


                            //把要查询是否重复的字段放入map中
                        }

                        //查询是否重复
                        exampapertopicService.insertBatch(exampapertopicList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }




    /**
    * 前端列表
    */
    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));

        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("/detail/{id}")
    public R detail(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("detail方法:,,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", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setExampaperId(exampaper.getId());
                }
                //级联表
                    ExamquestionEntity examquestion = examquestionService.selectById(exampapertopic.getExamquestionId());
                if(examquestion != null){
                    BeanUtils.copyProperties( examquestion , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setExamquestionId(examquestion.getId());
                }
                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody ExampapertopicEntity exampapertopic, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,exampapertopic:{}",this.getClass().getName(),exampapertopic.toString());
        Wrapper<ExampapertopicEntity> queryWrapper = new EntityWrapper<ExampapertopicEntity>()
            .eq("exampaper_id", exampapertopic.getExampaperId())
            .eq("examquestion_id", exampapertopic.getExamquestionId())
            .eq("exampapertopic_number", exampapertopic.getExampapertopicNumber())
//            .notIn("exampapertopic_types", new Integer[]{102})
            ;
        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("/examinationUpdate")
    public R examinationUpdate(@RequestBody ExampapertopicEntity exampapertopic, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,exampapertopic:{}",this.getClass().getName(),exampapertopic.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));

        //根据字段查询是否有相同数据
        Wrapper<ExampapertopicEntity> queryWrapper = new EntityWrapper<ExampapertopicEntity>()
            .notIn("id",exampapertopic.getId())
            .andNew()
            .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){
            ExampapertopicEntity exampapertopicEntity1 = exampapertopicService.selectById(exampapertopic.getId());
            if(exampapertopic.getExampaperId() == null){
              return R.error("修改时数据未获取到");
            }
            if(exampapertopicEntity1.getExampapertopicNumber()!=exampapertopic.getExampapertopicNumber()){
                ExampaperEntity exampaperEntity = exampaperService.selectById(exampapertopic.getExampaperId());
                exampaperEntity.setExampaperMyscore((exampaperEntity.getExampaperMyscore()-exampapertopicEntity1.getExampapertopicNumber())+exampapertopic.getExampapertopicNumber());
                exampaperService.updateById(exampaperEntity);
            }
            exampapertopicService.updateById(exampapertopic);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/examinationDelete")
    public R examinationDelete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        List<ExampapertopicEntity> exampapertopicEntities = exampapertopicService.selectBatchIds(Arrays.asList(ids));
        ExampaperEntity exampaperEntity1 = exampaperService.selectById(exampapertopicEntities.get(0).getExampaperId());
        for (ExampapertopicEntity topic:exampapertopicEntities) {
            exampaperEntity1.setExampaperMyscore(exampaperEntity1.getExampaperMyscore()-topic.getExampapertopicNumber());
        }
        exampaperService.updateById(exampaperEntity1);
        exampapertopicService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
    * 自动组卷
    */
    @RequestMapping("/zidongzujuan")
    public R zidongzujuan(@RequestParam Map<String, Object> params, HttpServletRequest request){
        //试卷科目
        Integer kemuTypes = Integer.valueOf(String.valueOf(params.get("kemuTypes")));
        //试卷数据信息
        ExampaperEntity exampaperEntity = new ExampaperEntity();
        exampaperEntity.setId(Integer.valueOf(String.valueOf(params.get("exampaperId"))));
        exampaperEntity.setExampaperMyscore(0);
        //单选数量和分数
        Integer danNum = Integer.valueOf(String.valueOf(params.get("danNum")));
        Integer danFen = Integer.valueOf(String.valueOf(params.get("danFen")));
        ArrayList<ExamquestionEntity> danList = new ArrayList<>();
        //多选数量和分数
        Integer duoNum = Integer.valueOf(String.valueOf(params.get("duoNum")));
        Integer duoFen = Integer.valueOf(String.valueOf(params.get("duoFen")));
        ArrayList<ExamquestionEntity> duoList = new ArrayList<>();
        //判断数量和分数
        Integer panNum = Integer.valueOf(String.valueOf(params.get("panNum")));
        Integer panFen = Integer.valueOf(String.valueOf(params.get("panFen")));
        ArrayList<ExamquestionEntity> panList = new ArrayList<>();
        //填空数量和分数
        Integer tianNum = Integer.valueOf(String.valueOf(params.get("tianNum")));
        Integer tianFen = Integer.valueOf(String.valueOf(params.get("tianFen")));
        ArrayList<ExamquestionEntity> tianList = new ArrayList<>();
        //存储已经筛选的数据
        ArrayList<ExampapertopicEntity> exampapertopicEntities = new ArrayList<>();
        //随机数
        Random random = new Random();

        //查询全部试题信息
        Wrapper<ExamquestionEntity> queryWrapper = new EntityWrapper<ExamquestionEntity>().eq("kemu_types", kemuTypes);
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        List<ExamquestionEntity> exampapertopicLists = examquestionService.selectList(null);
        for (ExamquestionEntity examquestion: exampapertopicLists) {
            //将对应类型数据放入对应的list集合中
            if(examquestion.getExamquestionTypes() == 1){//单选题
                danList.add(examquestion);
            }else if(examquestion.getExamquestionTypes() == 2){//多选题
                duoList.add(examquestion);
            }else if(examquestion.getExamquestionTypes() == 3){//判断题
                panList.add(examquestion);
            }else{//填空题
                tianList.add(examquestion);
            }
        }

        //判断前台传来的题数值是否为空
        if(danNum!=null && danNum>0 && danFen != null && danFen >0){//单选
            if(danList.size()<danNum)
                return R.error("单选题数量"+danNum+"超过数据库中存在的最大数量"+danList.size());
            for (int i = 0 ;i<danNum;i++){
                ExampapertopicEntity exampapertopicEntity = new ExampapertopicEntity();
                int intRandom = random.nextInt(danList.size());
                exampaperEntity.setExampaperMyscore(exampaperEntity.getExampaperMyscore()+danFen);
                exampapertopicEntity.setExamquestionId(danList.get(intRandom).getId());
                exampapertopicEntity.setExampapertopicNumber(danFen);
                exampapertopicEntity.setExampaperId(exampaperEntity.getId());
                exampapertopicEntities.add(exampapertopicEntity);
                danList.remove(intRandom);
            }
        }
        if(duoNum!=null && duoNum>0 && duoFen != null && duoFen >0){//多选
            if(duoList.size()<duoNum)
                return R.error("多选题数量"+duoNum+"超过数据库中存在的最大数量"+duoList.size());
            for (int i = 0 ;i<duoNum;i++){
                ExampapertopicEntity exampapertopicEntity = new ExampapertopicEntity();
                int intRandom = random.nextInt(duoList.size() );
                exampaperEntity.setExampaperMyscore(exampaperEntity.getExampaperMyscore()+duoFen);
                exampapertopicEntity.setExamquestionId(duoList.get(intRandom).getId());
                exampapertopicEntity.setExampapertopicNumber(duoFen);
                exampapertopicEntity.setExampaperId(exampaperEntity.getId());
                exampapertopicEntities.add(exampapertopicEntity);
                duoList.remove(intRandom);
            }
        }
        if(panNum!=null && panNum>0 && panFen != null && panFen >0){//判断
            if(panList.size()<panNum)
                return R.error("判断题数量"+panNum+"超过数据库中存在的最大数量"+panList.size());
            for (int i = 0 ;i<panNum;i++){
                ExampapertopicEntity exampapertopicEntity = new ExampapertopicEntity();
                int intRandom = random.nextInt(panList.size());
                exampaperEntity.setExampaperMyscore(exampaperEntity.getExampaperMyscore()+panFen);
                exampapertopicEntity.setExamquestionId(panList.get(intRandom).getId());
                exampapertopicEntity.setExampapertopicNumber(panFen);
                exampapertopicEntity.setExampaperId(exampaperEntity.getId());
                exampapertopicEntities.add(exampapertopicEntity);
                panList.remove(intRandom);
            }
        }
        if(tianNum!=null && tianNum>0 && tianFen != null && tianFen >0){//填空
            if(tianList.size()<tianNum)
                return R.error("填空题数量"+tianNum+"超过数据库中存在的最大数量"+tianList.size());
            for (int i = 0 ;i<tianNum;i++){
                ExampapertopicEntity exampapertopicEntity = new ExampapertopicEntity();
                int intRandom = random.nextInt(tianList.size());
                exampaperEntity.setExampaperMyscore(exampaperEntity.getExampaperMyscore()+tianFen);
                exampapertopicEntity.setExamquestionId(tianList.get(intRandom).getId());
                exampapertopicEntity.setExampapertopicNumber(tianFen);
                exampapertopicEntity.setExampaperId(exampaperEntity.getId());
                exampapertopicEntities.add(exampapertopicEntity);
                tianList.remove(intRandom);
            }
        }

        exampaperService.updateById(exampaperEntity);
        exampapertopicService.insertBatch(exampapertopicEntities);
        return R.ok();
    }

    /**
    * 获取当前试卷的总分数
    */
    @RequestMapping("/sumExampapertopicNumber")
        public R sumExampapertopicNumber(Integer exampaperId, HttpServletRequest request){
        if(exampaperId==null || exampaperId<=0)
            return R.error("试卷id不能为空");
        List<ExampapertopicEntity> list = exampapertopicService.selectList(
            new EntityWrapper<ExampapertopicEntity>()
                .eq("exampaper_id", exampaperId)
        );
        Integer exampapertopicNumber=0;
        if(!(list == null || list.size()==0)){
            for(ExampapertopicEntity exampapertopicEntity:list){
                exampapertopicNumber=exampapertopicNumber+exampapertopicEntity.getExampapertopicNumber();
            }
        }
        return R.ok().put("exampapertopicNumber",exampapertopicNumber);
    }

    /**
     * 考试题目获取
     */
    @RequestMapping("/questionAcquisition")
    public R questionAcquisition(Integer exampaperId, HttpServletRequest request){
        //获取当前试卷的选题信息
        HashMap<String, Object> params = new HashMap<>();
        params.put("limit","9999");
        params.put("exampaperId", exampaperId);
        CommonUtil.checkMap(params);
        PageUtils page = exampapertopicService.queryPage(params);
        List<ExampapertopicView> exampapertopicView =(List<ExampapertopicView>)page.getList();

        //试题id存放list
        List<Integer> exampapertopicId = new ArrayList<>();
        //循环选题信息获取试题id并存放起来
        for (ExampapertopicEntity papertopic:exampapertopicView) {
            exampapertopicId.add(papertopic.getExamquestionId());
        }
        //查询试题数据
        List<ExamquestionEntity> examquestionEntity = examquestionService.selectBatchIds(exampapertopicId);
        //试题数据存放到选题view中
        examquestionEntity.forEach(item -> {
            BeanUtils.copyProperties(item, exampapertopicView);
        });
        //字典表数据转换
        for(ExampapertopicView c:exampapertopicView){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c, request);
        }
        return R.ok().put("data",exampapertopicView);
    }

    /**
     * 提交试卷
     */
    @RequestMapping("/submitQuestions")
    public R submitQuestions(@RequestParam Map<String, Object> params, HttpServletRequest request){
        //答题编号
        String uuid = String.valueOf(new Date().getTime());
        //答题用户
        Integer yonghuId = Integer.valueOf(String.valueOf(params.get("yonghuId")));
        //试卷id
        Integer exampaperId = Integer.valueOf(String.valueOf(params.get("exampaperId")));
        //考试记录表信息
        ExamrecordEntity examrecordEntity = new ExamrecordEntity();
        examrecordEntity.setExamrecordUuidNumber(uuid);
        examrecordEntity.setTotalScore(0);//总分数
        examrecordEntity.setExampaperId(exampaperId);//试卷id
        examrecordEntity.setYonghuId(yonghuId);//考试用户
        examrecordEntity.setInsertTime(new Date());//时间
        examrecordEntity.setCreateTime(new Date());//时间
        //答题信息
        List<Map<String,String>> answerList = (List<Map<String,String>>)JSON.parse(String.valueOf(params.get("answerList")));
        //答题map
        HashMap<String, String> answerMap = new HashMap<>();
        for (Map<String,String> map:answerList) {
            answerMap.put(map.get("examquestionId"),map.get("answer"));
        }
        //试题信息
        HashMap<String, Object> map = new HashMap<>();
        map.put("limit","9999");
        map.put("exampaperId", exampaperId);
        CommonUtil.checkMap(map);
        PageUtils page = exampapertopicService.queryPage(map);
        List<ExampapertopicView> exampapertopicList =(List<ExampapertopicView>)page.getList();


        //答题详情
        List<ExamredetailsEntity> examredetailsList = new ArrayList<>();
        //错题详情
        List<ExamrewrongquestionEntity> examrewrongquestionList = new ArrayList<>();

        if(exampapertopicList != null && exampapertopicList.size()>0){
            boolean insert = examrecordService.insert(examrecordEntity);
            if(!insert){
                return R.error();
            }
        }
        //判断用户的答案
        for (ExampapertopicView exampapertopic:exampapertopicList) {
            boolean cuoti = false;
            //答题信息
            ExamredetailsEntity examredetailsEntity = new ExamredetailsEntity();
                //答题数据补充
                examredetailsEntity.setExamredetailsUuidNumber(uuid);
                examredetailsEntity.setYonghuId(yonghuId);
                examredetailsEntity.setExamquestionId(exampapertopic.getExamquestionId());
                examredetailsEntity.setCreateTime(new Date());
                //错题信息
                ExamrewrongquestionEntity examrewrongquestionEntity = new ExamrewrongquestionEntity();
                examrewrongquestionEntity.setYonghuId(yonghuId);
                examrewrongquestionEntity.setInsertTime(new Date());
                examrewrongquestionEntity.setCreateTime(new Date());
                examrewrongquestionEntity.setExampaperId(exampaperId);
                examrewrongquestionEntity.setExamquestionId(exampapertopic.getExamquestionId());
            //判断是否答题
            if(StringUtil.isNotEmpty(answerMap.get(exampapertopic.getExamquestionId()))){
                examredetailsEntity.setExamredetailsMyanswer(answerMap.get(exampapertopic.getExamquestionId()));
                examrewrongquestionEntity.setExamredetailsMyanswer(answerMap.get(exampapertopic.getExamquestionId()));
                //多选题判断对错
                if(exampapertopic.getExamquestionTypes() == 2){
                    //正确答案
                    List<String> split = Arrays.asList(exampapertopic.getExamquestionAnswer().split(","));
                    ArrayList<String> splitLs = new ArrayList<>();
                    splitLs.addAll(split);
                    //用户答案
                    List<String> answer = Arrays.asList(answerMap.get(exampapertopic.getExamquestionId()).split(","));
                    List<String> answerLs = new ArrayList<>();
                    answerLs.addAll(answer);
                    //判断用户是否回答正确
                    if(splitLs.size() == answerLs.size()){//判断用户回答信息的长度是否正确答案的长度一样
                        splitLs.retainAll(answerLs);
                        if(splitLs.size() == answerLs.size()){//判断内容是否正确
                            examrecordEntity.setTotalScore(examrecordEntity.getTotalScore()+exampapertopic.getExampapertopicNumber());
                            examredetailsEntity.setExamredetailsMyscore(exampapertopic.getExampapertopicNumber());
                        }else{//错误
                            cuoti = true;
                            examredetailsEntity.setExamredetailsMyscore(0);
                        }
                    }else{//错误
                        cuoti = true;
                        examredetailsEntity.setExamredetailsMyscore(0);
                    }
                }else{
                    //其他题判断对错
                    if(answerMap.get(exampapertopic.getExamquestionId()).equals(exampapertopic.getExamquestionAnswer())){//正确
                        examredetailsEntity.setExamredetailsMyscore(exampapertopic.getExampapertopicNumber());
                        examrecordEntity.setTotalScore(examrecordEntity.getTotalScore()+exampapertopic.getExampapertopicNumber());
                    }else{//错误
                        cuoti = true;
                        examredetailsEntity.setExamredetailsMyscore(0);
                    }
                }
            }else{//未作答
                cuoti = true;
                examrewrongquestionEntity.setExamredetailsMyanswer("未作答");
                examredetailsEntity.setExamredetailsMyanswer("未作答");
                examredetailsEntity.setExamredetailsMyscore(0);
            }
            if(cuoti){
                examrewrongquestionList.add(examrewrongquestionEntity);
                cuoti = false;
            }
            examredetailsList.add(examredetailsEntity);
        }

        examredetailsService.insertBatch(examredetailsList);
        examrewrongquestionService.insertBatch(examrewrongquestionList);
        examrecordService.updateById(examrecordEntity);
        return R.ok();
    }
}

  • 18
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值