package com.panzhihua.service_grid.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.panzhihua.common.model.dtos.grid.*;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.grid.ComActEasyPhotoAdminVO;
|
import com.panzhihua.common.model.vos.grid.ComActEasyPhotoDetailsVO;
|
import com.panzhihua.common.model.vos.grid.ComActEasyPhotoVO;
|
import com.panzhihua.service_grid.dao.ComActEasyPhotoMapper;
|
import com.panzhihua.service_grid.dao.ComActEasyPhotoTypeRelationMapper;
|
import com.panzhihua.service_grid.model.dos.ComActEasyPhotoDO;
|
import com.panzhihua.service_grid.model.dos.ComActEasyPhotoTypeRelationDO;
|
import com.panzhihua.service_grid.service.ComActEasyPhotoService;
|
import com.panzhihua.service_grid.service.ComActEasyPhotoTypeRelationService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* @auther lyq
|
* @create 2021-04-14 15:03:01
|
* @describe 订单表服务实现类
|
*/
|
@Slf4j
|
@Service
|
public class ComActEasyPhotoServiceImpl extends ServiceImpl<ComActEasyPhotoMapper, ComActEasyPhotoDO>
|
implements ComActEasyPhotoService {
|
|
@Resource
|
private ComActEasyPhotoMapper comActEasyPhotoMapper;
|
@Resource
|
private ComActEasyPhotoTypeRelationMapper comActEasyPhotoTypeRelationMapper;
|
@Resource
|
private ComActEasyPhotoTypeRelationService comActEasyPhotoTypeRelationService;
|
|
/**
|
* 新增社区活动 》随手拍
|
*
|
* @param comActEasyPhotoAddDTO
|
* @return 新增结果
|
*/
|
@Override
|
public R add(ComActEasyPhotoAddDTO comActEasyPhotoAddDTO) {
|
ComActEasyPhotoDO comActEasyPhotoDO = new ComActEasyPhotoDO();
|
BeanUtils.copyProperties(comActEasyPhotoAddDTO, comActEasyPhotoDO);
|
comActEasyPhotoDO.setCreateAt(new Date());
|
if (comActEasyPhotoMapper.insert(comActEasyPhotoDO) > 0) {
|
return R.ok();
|
}
|
return R.fail();
|
}
|
|
/**
|
* 修改社区活动 》随手拍
|
*
|
* @param comActEasyPhotoEditDTO
|
* @return 维护结果
|
*/
|
@Override
|
public R edit(ComActEasyPhotoEditDTO comActEasyPhotoEditDTO) {
|
ComActEasyPhotoDO comActEasyPhotoDO = new ComActEasyPhotoDO();
|
BeanUtils.copyProperties(comActEasyPhotoEditDTO, comActEasyPhotoDO);
|
// comActEasyPhotoDO.setUpdateAt(new Date());
|
if (comActEasyPhotoMapper.updateById(comActEasyPhotoDO) > 0) {
|
return R.ok();
|
}
|
return R.fail();
|
}
|
|
/**
|
* 分页查找社区活动 》随手拍
|
*
|
* @param easyAppDTO
|
* @return 维护结果
|
*/
|
@Override
|
public R<IPage<ComActEasyPhotoVO>> query(PageEasyAppDTO easyAppDTO) {
|
Page page = new Page(easyAppDTO.getPageNum(), easyAppDTO.getPageSize());
|
if (easyAppDTO.getStatus() != null) {
|
switch (easyAppDTO.getStatus()) {
|
case 1:
|
easyAppDTO.setHandleStatus(1);
|
break;
|
case 2:
|
easyAppDTO.setIsReport(1);
|
break;
|
case 3:
|
easyAppDTO.setIsPublicity(1);
|
break;
|
case 4:
|
easyAppDTO.setIsPublicity(2);
|
break;
|
default:
|
break;
|
}
|
}
|
return R.ok(comActEasyPhotoMapper.findByPage(page, easyAppDTO));
|
}
|
|
/**
|
* 删除社区活动 》随手拍
|
*
|
* @param ComActEasyPhotoDeleteDTO
|
* @return 平台用户信息
|
*/
|
@Override
|
public R delete(ComActEasyPhotoDeleteDTO ComActEasyPhotoDeleteDTO) {
|
return R.fail();
|
}
|
|
/**
|
* 查询社区活动 》随手拍详细信息
|
*
|
* @param id
|
* 社区活动 》随手拍 id
|
* @return 查找结果
|
*/
|
@Override
|
public R<ComActEasyPhotoDetailsVO> comActEasyPhotoDetails(Long id) {
|
ComActEasyPhotoDO comActEasyPhotoDO = comActEasyPhotoMapper.selectById(id);
|
if (comActEasyPhotoDO != null) {
|
ComActEasyPhotoDetailsVO comActEasyPhotoDetailsVO = new ComActEasyPhotoDetailsVO();
|
BeanUtils.copyProperties(comActEasyPhotoDO, comActEasyPhotoDetailsVO);
|
return R.ok(comActEasyPhotoDetailsVO);
|
}
|
return R.fail();
|
}
|
|
/**
|
* 根据随手拍id查询随手拍详情
|
*
|
* @param easyId
|
* 随手拍id
|
* @return 随手拍详情
|
*/
|
@Override
|
public R detail(Long easyId) {
|
ComActEasyPhotoVO easyPhotoVO = this.baseMapper.findByEaseId(easyId);
|
if (easyPhotoVO != null) {
|
// 查询随手拍类型
|
List<String> typeRelationList = comActEasyPhotoTypeRelationMapper.getEasyPhotoTypeRelationByEasyId(easyId);
|
if (!typeRelationList.isEmpty()) {
|
easyPhotoVO.setEasyPhotoList(typeRelationList);
|
}
|
}
|
return R.ok(easyPhotoVO);
|
}
|
|
/**
|
* 随手拍处理
|
*
|
* @param photoHandleDTO
|
* 请求参数
|
* @return 处理结果
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R easyHandle(ComActEasyPhotoHandleDTO photoHandleDTO) {
|
ComActEasyPhotoDO easyPhotoDO = this.baseMapper.selectById(photoHandleDTO.getId());
|
if (easyPhotoDO == null) {
|
return R.fail("随手拍不存在");
|
}
|
if (easyPhotoDO.getHandleStatus().equals(ComActEasyPhotoDO.handleStatus.yes)) {
|
return R.fail("该随手拍已处理");
|
}
|
BeanUtils.copyProperties(photoHandleDTO, easyPhotoDO);
|
easyPhotoDO.setHandleStatus(ComActEasyPhotoDO.handleStatus.yes);
|
easyPhotoDO.setFeedbackAt(new Date());
|
// 关联随手拍类型
|
// if (!photoHandleDTO.getEasyTypeIds().isEmpty()) {
|
// List<ComActEasyPhotoTypeRelationDO> typeRelationDOList = new ArrayList<>();
|
// photoHandleDTO.getEasyTypeIds().forEach(typeId -> {
|
// ComActEasyPhotoTypeRelationDO typeRelationDO = new ComActEasyPhotoTypeRelationDO();
|
// typeRelationDO.setEasyId(easyPhotoDO.getId());
|
// typeRelationDO.setEasyTypeId(typeId);
|
// typeRelationDO.setCreateAt(new Date());
|
// typeRelationDOList.add(typeRelationDO);
|
// });
|
// comActEasyPhotoTypeRelationService.saveBatch(typeRelationDOList);
|
// }
|
if (this.baseMapper.updateById(easyPhotoDO) > 0) {
|
return R.ok();
|
} else {
|
return R.fail();
|
}
|
}
|
|
/**
|
* 随手拍公示状态切换
|
*
|
* @param photoHandleDTO
|
* 请求参数
|
* @return 切换结果
|
*/
|
@Override
|
public R easyPublicity(ComActEasyPhotoHandleDTO photoHandleDTO) {
|
|
ComActEasyPhotoDO easyPhotoDO = this.baseMapper.selectById(photoHandleDTO.getId());
|
if (easyPhotoDO == null) {
|
return R.fail("随手拍不存在");
|
}
|
easyPhotoDO.setIsPublicity(photoHandleDTO.getIsPublicity());
|
if (this.baseMapper.updateById(easyPhotoDO) > 0) {
|
return R.ok();
|
} else {
|
return R.fail();
|
}
|
}
|
|
/**
|
* 随手拍上报社区
|
*
|
* @param photoHandleDTO
|
* 请求参数
|
* @return 上报结果
|
*/
|
@Override
|
public R easyReport(ComActEasyPhotoHandleDTO photoHandleDTO) {
|
ComActEasyPhotoDO easyPhotoDO = this.baseMapper.selectById(photoHandleDTO.getId());
|
if (easyPhotoDO == null) {
|
return R.fail("随手拍不存在");
|
}
|
if (easyPhotoDO.getIsReport().equals(ComActEasyPhotoDO.isReport.yes)) {
|
return R.fail("随手拍已上报");
|
}
|
easyPhotoDO.setIsReport(ComActEasyPhotoDO.isReport.yes);
|
if (this.baseMapper.updateById(easyPhotoDO) > 0) {
|
return R.ok();
|
} else {
|
return R.fail();
|
}
|
}
|
|
/**
|
* 后台管理-分页查询随手拍列表
|
*
|
* @param easyAppDTO
|
* 请求参数
|
* @return 随手拍列表
|
*/
|
@Override
|
public R easyListByAdmin(PageEasyAdminDTO easyAppDTO) {
|
IPage<ComActEasyPhotoAdminVO> photoAdminVOIPage =
|
this.baseMapper.easyListByAdmin(new Page(easyAppDTO.getPageNum(), easyAppDTO.getPageSize()), easyAppDTO);
|
if (!photoAdminVOIPage.getRecords().isEmpty()) {
|
photoAdminVOIPage.getRecords().forEach(photoAdmin -> {
|
if(photoAdmin.getClassifyId() != null){
|
List<String> photoTypeList =
|
comActEasyPhotoTypeRelationMapper.getEasyPhotoClassifyName(photoAdmin.getClassifyId());
|
if (!photoTypeList.isEmpty()) {
|
photoAdmin.setPhotoTypeList(photoTypeList);
|
}
|
}
|
});
|
}
|
return R.ok(photoAdminVOIPage);
|
}
|
|
/**
|
* 后台管理-随手拍详情
|
*
|
* @param easyId
|
* 随手拍id
|
* @return 随手拍详情
|
*/
|
@Override
|
public R easyDetailByAdmin(Long easyId) {
|
ComActEasyPhotoAdminVO photoAdminVO = this.baseMapper.easyDetailByAdmin(easyId);
|
if (photoAdminVO == null) {
|
return R.fail("随手拍不存在");
|
}
|
if (photoAdminVO.getHandleStatus().equals(ComActEasyPhotoDO.handleStatus.yes)) {
|
// 随手拍已处理,查询随手拍类型
|
List<String> photoTypeList =
|
comActEasyPhotoTypeRelationMapper.getEasyPhotoTypeRelationByEasyId(photoAdminVO.getId());
|
if (!photoTypeList.isEmpty()) {
|
photoAdminVO.setPhotoTypeList(photoTypeList);
|
}
|
}
|
return R.ok(photoAdminVO);
|
}
|
|
/**
|
* 后台管理-随手拍处理
|
*
|
* @param photoHandleDTO
|
* 请求参数
|
* @return 处理结果
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R easyHandleByAdmin(ComActEasyPhotoHandleDTO photoHandleDTO) {
|
ComActEasyPhotoDO easyPhotoDO = this.baseMapper.selectById(photoHandleDTO.getId());
|
if (easyPhotoDO == null) {
|
return R.fail("随手拍不存在");
|
}
|
if (easyPhotoDO.getIsReport().equals(ComActEasyPhotoDO.isReport.no)) {
|
return R.fail("该随手拍未上报,不可处理");
|
}
|
if (easyPhotoDO.getHandleStatus().equals(ComActEasyPhotoDO.handleStatus.yes)) {
|
return R.fail("该随手拍已处理");
|
}
|
BeanUtils.copyProperties(photoHandleDTO, easyPhotoDO);
|
easyPhotoDO.setHandleStatus(ComActEasyPhotoDO.handleStatus.yes);
|
easyPhotoDO.setFeedbackAt(new Date());
|
// 关联随手拍类型
|
if (!photoHandleDTO.getEasyTypeIds().isEmpty()) {
|
List<ComActEasyPhotoTypeRelationDO> typeRelationDOList = new ArrayList<>();
|
photoHandleDTO.getEasyTypeIds().forEach(typeId -> {
|
ComActEasyPhotoTypeRelationDO typeRelationDO = new ComActEasyPhotoTypeRelationDO();
|
typeRelationDO.setEasyId(easyPhotoDO.getId());
|
typeRelationDO.setEasyTypeId(typeId);
|
typeRelationDO.setCreateAt(new Date());
|
typeRelationDOList.add(typeRelationDO);
|
});
|
comActEasyPhotoTypeRelationService.saveBatch(typeRelationDOList);
|
}
|
if (this.baseMapper.updateById(easyPhotoDO) > 0) {
|
return R.ok();
|
} else {
|
return R.fail();
|
}
|
}
|
|
/**
|
* 后台管理-批量修改随手拍公示状态/删除随手拍
|
*
|
* @param photoEditDTO
|
* 请求参数
|
* @return 修改/删除结果
|
*/
|
@Override
|
public R easyPublicityByAdmin(ComActEasyPhotoEditAdminDTO photoEditDTO) {
|
|
if (photoEditDTO.getType().equals(1)) {
|
Integer count = this.baseMapper.selectCount(new QueryWrapper<ComActEasyPhotoDO>().lambda()
|
.eq(ComActEasyPhotoDO::getHandleStatus, ComActEasyPhotoDO.handleStatus.no)
|
.in(ComActEasyPhotoDO::getId, photoEditDTO.getIds()));
|
if (count > 0) {
|
return R.fail("您选择的有未处理的随手拍,不可进行操作");
|
}
|
}
|
|
if (this.baseMapper.easyPublicityByAdmin(photoEditDTO) > 0) {
|
return R.ok();
|
} else {
|
return R.fail();
|
}
|
}
|
|
}
|