Commit bd962c4b authored by 田涛's avatar 田涛

Bug-442\443修复

parent 8dd41241
......@@ -30,8 +30,7 @@ public class PlanClassifyTreeController extends BaseController {
String compCode = getOrgCode(reginParams);
model.setOrgCode(compCode);
model.setCreator(user.getUserId());
planClassifyTreeService.save(model);
return CommonResponseUtil2.success(model);
return CommonResponseUtil2.success(planClassifyTreeService.create(model));
}
@ApiOperation(value = "修改分类")
......@@ -42,19 +41,17 @@ public class PlanClassifyTreeController extends BaseController {
String compCode = getOrgCode(reginParams);
model.setOrgCode(compCode);
model.setCreator(user.getUserId());
planClassifyTreeService.save(model);
return CommonResponseUtil2.success(model);
return CommonResponseUtil2.success(planClassifyTreeService.update(model));
}
@ApiOperation(value = "删除分类")
@RequestMapping(value = "/{ids}", method = RequestMethod.DELETE)
public ResponseModel delete(@PathVariable("ids") String ids) {
planClassifyTreeService.delete(ids);
return CommonResponseUtil2.success();
return CommonResponseUtil2.success(planClassifyTreeService.delete(ids));
}
@ApiOperation(value = "查询分类树")
@RequestMapping(value = "/tree", method = RequestMethod.GET)
@RequestMapping(value = "/tree", method = RequestMethod.GET)
public ResponseModel getTree() {
Collection<PlanClassifyTreeVo> list = null;
try {
......
package com.yeejoin.amos.fas.business.dao.repository;
import com.yeejoin.amos.fas.business.vo.PlanClassifyTreeVo;
import com.yeejoin.amos.fas.dao.entity.PlanClassifyTree;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Set;
@Repository
public interface IPlanClassifyTreeDao extends BaseDao<PlanClassifyTree, Long> {
......@@ -16,4 +16,14 @@ public interface IPlanClassifyTreeDao extends BaseDao<PlanClassifyTree, Long> {
@Query(value = "select * from c_plan_classify_tree",nativeQuery = true)
List<PlanClassifyTree> getAll();
/**
* 查询当统计目录下特定名称的个数
* @param classifyName 名称
* @param parentId 父ID
* @return
*/
int countByClassifyNameAndParentId(String classifyName, Long parentId);
int deleteByIdIn(Set<Long> allIds);
}
......@@ -4,6 +4,7 @@ import com.yeejoin.amos.fas.dao.entity.PlanDetail;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
/**
......@@ -20,4 +21,5 @@ public interface IPlanDetailDao extends BaseDao<PlanDetail, Long> {
List<PlanDetail> getPlanDetailsByIdInAndIsDelete(List<Long> idList, Boolean isDelete);
boolean existsByClassifyIdInAndIsDelete(Collection<Long> classifyList, Boolean isDelete);
}
package com.yeejoin.amos.fas.business.service.impl;
import com.yeejoin.amos.fas.business.dao.repository.IPlanClassifyTreeDao;
import com.yeejoin.amos.fas.business.dao.repository.IPlanDetailDao;
import com.yeejoin.amos.fas.business.service.intfc.IPlanClassifyTreeService;
import com.yeejoin.amos.fas.business.vo.PlanClassifyTreeVo;
import com.yeejoin.amos.fas.dao.entity.PlanClassifyTree;
import com.yeejoin.amos.fas.exception.YeeException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -26,6 +28,8 @@ public class PlanClassifyTreeServiceImpl implements IPlanClassifyTreeService {
@Autowired
private IPlanClassifyTreeDao planClassifyTreeDao;
@Autowired
private IPlanDetailDao planDetailDao;
@Override
public PlanClassifyTree save(PlanClassifyTree model) {
......@@ -33,14 +37,21 @@ public class PlanClassifyTreeServiceImpl implements IPlanClassifyTreeService {
}
@Override
public void delete(String ids) {
public Boolean delete(String ids) {
List<Long> seqs = StringUtil.String2LongList(ids);
Set<Long> allIds = new HashSet<>(seqs);
for (Long seq : seqs) {
Optional<PlanClassifyTree> PlanClassifyTreeOpt = planClassifyTreeDao.findById(seq);
PlanClassifyTree planClassifyTree = planClassifyTreeDao.findById(seq).orElse(null);
//所有子分类
List<PlanClassifyTree> childGroupSequenceList = getChildSequenceList(PlanClassifyTreeOpt.get());
planClassifyTreeDao.deleteAll(childGroupSequenceList);
List<PlanClassifyTree> childGroupSequenceList = getChildSequenceList(planClassifyTree);
allIds.addAll(new HashSet(Bean.listToMap(childGroupSequenceList, "id", "id", PlanClassifyTree.class).keySet()));
}
// 查询分类下是否有预案
if (planDetailDao.existsByClassifyIdInAndIsDelete(allIds, false)) {
throw new YeeException("目录下存在预案");
}
planClassifyTreeDao.deleteByIdIn(allIds);
return true;
}
@Override
......@@ -84,7 +95,6 @@ public class PlanClassifyTreeServiceImpl implements IPlanClassifyTreeService {
return completeList;
}
/**
* 预案分类的子id
*
......@@ -102,7 +112,6 @@ public class PlanClassifyTreeServiceImpl implements IPlanClassifyTreeService {
return childList;
}
private void getAllChildList(PlanClassifyTree currentPlanClassifyTree, List<PlanClassifyTree> resList) {
if (null == currentPlanClassifyTree) {
return;
......@@ -131,4 +140,34 @@ public class PlanClassifyTreeServiceImpl implements IPlanClassifyTreeService {
}
return treeList;
}
@Override
public PlanClassifyTree create(PlanClassifyTree model) {
if (ValidationUtil.isEmpty(model.getClassifyName()) || ValidationUtil.isEmpty(model.getParentId())) {
throw new YeeException("参数有误");
}
if (classifyNameExist(model.getClassifyName(), model.getParentId())) {
throw new YeeException("名称重复");
}
model.setId(0);
return planClassifyTreeDao.save(model);
}
@Override
public PlanClassifyTree update(PlanClassifyTree model) {
if (ValidationUtil.isEmpty(model.getId()) || ValidationUtil.isEmpty(model.getClassifyName()) || ValidationUtil.isEmpty(model.getParentId())) {
throw new YeeException("参数有误");
}
if (!planClassifyTreeDao.existsById(model.getId())) {
throw new YeeException("原数据不存在");
}
if (classifyNameExist(model.getClassifyName(), model.getParentId())) {
throw new YeeException("名称重复");
}
return planClassifyTreeDao.save(model);
}
private boolean classifyNameExist(String classifyName, Long parentId) {
return 0 < planClassifyTreeDao.countByClassifyNameAndParentId(classifyName, parentId);
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ import com.yeejoin.amos.fas.business.vo.PlanClassifyTreeVo;
import com.yeejoin.amos.fas.dao.entity.PlanClassifyTree;
import java.util.Collection;
import java.util.List;
/**
* @author wjk
......@@ -15,7 +14,7 @@ public interface IPlanClassifyTreeService {
PlanClassifyTree save(PlanClassifyTree model);
void delete(String ids);
Boolean delete(String ids);
Collection<PlanClassifyTreeVo> getTree();
......@@ -25,4 +24,8 @@ public interface IPlanClassifyTreeService {
* @return
*/
Collection<PlanClassifyTreeVo> getAllChildIncludeMe(Long root);
PlanClassifyTree create(PlanClassifyTree model);
PlanClassifyTree update(PlanClassifyTree model);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment