package cn.com.goldenwater.dcproj.service.impl.tac; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.TacInspYearBatchGroupPersDao; import cn.com.goldenwater.dcproj.dao.TacWorkerBDao; import cn.com.goldenwater.dcproj.dto.TacInspYearBatchGroupDto; import cn.com.goldenwater.dcproj.model.BisInspAllRlation; import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroupPers; import cn.com.goldenwater.dcproj.model.TacWorkerB; import cn.com.goldenwater.dcproj.param.TacInspYearBatchGroupPersParam; import cn.com.goldenwater.dcproj.param.TacWorkerBParam; import cn.com.goldenwater.dcproj.service.TacInspYearBatchGroupPersService; import cn.com.goldenwater.dcproj.utils.BeanUtil; import cn.com.goldenwater.dcproj.utils.DateUtils; import cn.com.goldenwater.id.util.UuidUtil; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; /** * @author lune * @date 2019-9-6 */ @Service @Transactional(rollbackFor = Exception.class) public class TacInspYearBatchGroupPersServiceImpl extends AbstractCrudService implements TacInspYearBatchGroupPersService { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private TacInspYearBatchGroupPersDao tacInspYearBatchGroupPersDao; @Autowired private TacWorkerBDao tacWorkerBDao; public TacInspYearBatchGroupPersServiceImpl(TacInspYearBatchGroupPersDao tacInspYearBatchGroupPersDao) { super(tacInspYearBatchGroupPersDao); this.tacInspYearBatchGroupPersDao = tacInspYearBatchGroupPersDao; } @Override public int updateGroupPers(TacInspYearBatchGroupDto groupDto) { if (StringUtils.isBlank(groupDto.getGroupId())) { return 0; } if (groupDto.getBs() != null) { for (TacWorkerB workerB : groupDto.getBs()) { TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam(); groupPersParam.setYearBatchId(groupDto.getBatchId()); groupPersParam.setPersId(workerB.getId()); groupPersParam.setRoleType(workerB.getRoleTypeList().get(0).getValue()); List persList = tacInspYearBatchGroupPersDao.findList(groupPersParam); if (persList.size() == 1) { TacInspYearBatchGroupPers pers = persList.get(0); if (StringUtils.isBlank(pers.getGroupId())) { pers.setGroupId(groupDto.getGroupId()); pers.setGroupNm(groupDto.getGroupNm()); pers.setSendsmsTm(null); pers.setIsJoin("0"); pers.setIsNotice("0"); pers.setIsSms("0"); tacInspYearBatchGroupPersDao.update(pers); } else { TacInspYearBatchGroupPers newPers = new TacInspYearBatchGroupPers(); BeanUtil.copyObject1(pers, newPers); newPers.setId(UuidUtil.uuid()); newPers.setInTm(new Date()); newPers.setUpTm(new Date()); newPers.setDataStat("0"); newPers.setGroupId(groupDto.getGroupId()); newPers.setGroupNm(groupDto.getGroupNm()); pers.setIsJoin("0"); pers.setIsNotice("0"); pers.setIsSms("0"); tacInspYearBatchGroupPersDao.insert(newPers); } } else { TacInspYearBatchGroupPers pers = persList.get(0); TacInspYearBatchGroupPers newPers = new TacInspYearBatchGroupPers(); BeanUtil.copyObject1(pers, newPers); newPers.setId(UuidUtil.uuid()); newPers.setInTm(new Date()); newPers.setUpTm(new Date()); newPers.setDataStat("0"); newPers.setGroupId(groupDto.getGroupId()); newPers.setGroupNm(groupDto.getGroupNm()); pers.setIsJoin("0"); pers.setIsNotice("0"); pers.setIsSms("0"); tacInspYearBatchGroupPersDao.insert(newPers); } } } if (groupDto.getUpdateBs() != null) { for (TacWorkerB workerB : groupDto.getUpdateBs()) { TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam(); groupPersParam.setYearBatchId(groupDto.getBatchId()); groupPersParam.setPersId(workerB.getId()); groupPersParam.setRoleType(workerB.getRoleTypeList().get(0).getValue()); List persList = tacInspYearBatchGroupPersDao.findList(groupPersParam); if (persList.size() == 1) { TacInspYearBatchGroupPers pers = persList.get(0); pers.setGroupId(""); pers.setGroupNm(null); pers.setSendsmsTm(null); pers.setIsJoin("0"); pers.setIsNotice("0"); pers.setIsSms("0"); tacInspYearBatchGroupPersDao.update(pers); } else if (persList.size() > 1) { persList.forEach(tacInspYearBatchGroupPers -> { if (groupDto.getGroupId().equals(tacInspYearBatchGroupPers.getGroupId())) { tacInspYearBatchGroupPersDao.delete(tacInspYearBatchGroupPers.getId()); } }); } } } return 0; } @Override public List findPersList(TacInspYearBatchGroupPersParam param) { List list = tacInspYearBatchGroupPersDao.findPersList(param); return list; } @Override public int updateGroupPersInfo(TacInspYearBatchGroupPers group) { if (StringUtils.isNotBlank(group.getIsJoin())) { group.setDataStat(group.getIsJoin()); } tacInspYearBatchGroupPersDao.update(group); return 1; } @Override public TacInspYearBatchGroupPers getGroupPerByCode(TacInspYearBatchGroupPers group) { TacWorkerBParam bParam = new TacWorkerBParam(); bParam.setMobilenumb(group.getPhone()); bParam.setProvince(group.getProvince()); TacWorkerB b = tacWorkerBDao.getBy(bParam); if (b == null) { return null; } TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam(); groupPersParam.setYearBatchId(group.getYearBatchId()); groupPersParam.setPersId(b.getId()); TacInspYearBatchGroupPers groupPers = tacInspYearBatchGroupPersDao.getBy(groupPersParam); if (groupPers == null) { return null; } groupPers.setPersName(b.getName()); return groupPers; } @Override public int confirmerGroupPers(Map contentMap) { TacInspYearBatchGroupPersParam sqlGroupPers= new TacInspYearBatchGroupPersParam(); logger.info("已接收回复"); //满足条件为已通知,已成功发送短信,是否参加为初始默认值 sqlGroupPers.setIsSms("1"); sqlGroupPers.setIsNotice("1"); sqlGroupPers.setIsJoin("0"); sqlGroupPers.setPhone(contentMap.get("phone_number").toString()); //阿里云短信回复无法定位回复的是哪条短信。 //短信回复只能通过回复内容中的电话号码找到最近24小时以内发送短信的电话号码,匹配分组专家的人员数据 Calendar calendar = Calendar.getInstance(); String entm = DateUtils.Calendar2Str(calendar, "yyyy-MM-dd HH:mm:ss"); sqlGroupPers.setEntm(entm); calendar.add(Calendar.DAY_OF_MONTH, -1);//今天的时间减一天 String sttm = DateUtils.Calendar2Str(calendar, "yyyy-MM-dd HH:mm:ss"); sqlGroupPers.setSttm(sttm); logger.info("开始时间:" + sttm + "结束时间:" + entm +"开始改变是否参加数据---------"); List tacInspYearBatchGroupPers = tacInspYearBatchGroupPersDao.confirmerGroupPers(sqlGroupPers); int update=0; for (TacInspYearBatchGroupPers tacInspYearBatchGroupPer : tacInspYearBatchGroupPers) { logger.info("已找到24小时内已通知已发送短信,参加为初始值的人员"); if(StringUtils.isNotBlank(contentMap.get("content").toString())){//回复内容 if("1".equals(contentMap.get("content").toString())){ tacInspYearBatchGroupPer.setIsJoin("1"); update = tacInspYearBatchGroupPersDao.update(tacInspYearBatchGroupPer); }else{//回复不为1则默认不参加,删除分组人员数据 update = tacInspYearBatchGroupPersDao.deleteGroupPersInfo(tacInspYearBatchGroupPer); } }else{//回复内容为空,则默认不参加删除分组人员数据 update = tacInspYearBatchGroupPersDao.deleteGroupPersInfo(tacInspYearBatchGroupPer); } } return update; } }