package cn.gistack.sm.sjztmd.service.impl;
|
|
import cn.gistack.sm.sjztmd.entity.TbResGeneralInvestigation;
|
import cn.gistack.sm.sjztmd.entity.TbResGeneralInvestigationState;
|
import cn.gistack.sm.sjztmd.mapper.TbResGeneralInvestigationMapper;
|
import cn.gistack.sm.sjztmd.service.ITbResGeneralInvestigationService;
|
import cn.gistack.sm.sjztmd.service.ITbResGeneralInvestigationStateService;
|
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsBar;
|
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsParams;
|
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsPie;
|
import cn.gistack.sm.sjztmd.util.CalculateUtils;
|
import cn.gistack.sm.sjztmd.vo.TbResGeneralInvestigationParam;
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.DateUtil;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.text.DecimalFormat;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* @PROJECT_NAME: skjcmanager
|
* @DESCRIPTION:
|
* @USER: aix
|
* @DATE: 2024/1/3 14:36
|
*/
|
@Service
|
@DS("zt")
|
@Transactional(rollbackFor = Exception.class)
|
public class TbResGeneralInvestigationServiceImpl extends ServiceImpl<TbResGeneralInvestigationMapper, TbResGeneralInvestigation> implements ITbResGeneralInvestigationService {
|
|
@Autowired
|
private ITbResGeneralInvestigationStateService tbResGeneralInvestigationStateService;
|
|
@Override
|
@Transactional
|
public R saveOrUpdateBy(TbResGeneralInvestigation entity) {
|
|
QueryWrapper queryWrapper = new QueryWrapper();
|
queryWrapper.eq("\"res_guid\"",entity.getResGuid());
|
queryWrapper.eq("\"tb_year\"",entity.getTbYear());
|
// queryWrapper.eq("\"tb_quarter\"",entity.getTbQuarter());
|
TbResGeneralInvestigationState state = tbResGeneralInvestigationStateService.getOne(queryWrapper);
|
if (null == state) {
|
state = new TbResGeneralInvestigationState();
|
state.setResGuid(entity.getResGuid());
|
state.setTbQuarter(entity.getTbQuarter());
|
state.setTbYear(entity.getTbYear());
|
state.setCreateTime(entity.getCreateTime());
|
state.setCreateUser(entity.getCreateUser());
|
} else {
|
if (state.getCheckState() == 1 || state.getCheckState() == 2) {
|
return R.fail(entity.getResName() + "本年度已经普查完成,不能在提交了。");
|
}
|
}
|
|
// 是否普查完成 1是 0否
|
if (entity.getCheckState() != 0) {
|
state.setCheckState(entity.getIsInvCom());
|
}else{
|
state.setCheckState(0);
|
}
|
|
tbResGeneralInvestigationStateService.saveOrUpdate(state);
|
|
entity.setTbStateId(state.getGuid());
|
return R.status(this.saveOrUpdate(entity));
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public R saveOrUpdateByBatch(TbResGeneralInvestigationParam tbResGeneralInvestigationParam) {
|
List<TbResGeneralInvestigation> list = tbResGeneralInvestigationParam.getList();
|
TbResGeneralInvestigation entity = list.get(0);
|
|
//查询该水库本年度是否有填报状态记录
|
QueryWrapper queryWrapper = new QueryWrapper();
|
queryWrapper.eq("\"res_guid\"",entity.getResGuid());
|
queryWrapper.eq("\"tb_year\"",entity.getTbYear());
|
TbResGeneralInvestigationState state = tbResGeneralInvestigationStateService.getOne(queryWrapper);
|
if (null == state) {
|
//无填报状态记录则新建
|
state = new TbResGeneralInvestigationState();
|
state.setResGuid(entity.getResGuid());
|
state.setTbQuarter(entity.getTbQuarter());
|
state.setTbYear(entity.getTbYear());
|
state.setCreateTime(entity.getCreateTime());
|
state.setCreateUser(entity.getCreateUser());
|
} else {
|
//查看填报状态,只有0填报中才可以一直填报
|
if (state.getCheckState() == 1 || state.getCheckState() == 2) {
|
return R.fail(entity.getResName() + "本年度已经普查完成,不能在提交了。");
|
}
|
}
|
|
state.setCheckState(tbResGeneralInvestigationParam.getCheckState());
|
tbResGeneralInvestigationStateService.saveOrUpdate(state);
|
// //先把数据移除
|
// QueryWrapper delete = new QueryWrapper();
|
// delete.eq("\"tb_state_id\"",state.getGuid());
|
// boolean remove = remove(delete);
|
//
|
// if (remove){
|
//
|
// }
|
|
for (int i = 0; i < list.size(); i++) {
|
TbResGeneralInvestigation tbResGeneralInvestigation = list.get(i);
|
//id清空方便批量新增
|
// tbResGeneralInvestigation.setGuid("");
|
|
if (tbResGeneralInvestigation.getCreateTime() == null){
|
tbResGeneralInvestigation.setCreateTime(DateUtil.now());
|
}
|
|
if (tbResGeneralInvestigation.getCreateUser() == null){
|
tbResGeneralInvestigation.setCreateUser(AuthUtil.getUserId().toString());
|
}
|
|
//设置状态表id
|
tbResGeneralInvestigation.setTbStateId(state.getGuid());
|
}
|
return R.status(saveOrUpdateBatch(list));
|
}
|
|
@Override
|
public StatisticsPie statisticsPie(StatisticsParams statisticsParams) {
|
return baseMapper.statisticsPie(statisticsParams);
|
}
|
|
|
|
|
@Override
|
public List<StatisticsBar> statisticsBar(StatisticsParams statisticsParams) {
|
String adCode = statisticsParams.getAdCode();
|
//默认省
|
String adGrad = "1";
|
|
//若行政区划不为空
|
if (StringUtil.isNotBlank(adCode)){
|
if (adCode.substring(0,4).indexOf("00") > -1) {
|
//前四位包含00说明是湖北省 4200/00000000
|
adGrad = "1";
|
} else if (adCode.substring(0,6).indexOf("00") > -1) {
|
//前六位包含00说明是市级 420100/000000
|
adGrad = "2";
|
}else if (adCode.substring(0,8).indexOf("00") > -1){
|
//前8位包含00 说明是区级 42011700/0000
|
adGrad = "3";
|
}
|
}
|
List<StatisticsBar> list = new ArrayList<>();
|
|
if (adGrad.equals("3")){
|
//区级需要展示水库
|
list = baseMapper.getCountyStatisticsBar(statisticsParams);
|
}else if (adGrad.equals("2")){
|
list = baseMapper.getCityStatisticsBar(statisticsParams);
|
}else if (adGrad.equals("1")){
|
statisticsParams.setAdCode("420000000000");
|
list = baseMapper.getProvinceStatisticsBar(statisticsParams);
|
}
|
|
// if (!adGrad.equals("3")){
|
// //计算有蚁率
|
// DecimalFormat df = new DecimalFormat("0.00");
|
// list.forEach(statisticsBar -> {
|
//
|
// //有蚁率 = 危害座数/水库总数 =》dangerRate = dangerNum / resNum
|
// if (statisticsBar.getResNum() == 0){
|
// //如果水库数量为0,有蚁率为0
|
// statisticsBar.setDangerRate("0");
|
// }else{
|
// String percent = CalculateUtils.calculatePercent(statisticsBar.getDangerNum(), statisticsBar.getResNum());
|
//
|
// statisticsBar.setDangerRate(percent);
|
//
|
// }
|
// });
|
// }
|
|
return list;
|
}
|
}
|