Commit 96ea0b5c by xugaojun

Merge remote-tracking branch 'origin/developer' into developer

parents a0f5ba72 074dc1c6
......@@ -22,7 +22,6 @@ import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.common.utils.UuidUtil;
import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.enums.SecretTypeEnum;
import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.service.dao.mapper.StaffDepartmentRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
......@@ -62,17 +61,12 @@ public class StaffApiServiceImpl implements StaffApiService {
private StaffDepartmentRelatedService staffDepartmentRelatedService;
@Autowired
private StaffDepartmentRelatedMapper staffDepartmentRelatedMapper;
@Autowired
private QywxUserApiService qywxUserApiService;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private DepartmentService departmentService;
@Autowired
private DepartmentApiService departmentApiService;
@Autowired
private ClerkService clerkService;
@Autowired
......@@ -588,14 +582,16 @@ public class StaffApiServiceImpl implements StaffApiService {
}
private void staffEditDeal(StaffDTO staffDTO, String departmentIds) {
TabHaobanStaff oldStaff = staffMapper.selectByPrimaryKey(staffDTO.getStaffId());
String staffId = staffDTO.getStaffId();
TabHaobanStaff oldStaff = staffService.selectById(staffId);
logger.info("【员工修改】oldStaff={}", JSON.toJSONString(oldStaff));
//1、先更新staff
logger.info("【员工修改】staffDTO={}", JSON.toJSONString(staffDTO));
TabHaobanStaff tab = EntityUtil.changeEntityByJSON(TabHaobanStaff.class, staffDTO);
staffService.updateByPrimaryKey(tab);
String staffName = tab.getStaffName();
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staffDTO.getStaffId());
staffService.updateByPrimaryKey(EntityUtil.changeEntityByJSON(TabHaobanStaff.class, staffDTO));
//再去查一下
TabHaobanStaff staff = staffService.selectById(staffId);
String staffName = staff.getStaffName();
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staffId);
Map<String, TabHaobanStaffDepartmentRelated> map = com.gic.commons.util.CollectionUtil.toMap(list, "departmentId");
//2、该员工新增部门
if (StringUtils.isNotBlank(departmentIds)) {
......@@ -605,80 +601,42 @@ public class StaffApiServiceImpl implements StaffApiService {
//该员工新增了部门
StaffDepartmentRelatedDTO related = new StaffDepartmentRelatedDTO();
related.setStaffDepartmentRelatedId(UuidUtil.randomUUID());
related.setStaffId(staffDTO.getStaffId());
related.setStaffId(staffId);
related.setClerkCode(null);
related.setCreateTime(new Date());
related.setDepartmentId(addId);
related.setNationCode(staffDTO.getNationCode());
related.setPhoneNumber(staffDTO.getPhoneNumber());
related.setNationCode(staff.getNationCode());
related.setPhoneNumber(staff.getPhoneNumber());
related.setStatusFlag(1);
related.setUpdateTime(new Date());
related.setWxUserId(oldStaff.getWxUserId());
related.setWxEnterpriseId(staffDTO.getWxEnterpriseId());
related.setWxUserId(staff.getWxUserId());
related.setWxEnterpriseId(staff.getWxEnterpriseId());
related.setStaffName(staffName);
staffDepartmentRelatedService.add(related);
} else {
//该员工部门没做改变(只更新手机号即可)
TabHaobanStaffDepartmentRelated related = map.get(addId);
if (!staffDTO.getPhoneNumber().equals(related.getPhoneNumber())) {
related.setPhoneNumber(staffDTO.getPhoneNumber());
related.setNationCode(staffDTO.getNationCode());
if (!staff.getPhoneNumber().equals(related.getPhoneNumber())) {
related.setPhoneNumber(staff.getPhoneNumber());
related.setNationCode(staff.getNationCode());
related.setUpdateTime(new Date());
related.setStaffName(staffName);
related.setWxEnterpriseId(staff.getWxEnterpriseId());
staffDepartmentRelatedMapper.updateByPrimaryKeySelective(related);
}
}
}
}
//3、该员工删除部门
for (TabHaobanStaffDepartmentRelated tab1 : list) {
for (TabHaobanStaffDepartmentRelated staffDepartmentRelated : list) {
if (departmentIds == null) {
departmentIds = "";
}
//不包含,则说明员工删除了该部门
if (!departmentIds.contains(tab1.getDepartmentId())) {
logger.info("【员工修改删除】tab1.getDepartmentId()={}", tab1.getDepartmentId());
StaffDepartmentRelatedDTO related = EntityUtil.changeEntityByJSON(StaffDepartmentRelatedDTO.class, tab1);
if (!departmentIds.contains(staffDepartmentRelated.getDepartmentId())) {
logger.info("【员工修改删除】tab1.getDepartmentId()={}", staffDepartmentRelated.getDepartmentId());
StaffDepartmentRelatedDTO related = EntityUtil.changeEntityByJSON(StaffDepartmentRelatedDTO.class, staffDepartmentRelated);
staffDepartmentRelatedService.del(related);
}
}
Boolean weixinPush = staffDTO.getWeixinPush();
if (weixinPush == null || !weixinPush) {
//不需要推送到企微
//updateWxMessage(oldStaff, staffDTO, departmentIds);
}
}
private void updateWxMessage(TabHaobanStaff oldStaff, StaffDTO staffDTO, String departmentIds) {
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(oldStaff.getWxEnterpriseId());
if (enterpriseDTO != null) {
UserDTO userDTO = new UserDTO();
userDTO.setCorpid(enterpriseDTO.getCorpid());
userDTO.setAlias(staffDTO.getNickName());
String[] departmentIdArr = departmentIds.split(",");
Integer[] wxDepartmentIdArrIntegers = new Integer[departmentIdArr.length];
int index = 0;
for (String string : departmentIdArr) {
TabHaobanDepartment tabs = departmentService.selectById(string);
wxDepartmentIdArrIntegers[index] = Integer.parseInt(tabs.getWxDepartmentId());
index++;
}
userDTO.setDepartment(wxDepartmentIdArrIntegers);
userDTO.setGender(staffDTO.getSex() == null ? "" : staffDTO.getSex().toString());
userDTO.setMobile(staffDTO.getPhoneNumber());
userDTO.setName(staffDTO.getStaffName());
userDTO.setUserid(oldStaff.getWxUserId());
userDTO.setPosition(staffDTO.getPostion());
userDTO.setExternal_position(staffDTO.getExtendPostion());
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(enterpriseDTO.getWxEnterpriseId(), SecretTypeEnum.CONTACT_SECRET.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
throw new RuntimeException("没有设置通讯录secret");
}
JSONResponse jp = qywxUserApiService.updateSelfWorkWxUser(userDTO, enterpriseDTO.getCorpid(), secretSetting.getSecretVal());
if (jp.getErrorCode() != 0) {
throw new RuntimeException("微信新增失败");
}
}
}
@Override
......
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