Commit 6c3be6b2 by 邓实川 Committed by chenzg

新增/编辑业务组优化

parent f9a477e5
...@@ -87,7 +87,7 @@ public class CrmBusinessGroup extends Model<CrmBusinessGroup> { ...@@ -87,7 +87,7 @@ public class CrmBusinessGroup extends Model<CrmBusinessGroup> {
@Transient @Transient
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "组管理员id") @ApiModelProperty(value = "组管理员id")
private Integer[] managerIds; private List<Integer> managerIds;
@Transient @Transient
@TableField(exist = false) @TableField(exist = false)
...@@ -97,7 +97,7 @@ public class CrmBusinessGroup extends Model<CrmBusinessGroup> { ...@@ -97,7 +97,7 @@ public class CrmBusinessGroup extends Model<CrmBusinessGroup> {
@Transient @Transient
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "组成员id") @ApiModelProperty(value = "组成员id")
private Integer[] memberIds; private List<Integer> memberIds;
@Transient @Transient
@TableField(exist = false) @TableField(exist = false)
......
...@@ -112,11 +112,14 @@ public class CrmController { ...@@ -112,11 +112,14 @@ public class CrmController {
@PostMapping("addBusinessGroup") @PostMapping("addBusinessGroup")
@Transactional @Transactional
@ApiOperation(value = "新增业务组", httpMethod = "POST", notes = "接口发布说明") @ApiOperation(value = "新增/编辑业务组", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> addBusinessGroup(@CurrentUser UserBean userBean, public Result<Object> addBusinessGroup(@CurrentUser UserBean userBean,
@RequestBody CrmBusinessGroup crmBusinessGroup) { @RequestBody CrmBusinessGroup crmBusinessGroup) {
Integer orgCode = getOrgCode(userBean); Integer orgCode = getOrgCode(userBean);
Integer empNum = getEmpNum(userBean); Integer empNum = getEmpNum(userBean);
Integer gid = crmBusinessGroup.getId();
crmBusinessGroup.setModifyUser(empNum); // 修改人
if (gid == null) {
CrmBusinessGroup crmBusinessGroupOld = CrmBusinessGroup.builder().build() CrmBusinessGroup crmBusinessGroupOld = CrmBusinessGroup.builder().build()
.selectOne(new QueryWrapper<CrmBusinessGroup>().lambda().eq(CrmBusinessGroup::getOrgCode, orgCode) .selectOne(new QueryWrapper<CrmBusinessGroup>().lambda().eq(CrmBusinessGroup::getOrgCode, orgCode)
.select(CrmBusinessGroup::getSort).last("limit 1").orderByDesc(CrmBusinessGroup::getId)); .select(CrmBusinessGroup::getSort).last("limit 1").orderByDesc(CrmBusinessGroup::getId));
...@@ -124,30 +127,61 @@ public class CrmController { ...@@ -124,30 +127,61 @@ public class CrmController {
crmBusinessGroup.setSort(1); crmBusinessGroup.setSort(1);
else else
crmBusinessGroup.setSort(crmBusinessGroupOld.getSort() + 1);// 排序 crmBusinessGroup.setSort(crmBusinessGroupOld.getSort() + 1);// 排序
// crmBusinessGroup.setManagerName(getEmpName(orgCode, empNum)); // 设置管理员姓名
crmBusinessGroup.setCreateUser(empNum); // 创建人 crmBusinessGroup.setCreateUser(empNum); // 创建人
crmBusinessGroup.setModifyUser(empNum); // 修改人
crmBusinessGroup.setOrgCode(orgCode); crmBusinessGroup.setOrgCode(orgCode);
// crmBusinessGroup.setMember(member); // ,字符串拼接
boolean result = crmBusinessGroup.insert(); boolean result = crmBusinessGroup.insert();
if (!result) if (!result)
return ResultUtil.success("新增失败"); return ResultUtil.success("新增失败");
Integer gid = crmBusinessGroup.getId(); gid = crmBusinessGroup.getId();
Integer[] memberIds = crmBusinessGroup.getMemberIds(); List<Integer> memberIds = crmBusinessGroup.getMemberIds();
for (Integer empId : memberIds) { 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) { 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 crmSeaRule = crmBusinessGroup.getCrmSeaRules();
crmSeaRule.setGid(gid); crmSeaRule.setGid(gid);
crmSeaRule.insert(); 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("新增业务组成功"); 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") @GetMapping("getBusinessGroup")
@ApiOperation(value = "获取业务组列表", httpMethod = "GET", notes = "接口发布说明") @ApiOperation(value = "获取业务组列表", httpMethod = "GET", notes = "接口发布说明")
public Result<Object> getBusinessGroup(@CurrentUser UserBean userBean) { public Result<Object> getBusinessGroup(@CurrentUser UserBean userBean) {
...@@ -179,6 +213,7 @@ public class CrmController { ...@@ -179,6 +213,7 @@ public class CrmController {
String name = getEmpName(getOrgCode(userBean), empNum); String name = getEmpName(getOrgCode(userBean), empNum);
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("name", name); map.put("name", name);
map.put("empNum", empNum);
members.add(map); members.add(map);
} }
crmBusinessGroup.setMembers(members); 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