123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.huaxu.zoniot.service.impl;
- import com.alibaba.fastjson.JSON;
- import com.huaxu.zoniot.common.ModelValidate;
- import com.huaxu.zoniot.common.ResultStatus;
- import com.huaxu.zoniot.common.ServiceException;
- import com.huaxu.zoniot.dao.CommunityMapper;
- import com.huaxu.zoniot.entity.Community;
- import com.huaxu.zoniot.service.CommunityService;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- /**
- * <p></p>
- *
- * @Author wilian.peng
- * @Date 2021/1/9 19:16
- * @Version 1.0
- */
- @Slf4j
- @Service
- public class CommunityServiceImpl implements CommunityService, ModelValidate<Community> {
- @Autowired
- CommunityMapper communityMapper ;
- @Override
- public Community findCommunity(String name,
- Integer siteId ,
- Integer customerId ,
- Integer provinceCode,
- Integer cityCode,
- Integer regionCode) {
- Community object = new Community();
- object.setSiteId(siteId);
- object.setCustomerId(customerId);
- object.setName(name);
- object.setProvince(provinceCode);
- object.setCity(cityCode);
- object.setRegion(regionCode);
- validate(object);
- Community community = communityMapper.findCommunityWithName(name, siteId , customerId, provinceCode, cityCode, regionCode);
- return community;
- }
- @Override
- public Community saveCommunity(Community community) {
- validate(community);
- Community exist = findCommunity(community.getName(),
- community.getSiteId(),
- community.getCustomerId() ,
- community.getProvince(),
- community.getCity(),
- community.getRegion());
- if(exist != null){
- return exist ;
- }
- else {
- community.setDateCreate(new Date());
- community.setStatus(1);
- communityMapper.insert(community);
- return community ;
- }
- }
- @Override
- public Community findCommunityById(Integer communityId) {
- communityMapper.selectByPrimaryKey(communityId);
- return null;
- }
- @Override
- public boolean validate(Community object) {
- log.info("Validate Community , Object = {}", JSON.toJSONString(object));
- if(object == null){
- throw new ServiceException(ResultStatus.COMMUNITY_ERROR);
- }
- if(StringUtils.isBlank(object.getName())){
- throw new ServiceException(ResultStatus.COMMUNITY_NAME_ERROR);
- }
- if(object.getSiteId() == null){
- throw new ServiceException(ResultStatus.COMMUNITY_SITE_ERROR);
- }
- if(object.getCustomerId() == null){
- throw new ServiceException(ResultStatus.COMMUNITY_CUSTOMER_ERROR);
- }
- if(object.getProvince() == null){
- throw new ServiceException(ResultStatus.COMMUNITY_PROVINCE_ERROR);
- }
- if(object.getCity() == null){
- throw new ServiceException(ResultStatus.COMMUNITY_CITY_ERROR);
- }
- if(object.getRegion() == null){
- throw new ServiceException(ResultStatus.COMMUNITY_REGION_ERROR);
- }
- return true;
- }
- }
|