| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * @auther txb |
| | |
| | | return R.fail("该值班表不存在"); |
| | | } |
| | | BeanUtils.copyProperties(comSwRotaDO,comSwRotaVO); |
| | | comSwRotaVO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").format(comSwRotaDO.getRotaDate())); |
| | | if (null != comSwRotaDO.getRotaDate()) { |
| | | comSwRotaVO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").format(comSwRotaDO.getRotaDate())); |
| | | } |
| | | comSwRotaVO.setWeekDay(DateUtils.dateToWeek(comSwRotaVO.getRotaDate())); |
| | | StringBuilder leaderNameString = new StringBuilder(); |
| | | StringBuilder leaderPhoneString = new StringBuilder(); |
| | |
| | | |
| | | @Override |
| | | public R addRota(List<ComSwRotaSaveDTO> comSwRotaSaveDTOs) { |
| | | comSwRotaSaveDTOs.forEach(comSwRotaSaveDTO -> { |
| | | if (comSwRotaSaveDTO.getId() != null && comSwRotaSaveDTO.getId() != 0) { |
| | | ComSwRotaDO comSwRotaDO = new ComSwRotaDO(); |
| | | BeanUtils.copyProperties(comSwRotaSaveDTO, comSwRotaDO); |
| | | try { |
| | | comSwRotaDO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").parse(comSwRotaSaveDTO.getRotaDate())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | comSwRotaDAO.updateById(comSwRotaDO); |
| | | } else { |
| | | ComSwRotaDO comSwRotaDO = new ComSwRotaDO(); |
| | | BeanUtils.copyProperties(comSwRotaSaveDTO, comSwRotaDO); |
| | | comSwRotaDO.setId(Snowflake.getId()); |
| | | try { |
| | | comSwRotaDO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").parse(comSwRotaSaveDTO.getRotaDate())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | comSwRotaDAO.insert(comSwRotaDO); |
| | | for (ComSwRotaSaveDTO comSwRotaSaveDTO : comSwRotaSaveDTOs){ |
| | | if (comSwRotaSaveDTO.getId() != null && comSwRotaSaveDTO.getId() != 0) { |
| | | ComSwRotaDO comSwRotaDO = comSwRotaDAO.selectById(comSwRotaSaveDTO.getId()); |
| | | if (null == comSwRotaDO) { |
| | | return R.fail("该值班表不存在"); |
| | | } |
| | | }); |
| | | ComSwRotaDO checkCreditCode = comSwRotaDAO.selectOne(new QueryWrapper<ComSwRotaDO>().lambda().eq(ComSwRotaDO::getRotaDate, comSwRotaSaveDTO.getRotaDate())); |
| | | if (null != checkCreditCode && !comSwRotaDO.getId().equals(checkCreditCode.getId())) { |
| | | return R.fail("该值班表已存在,值班日期重复"); |
| | | } |
| | | BeanUtils.copyProperties(comSwRotaSaveDTO, comSwRotaDO); |
| | | try { |
| | | comSwRotaDO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").parse(comSwRotaSaveDTO.getRotaDate())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | comSwRotaDAO.updateById(comSwRotaDO); |
| | | } else { |
| | | Integer count = comSwRotaDAO.selectCount(new QueryWrapper<ComSwRotaDO>().lambda().eq(ComSwRotaDO::getRotaDate, comSwRotaSaveDTO.getRotaDate())); |
| | | if (count > 0) { |
| | | return R.fail("该值班表已存在,值班日期重复"); |
| | | } |
| | | ComSwRotaDO comSwRotaDO = new ComSwRotaDO(); |
| | | BeanUtils.copyProperties(comSwRotaSaveDTO, comSwRotaDO); |
| | | comSwRotaDO.setId(Snowflake.getId()); |
| | | try { |
| | | comSwRotaDO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").parse(comSwRotaSaveDTO.getRotaDate())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | comSwRotaDAO.insert(comSwRotaDO); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | }catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (comSwRotaDO == null) { |
| | | return R.fail(rotaDate + "值班表不存在"); |
| | | } |
| | | List<ComSwRotaPersonVO> rotaPersons = new ArrayList<>(); |
| | | if (null != comSwRotaDO){ |
| | | String rotaPerson = comSwRotaDO.getRotaPerson(); |
| | | String[] rotaPersonArray = rotaPerson.split(","); |
| | | for (int i = 0; i <= rotaPersonArray.length - 1; i++){ |
| | | ComSwRotaPersonVO comSwRotaPersonVO = new ComSwRotaPersonVO(); |
| | | Map<String,String> person = comSwPatrolRecordDAO.getPbServiceTeamById(rotaPersonArray[i]); |
| | | comSwRotaPersonVO.setId(Long.valueOf(rotaPersonArray[i])); |
| | | comSwRotaPersonVO.setName(person.get("name")); |
| | | comSwRotaPersonVO.setPhone(Long.valueOf(person.get("phone"))); |
| | | Map<String,String> userMap = this.comSwRotaDAO.getImageUrl(Long.valueOf(rotaPersonArray[i])); |
| | | if(userMap != null){ |
| | | comSwRotaPersonVO.setPhone(userMap.get("phone")); |
| | | comSwRotaPersonVO.setImageUrl(userMap.get("url")); |
| | | comSwRotaPersonVO.setName(userMap.get("name")); |
| | | } |
| | | rotaPersons.add(comSwRotaPersonVO); |
| | | } |
| | |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (comSwRotaDO == null) { |
| | | return R.fail(rotaDate + "值班表不存在"); |
| | | } |
| | | List<ComSwRotaPersonVO> rotaLeaders = new ArrayList<>(); |
| | | if (null != comSwRotaDO){ |
| | | String rotaPerson = comSwRotaDO.getRotaLeader(); |
| | | String[] rotaPersonArray = rotaPerson.split(","); |
| | | for (int i = 0; i <= rotaPersonArray.length - 1; i++){ |
| | | ComSwRotaPersonVO comSwRotaPersonVO = new ComSwRotaPersonVO(); |
| | | Map<String,String> leader = comSwPatrolRecordDAO.getPbServiceTeamById(rotaPersonArray[i]); |
| | | comSwRotaPersonVO.setId(Long.valueOf(rotaPersonArray[i])); |
| | | comSwRotaPersonVO.setName(leader.get("name")); |
| | | comSwRotaPersonVO.setPhone(Long.valueOf(leader.get("phone"))); |
| | | Map<String,String> userMap = this.comSwRotaDAO.getImageUrl(Long.valueOf(rotaPersonArray[i])); |
| | | if(userMap != null){ |
| | | comSwRotaPersonVO.setPhone(userMap.get("phone")); |
| | | comSwRotaPersonVO.setImageUrl(userMap.get("url")); |
| | | comSwRotaPersonVO.setName(userMap.get("name")); |
| | | } |
| | | rotaLeaders.add(comSwRotaPersonVO); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public R listSaveSwRotaExcelVO(List<ComSwRotaExcelVO> list, Long communityId) { |
| | | String[] parsePatterns = new String[]{"yyyy-MM-dd", "yyyy-M-dd", "yyyy-MM-d", "yyyy-M-d", "yyyy/MM/dd", "yyyy/M/dd", "yyyy/MM/d", "yyyy/M/d"}; |
| | | List<ComSwRotaDO> comSwRotaDOS = new ArrayList<>(); |
| | | list.forEach(comSwRotaExcelVO -> { |
| | | for (ComSwRotaExcelVO comSwRotaExcelVO : list){ |
| | | Date date = DateUtil.parse(comSwRotaExcelVO.getRotaDate(),parsePatterns); |
| | | Integer count = comSwRotaDAO.selectCount(new QueryWrapper<ComSwRotaDO>().lambda().eq(ComSwRotaDO::getRotaDate, date)); |
| | | if (count > 0) { |
| | | return R.fail("值班日期已存在," + comSwRotaExcelVO.getRotaDate() + "重复"); |
| | | } |
| | | ComSwRotaDO comSwRotaDO = new ComSwRotaDO(); |
| | | String[] leaderPhones = comSwRotaExcelVO.getLeaderPhone().split(","); |
| | | String[] leaderPhones = comSwRotaExcelVO.getLeaderPhone().split("、"); |
| | | String[] leaderNames = comSwRotaExcelVO.getLeaderName().split("、"); |
| | | List<String> leaderIds = new ArrayList<>(); |
| | | for (String leaderPhone : leaderPhones) { |
| | | String id = comSwRotaDAO.getTeamIdsByTeamPhone(leaderPhone); |
| | | for (int i = 0; i < leaderPhones.length; i++) { |
| | | String id = comSwRotaDAO.getTeamIdsByTeamPhone(leaderPhones[i]); |
| | | if (StringUtils.isEmpty(id)) { |
| | | return R.fail(leaderNames[i] + "为非社区团队人员或该人员电话未维护!"); |
| | | } |
| | | leaderIds.add(id); |
| | | } |
| | | |
| | | String[] personPhones = comSwRotaExcelVO.getPersonPhone().split(","); |
| | | String[] personPhones = comSwRotaExcelVO.getPersonPhone().split("、"); |
| | | String[] personNames = comSwRotaExcelVO.getPersonName().split("、"); |
| | | List<String> personIds = new ArrayList<>(); |
| | | for (String personPhone : personPhones) { |
| | | String id = comSwRotaDAO.getTeamIdsByTeamPhone(personPhone); |
| | | for (int i = 0; i < leaderPhones.length; i++) { |
| | | String id = comSwRotaDAO.getTeamIdsByTeamPhone(personPhones[i]); |
| | | if (StringUtils.isEmpty(id)) { |
| | | return R.fail(personNames[i] + "为非社区团队人员或该人员电话未维护!"); |
| | | } |
| | | personIds.add(id); |
| | | } |
| | | BeanUtils.copyProperties(comSwRotaExcelVO, comSwRotaDO); |
| | | comSwRotaDO.setId(Snowflake.getId()); |
| | | comSwRotaDO.setCommunityId(communityId); |
| | | try { |
| | | comSwRotaDO.setRotaDate(new SimpleDateFormat("yyyy-MM-dd").parse(comSwRotaExcelVO.getRotaDate())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // if (StringUtils.isNotEmpty(comSwRotaExcelVO.getRotaDate())) { |
| | | // String el = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) \n" + |
| | | // "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) "; |
| | | // Pattern p = Pattern.compile(el); |
| | | // Matcher m = p.matcher(comSwRotaExcelVO.getRotaDate()); |
| | | // if (!m.matches()) { |
| | | // return R.fail(comSwRotaExcelVO.getRotaDate() + "日期格式不正确"); |
| | | // } |
| | | // } |
| | | // try { |
| | | // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // comSwRotaDO.setRotaDate(sdf.parse(comSwRotaExcelVO.getRotaDate())); |
| | | // } catch (ParseException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | comSwRotaDO.setRotaDate(date); |
| | | comSwRotaDO.setRotaLeader(StringUtils.join(leaderIds, ",")); |
| | | comSwRotaDO.setRotaPerson(StringUtils.join(personIds, ",")); |
| | | comSwRotaDO.setLeaderName(comSwRotaExcelVO.getLeaderName().replace("、",",")); |
| | | comSwRotaDO.setPersonName(comSwRotaExcelVO.getPersonName().replace("、",",")); |
| | | comSwRotaDOS.add(comSwRotaDO); |
| | | }); |
| | | } |
| | | this.saveBatch(comSwRotaDOS); |
| | | return R.ok(); |
| | | } |