265 lines
9.2 KiB
Java
265 lines
9.2 KiB
Java
package com.nis.web.controller.basics;
|
||
|
||
import java.lang.reflect.Field;
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Properties;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.ui.Model;
|
||
import org.springframework.util.StringUtils;
|
||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.ResponseBody;
|
||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||
|
||
import com.nis.domain.Page;
|
||
import com.nis.domain.configuration.RequestInfo;
|
||
import com.nis.domain.configuration.TaskInfo;
|
||
import com.nis.util.Constants;
|
||
import com.nis.util.DateUtils;
|
||
import com.nis.util.LogUtils;
|
||
import com.nis.util.StringUtil;
|
||
import com.nis.util.excel.ExcelField;
|
||
import com.nis.web.controller.BaseController;
|
||
import com.nis.web.service.basics.TaskInfoService;
|
||
|
||
import jersey.repackaged.com.google.common.collect.Lists;
|
||
|
||
@Controller
|
||
@RequestMapping("${adminPath}/basics/taskInfo")
|
||
public class TaskInfoController extends BaseController{
|
||
|
||
@Autowired
|
||
private TaskInfoService taskInfoService;
|
||
|
||
/**
|
||
*来函列表
|
||
*/
|
||
@RequestMapping(value = {"list",""})
|
||
public String list(TaskInfo taskInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
|
||
Page<TaskInfo> page = taskInfoService.findTaskInfo(new Page<TaskInfo>(request, response,"r"), taskInfo);
|
||
model.addAttribute("page", page);
|
||
return "/basics/taskInfoList";
|
||
}
|
||
/**
|
||
* 进入用户添加或修改页面
|
||
*/
|
||
@RequestMapping(value={"form"})
|
||
public String form(TaskInfo taskInfo, Model model) {
|
||
if(taskInfo.getId()!=null){
|
||
Integer functionId=taskInfo.getFunctionId();
|
||
taskInfo = taskInfoService.getTaskInfoById(taskInfo.getId());
|
||
taskInfo.setFunctionId(functionId);
|
||
model.addAttribute("taskInfo", taskInfo);
|
||
}else{
|
||
model.addAttribute("taskInfo", taskInfo);
|
||
}
|
||
return "/basics/taskInfoForm";
|
||
}
|
||
|
||
/**
|
||
* 新增/修改
|
||
*/
|
||
@RequestMapping(value = "saveOrUpdate")
|
||
public String saveOrUpdate(TaskInfo taskInfo, HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) {
|
||
try {
|
||
if(taskInfo.getId()!=null){
|
||
// 保存用户信息
|
||
logger.info(taskInfo.getId()+"修改成功");
|
||
taskInfoService.saveOrUpdate(taskInfo);
|
||
addMessage(redirectAttributes,"success", "save_success");
|
||
}else{
|
||
if (!"true".equals(checkTaskName(taskInfo.getTaskName()))){
|
||
logger.info(taskInfo.getTaskName()+"重复数据");
|
||
Properties props=this.getMsgProp();
|
||
addMessage("error",model,props.getProperty("duplicate", "Duplicate")+" "+props.getProperty("task_name", "Task Name"));
|
||
return form(taskInfo, model);
|
||
}
|
||
// 保存用户信息
|
||
taskInfoService.saveOrUpdate(taskInfo);
|
||
addMessage(redirectAttributes,"success", "save_success");
|
||
logger.info(taskInfo.getId()+"保存成功");
|
||
}
|
||
} catch (Exception e) {
|
||
logger.error(e.getMessage());
|
||
e.printStackTrace();
|
||
addMessage(redirectAttributes,"error", "save_failed");
|
||
LogUtils.saveLog(request, null, e, null);
|
||
}
|
||
return "redirect:" + adminPath + "/basics/taskInfo/list?functionId="+taskInfo.getFunctionId()+"&repage";
|
||
}
|
||
|
||
/**
|
||
* 验证是否有效
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping(value = "checkTaskName")
|
||
public String checkTaskName(String taskName) {
|
||
if (taskName !=null && taskInfoService.getTaskInfoByTaskName(taskName) == null) {
|
||
return "true";
|
||
}
|
||
return "false";
|
||
}
|
||
|
||
/**
|
||
* 审核通过
|
||
* @param taskInfo
|
||
* @param model
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "taskExamine")
|
||
public String taskExamine(Integer functionId,String ids, Model model,RedirectAttributes redirectAttributes){
|
||
String[] exId = ids.split(",");
|
||
taskInfoService.taskExamine(exId);
|
||
addMessage(redirectAttributes,"success", "audit_success");
|
||
return "redirect:" + adminPath + "/basics/taskInfo/list?functionId="+functionId+"&repage";
|
||
|
||
}
|
||
/**
|
||
* 审核未通过
|
||
* @param taskInfo
|
||
* @param model
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "taskExamineNo")
|
||
public String taskExamineNo(Integer functionId,String ids, Model model,RedirectAttributes redirectAttributes){
|
||
String[] noId = ids.split(",");
|
||
taskInfoService.taskExamineNo(noId);
|
||
addMessage(redirectAttributes,"success", "audit_success");
|
||
return "redirect:" + adminPath + "/basics/taskInfo/list?functionId="+functionId+"&repage";
|
||
|
||
}
|
||
/**
|
||
* 取消审核
|
||
* @param taskInfo
|
||
* @param model
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "taskCancelExamine")
|
||
public String taskCancelExamine(Integer functionId,String ids, Model model,RedirectAttributes redirectAttributes){
|
||
String[] canclelId = ids.split(",");
|
||
taskInfoService.taskCancelExamine(canclelId);
|
||
addMessage(redirectAttributes,"success", "audit_success");
|
||
return "redirect:" + adminPath + "/basics/taskInfo/list?functionId="+functionId+"&repage";
|
||
|
||
}
|
||
/**
|
||
* 删除
|
||
* @param taskInfo
|
||
* @param model
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "delete")
|
||
public String delete(Integer functionId,String ids, Model model,RedirectAttributes redirectAttributes){
|
||
String[] delId = ids.split(",");
|
||
taskInfoService.delete(delId);
|
||
addMessage(redirectAttributes,"success", "delete_success");
|
||
return "redirect:" + adminPath + "/basics/taskInfo/list?functionId="+functionId+"&repage";
|
||
|
||
}
|
||
//配置导出
|
||
@RequestMapping(value = "exportTaskInfo")
|
||
public void exportTaskInfo(Model model,HttpServletRequest request,HttpServletResponse response,String hcolumn,String exType,
|
||
@ModelAttribute("cfg")TaskInfo entity,String ids,RedirectAttributes redirectAttributes){
|
||
try {
|
||
//export data info
|
||
List<String> titleList=new ArrayList<String>();
|
||
Map<String, Class<?>> classMap=new HashMap<String, Class<?>>();
|
||
Map<String, List> dataMap=new HashMap<String, List>();
|
||
Map<String, String> noExportMap=new HashMap<String, String>();
|
||
|
||
|
||
//导出选中记录
|
||
List<TaskInfo> list=Lists.newArrayList();
|
||
titleList.add(entity.getMenuNameCode());
|
||
classMap.put(entity.getMenuNameCode(), TaskInfo.class);
|
||
Field[] fields=TaskInfo.class.getDeclaredFields();
|
||
StringBuffer column=new StringBuffer();
|
||
Properties props= this.getMsgProp();
|
||
for(Field f: fields) {
|
||
ExcelField ex=f.getAnnotation(ExcelField.class);
|
||
if(ex!=null) {
|
||
String title=ex.title();
|
||
if(entity.getColumns().indexOf(props.getProperty(title, title))==-1) {
|
||
column.append(","+title);
|
||
}
|
||
}
|
||
}
|
||
if(column.toString().length()>0) {
|
||
column.append(",");
|
||
}
|
||
|
||
if(entity.getBeginDate()==null ){
|
||
hcolumn+=",task_time,";
|
||
}
|
||
if(entity.getDobeginDate()==null){
|
||
hcolumn+=",edit_time,";
|
||
}
|
||
|
||
if(!StringUtils.isEmpty(hcolumn)){
|
||
column.append(","+hcolumn+",");
|
||
}
|
||
|
||
noExportMap.put(entity.getMenuNameCode(),column.toString());
|
||
if(!StringUtil.isEmpty(ids)){
|
||
for(String id:ids.split(",")){
|
||
Long.parseLong(id);
|
||
}
|
||
list=taskInfoService.getTaskInfoByIds(ids);
|
||
}else{
|
||
//条件导出数据大于最大导出数,只导出最大导出条数
|
||
Page<TaskInfo> pageInfo=new Page<TaskInfo>(request, response,"a");
|
||
pageInfo.setPageNo(1);
|
||
pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE);
|
||
Page<TaskInfo> page = taskInfoService.findTaskInfo(pageInfo, entity);
|
||
list=page.getList();
|
||
}
|
||
dataMap.put(entity.getMenuNameCode(),list);
|
||
//获取国际化配置
|
||
String timeRange = initTaskMap(entity);
|
||
noExportMap.put("timeRange", timeRange);
|
||
if ("csv".equals(exType)) {
|
||
this._exportCsv(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
|
||
classMap, dataMap, noExportMap);
|
||
} else {
|
||
this._export(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
|
||
classMap, dataMap, noExportMap);
|
||
}
|
||
} catch (Exception e) {
|
||
logger.error("ip addr export failed",e);
|
||
addMessage(redirectAttributes,"error", "export_failed");
|
||
LogUtils.saveLog(request, null, e, null);
|
||
}
|
||
//return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+entity.getFunctionId();
|
||
}
|
||
public String initTaskMap(TaskInfo info){
|
||
Properties msgProp = getMsgProp();
|
||
String logTime=msgProp.getProperty(info.getMenuNameCode(),info.getMenuNameCode());
|
||
if(info.getBeginDate()!=null){
|
||
logTime+=" "+msgProp.getProperty("task_time","task_time")+":"+DateUtils.formatDateTime(info.getBeginDate());
|
||
if(info.getEndDate()!=null){
|
||
logTime+="—"+DateUtils.formatDateTime(info.getEndDate());
|
||
}else{
|
||
logTime+="—"+DateUtils.getDateTime();
|
||
}
|
||
}
|
||
if(info.getDobeginDate()!=null){
|
||
logTime+=" "+msgProp.getProperty("edit_time","edit_time")+":"+DateUtils.formatDateTime(info.getDobeginDate());
|
||
if(info.getDoendDate()!=null){
|
||
logTime+="—"+DateUtils.formatDateTime(info.getDoendDate());
|
||
}else{
|
||
logTime+="—"+DateUtils.getDateTime();
|
||
}
|
||
}
|
||
return logTime;
|
||
}
|
||
|
||
}
|