PageRenderTime 253ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/jusfoun/catalog/controller/BusinessContoller.java

https://gitlab.com/jusfoun_wz/catalog
Java | 331 lines | 241 code | 24 blank | 66 comment | 20 complexity | 044a02f6c3b3297f6bacdd1947c43868 MD5 | raw file
  1. package com.jusfoun.catalog.controller;
  2. import java.io.IOException;
  3. import java.util.Collections;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.servlet.http.HttpServletRequest;
  9. import org.apache.shiro.web.util.WebUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import org.springframework.web.servlet.ModelAndView;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.jusfoun.catalog.common.controller.BaseController;
  19. import com.jusfoun.catalog.common.entity.DataEntity;
  20. import com.jusfoun.catalog.common.mapper.JsonMapper;
  21. import com.jusfoun.catalog.common.tool.ServletTool;
  22. import com.jusfoun.catalog.entity.Business;
  23. import com.jusfoun.catalog.service.BusinessService;
  24. import com.jusfoun.catalog.utils.LogUtils;
  25. import com.jusfoun.catalog.utils.UserUtils;
  26. /**
  27. * 业务controller
  28. * @author liudebin
  29. *
  30. */
  31. @Controller
  32. public class BusinessContoller extends BaseController {
  33. @Autowired
  34. private BusinessService businessService;
  35. /**
  36. * 业务目录信息列表
  37. * @param request
  38. * @param response
  39. * @return
  40. */
  41. @RequestMapping(value = "${adminPath}/business/index", method = RequestMethod.GET)
  42. public String getBusinessInfoList(){
  43. return "admin/business/businessIndex";
  44. }
  45. /**
  46. * 业务目录维护
  47. * @param request
  48. * @param response
  49. * @return
  50. */
  51. @RequestMapping(value = "${adminPath}/business/maintenance")
  52. public String getBusinessMaintenance(){
  53. return "admin/business/businessMaintenance";
  54. }
  55. /**
  56. * 业务目录管理
  57. * @param request
  58. * @param response
  59. * @return
  60. */
  61. @RequestMapping(value = "${adminPath}/business/manage", method = RequestMethod.GET)
  62. public String getBusinessManage(){
  63. return "admin/business/businessManage";
  64. }
  65. /**
  66. * 业务目录操作导航--针对create、update及view
  67. * @param request
  68. * @param response
  69. * @return
  70. */
  71. @RequestMapping(value = "${adminPath}/business/action", method = RequestMethod.GET)
  72. public ModelAndView operBusinesAction(@RequestParam("type")String type,@RequestParam(value="id",required=false) Integer id){
  73. ModelAndView mav=new ModelAndView("admin/business/businessAction");
  74. if(null!=type&&!"".equals(type)&&(type.equals("view")||type.equals("update"))){
  75. if(id!=null){
  76. Business biz=businessService.get(id);
  77. if(biz!=null){
  78. mav.addObject("business", biz);
  79. if(type.equals("view")){
  80. mav.addObject("actionType", "view");
  81. }else{
  82. mav.addObject("actionType", "update");
  83. }
  84. }
  85. }
  86. }else{
  87. mav.addObject("business", null);
  88. mav.addObject("actionType", "create");
  89. }
  90. return mav;
  91. }
  92. /**
  93. * 新建业务
  94. * @param biz
  95. * @return
  96. */
  97. @RequestMapping(value = "${adminPath}/business/createBiz", method = RequestMethod.POST)
  98. public String createBiz(Business biz){
  99. biz.setCreateBy(UserUtils.getUser());
  100. biz.setCreateDate(new Date());
  101. biz.setStatus(DataEntity.STATUS_UNAPPLY);
  102. businessService.save(biz);
  103. LogUtils.saveLog(ServletTool.getRequest(), "部门目录-业务信息维护-新建业务");
  104. return "redirect:"+adminPath+"/business/maintenance";
  105. }
  106. /**
  107. * 更新业务
  108. * @param biz
  109. * @return
  110. */
  111. @RequestMapping(value = "${adminPath}/business/updateBiz", method = RequestMethod.POST)
  112. public String updateBiz(Business biz){
  113. businessService.updateBiz(biz);
  114. LogUtils.saveLog(ServletTool.getRequest(), "部门目录-业务信息维护-编辑业务");
  115. return "redirect:"+adminPath+"/business/maintenance";
  116. }
  117. /**
  118. * 批量更新业务
  119. * @param biz
  120. * @return
  121. */
  122. @RequestMapping(value = "${adminPath}/business/batchUpdateBiz", method = RequestMethod.POST)
  123. @ResponseBody
  124. public String batchUpdateBiz(@RequestParam(value="subId",required=false)Integer subId,@RequestParam(value="opType",required=false)Integer opType,@RequestParam(value="params")String params){
  125. businessService.batchUpdateBiz(subId,opType,params);
  126. return "success";
  127. }
  128. /**
  129. * 批量更新业务
  130. * @param biz
  131. * @return
  132. */
  133. @RequestMapping(value = "${adminPath}/business/batchUpdateBizCancel", method = RequestMethod.POST)
  134. @ResponseBody
  135. public String batchUpdateBizCancel(@RequestParam(value="subId",required=false)Integer subId,@RequestParam(value="opType",required=false)Integer opType,@RequestParam(value="params")String params){
  136. businessService.batchUpdateBizCancel(subId,opType,params);
  137. return "success";
  138. }
  139. @ResponseBody
  140. @RequestMapping(value = "${adminPath}/business/delBiz", method = RequestMethod.GET)
  141. public String delBiz(@RequestParam("id")Integer id){
  142. String delFlag="fail";
  143. if(null!=id){
  144. Business biz=new Business();
  145. biz.setId(id);
  146. businessService.delete(biz);
  147. LogUtils.saveLog(ServletTool.getRequest(), "部门目录-业务信息维护-删除业务");
  148. delFlag="success";
  149. }
  150. return delFlag;
  151. }
  152. @ResponseBody
  153. @RequestMapping(value = "${adminPath}/business/delBizLinkSub", method = RequestMethod.GET)
  154. public String delBizLinkSub(@RequestParam("id")Integer id){
  155. String delFlag="fail";
  156. if(null!=id){
  157. Business biz=new Business();
  158. biz.setId(id);
  159. biz.setSubjectId(0);
  160. businessService.updateBiz(biz);
  161. LogUtils.saveLog(ServletTool.getRequest(), "部门目录-业务信息维护-删除业务与主题间的关联");
  162. delFlag="success";
  163. }
  164. return delFlag;
  165. }
  166. @RequestMapping(value = "${adminPath}/business/businessTree", method = RequestMethod.POST)
  167. @ResponseBody
  168. public Object businessTree(
  169. @RequestParam(name = "officeId", required = true) Integer officeId) {
  170. List<Business> business = businessService.findBusinessByOfficeId(officeId);
  171. Map<String, Object> result = new HashMap<String, Object>();
  172. if (business != null && business.size() > 0) {
  173. result.put("business", business);
  174. result.put("businessSize", business.size());
  175. } else {
  176. result.put("business", Collections.EMPTY_LIST);
  177. result.put("businessSize", 0);
  178. }
  179. return result;
  180. }
  181. @RequestMapping(value = "${adminPath}/business/tree", method = RequestMethod.POST)
  182. @ResponseBody
  183. public Object tree(
  184. @RequestParam(name = "id", required = true) Integer officeId) {
  185. List<Business> business = businessService.findBusinessByOfficeId(officeId);
  186. if (business == null || business.size() == 0) {
  187. return null;
  188. }
  189. StringBuilder sb = new StringBuilder();
  190. sb.append("[");
  191. for (Business bs : business) {
  192. // { id:1, pId:0, name:"父节点1", open:true,isParent:true},
  193. sb.append("{ id:" + bs.getId() + ", pId:"
  194. + officeId + ", name:'" + bs.getName() +"',type:'business'},");
  195. }
  196. sb.deleteCharAt(sb.length()-1);
  197. sb.append("]");
  198. return JSONObject.parse(sb.toString());
  199. }
  200. @RequestMapping(value = "${adminPath}/business/businessInfo", method = RequestMethod.POST)
  201. @ResponseBody
  202. public Object businessInfo(@RequestParam(value="id",required=true) Integer id){
  203. Business bs = businessService.get(id);
  204. Map<String, Object> result = new HashMap<String, Object>();
  205. result.put("succ", 1);
  206. result.put("bs", bs);
  207. return result;
  208. }
  209. /**
  210. * 业务列表,根据当前页和记录数获取列表
  211. * @param page 当前页
  212. * @param rows 页面记录数
  213. * @param response
  214. * @throws IOException
  215. */
  216. @ResponseBody
  217. @RequestMapping("${adminPath}/business/bizList")
  218. public String bizList(int page,int rows,HttpServletRequest request) throws IOException{
  219. String name=WebUtils.getCleanParam(request,"name");
  220. String status=WebUtils.getCleanParam(request,"status");
  221. String id=WebUtils.getCleanParam(request,"id");
  222. Business rsc=new Business();
  223. if(null!=name||null!=status){
  224. if(null!=name){
  225. rsc.setName("%"+name+"%");
  226. }
  227. rsc.setStatus(status);
  228. }
  229. if(null!=id){
  230. rsc.setId(Integer.valueOf(id));
  231. }
  232. //求得开始记录与结束记录
  233. int start = (page-1)*rows+1;
  234. int end = page * rows;
  235. //把总记录和当前记录写到前台
  236. int total = businessService.findListCount(rsc);
  237. rsc.getSqlMap().put("start", ""+start);
  238. rsc.getSqlMap().put("end", ""+end);
  239. List<Business> uList = businessService.findList(rsc);
  240. String json = JsonMapper.toJsonString(uList);
  241. StringBuffer sb=new StringBuffer();
  242. sb.append("{\"total\":").append(total).append(",\"rows\":").append(json).append("}");
  243. return sb.toString();
  244. }
  245. @ResponseBody
  246. @RequestMapping("${adminPath}/business/getBusByBusId")
  247. public String getBusByBusId(int page,int rows,HttpServletRequest request) throws IOException{
  248. String busId=WebUtils.getCleanParam(request,"busId");
  249. Business rsc=new Business();
  250. //求得开始记录与结束记录
  251. int start = (page-1)*rows+1;
  252. int end = page * rows;
  253. //把总记录和当前记录写到前台
  254. //int total = businessService.findListCount(busId);
  255. rsc.getSqlMap().put("start", ""+start);
  256. rsc.getSqlMap().put("end", ""+end);
  257. List<Business> uList = businessService.getBusByBusId(busId);
  258. String json = JsonMapper.toJsonString(uList);
  259. StringBuffer sb=new StringBuffer();
  260. sb.append("{\"total\":").append(0).append(",\"rows\":").append(json).append("}");
  261. return sb.toString();
  262. }
  263. @ResponseBody
  264. @RequestMapping("${adminPath}/business/findBySubId")
  265. public String findListBySubjectId(int page,int rows,HttpServletRequest request) throws IOException{
  266. String subjectId=WebUtils.getCleanParam(request,"subjectId");
  267. StringBuffer sb=new StringBuffer();
  268. if(null!=subjectId){
  269. //把总记录和当前记录写到前台
  270. Map<String,Object> sqlMap=new HashMap<String,Object>();
  271. //求得开始记录与结束记录
  272. int start = (page-1)*rows+1;
  273. int end = page * rows;
  274. sqlMap.put("start", start);
  275. sqlMap.put("end", end);
  276. sqlMap.put("subjectId", Integer.valueOf(subjectId));
  277. int total = businessService.findListCountBySubId(sqlMap);
  278. List<Business> bList = businessService.findListBySubId(sqlMap);
  279. String json = JsonMapper.toJsonString(bList);
  280. sb.append("{\"total\":").append(total).append(",\"rows\":").append(json).append("}");
  281. return sb.toString();
  282. }
  283. return "{\"total\":0,\"rows\":[]}";
  284. }
  285. @ResponseBody
  286. @RequestMapping("${adminPath}/business/findByRscId")
  287. public String findListByRscId(int page,int rows,HttpServletRequest request) throws IOException{
  288. String resourceId=WebUtils.getCleanParam(request,"resourceId");
  289. StringBuffer sb=new StringBuffer();
  290. if(null!=resourceId){
  291. //把总记录和当前记录写到前台
  292. Map<String,Object> sqlMap=new HashMap<String,Object>();
  293. //求得开始记录与结束记录
  294. int start = (page-1)*rows+1;
  295. int end = page * rows;
  296. sqlMap.put("start", ""+start);
  297. sqlMap.put("end", ""+end);
  298. sqlMap.put("resourceId", Integer.valueOf(resourceId));
  299. int total = businessService.findListCountByRscId(sqlMap);
  300. List<Business> bList = businessService.findListByRscId(sqlMap);
  301. String json = JsonMapper.toJsonString(bList);
  302. sb.append("{\"total\":").append(total).append(",\"rows\":").append(json).append("}");
  303. return sb.toString();
  304. }
  305. return "{\"total\":0,\"rows\":[]}";
  306. }
  307. }