|
@ -6,17 +6,17 @@ import com.qs.serve.common.model.dto.PageVo; |
|
|
import com.qs.serve.common.model.dto.R; |
|
|
import com.qs.serve.common.model.dto.R; |
|
|
import com.qs.serve.common.model.enums.BizType; |
|
|
import com.qs.serve.common.model.enums.BizType; |
|
|
import com.qs.serve.common.model.enums.SystemModule; |
|
|
import com.qs.serve.common.model.enums.SystemModule; |
|
|
|
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
import com.qs.serve.common.util.TreeUtil; |
|
|
import com.qs.serve.common.util.TreeUtil; |
|
|
import com.qs.serve.modules.bms.entity.BmsCostCenter; |
|
|
import com.qs.serve.modules.bms.entity.*; |
|
|
import com.qs.serve.modules.bms.entity.BmsSubjectForm; |
|
|
|
|
|
import com.qs.serve.modules.bms.entity.bo.BmsCostCenterBo; |
|
|
import com.qs.serve.modules.bms.entity.bo.BmsCostCenterBo; |
|
|
import com.qs.serve.modules.bms.entity.vo.BmsRegionTreeVo; |
|
|
import com.qs.serve.modules.bms.entity.vo.BmsRegionTreeVo; |
|
|
import com.qs.serve.modules.bms.entity.vo.BmsSubjectTreeVo; |
|
|
import com.qs.serve.modules.bms.entity.vo.BmsSubjectTreeVo; |
|
|
import com.qs.serve.modules.bms.mapper.BmsSubjectMapper; |
|
|
import com.qs.serve.modules.bms.mapper.BmsSubjectMapper; |
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
import com.qs.serve.modules.bms.service.BmsSubjectFormService; |
|
|
import com.qs.serve.modules.bms.service.*; |
|
|
import com.qs.serve.modules.tbs.entity.TbsActivitySubject; |
|
|
import com.qs.serve.modules.tbs.entity.TbsActivitySubject; |
|
|
import com.qs.serve.modules.tbs.service.TbsActivitySubjectService; |
|
|
import com.qs.serve.modules.tbs.service.TbsActivitySubjectService; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
@ -25,10 +25,8 @@ import org.springframework.security.access.prepost.PreAuthorize; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
import javax.validation.Valid; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -47,6 +45,9 @@ public class BmsSubjectController { |
|
|
private BmsSubjectMapper bmsSubjectMapper; |
|
|
private BmsSubjectMapper bmsSubjectMapper; |
|
|
private TbsActivitySubjectService activitySubjectService; |
|
|
private TbsActivitySubjectService activitySubjectService; |
|
|
private BmsSubjectFormService bmsSubjectFormService; |
|
|
private BmsSubjectFormService bmsSubjectFormService; |
|
|
|
|
|
private BmsSubjectRegionService bmsSubjectRegionService; |
|
|
|
|
|
private BmsRegionService bmsRegionService; |
|
|
|
|
|
private BmsRegion2Service bmsRegion2Service; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 树查询 |
|
|
* 树查询 |
|
@ -88,6 +89,14 @@ public class BmsSubjectController { |
|
|
BmsSubjectForm subjectForm = bmsSubjectFormService.getById(bmsSubject.getFormId()); |
|
|
BmsSubjectForm subjectForm = bmsSubjectFormService.getById(bmsSubject.getFormId()); |
|
|
bmsSubject.setSubjectFormInfo(subjectForm); |
|
|
bmsSubject.setSubjectFormInfo(subjectForm); |
|
|
} |
|
|
} |
|
|
|
|
|
if(bmsSubject.getSaleRegionFlag().equals(1)){ |
|
|
|
|
|
List<BmsSubjectRegion> subjectRegionList = bmsSubjectRegionService.listBySubjectId(bmsSubject.getId(),0); |
|
|
|
|
|
bmsSubject.setSaleRegionInfos(subjectRegionList); |
|
|
|
|
|
} |
|
|
|
|
|
if(bmsSubject.getBizRegionFlag().equals(1)){ |
|
|
|
|
|
List<BmsSubjectRegion> subjectRegionList = bmsSubjectRegionService.listBySubjectId(bmsSubject.getId(),1); |
|
|
|
|
|
bmsSubject.setBizRegionInfos(subjectRegionList); |
|
|
|
|
|
} |
|
|
return R.ok(bmsSubject); |
|
|
return R.ok(bmsSubject); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -100,6 +109,9 @@ public class BmsSubjectController { |
|
|
@SysLog(module = SystemModule.BASE, title = "科目", biz = BizType.UPDATE) |
|
|
@SysLog(module = SystemModule.BASE, title = "科目", biz = BizType.UPDATE) |
|
|
@PreAuthorize("hasRole('bms:subject:update')") |
|
|
@PreAuthorize("hasRole('bms:subject:update')") |
|
|
public R<?> updateById(@RequestBody @Valid BmsSubject param){ |
|
|
public R<?> updateById(@RequestBody @Valid BmsSubject param){ |
|
|
|
|
|
if(param.getId()==null){ |
|
|
|
|
|
return R.error("资源不存在或被移除"); |
|
|
|
|
|
} |
|
|
commonEdit(param); |
|
|
commonEdit(param); |
|
|
return R.ok(); |
|
|
return R.ok(); |
|
|
} |
|
|
} |
|
@ -113,6 +125,7 @@ public class BmsSubjectController { |
|
|
@SysLog(module = SystemModule.BASE, title = "科目", biz = BizType.INSERT) |
|
|
@SysLog(module = SystemModule.BASE, title = "科目", biz = BizType.INSERT) |
|
|
@PreAuthorize("hasRole('bms:subject:insert')") |
|
|
@PreAuthorize("hasRole('bms:subject:insert')") |
|
|
public R<?> save(@RequestBody @Valid BmsSubject param){ |
|
|
public R<?> save(@RequestBody @Valid BmsSubject param){ |
|
|
|
|
|
param.setId(null); |
|
|
commonEdit(param); |
|
|
commonEdit(param); |
|
|
return R.ok(); |
|
|
return R.ok(); |
|
|
} |
|
|
} |
|
@ -120,25 +133,55 @@ public class BmsSubjectController { |
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void commonEdit(BmsSubject subject){ |
|
|
public void commonEdit(BmsSubject subject){ |
|
|
if(subject.getId()==null){ |
|
|
|
|
|
bmsSubjectService.save(subject); |
|
|
|
|
|
} |
|
|
|
|
|
if(subject.getPid()==null||subject.getPid().equals(0L)){ |
|
|
if(subject.getPid()==null||subject.getPid().equals(0L)){ |
|
|
subject.setPid(0L); |
|
|
subject.setPid(0L); |
|
|
subject.setLevel(1); |
|
|
subject.setLevel(1); |
|
|
subject.setPathNames(subject.getSubjectName()); |
|
|
subject.setPathNames(subject.getSubjectName()); |
|
|
bmsSubjectService.updateById(subject); |
|
|
|
|
|
}else { |
|
|
}else { |
|
|
BmsSubject parent = bmsSubjectService.getById(subject.getPid()); |
|
|
BmsSubject parent = bmsSubjectService.getById(subject.getPid()); |
|
|
//todo 判断父级节点是否存有已存数据
|
|
|
|
|
|
BmsSubject ori = bmsSubjectService.getById(subject.getId()); |
|
|
|
|
|
subject.setLevel(parent.getLevel()+1); |
|
|
subject.setLevel(parent.getLevel()+1); |
|
|
subject.setPathNames(parent.getPathNames()+"_"+subject.getSubjectName()); |
|
|
subject.setPathNames(parent.getPathNames()+"_"+subject.getSubjectName()); |
|
|
|
|
|
} |
|
|
|
|
|
if(subject.getId()==null){ |
|
|
|
|
|
bmsSubjectService.save(subject); |
|
|
|
|
|
}else { |
|
|
|
|
|
//异常历史的适用区域
|
|
|
|
|
|
bmsSubjectRegionService.removeBySubjectId(subject.getId(),0); |
|
|
|
|
|
bmsSubjectRegionService.removeBySubjectId(subject.getId(),1); |
|
|
|
|
|
BmsSubject ori = bmsSubjectService.getById(subject.getId()); |
|
|
bmsSubjectService.updateById(subject); |
|
|
bmsSubjectService.updateById(subject); |
|
|
if(!subject.getSubjectName().equals(ori.getSubjectName())) { |
|
|
if(!subject.getSubjectName().equals(ori.getSubjectName())) { |
|
|
bmsSubjectService.updatePathNameByParent(subject); |
|
|
bmsSubjectService.updatePathNameByParent(subject); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if(subject.getSaleRegionFlag().equals(1)){ |
|
|
|
|
|
List<BmsRegion> saleRegionList = bmsRegionService.listByIds(subject.getSaleRegionIds()); |
|
|
|
|
|
List<BmsSubjectRegion> subjectRegionList = saleRegionList.stream().map(region->{ |
|
|
|
|
|
BmsSubjectRegion subjectRegion = new BmsSubjectRegion(); |
|
|
|
|
|
subjectRegion.setSubjectId(subject.getId()); |
|
|
|
|
|
subjectRegion.setRegionId(region.getId()); |
|
|
|
|
|
subjectRegion.setRegionName(region.getName()); |
|
|
|
|
|
subjectRegion.setType(0); |
|
|
|
|
|
return subjectRegion; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(subjectRegionList)){ |
|
|
|
|
|
bmsSubjectRegionService.saveBatch(subjectRegionList); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(subject.getBizRegionFlag().equals(1)){ |
|
|
|
|
|
List<BmsRegion2> bizRegionList = bmsRegion2Service.listByIds(subject.getBizRegionIds()); |
|
|
|
|
|
List<BmsSubjectRegion> subjectRegionList = bizRegionList.stream().map(region->{ |
|
|
|
|
|
BmsSubjectRegion subjectRegion = new BmsSubjectRegion(); |
|
|
|
|
|
subjectRegion.setSubjectId(subject.getId()); |
|
|
|
|
|
subjectRegion.setRegionId(region.getId()); |
|
|
|
|
|
subjectRegion.setRegionName(region.getName()); |
|
|
|
|
|
subjectRegion.setType(1); |
|
|
|
|
|
return subjectRegion; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(subjectRegionList)){ |
|
|
|
|
|
bmsSubjectRegionService.saveBatch(subjectRegionList); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if(subject.getFormId()==null){ |
|
|
if(subject.getFormId()==null){ |
|
|
bmsSubjectMapper.removeFormId(subject.getId()); |
|
|
bmsSubjectMapper.removeFormId(subject.getId()); |
|
|
} |
|
|
} |
|
|