出现错误
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
### The error may exist in mappers/leave_form.xml
### The error may involve com.imooc.oa.dao.LeaveFormDao.selectByParams
### The error occurred while handling results
### SQL: select f.* ,e.name , d.* from adm_leave_form f,adm_process_flow pf , adm_employee e , adm_department d where f.form_id = pf.form_id and f.employee_id = e.employee_id and e.department_id = d.department_id and pf.state = ? and pf.operater_id = ?
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:153)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
at com.sun.proxy.$Proxy14.selectByParams(Unknown Source)
at com.imooc.oa.service.LeaveFormService.lambda$getLeaveFormList$1(LeaveFormService.java:114)
at com.imooc.oa.utils.MybatisUtils.executeQuery(MybatisUtils.java:26)
at com.imooc.oa.service.LeaveFormService.getLeaveFormList(LeaveFormService.java:112)
at com.imooc.oa.controller.LeaveFormServlet.getLeaveFormList(LeaveFormServlet.java:89)
at com.imooc.oa.controller.LeaveFormServlet.doPost(LeaveFormServlet.java:40)
at com.imooc.oa.controller.LeaveFormServlet.doGet(LeaveFormServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:616)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1629)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:87)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:561)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:403)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:355)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:329)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:302)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:195)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
... 37 more
Caused by: java.sql.SQLFeatureNotSupportedException
at com.alibaba.druid.pool.DruidPooledResultSet.getObject(DruidPooledResultSet.java:1771)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69)
at com.sun.proxy.$Proxy11.getObject(Unknown Source)
at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:38)
at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:28)
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85)
... 51 more
以下是相关代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.oa.dao.LeaveFormDao">
<insert id="insert" parameterType="com.imooc.oa.entity.LeaveForm"
useGeneratedKeys="true" keyProperty="formId" keyColumn="form_id">
INSERT INTO adm_leave_form (employee_id , form_type , start_time , end_time , reason , create_time , state )
VALUES (#{employeeId}, #{formType}, #{startTime}, #{endTime}, #{reason}, #{createTime} ,#{state})
</insert>
<select id="selectByParams" parameterType="java.util.Map" resultType="java.util.Map">
select f.* ,e.name , d.*
from
adm_leave_form f,adm_process_flow pf , adm_employee e , adm_department d
where
f.form_id = pf.form_id
and f.employee_id = e.employee_id
and e.department_id = d.department_id
and pf.state = #{pf_state} and pf.operater_id = #{pf_operater_id}
</select>
<select id="selectById" parameterType="Long" resultType="com.imooc.oa.entity.LeaveForm">
select * from adm_leave_form where form_id=#{value }
</select>
<update id="update" parameterType="com.imooc.oa.entity.LeaveForm">
UPDATE adm_leave_form SET employee_id = #{employeeId} , form_type = #{formType}, start_time = #{startTime}, end_time = #{endTime}, reason = #{reason}, state = #{state} ,create_time = #{createTime} WHERE form_id = #{formId}
</update>
</mapper>
package com.imooc.oa.service;
import com.imooc.oa.dao.EmployeeDao;
import com.imooc.oa.dao.LeaveFormDao;
import com.imooc.oa.dao.ProcessFlowDao;
import com.imooc.oa.entity.Employee;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.entity.ProcessFlow;
import com.imooc.oa.service.exception.BussinessException;
import com.imooc.oa.utils.MybatisUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 请假单流程服务
*/
public class LeaveFormService {
/**
* 创建请假单
* @param form 前端输入的请假单数据
* @return 持久化后的请假单对象
*/
public LeaveForm createLeaveForm(LeaveForm form) {
LeaveForm savedForm=(LeaveForm) MybatisUtils.executeUpdate(sqlSession -> {
//1.持久化form表单数据,8级以下表单状态为processing ,8级以上为approved
EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
Employee employee = employeeDao.selectById(form.getEmployeeId());
if (employee.getLevel() == 8) {
form.setState("approved");
}else{
form.setState("processing");
}
LeaveFormDao leaveFormDao = sqlSession.getMapper(LeaveFormDao.class);
leaveFormDao.insert(form);
//2.增加第一条流程数据,说明表单已提交,状态为complete
ProcessFlowDao processFlowDao = sqlSession.getMapper(ProcessFlowDao.class);
ProcessFlow flow1 = new ProcessFlow();
flow1.setFormId(form.getFormId());
flow1.setOperaterId(employee.getEmployeeId());
flow1.setAction("apply");
flow1.setCreateTime(new Date());
flow1.setOrderNo(1);
flow1.setState("complete");
flow1.setIsLast(0);
processFlowDao.insert(flow1);
//3.分情况创建其余流程数据
//3.1 7级以下员工,生成部门经理审批任务,请假时间大于36小时,还需生成总经理审批任务
if (employee.getLevel() < 7) {
Employee dmanager = employeeDao.selectLeader(employee);
ProcessFlow flow2 = new ProcessFlow();
flow2.setFormId(form.getFormId());
flow2.setOperaterId(dmanager.getEmployeeId());
flow2.setAction("audit");
flow2.setCreateTime(new Date());
flow2.setOrderNo(2);
flow2.setState("process");
long diff=form.getEndTime().getTime()-form.getStartTime().getTime();
float hours=diff / (1000 * 60 * 60) * 1f;
if (hours >= BussinessConstants.MANAGER_AUDIT_HOURS) {
flow2.setIsLast(0);
processFlowDao.insert(flow2);
Employee manager=employeeDao.selectLeader(dmanager);
ProcessFlow flow3 = new ProcessFlow();
flow3.setFormId(form.getFormId());
flow3.setOperaterId(manager.getEmployeeId());
flow3.setAction("audit");
flow3.setCreateTime(new Date());
flow3.setState("ready");
flow3.setOrderNo(3);
flow3.setIsLast(1);
processFlowDao.insert(flow3);
}else{
flow2.setIsLast(1);
processFlowDao.insert(flow2);
}
}else if(employee.getLevel()==7){
//3.2 7级员工,生成总经理审批任务
Employee manager = employeeDao.selectLeader(employee);
ProcessFlow flow = new ProcessFlow();
flow.setFormId(form.getFormId());
flow.setOperaterId(manager.getEmployeeId());
flow.setAction("audit");
flow.setCreateTime(new Date());
flow.setState("process");
flow.setOrderNo(2);
flow.setIsLast(1);
processFlowDao.insert(flow);
} else if (employee.getLevel() == 8) {
//3.3 8级员工,生成总经理审批任务,系统自动通过
ProcessFlow flow = new ProcessFlow();
flow.setFormId(form.getFormId());
flow.setOperaterId(employee.getEmployeeId());
flow.setAction("audit");
flow.setResult("approved");
flow.setReason("自动通过");
flow.setCreateTime(new Date());
flow.setAuditTime(new Date());
flow.setState("complete");
flow.setOrderNo(2);
flow.setIsLast(1);
processFlowDao.insert(flow);
}
return form;
});
return savedForm;
}
public List<Map> getLeaveFormList(String pfState, Long operaterId) {
return (List<Map>) MybatisUtils.executeQuery(sqlSession -> {
LeaveFormDao dao=sqlSession.getMapper(LeaveFormDao.class);
List<Map> formList=dao.selectByParams(pfState, operaterId);
return formList;
});
}
public void audit(Long formId, Long operaterId, String result, String reason) {
MybatisUtils.executeUpdate(sqlSession -> {
//1、无论同意/驳回,当前任务状态变更为complete
ProcessFlowDao processFlowDao = sqlSession.getMapper(ProcessFlowDao.class);
List<ProcessFlow> flowList = processFlowDao.selectByFormId(formId);
if (flowList.size() == 0) {
throw new BussinessException("PF001", "无效的审批流程");
}
//获取当前任务ProcessFlow对象
List<ProcessFlow> processList = flowList.stream().filter(p -> p.getOperaterId() == operaterId && p.getState().equals("process")).collect(Collectors.toList());
ProcessFlow process = null;
if (processList.size() == 0) {
throw new BussinessException("PF002", "未找到待处理任务");
}else {
process = processList.get(0);
process.setState("complete");
process.setResult(result);
process.setReason(reason);
process.setAuditTime(new Date());
processFlowDao.update(process);
}
//2、如果当前任务是最后一个节点,代表流程结束,更新请假单为对应的approved/refused
LeaveFormDao leaveFormDao = sqlSession.getMapper(LeaveFormDao.class);
LeaveForm form = leaveFormDao.selectById(formId);//得到对应的表单对象
if (process.getIsLast() == 1) {
form.setState(result);//result的值只有两个:approved或refused
leaveFormDao.update(form);
}else{
List<ProcessFlow> readyList = flowList.stream().filter(p -> p.getState().equals("ready")).collect(Collectors.toList());
// 3、如果当前任务不是最后一个节点且审批通过,那下一个节点的状态从ready变为process
if (result.equals("qpproved")) {
ProcessFlow readyProcess = readyList.get(0);
readyProcess.setState("process");
processFlowDao.update(readyProcess);
} else if (result.equals("refused")) {
//4、如果当前任务不是最后一个节点且审批驳回,那后续所有任务状态变为cancel,请假单状态变为refused
for (ProcessFlow p : readyList) {
p.setState("cancel");
processFlowDao.update(p);
}
form.setState("refused");
leaveFormDao.update(form);
}
}
return null;
});
}
}
package com.imooc.oa.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.Reader;
import java.util.function.Function;
public class MybatisUtils {
private static SqlSessionFactory sqlSessionFactory = null;
static {
Reader reader = null;
try{
reader = Resources.getResourceAsReader("mybatis-config.xml");
sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader);
}catch (IOException e){
throw new ExceptionInInitializerError(e);
}
}
public static Object executeQuery(Function<SqlSession,Object> func){
SqlSession sqlSession = sqlSessionFactory.openSession();
try{
Object obj=func.apply(sqlSession);
return obj;
}finally {
sqlSession.close();
}
}
public static Object executeUpdate(Function<SqlSession,Object> func) {
SqlSession sqlSession = sqlSessionFactory.openSession(false);
try {
Object obj = func.apply(sqlSession);
sqlSession.commit();
return obj;
} catch (RuntimeException e) {
sqlSession.rollback();
throw e;
} finally {
sqlSession.close();
}
}
}
package com.imooc.oa.service;
import com.imooc.oa.dao.EmployeeDao;
import com.imooc.oa.dao.LeaveFormDao;
import com.imooc.oa.dao.ProcessFlowDao;
import com.imooc.oa.entity.Employee;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.entity.ProcessFlow;
import com.imooc.oa.service.exception.BussinessException;
import com.imooc.oa.utils.MybatisUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 请假单流程服务
*/
public class LeaveFormService {
/**
* 创建请假单
* @param form 前端输入的请假单数据
* @return 持久化后的请假单对象
*/
public LeaveForm createLeaveForm(LeaveForm form) {
LeaveForm savedForm=(LeaveForm) MybatisUtils.executeUpdate(sqlSession -> {
//1.持久化form表单数据,8级以下表单状态为processing ,8级以上为approved
EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
Employee employee = employeeDao.selectById(form.getEmployeeId());
if (employee.getLevel() == 8) {
form.setState("approved");
}else{
form.setState("processing");
}
LeaveFormDao leaveFormDao = sqlSession.getMapper(LeaveFormDao.class);
leaveFormDao.insert(form);
//2.增加第一条流程数据,说明表单已提交,状态为complete
ProcessFlowDao processFlowDao = sqlSession.getMapper(ProcessFlowDao.class);
ProcessFlow flow1 = new ProcessFlow();
flow1.setFormId(form.getFormId());
flow1.setOperaterId(employee.getEmployeeId());
flow1.setAction("apply");
flow1.setCreateTime(new Date());
flow1.setOrderNo(1);
flow1.setState("complete");
flow1.setIsLast(0);
processFlowDao.insert(flow1);
//3.分情况创建其余流程数据
//3.1 7级以下员工,生成部门经理审批任务,请假时间大于36小时,还需生成总经理审批任务
if (employee.getLevel() < 7) {
Employee dmanager = employeeDao.selectLeader(employee);
ProcessFlow flow2 = new ProcessFlow();
flow2.setFormId(form.getFormId());
flow2.setOperaterId(dmanager.getEmployeeId());
flow2.setAction("audit");
flow2.setCreateTime(new Date());
flow2.setOrderNo(2);
flow2.setState("process");
long diff=form.getEndTime().getTime()-form.getStartTime().getTime();
float hours=diff / (1000 * 60 * 60) * 1f;
if (hours >= BussinessConstants.MANAGER_AUDIT_HOURS) {
flow2.setIsLast(0);
processFlowDao.insert(flow2);
Employee manager=employeeDao.selectLeader(dmanager);
ProcessFlow flow3 = new ProcessFlow();
flow3.setFormId(form.getFormId());
flow3.setOperaterId(manager.getEmployeeId());
flow3.setAction("audit");
flow3.setCreateTime(new Date());
flow3.setState("ready");
flow3.setOrderNo(3);
flow3.setIsLast(1);
processFlowDao.insert(flow3);
}else{
flow2.setIsLast(1);
processFlowDao.insert(flow2);
}
}else if(employee.getLevel()==7){
//3.2 7级员工,生成总经理审批任务
Employee manager = employeeDao.selectLeader(employee);
ProcessFlow flow = new ProcessFlow();
flow.setFormId(form.getFormId());
flow.setOperaterId(manager.getEmployeeId());
flow.setAction("audit");
flow.setCreateTime(new Date());
flow.setState("process");
flow.setOrderNo(2);
flow.setIsLast(1);
processFlowDao.insert(flow);
} else if (employee.getLevel() == 8) {
//3.3 8级员工,生成总经理审批任务,系统自动通过
ProcessFlow flow = new ProcessFlow();
flow.setFormId(form.getFormId());
flow.setOperaterId(employee.getEmployeeId());
flow.setAction("audit");
flow.setResult("approved");
flow.setReason("自动通过");
flow.setCreateTime(new Date());
flow.setAuditTime(new Date());
flow.setState("complete");
flow.setOrderNo(2);
flow.setIsLast(1);
processFlowDao.insert(flow);
}
return form;
});
return savedForm;
}
public List<Map> getLeaveFormList(String pfState, Long operaterId) {
return (List<Map>) MybatisUtils.executeQuery(sqlSession -> {
LeaveFormDao dao=sqlSession.getMapper(LeaveFormDao.class);
List<Map> formList=dao.selectByParams(pfState, operaterId);
return formList;
});
}
public void audit(Long formId, Long operaterId, String result, String reason) {
MybatisUtils.executeUpdate(sqlSession -> {
//1、无论同意/驳回,当前任务状态变更为complete
ProcessFlowDao processFlowDao = sqlSession.getMapper(ProcessFlowDao.class);
List<ProcessFlow> flowList = processFlowDao.selectByFormId(formId);
if (flowList.size() == 0) {
throw new BussinessException("PF001", "无效的审批流程");
}
//获取当前任务ProcessFlow对象
List<ProcessFlow> processList = flowList.stream().filter(p -> p.getOperaterId() == operaterId && p.getState().equals("process")).collect(Collectors.toList());
ProcessFlow process = null;
if (processList.size() == 0) {
throw new BussinessException("PF002", "未找到待处理任务");
}else {
process = processList.get(0);
process.setState("complete");
process.setResult(result);
process.setReason(reason);
process.setAuditTime(new Date());
processFlowDao.update(process);
}
//2、如果当前任务是最后一个节点,代表流程结束,更新请假单为对应的approved/refused
LeaveFormDao leaveFormDao = sqlSession.getMapper(LeaveFormDao.class);
LeaveForm form = leaveFormDao.selectById(formId);//得到对应的表单对象
if (process.getIsLast() == 1) {
form.setState(result);//result的值只有两个:approved或refused
leaveFormDao.update(form);
}else{
List<ProcessFlow> readyList = flowList.stream().filter(p -> p.getState().equals("ready")).collect(Collectors.toList());
// 3、如果当前任务不是最后一个节点且审批通过,那下一个节点的状态从ready变为process
if (result.equals("qpproved")) {
ProcessFlow readyProcess = readyList.get(0);
readyProcess.setState("process");
processFlowDao.update(readyProcess);
} else if (result.equals("refused")) {
//4、如果当前任务不是最后一个节点且审批驳回,那后续所有任务状态变为cancel,请假单状态变为refused
for (ProcessFlow p : readyList) {
p.setState("cancel");
processFlowDao.update(p);
}
form.setState("refused");
leaveFormDao.update(form);
}
}
return null;
});
}
}
package com.imooc.oa.controller;
import com.alibaba.fastjson.JSON;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.entity.User;
import com.imooc.oa.service.LeaveFormService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet(name = "LeaveFormServlet", value = "/leave/*")
public class LeaveFormServlet extends HttpServlet {
private LeaveFormService leaveFormService = new LeaveFormService();
private Logger logger = LoggerFactory.getLogger(LeaveFormServlet.class);
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//htttp://localhost/leave/create
String uri = request.getRequestURI();
String methodName = uri.substring(uri.lastIndexOf("/") + 1);
if (methodName.equals("create")) {
this.create(request, response);
} else if (methodName.equals("list")) {
this.getLeaveFormList(request, response);
} else if (methodName.equals("audit")) {
this.audit(request, response);
}
}
private void create(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.接收各项请假单数据
HttpSession session = request.getSession();
User user=(User) session.getAttribute("login_user");
String formType = request.getParameter("formType");
String strStartTime = request.getParameter("startTime");
String strEndTime = request.getParameter("endTime");
String reason = request.getParameter("reason");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
Map result = new HashMap();
try {
LeaveForm form = new LeaveForm();
form.setEmployeeId(user.getEmployeeId());
form.setStartTime(sdf.parse(strStartTime));
form.setEndTime(sdf.parse(strEndTime));
form.setFormType(Integer.parseInt(formType));
form.setReason(reason);
form.setCreateTime(new Date());
//2.调用业务逻辑方法
leaveFormService.createLeaveForm(form);
result.put("code", "0");
result.put("message", "success");
} catch (Exception e) {
e.printStackTrace();
logger.error("请假申请异常", e);
result.put("code", e.getClass().getSimpleName());
result.put("message", e.getMessage());
}
//3、组织响应数据
String json = JSON.toJSONString(result);
response.getWriter().println(json);
}
/**
* 查询须要审核的请假单列表
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void getLeaveFormList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User user = (User) request.getSession().getAttribute("login_user");
List<Map> formList = leaveFormService.getLeaveFormList("process", user.getEmployeeId());
Map result = new HashMap();
result.put("code", "0");
result.put("msg", "");
result.put("count", formList.size());
result.put("data", formList);
String json=JSON.toJSONString(result);
response.getWriter().println(json);
}
/**
* 处理审批操作
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void audit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String formId = request.getParameter("formId");
String result = request.getParameter("result");
String reason = request.getParameter("reason");
User user=(User)request.getSession().getAttribute("login_user");
Map mpResult = new HashMap();
try {
leaveFormService.audit(Long.parseLong(formId), user.getEmployeeId(), result, reason);
mpResult.put("code", "0");
mpResult.put("message", "success");
} catch (Exception e) {
logger.error("请假单审核失败", e);
mpResult.put("code", e.getClass().getSimpleName());
mpResult.put("message", e.getMessage());
}
String json = JSON.toJSONString(mpResult);
response.getWriter().println(json);
}
}
package com.imooc.oa.controller;
import com.alibaba.fastjson.JSON;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.entity.User;
import com.imooc.oa.service.LeaveFormService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet(name = "LeaveFormServlet", value = "/leave/*")
public class LeaveFormServlet extends HttpServlet {
private LeaveFormService leaveFormService = new LeaveFormService();
private Logger logger = LoggerFactory.getLogger(LeaveFormServlet.class);
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//htttp://localhost/leave/create
String uri = request.getRequestURI();
String methodName = uri.substring(uri.lastIndexOf("/") + 1);
if (methodName.equals("create")) {
this.create(request, response);
} else if (methodName.equals("list")) {
this.getLeaveFormList(request, response);
} else if (methodName.equals("audit")) {
this.audit(request, response);
}
}
private void create(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.接收各项请假单数据
HttpSession session = request.getSession();
User user=(User) session.getAttribute("login_user");
String formType = request.getParameter("formType");
String strStartTime = request.getParameter("startTime");
String strEndTime = request.getParameter("endTime");
String reason = request.getParameter("reason");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
Map result = new HashMap();
try {
LeaveForm form = new LeaveForm();
form.setEmployeeId(user.getEmployeeId());
form.setStartTime(sdf.parse(strStartTime));
form.setEndTime(sdf.parse(strEndTime));
form.setFormType(Integer.parseInt(formType));
form.setReason(reason);
form.setCreateTime(new Date());
//2.调用业务逻辑方法
leaveFormService.createLeaveForm(form);
result.put("code", "0");
result.put("message", "success");
} catch (Exception e) {
e.printStackTrace();
logger.error("请假申请异常", e);
result.put("code", e.getClass().getSimpleName());
result.put("message", e.getMessage());
}
//3、组织响应数据
String json = JSON.toJSONString(result);
response.getWriter().println(json);
}
/**
* 查询须要审核的请假单列表
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void getLeaveFormList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User user = (User) request.getSession().getAttribute("login_user");
List<Map> formList = leaveFormService.getLeaveFormList("process", user.getEmployeeId());
Map result = new HashMap();
result.put("code", "0");
result.put("msg", "");
result.put("count", formList.size());
result.put("data", formList);
String json=JSON.toJSONString(result);
response.getWriter().println(json);
}
/**
* 处理审批操作
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void audit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String formId = request.getParameter("formId");
String result = request.getParameter("result");
String reason = request.getParameter("reason");
User user=(User)request.getSession().getAttribute("login_user");
Map mpResult = new HashMap();
try {
leaveFormService.audit(Long.parseLong(formId), user.getEmployeeId(), result, reason);
mpResult.put("code", "0");
mpResult.put("message", "success");
} catch (Exception e) {
logger.error("请假单审核失败", e);
mpResult.put("code", e.getClass().getSimpleName());
mpResult.put("message", e.getMessage());
}
String json = JSON.toJSONString(mpResult);
response.getWriter().println(json);
}
}
package com.imooc.oa.controller;
import com.alibaba.fastjson.JSON;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.entity.User;
import com.imooc.oa.service.LeaveFormService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet(name = "LeaveFormServlet", value = "/leave/*")
public class LeaveFormServlet extends HttpServlet {
private LeaveFormService leaveFormService = new LeaveFormService();
private Logger logger = LoggerFactory.getLogger(LeaveFormServlet.class);
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//htttp://localhost/leave/create
String uri = request.getRequestURI();
String methodName = uri.substring(uri.lastIndexOf("/") + 1);
if (methodName.equals("create")) {
this.create(request, response);
} else if (methodName.equals("list")) {
this.getLeaveFormList(request, response);
} else if (methodName.equals("audit")) {
this.audit(request, response);
}
}
private void create(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.接收各项请假单数据
HttpSession session = request.getSession();
User user=(User) session.getAttribute("login_user");
String formType = request.getParameter("formType");
String strStartTime = request.getParameter("startTime");
String strEndTime = request.getParameter("endTime");
String reason = request.getParameter("reason");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
Map result = new HashMap();
try {
LeaveForm form = new LeaveForm();
form.setEmployeeId(user.getEmployeeId());
form.setStartTime(sdf.parse(strStartTime));
form.setEndTime(sdf.parse(strEndTime));
form.setFormType(Integer.parseInt(formType));
form.setReason(reason);
form.setCreateTime(new Date());
//2.调用业务逻辑方法
leaveFormService.createLeaveForm(form);
result.put("code", "0");
result.put("message", "success");
} catch (Exception e) {
e.printStackTrace();
logger.error("请假申请异常", e);
result.put("code", e.getClass().getSimpleName());
result.put("message", e.getMessage());
}
//3、组织响应数据
String json = JSON.toJSONString(result);
response.getWriter().println(json);
}
/**
* 查询须要审核的请假单列表
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void getLeaveFormList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User user = (User) request.getSession().getAttribute("login_user");
List<Map> formList = leaveFormService.getLeaveFormList("process", user.getEmployeeId());
Map result = new HashMap();
result.put("code", "0");
result.put("msg", "");
result.put("count", formList.size());
result.put("data", formList);
String json=JSON.toJSONString(result);
response.getWriter().println(json);
}
/**
* 处理审批操作
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void audit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String formId = request.getParameter("formId");
String result = request.getParameter("result");
String reason = request.getParameter("reason");
User user=(User)request.getSession().getAttribute("login_user");
Map mpResult = new HashMap();
try {
leaveFormService.audit(Long.parseLong(formId), user.getEmployeeId(), result, reason);
mpResult.put("code", "0");
mpResult.put("message", "success");
} catch (Exception e) {
logger.error("请假单审核失败", e);
mpResult.put("code", e.getClass().getSimpleName());
mpResult.put("message", e.getMessage());
}
String json = JSON.toJSONString(mpResult);
response.getWriter().println(json);
}
}
请问是哪里出现问题了呢?
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星