| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- package com.goafanti.admin.service.impl;
- import java.io.UnsupportedEncodingException;
- import java.text.ParseException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import javax.mail.MessagingException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.goafanti.admin.bo.AdminListBo;
- import com.goafanti.admin.bo.InputPublicDtails;
- import com.goafanti.admin.bo.InputPublicRelease;
- import com.goafanti.admin.bo.InputPublicReleaseList;
- import com.goafanti.admin.bo.InputPublicStatistics;
- import com.goafanti.admin.bo.OutPublicDtails;
- import com.goafanti.admin.bo.OutPublicRelease;
- import com.goafanti.admin.bo.OutPublicReleaseList;
- import com.goafanti.admin.bo.OutPublicStatistics;
- import com.goafanti.admin.bo.outPublicReleaseLog;
- import com.goafanti.admin.service.PublicReleaseService;
- import com.goafanti.common.bo.EmailBo;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.AdminMapper;
- import com.goafanti.common.dao.PublicReleaseLogMapper;
- import com.goafanti.common.dao.PublicReleaseMapper;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.Admin;
- import com.goafanti.common.model.PublicRelease;
- import com.goafanti.common.model.PublicReleaseLog;
- import com.goafanti.common.utils.AsyncUtils;
- import com.goafanti.common.utils.DateUtils;
- import com.goafanti.common.utils.SendEmailUtil;
- import com.goafanti.common.utils.WeChatUtils;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.customer.bo.FollowBusinessBo;
- import com.goafanti.customer.service.CustomerService;
- import cn.jiguang.common.utils.StringUtils;
- @Service
- public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper> implements PublicReleaseService {
- @Autowired
- private PublicReleaseMapper publicReleaseMapper;
- @Autowired
- private PublicReleaseLogMapper publicReleaseLogMapper;
- @Autowired
- private CustomerService customerService;
- @Autowired
- private WeChatUtils weChatUtils;
- @Autowired
- private AdminMapper adminMapper;
- @Autowired
- private AsyncUtils asyncUtils;
-
- @Override
- public int addPublicRelease(InputPublicRelease in) {
- Date date =new Date();
- in.setCreateTime(date);
- in.setStatus(1);
- in.setAid(TokenManager.getAdminId());
- try {
- in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
- in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- e.printStackTrace();
- throw new BusinessException("转换异常");
- }
- publicReleaseMapper.insertSelectiveGetId(in);
- AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
- Admin a=adminMapper.selectByPrimaryKey(my.getSuperiorId());
- PublicReleaseLog log=new PublicReleaseLog(in.getId(),TokenManager.getAdminId(),1,"发起外出申请",new Date());
- publicReleaseLogMapper.insertSelective(log);
- String openid=a.getOpenId();
- if (openid!=null) {
- Integer res= weChatUtils.addNotice(openid, in.getStatus(),date,my.getName(),"["+my.getName()+"]发起外出审核");
- if (res!=0) {
- senEmail(my, a,1);
- }
- return res;
- }else {
- //成功但是对方收不到消息
- return 2;
- }
- }
- private void senEmail(AdminListBo my, Admin a,Integer type) {
- String title="外出申请提醒";
- if (type==0) title="外出申请驳回提醒";
- else if (type==2) title="外出申请同意提醒";
- if (SendEmailUtil.isEmail(a.getEmail())) {
- EmailBo email=new EmailBo(title,a.getEmail() , my.getDepartmentName(), my.getName(),"详情请登录微信打卡小程序查看,谢谢!") ;
- try {
- asyncUtils.send(email);
- } catch (UnsupportedEncodingException | MessagingException e) {
- e.printStackTrace();
- }
- }
- }
-
-
-
-
-
-
- @Override
- public int updatePublicRelease(InputPublicRelease in) {
- try {
- in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
- in.setReleaseEnd(DateUtils.parseDate(in.getReleaseEnds(), AFTConstants.YYYYMMDDHHMMSS));
- } catch (ParseException e) {
- e.printStackTrace();
- throw new BusinessException("转换异常");
- }
- in.setStatus(1);
- publicReleaseMapper.updateByPrimaryKeySelective(in);
- return 1;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<OutPublicReleaseList> listPublicRelease(InputPublicReleaseList in) {
- Map<String,Object> map =new HashMap<String, Object>();
- map.put("type", in.getType()==null?0:in.getType());
- map.put("aid", TokenManager.getAdminId());
- if (StringUtils.isNotEmpty(in.getClockTime())) {
- map.put("clockTime", in.getClockTime());
- }
- return (Pagination<OutPublicReleaseList>) findPage("listPublicRelease", "countPublicRelease", map, in.getPageNo(), in.getPageSize());
- }
- @Override
- public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Double duration) {
- PublicRelease p=new PublicRelease();
- Date date =new Date();
- p.setId(id);
- p.setStatus(status);
- PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
- if (use.getStatus()!=1) {
- throw new BusinessException("只能修改已发起的状态");
- }
- publicReleaseMapper.updateByPrimaryKeySelective(p);
- PublicReleaseLog log=new PublicReleaseLog(id,TokenManager.getAdminId(),status,remarks,new Date());
- publicReleaseLogMapper.insertSelective(log);
- AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
- Admin a=adminMapper.selectByPrimaryKey(use.getAid());
- if (my.getOpenId()!=null) {
- Integer res=weChatUtils.addNotice(a.getOpenId(),p.getStatus(),date,my.getName(),remarks);
- if (res!=0) {
- senEmail( my, a, status);
- }
- return res;
- }
- return 1;
- }
-
- @Override
- public List<outPublicReleaseLog> listPublicReleaseLog(Integer id) {
- return publicReleaseLogMapper.listPublicReleaseLog(id);
- }
- @Override
- public int pushPublicReleaseClockIn(Integer id,String photoUrl) {
- PublicRelease p=new PublicRelease();
- PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
- p.setId(id);
- p.setClockIn(1);
- p.setPhotoUrl(photoUrl);
- p.setClockInTime(new Date());
- if (use.getClockIn()==0) {
- FollowBusinessBo fbb=new FollowBusinessBo();
- fbb.setUid(use.getUid());
- fbb.setContactType("0");
- fbb.setResult(use.getRemarks());
- fbb.setFollowTime(DateUtils.formatDate(p.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
- String ufid=UUID.randomUUID().toString();
- p.setUfid(ufid);
- customerService.addFollow(fbb,ufid);
- }
- publicReleaseMapper.updateByPrimaryKeySelective(p);
- return 1;
- }
- @Override
- public OutPublicRelease dtails(Integer id) {
- return publicReleaseMapper.selectByid(id);
- }
-
- @Override
- public OutPublicRelease followDtails(String id) {
- return publicReleaseMapper.selectByUfid(id);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Object publicReleaseStatistics(InputPublicStatistics in) {
- Map<String,Object> map =new HashMap<String, Object>();
- if(in.getAid()!=null)map.put("aid", in.getAid());
- if(in.getDepId()!=null)map.put("depId", in.getDepId());
- if(in.getClockStart()!=null)map.put("clockStart", in.getClockStart());
- if(in.getClockEnd()!=null)map.put("clockEnd", in.getClockEnd()+" 23:59:59");
- if(in.getCreateStart()!=null)map.put("createStart", in.getCreateStart());
- if(in.getCreateEnd()!=null)map.put("createEnd", in.getCreateEnd()+" 23:59:59");
- return (Pagination<OutPublicStatistics>) findPage("listPublicStatistics", "countPublicStatistics", map, in.getPageNo(), in.getPageSize());
- }
- @SuppressWarnings("unchecked")
- @Override
- public Object publicReleaseListDtails(InputPublicDtails in) {
- Map<String,Object> map =new HashMap<String, Object>();
- if(in.getAid()!=null)map.put("aid", in.getAid());
- if(in.getReleaseStart()!=null)map.put("releaseStart", in.getReleaseStart());
- if(in.getReleaseEnd()!=null)map.put("releaseEnd", in.getReleaseEnd()+" 23:59:59");
- if(in.getUid()!=null)map.put("uid", in.getUid());
- if(in.getStatus()!=null)map.put("status", in.getStatus());
- return (Pagination<OutPublicDtails>) findPage("listPublicDtails", "countPublicDtails", map, in.getPageNo(), in.getPageSize());
- }
-
-
- }
|