package com.panzhihua.service_dangjian.service.impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.google.common.collect.Lists;
|
import com.panzhihua.common.enums.ComPbCheckUnitTypeEnum;
|
import com.panzhihua.common.model.dtos.common.AddComPbCheckUnitDto;
|
import com.panzhihua.common.model.dtos.common.EditComPbCheckUnitDto;
|
import com.panzhihua.common.model.dtos.common.PageComPbCheckUnitDto;
|
import com.panzhihua.common.model.dtos.common.PagePbCheckUnitCommonDto;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.TreeListVO;
|
import com.panzhihua.common.model.vos.common.ComPbCheckUnitVo;
|
import com.panzhihua.common.model.vos.common.PbCheckUnitStatisticsVo;
|
import com.panzhihua.common.model.vos.partybuilding.excel.ComPbCheckUnitErrorExcelVO;
|
import com.panzhihua.common.model.vos.partybuilding.excel.ComPbCheckUnitExcelVO;
|
import com.panzhihua.common.utlis.StringUtils;
|
import com.panzhihua.service_dangjian.dao.ComPbCheckUnitMapper;
|
import com.panzhihua.service_dangjian.dao.ComPbMemberDAO;
|
import com.panzhihua.service_dangjian.dao.ComPbMemberRoleDAO;
|
import com.panzhihua.service_dangjian.entity.ComPbCheckUnit;
|
import com.panzhihua.service_dangjian.model.dos.ComPbMemberDO;
|
import com.panzhihua.service_dangjian.model.dos.ComPbMemberRoleDO;
|
import com.panzhihua.service_dangjian.service.ComPbCheckUnitService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* title: 党建-报到单位表服务实现类
|
* <p>
|
* projectName 成都呐喊信息技术有限公司-智慧社区项目
|
* <p>
|
* description: 党建-报到单位表服务实现类
|
*
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Service("comPbCheckUnitService")
|
public class ComPbCheckUnitServiceImpl extends ServiceImpl<ComPbCheckUnitMapper, ComPbCheckUnit> implements ComPbCheckUnitService {
|
|
@Resource
|
private ComPbMemberDAO comPbMemberDAO;
|
@Resource
|
private ComPbMemberRoleDAO comPbMemberRoleDAO;
|
|
|
/**
|
* description queryByPage 分页查询
|
*
|
* @param comPbCheckUnit 请求参数
|
* @return 分页查询列表数据
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Override
|
public R queryByPage(PageComPbCheckUnitDto comPbCheckUnit) {
|
|
Long communityId = comPbCheckUnit.getCommunityId();
|
if (communityId != null){
|
List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds = new ArrayList<>();
|
communityIds.add(communityId);
|
}
|
comPbCheckUnit.setCommunityIds(communityIds);
|
}
|
IPage<ComPbCheckUnitVo> checkUnitVoPage= this.baseMapper.queryAllByLimit(comPbCheckUnit, new Page(comPbCheckUnit.getPageNum(), comPbCheckUnit.getPageSize()));
|
checkUnitVoPage.getRecords().forEach(checkUnit -> {
|
if(StringUtils.isEmpty(checkUnit.getOrgName())){
|
checkUnit.setOrgName("待编辑党支部");
|
}
|
});
|
return R.ok(checkUnitVoPage);
|
}
|
|
@Override
|
public R treeList(TreeListVO treeListVO) {
|
QueryWrapper<ComPbCheckUnit> wrapper = new QueryWrapper<>();
|
if(treeListVO.getName() != null){
|
wrapper.eq("belong_to",treeListVO.getName());
|
} else if(treeListVO.getOrgName() != null){
|
wrapper.eq("org_name",treeListVO.getOrgName());
|
} else {
|
return R.ok();
|
}
|
List<ComPbCheckUnit> comPbCheckUnits = this.baseMapper.selectList(wrapper);
|
return R.ok(comPbCheckUnits);
|
}
|
|
@Override
|
public R orgList() {
|
QueryWrapper<ComPbCheckUnit> wrapper = new QueryWrapper<>();
|
List<ComPbCheckUnitVo> voList = new ArrayList<>();
|
List<ComPbCheckUnit> list = this.baseMapper.selectList(wrapper);
|
Map<String, List<ComPbCheckUnit>> map = list.stream().filter(f -> f.getOrgName() != null).collect(Collectors.groupingBy(ComPbCheckUnit::getOrgName));
|
for (Map.Entry<String, List<ComPbCheckUnit>> entry : map.entrySet()) {
|
ComPbCheckUnitVo pbCheckUnitVo = new ComPbCheckUnitVo();
|
pbCheckUnitVo.setOrgName(entry.getKey());
|
voList.add(pbCheckUnitVo);
|
}
|
return R.ok(voList);
|
}
|
|
/**
|
* description insert 新增数据
|
*
|
* @param comPbCheckUnit 请求参数
|
* @return 新增结果
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Override
|
@Transactional
|
public R insert(AddComPbCheckUnitDto comPbCheckUnit) {
|
Long communityId=this.baseMapper.selectCommunityId(comPbCheckUnit.getHelpCommunityName().split(",")[0],comPbCheckUnit.getHelpCommunityName().split(",")[1],comPbCheckUnit.getHelpCommunityName().split(",")[2]);
|
ComPbCheckUnit entity = new ComPbCheckUnit();
|
BeanUtils.copyProperties(comPbCheckUnit, entity);
|
int a=0;
|
if(!StringUtils.isEmpty(comPbCheckUnit.getAdminPhone()))
|
{
|
a=this.baseMapper.selectOrgAdmin(comPbCheckUnit.getAdminPhone());
|
}
|
if(a!=0)
|
{
|
return R.fail("该手机号已绑定管理员!");
|
}
|
if(communityId!=null){
|
entity.setCommunityId(communityId);
|
}
|
if (this.baseMapper.insert(entity) > 0) {
|
return R.ok();
|
}
|
return R.fail("添加失败");
|
}
|
|
/**
|
* description update 修改数据
|
*
|
* @param editDto 请求参数
|
* @return 修改结果
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Override
|
public R update(EditComPbCheckUnitDto editDto) {
|
ComPbCheckUnit entity = this.baseMapper.selectById(editDto.getId());
|
if (entity == null) {
|
return R.fail("未查询到该记录");
|
}
|
BeanUtils.copyProperties(editDto, entity);
|
if (this.baseMapper.updateById(entity) > 0) {
|
return R.ok();
|
}
|
return R.fail("修改失败");
|
}
|
|
/**
|
* description deleteById 通过主键删除数据
|
*
|
* @param id 主键id
|
* @return 删除结果
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Override
|
public R deleteById(Long id) {
|
Integer memberCount = comPbMemberDAO.selectCount(new QueryWrapper<ComPbMemberDO>().lambda()
|
.eq(ComPbMemberDO::getCheckUnitId,id));
|
if(memberCount > 0){
|
return R.fail("该数据已被引用,无法删除!");
|
}
|
Integer memberRoleCount = comPbMemberRoleDAO.selectCount(new QueryWrapper<ComPbMemberRoleDO>().lambda()
|
.eq(ComPbMemberRoleDO::getCheckUnitId,id));
|
if(memberRoleCount > 0){
|
return R.fail("该数据已被引用,无法删除!");
|
}
|
if (this.baseMapper.deleteById(id) > 0) {
|
return R.ok();
|
}
|
return R.fail("删除失败");
|
}
|
|
/**
|
* description detailById 查询详情
|
*
|
* @param id 主键id
|
* @return 详情数据
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Override
|
public R detailById(Long id) {
|
ComPbCheckUnitVo checkUnitVo = this.baseMapper.queryById(id);
|
if(checkUnitVo != null && StringUtils.isEmpty(checkUnitVo.getContacts())){
|
checkUnitVo.setContacts("待编辑负责人");
|
}
|
if(checkUnitVo != null && StringUtils.isEmpty(checkUnitVo.getOrgName())){
|
checkUnitVo.setOrgName("待编辑党支部");
|
}
|
return R.ok(checkUnitVo);
|
}
|
|
/**
|
* description queryByPage 查询列表
|
*
|
* @param comPbCheckUnit 请求参数
|
* @return 列表数据
|
* @author lyq
|
* @date 2022-02-16 16:22:26
|
*/
|
@Override
|
public R queryByList(PageComPbCheckUnitDto comPbCheckUnit) {
|
Long communityId = comPbCheckUnit.getCommunityId();
|
if (communityId != null){
|
List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds = new ArrayList<>();
|
communityIds.add(communityId);
|
}
|
comPbCheckUnit.setCommunityIds(communityIds);
|
}
|
IPage<ComPbCheckUnitVo> checkUnitList = this.baseMapper.queryAllByLimit(comPbCheckUnit,new Page(comPbCheckUnit.getPageNum(),comPbCheckUnit.getPageSize()));
|
checkUnitList.getRecords().forEach(checkUnit -> {
|
if(StringUtils.isEmpty(checkUnit.getOrgName())){
|
checkUnit.setOrgName("待编辑党支部");
|
}
|
if(StringUtils.isNotEmpty(checkUnit.getAreaCode())){
|
switch (checkUnit.getAreaCode()){
|
case "510423": checkUnit.setAreaName("西区"); break;
|
case "510402": checkUnit.setAreaName("东区"); break;
|
case "510411": checkUnit.setAreaName("仁和区"); break;
|
case "510421": checkUnit.setAreaName("米易县"); break;
|
case "510422": checkUnit.setAreaName("盐边"); break;
|
}
|
}
|
});
|
return R.ok(checkUnitList);
|
}
|
|
/**
|
* 批量导入报道单位
|
* @param list 导入数据
|
* @param communityId 社区id
|
* @param userId 用户id
|
* @return 导入结果
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R importCheckUnit(List<ComPbCheckUnitExcelVO> list, Long communityId, Long userId){
|
ArrayList<ComPbCheckUnitErrorExcelVO> mistakes = Lists.newArrayList();
|
ArrayList<ComPbCheckUnit> saveList = Lists.newArrayList();
|
Date nowDate = new Date();
|
if(list != null && list.size() > 0){
|
list.forEach(checkUnit -> {
|
ComPbCheckUnit comPbCheckUnit = this.baseMapper.selectOne(new QueryWrapper<ComPbCheckUnit>().lambda()
|
.eq(ComPbCheckUnit::getCommunityId,communityId).eq(ComPbCheckUnit::getName,checkUnit.getName()));
|
if(comPbCheckUnit != null){
|
ComPbCheckUnitErrorExcelVO checkUnitError = new ComPbCheckUnitErrorExcelVO();
|
BeanUtils.copyProperties(checkUnit,checkUnitError);
|
checkUnitError.setError("该单位已存在,不可重复导入");
|
mistakes.add(checkUnitError);
|
}else{
|
comPbCheckUnit = new ComPbCheckUnit();
|
BeanUtils.copyProperties(checkUnit,comPbCheckUnit);
|
comPbCheckUnit.setType(ComPbCheckUnitTypeEnum.getCodeByName(checkUnit.getType()));
|
comPbCheckUnit.setCommunityId(communityId);
|
comPbCheckUnit.setCreateAt(nowDate);
|
comPbCheckUnit.setCreateBy(userId);
|
saveList.add(comPbCheckUnit);
|
}
|
});
|
}
|
if(saveList.size() > 0){
|
this.saveBatch(saveList);
|
}
|
if(mistakes.size() > 0){
|
return R.fail(mistakes);
|
}
|
return R.ok();
|
}
|
|
@Override
|
public R detailByPhone(String phone) {
|
List<ComPbCheckUnit> comPbCheckUnits=this.baseMapper.selectList(new QueryWrapper<ComPbCheckUnit>().lambda().eq(ComPbCheckUnit::getAdminPhone,phone));
|
if(!comPbCheckUnits.isEmpty()){
|
return R.ok(comPbCheckUnits.get(0));
|
}
|
return R.ok();
|
}
|
|
/**
|
* 报到单位统计-顶部数据
|
* @param communityId
|
* @param belongTo
|
* @param choice
|
* @return
|
*/
|
@Override
|
public R unitStatisticsTop(Long communityId, String belongTo, String choice,Long[] unitIds,String yearTime) {
|
List<Long> communityIds = new ArrayList<>();
|
if (null != communityId){
|
communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds.add(communityId);
|
}
|
}
|
//查询 活动总积分
|
PbCheckUnitStatisticsVo vo = this.baseMapper.unitStatisticsTop(communityIds, belongTo, choice,unitIds,yearTime);
|
if(null != vo) {
|
Integer sum = this.baseMapper.organSumIntegral(communityIds,yearTime);
|
vo.setOrganSumIntegral(sum);
|
}
|
return R.ok(vo);
|
}
|
|
/**
|
* 报到单位统计
|
* @param commonDto
|
* @return
|
*/
|
@Override
|
public R unitStatistics(PagePbCheckUnitCommonDto commonDto) {
|
Long communityId = commonDto.getCommunityId();
|
if (null != communityId) {
|
List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds = new ArrayList<>();
|
communityIds.add(communityId);
|
}
|
commonDto.setCommunityIds(communityIds);
|
}
|
return R.ok(this.baseMapper.unitStatistics(commonDto, new Page(commonDto.getPageNum(), commonDto.getPageSize())));
|
}
|
|
/**
|
* 报到党员统计-顶部数据
|
* @param communityId
|
* @param belongTo
|
* @param choice
|
* @param checkUnitId
|
* @return
|
*/
|
@Override
|
public R pbStatisticsTop(Long communityId, String belongTo, String choice, Long checkUnitId,Long[] unitIds ,String yearTime) {
|
|
List<Long> communityIds = new ArrayList<>();
|
if (null != communityId){
|
communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds.add(communityId);
|
}
|
}
|
//查询 活动总积分
|
PbCheckUnitStatisticsVo vo = this.baseMapper.pbStatisticsTop(communityIds, belongTo, choice, checkUnitId,unitIds,yearTime);
|
if(null != vo) {
|
Integer sum = this.baseMapper.pbOrganSumIntegral(communityIds,yearTime);
|
vo.setOrganSumIntegral(sum);
|
}
|
return R.ok(vo);
|
}
|
|
/**
|
* 报到党员统计-按单位归属统计
|
* @param commonDto
|
* @return
|
*/
|
@Override
|
public R pbStatisticsBelong(PagePbCheckUnitCommonDto commonDto) {
|
Long communityId = commonDto.getCommunityId();
|
if (null != communityId) {
|
List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds = new ArrayList<>();
|
communityIds.add(communityId);
|
}
|
commonDto.setCommunityIds(communityIds);
|
}
|
return R.ok(this.baseMapper.pbStatisticsBelong(commonDto, new Page(commonDto.getPageNum(), commonDto.getPageSize())));
|
}
|
|
/**
|
* 报到党员统计-按单位统计
|
* @param commonDto
|
* @return
|
*/
|
@Override
|
public R pbStatisticsUnit(PagePbCheckUnitCommonDto commonDto) {
|
Long communityId = commonDto.getCommunityId();
|
List<Long> communityIds = comPbMemberDAO.selectIds(communityId);
|
if (CollUtil.isEmpty(communityIds)) {
|
communityIds = new ArrayList<>();
|
communityIds.add(communityId);
|
}
|
commonDto.setCommunityIds(communityIds);
|
return R.ok(this.baseMapper.pbStatisticsUnit(commonDto, new Page(commonDto.getPageNum(), commonDto.getPageSize())));
|
}
|
}
|