|
|
@ -6,8 +6,14 @@ import com.qs.serve.common.model.dto.PageVo; |
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.model.enums.BizType; |
|
|
|
import com.qs.serve.common.model.enums.SystemModule; |
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsBudget; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsScheduleItem; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetService; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsScheduleItemService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
@ -20,6 +26,7 @@ import com.qs.serve.modules.tbs.service.TbsScheduleService; |
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 预算 考核期 |
|
|
@ -33,7 +40,8 @@ import java.util.List; |
|
|
|
public class TbsScheduleController { |
|
|
|
|
|
|
|
private TbsScheduleService tbsScheduleService; |
|
|
|
|
|
|
|
private TbsScheduleItemService tbsScheduleItemService; |
|
|
|
private TbsBudgetService tbsBudgetService; |
|
|
|
/** |
|
|
|
* 列表 |
|
|
|
* @param param |
|
|
@ -71,8 +79,9 @@ public class TbsScheduleController { |
|
|
|
@GetMapping("/getById/{id}") |
|
|
|
@SysLog(module = SystemModule.Budget, title = "考核期", biz = BizType.QUERY) |
|
|
|
@PreAuthorize("hasRole('tbs:schedule:query')") |
|
|
|
public R<TbsSchedule> getById(@PathVariable("id") String id){ |
|
|
|
public R<TbsSchedule> getById(@PathVariable("id") Long id){ |
|
|
|
TbsSchedule tbsSchedule = tbsScheduleService.getById(id); |
|
|
|
tbsSchedule.setScheduleItemlist(tbsScheduleItemService.listByScheduleId(id)); |
|
|
|
return R.ok(tbsSchedule); |
|
|
|
} |
|
|
|
|
|
|
@ -86,9 +95,16 @@ public class TbsScheduleController { |
|
|
|
@PostMapping("/updateById") |
|
|
|
@SysLog(module = SystemModule.Budget, title = "考核期", biz = BizType.UPDATE) |
|
|
|
@PreAuthorize("hasRole('tbs:schedule:update')") |
|
|
|
public R<?> updateById(@RequestBody @Valid TbsScheduleBo param){ |
|
|
|
TbsSchedule entity = CopierUtil.copy(param,new TbsSchedule()); |
|
|
|
public R<?> updateById(@RequestBody @Valid TbsSchedule entity){ |
|
|
|
// TbsSchedule entity = CopierUtil.copy(param,new TbsSchedule());
|
|
|
|
boolean result = tbsScheduleService.updateById(entity); |
|
|
|
List<TbsScheduleItem> scheduleItems = tbsScheduleItemService.listByScheduleId(entity.getId()); |
|
|
|
tbsScheduleItemService.removeBatchByIds(scheduleItems); |
|
|
|
List<TbsScheduleItem> items = entity.getScheduleItemlist().stream().map(a->{ |
|
|
|
a.setScheduleId(entity.getId()); |
|
|
|
return a; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
tbsScheduleItemService.saveBatch(items); |
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
@ -103,6 +119,17 @@ public class TbsScheduleController { |
|
|
|
public R<?> save(@RequestBody @Valid TbsSchedule param){ |
|
|
|
TbsSchedule entity = CopierUtil.copy(param,new TbsSchedule()); |
|
|
|
boolean result = tbsScheduleService.save(entity); |
|
|
|
if(!result){ |
|
|
|
Assert.throwEx("保存失败!"); |
|
|
|
} |
|
|
|
for(TbsScheduleItem item:entity.getScheduleItemlist()){ |
|
|
|
if(item.getStartDate().isAfter(item.getEndDate())){ |
|
|
|
Assert.throwEx("开始时间不能大于结束时间"); |
|
|
|
} |
|
|
|
item.setScheduleId(entity.getId()); |
|
|
|
} |
|
|
|
tbsScheduleItemService.saveBatch(entity.getScheduleItemlist()); |
|
|
|
|
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
@ -115,6 +142,11 @@ public class TbsScheduleController { |
|
|
|
@SysLog(module = SystemModule.Budget, title = "考核期", biz = BizType.DELETE) |
|
|
|
@PreAuthorize("hasRole('tbs:schedule:delete')") |
|
|
|
public R<?> deleteById(@PathVariable("id") Long id){ |
|
|
|
LambdaQueryWrapper<TbsBudget> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudget::getScheduleId,id); |
|
|
|
if(tbsBudgetService.count(lqw)>0){ |
|
|
|
Assert.throwEx("预算中已使用该周期模板,不能删除"); |
|
|
|
} |
|
|
|
boolean result = tbsScheduleService.removeById(id); |
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|