Commit cbf7c2e1 authored by nie'hong's avatar nie'hong

优化sql

parent 8209023b
......@@ -59,7 +59,7 @@ public enum BASE_RESP_CODE_ENUM {
WORKDAY_NOT_NULL("637","工时日期不能为空"),
PROJECT_NOT_NULL("638","项目类型不能为空"),
NEW_PASSWORD_IS_HTE_SAME_OLD_PASSWORD("639","新密码不能与旧密码相同"),
PASSWORD_FORMAT_ERROR("640","密码由6到16位数字和字母组成"),
PASSWORD_FORMAT_ERROR("640","密码由6到16位数字组成"),
NOT_MANAGER_TYPE("642","没有可以管理的类型项目");
......
......@@ -46,7 +46,7 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
* @param userId
* @return
*/
MonthlyWorkingHoursStatistics statisticsByProjectType(@Param("userId") Integer userId, @Param("projectType") Integer projectType, @Param("currentMonthFirstDay") String currentMonthFirstDay);
List<MonthlyWorkingHoursStatistics> statisticsByProjectType(@Param("userId") Integer userId, @Param("currentMonthFirstDay") Date currentMonthFirstDay);
/**
* @param year
......
......@@ -28,15 +28,16 @@
<sql id="criteria">
<if test="id != null">AND id = #{id}</if>
<if test="deptName != null">AND dept_name = #{deptName}</if>
<if test="oaDeptId != null">AND oa_dept_id = #{oaDeptId}</if>
<if test="centreId != null">AND centre_id = #{centreId}</if>
<if test="managerId != null">AND manager_id = #{managerId}</if>
<if test="deptManagerId != null">AND dept_manager_id = #{deptManagerId}</if>
<if test="createTime != null">AND create_time = #{createTime}</if>
<if test="modifyTime != null">AND modify_time = #{modifyTime}</if>
</sql>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, oa_dept_id, dept_name, create_time, modify_time
id,dept_name, oa_dept_id,centre_id, dept_name, create_time, modify_time
</sql>
<select id="getDeptByCondition" resultMap="BaseResultMap" parameterType="integer">
......
......@@ -55,6 +55,7 @@
<resultMap id="monthlyWorkHourStatistics" type="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
<result property="count" column="count(1)"/>
<result property="workTime" column="sum(work_time)"/>
<result property="projectType" column="type"/>
</resultMap>
<sql id="table">
......@@ -138,9 +139,10 @@
</sql>
<select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics">
select count(1),sum(work_time)
select CASE WHEN type= 1 THEN "项目" WHEN type= 2 THEN "商机" END AS type, count(1),sum(work_time)
from <include refid="table"/>
where user_id = #{userId} AND type = #{projectType} AND work_day >=#{currentMonthFirstDay}
where user_id = #{userId} AND type in (1,2) AND work_day >= #{currentMonthFirstDay}
group by type
</select>
<select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
......@@ -179,16 +181,17 @@
</select>
<select id="getWorkTimeAndCostCollect" resultType="cn.wisenergy.model.dto.WorkTimeAndCostCollect" parameterType="integer">
select case when `type`= 1 then '商机' when `type`= 0 then '项目' end AS type,dept_id, project_id,MIN(work_day) AS firstTime,MAX(work_day) AS lastTime,SUM(work_time)/8 AS totalTime,(SUM(work_time))/8*10 AS cost
from <include refid="table"/>
where status in (2,5) and project_id in
select CASE WHEN t.type= 1 THEN "项目" WHEN t.type= 2 THEN "商机" END AS type,t.dept_id, t.project_id,MIN(t.work_day) AS firstTime,MAX(t.work_day) AS lastTime,SUM(t.work_time)/8 AS totalTime,(SUM(t.work_time))/8*10 AS cost,dept_name AS deptName,project_name AS projectName
from work_time_order t JOIN work_dept d ON t.dept_id=d.id
JOIN work_project p ON t.project_id=p.id
where status IN (2,5) AND t.type IN (1,2) AND project_id IN
<foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
#{projectId}
</foreach>
<if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth}
</if>
group by case when `type`= 1 then '商机' when `type`= 0 then '项目' end,dept_id, project_id
group by t.type,dept_id, project_id,dept_name,project_name
</select>
<select id="getDaysByDateAndStatus" resultType="date" >
......
......@@ -47,9 +47,6 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired
private WorkProjectService workProjectService;
@Autowired
private WorkHolidayService workHolidayService;
@Autowired
private WorkHolidayMapper workHolidayMapper;
......@@ -122,7 +119,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Object> objects = new ArrayList<>();
//存放查询条件
Map<String, Object> map = new HashMap<>();
//用户是项目或部门级别
//用户是项目或部门级别,查询审批统计
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode()) ||
user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
//以审批人、审核状态、开始时间查询本月审批数量
......@@ -130,17 +127,16 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("status", WorkOrderStatus.ALREADY_AUDIT.getCode());
map.put("startDay", firstDayOfMonth);
Integer completedCount = workTimeOrderMapper.getCountByCondition(map);
//本月驳回未重报数量
map.replace("status", WorkOrderStatus.TURN_DOWN.getCode());
Integer rejectAndNotResubmit = workTimeOrderMapper.getCountByCondition(map);
//项目级别,获取所管理项目,
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
List<WorkProject> projects = workProjectService.getUserManageProjects(userId);
ArrayList<Integer> projectIds = new ArrayList<>();
for (WorkProject project : projects) {
projectIds.add(project.getId());
}
if (CollectionUtil.isNotEmpty(projectIds)) {
if (CollectionUtil.isNotEmpty(projects)) {
List<Integer> projectIds = projects.stream().map(WorkProject::getId).collect(Collectors.toList());
map.put("projectIds", projectIds);
}
}
......@@ -157,8 +153,8 @@ public class StatisticsServiceImpl implements StatisticsService {
statusArray.add(WorkOrderStatus.RE_SUBMIT.getCode());
map.remove("reviewerId");
map.remove("status");
//本月未审批数量查询
map.put("statusArray", statusArray);
//本月未审批数量
Integer notCompletedCount = workTimeOrderMapper.getCountByCondition(map);
//所有查询结果封装进对象
ApprovalStatistics approvalStatistics = new ApprovalStatistics();
......@@ -167,13 +163,14 @@ public class StatisticsServiceImpl implements StatisticsService {
approvalStatistics.setNotApprovalCount(notCompletedCount);
objects.add(approvalStatistics);
}
//用户是普通用户或项目级别用户
ArrayList<MonthlyWorkingHoursStatistics> statisticsArrayList = new ArrayList<>();
//用户是普通用户或项目级别用户,查询填报统计
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode()) ||
user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
//本月应填报天数
// 本月应填报日期
List<Date> currentMonthWorkDays = this.currentMonthWorkDays();
// 本月已填报日期
List<Date> currentMonthFilledDays = currentMonthFilledDays(userId);
// 本月未填报日期
currentMonthWorkDays.removeAll(currentMonthFilledDays);
int notFilledCount = currentMonthWorkDays.size();
//本月被现存驳回数
......@@ -182,20 +179,14 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("userId", userId);
map.put("startDay", firstDayOfMonth);
Integer countByCondition = workTimeOrderMapper.getCountByCondition(map);
String currentDayOfMonth = DateUtil.convertDateToYMDStr(firstDayOfMonth);
//统计项目类型工单填报次数、总工时
MonthlyWorkingHoursStatistics statistics1 = workTimeOrderMapper.statisticsByProjectType(userId, ProjectTypeEnum.PROJECT.getType(), currentDayOfMonth);
statistics1.setProjectType(ProjectTypeEnum.PROJECT.getTypeName());
statistics1.setNotFilledCount(notFilledCount);
statistics1.setRejectCount(countByCondition);
statisticsArrayList.add(statistics1);
//统计商机类型工单填报次数、总工时
MonthlyWorkingHoursStatistics statistics2 = workTimeOrderMapper.statisticsByProjectType(userId, ProjectTypeEnum.BUSINESS_OPPORTUNITY.getType(), currentDayOfMonth);
statistics2.setProjectType(ProjectTypeEnum.BUSINESS_OPPORTUNITY.getTypeName());
statistics2.setNotFilledCount(notFilledCount);
statistics2.setRejectCount(countByCondition);
statisticsArrayList.add(statistics2);
objects.add(statisticsArrayList);
List<MonthlyWorkingHoursStatistics> monthlyWorkingHoursStatistics = workTimeOrderMapper.statisticsByProjectType(userId, firstDayOfMonth);
for (MonthlyWorkingHoursStatistics monthlyWorkingHoursStatistic : monthlyWorkingHoursStatistics) {
monthlyWorkingHoursStatistic.setNotFilledCount(notFilledCount);
monthlyWorkingHoursStatistic.setRejectCount(countByCondition);
}
objects.add(monthlyWorkingHoursStatistics);
}
return objects;
}
......@@ -219,16 +210,10 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList());
List<WorkTimeAndCostCollect> collect = workTimeOrderMapper.getWorkTimeAndCostCollect(projectIds, startTime);
for (WorkTimeAndCostCollect timeAndCostCollect : collect) {
//部门名称
timeAndCostCollect.setDeptName(workDeptService.getById(timeAndCostCollect.getDeptId()).getDeptName());
//项目名称
timeAndCostCollect.setProjectName(workProjectService.getById(timeAndCostCollect.getProjectId()).getProjectName());
}
return collect;
}
//获取本月应上班日期集合
//获取本月应上班日期
public List<Date> currentMonthWorkDays() {
log.info("StatisticsServiceImpl[]currentMonthWorkDays[]input.method");
//当前时间
......@@ -264,7 +249,7 @@ public class StatisticsServiceImpl implements StatisticsService {
return workDays;
}
//用户本月填报日期集合
//获取用户本月已填报的日期
public List<Date> currentMonthFilledDays(Integer userId) {
log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method");
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
......
......@@ -146,7 +146,7 @@ public class WorkProjectServiceImpl implements WorkProjectService {
if (workCentre == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.CENTRE_NOT_FOUND);
}
map.put("centre_id",workCentre.getId());
map.put("centreId",workCentre.getId());
//获取中心下的部门信息
List<WorkDept> workDepts = workDeptMapper.getDeptByCondition(map);
if (CollectionUtils.isEmpty(workDepts)) {
......
......@@ -72,11 +72,7 @@ public class WorkUserServiceImpl implements WorkUserService {
if (userId == null || StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
//校验新密码类型
String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
if (!newPassword.matches(regex)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.PASSWORD_FORMAT_ERROR);
}
//新密码与旧密码相同
if (oldPassword.equals(newPassword)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NEW_PASSWORD_IS_HTE_SAME_OLD_PASSWORD);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment