|
|
@@ -123,6 +123,7 @@ public class ServiceProjectServiceImpl extends ServiceImpl<ServiceProjectMapper,
|
|
|
if (!CollectionUtils.isEmpty(itemList)) {
|
|
|
//判断新增或者修改操作
|
|
|
itemList.forEach(ls -> {
|
|
|
+ ls.setTaskStatus(10);
|
|
|
//修改
|
|
|
if (null != ls.getId()) {
|
|
|
if (ls.getProjectType() == 2) {
|
|
|
@@ -478,115 +479,140 @@ public class ServiceProjectServiceImpl extends ServiceImpl<ServiceProjectMapper,
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public int dispatch(ServiceProject serviceProject) {
|
|
|
List<ServiceProjectItem> itemList = serviceProject.getItemList();
|
|
|
AtomicInteger status = new AtomicInteger(1);
|
|
|
itemList.forEach(ls -> {
|
|
|
+ //修改任务明细单据状态
|
|
|
+ ServiceProjectItem up = new ServiceProjectItem();
|
|
|
+ up.setId(ls.getId());
|
|
|
+ up.setTaskStatus(20);
|
|
|
+ up.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ up.setUpdateTime(new Date());
|
|
|
+ up.setUpdateUserName(SecureUtil.getUser().getUserName());
|
|
|
+ serviceProjectItemMapper.updateById(up);
|
|
|
+
|
|
|
+ //派工生成任务处理
|
|
|
//判断次数 如果为空赋值为1
|
|
|
- if (ObjectUtils.isNotNull(ls.getFrequency())) {
|
|
|
- //判断次数 如果为空赋值为1
|
|
|
- if (ObjectUtils.isNull(ls.getSecond())) {
|
|
|
- ls.setSecond(1);
|
|
|
- }
|
|
|
+ if (ObjectUtils.isNull(ls.getSecond())) {
|
|
|
+ ls.setSecond(1);
|
|
|
+ }
|
|
|
+ //获取当前时间
|
|
|
+ Date date = new Date();
|
|
|
+ //服务费
|
|
|
+ BigDecimal serviceCharge = ls.getServiceCharge().divide(new BigDecimal(ls.getSecond()));
|
|
|
+ //合计金额
|
|
|
+ BigDecimal amount = ls.getAmount().divide(new BigDecimal(ls.getSecond()));
|
|
|
+ //成本
|
|
|
+ BigDecimal matMoney = ls.getMatMoney().divide(new BigDecimal(ls.getSecond()));
|
|
|
+ //提成
|
|
|
+ if (ObjectUtils.isNotNull(ls.getCommission())) {
|
|
|
+ ls.setCommission(ls.getAmount().multiply(ls.getCommission()).divide(new BigDecimal(ls.getSecond())));
|
|
|
+ } else {
|
|
|
+ ls.setCommission(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ //通过频率次数循环生成任务
|
|
|
+ for (int i = 0; i < ls.getSecond(); i++) {
|
|
|
+ //获取需求开始日期
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(ls.getBeginTime());
|
|
|
+
|
|
|
+ //获取提醒日期
|
|
|
+ Calendar reminderCalendar = Calendar.getInstance();
|
|
|
+ Date reminderDate;
|
|
|
+
|
|
|
+ //判断开始,提醒日期
|
|
|
switch (ls.getFrequency()) {
|
|
|
case "1"://年
|
|
|
- if(ObjectUtils.isNotNull(ls.getCommission())){
|
|
|
- ls.setCommission(ls.getAmount().multiply(ls.getCommission()).divide(new BigDecimal(ls.getSecond() * 12)));
|
|
|
- }else{
|
|
|
- ls.setCommission(new BigDecimal(0));
|
|
|
+ if (i > 0) {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i + 12);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i + 12);//设置月分
|
|
|
+ } else {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i);//设置月分
|
|
|
}
|
|
|
- this.insertProjectItem(ls, ls.getSecond() * 12, serviceProject.getId());
|
|
|
case "2"://半年
|
|
|
- if(ObjectUtils.isNotNull(ls.getCommission())){
|
|
|
- ls.setCommission(ls.getAmount().multiply(ls.getCommission()).divide(new BigDecimal(ls.getSecond() * 6)));
|
|
|
- }else{
|
|
|
- ls.setCommission(new BigDecimal(0));
|
|
|
+ if (i > 0) {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i + 6);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i + 6);//设置月分
|
|
|
+ } else {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i);//设置月分
|
|
|
}
|
|
|
- this.insertProjectItem(ls, ls.getSecond() * 6, serviceProject.getId());
|
|
|
case "3"://季度
|
|
|
- if(ObjectUtils.isNotNull(ls.getCommission())){
|
|
|
- ls.setCommission(ls.getAmount().multiply(ls.getCommission()).divide(new BigDecimal(ls.getSecond() * 3)));
|
|
|
- }else{
|
|
|
- ls.setCommission(new BigDecimal(0));
|
|
|
+ if (i > 0) {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i + 3);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i + 3);//设置月分
|
|
|
+ } else {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i);//设置月分
|
|
|
}
|
|
|
- this.insertProjectItem(ls, ls.getSecond() * 3, serviceProject.getId());
|
|
|
case "4"://月
|
|
|
- if(ObjectUtils.isNotNull(ls.getCommission())){
|
|
|
- ls.setCommission(ls.getAmount().multiply(ls.getCommission()).divide(new BigDecimal(ls.getSecond())));
|
|
|
- }else{
|
|
|
- ls.setCommission(new BigDecimal(0));
|
|
|
+ if (i > 0) {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i + 1);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i + 1);//设置月分
|
|
|
+ } else {
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i);//设置月分
|
|
|
}
|
|
|
- this.insertProjectItem(ls, ls.getSecond(), serviceProject.getId());
|
|
|
case "5"://次
|
|
|
- if(ObjectUtils.isNotNull(ls.getCommission())){
|
|
|
- ls.setCommission(ls.getAmount().multiply(ls.getCommission()).divide(new BigDecimal(ls.getSecond())));
|
|
|
- }else{
|
|
|
- ls.setCommission(new BigDecimal(0));
|
|
|
- }
|
|
|
- this.insertProjectItem(ls, ls.getSecond(), serviceProject.getId());
|
|
|
+ //开始日期
|
|
|
+ calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
+ //提醒日期
|
|
|
+ reminderCalendar.add(Calendar.MONTH, i);//设置月分
|
|
|
default:
|
|
|
status.set(0);
|
|
|
break;
|
|
|
}
|
|
|
- } else {
|
|
|
- this.insertProjectItem(ls, 1, serviceProject.getId());
|
|
|
- }
|
|
|
- });
|
|
|
- return status.get();
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 派工生成单条或多条任务
|
|
|
- * @param ls 任务集合
|
|
|
- * @param number 生成条数
|
|
|
- * @param projectId 父id
|
|
|
- */
|
|
|
- public void insertProjectItem(ServiceProjectItem ls, int number, Long projectId) {
|
|
|
- //获取当前时间
|
|
|
- Date date = new Date();
|
|
|
- //服务费每月需缴纳
|
|
|
- BigDecimal serviceCharge = ls.getServiceCharge().divide(new BigDecimal(number));
|
|
|
- //合计金额每月需缴纳
|
|
|
- BigDecimal amount = ls.getAmount().divide(new BigDecimal(number));
|
|
|
- //成本每月需缴纳
|
|
|
- BigDecimal matMoney = ls.getMatMoney().divide(new BigDecimal(number));
|
|
|
- for (int i = 0; i < number; i++) {
|
|
|
- //获取需求开始日期
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(ls.getBeginTime());
|
|
|
- calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
|
|
|
- Date date1 = calendar.getTime();
|
|
|
-
|
|
|
- //获取提醒日期
|
|
|
- Calendar reminderCalendar = Calendar.getInstance();
|
|
|
- Date reminderDate;
|
|
|
- //判断提醒日期是否为空 空默认每月一日为提醒日期 否则 每月提醒日期为当前日
|
|
|
- if (ObjectUtils.isNotNull(ls.getReminderDay())) {
|
|
|
- reminderCalendar.setTime(ls.getReminderDay());
|
|
|
- calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
- reminderDate = calendar.getTime();
|
|
|
- } else {
|
|
|
- calendar.setTime(date);
|
|
|
calendar.add(Calendar.MONTH, i);//设置月分
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
|
|
|
- reminderDate = calendar.getTime();
|
|
|
- }
|
|
|
+ Date date1 = calendar.getTime();
|
|
|
+
|
|
|
+ //判断提醒日期是否为空 空默认每月一日为提醒日期 否则 每月提醒日期为当前日
|
|
|
+ if (ObjectUtils.isNotNull(ls.getReminderDay())) {
|
|
|
+ reminderCalendar.setTime(ls.getReminderDay());
|
|
|
+ reminderDate = reminderCalendar.getTime();
|
|
|
+ } else {
|
|
|
+ reminderCalendar.setTime(date);
|
|
|
+ reminderCalendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
|
|
|
+ reminderDate = reminderCalendar.getTime();
|
|
|
+ }
|
|
|
|
|
|
- ls.setServiceCharge(serviceCharge);
|
|
|
- ls.setAmount(amount);
|
|
|
- ls.setMatMoney(matMoney);
|
|
|
- ls.setBeginTime(date1);
|
|
|
- ls.setReminderDay(reminderDate);
|
|
|
- ls.setTenantId(AuthUtil.getTenantId());
|
|
|
- ls.setPId(projectId);
|
|
|
- ls.setCreateTime(new Date());
|
|
|
- ls.setCreateUser(SecureUtil.getUserId());
|
|
|
- ls.setCreateUserName(SecureUtil.getUser().getUserName());
|
|
|
- ls.setTaskStatus(10);
|
|
|
- ls.setBranch("Y");
|
|
|
- serviceProjectItemMapper.insert(ls);
|
|
|
- }
|
|
|
+ ls.setServiceCharge(serviceCharge);
|
|
|
+ ls.setAmount(amount);
|
|
|
+ ls.setMatMoney(matMoney);
|
|
|
+ ls.setBeginTime(date1);
|
|
|
+ ls.setReminderDay(reminderDate);
|
|
|
+ ls.setTenantId(AuthUtil.getTenantId());
|
|
|
+ ls.setPId(ls.getPId());
|
|
|
+ ls.setCreateTime(new Date());
|
|
|
+ ls.setCreateUser(SecureUtil.getUserId());
|
|
|
+ ls.setCreateUserName(SecureUtil.getUser().getUserName());
|
|
|
+ ls.setStatus(4);
|
|
|
+ ls.setBranch("Y");
|
|
|
+ ls.setId(null);
|
|
|
+ serviceProjectItemMapper.insert(ls);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return status.get();
|
|
|
}
|
|
|
|
|
|
public void checkMoney(Long serviceId, List<ServiceProjectItem> items) {
|