StaffService.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. package com.dk.mdm.service.mst;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.dk.common.exception.BaseBusinessException;
  4. import com.dk.common.infrastructure.annotaiton.Pagination;
  5. import com.dk.common.infrastructure.constant.Constant;
  6. import com.dk.common.infrastructure.enums.ErrorCodeEnum;
  7. import com.dk.common.model.pojo.PageList;
  8. import com.dk.common.model.pojo.mst.StaffPurview;
  9. import com.dk.common.model.pojo.mst.StaffRight;
  10. import com.dk.common.model.vo.core.StaffEntity;
  11. import com.dk.common.response.ResponseCodeEnum;
  12. import com.dk.common.response.ResponseResultUtil;
  13. import com.dk.common.response.ResponseResultVO;
  14. import com.dk.mdm.feign.CompanyFeign;
  15. import com.dk.mdm.feign.UserFeign;
  16. import com.dk.mdm.infrastructure.convert.mst.StaffConvert;
  17. import com.dk.mdm.infrastructure.util.AuthUtils;
  18. import com.dk.mdm.mapper.common.CommonMapper;
  19. import com.dk.mdm.mapper.mst.*;
  20. import com.dk.mdm.model.pojo.mst.*;
  21. import com.dk.common.service.BaseService;
  22. import com.dk.common.mapper.BaseMapper;
  23. import com.dk.mdm.model.query.mst.ComMenuQuery;
  24. import com.dk.mdm.model.query.mst.StaffQuery;
  25. import com.dk.common.model.response.mst.StaffResponse;
  26. import com.dk.common.model.vo.mst.StaffVO;
  27. import com.dk.mdm.model.vo.mst.ComMenuVO;
  28. import com.dk.mdm.service.common.CommonService;
  29. import lombok.extern.slf4j.Slf4j;
  30. import org.springframework.stereotype.Service;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.transaction.annotation.Transactional;
  33. import org.springframework.util.CollectionUtils;
  34. import javax.annotation.Resource;
  35. import java.util.*;
  36. /**
  37. * @author : 姜永辉
  38. * @desc : 员工API接口
  39. * @date : 2023/1/4 9:25
  40. */
  41. @Service
  42. @Slf4j
  43. public class StaffService extends BaseService<Staff> {
  44. @Resource
  45. private CompanyFeign companyFeign;
  46. @Resource
  47. private UserFeign userFeign;
  48. @Override
  49. public BaseMapper<Staff> getRepository() {
  50. return staffMapper;
  51. }
  52. /**
  53. * @desc : 重写主键
  54. * @author : 姜永辉
  55. * @date : 2023/1/9 10:39
  56. */
  57. @Override
  58. public String getPrimaryKey() {
  59. return "staff_id";
  60. }
  61. @Autowired
  62. private StaffMapper staffMapper;
  63. @Autowired
  64. private StaffConvert staffConvert;
  65. @Autowired
  66. private StaffRightService staffRightService;
  67. @Autowired
  68. private StaffPurviewService staffPurviewService;
  69. @Autowired
  70. private CommonService commonService;
  71. @Autowired
  72. private CommonMapper commonMapper;
  73. @Autowired
  74. private ComMenuService comMenuService;
  75. @Autowired
  76. private ComMenuMapper comMenuMapper;
  77. @Autowired
  78. private SettingValueMapper settingValueMapper;
  79. @Autowired
  80. private AuthUtils authUtils;
  81. @Autowired
  82. DictionaryDataMapper dictionaryDataMapper;
  83. @Autowired
  84. GoodsCategoryMapper goodsCategoryMapper;
  85. @Autowired
  86. RoleMapper roleMapper;
  87. @Autowired
  88. RoleFunMapper roleFunMapper;
  89. @Autowired
  90. UnitMapper unitMapper;
  91. @Autowired
  92. SaleChannelMapper saleChannelMapper;
  93. @Autowired
  94. WarehouseMapper warehouseMapper;
  95. @Autowired
  96. PrintLayoutMapper printLayoutMapper;
  97. /**
  98. * @desc : 条件查询
  99. * @author : 姜永辉
  100. * @date : 2023/1/9 10:40
  101. */
  102. @Pagination
  103. public ResponseResultVO<PageList<StaffResponse>> selectByCond(StaffQuery staffQuery) {
  104. // 获取当前公司的cpId
  105. if (staffQuery.getCpId() == null) {
  106. Integer cpId = authUtils.getStaff().getCpId();
  107. staffQuery.setCpId(cpId);
  108. }
  109. return super.mergeListWithCount(staffQuery, staffMapper.selectByCond(staffQuery),
  110. staffMapper.countByCond(staffQuery));
  111. }
  112. /**
  113. * @desc : 保存方法
  114. * @author : 姜永辉
  115. * @date : 2023/1/9 10:49
  116. */
  117. @Transactional(
  118. rollbackFor = {Exception.class}
  119. )
  120. public ResponseResultVO<?> insert(StaffVO staffVO) {
  121. // 转化实体
  122. Staff staff = staffConvert.convertToPo(staffVO);
  123. // 获取当前公司的cpId
  124. Integer cpId = authUtils.getStaff().getCpId();
  125. // 校验同一个公司的电话不能重复
  126. StaffQuery staffQuery = new StaffQuery();
  127. staffQuery.setStaffPhone(staff.getStaffPhone());
  128. staffQuery.setCpId(cpId);
  129. staff.setCpId(cpId);
  130. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  131. if (staffResponses != null && staffResponses.size() > 0) {
  132. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  133. }
  134. staffQuery.setStaffPhone(null);
  135. staffQuery.setStaffCode(staff.getStaffCode());
  136. staffResponses = staffMapper.selectByCondByCode(staffQuery);
  137. if (staffResponses != null && staffResponses.size() > 0) {
  138. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_CODE_EXIST);
  139. }
  140. // 获取编码和主键UuId
  141. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), false);
  142. staff.setStaffId(codeMap.get("outId").toString());
  143. // staff.setStaffCode(codeMap.get("outNote").toString());
  144. super.insert(staff);
  145. // 讲电话和名称插入微信用户表里
  146. Map<String, Object> collectQuery = new HashMap<>();
  147. collectQuery.put("currentCp", staff.getCpId());
  148. collectQuery.put("userName", staff.getStaffName());
  149. collectQuery.put("userPhone", staff.getStaffPhone());
  150. ResponseResultVO<?> resultVO = userFeign.registerFeign(collectQuery);
  151. Map<String, Object> m = new HashMap<>();
  152. // 如果没有成功返回,状态设置为待审
  153. if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  154. // 无用户
  155. throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  156. ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  157. } else {
  158. m = (Map<String, Object>) resultVO.getData();
  159. }
  160. staff.setWxUserId(m.get("userId").toString());
  161. super.updateByUuid(staff);
  162. return ResponseResultUtil.success(staff);
  163. }
  164. /**
  165. * @desc : 保存方法
  166. * @author : 姜永辉
  167. * @date : 2023/1/9 10:49
  168. */
  169. @Transactional(
  170. rollbackFor = {Exception.class}
  171. )
  172. public ResponseResultVO<?> insertFeignStaff(StaffVO staffVO) {
  173. // 转化实体
  174. Staff staff = staffConvert.convertToPo(staffVO);
  175. // 校验同一个公司的电话不能重复
  176. StaffQuery staffQuery = new StaffQuery();
  177. staffQuery.setCpId(staff.getCpId());
  178. staffQuery.setStaffPhone(staff.getStaffPhone());
  179. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  180. if (staffResponses != null && staffResponses.size() > 0) {
  181. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  182. }
  183. // 获取编码和主键UuId
  184. Map<String, Object> codeMap = commonService.getUniqueNoteCode(
  185. Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true);
  186. staff.setStaffId(codeMap.get("outId").toString());
  187. staff.setStaffCode(codeMap.get("outNote").toString());
  188. super.insert(staff);
  189. return ResponseResultUtil.success(staff);
  190. }
  191. /**
  192. * @desc : 注册商户时候插入 角色 基础资料(仓库 渠道 收入 支出 入库 出库 账户 来源 盈亏原因) 计量单位 种类 打印票据 等等。
  193. * 返回角色的数据
  194. * @author : 姜永辉
  195. * @date : 2023/1/9 10:49
  196. */
  197. @Transactional(rollbackFor = {Exception.class})
  198. public ResponseResultVO<?> insertFeignCompanyData(Map<String, List<Map<String, Object>>> map) {
  199. // 公司
  200. List<Map<String, Object>> listCom = map.get("company");
  201. // 版本
  202. String gradeCode = listCom.get(0).get("gradeCode").toString();
  203. // 角色
  204. List<Map<String, Object>> listRoles = map.get("roles");
  205. List<Role> listR = new ArrayList<>();
  206. String roleid = "";
  207. Integer cpId = Integer.parseInt(listCom.get(0).get("cpId").toString()) ;
  208. String staffId = listCom.get(0).get("staffId").toString();
  209. // 插入常用功能 标准版 插入 销售出库 库存查询 商品档案
  210. if(Constant.STD.equals(gradeCode)){
  211. List<String> objectCodeList = new ArrayList<>();
  212. // 销售出库
  213. objectCodeList.add("order-out");
  214. // 库存查询
  215. objectCodeList.add("ivt-detail-report");
  216. // 商品档案
  217. objectCodeList.add("goods");
  218. ComMenuVO comMenuVO = new ComMenuVO();
  219. comMenuVO.setCpId(cpId).setStaffId(staffId).setAppCode(Constant.AppCode.WEIXIN.getCode())
  220. .setObjectCodeList(objectCodeList);
  221. comMenuMapper.saveByCompany(comMenuVO);
  222. // 系统参数
  223. List<SettingValue> settingValueList = new ArrayList<>();
  224. // 自动办理
  225. settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_001.getValue())
  226. .setSettingValue("true"));
  227. // 欠货销售
  228. settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_002.getValue())
  229. .setSettingValue("true"));
  230. settingValueMapper.insertBatch(settingValueList);
  231. }
  232. for (int i = 0; i < listRoles.size(); i++) {
  233. Map<String, Object> m = listRoles.get(i);
  234. Role role = new Role();
  235. //设置编码
  236. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.ROLE.getName(),cpId, false);
  237. if (Constant.ROLE_DATA.equals(m.get("roleCode").toString())) {
  238. roleid = uniqueNoteCode.get("outId").toString();
  239. }
  240. role.setRoleId(uniqueNoteCode.get("outId").toString());
  241. role.setRoleCode(m.get("roleCode").toString());
  242. role.setRoleName(m.get("roleName").toString());
  243. role.setDisplayNo((Integer) m.get("displayNo"));
  244. role.setCpId(cpId);
  245. role.setOpCreateUserId(m.get("opCreateUserId").toString());
  246. listR.add(role);
  247. }
  248. roleMapper.insertBatch(listR);
  249. // 更新用户的角色ids-
  250. List<String> roleids = new ArrayList<>();
  251. roleids.add(roleid);
  252. this.updateByUuid(new Staff().setStaffId(staffId).setRoleIds(roleids));
  253. // 角色权限
  254. RoleFun roleFun = new RoleFun();
  255. roleFun.setRoleId(roleid);
  256. roleFun.setCpId(cpId);
  257. roleFun.setOpCreateUserId(staffId);
  258. roleFunMapper.insertRoleFunFeign(roleFun);
  259. // 仓库
  260. List<Map<String, Object>> listWarehouses = map.get("warehouses");
  261. List<Warehouse> listW = new ArrayList<>();
  262. for (int i = 0; i < listWarehouses.size(); i++) {
  263. Map<String, Object> m = listWarehouses.get(i);
  264. Warehouse warehouse = new Warehouse();
  265. warehouse.setWhCode(m.get("whCode").toString());
  266. warehouse.setWhName(m.get("whName").toString());
  267. warehouse.setDisplayNo((Integer) m.get("displayNo"));
  268. warehouse.setFlgDefault((Boolean) m.get("flgDefault"));
  269. warehouse.setCpId(cpId);
  270. warehouse.setOpCreateUserId(m.get("opCreateUserId").toString());
  271. listW.add(warehouse);
  272. }
  273. warehouseMapper.insertBatch(listW);
  274. // 渠道
  275. List<Map<String, Object>> listSaleChannels = map.get("saleChannels");
  276. List<SaleChannel> listSc = new ArrayList<>();
  277. for (int i = 0; i < listSaleChannels.size(); i++) {
  278. Map<String, Object> m = listSaleChannels.get(i);
  279. SaleChannel saleChannel = new SaleChannel();
  280. saleChannel.setChannelCode(m.get("channelCode").toString());
  281. saleChannel.setChannelName(m.get("channelName").toString());
  282. saleChannel.setDisplayNo((Integer) m.get("displayNo"));
  283. saleChannel.setFlgDefault((Boolean) m.get("flgDefault"));
  284. saleChannel.setCpId(cpId);
  285. saleChannel.setOpCreateUserId(m.get("opCreateUserId").toString());
  286. listSc.add(saleChannel);
  287. }
  288. saleChannelMapper.insertBatch(listSc);
  289. // 基础资料
  290. List<Map<String, Object>> listDictionaryDatas = map.get("dictionaryDatas");
  291. List<DictionaryData> listDD = new ArrayList<>();
  292. for (int i = 0; i < listDictionaryDatas.size(); i++) {
  293. Map<String, Object> m = listDictionaryDatas.get(i);
  294. DictionaryData dictionaryData = new DictionaryData();
  295. dictionaryData.setDictCode(m.get("dictCode").toString());
  296. dictionaryData.setDataCode(m.get("dataCode").toString());
  297. dictionaryData.setDataValue(m.get("dataValue").toString());
  298. dictionaryData.setDisplayNo((Integer) m.get("displayNo"));
  299. dictionaryData.setFlgDefault((Boolean) m.get("flgDefault"));
  300. dictionaryData.setCpId(cpId);
  301. dictionaryData.setOpCreateUserId(m.get("opCreateUserId").toString());
  302. listDD.add(dictionaryData);
  303. }
  304. dictionaryDataMapper.insertBatch(listDD);
  305. // 计量单位
  306. List<Map<String, Object>> listUnits = map.get("units");
  307. List<Unit> listU = new ArrayList<>();
  308. for (int i = 0; i < listUnits.size(); i++) {
  309. Map<String, Object> m = listUnits.get(i);
  310. Unit unit = new Unit();
  311. unit.setUnitCode(m.get("unitCode").toString());
  312. unit.setUnitName(m.get("unitName").toString());
  313. unit.setDecimalPlaces((Integer) m.get("decimalPlaces"));
  314. unit.setDisplayNo((Integer) m.get("displayNo"));
  315. unit.setCpId(cpId);
  316. unit.setOpCreateUserId(m.get("opCreateUserId").toString());
  317. listU.add(unit);
  318. }
  319. unitMapper.insertBatch(listU);
  320. // 种类
  321. List<Map<String, Object>> listGoodsCategorys = map.get("goodsCategorys");
  322. List<GoodsCategory> listG = new ArrayList<>();
  323. for (int i = 0; i < listGoodsCategorys.size(); i++) {
  324. Map<String, Object> m = listGoodsCategorys.get(i);
  325. GoodsCategory goodsCategory = new GoodsCategory();
  326. goodsCategory.setCatCode(m.get("catCode")+ "");
  327. goodsCategory.setCatName(m.get("catName")+ "");
  328. if (m.get("parentId")!=null){
  329. goodsCategory.setParentId(m.get("parentId")+ "");
  330. }
  331. if (m.get("topId")!=null){
  332. goodsCategory.setTopId(m.get("topId")+ "");
  333. }
  334. if (m.get("levelUpper")!=null){
  335. goodsCategory.setLevelUpper(m.get("levelUpper")+ "");
  336. }
  337. if (m.get("levelLower")!=null){
  338. goodsCategory.setLevelLower(m.get("levelLower")+ "");
  339. }
  340. goodsCategory.setLevelLeaf((Boolean) m.get("levelLeaf"));
  341. goodsCategory.setLevelNo((Integer) m.get("levelNo"));
  342. goodsCategory.setLevelCode(m.get("levelCode") + "");
  343. goodsCategory.setLevelName(m.get("levelName") + "");
  344. goodsCategory.setDisplayNo((Integer) m.get("displayNo"));
  345. goodsCategory.setCpId(cpId);
  346. goodsCategory.setOpCreateUserId(m.get("opCreateUserId").toString());
  347. listG.add(goodsCategory);
  348. }
  349. goodsCategoryMapper.insertBatch(listG);
  350. // 打印票据
  351. List<Map<String, Object>> listPrintLayout = map.get("printLayout");
  352. List<PrintLayout> listP = new ArrayList<>();
  353. for (int i = 0; i < listPrintLayout.size(); i++) {
  354. Map<String, Object> m = listPrintLayout.get(i);
  355. PrintLayout printLayout = new PrintLayout();
  356. printLayout.setLayoutName(m.get("layoutName") + "");
  357. printLayout.setLayoutData(JSONObject.parseObject(JSONObject.toJSONString(m.get("layoutData"))));
  358. printLayout.setDisplayNo((Integer) m.get("displayNo"));
  359. printLayout.setDocName(m.get("docName")+ "" );
  360. printLayout.setCpId(cpId);
  361. printLayout.setOpCreateUserId(m.get("opCreateUserId").toString());
  362. listP.add(printLayout);
  363. }
  364. printLayoutMapper.insertBatch(listP);
  365. return ResponseResultUtil.success();
  366. }
  367. /**
  368. * @desc : 保存方法-邀请员工的确定
  369. * @author : 姜永辉
  370. * @date : 2023/1/9 10:49
  371. */
  372. @Transactional(rollbackFor = {Exception.class})
  373. public ResponseResultVO<?> insertRequestStaff(StaffVO staffVO) {
  374. // 转化实体
  375. Staff staff = staffConvert.convertToPo(staffVO);
  376. // 校验同一个公司的电话不能重复
  377. StaffQuery staffQuery = new StaffQuery();
  378. staffQuery.setCpId(staff.getCpId());
  379. staffQuery.setStaffPhone(staff.getStaffPhone());
  380. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  381. if (staffResponses != null && staffResponses.size() > 0) {
  382. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  383. }
  384. // 获取编码和主键UuId
  385. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), true);
  386. staff.setStaffId(codeMap.get("outId").toString());
  387. staff.setStaffCode(codeMap.get("outNote").toString());
  388. // 更新 被邀人员的cpid
  389. if (staff.getWxUserId() != null) {
  390. // 更新 被邀请人员的微信用户的cpid 加入公司
  391. Map<String, Object> collectQuery = new HashMap<>();
  392. collectQuery.put("cpId", staff.getCpId());
  393. collectQuery.put("userId", staff.getWxUserId());
  394. companyFeign.updateWxUserCompany(collectQuery);
  395. }
  396. // 插入员工
  397. super.insert(staff);
  398. return ResponseResultUtil.success(staff);
  399. }
  400. /**
  401. * @desc : 编辑方法
  402. * @author : 姜永辉
  403. * @date : 2023/1/9 10:49
  404. */
  405. @Transactional(
  406. rollbackFor = {Exception.class}
  407. )
  408. public ResponseResultVO<Boolean> update(StaffVO staffVO) {
  409. // 转化实体
  410. Staff staff = staffConvert.convertToPo(staffVO);
  411. return super.updateByUuid(staff);
  412. }
  413. /**
  414. * @desc : 保存权限方法
  415. * @author : 姜永辉
  416. * @date : 2023/1/9 10:49
  417. */
  418. @Transactional(
  419. rollbackFor = {Exception.class}
  420. )
  421. public ResponseResultVO<?> saveStaffRight(StaffVO staffVO) {
  422. // 获取当前公司的cpId
  423. Integer cpId = authUtils.getStaff().getCpId();
  424. // 转化实体
  425. Staff staff = staffConvert.convertToPo(staffVO);
  426. staffRightService.delete(staffVO.getStaffId());
  427. for (StaffRight staffRight : staffVO.getStaffRightList()) {
  428. staffRight.setStaffId(staff.getStaffId());
  429. staffRight.setRightType(1);
  430. staffRight.setCpId(cpId);
  431. }
  432. if (staffVO.getStaffRightList() != null && staffVO.getStaffRightList().size() > 0) {
  433. staffRightService.saveStaffRight(staffVO.getStaffRightList());
  434. }
  435. return ResponseResultUtil.success();
  436. }
  437. /**
  438. * @desc : 保存权限方法
  439. * @author : 姜永辉
  440. * @date : 2023/1/9 10:49
  441. */
  442. @Transactional(
  443. rollbackFor = {Exception.class}
  444. )
  445. public ResponseResultVO<?> saveStaffPurview(StaffVO staffVO) {
  446. // 获取当前公司的cpId
  447. Integer cpId = authUtils.getStaff().getCpId();
  448. // 转化实体
  449. Staff staff = staffConvert.convertToPo(staffVO);
  450. for (StaffPurview staffRight : staffVO.getStaffPurviewList()) {
  451. staffRight.setStaffId(staff.getStaffId());
  452. staffRight.setCpId(cpId);
  453. }
  454. staffPurviewService.saveStaffPurview(staffVO.getStaffPurviewList());
  455. return ResponseResultUtil.success();
  456. }
  457. /**
  458. * @desc : 员工离职
  459. * @author : 姜永辉
  460. * @date : 2023/2/13 13:45
  461. */
  462. @Transactional(
  463. rollbackFor = {Exception.class}
  464. )
  465. public ResponseResultVO<Boolean> dimission(StaffVO staffVO) {
  466. // 将微信的用户的信息 openid current_cp , "joined_cps" 缩减相应的cpid
  467. // 更新 被邀请人员的微信用户的cpid 加入公司
  468. Map<String, Object> collectQuery = new HashMap<>();
  469. // 获取当前公司的cpId
  470. Integer cpId = authUtils.getStaff().getCpId();
  471. collectQuery.put("cpId", cpId);
  472. collectQuery.put("userId", staffVO.getWxUserId());
  473. ResponseResultVO<?> resultVO = userFeign.updateClearOpenidFeign(collectQuery);
  474. // 如果没有成功返回,状态设置为待审
  475. if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  476. // 无用户
  477. throw new BaseBusinessException(ErrorCodeEnum.STAFF_UPDATE_ERROR.getCode(),
  478. ErrorCodeEnum.STAFF_UPDATE_ERROR.getMessage());
  479. }
  480. // 转化实体
  481. Staff staff = staffConvert.convertToPo(staffVO);
  482. super.updateByUuid(staff);
  483. return ResponseResultUtil.success();
  484. }
  485. /**
  486. * @desc : 导入员工
  487. * @author : 姜永辉
  488. * @date : 2023/3/1 14:40
  489. */
  490. @Transactional(
  491. rollbackFor = {Exception.class}
  492. )
  493. public ResponseResultVO<Boolean> importStaffList(List<StaffVO> list) {
  494. if (CollectionUtils.isEmpty(list) || list.size() == 0) {
  495. return ResponseResultUtil.error(ResponseCodeEnum.INSERT_FAIL);
  496. }
  497. return ResponseResultUtil.success();
  498. }
  499. /**
  500. * @desc : 登录后获取信息
  501. * @author : 周兴
  502. * @date : 2024/3/4 11:41
  503. */
  504. @Transactional(
  505. rollbackFor = {Exception.class}
  506. )
  507. public ResponseResultVO<Dictionary<String, Object>> getInfoAfterLogin(Map<String, Object> param) {
  508. // 先根据userId查询当前企业的员工信息
  509. StaffResponse staff = staffMapper.selectByUserId(param.get("userId").toString(), Integer.parseInt(param.get("cpId").toString()));
  510. if (staff != null) {
  511. // 提示不允许登录
  512. if(staff.getFlgCanLogin() == null || !staff.getFlgCanLogin()){
  513. return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CAN_NOT_LOGIN.getMessage());
  514. }
  515. // 离职状态不允许登录
  516. if(staff.getHrStatus() != 1){
  517. return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_OUT_NOT_LOGIN.getMessage());
  518. }
  519. // 存Redis
  520. authUtils.saveStaff(new StaffEntity().setStaffId(staff.getStaffId())
  521. .setWxUserId(staff.getWxUserId())
  522. .setStaffCode(staff.getStaffCode())
  523. .setStaffName(staff.getStaffName())
  524. .setCpId(Integer.parseInt(param.get("cpId").toString()))
  525. .setAppCode(param.get("appCode").toString()));
  526. // 更新员工登录状态
  527. this.updateByUuid(new Staff().setStaffId(staff.getStaffId()).setFlgCanLogin(true));
  528. } else {
  529. return ResponseResultUtil.error(ErrorCodeEnum.STAFF_NOT_EXIST.getCode(), ErrorCodeEnum.STAFF_NOT_EXIST.getMessage());
  530. }
  531. // 获取菜单
  532. List menuList = commonMapper.getMenuByUser(param);
  533. // 获取常用菜单
  534. ResponseResultVO<?> comMenuList = comMenuService.selectMenu(new ComMenuQuery().setStaffId(staff.getStaffId())
  535. .setAppCode(param.get("appCode").toString()));
  536. // 获取所有参数
  537. Map<String, Object> allSettingValue = commonMapper.getAllSettingValue();
  538. Dictionary<String, Object> dic = new Hashtable<>();
  539. dic.put("menuList", menuList);
  540. dic.put("comMenuList", comMenuList.getData());
  541. dic.put("dataKindList", commonMapper.getDataKind(param));
  542. dic.put("settingValue", allSettingValue);
  543. dic.put("staff", staff);
  544. return ResponseResultUtil.success(dic);
  545. }
  546. /**
  547. * @desc : 退出登录
  548. * @author : 周兴
  549. * @date : 2024-03-18 09:03
  550. */
  551. @Transactional(
  552. rollbackFor = {Exception.class}
  553. )
  554. public ResponseResultVO<Boolean> logout(Map<String, Object> param) {
  555. // 更新员工登录状态
  556. this.updateByUuid(new Staff().setStaffId(param.get("staffId").toString()).setFlgCanLogin(false));
  557. return ResponseResultUtil.success(true);
  558. }
  559. }