|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.util.IdcardUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.PhoneUtil; | 
|---|
|  |  |  | import cn.hutool.http.HttpRequest; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.core.model.PageData; | 
|---|
|  |  |  | import com.doumee.core.model.PageWrap; | 
|---|
|  |  |  | import com.doumee.core.utils.*; | 
|---|
|  |  |  | import com.doumee.core.utils.redis.RedisUtil; | 
|---|
|  |  |  | import com.doumee.core.wx.WXConstant; | 
|---|
|  |  |  | import com.doumee.dao.admin.request.LaborEmpowerDTO; | 
|---|
|  |  |  | import com.doumee.dao.admin.request.LaborMemberDTO; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.*; | 
|---|
|  |  |  | import com.doumee.dao.business.dao.CompanyMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.RegisterDriverDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.ResetPasswordDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.join.MemberJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.RetentionJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.join.UserActionJoinMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.system.SystemUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDictData; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemUser; | 
|---|
|  |  |  | import com.doumee.dao.web.reqeust.AccountLoginDTO; | 
|---|
|  |  |  | import com.doumee.dao.web.reqeust.CheckVisitedDTO; | 
|---|
|  |  |  | import com.doumee.dao.web.reqeust.VisitMemberDTO; | 
|---|
|  |  |  | import com.doumee.dao.web.response.MemberVO; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.service.business.impl.hksync.HkSyncEmpowerServiceImpl; | 
|---|
|  |  |  | import com.doumee.service.business.impl.hksync.ferp.HkSyncOrgUserToHKServiceImpl; | 
|---|
|  |  |  | import com.doumee.service.system.SystemLoginService; | 
|---|
|  |  |  | import com.doumee.service.system.SystemUserService; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import org.apache.commons.collections.CollectionUtils; | 
|---|
|  |  |  | import org.apache.commons.lang3.RandomStringUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.context.annotation.Lazy; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.http.server.reactive.ServerHttpRequest; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | 
|---|
|  |  |  | if(dealHkUserBiz(insert)){ | 
|---|
|  |  |  | memberMapper.insert(insert); | 
|---|
|  |  |  | //创建系统登陆账号(默认无任何角色) | 
|---|
|  |  |  | if(Constants.equalsInteger(member.getCompanyType(),Constants.ONE)){ | 
|---|
|  |  |  | //                if(Constants.equalsInteger(member.getCompanyType(),Constants.ONE)){ | 
|---|
|  |  |  | //如果是内部组织人员,新增系统登陆账号 | 
|---|
|  |  |  | systemUserMapper.insert(createSystemUser(insert,systemDictDataBiz)); | 
|---|
|  |  |  | //处理培训有效期业务 | 
|---|
|  |  |  | dealTrainTIme(member,0,loginUserInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,员工信息同步安防平台失败,请稍后重试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | //如果发生异常,删除已经创建的人员信息 | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | deleteHkUserBiz(new String[]{insert.getHkId()}); | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,员工信息新建失败,请稍后重试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //处理新增数据 | 
|---|
|  |  |  | BaseResponse<UserAddResponse> result =  HKService.addUser(hkAddRequest); | 
|---|
|  |  |  | if(result!=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE) && result.getData()!=null){ | 
|---|
|  |  |  | if(result!=null && StringUtils.equals(result.getCode(), HKConstants.RESPONSE_SUCCEE) && result.getData()!=null){ | 
|---|
|  |  |  | insert.setHkId(hkAddRequest.getPersonId()); | 
|---|
|  |  |  | insert.setFaceId(result.getData().getFaceId()); | 
|---|
|  |  |  | if(StringUtils.isNotBlank(insert.getFaceId())){ | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"身份证号格式有误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(memberMapper.selectCount(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .in(Member::getType,new Integer[]{Constants.ZERO,Constants.TWO}) | 
|---|
|  |  |  | .eq(Member::getIdcardNo,DESUtil.encrypt(Constants.EDS_PWD, member.getIdcardNo())) | 
|---|
|  |  |  | .eq(Member::getIsdeleted,Constants.ZERO)) >0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "身份证号【"+member.getIdcardNo()+"】已被使用,不能重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(memberMapper.selectCount(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .eq(Member::getPhone,  member.getPhone()) | 
|---|
|  |  |  | .in(Member::getType,new Integer[]{Constants.ZERO,Constants.TWO}) | 
|---|
|  |  |  | .eq(Member::getIsdeleted,Constants.ZERO) ) >0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "手机号【"+member.getPhone()+"】已被使用,不能重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(memberMapper.selectCount(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .eq(Member::getPhone,member.getPhone()) | 
|---|
|  |  |  | .in(Member::getType,new Integer[]{Constants.ZERO,Constants.TWO}) | 
|---|
|  |  |  | .eq(Member::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .ne(Member::getId,member.getId())) >0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "手机号【"+member.getPhone()+"】已被使用,不能重复"); | 
|---|
|  |  |  | 
|---|
|  |  |  | if( !StringUtils.equals(model.getIdcardNo(),encrptNo) ){ | 
|---|
|  |  |  | if(memberMapper.selectCount(new QueryWrapper<Member>().lambda() | 
|---|
|  |  |  | .eq(Member::getIdcardNo,encrptNo) | 
|---|
|  |  |  | .in(Member::getType,new Integer[]{Constants.ZERO,Constants.TWO}) | 
|---|
|  |  |  | .eq(Member::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .ne(Member::getId,member.getId())) >0){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "身份证号【"+member.getIdcardNoNew()+"】已被使用,不能重复"); | 
|---|
|  |  |  | 
|---|
|  |  |  | public void deleteById(Integer id,LoginUserInfo loginUserInfo) { | 
|---|
|  |  |  | Member member=new Member(); | 
|---|
|  |  |  | member.setId(id); | 
|---|
|  |  |  | member.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | member.setIsdeleted(Constants.ONE); | 
|---|
|  |  |  | member.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | member.setEditDate(new Date()); | 
|---|
|  |  |  | member.setHkStatus(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(ids)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Member member=new Member(); | 
|---|
|  |  |  | for(Integer id : ids){ | 
|---|
|  |  |  | deleteById(id,loginUserInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* Member member=new Member(); | 
|---|
|  |  |  | ids.stream().forEach(s ->{ | 
|---|
|  |  |  | member.setId(s); | 
|---|
|  |  |  | member.setIsdeleted(Constants.ONE); | 
|---|
|  |  |  | 
|---|
|  |  |  | member.setEditDate(new Date()); | 
|---|
|  |  |  | memberMapper.updateById(member); | 
|---|
|  |  |  | saveUserActionBiz(member,loginUserInfo,Constants.UserActionType.DELETE,userActionJoinMapper,JSONObject.toJSONString(member)); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | });*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void saveUserActionBiz(Member updateMember,LoginUserInfo user, Constants.UserActionType type,UserActionJoinMapper userActionMapper,String content) { | 
|---|
|  |  |  | updateMember.setEditDate(updateMember.getEditDate()==null?new Date():updateMember.getEditDate()); | 
|---|
|  |  |  | UserAction userAction=new UserAction(); | 
|---|
|  |  |  | userAction.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | userAction.setCreateDate(updateMember.getEditDate()); | 
|---|
|  |  |  | 
|---|
|  |  |  | update.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | update.setCanVisit(member.getCanVisit()); | 
|---|
|  |  |  | memberMapper.updateById(update); | 
|---|
|  |  |  | member.setEditDate(update.getEditDate()); | 
|---|
|  |  |  | //记录操作日志 | 
|---|
|  |  |  | saveUserActionBiz(member,loginUserInfo,Constants.equalsInteger(member.getCanVisit(),Constants.ONE)?Constants.UserActionType.CANVISIT:Constants.UserActionType.CANCEL_VISIT,userActionJoinMapper,null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public PageData<Member> findMemberInfoPage(PageWrap<MemberQuery> pageWrap) { | 
|---|
|  |  |  | IPage<Member> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | MPJLambdaWrapper<Member> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pageWrap.getModel().setIsdeleted(Constants.formatIntegerNum(pageWrap.getModel().getIsdeleted())); | 
|---|
|  |  |  | queryWrapper.selectAll(Member.class); | 
|---|
|  |  |  | queryWrapper.selectAs(Company::getName,Member::getCompanyName); | 
|---|
|  |  |  | queryWrapper.selectAs(SystemUser::getRealname,Member::getEditorName); | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.selectAll(Member.class) | 
|---|
|  |  |  | .selectAs(Company::getName,Member::getCompanyName) | 
|---|
|  |  |  | .selectAs(Member::getLastVisitDate,Member::getLastVisitDate) | 
|---|
|  |  |  | .select(" (select count(v.id) from visits v where v.MEMBER_ID=t.id and v.ISDELETED=0 and v.status  in (7,8) ) as visitsCount"); | 
|---|
|  |  |  | .select(" (select count(v.id) from visits v where v.MEMBER_ID=t.id and v.ISDELETED=0 and v.status  in (7,8) ) as visitTimes"); | 
|---|
|  |  |  | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Member::getName,pageWrap.getModel().getName()) | 
|---|
|  |  |  | .like(StringUtils.isNotBlank(pageWrap.getModel().getPhone()),Member::getPhone,pageWrap.getModel().getPhone()) | 
|---|
|  |  |  | .and(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()), ms->ms.like(Member::getVisitCompanyName,pageWrap.getModel().getCompanyName()) | 
|---|
|  |  |  | 
|---|
|  |  |  | List<SystemUser> userList = new ArrayList<>(); | 
|---|
|  |  |  | for(Member insert: newList){ | 
|---|
|  |  |  | //创建系统登陆账号(默认无任何角色) | 
|---|
|  |  |  | if(Constants.equalsInteger(insert.getCompanyType(),Constants.ONE)){ | 
|---|
|  |  |  | //                if(Constants.equalsInteger(insert.getCompanyType(),Constants.ONE)){ | 
|---|
|  |  |  | //如果是内部组织人员,新增系统登陆账号 | 
|---|
|  |  |  | userList.add(createSystemUser(insert,systemDictDataBiz)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(userList.size()>0){ | 
|---|
|  |  |  | systemUserMapper.insert(userList); | 
|---|
|  |  |  | 
|---|
|  |  |  | systemUser.setUsername(registerDriverDTO.getPhone()); | 
|---|
|  |  |  | systemUser.setRealname(registerDriverDTO.getName()); | 
|---|
|  |  |  | systemUser.setMemberId(member.getId()); | 
|---|
|  |  |  | systemUser.setMobile(registerDriverDTO.getPhone()); | 
|---|
|  |  |  | systemUser.setSalt(salt); | 
|---|
|  |  |  | systemUser.setPassword(member.getPassward()); | 
|---|
|  |  |  | systemUser.setStatus(Constants.ZERO); | 
|---|