package com.ifish.action; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.ifish.entity.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import com.ifish.hibernate.Pagination; import com.ifish.search.SearchFilter; import com.ifish.service.AdminService; import com.ifish.service.FactoryService; import com.ifish.util.IfishUtil; import com.ifish.util.getRemoteAddress; /** * @ClassName: FactoryAction * @Description: 电子厂用户 * @author ggw */ @Controller("factoryAction") @RequestMapping("/factory") public class FactoryAction { @Autowired private FactoryService factoryService; @Autowired private AdminService adminService; private static Logger log = LoggerFactory.getLogger(FactoryAction.class); /** * 获取登录用户隶属厂家 * @return */ public FactoryList getFactoryListByUserName(){ SecurityUser securityUser = adminService.getSysUserByUserName(getLoginUserName()); if(securityUser!=null){ String code = securityUser.getCode(); return this.adminService.getFactoryByCode(code); } return null; } /** * 获取登录用户名 * @return */ public String getLoginUserName(){ UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return userDetails.getUsername(); } /** * 主页 * @return */ @RequestMapping("/home.do") public ModelAndView index() { return new ModelAndView("roleFactory/home"); } /** * 设备信息页面 * @return */ @RequestMapping("/tmpDeviceList.do") public ModelAndView tmpDeviceList(ModelMap map) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ //硬件类型 map.put("list1", factoryList.getHardwareTypeSet()); //鱼缸厂 map.put("list2", factoryList.getVenderLists()); } } catch (Exception e) { log.error("tmpDeviceList:error message:{}",e.toString()); } return new ModelAndView("roleFactory/tmpDeviceList",map); } /** * 设备信息页面 新 * @return */ @RequestMapping("/deviceListByPage.do") public ModelAndView deviceListByPage(ModelMap map) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ //鱼缸厂 map.put("list2", factoryList.getVenderLists()); } } catch (Exception e) { log.error("tmpDeviceList:error message:{}",e.toString()); } return new ModelAndView("roleFactory/deviceList",map); } /** * 设备授权页面 * @return */ @RequestMapping("/deviceAssignList.do") public ModelAndView deviceAssignList() { Map map = new HashMap(); try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ //硬件类型 map.put("list1", factoryList.getHardwareTypeSet()); //鱼缸厂 map.put("list2", factoryList.getVenderLists()); } } catch (Exception e) { log.error("deviceAssignList:error message:{}",e.toString()); } return new ModelAndView("roleFactory/deviceAssignList",map); } /** * 授权 * @return */ @RequestMapping("/deviceAuthorize.do") @ResponseBody public Object deviceAuthorize(SearchFilter searchFilter,HttpServletRequest request) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ String ip = getRemoteAddress.getIp(request); this.adminService.deviceAuthorize(ip,factoryList.getFactoryCode(),searchFilter); return true; } } catch (Exception e) { log.error("deviceAuthorize:error message:{}",e.toString()); } return false; } /** * 授权 * @return */ @RequestMapping("/deviceAuthorizeNew.do") @ResponseBody public Object deviceAuthorizeNew(HttpServletRequest request) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ String ip = getRemoteAddress.getIp(request); String[] deviceIds = request.getParameter("deviceId").split("_"); this.adminService.deviceAuthorizeNew(ip,factoryList.getFactoryCode(),deviceIds); return true; } } catch (Exception e) { log.error("deviceAuthorize:error message:{}",e.toString()); } return false; } /** * 重新分配 * @param createCode * @param brandCode * @param request * @return */ @RequestMapping("/deviceFenpei.do") @ResponseBody public Object deviceFenpei(String createCode,String brandCode,HttpServletRequest request) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ String ip = getRemoteAddress.getIp(request); this.adminService.deviceFenpei(ip,factoryList.getFactoryCode(),createCode,brandCode); return true; } } catch (Exception e) { log.error("deviceFenpei:error message:{}",e.toString()); } return false; } /** * 单个重新分配 * @param createCode * @param brandCode * @param request * @return */ @RequestMapping("/deviceFenpeiSingle.do") @ResponseBody public Object deviceFenpeiSingle(Integer deviceId,String brandCode,HttpServletRequest request) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ String ip = getRemoteAddress.getIp(request); this.adminService.deviceFenpeiSingle(ip,factoryList.getFactoryCode(),deviceId,brandCode); return true; } } catch (Exception e) { log.error("deviceFenpei:error message:{}",e.toString()); } return false; } /** * 单个重新分配 * @param request * @return */ @RequestMapping("/deviceFenpeiSingleNew.do") @ResponseBody public Object deviceFenpeiSingleNew(String deviceId,String brandCode,String createCode,HttpServletRequest request) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ String ip = getRemoteAddress.getIp(request); String[] deviceIds = deviceId.split("_"); //是否授权 String authorization = request.getParameter("authorization"); if (authorization.equals("0")) { this.adminService.deviceAuthorizeNew(ip,factoryList.getFactoryCode(),deviceIds); } for (String dId : deviceIds) { int id = Integer.parseInt(dId); this.adminService.deviceFenpeiSingleNew(ip,factoryList.getFactoryCode(),id,brandCode,createCode); } return true; } } catch (Exception e) { log.error("deviceFenpei:error message:{}",e.toString()); } return false; } /** * 设备信息 * @param searchFilter * @return */ @RequestMapping("/tmpDeviceListInf.do") @ResponseBody public Object tmpDeviceListInf(SearchFilter searchFilter) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ searchFilter.setSelectField3(factoryList.getFactoryCode()); Pagination page = this.factoryService.getDeviceByPage(searchFilter); return IfishUtil.returnPageData(page, searchFilter.getsEcho()); } else{ Pagination page = new Pagination(0,0,0,new ArrayList()); return IfishUtil.returnPageData(page , searchFilter.getsEcho()); } } catch (Exception e) { log.error("get tmpDeviceListInf information:error message:{}",e.toString()); } return null; } /** * 设备信息 新 * @param searchFilter * @return */ @RequestMapping("/deviceList.do") @ResponseBody public Object deviceList(SearchFilter searchFilter) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ searchFilter.setSelectField3(factoryList.getFactoryCode()); Pagination page = this.factoryService.getDeviceByPageNew(searchFilter,factoryList.getHardwareTypeSet()); return IfishUtil.returnPageData(page, searchFilter.getsEcho()); } else{ Pagination page = new Pagination(0,0,0,new ArrayList()); return IfishUtil.returnPageData(page , searchFilter.getsEcho()); } } catch (Exception e) { log.error("get tmpDeviceListInf information:error message:{}",e.toString()); } return null; } /** * 问题反馈列表页面 * @param user * @return */ @RequestMapping("/questionList.do") public ModelAndView questionList(String status) { return new ModelAndView("roleFactory/questionList","status",status); } /** * 问题反馈列表 * @param iDisplayStart * @param iDisplayLength * @param sEcho * @param sSearch * @return */ @RequestMapping("/questionInf.do") @ResponseBody public Object questionInf(SearchFilter searchFilter) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ searchFilter.setSelectField2(getLoginUserName()); } Pagination page = this.adminService.getQusetionByPage(searchFilter); return IfishUtil.returnPageData(page, searchFilter.getsEcho()); } catch (Exception e) { log.error("get questions page information:error message:{}",e.toString()); } return null; } /** * 回答用户反馈 * @param questionsFeedback * @return */ @RequestMapping("/replyQuestion.do") @ResponseBody public Object replyQuestion(QuestionsFeedback questionsFeedback){ //推送消息给用户 try { //更新 return this.adminService.questionsReply(questionsFeedback); } catch (Exception e) { log.error("replyQuestion:error message:{}",e.toString()); } return false; } /** * 上传Excel * @param user * @param fileUpload * @return * @throws Exception */ @RequestMapping("/uploadExcel.do") @ResponseBody public Object upload(@RequestParam String brandCode,@RequestParam MultipartFile fileUpload,HttpServletRequest request){ try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ String ip = getRemoteAddress.getIp(request); this.factoryService.uploadExcel(ip,factoryList.getFactoryCode(),brandCode,fileUpload); } return true; } catch (Exception e) { log.error("uploadExcel:error message:{}",e.toString()); return e.getMessage(); } } /** * 操作记录页面 * @param user * @return */ @RequestMapping("/operateRecord.do") public ModelAndView operateRecord() { return new ModelAndView("roleFactory/operateRecord"); } /** * 操作记录列表 * @param iDisplayStart * @param iDisplayLength * @param sEcho * @param sSearch * @return */ @RequestMapping("/operateRecordInf.do") @ResponseBody public Object operateRecordInf(SearchFilter searchFilter) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ searchFilter.setsSearch1(factoryList.getFactoryCode()); } Pagination page = this.adminService.getOperateRecordByPage(searchFilter); return IfishUtil.returnPageData(page, searchFilter.getsEcho()); } catch (Exception e) { log.error("operateRecordInf:error message:{}",e.toString()); } return null; } /** * 支付后台 * @return */ @RequestMapping("/payBill.do") public ModelAndView payBill() { PayeeInfo payeeInfo = this.adminService.getPayeeInfo(1); return new ModelAndView("roleFactory/payBill","payeeInfo",payeeInfo); } /** * 支付后台信息列表 * @param searchFilter * @return */ @RequestMapping("/payBillInf.do") @ResponseBody public Object payBillInf(SearchFilter searchFilter) { try { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ searchFilter.setsSearch(factoryList.getFactoryCode()); } Pagination page = this.adminService.getPayBillByPage(searchFilter); return IfishUtil.returnPageData(page, searchFilter.getsEcho()); } catch (Exception e) { log.error("payBillInf:error message:{}",e.toString()); } return null; } /** * 支付详情页面 * @param user * @return */ @RequestMapping("/payDetail.do") public ModelAndView operateRecord(ModelMap map,String billMonth) { FactoryList factoryList = getFactoryListByUserName(); if(factoryList!=null){ map.put("factoryCode", factoryList.getFactoryCode()); } map.put("billMonth", billMonth); return new ModelAndView("roleFactory/payDetail",map); } /** * 支付详情列表 * @param searchFilter * @return */ @RequestMapping("/payDetailInf.do") @ResponseBody public Object payDetailInf(SearchFilter searchFilter) { try { Pagination page = this.adminService.getOperateRecordByPage(searchFilter); return IfishUtil.returnPageData(page, searchFilter.getsEcho()); } catch (Exception e) { log.error("payDetailInf:error message:{}",e.toString()); } return null; } }