Pārlūkot izejas kodu

年假审批后修改人员状态

yanliming 1 gadu atpakaļ
vecāks
revīzija
504f00aeac

+ 2 - 0
common/src/main/java/com/jpsoft/shinestar/modules/business/service/YearRequestForLeaveInfoService.java

@@ -14,6 +14,8 @@ public interface YearRequestForLeaveInfoService {
 	boolean exist(String id);
 	int insert(YearRequestForLeaveInfo model);
 	int update(YearRequestForLeaveInfo model);
+	void updatePersonWorkStatus(YearRequestForLeaveInfo yearRequestForLeaveInfo);
+	void logic(YearRequestForLeaveInfo yearRequestForLeaveInfo) throws Exception;
 	int delete(String id);
 	List<YearRequestForLeaveInfo> list();
 	Page<YearRequestForLeaveInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);

+ 70 - 0
common/src/main/java/com/jpsoft/shinestar/modules/business/service/impl/YearRequestForLeaveInfoServiceImpl.java

@@ -14,6 +14,7 @@ import com.jpsoft.shinestar.modules.base.service.ApprovalConfigService;
 import com.jpsoft.shinestar.modules.base.service.CompanyInfoService;
 import com.jpsoft.shinestar.modules.base.service.PersonInfoService;
 import com.jpsoft.shinestar.modules.base.service.PersonPopedomService;
+import com.jpsoft.shinestar.modules.business.dto.UpdatePersonAttendanceDTO;
 import com.jpsoft.shinestar.modules.common.utils.JwtUtil2;
 import com.jpsoft.shinestar.modules.common.utils.WechatMessageUtil;
 import com.jpsoft.shinestar.modules.workflow.entity.ProcinstActUser;
@@ -21,6 +22,7 @@ import com.jpsoft.shinestar.modules.workflow.entity.ProcinstActivity;
 import com.jpsoft.shinestar.modules.workflow.service.ProcinstActUserService;
 import com.jpsoft.shinestar.modules.workflow.service.ProcinstActivityService;
 import com.jpsoft.shinestar.modules.workflow.service.ProcinstService;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.joda.time.DateTime;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -37,6 +39,7 @@ import com.github.pagehelper.PageHelper;
 
 @Transactional
 @Component(value="yearRequestForLeaveInfoService")
+@Slf4j
 public class YearRequestForLeaveInfoServiceImpl implements YearRequestForLeaveInfoService {
 	@Resource(name="yearRequestForLeaveInfoDAO")
 	private YearRequestForLeaveInfoDAO yearRequestForLeaveInfoDAO;
@@ -130,6 +133,73 @@ public class YearRequestForLeaveInfoServiceImpl implements YearRequestForLeaveIn
 	}
 
 
+	@Override
+	public void logic(YearRequestForLeaveInfo yearRequestForLeaveInfo) throws Exception {
+		//更新人员工作状态
+		updatePersonWorkStatus(yearRequestForLeaveInfo);
+
+		Date now = new Date();
+		if (yearRequestForLeaveInfo.getStartTime().before(now)) {
+			PersonPopedom personPopedom = personPopedomService.get(yearRequestForLeaveInfo.getPersonPopedomId());
+			PersonInfo personInfo = personInfoService.get(personPopedom.getPersonId());
+
+			UpdatePersonAttendanceDTO updatePersonAttendanceDTO = new UpdatePersonAttendanceDTO(
+					personInfo.getId(), yearRequestForLeaveInfo.getStartTime(),yearRequestForLeaveInfo.getEndTime());
+
+			rabbitTemplate.convertAndSend("updatePersonAttendanceQueue", updatePersonAttendanceDTO);
+		}
+	}
+
+	@Override
+	public void updatePersonWorkStatus(YearRequestForLeaveInfo yearRequestForLeaveInfo) {
+		try{
+			PersonPopedom personPopedom = personPopedomService.get(yearRequestForLeaveInfo.getPersonPopedomId());
+			PersonInfo personInfo = personInfoService.get(personPopedom.getPersonId());
+
+			Date now = new Date();
+
+			//如果出差开始时间<=当前时间,说明是补出差记录,可能正在出差
+			if (yearRequestForLeaveInfo.getStartTime().compareTo(now) <=0){
+				personInfo.setWorkStatus("7");
+				personInfoService.update(personInfo);
+			}
+			else {
+				//如果出差开始开始时间>当前时间,则延时修改状态
+				long millisecond = DateUtil.betweenMs(now,yearRequestForLeaveInfo.getStartTime());
+
+				log.warn("创建延时队列修改工作状态,id:"+yearRequestForLeaveInfo.getId());
+
+				rabbitTemplate.convertAndSend("businessOutDelayExchange", "businessOutSubmit",
+						yearRequestForLeaveInfo.getId(), (message)->{
+							message.getMessageProperties().setHeader("x-delay",millisecond);
+							return message;
+						});
+			}
+
+			if(yearRequestForLeaveInfo.getEndTime()!=null) {
+				//如果年假结束时间<=当前时间,说明年假结束
+				if (yearRequestForLeaveInfo.getEndTime().compareTo(now) <= 0) {
+					personInfo.setWorkStatus("1");
+					personInfoService.update(personInfo);
+				} else {
+					//如果出差结束时间>当前时间,则延时修改状态
+					long millisecond = DateUtil.betweenMs(now, yearRequestForLeaveInfo.getEndTime())+60000;
+
+					log.warn("创建延时队列修改工作状态,id:" + yearRequestForLeaveInfo.getId());
+
+					rabbitTemplate.convertAndSend("businessOutDelayExchange", "businessOutSubmit",
+							yearRequestForLeaveInfo.getId(), (message) -> {
+								message.getMessageProperties().setHeader("x-delay", millisecond);
+								return message;
+							});
+				}
+			}
+		}catch (Exception ex){
+			log.error(ex.getMessage(),ex);
+		}
+	}
+
+
 	@Override
 	public String leaveSubmit(PersonPopedom personPopedom, String startTime, String endTime, String startTimeQuantum, String endTimeQuantum, String imageUrl, String reason, String days, String formId, String activity, String draft, String id) throws Exception {
 		try {

+ 8 - 4
common/src/main/java/com/jpsoft/shinestar/modules/workflow/service/impl/ProcinstActUserServiceImpl.java

@@ -1325,19 +1325,23 @@ public class ProcinstActUserServiceImpl implements ProcinstActUserService {
                                 String statusN = "";
                                 if ("1".equals(yearRequestForLeaveInfo1.getStatus())) {
                                     statusN = "同意";
+
+                                    try {
+                                        //出差修改人员状态
+                                        yearRequestForLeaveInfoService.logic(yearRequestForLeaveInfo1);
+                                    } catch (Exception ex) {
+                                        ex.printStackTrace();
+                                    }
                                 }
                                 if ("3".equals(yearRequestForLeaveInfo1.getStatus())) {
                                     statusN = "拒绝";
                                 }
-                                PersonPopedom personPopedom1 = personPopedomService.findByIdIgnoreDel(yearRequestForLeaveInfo1.getPersonPopedomId());
 
-                                PersonInfo person = personInfoService.findByIdIgnoreDel(personPopedom1.getPersonId());
+                                PersonInfo person = personInfoService.get(yearRequestForLeaveInfo1.getPersonId());
 
                                 String accessToken = JwtUtil2.createToken(jwtSecret, person.getId() + "", DateTime.now().plusHours(30 * 24).toDate());
                                 WechatMessageUtil.sendExamine(person.getOpenId(), "年假审核" + statusN, person.getName(), "1", statusN, "年假", "前往查看", wxConfig.getPortalUrl() + "xsy/approval/info?id=" + yearRequestForLeaveInfo1.getId() + "&formId=" + processSet.getFormId() + "&token=" + accessToken, wxConfig.getAppId(), wxConfig.getAppSecret());
                             }).start();
-
-
                         }
                     }
                 }