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

优化sql

parent 8209023b
...@@ -59,7 +59,7 @@ public enum BASE_RESP_CODE_ENUM { ...@@ -59,7 +59,7 @@ public enum BASE_RESP_CODE_ENUM {
WORKDAY_NOT_NULL("637","工时日期不能为空"), WORKDAY_NOT_NULL("637","工时日期不能为空"),
PROJECT_NOT_NULL("638","项目类型不能为空"), PROJECT_NOT_NULL("638","项目类型不能为空"),
NEW_PASSWORD_IS_HTE_SAME_OLD_PASSWORD("639","新密码不能与旧密码相同"), NEW_PASSWORD_IS_HTE_SAME_OLD_PASSWORD("639","新密码不能与旧密码相同"),
PASSWORD_FORMAT_ERROR("640","密码由6到16位数字和字母组成"), PASSWORD_FORMAT_ERROR("640","密码由6到16位数字组成"),
NOT_MANAGER_TYPE("642","没有可以管理的类型项目"); NOT_MANAGER_TYPE("642","没有可以管理的类型项目");
......
...@@ -46,7 +46,7 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> { ...@@ -46,7 +46,7 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
* @param userId * @param userId
* @return * @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 * @param year
......
...@@ -28,15 +28,16 @@ ...@@ -28,15 +28,16 @@
<sql id="criteria"> <sql id="criteria">
<if test="id != null">AND id = #{id}</if> <if test="id != null">AND id = #{id}</if>
<if test="deptName != null">AND dept_name = #{deptName}</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="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="createTime != null">AND create_time = #{createTime}</if>
<if test="modifyTime != null">AND modify_time = #{modifyTime}</if> <if test="modifyTime != null">AND modify_time = #{modifyTime}</if>
</sql> </sql>
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="Base_Column_List"> <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> </sql>
<select id="getDeptByCondition" resultMap="BaseResultMap" parameterType="integer"> <select id="getDeptByCondition" resultMap="BaseResultMap" parameterType="integer">
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
<resultMap id="monthlyWorkHourStatistics" type="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics"> <resultMap id="monthlyWorkHourStatistics" type="cn.wisenergy.model.dto.MonthlyWorkingHoursStatistics">
<result property="count" column="count(1)"/> <result property="count" column="count(1)"/>
<result property="workTime" column="sum(work_time)"/> <result property="workTime" column="sum(work_time)"/>
<result property="projectType" column="type"/>
</resultMap> </resultMap>
<sql id="table"> <sql id="table">
...@@ -138,9 +139,10 @@ ...@@ -138,9 +139,10 @@
</sql> </sql>
<select id="statisticsByProjectType" resultMap="monthlyWorkHourStatistics"> <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"/> 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>
<select id="listByDateAndUserId" resultMap="dayWorkTimeAndType"> <select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
...@@ -179,16 +181,17 @@ ...@@ -179,16 +181,17 @@
</select> </select>
<select id="getWorkTimeAndCostCollect" resultType="cn.wisenergy.model.dto.WorkTimeAndCostCollect" parameterType="integer"> <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 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 <include refid="table"/> from work_time_order t JOIN work_dept d ON t.dept_id=d.id
where status in (2,5) and project_id in 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=","> <foreach collection="projectIds" item="projectId" open="(" close=")" separator=",">
#{projectId} #{projectId}
</foreach> </foreach>
<if test="firstDayOfMonth != null"> <if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth} AND work_day >= #{firstDayOfMonth}
</if> </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>
<select id="getDaysByDateAndStatus" resultType="date" > <select id="getDaysByDateAndStatus" resultType="date" >
......
...@@ -47,9 +47,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -47,9 +47,6 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired @Autowired
private WorkProjectService workProjectService; private WorkProjectService workProjectService;
@Autowired
private WorkHolidayService workHolidayService;
@Autowired @Autowired
private WorkHolidayMapper workHolidayMapper; private WorkHolidayMapper workHolidayMapper;
...@@ -122,7 +119,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -122,7 +119,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Object> objects = new ArrayList<>(); List<Object> objects = new ArrayList<>();
//存放查询条件 //存放查询条件
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
//用户是项目或部门级别 //用户是项目或部门级别,查询审批统计
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode()) || if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode()) ||
user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) { user.getLevel().equals(ManagerEnum.IS_DEPARTMENT_DIRECTOR.getCode())) {
//以审批人、审核状态、开始时间查询本月审批数量 //以审批人、审核状态、开始时间查询本月审批数量
...@@ -130,17 +127,16 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -130,17 +127,16 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("status", WorkOrderStatus.ALREADY_AUDIT.getCode()); map.put("status", WorkOrderStatus.ALREADY_AUDIT.getCode());
map.put("startDay", firstDayOfMonth); map.put("startDay", firstDayOfMonth);
Integer completedCount = workTimeOrderMapper.getCountByCondition(map); Integer completedCount = workTimeOrderMapper.getCountByCondition(map);
//本月驳回未重报数量 //本月驳回未重报数量
map.replace("status", WorkOrderStatus.TURN_DOWN.getCode()); map.replace("status", WorkOrderStatus.TURN_DOWN.getCode());
Integer rejectAndNotResubmit = workTimeOrderMapper.getCountByCondition(map); Integer rejectAndNotResubmit = workTimeOrderMapper.getCountByCondition(map);
//项目级别,获取所管理项目, //项目级别,获取所管理项目,
if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) { if (user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
List<WorkProject> projects = workProjectService.getUserManageProjects(userId); List<WorkProject> projects = workProjectService.getUserManageProjects(userId);
ArrayList<Integer> projectIds = new ArrayList<>(); if (CollectionUtil.isNotEmpty(projects)) {
for (WorkProject project : projects) { List<Integer> projectIds = projects.stream().map(WorkProject::getId).collect(Collectors.toList());
projectIds.add(project.getId());
}
if (CollectionUtil.isNotEmpty(projectIds)) {
map.put("projectIds", projectIds); map.put("projectIds", projectIds);
} }
} }
...@@ -157,8 +153,8 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -157,8 +153,8 @@ public class StatisticsServiceImpl implements StatisticsService {
statusArray.add(WorkOrderStatus.RE_SUBMIT.getCode()); statusArray.add(WorkOrderStatus.RE_SUBMIT.getCode());
map.remove("reviewerId"); map.remove("reviewerId");
map.remove("status"); map.remove("status");
//本月未审批数量查询
map.put("statusArray", statusArray); map.put("statusArray", statusArray);
//本月未审批数量
Integer notCompletedCount = workTimeOrderMapper.getCountByCondition(map); Integer notCompletedCount = workTimeOrderMapper.getCountByCondition(map);
//所有查询结果封装进对象 //所有查询结果封装进对象
ApprovalStatistics approvalStatistics = new ApprovalStatistics(); ApprovalStatistics approvalStatistics = new ApprovalStatistics();
...@@ -167,13 +163,14 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -167,13 +163,14 @@ public class StatisticsServiceImpl implements StatisticsService {
approvalStatistics.setNotApprovalCount(notCompletedCount); approvalStatistics.setNotApprovalCount(notCompletedCount);
objects.add(approvalStatistics); objects.add(approvalStatistics);
} }
//用户是普通用户或项目级别用户 //用户是普通用户或项目级别用户,查询填报统计
ArrayList<MonthlyWorkingHoursStatistics> statisticsArrayList = new ArrayList<>();
if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode()) || if (user.getLevel().equals(ManagerEnum.NOT_MANAGER.getCode()) ||
user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) { user.getLevel().equals(ManagerEnum.IS_PROJECT_DIRECTOR.getCode())) {
//本月应填报天数 // 本月应填报日期
List<Date> currentMonthWorkDays = this.currentMonthWorkDays(); List<Date> currentMonthWorkDays = this.currentMonthWorkDays();
// 本月已填报日期
List<Date> currentMonthFilledDays = currentMonthFilledDays(userId); List<Date> currentMonthFilledDays = currentMonthFilledDays(userId);
// 本月未填报日期
currentMonthWorkDays.removeAll(currentMonthFilledDays); currentMonthWorkDays.removeAll(currentMonthFilledDays);
int notFilledCount = currentMonthWorkDays.size(); int notFilledCount = currentMonthWorkDays.size();
//本月被现存驳回数 //本月被现存驳回数
...@@ -182,20 +179,14 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -182,20 +179,14 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("userId", userId); map.put("userId", userId);
map.put("startDay", firstDayOfMonth); map.put("startDay", firstDayOfMonth);
Integer countByCondition = workTimeOrderMapper.getCountByCondition(map); Integer countByCondition = workTimeOrderMapper.getCountByCondition(map);
String currentDayOfMonth = DateUtil.convertDateToYMDStr(firstDayOfMonth);
//统计项目类型工单填报次数、总工时 List<MonthlyWorkingHoursStatistics> monthlyWorkingHoursStatistics = workTimeOrderMapper.statisticsByProjectType(userId, firstDayOfMonth);
MonthlyWorkingHoursStatistics statistics1 = workTimeOrderMapper.statisticsByProjectType(userId, ProjectTypeEnum.PROJECT.getType(), currentDayOfMonth); for (MonthlyWorkingHoursStatistics monthlyWorkingHoursStatistic : monthlyWorkingHoursStatistics) {
statistics1.setProjectType(ProjectTypeEnum.PROJECT.getTypeName()); monthlyWorkingHoursStatistic.setNotFilledCount(notFilledCount);
statistics1.setNotFilledCount(notFilledCount); monthlyWorkingHoursStatistic.setRejectCount(countByCondition);
statistics1.setRejectCount(countByCondition); }
statisticsArrayList.add(statistics1);
//统计商机类型工单填报次数、总工时 objects.add(monthlyWorkingHoursStatistics);
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);
} }
return objects; return objects;
} }
...@@ -219,16 +210,10 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -219,16 +210,10 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList()); List<Integer> projectIds = userManageProjects.stream().map(WorkProject::getId).collect(Collectors.toList());
List<WorkTimeAndCostCollect> collect = workTimeOrderMapper.getWorkTimeAndCostCollect(projectIds, startTime); 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; return collect;
} }
//获取本月应上班日期集合 //获取本月应上班日期
public List<Date> currentMonthWorkDays() { public List<Date> currentMonthWorkDays() {
log.info("StatisticsServiceImpl[]currentMonthWorkDays[]input.method"); log.info("StatisticsServiceImpl[]currentMonthWorkDays[]input.method");
//当前时间 //当前时间
...@@ -264,7 +249,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -264,7 +249,7 @@ public class StatisticsServiceImpl implements StatisticsService {
return workDays; return workDays;
} }
//用户本月填报日期集合 //获取用户本月已填报的日期
public List<Date> currentMonthFilledDays(Integer userId) { public List<Date> currentMonthFilledDays(Integer userId) {
log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method"); log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method");
Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth(); Date firstDayOfMonth = DateUtil.getCurrentFirstDayOfMonth();
......
...@@ -146,7 +146,7 @@ public class WorkProjectServiceImpl implements WorkProjectService { ...@@ -146,7 +146,7 @@ public class WorkProjectServiceImpl implements WorkProjectService {
if (workCentre == null) { if (workCentre == null) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.CENTRE_NOT_FOUND); 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); List<WorkDept> workDepts = workDeptMapper.getDeptByCondition(map);
if (CollectionUtils.isEmpty(workDepts)) { if (CollectionUtils.isEmpty(workDepts)) {
......
...@@ -72,11 +72,7 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -72,11 +72,7 @@ public class WorkUserServiceImpl implements WorkUserService {
if (userId == null || StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)) { if (userId == null || StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL); 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)) { if (oldPassword.equals(newPassword)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NEW_PASSWORD_IS_HTE_SAME_OLD_PASSWORD); 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