InformationController.java 5.68 KB
package com.server.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.server.shiro.persistent.bean.SysUser;
import com.server.utils.DateUtils;
import com.server.web.common.mapper.TBaseSecondClassMapper;
import com.server.web.common.mapper.TKzyCourseMapper;
import com.server.web.common.mapper.TKzyInformationMapper;
import com.server.web.common.model.PageModel;
import com.server.web.common.model.TBaseSecondClass;
import com.server.web.common.model.TKzyCourse;
import com.server.web.common.model.TKzyInformation;
import com.server.web.common.service.CourseService;
import com.server.web.common.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资讯管理
 */
@RestController
@RequestMapping(BaseController.OSS_NAMESPACE + "/information")
public class InformationController extends BaseController {

    @Autowired
    private TKzyInformationMapper informationMapper;

    @Autowired
    private InformationService informationService;

    @Autowired
    private TBaseSecondClassMapper secondClassMapper;

    /**
     * 资讯列表
     * @param title
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/zbList", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map zbList(@RequestParam(defaultValue = "") String title
            ,@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "1") Integer pageSize) {
        try {
            Map paramMap = new HashMap<>();
            if(!("").equals(title)){
                paramMap.put("title","%"+title+"%");
            }
            PageHelper.startPage(pageNo,pageSize,true,false);
            List list = openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryInformation",paramMap);
            PageInfo pageInfo = new PageInfo(list);
            PageModel model = new PageModel();
            model.setTotal(pageInfo.getTotal());
            model.setList(list);
            return success(model);
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }

    /**
     * 删除资讯
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/deleteInformation", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map deleteInformation(@RequestParam long id) {
        try {
            TKzyInformation information = new TKzyInformation();
            information.setId(id);
            information.setIsDelete(1);
            information.setUpdateDt(new Date());
            informationMapper.updateByPrimaryKeySelective(information);
            return success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }


    @ResponseBody
    @RequestMapping(path = "/saveInformation", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map saveInformation(@RequestParam(defaultValue = "-1") long id,@RequestParam String title,@RequestParam String author,@RequestParam String content,
                            @RequestParam String picUrl,@RequestParam String iconUrl,@RequestParam(defaultValue = "") String classIds
                            ) {
        try {
            String [] ids = classIds.split(",");
            boolean flag = true;
            for (int i=0;i<ids.length;i++){
                TBaseSecondClass secondClass = secondClassMapper.selectByPrimaryKey(Long.valueOf(ids[i]));
                if(secondClass.getType()!=1){
                    flag = false;
                    break;
                }
            }
            if(!flag){
                return  error("0","分类类型不匹配","分类类型不匹配");
            }
            TKzyInformation information = new TKzyInformation();
            information.setTitle(title);
            information.setPicUrl(picUrl);
            information.setAuthor(author);
//            information.setContent();
            information.setIconUrl(iconUrl);
            if(id != -1){  //修改
                information.setId(id);
                information.setUpdateDt(new Date());
                informationService.updateInformation(information,classIds);
            }else{ //添加
                information.setCreateDt(new Date());
                information.setIsDelete(0);
                informationService.insertInformation(information,classIds);
            }
            return success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }

    /**
     * 资讯详情
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/informationInfo", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map informationInfo(@RequestParam long id) {
        try {
            Map paramMap = new HashMap<>();
            paramMap.put("id",id);
            paramMap.put("type",2);
            Map map = (Map)openSqlRingsService.selectOne_Rings("com.mapping.queryModel.queryInformationInfo",paramMap);
            List classList = openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryCourseClass",paramMap);
            map.put("classList",classList);
            return success(map);
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }

}