首页>代码>springboot+mybatis+Maven+jsp+Quartz整合实战林业厅项目>/ah_lyt/src/main/java/com/ct/ring/action/PersonAction.java
package com.ct.ring.action; import com.ct.ring.dto.Dept; import com.ct.ring.dto.Person; import com.ct.ring.dto.PersonCopy; import com.ct.ring.service.DeptService; import com.ct.ring.service.PersonService; import com.ct.ring.util.ExcelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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 javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.zip.Inflater; @Controller @EnableAutoConfiguration @RequestMapping("/person") public class PersonAction { protected static Logger logger = LoggerFactory.getLogger(PersonAction.class); @Autowired private DeptService deptService; @Autowired private PersonService personService; @Autowired private ExcelUtils excelUtils; private List<Dept> deptList; @RequestMapping("/index") public ModelAndView index ( HttpServletRequest request ) { int id = 0; deptList = deptService.deptList(id); ModelAndView mv = new ModelAndView( "person/index" ); String json = "[" + getZtree(deptList) + "]"; mv.addObject( "zTree",json ); return mv; } @RequestMapping("/getPersonPages") @ResponseBody public Map getPersonPages ( HttpServletRequest request ) { Map<String, Object> map = new HashMap<String, Object>(); int deptId=Integer.valueOf( request.getParameter( "deptId" ) ); String personName =request.getParameter( "personName" ); int pageIndex=Integer.valueOf( request.getParameter( "pageindex" ) ); int pageSize=Integer.valueOf( request.getParameter( "pageSize" ) ); List<Person> personList = personService.getPersonPages(deptId,personName,pageIndex,pageSize); List<Person> personListAll = personService.getPersonPageAll(deptId,personName); map.put( "totalCount",personListAll.size() ); map.put( "result" ,personList); return map; } @RequestMapping("/savePerson") @ResponseBody public Map savePerson ( HttpServletRequest request, Person person ) { Map<String, Object> map = new HashMap<String, Object>(); //表更新数据 int i=0; if(person.getId()==0){ //save Map m=personService.selectMax(person.getDeptId());//获取当前部门下,最大排序号 if(m!=null){ System.out.println( m.get( "sort" )+"-----------------" ); person.setSort((int)m.get( "sort" )+1 ); }else{ person.setSort(1); } i= personService.savePerson(person); }else{ //update i= personService.updatePerson(person); } if (i > 0) { map.put("status", true); } else { map.put("message", "保存失败!"); map.put("status", false); } return map; } @RequestMapping("/editPerson") @ResponseBody public List<Map> editPerson ( HttpServletRequest request ) { List<Map> list =personService.getPersonById( Integer.valueOf( request.getParameter( "personId" ) )); return list; } @RequestMapping("/delPerson") @ResponseBody public Map delPerson ( HttpServletRequest request ) { Map<String, Object> map = new HashMap<String, Object>(); //todo int i =personService.delPersonById(Integer.valueOf( request.getParameter( "personId" ) )); if (i > 0) { map.put("status", true); } else { map.put("message", "删除失败!"); map.put("status", false); } return map; } // 删除用户信息 @RequestMapping("/delPersons") public @ResponseBody Map dels(@RequestParam("ids") String ids) { Map<String, Object> map = new HashMap<String, Object>(); String[] array =ids.split(","); int i = personService.delPersons(array); if (i > 0) { map.put("status", true); } else { map.put("message", "删除失败!"); map.put("status", false); } return map; } @RequestMapping("/deptUser") @ResponseBody public Map deptUser ( HttpServletRequest request ) { Map<String, Object> map = new HashMap<String, Object>(); int deptId=Integer.valueOf( request.getParameter( "deptId" ) ); List<Person> personListAll = personService.getPersonPageAll(deptId,null); map.put( "obj",personListAll ); return map; } /** * 跳转到excel导入页面 * * @return */ @RequestMapping("excelPage") public String excelPage( ModelMap map) { return "person/excel"; } /*** * excel导入 * @return */ @RequestMapping("excel") @ResponseBody public Map excel( @RequestParam MultipartFile file ){ Map<String, Object> map = new HashMap<String, Object>(); List<PersonCopy> list=new ArrayList<PersonCopy>(); if(!file.isEmpty()){ try { list = excelUtils.personExcel(file.getInputStream()); int i=personService.insertByBatch(list); if(i>0){ map.put("status", true); }else { map.put("message", "保存失败!"); map.put("status", false); } } catch (IOException e) { e.printStackTrace(); } } return map; } private String getZtree(List<Dept> deptList) { String json = ""; for(int j=0;j<deptList.size();j++){ json += "{id:" + deptList.get(j).getId() + ",pId:" + deptList.get(j).getSuperId() + ",name:\"" + deptList.get(j).getDeptName() + "\",open:true},"; } json=json.substring( 0,json.length()-1 ); return json; } }