保存组接口增加对组管理员表lz_staff_role数据的插入

This commit is contained in:
wulin 2020-10-30 09:54:58 +08:00
parent 75e1c2ea2b
commit e5b21bde35
5 changed files with 55 additions and 10 deletions

View File

@ -42,4 +42,6 @@ public interface StaffRoleMapper extends BaseMapper<StaffRole> {
List<StaffRole> selectByCondition(@Param("page") IPage page, @Param("params") Map<String, Object> params);
List<StaffRole> selectByGroupId(@Param("id") Long id);
List<StaffRole> selectStaffRolesByStaffId(@Param("list") List<Long> mIds);
}

View File

@ -49,4 +49,6 @@ public interface StaffRoleService extends IService<StaffRole> {
List<SysMenuEntity> selectMenuList();
List<StaffRole> selectByGroupId(Long id);
List<StaffRole> selectStaffRolesByStaffId(List<Long> mIds);
}

View File

@ -270,4 +270,9 @@ public class StaffRoleServiceImpl extends ServiceImpl<StaffRoleMapper, StaffRole
}
}
@Override
public List<StaffRole> selectStaffRolesByStaffId(List<Long> mIds){
return staffRoleMapper.selectStaffRolesByStaffId(mIds);
}
}

View File

@ -11,21 +11,16 @@ import com.lz.modules.app.service.StaffService;
import com.lz.modules.flow.entity.EvaluationGroup;
import com.lz.modules.flow.entity.FlowManager;
import com.lz.modules.flow.entity.ResultModel;
import com.lz.modules.flow.entity.StaffRole;
import com.lz.modules.flow.model.EvaluationGroupDto;
import com.lz.modules.flow.req.EvaluationGroupReq;
import com.lz.modules.flow.service.EvaluationGroupService;
import com.lz.modules.flow.service.FlowManagerService;
import com.lz.modules.flow.service.ResultModelService;
import com.lz.modules.flow.service.StaffRoleDepartmentService;
import com.lz.modules.flow.service.*;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -49,6 +44,9 @@ public class EvaluationGroupController {
@Autowired
private StaffRoleDepartmentService staffRoleDepartmentService;
@Autowired
private StaffRoleService staffRoleService;
@ -133,8 +131,8 @@ public class EvaluationGroupController {
@ApiOperation("保存考评组")
@ApiResponses({@ApiResponse(code = 200, message = "成功", response = EvaluationGroup.class)})
public R save(@RequestBody @ApiParam EvaluationGroup evaluationGroup) {
EvaluationGroup evaluationGroup1 = evaluationGroupService.selectEvaluationGroupByName(evaluationGroup.getName());
if(evaluationGroup.getId() != null && evaluationGroup.getId().intValue() > 0){
EvaluationGroup evaluationGroup1 = evaluationGroupService.selectEvaluationGroupByName(evaluationGroup.getName());
if(evaluationGroup1 == null || evaluationGroup1.getId().equals(evaluationGroup.getId())){
evaluationGroupService.updateEvaluationGroupById(evaluationGroup);
}else {
@ -142,13 +140,43 @@ public class EvaluationGroupController {
}
}else{
EvaluationGroup evaluationGroup1 = evaluationGroupService.selectEvaluationGroupByName(evaluationGroup.getName());
if(evaluationGroup1 != null){
return R.error("已经存在相同名称考核组");
}
evaluationGroupService.insertEvaluationGroup(evaluationGroup);
}
//更新组管理员信息
if(evaluationGroup.getManagerIds() != null && evaluationGroup.getManagerIds().length() > 0){
List<Long> mIds = Arrays.stream(evaluationGroup.getManagerIds().split(",")).map(new Function<String, Long>() {
@Override
public Long apply(String s) {
return Long.parseLong(s);
}
}).collect(Collectors.toList());
List<StaffRole> staffRoles = staffRoleService.selectByGroupId(evaluationGroup.getId());
if(staffRoles.size() > 0){
Map<Long, StaffRole> staffRoleMap =
staffRoles.stream().collect(Collectors.toMap(StaffRole::getStaffId, Function.identity(), (e, repace) -> e));
for(int i = 0; i < mIds.size();){
Long l = mIds.get(i);
if(staffRoleMap.containsKey(l)){
mIds.remove(l);
}
}
}
if(mIds.size() > 0){
staffRoles = new ArrayList<>();
for (Long id:mIds
) {
StaffRole staffRole = new StaffRole();
staffRole.setStaffId(id);
staffRole.setEvaluationGroupId(evaluationGroup.getId());
staffRoles.add(staffRole);
}
staffRoleService.saveBatch(staffRoles);
}
}
return R.ok().put("data", evaluationGroup);
}

View File

@ -115,6 +115,14 @@
select * from lz_staff_role where is_delete = 0 and evaluation_group_id = #{id}
</select>
<select id="selectStaffRolesByStaffId" resultType="com.lz.modules.flow.entity.StaffRole">
select * from lz_staff_role where is_delete = 0 and staff_id in (
<foreach collection="list" item="item" separator=",">
#{item}
</foreach>
)
</select>
</mapper>