package com.newfiber.api.pc.controller.News; import com.baomidou.mybatisplus.plugins.Page; import com.newfiber.api.core.bean.ReqBodyObj; import com.newfiber.api.core.bean.RespBodyObj; import com.newfiber.api.core.utils.UUIDPK; import com.newfiber.api.pc.dao.News.AffichePublicDao; import com.newfiber.api.pc.model.EventsManage.AffichePublic; import com.newfiber.api.pc.model.EventsManage.AffichePublicQuery; import com.newfiber.api.pc.service.RestTemplateService; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Date; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by XuChengChao on 2017/7/20. */ @Controller public class AffichePublicController { @Autowired AffichePublicDao affichePublicDao; @Resource private RestTemplateService restTemplateService; /** * 新增公告信息 * @param request * @return */ @PostMapping(value = "affiche/addAffiche",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj addAffichePublic(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,String>> param){ String title = param.getData().get("title"); String pic = param.getData().get("pic"); String content = param.getData().get("content"); String abstracts = param.getData().get("abstracts"); String areaNo = param.getData().get("area"); String userNo = request.getHeader("userNo"); String userName = restTemplateService.getUserInfo(userNo).getUserName(); AffichePublic affichePublic = new AffichePublic(); String uuid = UUIDPK.UUIDGenerator.getUUID(); affichePublic.setAfficheNo(uuid); affichePublic.setTitle(title); affichePublic.setPublisherUsername(userName); affichePublic.setPublisherUserid(userNo); affichePublic.setAreas(areaNo); affichePublic.setContent(content); affichePublic.setAbstracts(abstracts); affichePublic.setPublishTime(new Date()); affichePublic.setTitleImg(pic); //上传图片 // if (!pic.isEmpty()){ // try { // List list = UploadController.uploadFileConfigurable(pic,request,"images"); // affichePublic.setTitleImg((String) list.get(1)); // } catch (Exception e) { // e.printStackTrace(); // } // } int flag=0; try { flag = affichePublicDao.insertSelective(affichePublic); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } if (flag!=0){ return RespBodyObj.ok("添加成功"); }else return RespBodyObj.ok("添加失败"); } /** * 修改公告信息 * @return */ @PostMapping(value = "affiche/updateAffiche",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj updateAffichePublic(@RequestBody ReqBodyObj<Map<String,String>> param){ String afficheNo = param.getData().get("afficheNo"); String title = param.getData().get("title"); String pic = param.getData().get("pic"); String content = param.getData().get("content"); String abstracts = param.getData().get("abstracts"); String areaNo = param.getData().get("area"); AffichePublicQuery query = new AffichePublicQuery(); query.createCriteria().andAfficheNoEqualTo(afficheNo); AffichePublic affichePublic = new AffichePublic(); affichePublic.setAbstracts(abstracts); affichePublic.setContent(content); affichePublic.setAreas(areaNo); affichePublic.setTitle(title); affichePublic.setTitleImg(pic); //上传图片 // List list = new ArrayList(); // if (!pic.isEmpty()){ // try { // list = UploadController.uploadFileConfigurable(pic,request,"images"); // } catch (Exception e) { // e.printStackTrace(); // } //插入缩略图的路径 //affichePublic.setTitleImg((String) list.get(1)); // } int flag =0; try { flag = affichePublicDao.updateByExampleSelective(affichePublic,query); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } if (flag!=0){ return RespBodyObj.ok("修改成功"); }else return RespBodyObj.ok("修改失败"); } /** * 批量删除公告信息 * @return */ @PostMapping(value = "affiche/deleteAffiche",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj deleteAffichePublic(@RequestBody ReqBodyObj<Map<String,String []>> param){ String [] afficheNos = param.getData().get("afficheNos"); if (afficheNos.length!=0){ int flag=0; for (int i=0;i<afficheNos.length;i++){ AffichePublicQuery query = new AffichePublicQuery(); query.createCriteria().andAfficheNoEqualTo(afficheNos[i]); try { flag = affichePublicDao.deleteByExample(query); }catch (Exception e){ e.printStackTrace(); return RespBodyObj.error(); } } if (flag!=0){ return RespBodyObj.ok("删除成功"); }else return RespBodyObj.ok("删除失败"); }else return RespBodyObj.ok("未选中数据"); } /** * 展示平台公告信息 * @return */ @PostMapping(value = "affiche/afficheList",produces = "application/json;charset=UTF-8") @ResponseBody public RespBodyObj showAfficheList(@RequestBody ReqBodyObj<Map<String,String>> params){ String area = params.getData().get("area"); String str = params.getData().get("str"); Integer page = params.getCurrent(); Integer rows = params.getSize(); String sort = params.getData().get("sort"); String order = params.getData().get("order"); AffichePublicQuery query = new AffichePublicQuery(); if (area!=null &&area!=""){ query.createCriteria().andAreasEqualTo(area); } if (str!=null && str!=""){ try { query.setStr(URLDecoder.decode(str,"UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if (page!=0 && rows !=0){ query.setPageNo(page); query.setPageSize(rows); } if (sort!=null && order!=null){ query.setSort(sort); query.setOrder(order); } List<AffichePublic> affichePublics = affichePublicDao.selectByExample(query); //查询的总数 int count = affichePublicDao.countByExample(query); Page page1 = new Page(); page1.setRecords(affichePublics); page1.setTotal(count); return RespBodyObj.ok(page1); } // @Autowired // SysDictionaryDao dictionaryDao; // /** // * 查询河道区域信息 // * @return // */ // @PostMapping(value = "area/areaList") // @ResponseBody // public String getDictionaryByGroup() { // List<SysDictionary> list = dictionaryDao.getDictionaryByGroup("行政区划"); // return JSON.toJSONString(list); // } // // /** // * 查询河道等级信息 // * @return // */ // @PostMapping(value = "area/levelList") // @ResponseBody // public String getDictionaryLevelByGroup() { // List<SysDictionary> list = dictionaryDao.getDictionaryByGroup("河道等级"); // return JSON.toJSONString(list); // } // // /** // * 获取行政区划二级排序树 // * @return // */ // @PostMapping(value = "area/getAreaGradeTree") // @ResponseBody // public String getDictionaryTree(){ // // List<SysDictionary> firstGradeList = dictionaryDao.getFirstGradeDictionary("行政区划"); // if (!(firstGradeList.isEmpty())){ // for (SysDictionary dic : firstGradeList){ // // String parentId = dic.getDic_NO(); // List<SysDictionary> sysDictionaries = dictionaryDao.getDicByParetId(parentId); // if (!(sysDictionaries.isEmpty())){ // dic.setChildren(sysDictionaries); // } // // } // return JSON.toJSONString(firstGradeList); // // // }else{ // JSONObject json = new JSONObject(); // json.put("data",new ArrayList<>()); // return json.toJSONString(); // } // // // } }