package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.newfiber.api.core.commons.CustomException; import com.newfiber.api.core.commons.ResultCode; import com.newfiber.api.pc.dao.UserSiteViewMapper; import com.newfiber.api.pc.dto.UserSiteDTO; import com.newfiber.api.pc.model.entity.UserSiteView; import com.newfiber.api.pc.service.UserSiteViewService; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; /** * @description: TODO * @author: 张鸿志 * @date: 2021/1/12 15:27 * @version: v1.0 */ @Service public class UserSiteViewServiceImpl extends ServiceImpl<UserSiteViewMapper, UserSiteView> implements UserSiteViewService { @Override public void configUserSite(UserSiteDTO userSiteDTO) { if(!StringUtils.isEmpty(userSiteDTO)){ //先查询当前用户编号是否已经配备,如果配备就删除掉,将新的数据插入其中 if(!StringUtils.isEmpty(userSiteDTO.getUserNo())){ EntityWrapper<UserSiteView> wrapper = new EntityWrapper<>(); wrapper.eq("user_no",userSiteDTO.getUserNo()); List<UserSiteView> userSiteViews = this.selectList(wrapper); if(userSiteViews.size() > 0){ //执行删除操作 this.delete(wrapper); } //执行新增操作 //构建对象 if(!(userSiteDTO.getSiteNos().size() > 8 || userSiteDTO.getSiteNos().size() < 0)){ List<UserSiteView> list = new ArrayList<>(); for(String siteNo : userSiteDTO.getSiteNos()){ UserSiteView usv = new UserSiteView(); usv.setUserNo(userSiteDTO.getUserNo()); usv.setSiteNo(siteNo); list.add(usv); } this.insertBatch(list); } } }else{ throw new CustomException(ResultCode.PARAM_NULL); } } @Override public List<UserSiteView> queryList(String userNo) { if(StringUtils.isEmpty(userNo)){ throw new CustomException(ResultCode.PARAM_NULL); } EntityWrapper<UserSiteView> wrapper = new EntityWrapper<>(); wrapper.eq("user_no",userNo); return this.selectList(wrapper); } }