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,40 +112,74 @@ public class CrmController { ...@@ -112,40 +112,74 @@ 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);
CrmBusinessGroup crmBusinessGroupOld = CrmBusinessGroup.builder().build()
.selectOne(new QueryWrapper<CrmBusinessGroup>().lambda().eq(CrmBusinessGroup::getOrgCode, orgCode)
.select(CrmBusinessGroup::getSort).last("limit 1").orderByDesc(CrmBusinessGroup::getId));
if (crmBusinessGroupOld == null)
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 gid = crmBusinessGroup.getId();
Integer[] memberIds = crmBusinessGroup.getMemberIds(); crmBusinessGroup.setModifyUser(empNum); // 修改人
for (Integer empId : memberIds) { if (gid == null) {
CrmBusinessGroupMember.builder().gid(gid).empNum(empId).orgCode(orgCode).type(0).build().insert(); CrmBusinessGroup crmBusinessGroupOld = CrmBusinessGroup.builder().build()
.selectOne(new QueryWrapper<CrmBusinessGroup>().lambda().eq(CrmBusinessGroup::getOrgCode, orgCode)
.select(CrmBusinessGroup::getSort).last("limit 1").orderByDesc(CrmBusinessGroup::getId));
if (crmBusinessGroupOld == null)
crmBusinessGroup.setSort(1);
else
crmBusinessGroup.setSort(crmBusinessGroupOld.getSort() + 1);// 排序
crmBusinessGroup.setCreateUser(empNum); // 创建人
crmBusinessGroup.setOrgCode(orgCode);
boolean result = crmBusinessGroup.insert();
if (!result)
return ResultUtil.success("新增失败");
gid = crmBusinessGroup.getId();
List<Integer> memberIds = crmBusinessGroup.getMemberIds();
for (Integer empId : memberIds) {
insertMembers(gid, empId, orgCode, 0);
}
List<Integer> managerIds = crmBusinessGroup.getManagerIds();
for (Integer empId : managerIds) {
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));
} }
Integer[] managerIds = crmBusinessGroup.getManagerIds(); return ResultUtil.success("新增业务组成功");
for (Integer empId : managerIds) { }
CrmBusinessGroupMember.builder().gid(gid).empNum(empId).orgCode(orgCode).type(1).build().insert();
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));
} }
CrmSeaRule crmSeaRule = crmBusinessGroup.getCrmSeaRules(); List<Integer> addList = CheckUtil.reduce(memberIds, oldIdsList); // 增
crmSeaRule.setGid(gid); for (Integer integer : addList) {
crmSeaRule.insert(); CrmBusinessGroupMember.builder().empNum(integer).gid(gid).orgCode(orgCode).type(type).build().insert();
return ResultUtil.success("新增业务组成功"); }
} }
@GetMapping("getBusinessGroup") @GetMapping("getBusinessGroup")
...@@ -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