You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-develop/src/com/engine/mzgsecond/service/impl/PortalElementCusServiceImpl...

237 lines
8.8 KiB
Java

package com.engine.mzgsecond.service.impl;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSONObject;
import com.api.doc.mobile.systemDoc.util.CategoryUtil;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.kq.biz.KQBalanceOfLeaveBiz;
import com.engine.mzgsecond.entity.BirthdayRemindVo;
import com.engine.mzgsecond.entity.PersonInfoVo;
import com.engine.mzgsecond.entity.TodoNoticeTrainVo;
import com.engine.mzgsecond.service.PortalElementCusService;
import com.engine.workflow.service.impl.RequestListServiceImpl;
import org.apache.commons.lang.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.common.database.dialect.DialectUtil;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2024/12/23 11:21 AM
* @Description: TODO
* @Version 1.0
*/
public class PortalElementCusServiceImpl extends Service implements PortalElementCusService {
@Override
public PersonInfoVo personInfo() {
RecordSet rs = new RecordSet();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
String amountId = rs.getPropValue("mzgsecond", "amountId");
String currentDate = DateUtil.getCurrentDate();
String restAmount = KQBalanceOfLeaveBiz.getRestAmount(String.valueOf(user.getUID()),amountId,currentDate);
String txAmountId = rs.getPropValue("mzgsecond", "txAmountId");
String txRestAmount = KQBalanceOfLeaveBiz.getRestAmount(String.valueOf(user.getUID()),txAmountId,currentDate);
PersonInfoVo personInfo = PersonInfoVo.builder()
.id(user.getUID())
.imageUrl(getImageFile(String.valueOf(user.getUID())))
.lastname(Util.formatMultiLang(user.getLastname(),String.valueOf(user.getLanguage())))
.jobTitle(jobTitlesComInfo.getJobTitlesname(user.getJobtitle()))
.day(0)
.amount(restAmount)
.txAmount(txRestAmount)
.performance("未开始")
.build();
String companystartdate = "";
Integer status = null;
rs.executeQuery("select companystartdate,status from hrmresource where id = ?",user.getUID());
if (rs.next()) {
companystartdate = Util.null2String(rs.getString("companystartdate"));
status = Util.getIntValue(rs.getString("status"));
}
personInfo.setStatus(getStatus(status));
if (StringUtils.isNotEmpty(companystartdate)) {
personInfo.setDay(getCompanyDay(companystartdate));
}
return personInfo;
}
@Override
public List<TodoNoticeTrainVo> todoNoticeTrain(HttpServletRequest request, HttpServletResponse response) {
RecordSet rs = new RecordSet();
List<TodoNoticeTrainVo> list = new ArrayList<>();
// 待办事项
TodoNoticeTrainVo todo = TodoNoticeTrainVo.builder()
.key("todo")
.title("待办事项")
.count(0)
.url(rs.getPropValue("mzgsecond", "todoUrl").replace("'", ""))
.build();
Map<String, Object> todoMap = ServiceUtil.getService(RequestListServiceImpl.class, user).doingCountInfo(request);
JSONObject totDatas = JSONObject.parseObject(JSONObject.toJSONString(todoMap));
if (totDatas.containsKey("totalcount")) {
JSONObject totalCount = totDatas.getJSONObject("totalcount");
String flowAll = totalCount.getString("flowAll");
todo.setCount(Convert.toInt(flowAll, 0));
}
list.add(todo);
// 通知公告
TodoNoticeTrainVo notice = TodoNoticeTrainVo.builder()
.key("notice")
.title("通知公告")
.count(0)
.url(rs.getPropValue("mzgsecond", "noticeUrl").replace("'", ""))
.build();
List<String> secCategoryList = new ArrayList<>();
String rootDirectory = rs.getPropValue("mzgsecond", "docId");
getSubdirectories(rootDirectory, secCategoryList);
Map<String, Object> params = ParamUtil.request2Map(request);
try {
params.put("secid", StringUtils.join(secCategoryList, ","));
Map<String, Object> result = CategoryUtil.getHasDocOfCategoryNum(user, CategoryUtil.NEWS_DOC, params);
String allNoReadNum = Util.null2String(result.get("allnoReadNum"));
notice.setCount(Convert.toInt(allNoReadNum, 0));
} catch (Exception e) {
rs.writeLog(e);
}
list.add(notice);
// 培训活动
TodoNoticeTrainVo train = TodoNoticeTrainVo.builder()
.key("train")
.title("培训活动")
.count(0)
.url(rs.getPropValue("mzgsecond", "trainUrl").replace("'", ""))
.build();
rs.executeQuery("select count(1) as num from uf_pxgcjl where zt = 0 ");
if (rs.next()) {
String number = rs.getString("num");
train.setCount(Convert.toInt(number, 0));
}
list.add(train);
return list;
}
@Override
public List<BirthdayRemindVo> birthdayRemind() {
List<BirthdayRemindVo> birthdayRemindVos = new ArrayList<>();
String currentMonth = DateUtil.getCurrentDate().substring(5, 7);
int day = Integer.parseInt(DateUtil.getCurrentDate().substring(8, 10));
RecordSet rs = new RecordSet();
String substrFun = ("oracle".equals(rs.getDBType()) || DialectUtil.isMySql(rs.getDBType())) ? "substr" : "substring";
rs.executeQuery("select lastname,"+substrFun+"(birthday,9,2) as days from hrmresource where birthday is not null and birthday <> ''\n" +
" and "+substrFun+"(birthday,6,2) = ? order by secLevel desc",currentMonth);
while (rs.next()) {
String lastname = Util.null2String(rs.getString("lastname"));
int days = Util.getIntValue(rs.getString("days"));
int betweenDay = days - day;
if (betweenDay >= 0) {
birthdayRemindVos.add(BirthdayRemindVo.builder()
.lastname(lastname)
.day(betweenDay)
.build());
}
}
//获取前3条数据
return birthdayRemindVos.stream()
.sorted(Comparator.comparing(BirthdayRemindVo::getDay))
.limit(3)
.collect(Collectors.toList());
}
/**
* 递归获取所有子目录
*
* @param rootDirectory
* @param seccategoryList
*/
private void getSubdirectories(String rootDirectory, List<String> seccategoryList) {
RecordSet rs = new RecordSet();
seccategoryList.add(rootDirectory);
rs.executeQuery("select id from DocSecCategory where parentid = ?", rootDirectory);
while (rs.next()) {
String id = rs.getString("id");
getSubdirectories(id, seccategoryList);
}
}
private String getStatus(int status) {
String statusName = "";
switch (status){
case 0:
statusName="试用";break;
case 1:
statusName="正式";break;
case 2:
statusName="临时";break;
case 3:
statusName="试用延期";break;
case 4:
statusName="解聘";break;
case 5:
statusName="离职";break;
case 6:
statusName="退休";break;
case 7:
statusName="无效";break;
default: statusName="未设置";
break;
}
return statusName;
}
private String getImageFile(String uId) {
String imageUrl = "";
try {
imageUrl = new ResourceComInfo().getMessagerUrls(uId);
if ("/messager/images/icon_w_wev8.jpg".equals(imageUrl) || "/messager/images/icon_m_wev8.jpg".equals(imageUrl)) {
imageUrl = "";
}
} catch (Exception e) {
e.printStackTrace();
}
return imageUrl;
}
private int getCompanyDay(String companyDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate = LocalDate.parse(companyDate, formatter);
LocalDate currentDate = LocalDate.now();
return (int)ChronoUnit.DAYS.between(startDate, currentDate);
}
}