StaffService.java 31 KB

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