package com.java110.common.smo.impl; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import com.java110.common.dao.ISmallProgramAdvertHistoryServiceDao; import com.java110.common.dao.ISmallProgramAdvertServiceDao; import com.java110.core.base.smo.BaseServiceSMO; import com.java110.core.factory.GenerateCodeFactory; import com.java110.dto.PageDto; import com.java110.dto.smallProgramAdvert.*; import com.java110.dto.user.UserDto; import com.java110.intf.common.ISmallProgramAdvertServiceSMO; import com.java110.intf.user.IUserInnerServiceSMO; import com.java110.utils.constant.ResponseConstant; import com.java110.utils.exception.BusinessException; import com.java110.utils.exception.DAOException; import com.java110.utils.util.BeanConvertUtil; import com.java110.vo.ResultVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.Map; import static com.java110.utils.util.BeanConvertUtil.covertBeanList; /** * @ClassName FloorInnerServiceSMOImpl * @Description 广告信息内部服务实现类 * @Author wuxw * @Date 2019/4/24 9:20 * @Version 1.0 * add by wuxw 2019/4/24 **/ @RestController public class SmallProgramAdvertServiceSMOImpl extends BaseServiceSMO implements ISmallProgramAdvertServiceSMO { @Resource private ISmallProgramAdvertServiceDao smallProgramAdvertServiceDao; @Resource private ISmallProgramAdvertHistoryServiceDao smallProgramAdvertHistoryServiceDao; @Resource private IUserInnerServiceSMO userInnerServiceSMOImpl; @Override public ResultVo querySmallAdverts(QuertAdvertDto quertAdvertDto) { //校验是否传了 分页信息 int page = quertAdvertDto.getPage(); if (page != PageDto.DEFAULT_PAGE) { quertAdvertDto.setPage((page - 1) * quertAdvertDto.getRow()); } int count = smallProgramAdvertServiceDao.querySmallProgramAdvertsCount(BeanConvertUtil.beanCovertMap(quertAdvertDto)); List smallProgramAdvertListDtoList = Lists.newArrayList(); if (count > 0) { smallProgramAdvertListDtoList = BeanConvertUtil.covertBeanList(smallProgramAdvertServiceDao.querySmallProgramAdvertInfoList(BeanConvertUtil.beanCovertMap(quertAdvertDto)), SmallProgramAdvertDto.class); } ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) quertAdvertDto.getRow()), count, smallProgramAdvertListDtoList); return resultVo; } @Override public SmallProgramAdvertDto querySmallAdvertsInfo(QuertAdvertDto quertAdvertDto) { Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(quertAdvertDto)); if(map != null){ SmallProgramAdvertDto smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvertDto.class); List historyMap = smallProgramAdvertHistoryServiceDao.querySmallProgramAdvertInfoList(smallProgramAdvert.getId()); List historyList = BeanConvertUtil.covertBeanList(historyMap, SmallProgramAdvertHistoryDto.class); for(SmallProgramAdvertHistoryDto smallProgramAdvertHistoryDto : historyList){ UserDto userDto = new UserDto(); userDto.setUserId(smallProgramAdvertHistoryDto.getOperateUserId()); List userDtos = userInnerServiceSMOImpl.getUsers(userDto); if(!CollectionUtils.isEmpty(userDtos)){ smallProgramAdvertHistoryDto.setOperateUserName(userDtos.get(0).getName()); } } smallProgramAdvert.setHistoryList(historyList); return smallProgramAdvert; }else{ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息"); } } @Override public void saveSmallAdverts(SmallProgramAdvert smallProgramAdvert) { smallProgramAdvertServiceDao.saveSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert)); } @Override @Transactional public void updateSmallAdverts(SmallProgramAdvertSaveDto smallProgramAdvertSaveDto,String userId) { Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvertSaveDto)); if(map != null){ SmallProgramAdvert smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvert.class); String operation = "更新广告"; if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getPosition())){ smallProgramAdvert.setPosition(smallProgramAdvertSaveDto.getPosition()); } if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getAdvertsName())){ smallProgramAdvert.setAdvertsName(smallProgramAdvertSaveDto.getAdvertsName()); } if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getPicUrl())){ smallProgramAdvert.setPicUrl(smallProgramAdvertSaveDto.getPicUrl()); } if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getOssUrl())){ smallProgramAdvert.setOssUrl(smallProgramAdvertSaveDto.getOssUrl()); } if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getUrl())){ smallProgramAdvert.setUrl(smallProgramAdvertSaveDto.getUrl()); } if(smallProgramAdvertSaveDto.getSort() != null){ smallProgramAdvert.setSort(smallProgramAdvertSaveDto.getSort()); } if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getSupplierName())){ smallProgramAdvert.setSupplierName(smallProgramAdvertSaveDto.getSupplierName()); } if(!StringUtils.isEmpty(smallProgramAdvertSaveDto.getDesc())){ smallProgramAdvert.setDesc(smallProgramAdvertSaveDto.getDesc()); } smallProgramAdvert.setUpdateTime(new Date()); smallProgramAdvert.setUpdateUserId(userId); smallProgramAdvertServiceDao.updateSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert)); //保存更新日志 saveHistory(BeanConvertUtil.covertBean(map,SmallProgramAdvert.class),userId,operation); }else{ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息,广告id:"+smallProgramAdvertSaveDto.getId()); } } @Override @Transactional public void updateSmallAdvertsStatus(SmallProgramAdvertSaveDto smallProgramAdvertSaveDto,String userId) { if(!CollectionUtils.isEmpty(smallProgramAdvertSaveDto.getIdList())){ for(String id : smallProgramAdvertSaveDto.getIdList()){ smallProgramAdvertSaveDto.setId(id); Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvertSaveDto)); if(map != null){ SmallProgramAdvert smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvert.class); String operation = "更新广告"; if(smallProgramAdvertSaveDto.getStatus() != null){ smallProgramAdvert.setStatus(smallProgramAdvertSaveDto.getStatus()); if(smallProgramAdvertSaveDto.getStatus() == 2){ operation = "下线广告"; smallProgramAdvert.setOfflineTime(new Date()); smallProgramAdvert.setOnlineTime(null); }else if(smallProgramAdvertSaveDto.getStatus() == 1){ operation = "上线广告"; smallProgramAdvert.setOnlineTime(new Date()); smallProgramAdvert.setOfflineTime(null); } } smallProgramAdvert.setUpdateTime(new Date()); smallProgramAdvert.setUpdateUserId(userId); smallProgramAdvertServiceDao.updateSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert)); //保存更新日志 saveHistory(BeanConvertUtil.covertBean(map,SmallProgramAdvert.class),userId,operation); }else{ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息,广告id:"+id); } } } } @Override @Transactional public void deleteSmallAdverts(SmallProgramAdvertSaveDto smallProgramAdvertSaveDto, String userId) { if(!CollectionUtils.isEmpty(smallProgramAdvertSaveDto.getIdList())){ for(String id : smallProgramAdvertSaveDto.getIdList()){ smallProgramAdvertSaveDto.setId(id); Map map = smallProgramAdvertServiceDao.queryBusinessAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvertSaveDto)); if(map != null){ SmallProgramAdvert smallProgramAdvert = BeanConvertUtil.covertBean(map,SmallProgramAdvert.class); smallProgramAdvert.setUpdateTime(new Date()); smallProgramAdvert.setUpdateUserId(userId); smallProgramAdvert.setStatus(smallProgramAdvertSaveDto.getStatus()); smallProgramAdvertServiceDao.updateSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(smallProgramAdvert)); //保存更新日志 saveHistory(BeanConvertUtil.covertBean(map,SmallProgramAdvert.class),userId,"删除广告"); }else{ throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "无此广告信息,广告id:"+id); } } } } private void saveHistory(SmallProgramAdvert smallProgramAdvert,String userId ,String operation){ SmallProgramAdvertHistoryDto historyDto = new SmallProgramAdvertHistoryDto(); String historyId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_advertId); historyDto.setId(historyId); historyDto.setAdvertsId(smallProgramAdvert.getId()); historyDto.setOperateTime(new Date()); historyDto.setOperateUserId(userId); historyDto.setContent(JSONObject.toJSONString(smallProgramAdvert)); historyDto.setOperation(operation); smallProgramAdvertHistoryServiceDao.saveSmallProgramAdvertInfo(BeanConvertUtil.beanCovertMap(historyDto)); } }