CommunityServiceImpl.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.huaxu.zoniot.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.huaxu.zoniot.common.ModelValidate;
  4. import com.huaxu.zoniot.common.ResultStatus;
  5. import com.huaxu.zoniot.common.ServiceException;
  6. import com.huaxu.zoniot.dao.CommunityMapper;
  7. import com.huaxu.zoniot.entity.Community;
  8. import com.huaxu.zoniot.service.CommunityService;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import java.util.Date;
  14. /**
  15. * <p></p>
  16. *
  17. * @Author wilian.peng
  18. * @Date 2021/1/9 19:16
  19. * @Version 1.0
  20. */
  21. @Slf4j
  22. @Service
  23. public class CommunityServiceImpl implements CommunityService, ModelValidate<Community> {
  24. @Autowired
  25. CommunityMapper communityMapper ;
  26. @Override
  27. public Community findCommunity(String name,
  28. Integer siteId ,
  29. Integer customerId ,
  30. Integer provinceCode,
  31. Integer cityCode,
  32. Integer regionCode) {
  33. Community object = new Community();
  34. object.setSiteId(siteId);
  35. object.setCustomerId(customerId);
  36. object.setName(name);
  37. object.setProvince(provinceCode);
  38. object.setCity(cityCode);
  39. object.setRegion(regionCode);
  40. validate(object);
  41. Community community = communityMapper.findCommunityWithName(name, siteId , customerId, provinceCode, cityCode, regionCode);
  42. return community;
  43. }
  44. @Override
  45. public Community saveCommunity(Community community) {
  46. validate(community);
  47. Community exist = findCommunity(community.getName(),
  48. community.getSiteId(),
  49. community.getCustomerId() ,
  50. community.getProvince(),
  51. community.getCity(),
  52. community.getRegion());
  53. if(exist != null){
  54. return exist ;
  55. }
  56. else {
  57. community.setDateCreate(new Date());
  58. community.setStatus(1);
  59. communityMapper.insert(community);
  60. return community ;
  61. }
  62. }
  63. @Override
  64. public Community findCommunityById(Integer communityId) {
  65. communityMapper.selectByPrimaryKey(communityId);
  66. return null;
  67. }
  68. @Override
  69. public boolean validate(Community object) {
  70. log.info("Validate Community , Object = {}", JSON.toJSONString(object));
  71. if(object == null){
  72. throw new ServiceException(ResultStatus.COMMUNITY_ERROR);
  73. }
  74. if(StringUtils.isBlank(object.getName())){
  75. throw new ServiceException(ResultStatus.COMMUNITY_NAME_ERROR);
  76. }
  77. if(object.getSiteId() == null){
  78. throw new ServiceException(ResultStatus.COMMUNITY_SITE_ERROR);
  79. }
  80. if(object.getCustomerId() == null){
  81. throw new ServiceException(ResultStatus.COMMUNITY_CUSTOMER_ERROR);
  82. }
  83. if(object.getProvince() == null){
  84. throw new ServiceException(ResultStatus.COMMUNITY_PROVINCE_ERROR);
  85. }
  86. if(object.getCity() == null){
  87. throw new ServiceException(ResultStatus.COMMUNITY_CITY_ERROR);
  88. }
  89. if(object.getRegion() == null){
  90. throw new ServiceException(ResultStatus.COMMUNITY_REGION_ERROR);
  91. }
  92. return true;
  93. }
  94. }