基于小程序宿舍报修系统+ssm后端源码和论文

互联网发展至今,无论是其理论还是技术都已经成熟,而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播,搭配信息管理工具可以很好地为人们提供服务。针对成果信息管理混乱,出错率高,信息安全性差,劳动强度大,费时费力等问题,采用基于微信小程序的宿舍报修系统可以有效管理,使信息管理能够更加科学和规范。

基于微信小程序的宿舍报修系统使用Java语言进行编码,使用Mysql创建数据表保存本系统产生的数据。系统可以提供信息显示和相应服务,总之,基于微信小程序的宿舍报修系统集中管理信息,有着保密性强,效率高,存储空间大,成本低等诸多优点。它可以降低信息管理成本,实现信息管理计算机化。

关键词:基于微信小程序的宿舍报修系统;Java语言;Mysql

基于小程序宿舍报修系统+ssm后端源码和论文weixin183
Abstract

Since the development of the Internet, both its theory and technology have matured, and it has been widely involved in all aspects of society. It allows information to be disseminated through the Internet, and it can serve people well with information management tools. In view of the chaotic information management of CET-4, high error rate, poor information security, high labor intensity, and time-consuming and labor-consuming problems, the use of the web-based CET-4 online test system can effectively manage the information and make information management more scientific and standardized.

The web-based English Level 4 online examination system uses Java language for coding, and uses Mysql to create data tables to save the data generated by the system. The system can provide information display and corresponding services. Its administrator manages the test papers and the information of the question bank that composes the test papers, checks the scores of the student test papers, and manages classes and students. Students choose the test questions to answer the questions, and they can view the answer scores.

In short, the web-based English Level 4 online examination system centrally manages information and has many advantages such as strong confidentiality, high efficiency, large storage space, and low cost. It can reduce the cost of information management and realize the computerization of information management.

Key WordsWeb-based English Level 4 online examination system; Java language; Mysql


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("/weixiuyuan")
public class WeixiuyuanController {
    private static final Logger logger = LoggerFactory.getLogger(WeixiuyuanController.class);

    @Autowired
    private WeixiuyuanService weixiuyuanService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;

    //级联表service

    @Autowired
    private XueshengService xueshengService;


    /**
    * 后端列表
    */
    @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(StringUtil.isEmpty(role))
            return R.error(511,"权限为空");
        else if("学生".equals(role))
            params.put("xueshengId",request.getSession().getAttribute("userId"));
        else if("维修人员".equals(role))
            params.put("weixiuyuanId",request.getSession().getAttribute("userId"));
        params.put("weixiuyuanDeleteStart",1);params.put("weixiuyuanDeleteEnd",1);
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = weixiuyuanService.queryPage(params);

        //字典表数据转换
        List<WeixiuyuanView> list =(List<WeixiuyuanView>)page.getList();
        for(WeixiuyuanView 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);
        WeixiuyuanEntity weixiuyuan = weixiuyuanService.selectById(id);
        if(weixiuyuan !=null){
            //entity转view
            WeixiuyuanView view = new WeixiuyuanView();
            BeanUtils.copyProperties( weixiuyuan , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody WeixiuyuanEntity weixiuyuan, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,weixiuyuan:{}",this.getClass().getName(),weixiuyuan.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(StringUtil.isEmpty(role))
            return R.error(511,"权限为空");

        Wrapper<WeixiuyuanEntity> queryWrapper = new EntityWrapper<WeixiuyuanEntity>()
            .eq("username", weixiuyuan.getUsername())
            .or()
            .eq("weixiuyuan_phone", weixiuyuan.getWeixiuyuanPhone())
            .andNew()
            .eq("weixiuyuan_delete", 1)
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        WeixiuyuanEntity weixiuyuanEntity = weixiuyuanService.selectOne(queryWrapper);
        if(weixiuyuanEntity==null){
            weixiuyuan.setWeixiuyuanDelete(1);
            weixiuyuan.setCreateTime(new Date());
            weixiuyuan.setPassword("123456");
            weixiuyuanService.insert(weixiuyuan);
            return R.ok();
        }else {
            return R.error(511,"账户或者联系方式已经被使用");
        }
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody WeixiuyuanEntity weixiuyuan, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,weixiuyuan:{}",this.getClass().getName(),weixiuyuan.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(StringUtil.isEmpty(role))
//            return R.error(511,"权限为空");
        //根据字段查询是否有相同数据
        Wrapper<WeixiuyuanEntity> queryWrapper = new EntityWrapper<WeixiuyuanEntity>()
            .notIn("id",weixiuyuan.getId())
            .andNew()
            .eq("username", weixiuyuan.getUsername())
            .or()
            .eq("weixiuyuan_phone", weixiuyuan.getWeixiuyuanPhone())
            .andNew()
            .eq("weixiuyuan_delete", 1)
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        WeixiuyuanEntity weixiuyuanEntity = weixiuyuanService.selectOne(queryWrapper);
        if("".equals(weixiuyuan.getWeixiuyuanPhoto()) || "null".equals(weixiuyuan.getWeixiuyuanPhoto())){
                weixiuyuan.setWeixiuyuanPhoto(null);
        }
        if(weixiuyuanEntity==null){
            //  String role = String.valueOf(request.getSession().getAttribute("role"));
            //  if("".equals(role)){
            //      weixiuyuan.set
            //  }
            weixiuyuanService.updateById(weixiuyuan);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"账户或者联系方式已经被使用");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        ArrayList<WeixiuyuanEntity> list = new ArrayList<>();
        for(Integer id:ids){
            WeixiuyuanEntity weixiuyuanEntity = new WeixiuyuanEntity();
            weixiuyuanEntity.setId(id);
            weixiuyuanEntity.setWeixiuyuanDelete(2);
            list.add(weixiuyuanEntity);
        }
        if(list != null && list.size() >0){
            weixiuyuanService.updateBatchById(list);
        }
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<WeixiuyuanEntity> weixiuyuanList = 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){
                            //循环
                            WeixiuyuanEntity weixiuyuanEntity = new WeixiuyuanEntity();
//                            weixiuyuanEntity.setUsername(data.get(0));                    //账号 要改的
//                            //weixiuyuanEntity.setPassword("123456");//密码
//                            weixiuyuanEntity.setWeixiuyuanName(data.get(0));                    //维修员姓名 要改的
//                            weixiuyuanEntity.setSexTypes(Integer.valueOf(data.get(0)));   //性别 要改的
//                            weixiuyuanEntity.setWeixiuyuanNianxian(data.get(0));                    //工作年限 要改的
//                            weixiuyuanEntity.setWeixiuyuanPhone(data.get(0));                    //联系方式 要改的
//                            weixiuyuanEntity.setWeixiuyuanPhoto("");//照片
//                            weixiuyuanEntity.setWeixiuyuanContent("");//照片
//                            weixiuyuanEntity.setWeixiuyuanDelete(1);//逻辑删除字段
//                            weixiuyuanEntity.setCreateTime(date);//时间
                            weixiuyuanList.add(weixiuyuanEntity);


                            //把要查询是否重复的字段放入map中
                                //账号
                                if(seachFields.containsKey("username")){
                                    List<String> username = seachFields.get("username");
                                    username.add(data.get(0));//要改的
                                }else{
                                    List<String> username = new ArrayList<>();
                                    username.add(data.get(0));//要改的
                                    seachFields.put("username",username);
                                }
                                //联系方式
                                if(seachFields.containsKey("weixiuyuanPhone")){
                                    List<String> weixiuyuanPhone = seachFields.get("weixiuyuanPhone");
                                    weixiuyuanPhone.add(data.get(0));//要改的
                                }else{
                                    List<String> weixiuyuanPhone = new ArrayList<>();
                                    weixiuyuanPhone.add(data.get(0));//要改的
                                    seachFields.put("weixiuyuanPhone",weixiuyuanPhone);
                                }
                        }

                        //查询是否重复
                         //账号
                        List<WeixiuyuanEntity> weixiuyuanEntities_username = weixiuyuanService.selectList(new EntityWrapper<WeixiuyuanEntity>().in("username", seachFields.get("username")).eq("weixiuyuan_delete", 1));
                        if(weixiuyuanEntities_username.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(WeixiuyuanEntity s:weixiuyuanEntities_username){
                                repeatFields.add(s.getUsername());
                            }
                            return R.error(511,"数据库的该表中的 [账号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //联系方式
                        List<WeixiuyuanEntity> weixiuyuanEntities_weixiuyuanPhone = weixiuyuanService.selectList(new EntityWrapper<WeixiuyuanEntity>().in("weixiuyuan_phone", seachFields.get("weixiuyuanPhone")).eq("weixiuyuan_delete", 1));
                        if(weixiuyuanEntities_weixiuyuanPhone.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(WeixiuyuanEntity s:weixiuyuanEntities_weixiuyuanPhone){
                                repeatFields.add(s.getWeixiuyuanPhone());
                            }
                            return R.error(511,"数据库的该表中的 [联系方式] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                        weixiuyuanService.insertBatch(weixiuyuanList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }


    /**
    * 登录
    */
    @IgnoreAuth
    @RequestMapping(value = "/login")
    public R login(String username, String password, String captcha, HttpServletRequest request) {
        WeixiuyuanEntity weixiuyuan = weixiuyuanService.selectOne(new EntityWrapper<WeixiuyuanEntity>().eq("username", username));
        if(weixiuyuan==null || !weixiuyuan.getPassword().equals(password))
            return R.error("账号或密码不正确");
        else if(weixiuyuan.getWeixiuyuanDelete() != 1)
            return R.error("账户已被删除");
        //  // 获取监听器中的字典表
        // ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
        // Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
        // Map<Integer, String> role_types = dictionaryMap.get("role_types");
        // role_types.get(.getRoleTypes());
        String token = tokenService.generateToken(weixiuyuan.getId(),username, "weixiuyuan", "维修人员");
        R r = R.ok();
        r.put("token", token);
        r.put("role","维修人员");
        r.put("username",weixiuyuan.getWeixiuyuanName());
        r.put("tableName","weixiuyuan");
        r.put("userId",weixiuyuan.getId());
        return r;
    }

    /**
    * 注册
    */
    @IgnoreAuth
    @PostMapping(value = "/register")
    public R register(@RequestBody WeixiuyuanEntity weixiuyuan){
//    	ValidatorUtils.validateEntity(user);
        Wrapper<WeixiuyuanEntity> queryWrapper = new EntityWrapper<WeixiuyuanEntity>()
            .eq("username", weixiuyuan.getUsername())
            .or()
            .eq("weixiuyuan_phone", weixiuyuan.getWeixiuyuanPhone())
            .andNew()
            .eq("weixiuyuan_delete", 1)
            ;
        WeixiuyuanEntity weixiuyuanEntity = weixiuyuanService.selectOne(queryWrapper);
        if(weixiuyuanEntity != null)
            return R.error("账户或者联系方式已经被使用");
        weixiuyuan.setWeixiuyuanDelete(1);
        weixiuyuan.setCreateTime(new Date());
        weixiuyuanService.insert(weixiuyuan);
        return R.ok();
    }

    /**
     * 重置密码
     */
    @GetMapping(value = "/resetPassword")
    public R resetPassword(Integer  id){
        WeixiuyuanEntity weixiuyuan = new WeixiuyuanEntity();
        weixiuyuan.setPassword("123456");
        weixiuyuan.setId(id);
        weixiuyuanService.updateById(weixiuyuan);
        return R.ok();
    }


    /**
     * 忘记密码
     */
    @IgnoreAuth
    @RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request) {
        WeixiuyuanEntity weixiuyuan = weixiuyuanService.selectOne(new EntityWrapper<WeixiuyuanEntity>().eq("username", username));
        if(weixiuyuan!=null){
            weixiuyuan.setPassword("123456");
            boolean b = weixiuyuanService.updateById(weixiuyuan);
            if(!b){
               return R.error();
            }
        }else{
           return R.error("账号不存在");
        }
        return R.ok();
    }


    /**
    * 获取用户的session用户信息
    */
    @RequestMapping("/session")
    public R getCurrWeixiuyuan(HttpServletRequest request){
        Integer id = (Integer)request.getSession().getAttribute("userId");
        WeixiuyuanEntity weixiuyuan = weixiuyuanService.selectById(id);
        if(weixiuyuan !=null){
            //entity转view
            WeixiuyuanView view = new WeixiuyuanView();
            BeanUtils.copyProperties( weixiuyuan , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }
    }


    /**
    * 退出
    */
    @GetMapping(value = "logout")
    public R logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return R.ok("退出成功");
    }




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

        // 没有指定排序字段就默认id倒序
        if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
            params.put("orderBy","id");
        }
        PageUtils page = weixiuyuanService.queryPage(params);

        //字典表数据转换
        List<WeixiuyuanView> list =(List<WeixiuyuanView>)page.getList();
        for(WeixiuyuanView 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);
        WeixiuyuanEntity weixiuyuan = weixiuyuanService.selectById(id);
            if(weixiuyuan !=null){


                //entity转view
                WeixiuyuanView view = new WeixiuyuanView();
                BeanUtils.copyProperties( weixiuyuan , view );//把实体数据重构到view中

                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody WeixiuyuanEntity weixiuyuan, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,weixiuyuan:{}",this.getClass().getName(),weixiuyuan.toString());
        Wrapper<WeixiuyuanEntity> queryWrapper = new EntityWrapper<WeixiuyuanEntity>()
            .eq("username", weixiuyuan.getUsername())
            .or()
            .eq("weixiuyuan_phone", weixiuyuan.getWeixiuyuanPhone())
            .andNew()
            .eq("weixiuyuan_delete", 1)
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        WeixiuyuanEntity weixiuyuanEntity = weixiuyuanService.selectOne(queryWrapper);
        if(weixiuyuanEntity==null){
            weixiuyuan.setWeixiuyuanDelete(1);
            weixiuyuan.setCreateTime(new Date());
        weixiuyuan.setPassword("123456");
        //  String role = String.valueOf(request.getSession().getAttribute("role"));
        //  if("".equals(role)){
        //      weixiuyuan.set
        //  }
        weixiuyuanService.insert(weixiuyuan);
            return R.ok();
        }else {
            return R.error(511,"账户或者联系方式已经被使用");
        }
    }


}


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("/guzhangshangbaoCommentback")
public class GuzhangshangbaoCommentbackController {
    private static final Logger logger = LoggerFactory.getLogger(GuzhangshangbaoCommentbackController.class);

    @Autowired
    private GuzhangshangbaoCommentbackService guzhangshangbaoCommentbackService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;

    //级联表service
    @Autowired
    private GuzhangshangbaoService guzhangshangbaoService;
    @Autowired
    private XueshengService xueshengService;

    @Autowired
    private WeixiuyuanService weixiuyuanService;


    /**
    * 后端列表
    */
    @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(StringUtil.isEmpty(role))
            return R.error(511,"权限为空");
        else if("学生".equals(role))
            params.put("xueshengId",request.getSession().getAttribute("userId"));
        else if("维修人员".equals(role))
            params.put("weixiuyuanId",request.getSession().getAttribute("userId"));
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = guzhangshangbaoCommentbackService.queryPage(params);

        //字典表数据转换
        List<GuzhangshangbaoCommentbackView> list =(List<GuzhangshangbaoCommentbackView>)page.getList();
        for(GuzhangshangbaoCommentbackView 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);
        GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentback = guzhangshangbaoCommentbackService.selectById(id);
        if(guzhangshangbaoCommentback !=null){
            //entity转view
            GuzhangshangbaoCommentbackView view = new GuzhangshangbaoCommentbackView();
            BeanUtils.copyProperties( guzhangshangbaoCommentback , view );//把实体数据重构到view中

                //级联表
                GuzhangshangbaoEntity guzhangshangbao = guzhangshangbaoService.selectById(guzhangshangbaoCommentback.getGuzhangshangbaoId());
                if(guzhangshangbao != null){
                    BeanUtils.copyProperties( guzhangshangbao , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "xueshengId"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setGuzhangshangbaoId(guzhangshangbao.getId());
                    view.setGuzhangshangbaoXueshengId(guzhangshangbao.getXueshengId());
                }
                //级联表
                XueshengEntity xuesheng = xueshengService.selectById(guzhangshangbaoCommentback.getXueshengId());
                if(xuesheng != null){
                    BeanUtils.copyProperties( xuesheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setXueshengId(xuesheng.getId());
                }
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentback, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,guzhangshangbaoCommentback:{}",this.getClass().getName(),guzhangshangbaoCommentback.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(StringUtil.isEmpty(role))
            return R.error(511,"权限为空");
        else if("学生".equals(role))
            guzhangshangbaoCommentback.setXueshengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));

        guzhangshangbaoCommentback.setInsertTime(new Date());
        guzhangshangbaoCommentback.setCreateTime(new Date());
        guzhangshangbaoCommentbackService.insert(guzhangshangbaoCommentback);
        return R.ok();
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentback, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,guzhangshangbaoCommentback:{}",this.getClass().getName(),guzhangshangbaoCommentback.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(StringUtil.isEmpty(role))
//            return R.error(511,"权限为空");
//        else if("学生".equals(role))
//            guzhangshangbaoCommentback.setXueshengId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
        //根据字段查询是否有相同数据
        Wrapper<GuzhangshangbaoCommentbackEntity> queryWrapper = new EntityWrapper<GuzhangshangbaoCommentbackEntity>()
            .eq("id",0)
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentbackEntity = guzhangshangbaoCommentbackService.selectOne(queryWrapper);
        guzhangshangbaoCommentback.setUpdateTime(new Date());
        if(guzhangshangbaoCommentbackEntity==null){
            //  String role = String.valueOf(request.getSession().getAttribute("role"));
            //  if("".equals(role)){
            //      guzhangshangbaoCommentback.set
            //  }
            guzhangshangbaoCommentbackService.updateById(guzhangshangbaoCommentback);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        guzhangshangbaoCommentbackService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<GuzhangshangbaoCommentbackEntity> guzhangshangbaoCommentbackList = 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){
                            //循环
                            GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentbackEntity = new GuzhangshangbaoCommentbackEntity();
//                            guzhangshangbaoCommentbackEntity.setGuzhangshangbaoId(Integer.valueOf(data.get(0)));   //故障上报 要改的
//                            guzhangshangbaoCommentbackEntity.setXueshengId(Integer.valueOf(data.get(0)));   //学生 要改的
//                            guzhangshangbaoCommentbackEntity.setGuzhangshangbaoCommentbackText(data.get(0));                    //评价内容 要改的
//                            guzhangshangbaoCommentbackEntity.setReplyText(data.get(0));                    //回复内容 要改的
//                            guzhangshangbaoCommentbackEntity.setInsertTime(date);//时间
//                            guzhangshangbaoCommentbackEntity.setUpdateTime(new Date(data.get(0)));          //回复时间 要改的
//                            guzhangshangbaoCommentbackEntity.setCreateTime(date);//时间
                            guzhangshangbaoCommentbackList.add(guzhangshangbaoCommentbackEntity);


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

                        //查询是否重复
                        guzhangshangbaoCommentbackService.insertBatch(guzhangshangbaoCommentbackList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            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));

        // 没有指定排序字段就默认id倒序
        if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
            params.put("orderBy","id");
        }
        PageUtils page = guzhangshangbaoCommentbackService.queryPage(params);

        //字典表数据转换
        List<GuzhangshangbaoCommentbackView> list =(List<GuzhangshangbaoCommentbackView>)page.getList();
        for(GuzhangshangbaoCommentbackView 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);
        GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentback = guzhangshangbaoCommentbackService.selectById(id);
            if(guzhangshangbaoCommentback !=null){


                //entity转view
                GuzhangshangbaoCommentbackView view = new GuzhangshangbaoCommentbackView();
                BeanUtils.copyProperties( guzhangshangbaoCommentback , view );//把实体数据重构到view中

                //级联表
                    GuzhangshangbaoEntity guzhangshangbao = guzhangshangbaoService.selectById(guzhangshangbaoCommentback.getGuzhangshangbaoId());
                if(guzhangshangbao != null){
                    BeanUtils.copyProperties( guzhangshangbao , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setGuzhangshangbaoId(guzhangshangbao.getId());
                }
                //级联表
                    XueshengEntity xuesheng = xueshengService.selectById(guzhangshangbaoCommentback.getXueshengId());
                if(xuesheng != null){
                    BeanUtils.copyProperties( xuesheng , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setXueshengId(xuesheng.getId());
                }
                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody GuzhangshangbaoCommentbackEntity guzhangshangbaoCommentback, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,guzhangshangbaoCommentback:{}",this.getClass().getName(),guzhangshangbaoCommentback.toString());
        guzhangshangbaoCommentback.setInsertTime(new Date());
        guzhangshangbaoCommentback.setCreateTime(new Date());
        guzhangshangbaoCommentbackService.insert(guzhangshangbaoCommentback);
        return R.ok();
        }


}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值