WxFeedbackController.java 4.7 KB
/**
 * Copyright &copy; 2015-2018 <a href="#">J-Site</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.wechat.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.service.OfficeService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.wechat.entity.WxFeedback;
import com.thinkgem.jeesite.modules.wechat.service.WxFeedbackService;

/**
 * 反馈意见Controller
 * @author lzj
 * @version 2020-03-19
 */
@Controller
@RequestMapping(value = "${adminPath}/wechat/wxFeedback")
public class WxFeedbackController extends BaseController {

	@Autowired
	private WxFeedbackService wxFeedbackService;
	@Autowired
	private OfficeService officeService;
	
	@ModelAttribute
	public WxFeedback get(@RequestParam(required=false) String id) {
		WxFeedback entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = wxFeedbackService.get(id);
		}
		if (entity == null){
			entity = new WxFeedback();
		}
		return entity;
	}
	
	@RequiresPermissions("wechat:wxFeedback:view")
	@RequestMapping(value = {"list", ""})
	public String list(WxFeedback wxFeedback, HttpServletRequest request, HttpServletResponse response, Model model) {
		User user = UserUtils.getUser();
		String office = user.getOffice().getName();
		if(StringUtils.isNotBlank(office)) {
			if(office.indexOf("权证") != -1) {
				wxFeedback.setKes("10");
			}else if(office.indexOf("抵押") != -1) {
				wxFeedback.setKes("20");
			}else if(office.indexOf("预告") != -1) {
				wxFeedback.setKes("30");
			}else if(office.indexOf("农林") != -1) {
				wxFeedback.setKes("40");
			}else if(office.indexOf("更正") != -1) {
				wxFeedback.setKes("100");
			}else {
				String name = user.getName();
				if(name.equals("代军")) {
					wxFeedback.setKes("60");
				}else if(name.equals("王才旺")) {
					wxFeedback.setKes("50");
				}
			}
		Page<WxFeedback> page = wxFeedbackService.findPage(new Page<WxFeedback>(request, response), wxFeedback); 
		model.addAttribute("page", page);
		}
		return "modules/wechat/wxFeedbackList";
	}

	@RequiresPermissions("wechat:wxFeedback:view")
	@RequestMapping(value = "form")
	public String form(WxFeedback wxFeedback, Model model) {
		model.addAttribute("wxFeedback", wxFeedback);
		return "modules/wechat/wxFeedbackForm";
	}

	@RequiresPermissions("wechat:wxFeedback:edit")
	@RequestMapping(value = "save")
	public String save(WxFeedback wxFeedback, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, wxFeedback)){
			return form(wxFeedback, model);
		}
		wxFeedbackService.save(wxFeedback);
		Map map = new HashMap();
		try {
		map = wxFeedbackService.answer(wxFeedback);
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("resultMsg", e.getMessage());
		}
		addMessage(redirectAttributes, "保存反馈意见成功");
		return "redirect:"+Global.getAdminPath()+"/wechat/wxFeedback/?repage";
	}
	
	@RequiresPermissions("wechat:wxFeedback:edit")
	@RequestMapping(value = "open")
	public String open(WxFeedback wxFeedback, Model model,HttpServletRequest request, RedirectAttributes redirectAttributes) {
		String isopen = request.getParameter("isopen");
		wxFeedback.setIsopen(isopen);
		wxFeedbackService.save(wxFeedback);
		Map map = new HashMap();
		try {
		map = wxFeedbackService.open(wxFeedback);
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("resultMsg", e.getMessage());
		}
		addMessage(redirectAttributes, "保存反馈意见成功");
		return "redirect:"+Global.getAdminPath()+"/wechat/wxFeedback/?repage";
	}
	
	@RequiresPermissions("wechat:wxFeedback:edit")
	@RequestMapping(value = "delete")
	public String delete(WxFeedback wxFeedback, RedirectAttributes redirectAttributes) {
		wxFeedbackService.delete(wxFeedback);
		addMessage(redirectAttributes, "删除反馈意见成功");
		return "redirect:"+Global.getAdminPath()+"/wechat/wxFeedback/?repage";
	}

}