Commit f4c10adf by dengshichuan

Merge branch 'dsc' into 'develop'

Dsc

See merge request 8timerv2/8timerapiv200!164
parents 45d89e3e 1fd371cf
......@@ -87,7 +87,7 @@ public class CrmBusinessGroup extends Model<CrmBusinessGroup> {
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "组管理员id")
private Integer[] managerIds;
private List<Integer> managerIds;
@Transient
@TableField(exist = false)
......@@ -97,7 +97,7 @@ public class CrmBusinessGroup extends Model<CrmBusinessGroup> {
@Transient
@TableField(exist = false)
@ApiModelProperty(value = "组成员id")
private Integer[] memberIds;
private List<Integer> memberIds;
@Transient
@TableField(exist = false)
......
......@@ -112,11 +112,14 @@ public class CrmController {
@PostMapping("addBusinessGroup")
@Transactional
@ApiOperation(value = "新增业务组", httpMethod = "POST", notes = "接口发布说明")
@ApiOperation(value = "新增/编辑业务组", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> addBusinessGroup(@CurrentUser UserBean userBean,
@RequestBody CrmBusinessGroup crmBusinessGroup) {
Integer orgCode = getOrgCode(userBean);
Integer empNum = getEmpNum(userBean);
Integer gid = crmBusinessGroup.getId();
crmBusinessGroup.setModifyUser(empNum); // 修改人
if (gid == null) {
CrmBusinessGroup crmBusinessGroupOld = CrmBusinessGroup.builder().build()
.selectOne(new QueryWrapper<CrmBusinessGroup>().lambda().eq(CrmBusinessGroup::getOrgCode, orgCode)
.select(CrmBusinessGroup::getSort).last("limit 1").orderByDesc(CrmBusinessGroup::getId));
......@@ -124,30 +127,61 @@ public class CrmController {
crmBusinessGroup.setSort(1);
else
crmBusinessGroup.setSort(crmBusinessGroupOld.getSort() + 1);// 排序
// crmBusinessGroup.setManagerName(getEmpName(orgCode, empNum)); // 设置管理员姓名
crmBusinessGroup.setCreateUser(empNum); // 创建人
crmBusinessGroup.setModifyUser(empNum); // 修改人
crmBusinessGroup.setOrgCode(orgCode);
// crmBusinessGroup.setMember(member); // ,字符串拼接
boolean result = crmBusinessGroup.insert();
if (!result)
return ResultUtil.success("新增失败");
Integer gid = crmBusinessGroup.getId();
Integer[] memberIds = crmBusinessGroup.getMemberIds();
gid = crmBusinessGroup.getId();
List<Integer> memberIds = crmBusinessGroup.getMemberIds();
for (Integer empId : memberIds) {
CrmBusinessGroupMember.builder().gid(gid).empNum(empId).orgCode(orgCode).type(0).build().insert();
insertMembers(gid, empId, orgCode, 0);
}
Integer[] managerIds = crmBusinessGroup.getManagerIds();
List<Integer> managerIds = crmBusinessGroup.getManagerIds();
for (Integer empId : managerIds) {
CrmBusinessGroupMember.builder().gid(gid).empNum(empId).orgCode(orgCode).type(1).build().insert();
insertMembers(gid, empId, orgCode, 1);
}
CrmSeaRule crmSeaRule = crmBusinessGroup.getCrmSeaRules();
crmSeaRule.setGid(gid);
crmSeaRule.insert();
} else {
List<Integer> memberIds = crmBusinessGroup.getMemberIds();
List<Integer> managerIds = crmBusinessGroup.getManagerIds();
// 更新组成员
updateMembers(orgCode, gid, memberIds, 0);
updateMembers(orgCode, gid, managerIds, 1);
// 更新公海规则
crmBusinessGroup.getCrmSeaRules().update(new LambdaQueryWrapper<CrmSeaRule>().eq(CrmSeaRule::getGid, gid));
}
return ResultUtil.success("新增业务组成功");
}
private void insertMembers(Integer gid, Integer empId, Integer orgCode, Integer type) {
CrmBusinessGroupMember.builder().gid(gid).empNum(empId).orgCode(orgCode).type(type).build().insert();
}
private void updateMembers(Integer orgCode, Integer gid, List<Integer> memberIds, Integer type) {
List<CrmBusinessGroupMember> oldMembers = CrmBusinessGroupMember.builder().build()
.selectList(new LambdaQueryWrapper<CrmBusinessGroupMember>().eq(CrmBusinessGroupMember::getGid, gid)
.eq(CrmBusinessGroupMember::getType, type).select(CrmBusinessGroupMember::getEmpNum));
// 旧组成员idlist
List<Integer> oldIdsList = oldMembers.stream().map(CrmBusinessGroupMember::getEmpNum)
.collect(Collectors.toList());
List<Integer> deList = CheckUtil.reduce(oldIdsList, memberIds); // 删
for (Integer integer : deList) {
CrmBusinessGroupMember.builder().build()
.delete(new LambdaQueryWrapper<CrmBusinessGroupMember>()
.eq(CrmBusinessGroupMember::getEmpNum, integer).eq(CrmBusinessGroupMember::getGid, gid)
.eq(CrmBusinessGroupMember::getOrgCode, orgCode).eq(CrmBusinessGroupMember::getType, type));
}
List<Integer> addList = CheckUtil.reduce(memberIds, oldIdsList); // 增
for (Integer integer : addList) {
CrmBusinessGroupMember.builder().empNum(integer).gid(gid).orgCode(orgCode).type(type).build().insert();
}
}
@GetMapping("getBusinessGroup")
@ApiOperation(value = "获取业务组列表", httpMethod = "GET", notes = "接口发布说明")
public Result<Object> getBusinessGroup(@CurrentUser UserBean userBean) {
......@@ -169,6 +203,7 @@ public class CrmController {
String name = getEmpName(getOrgCode(userBean), empNum);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", name);
map.put("empNum", empNum);
managers.add(map);
}
crmBusinessGroup.setManagers(managers);
......@@ -179,6 +214,7 @@ public class CrmController {
String name = getEmpName(getOrgCode(userBean), empNum);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", name);
map.put("empNum", empNum);
members.add(map);
}
crmBusinessGroup.setMembers(members);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment