package com.doumee.service.business.impl;
|
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.LoginUserInfo;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.Utils;
|
import com.doumee.dao.business.HotCityMapper;
|
import com.doumee.dao.business.join.HotCityJoinMapper;
|
import com.doumee.dao.business.model.Activity;
|
import com.doumee.dao.business.model.Areas;
|
import com.doumee.dao.business.model.HotCity;
|
import com.doumee.dao.web.response.HotCityResponse;
|
import com.doumee.service.business.HotCityService;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 常用城市配置表Service实现
|
* @author 江蹄蹄
|
* @date 2023/03/21 15:48
|
*/
|
@Service
|
public class HotCityServiceImpl implements HotCityService {
|
|
@Autowired
|
private HotCityMapper hotCityMapper;
|
|
@Autowired
|
private HotCityJoinMapper hotCityJoinMapper;
|
|
@Override
|
public Integer create(HotCity hotCity) {
|
if(hotCity.getCityId()==null){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),ResponseStatus.BAD_REQUEST.getMessage());
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
hotCity.setIsdeleted(Constants.ZERO);
|
hotCity.setCreateDate(new Date());
|
hotCity.setCreator(user.getId());
|
|
HotCity query=new HotCity();
|
query.setCityId(hotCity.getCityId());
|
query.setIsdeleted(Constants.ZERO);
|
List<HotCity> list= hotCityMapper.selectList(new QueryWrapper<>(query));
|
if(!CollectionUtils.isEmpty(list)){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"常用城市已存在,禁止添加");
|
}
|
hotCityMapper.insert(hotCity);
|
return hotCity.getId();
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
HotCity hotCity=new HotCity();
|
hotCity.setEditDate(new Date());
|
hotCity.setEditor(user.getId());
|
hotCity.setId(id);
|
hotCity.setIsdeleted(Constants.ONE);
|
hotCityMapper.updateById(hotCity);
|
}
|
|
@Override
|
public void delete(HotCity hotCity) {
|
UpdateWrapper<HotCity> deleteWrapper = new UpdateWrapper<>(hotCity);
|
hotCityMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
hotCityMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void updateById(HotCity hotCity) {
|
if(hotCity.getCityId()==null){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),ResponseStatus.BAD_REQUEST.getMessage());
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
hotCity.setEditDate(new Date());
|
hotCity.setEditor(user.getId());
|
|
HotCity query=new HotCity();
|
query.setCityId(hotCity.getCityId());
|
query.setIsdeleted(Constants.ZERO);
|
List<HotCity> list= hotCityMapper.selectList(new QueryWrapper<>(query));
|
if(!CollectionUtils.isEmpty(list)&&!Constants.equalsInteger(list.get(0).getId(),hotCity.getId())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"常用城市已存在,禁止添加");
|
}
|
hotCityMapper.updateById(hotCity);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<HotCity> hotCitys) {
|
if (CollectionUtils.isEmpty(hotCitys)) {
|
return;
|
}
|
for (HotCity hotCity: hotCitys) {
|
this.updateById(hotCity);
|
}
|
}
|
|
@Override
|
public HotCity findById(Integer id) {
|
return hotCityMapper.selectById(id);
|
}
|
|
@Override
|
public HotCity findOne(HotCity hotCity) {
|
QueryWrapper<HotCity> wrapper = new QueryWrapper<>(hotCity);
|
return hotCityMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<HotCity> findList(HotCity hotCity) {
|
QueryWrapper<HotCity> wrapper = new QueryWrapper<>(hotCity);
|
return hotCityMapper.selectList(wrapper);
|
}
|
|
@Override
|
public PageData<HotCity> findPage(PageWrap<HotCity> pageWrap) {
|
IPage<HotCity> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
MPJLambdaWrapper<HotCity> queryWrapper = new MPJLambdaWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
|
queryWrapper.selectAll(HotCity.class);
|
queryWrapper.selectAs(Areas::getName,HotCity::getCityName);
|
queryWrapper.leftJoin(Areas.class,Areas::getId,HotCity::getCityId);
|
|
queryWrapper.eq(pageWrap.getModel().getCityId()!=null,HotCity::getCityId,pageWrap.getModel().getCityId());
|
queryWrapper.eq(HotCity::getIsdeleted,Constants.ZERO);
|
queryWrapper.orderByAsc(HotCity::getSortnum);
|
IPage<HotCity> result = hotCityJoinMapper.selectJoinPage(page, HotCity.class, queryWrapper);
|
return PageData.from(result);
|
}
|
|
@Override
|
public long count(HotCity hotCity) {
|
QueryWrapper<HotCity> wrapper = new QueryWrapper<>(hotCity);
|
return hotCityMapper.selectCount(wrapper);
|
}
|
|
/****************************************移动端接口开始********************************************************************/
|
|
@Override
|
public List<HotCityResponse> getHotCityResponseList() {
|
return hotCityMapper.getHotCityResponse();
|
}
|
|
}
|