启动值班管理

This commit is contained in:
DB 2023-11-23 10:52:38 +08:00
parent c34719a476
commit 8465ceb4d0
10 changed files with 131 additions and 58 deletions

View File

@ -13,7 +13,7 @@ import java.util.List;
/**
* @author DB
* @createTime 2023/09/15 16:24
* @description
* @description 企微机器人
*/
@Component
public class WebHookSendHandler {

View File

@ -4,6 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author DB
@ -11,6 +12,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication(scanBasePackages = {"com.cpop.**"})
@MapperScan("com.cpop.**.mapper")
@EnableAsync
@EnableScheduling
public class CpopOamWebApplication {
public static void main(String[] args) {

View File

@ -1,5 +1,8 @@
package com.cpop.oam.business.controller.backstage;
import com.cpop.core.base.entity.LoginUser;
import com.cpop.core.base.enums.InitRoleEnum;
import com.cpop.core.utils.SecurityUtils;
import com.cpop.system.business.service.RoleService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
@ -14,6 +17,7 @@ import com.cpop.oam.business.service.StaffService;
import com.cpop.oam.business.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@ -123,9 +127,11 @@ public class StaffController {
@ApiOperation("获取所有角色信息")
@GetMapping("/getAllRoleList")
public R<List<RoleVo>> getAllSysRoleList() {
LoginUser loginUser = SecurityUtils.getInstance().getLoginUser();
List<RoleVo> list = SpringUtils.getBean(RoleService.class).listAs(QueryWrapper.create()
.where(ROLE.STATUS.eq(true))
.and(ROLE.ROLE_VALUE.ne(Constants.SUPER_ADMIN_VALUE))
.and(ROLE.ID.ne(InitRoleEnum.SUPER_OAM_ROLE.getId()))
.and(ROLE.USER_TYPE.eq(loginUser.getUserType()))
.orderBy(ROLE.ORDER_NO.asc())
, RoleVo.class);
return R.ok(list);

View File

@ -0,0 +1,22 @@
package com.cpop.oam.business.dto;
import lombok.Data;
/**
* @author DB
* @createTime 2023/11/22 18:26
* @description
*/
@Data
public class StaffDto {
/**
* 手机号
*/
private String phoneNumber;
/**
* 姓名
*/
private String name;
}

View File

@ -41,4 +41,12 @@ public interface DutyService extends IService<Duty> {
* @param dutyDate 值班日期
*/
void removeDutyByDate(String dutyDate);
/**
* @descriptions 每天9点通知值班人员
* @author DB
* @date 2023/11/22 18:09
* @return: void
*/
void dutyNotice();
}

View File

@ -1,6 +1,14 @@
package com.cpop.oam.business.service.impl;
import com.cpop.api.tencent.wxWork.handler.WebHookSendHandler;
import com.cpop.core.base.exception.ServiceException;
import com.cpop.core.base.table.SysUser;
import com.cpop.oam.business.dto.StaffDto;
import com.cpop.oam.business.vo.StaffPageVo;
import com.cpop.oam.business.vo.StaffVo;
import com.cpop.oam.framework.constant.WebHookKeyConstant;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.DbChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.common.utils.DateUtils;
import com.cpop.common.utils.StringUtils;
@ -13,19 +21,20 @@ import com.cpop.oam.business.mapper.DutyMapper;
import com.cpop.oam.business.service.DutyService;
import com.cpop.oam.business.service.StaffService;
import com.cpop.oam.business.vo.DutyListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.sql.Date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import static com.cpop.core.base.table.table.SysUserTableDef.SYS_USER;
import static com.cpop.oam.business.entity.table.DutyTableDef.DUTY;
import static com.cpop.oam.business.entity.table.StaffTableDef.STAFF;
/**
* 值班表 服务层实现
@ -36,6 +45,9 @@ import static com.cpop.oam.business.entity.table.DutyTableDef.DUTY;
@Service("oamDutyService")
public class DutyServiceImpl extends ServiceImpl<DutyMapper, Duty> implements DutyService {
@Autowired
private WebHookSendHandler webHookSendHandler;
/**
* @Description: 查询值班列表(当月)
* @param bo 请求参数
@ -75,6 +87,17 @@ public class DutyServiceImpl extends ServiceImpl<DutyMapper, Duty> implements Du
item.setTechnologyStaffName(staffMap.get(item.getTechnologyStaffId()));
});
return list;
//查询过多
/*return this.mapper.selectListByQueryAs(QueryWrapper.create()
.select(DUTY.ID, DUTY.DUTY_DATE, DUTY.SERVICE_STAFF_ID, DUTY.TECHNOLOGY_STAFF_ID)
.where(DUTY.DUTY_DATE.ge(firstDay).and(DUTY.DUTY_DATE.le(lastDay))),
DutyListVo.class,
//服务人员名
item -> item.field(DutyListVo::getServiceStaffName)
.queryWrapper(serviceStaffName -> queryChain().select(STAFF.NAME).from(STAFF).where(STAFF.ID.eq(serviceStaffName.getServiceStaffId()))),
//技术人员名
item -> item.field(DutyListVo::getTechnologyStaffName)
.queryWrapper(serviceStaffName -> queryChain().select(STAFF.NAME).from(STAFF).where(STAFF.ID.eq(serviceStaffName.getTechnologyStaffId()))));*/
}
/**
@ -113,4 +136,29 @@ public class DutyServiceImpl extends ServiceImpl<DutyMapper, Duty> implements Du
public void removeDutyByDate(String dutyDate) {
this.remove(QueryWrapper.create().where(DUTY.DUTY_DATE.eq(dutyDate)));
}
/**
* @descriptions 每天9点通知值班人员
* @author DB
* @date 2023/11/22 18:10
* @return: void
*/
@Override
public void dutyNotice() {
LocalDate now = LocalDate.now();
//获取当天值班员工
Duty one = this.queryChain().where(DUTY.DUTY_DATE.eq(now)).one();
//获取当天技术值班人员
StaffDto staff = DbChain.table(SYS_USER).select(SYS_USER.PHONE_NUMBER, STAFF.NAME).from(SYS_USER)
.leftJoin(STAFF).on(STAFF.USER_ID.eq(SYS_USER.ID))
.where(STAFF.ID.eq(one.getTechnologyStaffId())).oneAs(StaffDto.class);
//技术售后群提醒
try {
webHookSendHandler.webHookSendText(WebHookKeyConstant.ORDER_INFO_BOT, Collections.singletonList(staff.getPhoneNumber()),
"===今日值班" + staff.getName() + "==="
, false);
} catch (IOException e) {
throw new ServiceException(e.getMessage());
}
}
}

View File

@ -23,7 +23,6 @@ import com.cpop.oam.business.service.FinanceReimburseStageService;
import com.cpop.oam.business.vo.FinanceReimburseAuditPageVo;
import com.cpop.oam.business.vo.FinanceReimbursePageVo;
import com.cpop.oam.business.vo.ReimbursePersonStatisticVo;
import com.cpop.oam.framework.utils.OamUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@ -131,9 +130,9 @@ public class FinanceReimburseServiceImpl extends ServiceImpl<FinanceReimburseMap
@Override
public void insertReimburseApplication(ReimburseApplicationBo bo) {
//获取申请员工信息
OamStaffLoginInfo staffInfo = SpringUtils.getBean(OamUtils.class).getLoginStaffInfo();
JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo();
FinanceReimburse financeReimburse = BeanUtils.mapToClass(bo, FinanceReimburse.class);
financeReimburse.setStaffId(staffInfo.getId())
financeReimburse.setStaffId(loginUserInfo.getString("id"))
.setStatus(0);
this.save(financeReimburse);
}

View File

@ -1,6 +1,5 @@
package com.cpop.oam.business.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cpop.common.constant.Constants;
import com.cpop.common.utils.StringUtils;
@ -11,7 +10,6 @@ import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo;
import com.cpop.core.base.enums.UserType;
import com.cpop.core.base.exception.ServiceException;
import com.cpop.core.base.table.SysUser;
import com.cpop.core.mapper.CoreMapper;
import com.cpop.core.service.CoreService;
import com.cpop.core.service.RedisService;
import com.cpop.core.utils.*;
@ -21,19 +19,15 @@ import com.cpop.oam.business.bo.ModifyUserPasswordBo;
import com.cpop.oam.business.bo.StaffBo;
import com.cpop.oam.business.bo.StaffPageBo;
import com.cpop.oam.business.bo.SysUserLogBo;
import com.cpop.oam.business.entity.Dept;
import com.cpop.oam.business.entity.Staff;
import com.cpop.oam.business.entity.StaffMidDept;
import com.cpop.oam.business.mapper.StaffMapper;
import com.cpop.oam.business.service.DeptService;
import com.cpop.oam.business.service.StaffMidDeptService;
import com.cpop.oam.business.service.StaffService;
import com.cpop.oam.business.vo.StaffInfoVo;
import com.cpop.oam.business.vo.StaffPageVo;
import com.cpop.oam.business.vo.StaffVo;
import com.cpop.oam.business.vo.SysOperationLogVo;
import com.cpop.oam.framework.config.wxCp.WxCpConfiguration;
import com.cpop.oam.framework.utils.OamUtils;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db;
@ -41,9 +35,7 @@ import com.mybatisflex.core.row.DbChain;
import com.mybatisflex.core.row.Row;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;
@ -52,11 +44,9 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import static com.cpop.core.base.table.table.SysOperationLogTableDef.SYS_OPERATION_LOG;
import static com.cpop.core.base.table.table.SysUserTableDef.SYS_USER;
import static com.cpop.oam.business.entity.table.DeptTableDef.DEPT;
import static com.cpop.oam.business.entity.table.StaffMidDeptTableDef.STAFF_MID_DEPT;
import static com.cpop.oam.business.entity.table.StaffTableDef.STAFF;
import static com.cpop.system.business.entity.table.RoleTableDef.ROLE;
@ -90,7 +80,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
.select(SYS_USER.USER_NAME,SYS_USER.NICK_NAME, SYS_USER.EMAIL, SYS_USER.PHONE_NUMBER, SYS_USER.SEX, SYS_USER.AVATAR, SYS_USER.STATUS, SYS_USER.PASSWORD)
.select(ROLE.ROLE_NAME)
//将部门id分组
.select(groupConcat(STAFF_MID_DEPT.DEPT_ID))
.select(groupConcat(STAFF_MID_DEPT.DEPT_ID).as(StaffPageVo::getDeptId))
.from(STAFF)
.leftJoin(SYS_USER).on(SYS_USER.ID.eq(STAFF.USER_ID))
.leftJoin(ROLE).on(ROLE.ID.eq(STAFF.ROLE_ID))
@ -332,8 +322,8 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
@Override
public void modifyUserPassword(ModifyUserPasswordBo bo) {
//只允许超级管理员或自己修改面膜
OamStaffLoginInfo loginStaffInfo = SpringUtils.getBean(OamUtils.class).getLoginStaffInfo();
String userName = loginStaffInfo.getUserName();
LoginUser loginUser = SecurityUtils.getInstance().getLoginUser();
String userName = loginUser.getUsername();
//同数据库密码进行比较
SysUser user = DbChain.table(SYS_USER)
.where(SYS_USER.ID.eq(bo.getUserId()))

View File

@ -0,0 +1,34 @@
package com.cpop.oam.framework.tasks;
import com.cpop.oam.business.service.DutyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
/**
* @author DB
* @createTime 2023/11/22 18:07
* @description
*/
@Slf4j
@Configuration
@Profile("prod")
public class OamScheduledTasks {
@Autowired
private DutyService dutyService;
/**
* @descriptions 每天9点通知值班人员
* @author DB
* @date 2023/11/22 18:08
* @return: void
*/
@Scheduled(cron = "0 0 9 * * *")
public void dutyNotice() {
dutyService.dutyNotice();
}
}

View File

@ -1,36 +0,0 @@
package com.cpop.oam.framework.utils;
import com.alibaba.fastjson.JSONObject;
import com.cpop.core.base.entity.LoginUser;
import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo;
import com.cpop.core.base.enums.UserType;
import com.cpop.core.service.RedisService;
import com.cpop.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author DB
* @createTime 2023/09/21 15:59
* @description
*/
@Component
public class OamUtils {
@Autowired
private RedisService redisService;
/**
* @descriptions 获取登陆员工信息
* @author DB
* @date 2023/09/21 16:00
* @return com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo
*/
public OamStaffLoginInfo getLoginStaffInfo() {
//获取当前登录用户信息
LoginUser loginUser = SecurityUtils.getInstance().getLoginUser();
//获取缓存信息
JSONObject jsonObject = redisService.getCacheObject(UserType.OAM_USER.getKey() + loginUser.getUsername());
return jsonObject.getJSONObject("user").toJavaObject(OamStaffLoginInfo.class);
}
}