package com.ld.igds.oa.service;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.ld.igds.models.*;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.hibernate.Session;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.oa.OAUtil;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
|
@Component
|
public class HOfficeAutoService extends HibernateDao {
|
|
@Autowired
|
private CoreGpsService coreGpsService;
|
|
public void pageAttendance(Page<OAAttendance> page,
|
Map<String, Object> param) throws Exception {
|
String hql = " from " + OAAttendance.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
|
String str = (String) param.get("userId");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and userId =:userId";
|
args.put("userId", str);
|
}
|
|
str = (String) param.get("userName");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and userName like:userName";
|
args.put("userName", "%" + str + "%");
|
}
|
|
Date date = (Date) param.get("start");
|
if (null != date) {
|
hql += " and workDay >=:start";
|
args.put("start", DateUtil.getCurZero(date));
|
}
|
|
date = (Date) param.get("end");
|
if (null != date) {
|
hql += " and workDay <:end";
|
args.put("end", DateUtil.getNextZero(date));
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
|
hql += " order by workDay desc";
|
|
this.pagingQuery(page, hql, count, args);
|
|
}
|
|
public void saveAttendance(OAAttendance data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (null == data.getWorkDay()) {
|
data.setWorkDay(new Date());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delAttendance(OAAttendance data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pageAppraisal(Page<OAAppraisal> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + OAAppraisal.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
String name = (String) param.get("name");
|
if (null != name) {
|
hql += " and name like:name ";
|
args.put("name", "%" + name + "%");
|
}
|
|
Date date = (Date) param.get("start");
|
if (null != date) {
|
hql += " and publishTime >=:start";
|
args.put("start", DateUtil.getCurZero(date));
|
}
|
|
date = (Date) param.get("end");
|
if (null != date) {
|
hql += " and publishTime <:end";
|
args.put("end", DateUtil.getNextZero(date));
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
|
hql += " order by publishTime desc";
|
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public List<OAAppraisalDetail> listAppraisalDetail(String id) {
|
String hql = " from " + OAAppraisalDetail.class.getName()
|
+ " where appraisalId=:appraisalId order by userId";
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("appraisalId", id);
|
return this.query(hql, args);
|
}
|
|
public void saveAppraisal(OAAppraisal data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
if (null == data.getPublishTime()) {
|
data.setPublishTime(new Date());
|
}
|
if (null == data.getPublishUser()) {
|
data.setPublishUser(ContextUtil.getLoginUserCName());
|
}
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
this.saveAppraisalDetail(data.getDetails(), data.getId(), session);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
private void saveAppraisalDetail(List<OAAppraisalDetail> details,
|
String id, Session session) {
|
if (null == details || details.isEmpty())
|
return;
|
for (OAAppraisalDetail detail : details) {
|
detail.setAppraisalId(id);
|
if (StringUtils.isEmpty(detail.getId())) {
|
detail.setId(ContextUtil.getUUID());
|
session.save(detail);
|
} else {
|
session.update(detail);
|
}
|
}
|
}
|
|
public String delAppraisal(OAAppraisal data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
delDetailByAppraisalId(data.getId(), session);
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
private void delDetailByAppraisalId(String id, Session session) {
|
String hql = " delete from " + OAAppraisalDetail.class.getName()
|
+ " where appraisalId=:appraisalId";
|
session.createQuery(hql).setString("appraisalId", id).executeUpdate();
|
}
|
|
public String delAppraisalDetail(OAAppraisalDetail data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pageSalary(Page<OASalary> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + OASalary.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
|
String str = (String) param.get("userId");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and userId =:userId";
|
args.put("userId", str);
|
}
|
|
str = (String) param.get("userName");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and userName like:userName";
|
args.put("userName", "%" + str + "%");
|
}
|
|
str = (String) param.get("salaryTime");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and salaryTime =:salaryTime";
|
args.put("salaryTime", str);
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
|
hql += " order by salaryTime desc,userId";
|
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public void saveSalary(OASalary data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
|
}
|
|
public String delSalary(OASalary data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pageArchives(Page<OAArchives> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + OAArchives.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
|
String str = (String) param.get("year");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and year =:year";
|
args.put("year", str);
|
}
|
|
str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and name like:name";
|
args.put("name", "%" + str + "%");
|
}
|
|
str = (String) param.get("category");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and category=:category";
|
args.put("category", str);
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
|
hql += " order by updateTime desc";
|
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public String saveArchives(OAArchives data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
data.setUpdateTime(new Date());
|
data.setUpdateUser(ContextUtil.getLoginUserCName());
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return data.getId();
|
}
|
|
public String delArchives(OAArchives data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pageAsset(Page<OAAsset> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + OAAsset.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
String str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and name like:name";
|
args.put("name", "%" + str + "%");
|
}
|
|
str = (String) param.get("category");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and category=:category";
|
args.put("category", str);
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
hql += " order by handleTime desc";
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public void saveAsset(OAAsset data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
if (null == data.getHandleUser()) {
|
data.setHandleUser(ContextUtil.getLoginUserCName());
|
}
|
if (null == data.getHandleTime()) {
|
data.setHandleTime(new Date());
|
}
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delAsset(OAAsset data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pageExpClaim(Page<OAExpClaim> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + OAExpClaim.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
String str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and name like:name";
|
args.put("name", "%" + str + "%");
|
}
|
str = (String) param.get("submitUser");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and submitUser like :submitUser";
|
args.put("submitUser", "%" + str + "%");
|
}
|
|
str = (String) param.get("submitUserId");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and submitUserId =:submitUserId";
|
args.put("submitUserId", str);
|
}
|
|
str = (String) param.get("status");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and status =:status";
|
args.put("status", str);
|
}
|
|
Date date = (Date) param.get("start");
|
if (null != date) {
|
hql += " and submitTime >= :start";
|
args.put("start", DateUtil.getCurZero(date));
|
}
|
date = (Date) param.get("end");
|
if (null != date) {
|
hql += " and submitTime <= :end";
|
args.put("end", DateUtil.getNextZero(date));
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
hql += " order by submitTime desc";
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public List<OAExpClaimDetail> listExpClaimDetail(String id) {
|
String hql = " from " + OAExpClaimDetail.class.getName()
|
+ " where expClaimId=:expClaimId";
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("expClaimId", id);
|
return this.query(hql, args);
|
}
|
|
public void saveExpClaim(OAExpClaim data, boolean isAudit) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
|
if (data.getSumAmount() <= 0) {
|
double sumAmount = 0.0;
|
if (null != data.getDetails()) {
|
for (OAExpClaimDetail detail : data.getDetails()) {
|
sumAmount += detail.getAmount();
|
}
|
}
|
data.setSumAmount(sumAmount);
|
}
|
|
if (null == data.getId()) {
|
data.setStatus(OAUtil.AUDIT_NONE);
|
data.setId(OAUtil.createExpClaimId());
|
if (null == data.getSubmitTime()) {
|
data.setSubmitTime(new Date());
|
}
|
if (null == data.getSubmitUser()) {
|
data.setSubmitUser(ContextUtil.getLoginUserCName());
|
data.setSubmitUserId(ContextUtil.getLoginUserName());
|
}
|
session.save(data);
|
} else {
|
|
if (isAudit) {
|
if (null == data.getAuditTime()) {
|
data.setAuditTime(new Date());
|
}
|
|
if (null == data.getAuditUser()) {
|
data.setAuditUser(ContextUtil.getLoginUserCName());
|
data.setAuditUserId(ContextUtil.getLoginUserName());
|
}
|
}
|
session.update(data);
|
}
|
this.saveExpClaimDetail(data.getDetails(), data.getId(), session);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
private void saveExpClaimDetail(List<OAExpClaimDetail> details, String id,
|
Session session) {
|
if (null == details || details.isEmpty())
|
return;
|
for (OAExpClaimDetail detail : details) {
|
detail.setExpClaimId(id);
|
if (StringUtils.isEmpty(detail.getId())) {
|
detail.setId(ContextUtil.getUUID());
|
session.save(detail);
|
} else {
|
session.update(detail);
|
}
|
}
|
}
|
|
public String delExpClaim(OAExpClaim data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
|
this.delDetailByExpClaimId(data.getId(), session);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
private void delDetailByExpClaimId(String id, Session session) {
|
String hql = " delete from " + OAExpClaimDetail.class.getName()
|
+ " where expClaimId=:expClaimId";
|
session.createQuery(hql).setString("expClaimId", id).executeUpdate();
|
}
|
|
public String delExpClaimDetail(OAExpClaimDetail data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public List<OAGps> getGps() {
|
String companyId = ContextUtil.getCompanyId();
|
|
String hql = " from " + OAGps.class.getName()
|
+ " where companyId=:companyId ";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", companyId);
|
|
hql += " order by updateTime";
|
|
return this.query(hql, args);
|
}
|
|
public String saveGps(OAGps data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (data.getUpdateTime() == null) {
|
data.setUpdateTime(new Date());
|
}
|
if (StringUtils.isEmpty(data.getId())) {
|
data.setId(ContextUtil.getCurTimeMillis());
|
data.setCompanyId(ContextUtil.getCompanyId());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public String delGps(OAGps data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public String flushCache(String companyId) {
|
List<OAGps> list = this.getGps();
|
coreGpsService.setCacheGpsData(companyId, list);
|
return null;
|
}
|
}
|