班组签到报表

2018-07-13 02:39:41来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

  package com.bridgesoft.bims.report;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.bridgesoft.bims.jooq.db.tables.TTeamSignin.T_TEAM_SIGNIN;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import java.sql.Timestamp;
import org.jooq.Condition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.bridgesoft.bims.common.BimsUtils;
import com.bridgesoft.bims.dao.jooq.TModuleAtUserDao;
import com.bridgesoft.bims.dao.jooq.TTeamSignInDao;
import com.bridgesoft.bims.entity.UserEntity;
import com.bridgesoft.bims.entity.jooq.TModuleAtUserEntity;
import com.bridgesoft.bims.entity.jooq.TTeamSignInEntity;
import com.bridgesoft.bims.enumeration.ModuleTypeEnum;
import com.bridgesoft.bims.enumeration.TeamSignInStatus;
import com.bstek.ureport.datasource.ReportDataProvider;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Repository("bims.UserSignInReport")
public class UserSignInReport implements ReportDataProvider<Object> {
@Autowired
private TTeamSignInDao teamSignInDao;
@Autowired
private TModuleAtUserDao tModuleAtUserDao;
@Data
public class General {
private String teamName;// 单位名称
private Date beginDate;// 开始时间
private Date endDate;// 结束时间
}

@Data
public class SignInObj {
private String userName;// 签到人名
private int count;// 总数量
private String remark;// 标签
private int num;// 序号1.2.3
private String signIn1;// 签到
private String signIn2;
private String signIn3;
private String signIn4;
private String signIn5;
private String signIn6;
private String signIn7;
private String signIn8;
private String signIn9;
private String signIn10;
private String signIn11;
private String signIn12;
private String signIn13;
private String signIn14;
private String signIn15;
private String signIn16;
private String signIn17;
private String signIn18;
private String signIn19;
private String signIn20;
private String signIn21;
private String signIn22;
private String signIn23;
private String signIn24;
private String signIn25;
private String signIn26;
private String signIn27;
private String signIn28;
private String signIn29 = "";
private String signIn30 = "";
private String signIn31 = "";//可以设置为空字符串。。。

}

@Data
public class EveryDt {
private String dt1;// 日期
private String dt2;
private String dt3;
private String dt4;
private String dt5;
private String dt6;
private String dt7;
private String dt8;
private String dt9;
private String dt10;
private String dt11;
private String dt12;
private String dt13;
private String dt14;
private String dt15;
private String dt16;
private String dt17;
private String dt18;
private String dt19;
private String dt20;
private String dt21;
private String dt22;
private String dt23;
private String dt24;
private String dt25;
private String dt26;
private String dt27;
private String dt28;
private String dt29="";
private String dt30="";
private String dt31="";
}
@Override
public List<Object> provide(String source, Map<String, Object> params) {
List<Object> list = new ArrayList<>();
if (params == null || !params.containsKey("teamId") || !params.containsKey("teamName")) {
return list;
}
try {
Long teamId = Long.valueOf(params.get("teamId").toString());
String teamName = (params.get("teamName").toString());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate = format.parse(params.get("beginDate").toString());
Date endDate = BimsUtils.plusOneMonth(beginDate);// 加一个月
switch (source) {
case "general":
General general = new General();
general.setTeamName(teamName);// 单位
general.setBeginDate(beginDate);// 开始日期
general.setEndDate(endDate);// 结束日期
list.add(general);
break;
case "signInObjList":
List<SignInObj> signInList = new ArrayList<>();

List<UserEntity> userList = teamSignInDao.getUsersByTeamId(teamId);
if (userList.isEmpty() || userList.size() <= 0) {
return list;
}
int number = 1;// 序号
// 区间一个月一个组班组签到情况
List<Condition> signConds = new ArrayList<>();
signConds.add(T_TEAM_SIGNIN.CREATE_DT.between(new Timestamp(beginDate.getTime()),
new Timestamp(endDate.getTime())));
signConds.add(T_TEAM_SIGNIN.STATUS.eq(TeamSignInStatus.Accepted.name()));

List<TTeamSignInEntity> singInList = teamSignInDao.queryTeamSignByDate(signConds);
// 将班组签到转换成Map<业务ID,创建时间>
Map<Long, Date> signDtMap = singInList.stream()
.collect(Collectors.toMap(TTeamSignInEntity::getId, u -> u.getCreateDt(), (p1, p2) -> {
return p1;
}));

List<TModuleAtUserEntity> signInOneMonthList = teamSignInDao.getOneMonthList(beginDate, endDate,
teamId);

Map<Long, List<TModuleAtUserEntity>> signInOneMonthMap = signInOneMonthList.stream()
.collect(groupingBy(TModuleAtUserEntity::getAtUserId, mapping(f -> f, toList())));// 签到id对应签到情况

// 对应的每个人的当月的签到情况Map<uid,签到的日期>
Map<Long, List<Date>> userSignMap = new HashMap<>();

for (Map.Entry<Long, List<TModuleAtUserEntity>> entry : signInOneMonthMap.entrySet()) {
List<TModuleAtUserEntity> atUserList = entry.getValue();
List<Date> signDts = new ArrayList<>();
for (TModuleAtUserEntity atUserEn : atUserList) {
Long signId = atUserEn.getModuleId();
if (signDtMap != null && signDtMap.containsKey(signId)) {
Date signDt = signDtMap.get(signId);
signDts.add(signDt);
}
}
userSignMap.put(entry.getKey(), signDts);
}

for (UserEntity u : userList) {
List<String> stringList = new ArrayList<>();
List<Date> signList = new ArrayList<>();
int count = 0;
SignInObj signInObj = new SignInObj();
Long uid = u.getId();
if (userSignMap != null && userSignMap.containsKey(uid)) {
signList = userSignMap.get(uid);// 得到一个用户的一个月签到情况
} else {
signList = null;
}
stringList = teamSignInDao.sortByDate(beginDate, endDate, signList);
for (String o : stringList) {
if (o.equals("○")) {
count++;
}
}
signInObj.setUserName(u.getName());
signInObj.setSignIn1(stringList.get(0));
signInObj.setSignIn2(stringList.get(1));
signInObj.setSignIn3(stringList.get(2));
signInObj.setSignIn4(stringList.get(3));
signInObj.setSignIn5(stringList.get(4));
signInObj.setSignIn6(stringList.get(5));
signInObj.setSignIn7(stringList.get(6));
signInObj.setSignIn8(stringList.get(7));
signInObj.setSignIn9(stringList.get(8));
signInObj.setSignIn10(stringList.get(9));
signInObj.setSignIn11(stringList.get(10));
signInObj.setSignIn12(stringList.get(11));
signInObj.setSignIn13(stringList.get(12));
signInObj.setSignIn14(stringList.get(13));
signInObj.setSignIn15(stringList.get(14));
signInObj.setSignIn16(stringList.get(15));
signInObj.setSignIn17(stringList.get(16));
signInObj.setSignIn18(stringList.get(17));
signInObj.setSignIn19(stringList.get(18));
signInObj.setSignIn20(stringList.get(19));
signInObj.setSignIn21(stringList.get(20));
signInObj.setSignIn22(stringList.get(21));
signInObj.setSignIn23(stringList.get(22));
signInObj.setSignIn24(stringList.get(23));
signInObj.setSignIn25(stringList.get(24));
signInObj.setSignIn26(stringList.get(25));
signInObj.setSignIn27(stringList.get(26));
signInObj.setSignIn28(stringList.get(27));

int sSize = stringList.size();

if (sSize >= 31) {
signInObj.setSignIn31(stringList.get(30));
}
if (sSize >= 30) {
signInObj.setSignIn30(stringList.get(29));
}
if (sSize >= 29) {
signInObj.setSignIn29(stringList.get(28));
}
signInObj.setCount(count);
signInObj.setRemark("");
signInObj.setNum(number++);
signInList.add(signInObj);

}
if (signInList.size() > 0) {
list.addAll(signInList);
}
break;
case "dateList":
EveryDt everyDt = new EveryDt();
// 排序后的
List<Date> dateList = teamSignInDao.getDateListOfOneMonth(beginDate, endDate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
List<String> timeList = new ArrayList<>();
for (Date date : dateList) {
String time = sdf.format(date);
String timeSub = time.substring(8, 10);// 截取日
if (timeSub.startsWith("0")) {
timeSub = timeSub.substring(1);// 去0
}
timeList.add(timeSub);
}
everyDt.setDt1(timeList.get(0));
everyDt.setDt2(timeList.get(1));
everyDt.setDt3(timeList.get(2));
everyDt.setDt4(timeList.get(3));
everyDt.setDt5(timeList.get(4));
everyDt.setDt6(timeList.get(5));
everyDt.setDt7(timeList.get(6));
everyDt.setDt8(timeList.get(7));
everyDt.setDt9(timeList.get(8));
everyDt.setDt10(timeList.get(9));
everyDt.setDt11(timeList.get(10));
everyDt.setDt12(timeList.get(11));
everyDt.setDt13(timeList.get(12));
everyDt.setDt14(timeList.get(13));
everyDt.setDt15(timeList.get(14));
everyDt.setDt16(timeList.get(15));
everyDt.setDt17(timeList.get(16));
everyDt.setDt18(timeList.get(17));
everyDt.setDt19(timeList.get(18));
everyDt.setDt20(timeList.get(19));
everyDt.setDt21(timeList.get(20));
everyDt.setDt22(timeList.get(21));
everyDt.setDt23(timeList.get(22));
everyDt.setDt24(timeList.get(23));
everyDt.setDt25(timeList.get(24));
everyDt.setDt26(timeList.get(25));
everyDt.setDt27(timeList.get(26));
everyDt.setDt28(timeList.get(27));
int sSize = timeList.size();
if (sSize >= 31) {
everyDt.setDt31(timeList.get(30));
}
if (sSize >= 30) {
everyDt.setDt30(timeList.get(29));
}
if (sSize >= 29) {
everyDt.setDt29(timeList.get(28));
}
list.add(everyDt);
break;
}

} catch (Exception ex) {
log.error("fail to export report ", ex);

}
return list;
}

}




@Repository
public class TTeamSignInDao extends JooqBaseDao<TTeamSigninRecord, TTeamSignInEntity, Long> {
@Autowired
private TSectionDao sectionDao;
@Autowired
private TOrgDao teamDao;
@Autowired
private TWorkAreaDao workAreaDao;
@Autowired
private TUserDao userDao;
@Autowired
private TModuleFileDao moduleFileDao;
@Autowired
private TModuleAtUserDao moduleAtUserDao;
@Autowired
private TWBSDao wbsDao;
@Autowired
private ConstructionSequenceDao seqDao;
@Autowired
private TOrgUserDutyDao dutyDao;
@Autowired
private TTeamSignInAcceptDao teamSignInAcceptDao;

@Autowired
private ModuleService moduleService;

@Autowired
private ProcessService processService;

@Autowired
private TTrendDao trendDao;

@Autowired
private BimsFloService floService;

@Autowired
private GtPushService pushService;

@Autowired
private TQualitySelfInspectionDao selfInspectionDao;

@Autowired
@Qualifier(TaskService.BEAN_ID)
private TaskService taskService;

@Autowired
@Qualifier(IOrgService.BEAN_ID)
private BimsOrgService orgService;

@Override
protected Long getId(TTeamSignInEntity arg0) {
// TODO Auto-generated method stub
return null;
}

public List<TTeamSignInEntity> queryTeamSignByDate(List<Condition> signConds){
List<TTeamSignInEntity> list= getDsl().selectFrom(T_TEAM_SIGNIN).where(signConds)
.fetchInto(TTeamSignInEntity.class);

for (TTeamSignInEntity t : list) {
t.setCreateDt(BimsUtils.getDatetmsByDate(t.getCreateDt()));// 去时分秒
}

return list;
}

/**
* 获得一个月的list 排序
*
* @param teamSignInId
* @return
*/
public List<Date> getDateListOfOneMonth(Date begin, Date end) {
List<Date> dateList = new ArrayList<>();
// 得到天数
Long count = checkDate(begin, end);

Calendar calendar = Calendar.getInstance();
calendar.setTime(begin);

Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(end);

// 把每一天放在List里
dateList.add(calendar.getTime());
for (int i = 0; i < count - 1; i++) {

calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
dateList.add(calendar.getTime());
}

return dateList;
}

/**
* 查询一个班组的所有人
*/
public List<UserEntity> getUsersByTeamId(Long teamId) {

return getDsl().selectFrom(T_USER).where(T_USER.ORG_ID.eq(teamId)).fetchInto(UserEntity.class);
}

/**
* 得到一个月的签到情况
*
* @param begin
* @param end
* @return
*/
private static TModuleAtUser at = T_MODULE_AT_USER;

public List<TModuleAtUserEntity> getOneMonthList(Date begin, Date end, Long teamId) {
List<Condition> conds = new ArrayList<>();
Long beginTime = begin.getTime();
Long endTime = end.getTime();
// Map<Date,List<TModuleAtUserEntity>> list = new HashedMap();
// List<TModuleAtUserEntity> l = new ArrayList<>();
// TModuleAtUserEntity u = new TModuleAtUserEntity();

conds.add(T_TEAM_SIGNIN.CREATE_DT.between(new Timestamp(beginTime), new Timestamp(endTime)));
conds.add(T_TEAM_SIGNIN.STATUS.eq(TeamSignInStatus.Accepted.name()));
conds.add(T_TEAM_SIGNIN.TEAM_ID.eq(teamId));

conds.add(at.MODULE_TYPE.eq(ModuleTypeEnum.TeamSignIn.name()));
conds.add(at.USER_TYPE.eq("AcceptedRelatedUsers"));

List<TModuleAtUserEntity> a= getDsl().select(at.fields()).from(at).join(T_TEAM_SIGNIN)
.on(at.MODULE_ID.eq(T_TEAM_SIGNIN.ID)).where(conds).fetchInto(TModuleAtUserEntity.class);
// forEach(e->{
// Date d= e.getValue(T_TEAM_SIGNIN.CREATE_DT);
// String type = e.getValue(at.MODULE_TYPE);
// ModuleTypeEnum t = ModuleTypeEnum.valueOf(type);
// u.setMoudleType(t);
// l.add(u);
//// list.put(d, l);
// });

// for (TTeamSignInEntity t : signList) {
// t.setCreateDt(BimsUtils.getDatetmsByDate(t.getCreateDt()));// 去时分秒
// }
// List<TModuleAtUserEntity> singInOneMonthList =
// getDsl().selectFrom(T_TEAM_SIGNIN).where(conds)
// .fetchInto(TTeamSignInEntity.class);
return a;
}

/**
* 排序
*/
public List<String> sortByDate(Date begin, Date end, List<Date> signList) {

// 获得一个月排序
List<Date> dateList = getDateListOfOneMonth(begin, end);
List<String> list = new ArrayList<>();

if (signList != null) {
// for (Date t : signList) {
//
// for (Date date : dateList) {
// if (BimsUtils.getDatetmsByDate(t).contains(date)) {
// list.add("○");
// } else {
// list.add("×");
// }
// }
// }
// Map<Date, List<TModuleAtUserEntity>> signInMap = signList.stream()
// .collect(groupingBy(TModuleAtUserEntity::getCreateDt, mapping(f -> f, toList())));

for (Date date : dateList) {
if (signList.contains(date)) {
list.add("○");
} else {
list.add("×");
}
}
} else {
for (Date date : dateList) {
list.add("×");
}
}
return list;
}

/**
* 检查日期是否缺少得到相关的天数
*/
public Long checkDate(Date startDate, Date endDate) {

Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();

startTime.setTime(startDate);
endTime.setTime(endDate);

// 得到微秒级时间差
Long val = Math.abs(endTime.getTimeInMillis() - startTime.getTimeInMillis());
// 换算后得到天数
Long day = val / (1000 * 60 * 60 * 24);
return day;

}

// 查询详情公用方法
public TTeamSignInEntity getTTeamSignInEnById(Long teamSignInId) {

Long proId = BimsUtils.getCurrentProjectId();

TTeamSignInEntity entity = findById(teamSignInId);

/*
* 根据标段Id的集合取标段的集合
*/
Map<Long, SectionEntity> sectionMap = sectionDao.getNameBySectionIds(entity.getSectionId());

/*
* 根据OrgId的集合取Org的集合和班组负责人的集合
*/
Map<Long, String> orgMap = teamDao.getOrgNameMap(entity.getTeamId());

/*
* 根据wbsCode的集合取wbsName的集合
*/
Map<String, Long> wbsMap = wbsDao.getMapIdByWbsCodes(entity.getProjectId(), entity.getWbsCode());

/*
* 根据工序Code的集合取工序Name的集合
*/
Map<String, String> sequenceMap = seqDao.getSeqNameBySeqCodes(entity.getConstrSeqCode());

Map<String, TWorkAreaEntity> workAreaMap = workAreaDao.getWorkAreaMapByCodes(entity.getWorkAreaCode());

if (sectionMap != null) {
entity.setSectionName(sectionMap.get(entity.getSectionId()).getName());
entity.setSectionCode(sectionMap.get(entity.getSectionId()).getCode());
}
if (orgMap != null) {
entity.setTeamName(orgMap.get(entity.getTeamId()));
}
Map<String, Object> teamInfo = orgService.getTeamInfo(entity.getTeamId());
if (teamInfo == null || teamInfo.get("orgUserDutyName") == null) {
entity.setTeamLeader(null);
} else {
entity.setTeamLeader(teamInfo.get("orgUserDutyName").toString());
}
if (wbsMap != null) {
entity.setWbsName(selfInspectionDao.queryAllWbsName(wbsMap.get(entity.getWbsCode())));
}
if (sequenceMap != null) {
entity.setConstrSeqName(sequenceMap.get(entity.getConstrSeqCode()));
}
if (workAreaMap != null) {
entity.setWorkAreaName(workAreaMap.get(entity.getWorkAreaCode()).getName());
}

String companyName = queryCompNameByOrgId(entity.getTeamId());
entity.setCompName(companyName);

Map<String, List<TModuleAtUserEntity>> atUserMap = moduleAtUserDao
.getModuleAtUserGroupByUserType(entity.getId(), ModuleTypeEnum.TeamSignIn);

// 签到相关人员
List<TModuleAtUserEntity> relatedUsers = atUserMap.get("RelatedUsers");
String participantNames = "";
List<Long> uids = new ArrayList<>();
for (TModuleAtUserEntity tModuleAtUserEntity : relatedUsers) {
participantNames += tModuleAtUserEntity.getUserName() + ",";
uids.add(tModuleAtUserEntity.getAtUserId());
}
entity.setParticipantNames(participantNames.substring(0, participantNames.length() - 1));
entity.setRelatedUsers(relatedUsers);
entity.setParticipantIds(uids);
// 签认人员
List<TModuleAtUserEntity> signUsers = atUserMap.get("ConfirmingUserAssignee");
String signUserNames = "";
for (TModuleAtUserEntity tModuleAtUserEntity : signUsers) {
signUserNames += tModuleAtUserEntity.getUserName() + ",";
}
entity.setSignUserNames(signUserNames.substring(0, signUserNames.length() - 1));
entity.setSignUsers(signUsers);

entity.setCreateUserName(userDao.findById(entity.getCreateUserId()).getName());

List<TModuleFileEntity> fileList = moduleFileDao.getModuleFileList(entity.getId(), ModuleTypeEnum.TeamSignIn);

if (fileList != null && fileList.size() > 0) {
List<TModuleFileEntity> moduleFileAttachment = fileList.stream()
.filter(f -> f.getFileType() == FileTypeEnum.TeamAttendancePicture).collect(toList());
// 设置现场照片
entity.setModulePics(moduleFileAttachment);
// 设置现场视频
List<TModuleFileEntity> moduleFileAttachmentVideos = fileList.stream()
.filter(f -> f.getFileType() == FileTypeEnum.TeamAttendanceVideos).collect(toList());
entity.setModuleVideos(moduleFileAttachmentVideos);
}

return entity;
}

/**
* web端班组签到VIEW
*/
public void pageQuery(Page<TTeamSignInEntity> page, Collection<Condition> conditions,
Collection<? extends SortField<?>> orderCollections) {
super.pageQuery(page, conditions, orderCollections);
// 取出查询结果
Collection<TTeamSignInEntity> entitys = page.getEntities();
if (entitys == null || entitys.size() == 0) {
return;
}
// 用户
List<Long> userIds = entitys.stream().map(i -> i.getCreateUserId()).distinct().collect(toList());
Map<Long, UserEntity> userMap = userDao.getUserBasicInfo(userIds);
// 标段
List<Long> sectionIds = entitys.stream().map(i -> i.getSectionId()).distinct().collect(toList());
Map<Long, SectionEntity> sectionMap = sectionDao
.getNameBySectionIds(sectionIds.toArray(new Long[sectionIds.size()]));
// 班组
List<Long> orgIds = entitys.stream().map(i -> i.getTeamId()).distinct().collect(toList());
Map<Long, String> orgMap = teamDao.getOrgNameMap(orgIds.toArray(new Long[orgIds.size()]));
for (TTeamSignInEntity entity : entitys) {
if (sectionMap != null && sectionMap.containsKey(entity.getSectionId())) {
entity.setSectionName(sectionMap.get(entity.getSectionId()).getName());
}
if (userMap != null && userMap.containsKey(entity.getCreateUserId())) {
entity.setCreateUserName(userMap.get(entity.getCreateUserId()).getName());
}
if (orgMap != null && orgMap.containsKey(entity.getTeamId())) {
entity.setTeamName(orgMap.get(entity.getTeamId()));
}

Map<String, Object> teamInfo = orgService.getTeamInfo(entity.getTeamId());
if (teamInfo == null || teamInfo.get("orgUserDutyName") == null) {
entity.setTeamLeader(null);
} else {
entity.setTeamLeader(teamInfo.get("orgUserDutyName").toString());
}
}
}

/**
* app班组签到列表
*
* @param page
* @param conditions
* @param orderCollections
*/
public void pageQueryForApp(Page<TeamSignInItem> page, Collection<Condition> conditions,
Collection<? extends SortField<?>> orderCollections) {
if (conditions == null) {
conditions = EMPTY_CONDITION_COLLECTION;
}
if (orderCollections == null) {
orderCollections = EMPTY_SORT_COLLECTION;
}
int count = count(conditions);
page.setEntityCount(count);
int start = (page.getPageNo() - 1) * page.getPageSize();
TUser u = T_USER;
Result<Record8<Long, String, String, String, Long, Timestamp, String, String>> result = this.getDsl()
.select(T_TEAM_SIGNIN.ID, T_TEAM_SIGNIN.STATUS, T_ORG.NAME, T_SECTION.NAME,
T_TEAM_SIGNIN.CREATE_USER_ID, T_TEAM_SIGNIN.CREATE_DT, u.CHINESE_NAME, u.AVATAR_URI)
.from(T_TEAM_SIGNIN).leftJoin(T_SECTION).on(T_TEAM_SIGNIN.SECTION_ID.eq(T_SECTION.ID)).leftJoin(T_ORG)
.on(T_TEAM_SIGNIN.TEAM_ID.eq(T_ORG.ID)).leftJoin(u).on(T_TEAM_SIGNIN.CREATE_USER_ID.eq(u.ID))
.where(conditions).orderBy(orderCollections).limit(start, page.getPageSize()).fetch();
List<TeamSignInItem> dmnObjList = new ArrayList<>();
result.forEach(i -> {
TeamSignInItem obj = new TeamSignInItem();
obj.setId(i.get(T_TEAM_SIGNIN.ID));
obj.setTeamName(i.get(T_ORG.NAME));
obj.setSectionName(i.get(T_SECTION.NAME));
obj.setCreateUserId(i.get(T_TEAM_SIGNIN.CREATE_USER_ID));
obj.setCreateDt(i.get(T_TEAM_SIGNIN.CREATE_DT));
obj.setCreateUserName(i.get(u.CHINESE_NAME));
obj.setStatus(i.get(T_TEAM_SIGNIN.STATUS));
String url = i.get(u.AVATAR_URI);
if (url == null || url.equals("")) {
url = Configure.getString("bims.thumbnail.default");
}
obj.setCreateUserAvatar(BimsUtils.toAbsoluteUrl(url));
dmnObjList.add(obj);
});
page.setEntities(dmnObjList);
}

/**
* app端班组签到详情
*
* @param id
* @param type
*/
public TeamSignInDmnObj queryDetailForApp(Long id, ModuleTypeEnum type) {
TTeamSignInEntity em = this.findById(id);
TeamSignInDmnObj obj = new TeamSignInDmnObj();
obj.setId(em.getId());
Long sectionId = em.getSectionId();
obj.setSectionId(sectionId);
obj.setStatus(em.getStatus().toString());

SectionEntity secEntity = sectionDao.findById(sectionId);
if (secEntity != null) {
obj.setSectionCode(secEntity.getCode());
obj.setSectionName(secEntity.getName());
} else {
obj.setSectionCode(null);
obj.setSectionName(null);
}
String companyName = queryCompNameByOrgId(em.getTeamId());
obj.setCompanyName(companyName);

Long teamId = em.getTeamId();
obj.setTeamId(teamId);
// 班组名
String teamName = teamDao.getOrgNameMap(teamId).get(teamId);
obj.setTeamName(teamName);
// 班组长
Map<String, Object> teamInfo = orgService.getTeamInfo(em.getTeamId());
if (teamInfo == null || teamInfo.get("orgUserDutyName") == null) {
obj.setTeamLeader(null);
} else {
obj.setTeamLeader(teamInfo.get("orgUserDutyName").toString());
}

Long proId = BimsUtils.getProjectIdFromParams(null);
// 分部分项
String wbsCode = em.getWbsCode();
Map<String, Long> wbsMap = wbsDao.getMapIdByWbsCodes(em.getProjectId(), wbsCode);
String wbsName = selfInspectionDao.queryAllWbsName(wbsMap.get(wbsCode));
obj.setWbsCode(wbsCode);
obj.setWbsName(wbsName);
// 工序
String seqCode = em.getConstrSeqCode();
String seqName = seqDao.getSeqNameBySeqCodes(seqCode).get(seqCode);
obj.setConstrSeqCode(seqCode);
obj.setConstrSeqName(seqName);
// 工区
String areaCode = em.getWorkAreaCode();
String areaName = workAreaDao.getWorkAreaMapByCodes(areaCode).get(areaCode).getName();
obj.setWorkAreaCode(areaCode);
obj.setWorkAreaName(areaName);
Long moduleId = em.getId();
Map<String, List<TModuleAtUserEntity>> atUserMap = moduleAtUserDao.getModuleAtUserGroupByUserType(moduleId,
ModuleTypeEnum.TeamSignIn);
// 签到相关人员
List<TModuleAtUserEntity> relatedUsers = atUserMap.get("RelatedUsers");
for (TModuleAtUserEntity userFiles : relatedUsers) {
UserEntity user = userDao.findById(userFiles.getAtUserId());
if (user != null) {
String path = user.getAvatarUri();
String name = user.getName();
if (path == null) {
userFiles.setUserAvator(BimsUtils.toAbsoluteUrl(Configure.getString("bims.thumbnail.default")));
}
userFiles.setUserName(name);
}
}
obj.setRelatedUsers(relatedUsers);

List<TModuleAtUserEntity> acceptedRelatedUsers = atUserMap.get("AcceptedRelatedUsers");
if (acceptedRelatedUsers != null && acceptedRelatedUsers.size() > 0) {
for (TModuleAtUserEntity userFiles : acceptedRelatedUsers) {
UserEntity user = userDao.findById(userFiles.getAtUserId());
if (user != null) {
String path = user.getAvatarUri();
String name = user.getName();
if (path == null) {
userFiles.setUserAvator(BimsUtils.toAbsoluteUrl(Configure.getString("bims.thumbnail.default")));
}
userFiles.setUserName(name);
}
}
obj.setAcceptedRelatedUsers(acceptedRelatedUsers);
}

List<TModuleAtUserEntity> signUsers = atUserMap.get("ConfirmingUserAssignee");
String signUserNames = "";
for (TModuleAtUserEntity tModuleAtUserEntity : signUsers) {
signUserNames += tModuleAtUserEntity.getUserName() + ",";
}
obj.setSignUserNames(signUserNames.substring(0, signUserNames.length() - 1));
obj.setSignUsers(signUsers);

obj.setLocation(em.getLocation());
Map<FileTypeEnum, List<FileEntity>> fileListMap = moduleFileDao.getModuleFileMap(em.getId(), type);
Map<FileTypeEnum, List<FileEntity>> fileMap = moduleFileDao.updateModuleFileUrl(fileListMap);// 改变路径
obj.setModulePics(fileMap.containsKey(FileTypeEnum.TeamAttendancePicture)
? fileMap.get(FileTypeEnum.TeamAttendancePicture) : new ArrayList<>());
obj.setFileVideos(fileMap.containsKey(FileTypeEnum.TeamAttendanceVideos)
? fileMap.get(FileTypeEnum.TeamAttendanceVideos) : new ArrayList<>());
// 用户名称
Long createUserId = em.getCreateUserId();
Map<Long, String> userMap = userDao.getUserNameMap(createUserId);
obj.setCreateUserName(userMap.get(createUserId));
// 创建日期
obj.setCreateDt(em.getCreateDt());
obj.setCreateUserId(createUserId);

if (em.getStatus() == TeamSignInStatus.Accepted) {
TTeamSignInAcceptEntity teamSignInAcceptEn = teamSignInAcceptDao.queryAllAcceptEnBySignId(em.getId());
obj.setTeamSignInAcceptEn(teamSignInAcceptEn);
}

return obj;
}

/**
*
* 操作参与人员TModuleAtUserEntity表
*
* @param edumeeting
* @param type
*/
public void saveModuleUser(TTeamSignInEntity edumeeting, ModuleTypeEnum type) {
if (edumeeting.getRelatedUsers() != null && edumeeting.getRelatedUsers().size() > 0) {
List<TModuleAtUserEntity> moduleUserList = edumeeting.getRelatedUsers();
deleteUserlessParticipant(edumeeting.getId(), type);
for (TModuleAtUserEntity moduleUser : moduleUserList) {
moduleUser.setModuleId(edumeeting.getId());
moduleUser.setMoudleType(type);
moduleUser.setUserType("RelatedUsers");
moduleAtUserDao.insert(moduleUser);
}
}
}

/**
* 操作对应的中间表,对参与人员进行无用数据删除操作
*
* @param edumeeting
*/
public void deleteUserlessParticipant(Long moduleId, ModuleTypeEnum type) {
List<TModuleAtUserEntity> users = moduleAtUserDao.getModuleAtUserList(moduleId, type);
for (TModuleAtUserEntity tModuleAtUserEntity : users) {
if (tModuleAtUserEntity.getUserType().equals("RelatedUsers")) {
moduleAtUserDao.delete(tModuleAtUserEntity);
}
}
}

private static TModuleAtUser atTbl = T_MODULE_AT_USER;

/**
* 开启班组签到工作流
*
* @param teamSignIn
*/
public void startTeamSignInProcessInfo(TTeamSignInEntity teamSignIn, UserEntity user, boolean isWeb) {
/**
* 开启工作流
*/
StartProcessInfo pInfo = new StartProcessInfo();
pInfo.setBusinessId(String.valueOf(teamSignIn.getId()));
pInfo.setCompleteStartTask(true);
pInfo.setPromoter(user.getId().toString());

List<TModuleAtUserEntity> signUsers = teamSignIn.getSignUsers();

Map<String, Object> vars = new HashMap<>();
vars.put("confirmingUserAssignee", moduleService.getUserIdsByUserType(signUsers, "ConfirmingUserAssignee"));// 绑定设计意见的用户
pInfo.setVariables(vars);

if (isWeb) {
for (TModuleAtUserEntity tModuleAtUserEntity : signUsers) {
tModuleAtUserEntity.setModuleId(teamSignIn.getId());
}
moduleService.saveModuleAtUsers(signUsers);
} else {
for (TModuleAtUserEntity tModuleAtUserEntity : signUsers) {
tModuleAtUserEntity.setModuleId(teamSignIn.getId());
moduleAtUserDao.insert(tModuleAtUserEntity);
}
}

ProcessInstance processInst = processService.startProcessByName(BimsConstants.FLO_PROCESS_TEAM_SIGN_IN_HANDOVER,
pInfo);// 开启流

// 添加动态
@SuppressWarnings("unchecked")
Map<String, Object> data = new HashedMap();
data.put("teamSignInId", teamSignIn.getId());
data.put("isView", true);
trendDao.addTrend("新增班组签到", user.getDefaultProjectId(), user.getId(), BimsConstants.TREND_MODULE_TEAM_SIGN_IN,
data, teamSignIn.getId());

List<Long> uids = moduleAtUserDao.getDsl().select(atTbl.AT_USER_ID).from(atTbl)
.where(atTbl.MODULE_TYPE.eq("TeamSignIn").and(atTbl.MODULE_ID.eq(teamSignIn.getId())))
.fetchInto(Long.class);
pushMessageToUsers(uids);
}

/**
* 发送消息
*
* @param proId
*/
public void pushMessageToUsers(List<Long> uids) {
String title = "班组签到";
String message = "有新的班组签到产生,详情请登录BIM协同平台查看。";
Boolean isAutoBadge = false;
pushService.pushToUsers(title, message, null, isAutoBadge, uids);
}

/**
* 根据对应的班组签到Id对班组签到进行删除(APP和WEB都可以用)
*
* @param teamSignInId
*
*/
public int delectTeamSignInDaoById(Long teamSignInId) {

/**
* 删除流程实例
*/
floService.deleteProcessInstanceByBusinessId(BimsConstants.FLO_PROCESS_TEAM_SIGN_IN_HANDOVER, teamSignInId);

moduleAtUserDao.deleteAllModuleAtUsers(teamSignInId, ModuleTypeEnum.TeamSignIn);

/**
* 删除的质量三检
*/
int delResult = deleteById(teamSignInId);

// 删除动态
trendDao.deleteTrend(BimsConstants.TREND_MODULE_TEAM_SIGN_IN, teamSignInId);

return delResult;
}

/**
* 开始真正处理task
*
* @param opinionEn
*/
public void proceedTask(Long taskId, Long uId, String nodeName) {
Task task = floService.getTaskById(taskId);
boolean needStart = false;
if (TaskType.Participative.equals(task.getType())) {
if (StringUtils.isBlank(task.getAssignee())) {
taskService.claim(taskId, uId.toString());
needStart = true;
}
} else {
taskService.changeTaskAssignee(taskId, uId.toString());
}

if (needStart || TaskState.Created.equals(task.getState()) || TaskState.Reserved.equals(task.getState())) {
taskService.start(taskId);
}

taskService.forward(taskId, nodeName);
}

/**
* 获取默认新增参数
*
* @return
*/
public Map<String, Object> getUserInfo() {
UserEntity user = (UserEntity) BimsCoreUtils.getCurrentUser();
Map<String, Object> map = getTeamInfo(user.getOrgId());
boolean isDuty = checkUserPermission(user);
if (isDuty) {
map.put("isDuty", true);
map.put("teamName", map.get("orgName"));
map.put("teamLeader", map.get("orgUserDutyName"));
map.put("compName", map.get("compName"));
map.put("createUserId", user.getId());
map.put("createUserName", user.getName());

}
return map;
}

/**
* 当前登录人是否有权限添加
*
* @return
*/
public boolean checkUserPermission(UserEntity user) {
if (user != null) {
TOrgEntity orgEn = teamDao.findById(user.getOrgId());
if (OrgTypeEnum.Team.equals(orgEn.getType())) {
if (BimsConstants.DUTY_TEAM_LEADER.equals(user.getDutyId())) {
return true;
}
}

}
return false;
}

/**
* 根据登录人获取班组,标段,班组长,是否有权限添加
*
* @return
*/
public Map<String, Object> getTeamInfo(long orgId) {

Map<String, Object> info = new HashMap<>();

TOrgEntity orgEntity = teamDao.findById(orgId);

/**
* 判断当前登录人所属的是否为班组
*/
if (orgEntity.getType().equals(OrgTypeEnum.Team)) {

String companyName = queryCompNameByOrgId(orgId);

/**
* 通过承包公司Id查询相应的标段,业务需求上,一个公司应该只承包一个标段
*/
SectionEntity sectionEntity = orgService.getSectionByOrgId(orgId);
if (sectionEntity != null) {
String sectionName = sectionEntity.getName();
Long sectionId = sectionEntity.getId();
String sectionCode = sectionEntity.getCode();
info.put("sectionId", sectionId);// 标段Id
info.put("sectionCode", sectionCode);// 标段Id
info.put("sectionName", sectionName);// 标段名称
} else {
info.put("sectionId", null);// 标段Id
info.put("sectionCode", null);// 标段Id
info.put("sectionName", null);// 标段名称
}

TUser u = T_USER;
List<String> dutyList = new ArrayList<>();
dutyList.add(BimsConstants.DUTY_TEAM_LEADER);
dutyList.add(BimsConstants.DUTY_CONSTRUCTION_ENGINEER);
String orgUserDutyName = teamDao.getDsl().select(u.CHINESE_NAME).from(u)
.where(u.DUTY_ID.eq(BimsConstants.DUTY_TEAM_LEADER)).and(u.ORG_ID.eq(orgId)).orderBy(u.ID).limit(1)
.fetchOne(u.CHINESE_NAME);
info.put("teamId", orgId);// 班组Id
info.put("orgUserDutyName", orgUserDutyName);// 班组长名称

info.put("orgName", orgEntity.getName());// 班组名称

info.put("compName", companyName);// 班组名称
}

return info;
}

/**
* 查询班组的直系公司名字
*
* @param orgId
* @return
*/
public String queryCompNameByOrgId(Long orgId) {
TOrg t = T_ORG;
Long companyId = teamDao.getDsl().select(t.COMPANY_ID).from(t).where(t.ID.eq(orgId)).fetchOneInto(Long.class);
return teamDao.getDsl().select(t.NAME).from(t).where(t.ID.eq(companyId)).fetchOneInto(String.class);
}

}
直接取组长一个月的签到时间。
判断组员签到表的签到情况和时间是否。
生成一个<Long,list<date>>类型的MAP来实现功能

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Spring Boot 注入外部配置到应用内部的静态变量

下一篇:Java中的File.separator用法