| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.service.business.impl.hksync.fhk; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.DataSyncConfig; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.haikang.model.HKConstants; |
| | | import com.doumee.core.haikang.model.param.BaseListPageResponse; |
| | | import com.doumee.core.haikang.model.param.BaseResponse; |
| | | import com.doumee.core.haikang.model.param.request.TimeRangeListRequest; |
| | | import com.doumee.core.haikang.model.param.respose.OrgInfoResponse; |
| | | import com.doumee.core.haikang.model.param.respose.UserInfoResponse; |
| | | import com.doumee.core.haikang.service.HKService; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DESUtil; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.dao.CompanyMapper; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.vo.CompanyTree; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.MemberService; |
| | | import com.doumee.service.business.impl.MemberServiceImpl; |
| | | import com.doumee.service.business.impl.hksync.HkSyncBaseServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 海康ç»ç»äººåéè¿æ¥Serviceå®ç°(èªè¡ç»´æ¤æ
åµï¼ |
| | | * @author æ±è¹è¹ |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class HkSyncOrgUserFromSelfServiceImpl extends HkSyncBaseServiceImpl { |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | @Autowired |
| | | private SystemUserMapper systemUserMapper; |
| | | |
| | | @Autowired |
| | | private DataSyncConfig dataSyncConfig; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | /** |
| | | * åæ¥æµ·åº·ç»ç»ä¿¡æ¯å°ä¸å¡ç³»ç» |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void syncOrgData(LoginUserInfo user ){ |
| | | if(Constants.DEALING_HK_ORG){ |
| | | return ; |
| | | } |
| | | Constants.DEALING_HK_ORG =true; |
| | | try { |
| | | if( Constants.formatIntegerNum(dataSyncConfig.getOrgUserDataOrigin()) != DataSyncConfig.origin.self){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对ä¸èµ·ï¼å½å䏿¯æç»ç»åæ¥æä½~"); |
| | | } |
| | | TimeRangeListRequest param = null; |
| | | //è·åERPç»ç»ä¿¡æ¯ï¼å
¨éåæ¥ï¼ |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | |
| | | List<Company> allHkList = new ArrayList<>(); |
| | | while (hasNext){ |
| | | //å页éåå¾ªç¯æ¥è¯¢ææé¨ç¦è®¾å¤æ°æ® |
| | | param = new TimeRangeListRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<BaseListPageResponse<OrgInfoResponse>> response = HKService.orgAllList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | } |
| | | if(response.getData() == null || response.getData().getTotal() ==0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"æªåæ¥å°ä»»ä½ä¿¡æ¯ï¼"); |
| | | } |
| | | BaseListPageResponse<OrgInfoResponse> r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(getNewOrgModelBYList(r.getList(),user.getId())); |
| | | } |
| | | curPage++; |
| | | } |
| | | if(allHkList .size() == 0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"æªåæ¥å°ä»»ä½ç»ç»ä¿¡æ¯ï¼"); |
| | | } |
| | | companyMapper.delete(new UpdateWrapper<>());//æ¸
ç©ºåææ°æ® |
| | | companyMapper.update(null,new UpdateWrapper<Company>().lambda() |
| | | .eq(Company::getType,Constants.ONE) |
| | | .eq(Company::getIsdeleted,Constants.ZERO) |
| | | .set(Company::getIsdeleted,Constants.ONE));//æ¸
ç©ºåææ°æ® |
| | | companyMapper.insert(allHkList);//æå
¥æ°æ°æ® |
| | | dealTreePathInfo(allHkList);//å¤çæ å½¢ç»ææ°æ® |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | }finally { |
| | | Constants.DEALING_HK_ORG =false; |
| | | } |
| | | } |
| | | |
| | | private void dealTreePathInfo(List<Company> allHkList) { |
| | | List<Company> tree = new CompanyTree(allHkList,DataSyncConfig.origin.hk).buildTree(); |
| | | if(tree!=null || tree.size()>0){ |
| | | for(Company t : tree){ |
| | | t.setCompanyPath(t.getId()+"/"); |
| | | t.setCompanyNamePath(t.getName()); |
| | | companyMapper.updateById(t); |
| | | dealChildParentId(t,t.getChildList()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void dealChildParentId(Company t, List<Company> childList) { |
| | | if(childList ==null || childList.size()==0){ |
| | | return; |
| | | } |
| | | for(Company c : childList){ |
| | | c.setParentId(t.getId()); |
| | | c.setCompanyPath(t.getCompanyPath()+c.getId()+"/"); |
| | | c.setCompanyNamePath(t.getCompanyNamePath()+"/"+c.getName()); |
| | | companyMapper.updateById(c); |
| | | if(t.getChildList()!=null || t.getChildList().size()==0){ |
| | | //éå½å¤çåé |
| | | dealChildParentId(c,c.getChildList()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private List<Company> getNewOrgModelBYList(List<OrgInfoResponse> list, Integer userid) { |
| | | List<Company> newList = new ArrayList<>(); |
| | | if(list == null || list.size()==0){ |
| | | return newList; |
| | | } |
| | | for(OrgInfoResponse model :list){ |
| | | Company c = new Company(); |
| | | c.setHkId(model.getOrgIndexCode()); |
| | | c.setCode(model.getOrgNo()); |
| | | c.setName(model.getOrgName()); |
| | | c.setHkStatus(Constants.ONE); |
| | | c.setHkDate(new Date()); |
| | | c.setIsdeleted(Constants.ZERO); |
| | | c.setCreateDate(c.getHkDate()); |
| | | c.setEditDate(DateUtil.getISO8601DateByStr(model.getUpdateTime())); |
| | | c.setCreator(userid); |
| | | c.setEditor(userid); |
| | | c.setStatus(Constants.ZERO); |
| | | c.setType(Constants.ONE); |
| | | if(!StringUtils.equals(model.getOrgIndexCode(),systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode())){ |
| | | c.setHkParentId(model.getParentOrgIndexCode()); |
| | | } |
| | | newList.add(c); |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | /** |
| | | * åæ¥æµ·åº·äººåä¿¡æ¯ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void syncUserData(LoginUserInfo user){ |
| | | if(Constants.DEALING_HK_USER){ |
| | | return ; |
| | | } |
| | | Constants.DEALING_HK_USER =true; |
| | | try { |
| | | if( Constants.formatIntegerNum(dataSyncConfig.getOrgUserDataOrigin()) != DataSyncConfig.origin.self){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对ä¸èµ·ï¼å½å䏿¯æç»ç»åæ¥æä½~"); |
| | | } |
| | | List<Company> companies = companyMapper.selectList(new QueryWrapper<>()); |
| | | if(companies == null || companies.size() == 0){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对ä¸èµ·ï¼è¯·å
忥ä¼ä¸ç»ç»ä¿¡æ¯~"); |
| | | } |
| | | TimeRangeListRequest param = new TimeRangeListRequest(); |
| | | //è·åERPç»ç»ä¿¡æ¯ï¼å
¨éåæ¥ï¼ |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | List<Member> allHkList = new ArrayList<>(); |
| | | List<SystemUser> allUserList = new ArrayList<>(); |
| | | while (hasNext){ |
| | | //å页éåå¾ªç¯æ¥è¯¢ææé¨ç¦è®¾å¤æ°æ® |
| | | param = new TimeRangeListRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<BaseListPageResponse<UserInfoResponse>> response = HKService.userAllList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | } |
| | | if(response.getData() == null || response.getData().getTotal() ==0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"æªåæ¥å°ä»»ä½ä¿¡æ¯ï¼"); |
| | | } |
| | | BaseListPageResponse<UserInfoResponse> r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(getNewUserModelBYList(r.getList(),companies,user.getId())); |
| | | } |
| | | curPage++; |
| | | } |
| | | if(allHkList .size() == 0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"æªåæ¥å°ä»»ä½ç»ç»ä¿¡æ¯ï¼"); |
| | | } |
| | | memberMapper.update(null,new UpdateWrapper<Member>().lambda() |
| | | .eq(Member::getType,Constants.TWO) |
| | | .eq(Member::getIsdeleted,Constants.ZERO) |
| | | .set(Member::getIsdeleted,Constants.ONE));//æ¸
ç©ºåææ°æ® |
| | | systemUserMapper.update(null,new UpdateWrapper<SystemUser>().lambda() |
| | | .eq(SystemUser::getType,Constants.TWO) |
| | | .eq(SystemUser::getDeleted,Boolean.FALSE) |
| | | .set(SystemUser::getDeleted,Boolean.TRUE));//æ¸
ç©ºåææ°æ® |
| | | memberMapper.insert(allHkList);//æå
¥æ°æ°æ® |
| | | for(Member c :allHkList){ |
| | | allUserList.add(MemberServiceImpl.createSystemUser(c,systemDictDataBiz));//å建ç»éè´¦å· |
| | | } |
| | | systemUserMapper.insert(allUserList); |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | }finally { |
| | | Constants.DEALING_HK_USER =false; |
| | | } |
| | | } |
| | | |
| | | private List<Member> getNewUserModelBYList(List<UserInfoResponse> list, List<Company> companies,Integer userid) { |
| | | List<Member> newList = new ArrayList<>(); |
| | | if(list == null || list.size()==0){ |
| | | return newList; |
| | | } |
| | | for(UserInfoResponse model :list){ |
| | | Member c = new Member(); |
| | | String encryptIdNo = DESUtil.encrypt(Constants.EDS_PWD,model.getCertificateNo()); |
| | | c.setIdcardNo(encryptIdNo); |
| | | c.setIdcardDecode(Constants.getTuominStr(model.getCertificateNo())); |
| | | c.setIdcardType(getIdcardTypeByHk(model.getCertificateType())); |
| | | c.setCode(model.getJobNo()); |
| | | c.setPhone(model.getPhoneNo()); |
| | | c.setHkId(model.getPersonId()); |
| | | c.setName(model.getPersonName()); |
| | | c.setHkStatus(Constants.ONE); |
| | | c.setHkDate(new Date()); |
| | | c.setCanVisit(Constants.ZERO); |
| | | c.setWorkStatus(Constants.ZERO); |
| | | c.setHighCheckor(Constants.ZERO); |
| | | c.setSex(model.getGender()); |
| | | c.setIsdeleted(Constants.ZERO); |
| | | c.setCreateDate(c.getHkDate()); |
| | | c.setEditDate(DateUtil.getISO8601DateByStr(model.getUpdateTime())); |
| | | c.setCreator(userid); |
| | | c.setEditor(userid); |
| | | c.setStatus(Constants.ZERO); |
| | | c.setType(Constants.TWO); |
| | | c.setCompanyId(getCompanyId(companies,model.getOrgIndexCode())); |
| | | if(model.getPersonPhoto()!=null && model.getPersonPhoto().size()>0){ |
| | | c.setFaceId(model.getPersonPhoto().get(0).getPersonPhotoIndexCode()); |
| | | c.setFaceImg(HKConstants.IMG_INDEX+model.getPersonPhoto().get(0).getPicUri()); |
| | | c.setFaceServerIndexCode(model.getPersonPhoto().get(0).getServerIndexCode()); |
| | | } |
| | | newList.add(c); |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | private Integer getCompanyId(List<Company> companies, String orgIndexCode) { |
| | | if(companies == null){ |
| | | return null; |
| | | } |
| | | for(Company c : companies){ |
| | | if(StringUtils.equals(c.getHkId(),orgIndexCode)){ |
| | | return c.getId(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * //è¯ä»¶ç±»å111:身份è¯414:æ¤ç
§113:æ·å£ç°¿335:驾驶è¯131:å·¥ä½è¯133:å¦çè¯990:å
¶ä» ; |
| | | * // è¯ä»¶ç±»å 0èº«ä»½è¯ 1港澳è¯ä»¶ 2æ¤ç
§ |
| | | * @param certificateType |
| | | * @return |
| | | */ |
| | | private Integer getIdcardTypeByHk(Integer certificateType) { |
| | | if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.SHENFENZHENG.getKey())){ |
| | | return 0; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.HUZHAO.getKey())){ |
| | | return 2; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.JIASHIZHENG.getKey())){ |
| | | return 3; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.XUESHENGZHENG.getKey())){ |
| | | return 4; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.GONGXUOZHENG.getKey())){ |
| | | return 5; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.GONGXUOZHENG.getKey())){ |
| | | return 6; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.HUKOUBEN.getKey())){ |
| | | return 7; |
| | | }else if(Constants.equalsInteger(certificateType,HKConstants.CertificateType.QITA.getKey())){ |
| | | return 8; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |