package com.semor.workorder.services;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.semor.workorder.dao.implDao.WorkOrderDao;
import com.semor.workorder.dbhelper.ConnectionManager;
import com.semor.workorder.models.CustomerInfoModel;
import com.semor.workorder.models.EmployeeModel;
import com.semor.workorder.models.InstallTypeModel;
import com.semor.workorder.models.PackageModel;
import com.semor.workorder.models.WorkOrderModel;
/**
* 表单业务处理
*
* @author Administrator
*
*/
public class WorkOrderService {
private WorkOrderDao wod = new WorkOrderDao();
/**
* 执行插入操作
*
* @param wom
* @return
*/
public int exeInsert(WorkOrderModel wom) {
Connection con = null;
try {
con = ConnectionManager.getConnection();
return this.wod.add(wom, con);
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return -1;
}
/**
* 获取总记录数
*
* @return
*/
public int getTotalCount() {
Connection con = null;
try {
con = ConnectionManager.getConnection();
Object obj = this.wod.findByCondition(null, 2, con);
if (obj != null) {
return (int) obj;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return -1;
}
/**
* 分页获取数据
*
* @param startPage
* @param count
* @return
*/
public List<WorkOrderModel> findByPage(int startPage, int count) {
Connection con = null;
int[] obj = { startPage, count };
try {
con = ConnectionManager.getConnection();
Object o = this.wod.findByCondition(obj, 1, con);
if (o != null) {
@SuppressWarnings("unchecked")
List<WorkOrderModel> list = (List<WorkOrderModel>) o;
if (list != null && list.size() > 0) {
for (WorkOrderModel em : list) {
if (em != null) {
em.setCim(new CustomerInfoService().findById(new CustomerInfoModel(em.getWorCustomerId())));
em.setEm(new EmployeeService().findById(new EmployeeModel(em.getWorAddUserId())));
em.setItm(
new InstallTypeService().findById(new InstallTypeModel(em.getWorInstallTypeId())));
em.setPm(new PackageService().findById(new PackageModel(em.getWorPackageId())));
}
}
}
return list;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return null;
}
/**
* 查找自己的工单
*
* @param startPage
* @param count
* @param id
* @return
*/
public List<WorkOrderModel> findSelfByPage(int startPage, int count, int id) {
Connection con = null;
int[] obj = { startPage, count, id };
try {
con = ConnectionManager.getConnection();
Object o = this.wod.findByCondition(obj, 4, con);
if (o != null) {
@SuppressWarnings("unchecked")
List<WorkOrderModel> list = (List<WorkOrderModel>) o;
if (list != null && list.size() > 0) {
for (WorkOrderModel em : list) {
if (em != null) {
em.setCim(new CustomerInfoService().findById(new CustomerInfoModel(em.getWorCustomerId())));
em.setEm(new EmployeeService().findById(new EmployeeModel(em.getWorAddUserId())));
em.setItm(
new InstallTypeService().findById(new InstallTypeModel(em.getWorInstallTypeId())));
em.setPm(new PackageService().findById(new PackageModel(em.getWorPackageId())));
}
}
}
return list;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return null;
}
/**
* 获取自己表单总量
*
* @param id
* @return
*/
public int getTotalCount(int id) {
Connection con = null;
try {
con = ConnectionManager.getConnection();
Object obj = this.wod.findByCondition(id, 5, con);
if (obj != null) {
return (int) obj;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return -1;
}
/**
* 显示待销户工单数量
*
* @return
*/
public int getWaitDeleteTotalCount() {
Connection con = null;
try {
con = ConnectionManager.getConnection();
Object obj = this.wod.findByCondition(null, 6, con);
if (obj != null) {
return (int) obj;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return -1;
}
/**
* 显示待销户工单
*
* @param startPage
* @param count
* @return
*/
public List<WorkOrderModel> findWaitDeleteByPage(int startPage, int count) {
Connection con = null;
int[] obj = { startPage, count };
try {
con = ConnectionManager.getConnection();
Object o = this.wod.findByCondition(obj, 7, con);
if (o != null) {
@SuppressWarnings("unchecked")
List<WorkOrderModel> list = (List<WorkOrderModel>) o;
if (list != null && list.size() > 0) {
for (WorkOrderModel em : list) {
if (em != null) {
em.setCim(new CustomerInfoService().findById(new CustomerInfoModel(em.getWorCustomerId())));
em.setEm(new EmployeeService().findById(new EmployeeModel(em.getWorAddUserId())));
em.setItm(
new InstallTypeService().findById(new InstallTypeModel(em.getWorInstallTypeId())));
em.setPm(new PackageService().findById(new PackageModel(em.getWorPackageId())));
}
}
}
return list;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return null;
}
/**
* 显示待安装工单
*
* @return
*/
public int getWaitInstallTotalCount() {
Connection con = null;
try {
con = ConnectionManager.getConnection();
Object obj = this.wod.findByCondition(null, 8, con);
if (obj != null) {
return (int) obj;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return -1;
}
/**
* 查找待安装工单
*
* @param startPage
* @param count
* @return
*/
public List<WorkOrderModel> findWaitInstallByPage(int startPage, int count) {
Connection con = null;
int[] obj = { startPage, count };
try {
con = ConnectionManager.getConnection();
Object o = this.wod.findByCondition(obj, 9, con);
if (o != null) {
@SuppressWarnings("unchecked")
List<WorkOrderModel> list = (List<WorkOrderModel>) o;
if (list != null && list.size() > 0) {
for (WorkOrderModel em : list) {
if (em != null) {
em.setCim(new CustomerInfoService().findById(new CustomerInfoModel(em.getWorCustomerId())));
em.setEm(new EmployeeService().findById(new EmployeeModel(em.getWorAddUserId())));
em.setItm(
new InstallTypeService().findById(new InstallTypeModel(em.getWorInstallTypeId())));
em.setPm(new PackageService().findById(new PackageModel(em.getWorPackageId())));
}
}
}
return list;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(con);
}
return null;
}
/**
* 根据id查找数据
*
* @param wom
* @return
*/
public WorkOrderModel findById(WorkOrderModel wom) {
Connection con = null;
try {
con = ConnectionManager.getConnection();
WorkOrderModel em = this.wod.findById(wom, con);
if (em != null) {
em.setCim(new CustomerInfoService().findById(new CustomerInfoModel(em.getWorCustomerId())));
em.setEm(new EmployeeService().findById(new EmployeeModel(em.getWorAddUserId())));
em.setItm(new InstallTypeService().findById(new InstallTypeMod