StaffService.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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.util.*;
  39. import java.util.stream.Collectors;
  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 intWebMaxnum = Integer.parseInt(mp.get("web_max_num") + "");
  166. int intWxMaxnum = Integer.parseInt(mp.get("wx_max_num") + "");
  167. staffQuery = new StaffQuery();
  168. staffQuery.setFlgCanLogin(true);
  169. staffQuery.setCpId(cpId);
  170. List<StaffResponse> staffResponsesFlgCanLogin = staffMapper.selectByCond(staffQuery);
  171. if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0 ) {
  172. List<StaffResponse> collectPc = staffResponsesFlgCanLogin.stream().filter(it -> it.getLoginType() == 1 || it.getLoginType() == 3).collect(Collectors.toList());
  173. List<StaffResponse> collectWx = staffResponsesFlgCanLogin.stream().filter(it -> it.getLoginType() == 2 || it.getLoginType() == 3).collect(Collectors.toList());
  174. if ((staffVO.getLoginType() == 1 || staffVO.getLoginType() == 3 ) &&
  175. collectPc != null && collectPc.size() > 0 && intWebMaxnum < collectPc.size() + 1) {
  176. // 无用户
  177. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getCode(),
  178. ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getMessage());
  179. }
  180. if ((staffVO.getLoginType() == 2 || staffVO.getLoginType() == 3 ) &&
  181. collectWx != null && collectWx.size() > 0 && intWxMaxnum < collectWx.size() + 1) {
  182. // 无用户
  183. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getCode(),
  184. ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getMessage());
  185. }
  186. }
  187. }
  188. }
  189. // 获取编码和主键UuId
  190. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), false);
  191. staff.setStaffId(codeMap.get("outId").toString());
  192. // staff.setStaffCode(codeMap.get("outNote").toString());
  193. super.insert(staff);
  194. // 讲电话和名称插入微信用户表里
  195. Map<String, Object> collectQuery = new HashMap<>();
  196. collectQuery.put("currentCp", staff.getCpId());
  197. collectQuery.put("userName", staff.getStaffName());
  198. collectQuery.put("userPhone", staff.getStaffPhone());
  199. ResponseResultVO<?> resultVO = userFeign.registerFeign(collectQuery);
  200. Map<String, Object> m = new HashMap<>();
  201. // 如果没有成功返回,状态设置为待审
  202. if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  203. // 无用户
  204. throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  205. ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  206. } else {
  207. m = (Map<String, Object>) resultVO.getData();
  208. }
  209. staff.setWxUserId(m.get("userId").toString());
  210. super.updateByUuid(staff);
  211. return ResponseResultUtil.success(staff);
  212. }
  213. /**
  214. * @desc : 保存方法
  215. * @author : 姜永辉
  216. * @date : 2023/1/9 10:49
  217. */
  218. @Transactional(
  219. rollbackFor = {Exception.class}
  220. )
  221. public ResponseResultVO<?> insertFeignStaff(StaffVO staffVO) {
  222. // 转化实体
  223. Staff staff = staffConvert.convertToPo(staffVO);
  224. // 校验同一个公司的电话不能重复
  225. StaffQuery staffQuery = new StaffQuery();
  226. staffQuery.setCpId(staff.getCpId());
  227. staffQuery.setStaffPhone(staff.getStaffPhone());
  228. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  229. if (staffResponses != null && staffResponses.size() > 0) {
  230. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  231. }
  232. // 获取编码和主键UuId
  233. Map<String, Object> codeMap = commonService.getUniqueNoteCode(
  234. Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true);
  235. staff.setStaffId(codeMap.get("outId").toString());
  236. staff.setStaffCode(codeMap.get("outNote").toString());
  237. staff.setFlgCanLogin(true);
  238. super.insert(staff);
  239. return ResponseResultUtil.success(staff);
  240. }
  241. /**
  242. * @desc : 注册商户时候插入 角色 基础资料(仓库 渠道 收入 支出 入库 出库 账户 来源 盈亏原因) 计量单位 种类 打印票据 等等。
  243. * 返回角色的数据
  244. * @author : 姜永辉
  245. * @date : 2023/1/9 10:49
  246. */
  247. @Transactional(rollbackFor = {Exception.class})
  248. public ResponseResultVO<?> insertFeignCompanyData(Map<String, List<Map<String, Object>>> map) {
  249. // 公司
  250. List<Map<String, Object>> listCom = map.get("company");
  251. // 版本
  252. String gradeCode = listCom.get(0).get("gradeCode").toString();
  253. // 角色
  254. List<Map<String, Object>> listRoles = map.get("roles");
  255. List<Role> listR = new ArrayList<>();
  256. String roleid = "";
  257. Integer cpId = Integer.parseInt(listCom.get(0).get("cpId").toString());
  258. String staffId = listCom.get(0).get("staffId").toString();
  259. // 插入常用功能 标准版 插入 销售出库 库存查询 商品档案
  260. if (Constant.STD.equals(gradeCode)) {
  261. List<String> objectCodeList = new ArrayList<>();
  262. // 销售出库
  263. objectCodeList.add("order-out");
  264. // 库存查询
  265. objectCodeList.add("ivt-detail-report");
  266. // 商品档案
  267. objectCodeList.add("goods");
  268. ComMenuVO comMenuVO = new ComMenuVO();
  269. comMenuVO.setCpId(cpId).setStaffId(staffId).setAppCode(Constant.AppCode.WEIXIN.getCode())
  270. .setObjectCodeList(objectCodeList);
  271. comMenuMapper.saveByCompany(comMenuVO);
  272. // 系统参数
  273. List<SettingValue> settingValueList = new ArrayList<>();
  274. // 自动办理
  275. settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_001.getValue())
  276. .setSettingValue("false"));
  277. // 欠货销售
  278. settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_002.getValue())
  279. .setSettingValue("false"));
  280. settingValueMapper.insertBatch(settingValueList);
  281. }
  282. for (int i = 0; i < listRoles.size(); i++) {
  283. Map<String, Object> m = listRoles.get(i);
  284. Role role = new Role();
  285. //设置编码
  286. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.ROLE.getName(), cpId, false);
  287. if (Constant.ROLE_DATA.equals(m.get("roleCode").toString())) {
  288. roleid = uniqueNoteCode.get("outId").toString();
  289. }
  290. role.setRoleId(uniqueNoteCode.get("outId").toString());
  291. role.setRoleCode(m.get("roleCode").toString());
  292. role.setRoleName(m.get("roleName").toString());
  293. role.setDisplayNo((Integer) m.get("displayNo"));
  294. role.setCpId(cpId);
  295. role.setOpCreateUserId(staffId);
  296. listR.add(role);
  297. }
  298. roleMapper.insertBatch(listR);
  299. // 更新用户的角色ids-
  300. List<String> roleids = new ArrayList<>();
  301. roleids.add(roleid);
  302. this.updateByUuid(new Staff().setStaffId(staffId).setRoleIds(roleids));
  303. // 角色权限
  304. RoleFun roleFun = new RoleFun();
  305. roleFun.setRoleId(roleid);
  306. roleFun.setCpId(cpId);
  307. roleFun.setOpCreateUserId(staffId);
  308. roleFunMapper.insertRoleFunFeign(roleFun);
  309. // 仓库
  310. List<Map<String, Object>> listWarehouses = map.get("warehouses");
  311. List<Warehouse> listW = new ArrayList<>();
  312. if (listWarehouses != null && listWarehouses.size() > 0) {
  313. for (int i = 0; i < listWarehouses.size(); i++) {
  314. Map<String, Object> m = listWarehouses.get(i);
  315. Warehouse warehouse = new Warehouse();
  316. warehouse.setWhCode(m.get("whCode").toString());
  317. warehouse.setWhName(m.get("whName").toString());
  318. warehouse.setDisplayNo((Integer) m.get("displayNo"));
  319. warehouse.setFlgDefault((Boolean) m.get("flgDefault"));
  320. warehouse.setCpId(cpId);
  321. warehouse.setOpCreateUserId(staffId);
  322. listW.add(warehouse);
  323. }
  324. warehouseMapper.insertBatch(listW);
  325. }
  326. // 渠道
  327. List<Map<String, Object>> listSaleChannels = map.get("saleChannels");
  328. List<SaleChannel> listSc = new ArrayList<>();
  329. if (listSaleChannels != null && listSaleChannels.size() > 0) {
  330. for (int i = 0; i < listSaleChannels.size(); i++) {
  331. Map<String, Object> m = listSaleChannels.get(i);
  332. SaleChannel saleChannel = new SaleChannel();
  333. saleChannel.setChannelCode(m.get("channelCode").toString());
  334. saleChannel.setChannelName(m.get("channelName").toString());
  335. saleChannel.setDisplayNo((Integer) m.get("displayNo"));
  336. saleChannel.setFlgDefault((Boolean) m.get("flgDefault"));
  337. saleChannel.setCpId(cpId);
  338. saleChannel.setOpCreateUserId(staffId);
  339. listSc.add(saleChannel);
  340. }
  341. saleChannelMapper.insertBatch(listSc);
  342. }
  343. // 基础资料
  344. List<Map<String, Object>> listDictionaryDatas = map.get("dictionaryDatas");
  345. List<DictionaryData> listDD = new ArrayList<>();
  346. if (listDictionaryDatas != null && listDictionaryDatas.size() > 0) {
  347. for (int i = 0; i < listDictionaryDatas.size(); i++) {
  348. Map<String, Object> m = listDictionaryDatas.get(i);
  349. DictionaryData dictionaryData = new DictionaryData();
  350. dictionaryData.setDictCode(m.get("dictCode").toString());
  351. dictionaryData.setDataCode(m.get("dataCode").toString());
  352. dictionaryData.setDataValue(m.get("dataValue").toString());
  353. dictionaryData.setDisplayNo((Integer) m.get("displayNo"));
  354. dictionaryData.setFlgDefault((Boolean) m.get("flgDefault"));
  355. dictionaryData.setCpId(cpId);
  356. dictionaryData.setOpCreateUserId(staffId);
  357. listDD.add(dictionaryData);
  358. }
  359. dictionaryDataMapper.insertBatch(listDD);
  360. }
  361. // 资金账户
  362. List<Map<String, Object>> listMoneyAccounts = map.get("moneyAccounts");
  363. List<MoneyAccount> listMa = new ArrayList<>();
  364. if (listMoneyAccounts != null && listMoneyAccounts.size() > 0) {
  365. for (int i = 0; i < listMoneyAccounts.size(); i++) {
  366. Map<String, Object> m = listMoneyAccounts.get(i);
  367. MoneyAccount moneyAccount = new MoneyAccount();
  368. moneyAccount.setMacCode(m.get("macCode").toString());
  369. moneyAccount.setMacName(m.get("macName").toString());
  370. moneyAccount.setMacType(m.get("macType").toString());
  371. moneyAccount.setBalance((BigDecimal) m.get("balance"));
  372. moneyAccount.setFlgDefault((Boolean) m.get("flgDefault"));
  373. moneyAccount.setDisplayNo((Integer) m.get("displayNo"));
  374. moneyAccount.setCpId(cpId);
  375. listMa.add(moneyAccount);
  376. }
  377. moneyAccountMapper.insertBatch(listMa);
  378. }
  379. // 计量单位
  380. List<Map<String, Object>> listUnits = map.get("units");
  381. List<Unit> listU = new ArrayList<>();
  382. if (listUnits != null && listUnits.size() > 0) {
  383. for (int i = 0; i < listUnits.size(); i++) {
  384. Map<String, Object> m = listUnits.get(i);
  385. Unit unit = new Unit();
  386. unit.setUnitCode(m.get("unitCode").toString());
  387. unit.setUnitName(m.get("unitName").toString());
  388. unit.setDecimalPlaces((Integer) m.get("decimalPlaces"));
  389. unit.setDisplayNo((Integer) m.get("displayNo"));
  390. unit.setCpId(cpId);
  391. unit.setOpCreateUserId(staffId);
  392. listU.add(unit);
  393. }
  394. unitMapper.insertBatch(listU);
  395. }
  396. // 种类
  397. List<Map<String, Object>> listGoodsCategorys = map.get("goodsCategorys");
  398. List<GoodsCategory> listG = new ArrayList<>();
  399. if (listGoodsCategorys != null && listGoodsCategorys.size() > 0) {
  400. for (int i = 0; i < listGoodsCategorys.size(); i++) {
  401. Map<String, Object> m = listGoodsCategorys.get(i);
  402. GoodsCategory goodsCategory = new GoodsCategory();
  403. goodsCategory.setCatCode(m.get("catCode") + "");
  404. goodsCategory.setCatName(m.get("catName") + "");
  405. if (m.get("parentId") != null) {
  406. goodsCategory.setParentId(m.get("parentId") + "");
  407. }
  408. if (m.get("topId") != null) {
  409. goodsCategory.setTopId(m.get("topId") + "");
  410. }
  411. if (m.get("levelUpper") != null) {
  412. goodsCategory.setLevelUpper(m.get("levelUpper") + "");
  413. }
  414. if (m.get("levelLower") != null) {
  415. goodsCategory.setLevelLower(m.get("levelLower") + "");
  416. }
  417. goodsCategory.setLevelLeaf((Boolean) m.get("levelLeaf"));
  418. goodsCategory.setLevelNo((Integer) m.get("levelNo"));
  419. goodsCategory.setLevelCode(m.get("levelCode") + "");
  420. goodsCategory.setLevelName(m.get("levelName") + "");
  421. goodsCategory.setDisplayNo((Integer) m.get("displayNo"));
  422. goodsCategory.setCpId(cpId);
  423. goodsCategory.setOpCreateUserId(staffId);
  424. listG.add(goodsCategory);
  425. }
  426. goodsCategoryMapper.insertBatch(listG);
  427. }
  428. // 打印票据
  429. List<Map<String, Object>> listPrintLayout = map.get("printLayout");
  430. List<PrintLayout> listP = new ArrayList<>();
  431. if (listPrintLayout != null && listPrintLayout.size() > 0) {
  432. for (int i = 0; i < listPrintLayout.size(); i++) {
  433. Map<String, Object> m = listPrintLayout.get(i);
  434. PrintLayout printLayout = new PrintLayout();
  435. printLayout.setLayoutName(m.get("layoutName") + "");
  436. printLayout.setLayoutData(JSONObject.parseObject(JSONObject.toJSONString(m.get("layoutData"))));
  437. printLayout.setDisplayNo((Integer) m.get("displayNo"));
  438. printLayout.setDocName(m.get("docName") + "");
  439. printLayout.setCpId(cpId);
  440. printLayout.setOpCreateUserId(staffId);
  441. listP.add(printLayout);
  442. }
  443. printLayoutMapper.insertBatch(listP);
  444. }
  445. return ResponseResultUtil.success();
  446. }
  447. /**
  448. * @desc : 保存方法-邀请员工的确定
  449. * @author : 姜永辉
  450. * @date : 2023/1/9 10:49
  451. */
  452. @Transactional(rollbackFor = {Exception.class})
  453. public ResponseResultVO<?> insertRequestStaff(StaffVO staffVO) {
  454. // 转化实体
  455. Staff staff = staffConvert.convertToPo(staffVO);
  456. // 校验同一个公司的电话不能重复
  457. StaffQuery staffQuery = new StaffQuery();
  458. staffQuery.setCpId(staff.getCpId());
  459. staffQuery.setStaffPhone(staff.getStaffPhone());
  460. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  461. if (staffResponses != null && staffResponses.size() > 0) {
  462. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  463. }
  464. // 获取编码和主键UuId
  465. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), true);
  466. staff.setStaffId(codeMap.get("outId").toString());
  467. staff.setStaffCode(codeMap.get("outNote").toString());
  468. // 更新 被邀人员的cpid
  469. if (staff.getWxUserId() != null) {
  470. // 更新 被邀请人员的微信用户的cpid 加入公司
  471. Map<String, Object> collectQuery = new HashMap<>();
  472. collectQuery.put("cpId", staff.getCpId());
  473. collectQuery.put("userId", staff.getWxUserId());
  474. companyFeign.updateWxUserCompany(collectQuery);
  475. }
  476. // 插入员工
  477. super.insert(staff);
  478. return ResponseResultUtil.success(staff);
  479. }
  480. /**
  481. * @desc : 编辑方法
  482. * @author : 姜永辉
  483. * @date : 2023/1/9 10:49
  484. */
  485. @Transactional(
  486. rollbackFor = {Exception.class}
  487. )
  488. public ResponseResultVO<Boolean> update(StaffVO staffVO) {
  489. // 转化实体
  490. Staff staff = staffConvert.convertToPo(staffVO);
  491. // 查询原来的getFlgCanLogin
  492. StaffResponse staffResponseOld = staffMapper.selectById(staffVO.getStaffId());
  493. super.updateByUuid(staff);
  494. // 获取当前公司的cpId
  495. Integer cpId = authUtils.getStaff().getCpId();
  496. //可以绑定微信的员工人数 人数上限
  497. if (staffVO.getFlgCanLogin()) {
  498. ResponseResultVO<?> resultMaxnum = companyFeign.getCompanyMaxStaffNum(cpId);
  499. if (resultMaxnum.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  500. // 无用户
  501. throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  502. ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  503. } else {
  504. if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
  505. Map<String, Object> mp = (Map<String, Object>) resultMaxnum.getData();
  506. int intWebMaxnum = Integer.parseInt(mp.get("web_max_num") + "");
  507. int intWxMaxnum = Integer.parseInt(mp.get("wx_max_num") + "");
  508. StaffQuery staffQuery = new StaffQuery();
  509. staffQuery.setFlgCanLogin(true);
  510. staffQuery.setCpId(cpId);
  511. List<StaffResponse> staffResponsesFlgCanLogin = staffMapper.selectByCond(staffQuery);
  512. if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0 ) {
  513. List<StaffResponse> collectPc = staffResponsesFlgCanLogin.stream().filter(it -> it.getLoginType() == 1 || it.getLoginType() == 3).collect(Collectors.toList());
  514. List<StaffResponse> collectWx = staffResponsesFlgCanLogin.stream().filter(it -> it.getLoginType() == 2 || it.getLoginType() == 3).collect(Collectors.toList());
  515. if (collectPc != null && collectPc.size() > 0 && intWebMaxnum < collectPc.size()) {
  516. // 无用户
  517. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getCode(),
  518. ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getMessage());
  519. }
  520. if (collectWx != null && collectWx.size() > 0 && intWxMaxnum < collectWx.size()) {
  521. // 无用户
  522. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getCode(),
  523. ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getMessage());
  524. }
  525. }
  526. }
  527. // if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0 && intMaxnum < staffResponsesFlgCanLogin.size()) {
  528. // // 无用户
  529. // throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_STAFF_ERROR.getCode(),
  530. // ErrorCodeEnum.USER_MAX_STAFF_ERROR.getMessage());
  531. // }
  532. }
  533. // if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
  534. // // 增加一个可以cur_staff_num
  535. // Map<String, Object> m = new HashMap<>();
  536. // m.put("curStaffNum", 1);
  537. // m.put("cpId", cpId);
  538. // ResponseResultVO<Boolean> booleanResponseResultVO = companyFeign.updateCompanyCurStaffNum(m);
  539. // if (booleanResponseResultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  540. // // 无用户
  541. // throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  542. // ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  543. // }
  544. // }
  545. } else {
  546. // 2024-05-20 edit
  547. // if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
  548. // // 减少一个可以cur_staff_num
  549. // Map<String, Object> m = new HashMap<>();
  550. // m.put("curStaffNum", -1);
  551. // m.put("cpId", cpId);
  552. // ResponseResultVO<Boolean> booleanResponseResultVO = companyFeign.updateCompanyCurStaffNum(m);
  553. // if (booleanResponseResultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  554. // // 无用户
  555. // throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  556. // ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  557. // }
  558. // }
  559. }
  560. return ResponseResultUtil.success();
  561. }
  562. /**
  563. * @desc : 保存权限方法
  564. * @author : 姜永辉
  565. * @date : 2023/1/9 10:49
  566. */
  567. @Transactional(
  568. rollbackFor = {Exception.class}
  569. )
  570. public ResponseResultVO<?> saveStaffRight(StaffVO staffVO) {
  571. // 获取当前公司的cpId
  572. Integer cpId = authUtils.getStaff().getCpId();
  573. // 转化实体
  574. Staff staff = staffConvert.convertToPo(staffVO);
  575. staffRightService.delete(staffVO.getStaffId());
  576. for (StaffRight staffRight : staffVO.getStaffRightList()) {
  577. staffRight.setStaffId(staff.getStaffId());
  578. staffRight.setRightType(1);
  579. staffRight.setCpId(cpId);
  580. }
  581. if (staffVO.getStaffRightList() != null && staffVO.getStaffRightList().size() > 0) {
  582. staffRightService.saveStaffRight(staffVO.getStaffRightList());
  583. }
  584. return ResponseResultUtil.success();
  585. }
  586. /**
  587. * @desc : 保存权限方法
  588. * @author : 姜永辉
  589. * @date : 2023/1/9 10:49
  590. */
  591. @Transactional(
  592. rollbackFor = {Exception.class}
  593. )
  594. public ResponseResultVO<?> saveStaffPurview(StaffVO staffVO) {
  595. // 获取当前公司的cpId
  596. Integer cpId = authUtils.getStaff().getCpId();
  597. // 转化实体
  598. Staff staff = staffConvert.convertToPo(staffVO);
  599. for (StaffPurview staffRight : staffVO.getStaffPurviewList()) {
  600. staffRight.setStaffId(staff.getStaffId());
  601. staffRight.setCpId(cpId);
  602. }
  603. staffPurviewService.saveStaffPurview(staffVO.getStaffPurviewList());
  604. return ResponseResultUtil.success();
  605. }
  606. /**
  607. * @desc : 员工离职
  608. * @author : 姜永辉
  609. * @date : 2023/2/13 13:45
  610. */
  611. @Transactional(
  612. rollbackFor = {Exception.class}
  613. )
  614. public ResponseResultVO<Boolean> dimission(StaffVO staffVO) {
  615. // 将微信的用户的信息 openid current_cp , "joined_cps" 缩减相应的cpid
  616. // 更新 被邀请人员的微信用户的cpid 加入公司
  617. Map<String, Object> collectQuery = new HashMap<>();
  618. // 获取当前公司的cpId
  619. Integer cpId = authUtils.getStaff().getCpId();
  620. collectQuery.put("cpId", cpId);
  621. collectQuery.put("userId", staffVO.getWxUserId());
  622. ResponseResultVO<?> resultVO = userFeign.updateClearOpenidFeign(collectQuery);
  623. // 如果没有成功返回,状态设置为待审
  624. if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  625. // 无用户
  626. throw new BaseBusinessException(ErrorCodeEnum.STAFF_UPDATE_ERROR.getCode(),
  627. ErrorCodeEnum.STAFF_UPDATE_ERROR.getMessage());
  628. }
  629. // 转化实体
  630. Staff staff = staffConvert.convertToPo(staffVO);
  631. super.updateByUuid(staff);
  632. return ResponseResultUtil.success();
  633. }
  634. /**
  635. * @desc : 导入员工
  636. * @author : 姜永辉
  637. * @date : 2023/3/1 14:40
  638. */
  639. @Transactional(
  640. rollbackFor = {Exception.class}
  641. )
  642. public ResponseResultVO<Boolean> importStaffList(List<StaffVO> list) {
  643. if (CollectionUtils.isEmpty(list) || list.size() == 0) {
  644. return ResponseResultUtil.error(ResponseCodeEnum.INSERT_FAIL);
  645. }
  646. return ResponseResultUtil.success();
  647. }
  648. /**
  649. * @desc : 登录后获取信息
  650. * @author : 周兴
  651. * @date : 2024/3/4 11:41
  652. */
  653. @Transactional(
  654. rollbackFor = {Exception.class}
  655. )
  656. public ResponseResultVO<Dictionary<String, Object>> getInfoAfterLogin(Map<String, Object> param) {
  657. // 先根据userId查询当前企业的员工信息
  658. StaffResponse staff = staffMapper.selectByUserId(param.get("userId").toString(), Integer.parseInt(param.get("cpId").toString()));
  659. if (staff != null) {
  660. // 提示不允许登录
  661. if (staff.getFlgCanLogin() == null || !staff.getFlgCanLogin()) {
  662. return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CAN_NOT_LOGIN.getMessage());
  663. }
  664. // 离职状态不允许登录
  665. if (staff.getHrStatus() != 1) {
  666. return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_OUT_NOT_LOGIN.getMessage());
  667. }
  668. // 存Redis
  669. authUtils.saveStaff(new StaffEntity().setStaffId(staff.getStaffId())
  670. .setWxUserId(staff.getWxUserId())
  671. .setStaffCode(staff.getStaffCode())
  672. .setStaffName(staff.getStaffName())
  673. .setCpId(Integer.parseInt(param.get("cpId").toString()))
  674. .setAppCode(param.get("appCode").toString()));
  675. // 更新员工登录状态
  676. this.updateByUuid(new Staff().setStaffId(staff.getStaffId()).setFlgCanLogin(true));
  677. } else {
  678. return ResponseResultUtil.error(ErrorCodeEnum.STAFF_NOT_EXIST.getCode(), ErrorCodeEnum.STAFF_NOT_EXIST.getMessage());
  679. }
  680. // 获取菜单
  681. List menuList = commonMapper.getMenuByUser(param);
  682. // 获取常用菜单
  683. ResponseResultVO<?> comMenuList = comMenuService.selectMenu(new ComMenuQuery().setStaffId(staff.getStaffId())
  684. .setAppCode(param.get("appCode").toString()));
  685. // 获取所有参数
  686. Map<String, Object> allSettingValue = commonMapper.getAllSettingValue();
  687. Dictionary<String, Object> dic = new Hashtable<>();
  688. dic.put("menuList", menuList);
  689. dic.put("comMenuList", comMenuList.getData());
  690. dic.put("dataKindList", commonMapper.getDataKind(param));
  691. dic.put("settingValue", allSettingValue);
  692. dic.put("staff", staff);
  693. return ResponseResultUtil.success(dic);
  694. }
  695. /**
  696. * @desc : 退出登录
  697. * @author : 周兴
  698. * @date : 2024-03-18 09:03
  699. */
  700. @Transactional(
  701. rollbackFor = {Exception.class}
  702. )
  703. public ResponseResultVO<Boolean> logout(Map<String, Object> param) {
  704. // 更新员工登录状态
  705. // this.updateByUuid(new Staff().setStaffId(param.get("staffId").toString()).setFlgCanLogin(false));
  706. return ResponseResultUtil.success(true);
  707. }
  708. }