package com.zky.zhyw.smsb ;
import java.io.IOException ;
import java.io.UnsupportedEncodingException ;
import java.net.URLEncoder ;
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.SQLException ;
import javax.servlet.ServletException ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import oracle.jdbc.dbaccess.DBAccess ;
import sun.nio.cs.ext.GB18030 ;
import com.sun.org.apache.bcel.internal.generic.NEW ;
import com.zky.manager.Login ;
import com.zky.manager.StudentPullulate ;
import com.zky.pub.Common ;
import com.zky.pub.DbConn ;
import com.zky.pub.DispatchServlet ;
import com.zky.pub.HashFmlBuf ;
import com.zky.util.PageQuery ;
import com.zky.util.jdbc.HashFmlBufResultSetHandler ;
import com.zky.util.jdbc.JDBCUtils ;
public class PropertyMaintainManageServlet extends DispatchServlet {
Connection conn ;
PreparedStatement pstmt , pstmt1 ;
StudentPullulate p = new StudentPullulate ( ) ;
@Override
public void defaultMethod ( HttpServletRequest request ,
HttpServletResponse response ) throws Exception {
}
/ * *
* 转 至 添 加 资 产 维 修 信 息 页 面
* @throws SQLException
* /
public void PropertyMaintainAdd ( HttpServletRequest request , HttpServletResponse response ) throws SQLException
{
String useId = request . getParameter ( "useId" ) ;
String deptSql = "select d.departid,d.departname from tab_department d left join tm_dtl_property_use u on d.departid=u.use_departid where u.use_id=?" ;
String sql = new String ( "select r.recover_id,r.use_id,r.recover_cause,r.recover_departid,r.recover_staffid,r.recover_date,m.maintain_id," +
"m.give_departid,m.give_staffid,m.give_date,o.maintain_state,o.hold_departid,o.hold_staffid,o.hold_date,u.property_name,d.departname,e.empname from tm_dtl_property_recover r left join tm_dtl_property_maintain m " +
"on r.use_id=m.use_id left join tr_property_operate o on r.use_id=o.use_id left join tm_dtl_property_use u on r.use_id=u.use_id left join tab_department d on m.give_departid=d.departid left join tab_employee e on m.give_staffid=e.empid" +
" where r.use_id=?" ) ;
try {
conn = DbConn . getConn ( ) ;
HashFmlBuf maintainBuf = ( HashFmlBuf ) JDBCUtils . query ( conn , sql , new Object [ ] { useId } , new HashFmlBufResultSetHandler ( ) ) ;
HashFmlBuf departBuf = ( HashFmlBuf ) JDBCUtils . query ( conn , deptSql , new Object [ ] { useId } , new HashFmlBufResultSetHandler ( ) ) ;
request . setAttribute ( "writeDepartment" , departBuf ) ;
request . setAttribute ( "maintainBuf" , maintainBuf ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainAdd.jsp" ) . forward ( request , response ) ;
} catch ( Exception e ) {
// TODO: handle exception
e . printStackTrace ( ) ;
}
finally
{
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
/ * *
* 添 加 资 产 维 护 记 录
* @param request
* @param response
* @throws SQLException
* @throws IOException
* @throws UnsupportedEncodingException
* /
public void addPropertyMaintain ( HttpServletRequest request , HttpServletResponse response ) throws SQLException , UnsupportedEncodingException , IOException , NumberFormatException
{
String Id = request . getParameter ( "Id" ) ;
String MaintainDepart = request . getParameter ( "MaintainDepart" ) ;
String MaintainStaff = request . getParameter ( "MaintainStaff" ) ;
String Waiter = request . getParameter ( "Waiter" ) ;
String remark = request . getParameter ( "remark" ) ;
String sql = "update tm_dtl_property_info e set e.MAINTAIN_STATE='1',e.WAITER=?,e.REMARK=?,e.MAINTAIN_DATE=now(),e.MAINTAIN_DEPARTID=?,e.MAINTAIN_STAFFID=? where e.id=?" ;
PreparedStatement pstmt = null ;
try {
conn = DbConn . getConn ( ) ;
pstmt = conn . prepareStatement ( sql ) ;
pstmt . setString ( 1 , Waiter ) ;
pstmt . setString ( 2 , remark ) ;
pstmt . setString ( 3 , MaintainDepart ) ;
pstmt . setString ( 4 , MaintainStaff ) ;
pstmt . setString ( 5 , Id ) ;
pstmt . execute ( ) ;
conn . commit ( ) ;
queryPropertyMaintainPage ( request , response ) ;
} catch ( Exception e ) {
String errorinfo = "" ;
if ( e . getMessage ( ) . startsWith ( "ORA-00001" ) ) {
errorinfo = "资产维修失败,相关流水号已经存在!" ;
} else {
errorinfo = "资产维修失败!" + e . toString ( ) ;
}
response . sendRedirect ( Common . GbConvertIso ( "/error.jsp?errorinfo=" + Common . toGb ( errorinfo ) ) ) ;
e . printStackTrace ( ) ;
e . printStackTrace ( ) ;
}
finally
{
if ( pstmt ! = null )
{
pstmt . close ( ) ;
}
if ( pstmt1 ! = null )
{
pstmt1 . close ( ) ;
}
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
//根据部门查询员工
public void readEmployeeByDepartmentManage ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
Login login = ( Login ) request . getSession ( ) . getAttribute ( "login" ) ;
String areaId = request . getParameter ( "areaid" ) ; //获取区县id
String schoolId = request . getParameter ( "schoolid" ) ; //获取部门id
request . setAttribute ( "areaid" , areaId ) ;
request . setAttribute ( "schoolid" , schoolId ) ;
HashFmlBuf bufschool = p . readSchoolByAreaId ( areaId , login ) ;
request . setAttribute ( "writeDepartment" , bufschool ) ;
HashFmlBuf bufEmployee = p . readEmployees ( request , response ) ;
request . setAttribute ( "bufEmployee" , bufEmployee ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainManage.jsp" ) . forward ( request , response ) ;
}
/ * *
* 查 询 最 新 操 作 的 资 产 维 护 记 录 信 息
* @param request
* @param response
* @throws SQLException
* /
public void queryPropertyMaintain ( HttpServletRequest request , HttpServletResponse response ) throws SQLException
{
Login login = ( Login ) request . getSession ( ) . getAttribute ( "login" ) ;
String useId = request . getParameter ( "useId" ) ;
String school = request . getParameter ( "school" ) ;
String qj = request . getParameter ( "qj" ) ;
String sj = request . getParameter ( "sj" ) ;
StringBuffer querySql = new StringBuffer ( "select u.framework_id,u.area_id,u.use_staffid,u.use_departid,u.use_id,e.empname,t.departname,date_format(u.use_date,'%Y-%m-%d') as use_date," +
"u.recover_staffid,date_format(u.recover_date,'%Y-%m-%d') as recover_date from tm_dtl_property_use u left join tab_department t " +
"ON t.departid=u.recover_departid left join tab_employee e " +
"on u.use_staffid=e.empid where 1=1 " ) ;
if ( ! Common . isNull ( useId ) )
{
querySql . append ( " and u.use_id='" ) . append ( useId ) . append ( "'" ) ;
}
if ( ! Common . isNull ( school ) )
{
querySql . append ( " and u.use_departid='" ) . append ( school ) . append ( "'" ) ;
}
if ( ! Common . isNull ( sj ) )
{
querySql . append ( " and u.framework_id='" ) . append ( sj ) . append ( "'" ) ;
}
if ( ! Common . isNull ( qj ) )
{
querySql . append ( " and u.area_id='" ) . append ( qj ) . append ( "'" ) ;
}
try {
conn = DbConn . getConn ( ) ;
PageQuery pageQuery = new PageQuery ( conn , querySql . toString ( ) , new HashFmlBufResultSetHandler ( ) , request ) ;
HashFmlBuf useBuf = ( HashFmlBuf ) pageQuery . query ( 100 ) ;
request . setAttribute ( "useBuf" , useBuf ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainManage.jsp" ) . forward ( request , response ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally
{
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
/ * *
* 查 询 最 新 操 作 的 资 产 维 护 记 录 信 息
* @param request
* @param response
* @throws SQLException
* /
public void queryPropertyMaintainById ( HttpServletRequest request , HttpServletResponse response ) throws SQLException
{
Login login = ( Login ) request . getSession ( ) . getAttribute ( "login" ) ;
String useId = request . getParameter ( "useId" ) ;
String querySql = "select a.id,a.maintain_departid,a.maintain_staffid,a.maintain_num,b.maintain_state,b.recover_departid,b.recover_staffid,a.use_id,b.maintain_state,a.maintain_departid,a.maintain_staffid,b.use_departid,b.use_staffid," +
"date_format(b.maintain_date ,'%Y-%m-%d') as maintain_date,b.property_name,b.property_no,a.maintain_all,a.maintain_num FROM tm_dtl_property_main a LEFT JOIN tm_dtl_property_use b ON a.use_id=b.use_id " +
"where 1=1 and a.id=? " ;
try {
conn = DbConn . getConn ( ) ;
HashFmlBuf useBufById = ( HashFmlBuf ) JDBCUtils . query ( conn , querySql , new Object [ ] { useId } ,
new HashFmlBufResultSetHandler ( ) ) ;
request . setAttribute ( "useBufById" , useBufById ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainAdd.jsp" ) . forward ( request , response ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally
{
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
/ * *
* 查 询 最 新 操 作 的 资 产 维 护 记 录 信 息
* @param request
* @param response
* @throws SQLException
* /
public void queryPropertyMaintainById1 ( HttpServletRequest request , HttpServletResponse response ) throws SQLException
{
Login login = ( Login ) request . getSession ( ) . getAttribute ( "login" ) ;
String querySql = "select u.use_id,u.property_name,u.property_no," +
"e.empname,u.AREA_ID,u.USE_DEPARTID,u.USE_STAFFID,u.RECOVER_DEPARTID,u.RECOVER_STAFFID,u.MAINTAIN_STATE,u.MAINTAIN_DEPARTID,u.MAINTAIN_STAFFID,date_format(u.MAINTAIN_DATE,'%Y-%m-%d') as MAINTAIN_DATE,date_format(u.use_date,'%Y-%m-%d') as use_date," +
"u.property_num from tm_dtl_property_use u" +
" left join tab_department t ON t.departid=u.MAINTAIN_DEPARTID" +
" left join tab_employee e on u.MAINTAIN_STAFFID=e.empid " +
"where 1=1 and u.destory_state='0' " ;
String sql = "SELECT a.indenture_name,a.indenture_linkman FROM td_indenture a" ;
try {
conn = DbConn . getConn ( ) ;
HashFmlBuf useBufById = ( HashFmlBuf ) JDBCUtils . query ( conn , querySql , new HashFmlBufResultSetHandler ( ) ) ;
request . setAttribute ( "useBufById" , useBufById ) ;
PageQuery Query = new PageQuery ( conn , sql . toString ( ) , new HashFmlBufResultSetHandler ( ) , request ) ;
HashFmlBuf ById = ( HashFmlBuf ) Query . query ( 100 ) ;
request . setAttribute ( "ById" , ById ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/extractProperty.jsp" ) . forward ( request , response ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally
{
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
/ * *
* 资 产 维 修
* @param request
* @param response
* @throws SQLException
* /
public void MaintainPropertyId ( HttpServletRequest request , HttpServletResponse response ) throws IOException {
Login login = ( Login ) request . getSession ( ) . getAttribute ( "login" ) ;
String useId = request . getParameter ( "id" ) ;
String sql = "update tm_dtl_property_main e set e.MAINTAIN_STATE='1',e.MAINTAIN_DATE=now() where e.id=?" ;
PreparedStatement pstmt = null ;
Connection conn = null ;
try {
conn = DbConn . getConn ( ) ;
pstmt = conn . prepareStatement ( sql ) ;
pstmt . setString ( 1 , useId ) ;
pstmt . execute ( ) ;
conn . commit ( ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainManage.jsp?operate=queryPropertyMaintain" ) . forward ( request , response ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
response . sendRedirect ( Common . GbConvertIso ( "/error.jsp?errorinfo=" + URLEncoder . encode ( "接收文件失败!" , "GB2312" ) + e . toString ( ) ) ) ;
} finally {
try {
if ( conn ! = null ) {
conn . close ( ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
}
/ * *
* 查 询 资 产 销 毁 分 页 信 息
* @param request
* @param response
* @throws SQLException
* /
public void queryPropertyMaintainPage ( HttpServletRequest request , HttpServletResponse response ) throws SQLException
{
Login login = ( Login ) request . getSession ( ) . getAttribute ( "login" ) ;
String areaId = request . getParameter ( "areaid" ) ;
String departId = request . getParameter ( "schoolid" ) ;
String employeeId = request . getParameter ( "writeempid" ) ;
String fileSecret = request . getParameter ( "filesecret" ) ;
String fileState = request . getParameter ( "filestate" ) ;
HashFmlBuf bufschool = p . readSchoolByAreaId ( areaId , login ) ;
HashFmlBuf holdDeptBuf = p . readSchoolByAreaId ( areaId , login ) ;
HashFmlBuf manageDeptBuf = p . readSchoolByAreaId ( areaId , login ) ;
request . setAttribute ( "writeDepartment" , bufschool ) ;
request . setAttribute ( "holdDeptBuf" , holdDeptBuf ) ;
request . setAttribute ( "manageDeptBuf" , manageDeptBuf ) ;
HashFmlBuf bufEmployee = p . readEmployees ( request , response ) ;
HashFmlBuf holdEmpBuf = p . readEmployees ( request , response ) ;
HashFmlBuf manageEmpBuf = p . readEmployees ( request , response ) ;
request . setAttribute ( "bufEmployee" , bufEmployee ) ;
request . setAttribute ( "holdEmpBuf" , holdEmpBuf ) ;
request . setAttribute ( "manageEmpBuf" , manageEmpBuf ) ;
String maintainId = request . getParameter ( "maintainId" ) ;
String giveDepartId = request . getParameter ( "giveDepartId" ) ;
String giveStaffId = request . getParameter ( "giveStaffId" ) ;
String indentureId = request . getParameter ( "indentureId" ) ;
String maintainState = request . getParameter ( "maintainState" ) ;
StringBuffer sql = new StringBuffer ( "select o.use_id,o.maintain_state,o.recover_state,m.maintain_id,m.indenture_id,m.give_departid,m.give_staffid," +
"m.give_date,u.property_name,d.departname,e.empname from tr_property_operate o left join tm_dtl_property_use u on o.use_id=u.use_id " +
"left join tm_dtl_property_maintain m on o.use_id=m.use_id left join tab_department d on m.give_departid=d.departId left join tab_employee e on m.give_staffid=e.empid where 1=1" +
"and o.recover_type='1'" ) ;
if ( ! Common . isNull ( maintainId ) )
{
sql . append ( " and m.use_id='" ) . append ( maintainId ) . append ( "'" ) ;
}
if ( ! Common . isNull ( giveDepartId ) )
{
sql . append ( " and m.give_departid='" ) . append ( departId ) . append ( "'" ) ;
}
if ( ! Common . isNull ( giveStaffId ) )
{
sql . append ( " and m.give_staffid='" ) . append ( employeeId ) . append ( "'" ) ;
}
if ( ! Common . isNull ( maintainState ) )
{
sql . append ( "and o.maintain_state='" ) . append ( maintainState ) . append ( "'" ) ;
}
try
{
conn = DbConn . getConn ( ) ;
PageQuery pageQuery = new PageQuery ( conn , sql . toString ( ) , new HashFmlBufResultSetHandler ( ) , request ) ;
HashFmlBuf maintainBuf = ( HashFmlBuf ) pageQuery . query ( 100 ) ;
request . setAttribute ( "maintainBuf" , maintainBuf ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainManage.jsp" ) . forward ( request , response ) ;
}
catch ( Exception e ) {
// TODO: handle exception
e . printStackTrace ( ) ;
}
finally
{
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
/ * *
* 显 示 资 产 维 护 明 细 信 息
* @param request
* @param response
* @throws SQLException
* /
public void queryPropertyById ( HttpServletRequest request , HttpServletResponse response ) throws IOException {
String Id = request . getParameter ( "Id" ) ;
String sql = "select * from tm_dtl_property_info a left join tm_dtl_property_use b on a.use_id=b.use_id where a.id=?" ;
Connection conn = null ;
try {
conn = DbConn . getConn ( ) ;
HashFmlBuf buf = ( HashFmlBuf ) JDBCUtils . query ( conn , sql , new Object [ ] { Id } ,
new HashFmlBufResultSetHandler ( ) ) ;
request . setAttribute ( "by_PropertyBy" , buf ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainAdd.jsp" ) . forward ( request , response ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
response . sendRedirect ( Common . GbConvertIso ( "/error.jsp?errorinfo=" + URLEncoder . encode ( "根据编号查询资产记录失败!" , "GB2312" ) + e . toString ( ) ) ) ;
} finally {
try {
if ( conn ! = null ) {
conn . close ( ) ;
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
}
public void showPropertyDetail ( HttpServletRequest request , HttpServletResponse response ) throws SQLException
{
String useId = request . getParameter ( "useId" ) ;
StringBuffer sql1 = new StringBuffer ( "select a.id,a.use_id,a.property_brand,a.property_mac,a.property_imei,a.property_type,a.property_no,a.property_name,a.property_soff,a.property_soffwe,a.property_sn,a.maintain_departid,a.maintain_staffid,a.maintain_date,a.maintain_state,a.waiter from tm_dtl_property_info a where a.use_id=? and a.destory_state='0' " ) ;
try {
conn = DbConn . getConn ( ) ;
HashFmlBuf useInfo = ( HashFmlBuf ) JDBCUtils . query ( conn , sql1 . toString ( ) , new Object [ ] { useId } , new HashFmlBufResultSetHandler ( ) ) ;
request . setAttribute ( "useInfo" , useInfo ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/extractProperty.jsp" ) . forward ( request , response ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally
{
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
public void extractMaintainProperty ( HttpServletRequest request , HttpServletResponse response ) throws SQLException , ServletException , IOException
{
String useId = request . getParameter ( "useId" ) ;
String maintainId = request . getParameter ( "maintainId" ) ;
String deptId = request . getParameter ( "deptId" ) ;
String empId = request . getParameter ( "empId" ) ;
String updateSql = "update tr_property_operate set provide_state='2',receive_state='0',recover_state='0',maintain_state='2',extract_state='1',hold_departid=?,hold_staffid=?,hold_date=now() where use_id=?" ;
String sql = "select m.maintain_id,m.indenture_id,m.use_id,m.give_departid,m.give_staffid," +
"m.give_date,i.indenture_name,u.property_name,d.departname,e.empname,o.operate_id,o.maintain_state" +
" from tm_dtl_property_maintain m left join tr_property_operate o on m.use_id=o.use_id left join td_indenture i on m.indenture_id=i.indenture_id left join tm_dtl_property_use u " +
"on m.use_id=u.use_id left join tab_department d on o.hold_departid=d.departId left join tab_employee e on o.hold_staffid=e.empid" +
" where m.maintain_id=?" ;
try {
conn = DbConn . getConn ( ) ;
HashFmlBuf maintainBuf = ( HashFmlBuf ) JDBCUtils . query ( conn , sql , new Object [ ] { useId } , new HashFmlBufResultSetHandler ( ) ) ;
pstmt = conn . prepareStatement ( updateSql ) ;
pstmt . setString ( 1 , deptId ) ;
pstmt . setString ( 2 , empId ) ;
pstmt . setString ( 3 , useId ) ;
pstmt . execute ( ) ;
conn . commit ( ) ;
request . setAttribute ( "maintainBuf" , maintainBuf ) ;
request . getRequestDispatcher ( "/zhyw/smsb/sbwx/propertyMaintainManage.jsp" ) . forward ( request , response ) ;
queryPropertyMaintain ( request , response ) ;
} catch ( Exception e ) {
// TODO: handle exception
e . printStackTrace ( ) ;
String errorinfo = "" ;
if ( e . getMessage ( ) . startsWith ( "ORA-00001" ) ) {
errorinfo = "资产取回失败,相关流水号已经存在!" ;
} else {
errorinfo = "资产取回失败!" + e . toString ( ) ;
}
response . sendRedirect ( Common . GbConvertIso ( "/error.jsp?errorinfo=" + Common . toGb ( errorinfo ) ) ) ;
e . printStackTrace ( ) ;
}
finally
{
if ( pstmt ! = null )
{
pstmt . close ( ) ;
}
if ( conn ! = null )
{
conn . close ( ) ;
}
}
}
}