SynchroRelatedService.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.maxkey.persistence.service;
  17. import java.sql.Types;
  18. import java.util.Date;
  19. import java.util.List;
  20. import org.apache.mybatis.jpa.persistence.JpaBaseService;
  21. import org.maxkey.entity.Organizations;
  22. import org.maxkey.entity.SynchroRelated;
  23. import org.maxkey.entity.Synchronizers;
  24. import org.maxkey.persistence.mapper.SynchroRelatedMapper;
  25. import org.maxkey.util.DateUtils;
  26. import org.springframework.stereotype.Repository;
  27. @Repository
  28. public class SynchroRelatedService extends JpaBaseService<SynchroRelated>{
  29. public SynchroRelatedService() {
  30. super(SynchroRelatedMapper.class);
  31. }
  32. /* (non-Javadoc)
  33. * @see com.connsec.db.service.BaseService#getMapper()
  34. */
  35. @Override
  36. public SynchroRelatedMapper getMapper() {
  37. return (SynchroRelatedMapper)super.getMapper();
  38. }
  39. public int updateSyncTime(SynchroRelated synchroRelated) {
  40. return getMapper().updateSyncTime(synchroRelated);
  41. }
  42. public List<SynchroRelated> findOrgs(Synchronizers synchronizer) {
  43. return find(
  44. "instid = ? and syncid = ? and objecttype = ? ",
  45. new Object[] { synchronizer.getInstId() ,synchronizer.getId(),Organizations.CLASS_TYPE},
  46. new int[] { Types.VARCHAR,Types.VARCHAR,Types.VARCHAR}
  47. );
  48. }
  49. public SynchroRelated findByOriginId(Synchronizers synchronizer,String originId,String classType) {
  50. return findOne("instid = ? and syncId = ? and originid = ? and objecttype = ? ",
  51. new Object[] { synchronizer.getInstId(),synchronizer.getId(),originId,classType },
  52. new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,Types.VARCHAR});
  53. }
  54. public void updateSynchroRelated(Synchronizers synchronizer,SynchroRelated synchroRelated,String classType) {
  55. SynchroRelated loadSynchroRelated =
  56. findByOriginId(
  57. synchronizer,synchroRelated.getOriginId(),classType );
  58. if(loadSynchroRelated == null) {
  59. insert(synchroRelated);
  60. }else {
  61. synchroRelated.setId(loadSynchroRelated.getId());
  62. synchroRelated.setSyncTime(DateUtils.formatDateTime(new Date()));
  63. updateSyncTime(synchroRelated);
  64. }
  65. }
  66. }