package com.dy.pipIrrIrrigate.project;
|
|
|
import com.dy.common.webUtil.QueryResultVo;
|
import com.dy.pipIrrGlobal.daoIr.IrProjectGroupMapper;
|
import com.dy.pipIrrGlobal.daoIr.IrProjectMapper;
|
import com.dy.pipIrrGlobal.pojoIr.IrProject;
|
import com.dy.pipIrrGlobal.pojoIr.IrProjectGroup;
|
import com.dy.pipIrrGlobal.voIr.VoProject;
|
import com.dy.pipIrrGlobal.voIr.VoProjectDetail;
|
import com.dy.pipIrrGlobal.voIr.VoProjectOne;
|
import com.dy.pipIrrGlobal.voIr.VoProjectSimple;
|
import com.dy.pipIrrIrrigate.project.dto.IrrigateProject;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.dubbo.common.utils.PojoUtils;
|
import org.springframework.aop.framework.AopContext;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author :WuZeYu
|
* @Date :2024/5/14 13:56
|
* @LastEditTime :2024/5/14 13:56
|
* @Description
|
*/
|
@Slf4j
|
@Service
|
public class ProjectSv {
|
@Autowired
|
private IrProjectMapper irProjectMapper;
|
|
@Autowired
|
private IrProjectGroupMapper irProjectGroupMapper;
|
|
/**
|
* 添加项目,旧版本,原则上废弃
|
* @param po
|
* @return
|
*/
|
public Integer addProject(IrProject po) {
|
po.setOperateTime(new Date());
|
po.setDeleted((byte) 0);
|
if (po.getVillageId() != null) {
|
po.setTownId(irProjectMapper.getSupperByVillageId(po.getVillageId()));
|
po.setCountyId(irProjectMapper.getSupperByVillageId(po.getTownId()));
|
po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId()));
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
if (po.getTownId() != null) {
|
po.setCountyId(irProjectMapper.getSupperByVillageId(po.getTownId()));
|
po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId()));
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
if (po.getCountyId() != null) {
|
po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId()));
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
if (po.getCityId() != null) {
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
int rows = irProjectMapper.insertSelective(po);
|
if (rows == 0) {
|
return 0;
|
}
|
return 1;
|
}
|
|
/**
|
* 添加项目,目前使用
|
* @param po
|
* @return
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
public Map addIrrigateProject(IrrigateProject po) {
|
String projectName = po.getProjectName();
|
String irrigateGroups = po.getIrrigateGroups();
|
Long operatorId = po.getOperator();
|
|
IrProject irProject = new IrProject();
|
irProject.setProjectName(projectName);
|
irProject.setProjectState((byte)1);
|
irProject.setOperator(operatorId);
|
irProject.setOperateTime(new Date());
|
irProject.setDeleted((byte)0);
|
irProjectMapper.insert(irProject);
|
Long projectId = irProject.getId();
|
if(projectId == null) {
|
Map map = new HashMap<>();
|
map.put("success", false);
|
map.put("msg", "创建灌溉项目失败");
|
map.put("content", null);
|
return map;
|
}
|
|
String[] irrigateGroupArr = irrigateGroups.split(",");
|
Integer sort = 1;
|
for(String irrigateGroupId : irrigateGroupArr) {
|
String trimmed = irrigateGroupId.trim();
|
if(trimmed.isEmpty()) {
|
continue;
|
}
|
try {
|
Long irrigateGroupIdLong = Long.parseLong(trimmed);
|
IrProjectGroup irProjectGroup = new IrProjectGroup();
|
irProjectGroup.setProjectId(projectId);
|
irProjectGroup.setGroupId(irrigateGroupIdLong);
|
irProjectGroup.setSort(sort++);
|
irProjectGroupMapper.insert(irProjectGroup);
|
} catch (NumberFormatException e) {
|
Map map = new HashMap<>();
|
map.put("success", false);
|
map.put("msg", "灌溉组ID格式错误");
|
map.put("content", null);
|
return map;
|
}
|
}
|
Map map = new HashMap<>();
|
map.put("success", true);
|
map.put("msg", "添加灌溉项目成功");
|
map.put("content", null);
|
return map;
|
}
|
|
/**
|
* 删除灌溉项目,目前使用
|
* @param projectId
|
* @return
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
public Map deleteIrrigateProject(Long projectId) {
|
try {
|
irProjectGroupMapper.unbindGroup(projectId);
|
irProjectMapper.deleteByPrimaryKey(projectId);
|
|
Map map = new HashMap<>();
|
map.put("success", true);
|
map.put("msg", "灌溉项目删除成功");
|
map.put("content", null);
|
return map;
|
} catch (Exception e) {
|
Map map = new HashMap<>();
|
map.put("success", false);
|
map.put("msg", "灌溉项目删除失败");
|
map.put("content", null);
|
return map;
|
}
|
}
|
|
/**
|
* 修改灌溉项目,目前使用
|
* @param po
|
* @return
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
public Map updateIrrigateProject(IrrigateProject po) {
|
Long projectId = po.getProjectId();
|
Map map_deleteProject = ((ProjectSv) AopContext.currentProxy()).deleteIrrigateProject(projectId);
|
if(map_deleteProject.get("success").equals(false)) {
|
Map map = new HashMap<>();
|
map.put("success", false);
|
map.put("msg", map_deleteProject.get("msg").toString());
|
map.put("content", null);
|
return map;
|
}
|
|
Map map_addProject = ((ProjectSv) AopContext.currentProxy()).addIrrigateProject(po);
|
if(map_addProject.get("success").equals(false)) {
|
Map map = new HashMap<>();
|
map.put("success", false);
|
map.put("msg", map_addProject.get("msg").toString());
|
map.put("content", null);
|
return map;
|
}
|
|
Map map = new HashMap<>();
|
map.put("success", true);
|
map.put("msg", "修改灌溉项目成功");
|
map.put("content", null);
|
return map;
|
}
|
|
/**
|
* 删除项目,旧版本,原则上废弃
|
* @param id
|
*/
|
public Integer deleteProject(Long id) {
|
int rows = irProjectMapper.deleteLogicById(id);
|
if (rows == 0) {
|
return 0;
|
}
|
return 1;
|
}
|
|
/**
|
* 修改项目信息
|
* @param po
|
* @return
|
*/
|
public Integer updateProject(IrProject po){
|
po.setOperateTime(new Date());
|
if (po.getVillageId() != null) {
|
po.setTownId(irProjectMapper.getSupperByVillageId(po.getVillageId()));
|
po.setCountyId(irProjectMapper.getSupperByVillageId(po.getTownId()));
|
po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId()));
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
if (po.getTownId() != null) {
|
po.setCountyId(irProjectMapper.getSupperByVillageId(po.getTownId()));
|
po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId()));
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
if (po.getCountyId() != null) {
|
po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId()));
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
if (po.getCityId() != null) {
|
po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId()));
|
}
|
int rows = irProjectMapper.updateByPrimaryKeySelective(po);
|
if (rows == 0){
|
return 0;
|
}
|
return 1;
|
}
|
|
/**
|
* 修改项目状态
|
* @param po
|
* @return
|
*/
|
public Integer updateProjectState(IrProject po){
|
po.setOperateTime(new Date());
|
int rows = irProjectMapper.updateProjectState(po);
|
if (rows == 0){
|
return 0;
|
}
|
return 1;
|
}
|
|
/**
|
* 获取一个项目数据
|
* @param id
|
* @return
|
*/
|
public VoProjectOne selectById(Long id){
|
VoProjectOne irProject = irProjectMapper.selectById(id);
|
return irProject;
|
}
|
|
/**
|
* 分页查询项目,旧版本,原则上废弃
|
* @param queryVo
|
* @return
|
*/
|
public QueryResultVo<List<VoProject>> getProjects(QueryVo queryVo){
|
Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
|
Long itemTotal = irProjectMapper.getRecordCount(params);
|
|
QueryResultVo<List<VoProject>> rsVo = new QueryResultVo<>();
|
rsVo.pageSize = queryVo.pageSize;
|
rsVo.pageCurr = queryVo.pageCurr;
|
rsVo.calculateAndSet(itemTotal, params);
|
rsVo.obj = irProjectMapper.getProjects(params);
|
return rsVo;
|
}
|
|
/**
|
* 分页查询项目,新版本,目前使用
|
* @param queryVo
|
* @return
|
*/
|
public QueryResultVo<List<VoProjectSimple>> getSimpleProjects(QueryVo queryVo) {
|
Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
|
Long itemTotal = irProjectMapper.getSimpleProjectsCount(params);
|
|
QueryResultVo<List<VoProjectSimple>> rsVo = new QueryResultVo<>();
|
rsVo.pageSize = queryVo.pageSize;
|
rsVo.pageCurr = queryVo.pageCurr;
|
rsVo.calculateAndSet(itemTotal, params);
|
rsVo.obj = irProjectMapper.getSimpleProjects(params);
|
return rsVo;
|
}
|
|
/**
|
* 根据项目Id获取项目详情,编辑项目信息使用
|
* @param projectId
|
* @return
|
*/
|
public Map getProjectDetail(Long projectId) {
|
try {
|
VoProjectDetail voProjectDetail = irProjectMapper.getProjectDetail(projectId);
|
Map map = new HashMap<>();
|
map.put("success", true);
|
map.put("msg", "获取项目详情成功");
|
map.put("content", voProjectDetail);
|
return map;
|
} catch (Exception e) {
|
Map map = new HashMap<>();
|
map.put("success", false);
|
map.put("msg", "获取项目详情失败");
|
map.put("content", null);
|
return map;
|
}
|
}
|
}
|