214 lines
7.4 KiB
Plaintext
214 lines
7.4 KiB
Plaintext
package com.securityControl.task.service.impl;
|
|
|
|
import com.securityControl.common.core.utils.aes.DateTimeHelper;
|
|
import com.securityControl.common.core.utils.aes.ListHelper;
|
|
|
|
import com.securityControl.task.domain.vo.ClassMettingCheckVo;
|
|
import com.securityControl.task.domain.vo.JjPeoson;
|
|
import com.securityControl.task.domain.vo.UserVo;
|
|
import com.securityControl.task.domain.vo.WorkTeamVo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import sun.awt.geom.AreaOp;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* 班组定时器
|
|
*/
|
|
@Service
|
|
@Slf4j
|
|
public class WorkTeamSchedule {
|
|
|
|
|
|
@Autowired
|
|
private TaskScheduleService service;
|
|
|
|
/**
|
|
* 站班会自动分配给人员
|
|
*/
|
|
public void classMettingZdFp(){
|
|
try{
|
|
List<UserVo> zzUser=new ArrayList<>();//要分配的用户
|
|
List<UserVo> isFPUser=new ArrayList<>();//要分配的用户
|
|
List<UserVo> isBDZuser=new ArrayList<>();//要分配的变电站用户
|
|
List<UserVo> delUser=new ArrayList<>();//已分配要删除的用户
|
|
String type=getRoundMath();
|
|
List<UserVo> users=service.getAllDcUsers(type); //查询督查人员找账号 dcry-001
|
|
if(ListHelper.isNotEmpty(users)){
|
|
fpUserList(users,isFPUser,delUser,isBDZuser,zzUser);//数据分为两种
|
|
delUser(delUser);//清空已分配数据
|
|
}//数据划分
|
|
//只有一个会分配建设部的 两个就不会分配了
|
|
if(ListHelper.isNotEmpty(zzUser)&& zzUser.size()==1 ){//专责不是 空的
|
|
delNotJsbUser(zzUser);//删除非建设部数据
|
|
insertZZCheck(zzUser.get(0).getId());//对缺少的进行补
|
|
}
|
|
Integer allNum=service.getAllClassNum();//全部站班会数量
|
|
List<String> classes=service.getWfpList(null);//查询未分配的站班会
|
|
if(ListHelper.isNotEmpty(classes) && ListHelper.isNotEmpty(isFPUser) ){
|
|
int num=allNum/isFPUser.size();// 按照全部数据 每个人是多少
|
|
if(num>0){
|
|
for (UserVo user:isFPUser) {//先按照平准数量分配
|
|
Integer fpNum=service.getFpNum(user.getId());
|
|
if(fpNum==null){
|
|
fpNum=0;
|
|
}
|
|
if(num-fpNum>0){
|
|
insertCheck(num-fpNum,user.getId());//对缺少的进行补
|
|
}
|
|
}
|
|
}
|
|
for (UserVo user:isFPUser) {//先按照平准数量分配
|
|
insertCheck(1,user.getId());
|
|
}
|
|
}
|
|
//分配 质量专员
|
|
List<String> bdzList=service.getBDZlist(null);//查询未分配的变电站工程
|
|
Integer allBdzNum=service.getAllBDZClassNum();
|
|
if(ListHelper.isNotEmpty(bdzList) && ListHelper.isNotEmpty(isBDZuser) ) {
|
|
int num = allBdzNum / isBDZuser.size();// 按照全部数据 每个人是多少
|
|
if (num > 0) {
|
|
for (UserVo user : isBDZuser) {//先按照平准数量分配
|
|
Integer fpNum = service.getFpNum(user.getId());
|
|
if (num - fpNum > 0) {
|
|
insertBDZCheck(num - fpNum, user.getId());//对缺少的进行补
|
|
}
|
|
}
|
|
}
|
|
for (UserVo user : isBDZuser) {//先按照平准数量分配
|
|
insertBDZCheck(1, user.getId());
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.info("自动分配异常");
|
|
log.error(e.toString(),e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void insertZZCheck(String userId) {
|
|
List<String> fpc=service.getJsbList(userId);//查询未分配的站班会
|
|
if(ListHelper.isNotEmpty(fpc)){
|
|
ClassMettingCheckVo check=new ClassMettingCheckVo();
|
|
check.setCheckUser(userId);
|
|
check.setIsCheck("0");
|
|
check.setQuality("AU");
|
|
check.setIsPj("0");
|
|
check.setCheckTime("0");
|
|
check.setCreateTime(DateTimeHelper.getNowDate());
|
|
service.insertCheck(check,fpc);
|
|
}
|
|
}
|
|
|
|
private void delNotJsbUser(List<UserVo> zzUser) {
|
|
for (UserVo user:zzUser) {
|
|
Integer num= service.delNotJsbUser(user);
|
|
Integer num2= service.delNsbUser(user);//删除非专责用户 已分配的 建设部数据
|
|
System.err.println(num+"----->"+num2);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 分配用户
|
|
* @param users
|
|
* @param isFPUser
|
|
* @param delUser
|
|
*/
|
|
public void fpUserList(List<UserVo> users, List<UserVo> isFPUser, List<UserVo> delUser,List<UserVo> bdzUser, List<UserVo> zzUser){
|
|
for (UserVo user:users) {//先按照平准数量分配
|
|
if("0".equals(user.getCommissioner())){//不是转机
|
|
if("1".equals(user.getQuality())){//质量专员
|
|
bdzUser.add(user);
|
|
}else{
|
|
if("1".equals(user.getOnDuty())){//在职的
|
|
isFPUser.add(user);
|
|
}else{
|
|
delUser.add(user);//不在职的
|
|
}
|
|
}
|
|
}else{
|
|
zzUser.add(user);//专责
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除已分配的用户
|
|
* @param delUser
|
|
*/
|
|
public void delUser(List<UserVo> delUser){
|
|
try{
|
|
if(ListHelper.isNotEmpty(delUser)){
|
|
for (UserVo user:delUser) {
|
|
service.delUser(user);//将已分配的数据进行删除
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String getRoundMath(){
|
|
try{
|
|
Random random=new Random();
|
|
int result=random.nextInt(4);
|
|
return result+1+"";
|
|
}catch (Exception e){
|
|
|
|
}
|
|
return "0";
|
|
}
|
|
|
|
public void insertBDZCheck(Integer num,String user){
|
|
List<String> fpc=service.getBDZlist(num);//查询未分配的站班会
|
|
if(ListHelper.isNotEmpty(fpc)){
|
|
ClassMettingCheckVo check=new ClassMettingCheckVo();
|
|
check.setCheckUser(user);
|
|
check.setIsCheck("0");
|
|
check.setQuality("QU");
|
|
check.setIsPj("0");
|
|
check.setCheckTime("0");
|
|
check.setCreateTime(DateTimeHelper.getNowDate());
|
|
service.insertCheck(check,fpc);
|
|
}
|
|
}
|
|
|
|
|
|
public void insertCheck(Integer num,String user){
|
|
List<String> fpc=service.getWfpList(num);//查询未分配的站班会
|
|
if(ListHelper.isNotEmpty(fpc)){
|
|
ClassMettingCheckVo check=new ClassMettingCheckVo();
|
|
check.setCheckUser(user);
|
|
check.setIsCheck("0");
|
|
check.setQuality("AU");
|
|
check.setIsPj("0");
|
|
check.setCheckTime("0");
|
|
check.setCreateTime(DateTimeHelper.getNowDate());
|
|
service.insertCheck(check,fpc);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 更新用户初始化信息
|
|
*/
|
|
public void updaeUserInformation() {
|
|
try{
|
|
service.updaeUserInformation();
|
|
}catch (Exception e){
|
|
log.error(e.toString(),e);
|
|
}
|
|
}
|
|
}
|