|
|
|
@ -18,12 +18,16 @@ import cn.iocoder.yudao.module.farm.controller.admin.workHour.dto.WorkUserMsgDTO
|
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.WorkHourBaseVO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.convert.discuss.DiscussConvert; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.cropRecord.CropRecordDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.cropRecord.CropRecordMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.discuss.DiscussMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.enums.TaskStatus; |
|
|
|
|
import cn.iocoder.yudao.module.farm.service.area.AreaService; |
|
|
|
@ -69,6 +73,10 @@ public class DiscussServiceImpl implements DiscussService {
|
|
|
|
|
private AreaMapper areaMapper; |
|
|
|
|
@Resource |
|
|
|
|
private TaskMapper taskMapper; |
|
|
|
|
@Resource |
|
|
|
|
private CropRecordMapper cropRecordMapper; |
|
|
|
|
@Resource |
|
|
|
|
private TaskCateMapper taskCateMapper; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Long createDiscuss(DiscussCreateReqVO createReqVO) { |
|
|
|
@ -78,38 +86,11 @@ public class DiscussServiceImpl implements DiscussService {
|
|
|
|
|
DiscussDO discuss = DiscussConvert.INSTANCE.convert(createReqVO); |
|
|
|
|
discussMapper.insert(discuss); |
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(createReqVO.getWorkHourList())){ |
|
|
|
|
List<Long> workUserIdList = createReqVO.getWorkHourList().stream().map(WorkHourBaseVO::getUserId).collect(Collectors.toList()); |
|
|
|
|
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList)); |
|
|
|
|
//添加工时记录
|
|
|
|
|
addWorkHourRecord(createReqVO, discuss); |
|
|
|
|
|
|
|
|
|
//传了工时
|
|
|
|
|
List<WorkHourDO> workSaveList = new ArrayList<>(); |
|
|
|
|
for (WorkHourBaseVO work : createReqVO.getWorkHourList()) { |
|
|
|
|
WorkHourDO workHourDO = WorkHourDO.builder() |
|
|
|
|
.userId(work.getUserId()) |
|
|
|
|
.discussId(discuss.getId()) |
|
|
|
|
.projectId(work.getProjectId()) |
|
|
|
|
.taskId(work.getTaskId()) |
|
|
|
|
.hour(work.getHour()) |
|
|
|
|
.build(); |
|
|
|
|
workSaveList.add(workHourDO); |
|
|
|
|
|
|
|
|
|
userList.forEach(user ->{ |
|
|
|
|
if (work.getUserId().equals(user.getId())){ |
|
|
|
|
user.setWorkHour(user.getWorkHour() + work.getHour()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//插入工时记录
|
|
|
|
|
workHourMapper.insertBatch(workSaveList); |
|
|
|
|
//更新员工工时合计
|
|
|
|
|
//todo service有问题
|
|
|
|
|
// cpUserService.updateBatchById(userList);
|
|
|
|
|
userList.stream().forEach(item ->{ |
|
|
|
|
cpUserMapper.updateById(item); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//添加作物入库记录
|
|
|
|
|
addCropRecord(createReqVO); |
|
|
|
|
|
|
|
|
|
// 返回
|
|
|
|
|
return discuss.getId(); |
|
|
|
@ -244,4 +225,62 @@ public class DiscussServiceImpl implements DiscussService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加工时记录 |
|
|
|
|
*/ |
|
|
|
|
public void addWorkHourRecord(DiscussCreateReqVO createReqVO, DiscussDO discuss){ |
|
|
|
|
if (ObjectUtil.isNotEmpty(createReqVO.getWorkHourList())){ |
|
|
|
|
List<Long> workUserIdList = createReqVO.getWorkHourList().stream().map(WorkHourBaseVO::getUserId).collect(Collectors.toList()); |
|
|
|
|
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, workUserIdList)); |
|
|
|
|
//传了工时
|
|
|
|
|
List<WorkHourDO> workSaveList = new ArrayList<>(); |
|
|
|
|
for (WorkHourBaseVO work : createReqVO.getWorkHourList()) { |
|
|
|
|
WorkHourDO workHourDO = WorkHourDO.builder() |
|
|
|
|
.userId(work.getUserId()) |
|
|
|
|
.discussId(discuss.getId()) |
|
|
|
|
.projectId(work.getProjectId()) |
|
|
|
|
.taskId(work.getTaskId()) |
|
|
|
|
.hour(work.getHour()) |
|
|
|
|
.build(); |
|
|
|
|
workSaveList.add(workHourDO); |
|
|
|
|
|
|
|
|
|
userList.forEach(user ->{ |
|
|
|
|
if (work.getUserId().equals(user.getId())){ |
|
|
|
|
user.setWorkHour(user.getWorkHour() + work.getHour()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//插入工时记录
|
|
|
|
|
workHourMapper.insertBatch(workSaveList); |
|
|
|
|
//更新员工工时合计
|
|
|
|
|
userList.stream().forEach(item ->{ |
|
|
|
|
cpUserMapper.updateById(item); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加农作物收入记录 |
|
|
|
|
*/ |
|
|
|
|
public void addCropRecord(DiscussCreateReqVO reqVO){ |
|
|
|
|
TaskDO taskDO = taskMapper.selectById(reqVO.getTaskId()); |
|
|
|
|
TaskCateDO cateDO = taskCateMapper.selectById(taskDO.getTaskCateName()); |
|
|
|
|
//如果任务内容 是要同步的
|
|
|
|
|
if (cateDO.getSynchronizeErp()){ |
|
|
|
|
Optional<CropRecordDO> max = cropRecordMapper.selectList(Wrappers.<CropRecordDO>lambdaQuery().eq(CropRecordDO::getCropId, taskDO.getCropId())) |
|
|
|
|
.stream().max(Comparator.comparing(CropRecordDO::getId)); |
|
|
|
|
Integer afterStock = max.isPresent() ? max.get().getAfterStock() : 0; |
|
|
|
|
CropRecordDO cropRecordDO = CropRecordDO.builder() |
|
|
|
|
.cropId(taskDO.getCropId()) |
|
|
|
|
.type(true) |
|
|
|
|
.stock(reqVO.getCropNum().intValue()) |
|
|
|
|
.afterStock(reqVO.getCropNum().intValue() + afterStock) |
|
|
|
|
.build(); |
|
|
|
|
cropRecordMapper.insert(cropRecordDO); |
|
|
|
|
|
|
|
|
|
//todo 调用ERP出入库接口
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|