fourcal/src/main/java/cn/palmte/work/service/ProjectService.java

72 lines
3.7 KiB
Java
Raw Normal View History

2021-10-29 10:15:36 +00:00
package cn.palmte.work.service;
import cn.palmte.work.model.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jfunc.common.db.QueryHelper;
import top.jfunc.common.db.bean.Page;
import top.jfunc.common.db.utils.Pagination;
import top.jfunc.common.utils.StrUtil;
import java.util.Map;
/**
* @author xiongshiyan at 2021/10/29 , contact me with email yanshixiong@126.com or phone 15208384257
*/
@Service
public class ProjectService {
@Autowired
private Pagination pagination;
private QueryHelper getQueryHelper(Map<String, String> searchInfo, int pageNumber, int pageSize) {
/*"CASE p.type WHEN 1 THEN '工程集成类' WHEN 2 THEN '设备集成类' WHEN 3 THEN '战略合作类' ELSE '未知' AS typeDesc," +
"CASE p.status WHEN 0 THEN '草稿' WHEN 1 THEN '项目创建' WHEN 5 THEN '概算完成' WHEN 10 THEN '预算完成' WHEN 15 THEN '结算中' WHEN 20 THEN '决算完成' ELSE '未知' AS statusDesc," +
"CASE p.approve_status WHEN 0 THEN '待审核' WHEN 1 THEN '审核通过' WHEN 2 THEN '审核不通过' ELSE '未知' AS approveStatusDesc," +
*/
QueryHelper queryHelper = new QueryHelper("SELECT p.*","project","p");
2021-11-01 03:22:37 +00:00
if(StrUtil.isNotEmpty(searchInfo.get("status")) && !"-1".equals(searchInfo.get("status"))){
queryHelper.addCondition("p.status=?", Integer.parseInt(searchInfo.get("status")));
2021-10-29 10:15:36 +00:00
}
2021-11-01 03:22:37 +00:00
if(StrUtil.isNotEmpty(searchInfo.get("approveStatus")) && !"-1".equals(searchInfo.get("approveStatus"))){
queryHelper.addCondition("p.approve_status=?", Integer.parseInt(searchInfo.get("approveStatus")));
2021-10-29 10:15:36 +00:00
}
2021-11-01 03:22:37 +00:00
if(StrUtil.isNotEmpty(searchInfo.get("deptId")) && !"-1".equals(searchInfo.get("deptId"))){
queryHelper.addCondition("p.dept_id=?", Integer.parseInt(searchInfo.get("deptId")));
2021-10-29 10:15:36 +00:00
}
2021-11-01 03:22:37 +00:00
if(StrUtil.isNotEmpty(searchInfo.get("type")) && !"-1".equals(searchInfo.get("type"))){
queryHelper.addCondition("p.type=?", Integer.parseInt(searchInfo.get("type")));
2021-10-29 10:15:36 +00:00
}
queryHelper.addCondition(StrUtil.isNotEmpty(searchInfo.get("name")),"p.name LIKE ?", "%"+searchInfo.get("name")+"%");
queryHelper.addCondition(StrUtil.isNotEmpty(searchInfo.get("creatorName")),"p.creator_name LIKE ?", "%"+searchInfo.get("creatorName")+"%");
/**
*
*/
if(StrUtil.isNotEmpty(searchInfo.get("startTime")) && StrUtil.isEmpty(searchInfo.get("endTime"))){
2021-11-01 03:22:37 +00:00
String time = searchInfo.get("startTime") + " 00:00:00";
queryHelper.addCondition("p.start_date<=? AND p.end_date>=?", time, time);
2021-10-29 10:15:36 +00:00
}
if(StrUtil.isNotEmpty(searchInfo.get("endTime")) && StrUtil.isEmpty(searchInfo.get("startTime"))){
2021-11-01 03:22:37 +00:00
String time = searchInfo.get("endTime") + " 00:00:00";
queryHelper.addCondition("p.start_date<=? AND p.end_date>=?", time, time);
2021-10-29 10:15:36 +00:00
}
/**
*
*/
if(StrUtil.isNotEmpty(searchInfo.get("startTime")) && StrUtil.isNotEmpty(searchInfo.get("endTime"))){
2021-11-01 03:22:37 +00:00
String startTime = searchInfo.get("startTime") + " 00:00:00";
String endTime = searchInfo.get("endTime") + " 23:59:59";
queryHelper.addCondition("p.start_date>=? AND p.end_date<=?", startTime, endTime);
2021-10-29 10:15:36 +00:00
}
return queryHelper;
}
public Page<Project> list(Map<String, String> searchInfo, int pageNumber, int pageSize){
QueryHelper queryHelper = getQueryHelper(searchInfo, pageNumber, pageSize);
return pagination.paginate(queryHelper.getSql(), Project.class,pageNumber,pageSize);
}
}