StaffService.java 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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.ivt.InboundItemQuery;
  26. import com.dk.mdm.model.query.mst.ComMenuQuery;
  27. import com.dk.mdm.model.query.mst.DictionaryDataQuery;
  28. import com.dk.mdm.model.query.mst.GoodsCategoryQuery;
  29. import com.dk.mdm.model.query.mst.StaffQuery;
  30. import com.dk.common.model.response.mst.StaffResponse;
  31. import com.dk.common.model.vo.mst.StaffVO;
  32. import com.dk.mdm.model.response.mst.ComMenuResponse;
  33. import com.dk.mdm.model.response.mst.DictionaryDataResponse;
  34. import com.dk.mdm.model.vo.mst.ComMenuVO;
  35. import com.dk.mdm.service.common.CommonService;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.springframework.stereotype.Service;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.transaction.annotation.Transactional;
  40. import org.springframework.util.CollectionUtils;
  41. import javax.annotation.Resource;
  42. import java.math.BigDecimal;
  43. import java.time.LocalDate;
  44. import java.util.*;
  45. import java.util.stream.Collectors;
  46. import java.util.stream.Stream;
  47. /**
  48. * @author : 姜永辉
  49. * @desc : 员工API接口
  50. * @date : 2023/1/4 9:25
  51. */
  52. @Service
  53. @Slf4j
  54. public class StaffService extends BaseService<Staff> {
  55. @Resource
  56. private CompanyFeign companyFeign;
  57. @Resource
  58. private UserFeign userFeign;
  59. @Override
  60. public BaseMapper<Staff> getRepository() {
  61. return staffMapper;
  62. }
  63. /**
  64. * @desc : 重写主键
  65. * @author : 姜永辉
  66. * @date : 2023/1/9 10:39
  67. */
  68. @Override
  69. public String getPrimaryKey() {
  70. return "staff_id";
  71. }
  72. @Autowired
  73. private StaffMapper staffMapper;
  74. @Autowired
  75. private StaffConvert staffConvert;
  76. @Autowired
  77. private StaffRightService staffRightService;
  78. @Autowired
  79. private StaffPurviewService staffPurviewService;
  80. @Autowired
  81. private CommonService commonService;
  82. @Autowired
  83. private CommonMapper commonMapper;
  84. @Autowired
  85. private ComMenuService comMenuService;
  86. @Autowired
  87. private ComMenuMapper comMenuMapper;
  88. @Autowired
  89. private SettingValueMapper settingValueMapper;
  90. @Autowired
  91. private AuthUtils authUtils;
  92. @Autowired
  93. DictionaryDataMapper dictionaryDataMapper;
  94. @Autowired
  95. GoodsCategoryMapper goodsCategoryMapper;
  96. @Autowired
  97. RoleMapper roleMapper;
  98. @Autowired
  99. RoleFunMapper roleFunMapper;
  100. @Autowired
  101. UnitMapper unitMapper;
  102. @Autowired
  103. SaleChannelMapper saleChannelMapper;
  104. @Autowired
  105. WarehouseMapper warehouseMapper;
  106. @Autowired
  107. MoneyAccountMapper moneyAccountMapper;
  108. @Autowired
  109. PrintLayoutMapper printLayoutMapper;
  110. /**
  111. * @desc : 条件查询
  112. * @author : 姜永辉
  113. * @date : 2023/1/9 10:40
  114. */
  115. @Pagination
  116. public ResponseResultVO<PageList<StaffResponse>> selectByCond(StaffQuery staffQuery) {
  117. // 获取当前公司的cpId
  118. if (staffQuery.getCpId() == null) {
  119. Integer cpId = authUtils.getStaff().getCpId();
  120. staffQuery.setCpId(cpId);
  121. }
  122. // Map<String, Object> map = new HashMap<>();
  123. // map.put("grade_code", "STD");
  124. // map.put("end_date", "2099-12-31");
  125. //// map.put("user_end_date", "2025-04-01");
  126. // map.put("wx_max_num", 20);
  127. //// map.put("web_max_num", 20);
  128. // List<Map<String,Object>> mapList = new ArrayList<>();
  129. // Map<String,Object> map1 = new HashMap<>();
  130. // List<String> funList = new ArrayList<>();
  131. // funList.add("45adf0c1-cb1d-4baa-8cd0-9cefe5649687");
  132. // funList.add("af9fe752-9431-4301-907a-ebee6f1d01bd");
  133. // funList.add("a577397a-78b9-475d-b44a-92294a4ac5a7");
  134. // funList.add("0b95fe60-add2-4177-9cab-6bd936aac090");
  135. // funList.add("5f415229-e64c-4e88-b9c4-72a661b56d64");
  136. // funList.add("3644ebc5-fde2-44fc-bba8-9adc91ccb483");
  137. // funList.add("f2f912f4-dad3-42ca-9835-184de6ecf27b");
  138. // map1.put("activityId","10002024-0701-0000-0000-0000052aaec4");
  139. // map1.put("funUuids",funList);
  140. // mapList.add(map1);
  141. // Map<String,Object> map2 = new HashMap<>();
  142. // List<String> funList2 = new ArrayList<>();
  143. // funList2.add("851e952a-27c6-42d2-91ad-097e266f63ea");
  144. // map2.put("activityId","10002024-0701-0000-0000-0000052aaec3");
  145. // map2.put("funUuids",funList2);
  146. // mapList.add(map2);
  147. // Map<String,Object> map3 = new HashMap<>();
  148. // List<String> funList3 = new ArrayList<>();
  149. // funList3.add("3e43dc4c-0e98-49ca-8ca4-2fe47f286e1d");
  150. // funList3.add("1b3ce29f-f7d6-40c0-9ca5-754ff8e85db6");
  151. // funList3.add("67df7456-3deb-41de-a6db-f916eae66089");
  152. // map3.put("activityId","10002024-0701-0000-0000-0000052aaec3");
  153. // map3.put("funUuids",funList3);
  154. // mapList.add(map3);
  155. // map.put("fun_package",mapList);
  156. // String s1 = JSON.toJSONString(map);
  157. // // 加密
  158. // String s = AESUtil.aesEncrypt(s1);
  159. // // 解密
  160. // Map<String,Object> ss = JSON.parseObject(AESUtil.desEncrypt(s),Map.class) ;
  161. return super.mergeListWithCount(staffQuery, staffMapper.selectByCond(staffQuery),
  162. staffMapper.countByCond(staffQuery));
  163. }
  164. /**
  165. * @desc : 保存方法
  166. * @author : 姜永辉
  167. * @date : 2023/1/9 10:49
  168. */
  169. @Transactional(
  170. rollbackFor = {Exception.class}
  171. )
  172. public ResponseResultVO<?> insert(StaffVO staffVO) {
  173. // 转化实体
  174. Staff staff = staffConvert.convertToPo(staffVO);
  175. // 获取当前公司的cpId
  176. StaffEntity staffEntity = authUtils.getStaff();
  177. Integer cpId = staffEntity.getCpId();
  178. // 校验同一个公司的电话不能重复
  179. StaffQuery staffQuery = new StaffQuery();
  180. staffQuery.setStaffPhone(staff.getStaffPhone());
  181. staffQuery.setCpId(cpId);
  182. staffQuery.setFlgValid(true);
  183. staff.setCpId(cpId);
  184. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  185. if (staffResponses != null && staffResponses.size() > 0) {
  186. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  187. }
  188. staffQuery.setStaffPhone(null);
  189. staffQuery.setStaffCode(staff.getStaffCode());
  190. staffResponses = staffMapper.selectByCondByCode(staffQuery);
  191. if (staffResponses != null && staffResponses.size() > 0) {
  192. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_CODE_EXIST);
  193. }
  194. //可以绑定微信的员工人数 人数上限
  195. if (staffVO.getFlgCanLogin() != null && staffVO.getFlgCanLogin()) {
  196. ResponseResultVO<?> resultMaxnum = companyFeign.getCompanyMaxStaffNum(cpId);
  197. if (resultMaxnum.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  198. // 无用户
  199. throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  200. ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  201. } else {
  202. Map<String, Object> mp = (Map<String, Object>) resultMaxnum.getData();
  203. int intWebMaxnum = 0;
  204. if (mp.get("web_max_num") != null) {
  205. intWebMaxnum = Integer.parseInt(mp.get("web_max_num") + "");
  206. }
  207. int intWxMaxnum = 0;
  208. if (mp.get("wx_max_num") != null) {
  209. intWxMaxnum = Integer.parseInt(mp.get("wx_max_num") + "");
  210. }
  211. staffQuery = new StaffQuery();
  212. staffQuery.setFlgCanLogin(true);
  213. staffQuery.setFlgValid(true);
  214. staffQuery.setCpId(cpId);
  215. List<StaffResponse> staffResponsesFlgCanLogin = staffMapper.selectByCond(staffQuery);
  216. if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0) {
  217. List<StaffResponse> collectPc = staffResponsesFlgCanLogin.stream().filter(it -> (it.getLoginType() != null && it.getLoginType() == 1) || (it.getLoginType() != null && it.getLoginType() == 3)).collect(Collectors.toList());
  218. List<StaffResponse> collectWx = staffResponsesFlgCanLogin.stream().filter(it -> (it.getLoginType() != null && it.getLoginType() == 2) || (it.getLoginType() != null && it.getLoginType() == 3)).collect(Collectors.toList());
  219. if ((staffVO.getLoginType() == 1 || staffVO.getLoginType() == 3) &&
  220. collectPc != null && collectPc.size() > 0 && intWebMaxnum < collectPc.size() + 1) {
  221. // 无用户
  222. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getCode(),
  223. ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getMessage());
  224. }
  225. if ((staffVO.getLoginType() == 2 || staffVO.getLoginType() == 3) &&
  226. collectWx != null && collectWx.size() > 0 && intWxMaxnum < collectWx.size() + 1) {
  227. // 无用户
  228. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getCode(),
  229. ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getMessage());
  230. }
  231. }
  232. }
  233. }
  234. // 获取编码和主键UuId
  235. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), false);
  236. staff.setStaffId(codeMap.get("outId").toString());
  237. // staff.setStaffCode(codeMap.get("outNote").toString());
  238. super.insert(staff);
  239. // 常用菜单的插入
  240. if (staffVO.getFlgCanLogin() != null && staffVO.getFlgCanLogin()) {
  241. ResponseResultVO<?> comMenuRes = companyFeign.getComMenu(staffEntity.getGradeCode());
  242. if (comMenuRes.getCode() == ResponseCodeEnum.SUCCESS.getCode()) {
  243. List<Map<String, Object>> comMenuMapList = (List<Map<String, Object>>) comMenuRes.getData();
  244. List<ComMenu> listCom = new ArrayList<>();
  245. if (comMenuMapList != null && comMenuMapList.size() > 0) {
  246. for (int i = 0; i < comMenuMapList.size(); i++) {
  247. Map<String, Object> m = comMenuMapList.get(i);
  248. ComMenu comMenu = new ComMenu();
  249. comMenu.setMenuUuid(m.get("menuUuid").toString());
  250. comMenu.setStaffId(staff.getStaffId());
  251. comMenu.setAppCode(m.get("appCode").toString());
  252. comMenu.setDisplayNo((Integer) m.get("displayNo"));
  253. comMenu.setCpId(cpId);
  254. listCom.add(comMenu);
  255. }
  256. comMenuMapper.insertBatch(listCom);
  257. }
  258. }
  259. }
  260. // 讲电话和名称插入微信用户表里
  261. Map<String, Object> collectQuery = new HashMap<>();
  262. collectQuery.put("currentCp", staff.getCpId());
  263. collectQuery.put("userName", staff.getStaffName());
  264. collectQuery.put("userPhone", staff.getStaffPhone());
  265. ResponseResultVO<?> resultVO = userFeign.registerFeign(collectQuery);
  266. Map<String, Object> m = new HashMap<>();
  267. // 如果没有成功返回,状态设置为待审
  268. if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  269. // 无用户
  270. throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  271. ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  272. } else {
  273. m = (Map<String, Object>) resultVO.getData();
  274. }
  275. staff.setWxUserId(m.get("userId").toString());
  276. super.updateByUuid(staff);
  277. return ResponseResultUtil.success(staff);
  278. }
  279. /**
  280. * @desc : 保存方法
  281. * @author : 姜永辉
  282. * @date : 2023/1/9 10:49
  283. */
  284. @Transactional(
  285. rollbackFor = {Exception.class}
  286. )
  287. public ResponseResultVO<?> insertFeignStaff(StaffVO staffVO) {
  288. // 转化实体
  289. Staff staff = staffConvert.convertToPo(staffVO);
  290. // 校验同一个公司的电话不能重复
  291. StaffQuery staffQuery = new StaffQuery();
  292. staffQuery.setCpId(staff.getCpId());
  293. staffQuery.setStaffPhone(staff.getStaffPhone());
  294. staffQuery.setFlgValid(true);
  295. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  296. if (staffResponses != null && staffResponses.size() > 0) {
  297. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  298. }
  299. // 获取编码和主键UuId
  300. Map<String, Object> codeMap = commonService.getUniqueNoteCode(
  301. Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true);
  302. staff.setStaffId(codeMap.get("outId").toString());
  303. staff.setStaffCode(codeMap.get("outNote").toString());
  304. staff.setFlgCanLogin(true);
  305. // 标准版
  306. if (Constant.GradeCode.STD.getName().equals(staffVO.getGradeCode())) {
  307. staff.setLoginType(2);
  308. } else {
  309. staff.setLoginType(3);
  310. }
  311. // 初始标识
  312. staff.setFlgInit(true);
  313. super.insert(staff);
  314. return ResponseResultUtil.success(staff);
  315. }
  316. /**
  317. * @desc : 注册商户时候插入 角色 基础资料(仓库 渠道 收入 支出 入库 出库 账户 来源 盈亏原因) 计量单位 种类 打印票据 等等。
  318. * 返回角色的数据
  319. * @author : 姜永辉
  320. * @date : 2023/1/9 10:49
  321. */
  322. @Transactional(rollbackFor = {Exception.class})
  323. public ResponseResultVO<?> insertFeignCompanyData(Map<String, List<Map<String, Object>>> map) {
  324. // 公司
  325. List<Map<String, Object>> listCom = map.get("company");
  326. // 版本
  327. String gradeCode = listCom.get(0).get("gradeCode").toString();
  328. // 角色
  329. List<Map<String, Object>> listRoles = map.get("roles");
  330. List<Role> listR = new ArrayList<>();
  331. String roleid = "";
  332. Integer cpId = Integer.parseInt(listCom.get(0).get("cpId").toString());
  333. String staffId = listCom.get(0).get("staffId").toString();
  334. List<Map<String, Object>> listComMenu = map.get("listComMenu");
  335. List<ComMenu> listC = new ArrayList<>();
  336. if (listComMenu != null && listComMenu.size() > 0) {
  337. for (int i = 0; i < listComMenu.size(); i++) {
  338. Map<String, Object> m = listComMenu.get(i);
  339. ComMenu comMenu = new ComMenu();
  340. comMenu.setMenuUuid(m.get("menuUuid").toString());
  341. comMenu.setAppCode(m.get("appCode").toString());
  342. comMenu.setDisplayNo((Integer) m.get("displayNo"));
  343. comMenu.setCpId(cpId);
  344. comMenu.setStaffId(staffId);
  345. listC.add(comMenu);
  346. }
  347. comMenuMapper.insertBatch(listC);
  348. }
  349. // 插入常用功能 标准版 插入 销售出库 库存查询 商品档案
  350. if (Constant.STD.equals(gradeCode)) {
  351. // List<String> objectCodeList = new ArrayList<>();
  352. // // 商品属性
  353. // objectCodeList.add("goods-attr");
  354. // // 商品档案
  355. // objectCodeList.add("goods");
  356. // // 销售订单
  357. // objectCodeList.add("order");
  358. // // 销售出库
  359. // objectCodeList.add("order-out");
  360. // // 库存查询
  361. // objectCodeList.add("ivt-detail-report");
  362. //
  363. // ComMenuVO comMenuVO = new ComMenuVO();
  364. // comMenuVO.setCpId(cpId).setStaffId(staffId).setAppCode(Constant.AppCode.WEIXIN.getCode())
  365. // .setObjectCodeList(objectCodeList);
  366. // comMenuMapper.saveByCompany(comMenuVO);
  367. // 系统参数
  368. List<SettingValue> settingValueList = new ArrayList<>();
  369. // 自动办理
  370. settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_001.getValue())
  371. .setSettingValue("true"));
  372. // 欠货销售
  373. settingValueList.add(new SettingValue().setCpId(cpId).setSettingCode(Constant.SystemConstant.IVT_002.getValue())
  374. .setSettingValue("false"));
  375. settingValueMapper.insertBatch(settingValueList);
  376. }
  377. for (int i = 0; i < listRoles.size(); i++) {
  378. Map<String, Object> m = listRoles.get(i);
  379. Role role = new Role();
  380. //设置编码
  381. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.ROLE.getName(), cpId, false);
  382. if (Constant.ROLE_DATA.equals(m.get("roleCode").toString())) {
  383. roleid = uniqueNoteCode.get("outId").toString();
  384. }
  385. role.setRoleId(uniqueNoteCode.get("outId").toString());
  386. role.setRoleCode(m.get("roleCode").toString());
  387. role.setRoleName(m.get("roleName").toString());
  388. role.setDisplayNo((Integer) m.get("displayNo"));
  389. role.setCpId(cpId);
  390. role.setOpCreateUserId(staffId);
  391. // 标准版 不限制权限
  392. if (Constant.STD.equals(gradeCode)) {
  393. role.setFlgNolimitFun(true);
  394. role.setFlgNolimitPvw(true);
  395. role.setFlgNolimitSen(true);
  396. } else {
  397. role.setFlgNolimitFun(false);
  398. role.setFlgNolimitPvw(false);
  399. role.setFlgNolimitSen(false);
  400. }
  401. listR.add(role);
  402. }
  403. roleMapper.insertBatch(listR);
  404. // 更新用户的角色ids-
  405. List<String> roleids = new ArrayList<>();
  406. roleids.add(roleid);
  407. this.updateByUuid(new Staff().setStaffId(staffId).setRoleIds(roleids));
  408. // 角色权限
  409. RoleFun roleFun = new RoleFun();
  410. roleFun.setRoleId(roleid);
  411. roleFun.setCpId(cpId);
  412. roleFun.setOpCreateUserId(staffId);
  413. roleFunMapper.insertRoleFunFeign(roleFun);
  414. // 仓库
  415. List<Map<String, Object>> listWarehouses = map.get("warehouses");
  416. List<Warehouse> listW = new ArrayList<>();
  417. if (listWarehouses != null && listWarehouses.size() > 0) {
  418. for (int i = 0; i < listWarehouses.size(); i++) {
  419. Map<String, Object> m = listWarehouses.get(i);
  420. Warehouse warehouse = new Warehouse();
  421. warehouse.setWhCode(m.get("whCode").toString());
  422. warehouse.setWhName(m.get("whName").toString());
  423. warehouse.setDisplayNo((Integer) m.get("displayNo"));
  424. warehouse.setFlgDefault((Boolean) m.get("flgDefault"));
  425. warehouse.setCpId(cpId);
  426. warehouse.setOpCreateUserId(staffId);
  427. listW.add(warehouse);
  428. }
  429. warehouseMapper.insertBatch(listW);
  430. }
  431. // 渠道
  432. List<Map<String, Object>> listSaleChannels = map.get("saleChannels");
  433. List<SaleChannel> listSc = new ArrayList<>();
  434. if (listSaleChannels != null && listSaleChannels.size() > 0) {
  435. for (int i = 0; i < listSaleChannels.size(); i++) {
  436. Map<String, Object> m = listSaleChannels.get(i);
  437. SaleChannel saleChannel = new SaleChannel();
  438. saleChannel.setChannelCode(m.get("channelCode").toString());
  439. saleChannel.setChannelName(m.get("channelName").toString());
  440. saleChannel.setDisplayNo((Integer) m.get("displayNo"));
  441. saleChannel.setFlgDefault((Boolean) m.get("flgDefault"));
  442. saleChannel.setCpId(cpId);
  443. saleChannel.setOpCreateUserId(staffId);
  444. listSc.add(saleChannel);
  445. }
  446. saleChannelMapper.insertBatch(listSc);
  447. }
  448. // 基础资料
  449. List<Map<String, Object>> listDictionaryDatas = map.get("dictionaryDatas");
  450. List<DictionaryData> listDD = new ArrayList<>();
  451. if (listDictionaryDatas != null && listDictionaryDatas.size() > 0) {
  452. for (int i = 0; i < listDictionaryDatas.size(); i++) {
  453. Map<String, Object> m = listDictionaryDatas.get(i);
  454. DictionaryData dictionaryData = new DictionaryData();
  455. dictionaryData.setDataId(UUID.randomUUID().toString());
  456. dictionaryData.setDictCode(m.get("dictCode").toString());
  457. dictionaryData.setDataCode(m.get("dataCode").toString());
  458. dictionaryData.setDataValue(m.get("dataValue").toString());
  459. dictionaryData.setDisplayNo((Integer) m.get("displayNo"));
  460. dictionaryData.setFlgDefault((Boolean) m.get("flgDefault"));
  461. dictionaryData.setCpId(cpId);
  462. dictionaryData.setOpCreateUserId(staffId);
  463. listDD.add(dictionaryData);
  464. }
  465. dictionaryDataMapper.insertBatch(listDD);
  466. }
  467. // 资金账户
  468. List<Map<String, Object>> listMoneyAccounts = map.get("moneyAccounts");
  469. List<MoneyAccount> listMa = new ArrayList<>();
  470. if (listMoneyAccounts != null && listMoneyAccounts.size() > 0) {
  471. for (int i = 0; i < listMoneyAccounts.size(); i++) {
  472. Map<String, Object> m = listMoneyAccounts.get(i);
  473. MoneyAccount moneyAccount = new MoneyAccount();
  474. moneyAccount.setMacCode(m.get("macCode").toString());
  475. moneyAccount.setMacName(m.get("macName").toString());
  476. // 从上面数据字典中查询 新的id 240814
  477. List<DictionaryData> dictionaryDatas = listDD.stream().filter(it ->
  478. "基础资料-账户".equals(it.getDataCode()) && (m.get("macName") + "").equals(it.getDataValue())
  479. ).collect(Collectors.toList());
  480. if (dictionaryDatas != null && dictionaryDatas.size() > 0) {
  481. moneyAccount.setMacType(dictionaryDatas.get(0).getDataId());
  482. } else {
  483. // 该值不正确 要清洗数据
  484. moneyAccount.setMacType(m.get("macType").toString());
  485. }
  486. moneyAccount.setAccDate(LocalDate.now());
  487. // moneyAccount.setBalance((BigDecimal) m.get("balance"));
  488. moneyAccount.setBalance(new BigDecimal(m.get("balance").toString()));
  489. moneyAccount.setFlgDefault((Boolean) m.get("flgDefault"));
  490. moneyAccount.setFlgNegative((Boolean) m.get("flgNegative"));
  491. moneyAccount.setDisplayNo((Integer) m.get("displayNo"));
  492. moneyAccount.setCpId(cpId);
  493. listMa.add(moneyAccount);
  494. }
  495. moneyAccountMapper.insertBatch(listMa);
  496. }
  497. // 计量单位
  498. List<Map<String, Object>> listUnits = map.get("units");
  499. List<Unit> listU = new ArrayList<>();
  500. if (listUnits != null && listUnits.size() > 0) {
  501. for (int i = 0; i < listUnits.size(); i++) {
  502. Map<String, Object> m = listUnits.get(i);
  503. Unit unit = new Unit();
  504. unit.setUnitCode(m.get("unitCode").toString());
  505. unit.setUnitName(m.get("unitName").toString());
  506. unit.setDecimalPlaces((Integer) m.get("decimalPlaces"));
  507. unit.setDisplayNo((Integer) m.get("displayNo"));
  508. unit.setCpId(cpId);
  509. unit.setOpCreateUserId(staffId);
  510. listU.add(unit);
  511. }
  512. unitMapper.insertBatch(listU);
  513. }
  514. // 种类
  515. List<Map<String, Object>> listGoodsCategorys = map.get("goodsCategorys");
  516. List<GoodsCategory> listG = new ArrayList<>();
  517. List<Map<String, Object>> parentList = listGoodsCategorys.stream().filter(it -> it.get("parentId") == null).collect(Collectors.toList());
  518. if (parentList != null && parentList.size() > 0) {
  519. for (int i = 0; i < parentList.size(); i++) {
  520. Map<String, Object> m = parentList.get(i);
  521. // 获取子级
  522. List<Map<String, Object>> childList = listGoodsCategorys.stream().filter(it -> m.get("catId").equals(it.get("parentId"))).collect(Collectors.toList());
  523. GoodsCategory goodsCategory = new GoodsCategory();
  524. goodsCategory.setCatCode(m.get("catCode") + "");
  525. goodsCategory.setCatName(m.get("catName") + "");
  526. if (m.get("parentId") != null) {
  527. goodsCategory.setParentId(m.get("parentId") + "");
  528. }
  529. if (m.get("topId") != null) {
  530. goodsCategory.setTopId(m.get("topId") + "");
  531. }
  532. goodsCategory.setCatId(UUID.randomUUID().toString());
  533. goodsCategory.setDisplayNo((Integer) m.get("displayNo"));
  534. goodsCategory.setCpId(cpId);
  535. goodsCategory.setOpCreateUserId(staffId);
  536. goodsCategoryMapper.insert(goodsCategory);
  537. listG = new ArrayList<>();
  538. // 插入子级
  539. for (Map<String, Object> c : childList) {
  540. GoodsCategory gc = new GoodsCategory();
  541. gc.setCatCode(c.get("catCode") + "");
  542. gc.setCatName(c.get("catName") + "");
  543. gc.setParentId(goodsCategory.getCatId());
  544. gc.setTopId(goodsCategory.getTopId());
  545. gc.setDisplayNo((Integer) c.get("displayNo"));
  546. gc.setCpId(cpId);
  547. gc.setOpCreateUserId(staffId);
  548. listG.add(gc);
  549. }
  550. ;
  551. if (listG != null && listG.size() > 0) {
  552. goodsCategoryMapper.insertBatch(listG);
  553. }
  554. }
  555. //执行函数
  556. goodsCategoryMapper.resetLevelGoodsCategory(new GoodsCategoryQuery());
  557. }
  558. // 打印票据
  559. List<Map<String, Object>> listPrintLayout = map.get("printLayout");
  560. List<PrintLayout> listP = new ArrayList<>();
  561. if (listPrintLayout != null && listPrintLayout.size() > 0) {
  562. for (int i = 0; i < listPrintLayout.size(); i++) {
  563. Map<String, Object> m = listPrintLayout.get(i);
  564. PrintLayout printLayout = new PrintLayout();
  565. printLayout.setLayoutName(m.get("layoutName") + "");
  566. printLayout.setLayoutData(JSONObject.parseObject(JSONObject.toJSONString(m.get("layoutData"))));
  567. printLayout.setDisplayNo((Integer) m.get("displayNo"));
  568. printLayout.setDocName(m.get("docName") + "");
  569. printLayout.setCpId(cpId);
  570. printLayout.setOpCreateUserId(staffId);
  571. listP.add(printLayout);
  572. }
  573. printLayoutMapper.insertBatch(listP);
  574. }
  575. return ResponseResultUtil.success();
  576. }
  577. /**
  578. * @desc : 保存方法-邀请员工的确定
  579. * @author : 姜永辉
  580. * @date : 2023/1/9 10:49
  581. */
  582. @Transactional(rollbackFor = {Exception.class})
  583. public ResponseResultVO<?> insertRequestStaff(StaffVO staffVO) {
  584. // 转化实体
  585. Staff staff = staffConvert.convertToPo(staffVO);
  586. // 校验同一个公司的电话不能重复
  587. StaffQuery staffQuery = new StaffQuery();
  588. staffQuery.setCpId(staff.getCpId());
  589. staffQuery.setStaffPhone(staff.getStaffPhone());
  590. staffQuery.setFlgValid(true);
  591. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  592. if (staffResponses != null && staffResponses.size() > 0) {
  593. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  594. }
  595. // 获取编码和主键UuId
  596. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), true);
  597. staff.setStaffId(codeMap.get("outId").toString());
  598. staff.setStaffCode(codeMap.get("outNote").toString());
  599. // 更新 被邀人员的cpid
  600. if (staff.getWxUserId() != null) {
  601. // 更新 被邀请人员的微信用户的cpid 加入公司
  602. Map<String, Object> collectQuery = new HashMap<>();
  603. collectQuery.put("cpId", staff.getCpId());
  604. collectQuery.put("userId", staff.getWxUserId());
  605. companyFeign.updateWxUserCompany(collectQuery);
  606. }
  607. // 插入员工
  608. super.insert(staff);
  609. return ResponseResultUtil.success(staff);
  610. }
  611. /**
  612. * @desc : 编辑方法
  613. * @author : 姜永辉
  614. * @date : 2023/1/9 10:49
  615. */
  616. @Transactional(
  617. rollbackFor = {Exception.class}
  618. )
  619. public ResponseResultVO<Boolean> update(StaffVO staffVO) {
  620. // 转化实体
  621. Staff staff = staffConvert.convertToPo(staffVO);
  622. // 查询原来的getFlgCanLogin
  623. StaffResponse staffResponseOld = staffMapper.selectById(staffVO.getStaffId());
  624. // 获取当前公司的cpId
  625. Integer cpId = authUtils.getStaff().getCpId();
  626. // 校验同一个公司的电话不能重复
  627. StaffQuery staffQuery = new StaffQuery();
  628. staffQuery.setStaffPhone(staff.getStaffPhone());
  629. staffQuery.setCpId(cpId);
  630. staffQuery.setFlgValid(true);
  631. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  632. if (staffResponses != null && staffResponses.size() > 0 && !staffVO.getStaffId().equals(staffResponses.get(0).getStaffId())) {
  633. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST);
  634. }
  635. staffQuery.setStaffPhone(null);
  636. staffQuery.setStaffCode(staff.getStaffCode());
  637. staffResponses = staffMapper.selectByCondByCode(staffQuery);
  638. if (staffResponses != null && staffResponses.size() > 0 && !staffVO.getStaffId().equals(staffResponses.get(0).getStaffId())) {
  639. return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_CODE_EXIST);
  640. }
  641. super.updateByUuid(staff);
  642. //可以绑定微信的员工人数 人数上限
  643. if (staffVO.getFlgCanLogin() != null && staffVO.getFlgCanLogin()) {
  644. ResponseResultVO<?> resultMaxnum = companyFeign.getCompanyMaxStaffNum(cpId);
  645. if (resultMaxnum.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  646. // 无用户
  647. throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  648. ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  649. } else {
  650. if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
  651. Map<String, Object> mp = (Map<String, Object>) resultMaxnum.getData();
  652. int intWebMaxnum = 0;
  653. if (mp.get("web_max_num") != null) {
  654. intWebMaxnum = Integer.parseInt(mp.get("web_max_num") + "");
  655. }
  656. int intWxMaxnum = 0;
  657. if (mp.get("wx_max_num") != null) {
  658. intWxMaxnum = Integer.parseInt(mp.get("wx_max_num") + "");
  659. }
  660. StaffQuery staffQueryf = new StaffQuery();
  661. staffQueryf.setFlgCanLogin(true);
  662. staffQueryf.setCpId(cpId);
  663. List<StaffResponse> staffResponsesFlgCanLogin = staffMapper.selectByCond(staffQueryf);
  664. if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0) {
  665. List<StaffResponse> collectPc = staffResponsesFlgCanLogin.stream().filter(it -> it.getLoginType() == 1 || it.getLoginType() == 3).collect(Collectors.toList());
  666. List<StaffResponse> collectWx = staffResponsesFlgCanLogin.stream().filter(it -> it.getLoginType() == 2 || it.getLoginType() == 3).collect(Collectors.toList());
  667. if (collectPc != null && collectPc.size() > 0 && intWebMaxnum < collectPc.size()) {
  668. // 无用户
  669. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getCode(),
  670. ErrorCodeEnum.USER_MAX_PC_STAFF_ERROR.getMessage());
  671. }
  672. if (collectWx != null && collectWx.size() > 0 && intWxMaxnum < collectWx.size()) {
  673. // 无用户
  674. throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getCode(),
  675. ErrorCodeEnum.USER_MAX_WX_STAFF_ERROR.getMessage());
  676. }
  677. }
  678. }
  679. // if (staffResponsesFlgCanLogin != null && staffResponsesFlgCanLogin.size() > 0 && intMaxnum < staffResponsesFlgCanLogin.size()) {
  680. // // 无用户
  681. // throw new BaseBusinessException(ErrorCodeEnum.USER_MAX_STAFF_ERROR.getCode(),
  682. // ErrorCodeEnum.USER_MAX_STAFF_ERROR.getMessage());
  683. // }
  684. }
  685. // if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
  686. // // 增加一个可以cur_staff_num
  687. // Map<String, Object> m = new HashMap<>();
  688. // m.put("curStaffNum", 1);
  689. // m.put("cpId", cpId);
  690. // ResponseResultVO<Boolean> booleanResponseResultVO = companyFeign.updateCompanyCurStaffNum(m);
  691. // if (booleanResponseResultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  692. // // 无用户
  693. // throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  694. // ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  695. // }
  696. // }
  697. } else {
  698. // 2024-05-20 edit
  699. // if (staffResponseOld.getFlgCanLogin() != staffVO.getFlgCanLogin()) {
  700. // // 减少一个可以cur_staff_num
  701. // Map<String, Object> m = new HashMap<>();
  702. // m.put("curStaffNum", -1);
  703. // m.put("cpId", cpId);
  704. // ResponseResultVO<Boolean> booleanResponseResultVO = companyFeign.updateCompanyCurStaffNum(m);
  705. // if (booleanResponseResultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  706. // // 无用户
  707. // throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
  708. // ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
  709. // }
  710. // }
  711. }
  712. return ResponseResultUtil.success();
  713. }
  714. /**
  715. * @desc : 更新员工的登录标识
  716. * @author : 姜永辉
  717. * @date : 2023/1/9 10:49
  718. */
  719. @Transactional(rollbackFor = {Exception.class})
  720. public ResponseResultVO<Boolean> updateFeignStaffFlgCanLogin(List<String> list) {
  721. // FlgCanLogin 登录系统(1:PC端,2:移动端,3:PC+移动端, 4:无)
  722. staffMapper.updateFeignStaffFlgCanLogin(list);
  723. return ResponseResultUtil.success();
  724. }
  725. /**
  726. * @desc : 保存权限方法
  727. * @author : 姜永辉
  728. * @date : 2023/1/9 10:49
  729. */
  730. @Transactional(
  731. rollbackFor = {Exception.class}
  732. )
  733. public ResponseResultVO<?> saveStaffRight(StaffVO staffVO) {
  734. // 获取当前公司的cpId
  735. Integer cpId = authUtils.getStaff().getCpId();
  736. // 转化实体
  737. Staff staff = staffConvert.convertToPo(staffVO);
  738. staffRightService.delete(staffVO.getStaffId());
  739. for (StaffRight staffRight : staffVO.getStaffRightList()) {
  740. staffRight.setStaffId(staff.getStaffId());
  741. staffRight.setRightType(1);
  742. staffRight.setCpId(cpId);
  743. }
  744. if (staffVO.getStaffRightList() != null && staffVO.getStaffRightList().size() > 0) {
  745. staffRightService.saveStaffRight(staffVO.getStaffRightList());
  746. }
  747. return ResponseResultUtil.success();
  748. }
  749. /**
  750. * @desc : 保存权限方法
  751. * @author : 姜永辉
  752. * @date : 2023/1/9 10:49
  753. */
  754. @Transactional(
  755. rollbackFor = {Exception.class}
  756. )
  757. public ResponseResultVO<?> saveStaffPurview(StaffVO staffVO) {
  758. // 获取当前公司的cpId
  759. Integer cpId = authUtils.getStaff().getCpId();
  760. // 转化实体
  761. Staff staff = staffConvert.convertToPo(staffVO);
  762. for (StaffPurview staffRight : staffVO.getStaffPurviewList()) {
  763. staffRight.setStaffId(staff.getStaffId());
  764. staffRight.setCpId(cpId);
  765. }
  766. staffPurviewService.saveStaffPurview(staffVO.getStaffPurviewList());
  767. return ResponseResultUtil.success();
  768. }
  769. /**
  770. * @desc : 员工离职
  771. * @author : 姜永辉
  772. * @date : 2023/2/13 13:45
  773. */
  774. @Transactional(
  775. rollbackFor = {Exception.class}
  776. )
  777. public ResponseResultVO<Boolean> dimission(StaffVO staffVO) {
  778. // 将微信的用户的信息 openid current_cp , "joined_cps" 缩减相应的cpid
  779. // 更新 被邀请人员的微信用户的cpid 加入公司
  780. Map<String, Object> collectQuery = new HashMap<>();
  781. // 获取当前公司的cpId
  782. Integer cpId = authUtils.getStaff().getCpId();
  783. collectQuery.put("cpId", cpId);
  784. collectQuery.put("userId", staffVO.getWxUserId());
  785. ResponseResultVO<?> resultVO = userFeign.updateClearOpenidFeign(collectQuery);
  786. // 如果没有成功返回,状态设置为待审
  787. if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
  788. // 无用户
  789. throw new BaseBusinessException(ErrorCodeEnum.STAFF_UPDATE_ERROR.getCode(),
  790. ErrorCodeEnum.STAFF_UPDATE_ERROR.getMessage());
  791. }
  792. // 转化实体
  793. Staff staff = staffConvert.convertToPo(staffVO);
  794. super.updateByUuid(staff);
  795. return ResponseResultUtil.success();
  796. }
  797. /**
  798. * @desc : 导入员工
  799. * @author : 姜永辉
  800. * @date : 2023/3/1 14:40
  801. */
  802. @Transactional(
  803. rollbackFor = {Exception.class}
  804. )
  805. public ResponseResultVO<Boolean> importStaffList(List<StaffVO> list) {
  806. if (CollectionUtils.isEmpty(list) || list.size() == 0) {
  807. return ResponseResultUtil.error(ResponseCodeEnum.INSERT_FAIL);
  808. }
  809. return ResponseResultUtil.success();
  810. }
  811. /**
  812. * @desc : 登录后获取信息
  813. * @author : 周兴
  814. * @date : 2024/3/4 11:41
  815. */
  816. @Transactional(
  817. rollbackFor = {Exception.class}
  818. )
  819. public ResponseResultVO<Dictionary<String, Object>> getInfoAfterLogin(Map<String, Object> param) {
  820. // 先根据userId查询当前企业的员工信息
  821. StaffResponse staff = staffMapper.selectByUserId(param.get("userId").toString(), Integer.parseInt(param.get("cpId").toString()));
  822. if (staff != null) {
  823. // 提示不允许登录
  824. if (staff.getFlgCanLogin() == null || !staff.getFlgCanLogin()) {
  825. return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CAN_NOT_LOGIN.getMessage());
  826. }
  827. // 离职状态不允许登录
  828. if (staff.getHrStatus() != 1) {
  829. return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_OUT_NOT_LOGIN.getMessage());
  830. }
  831. // 存Redis
  832. authUtils.saveStaff(new StaffEntity().setStaffId(staff.getStaffId())
  833. .setWxUserId(staff.getWxUserId())
  834. .setStaffCode(staff.getStaffCode())
  835. .setStaffName(staff.getStaffName())
  836. .setGradeCode(staff.getGradeCode())
  837. .setCpId(Integer.parseInt(param.get("cpId").toString()))
  838. .setAppCode(param.get("appCode").toString()));
  839. // 更新员工登录状态
  840. this.updateByUuid(new Staff().setStaffId(staff.getStaffId()).setFlgCanLogin(true));
  841. } else {
  842. return ResponseResultUtil.error(ErrorCodeEnum.STAFF_NOT_EXIST.getCode(), ErrorCodeEnum.STAFF_NOT_EXIST.getMessage());
  843. }
  844. // 获取菜单
  845. List menuList = commonMapper.getMenuByUser(param);
  846. // 获取常用菜单
  847. ResponseResultVO<?> comMenuList = comMenuService.selectMenu(new ComMenuQuery().setStaffId(staff.getStaffId())
  848. .setAppCode(param.get("appCode").toString()));
  849. // 获取所有参数
  850. Map<String, Object> allSettingValue = commonMapper.getAllSettingValue();
  851. Dictionary<String, Object> dic = new Hashtable<>();
  852. dic.put("menuList", menuList);
  853. dic.put("comMenuList", comMenuList.getData());
  854. dic.put("dataKindList", commonMapper.getDataKind(param));
  855. dic.put("settingValue", allSettingValue);
  856. dic.put("staff", staff);
  857. // 判断是否到期 返回服务器的时间
  858. dic.put("nowDate", LocalDate.now());
  859. return ResponseResultUtil.success(dic);
  860. }
  861. /**
  862. * @desc : 退出登录
  863. * @author : 周兴
  864. * @date : 2024-03-18 09:03
  865. */
  866. @Transactional(
  867. rollbackFor = {Exception.class}
  868. )
  869. public ResponseResultVO<Boolean> logout(Map<String, Object> param) {
  870. // 更新员工登录状态
  871. // this.updateByUuid(new Staff().setStaffId(param.get("staffId").toString()).setFlgCanLogin(false));
  872. return ResponseResultUtil.success(true);
  873. }
  874. /**
  875. * @desc : 生成幽灵标识的数据
  876. * @author : 常皓宁
  877. * @date : 2024/6/19 10:53
  878. */
  879. @Transactional(
  880. rollbackFor = {Exception.class}
  881. )
  882. public ResponseResultVO<?> insertGhostStaff(StaffVO staffVO) {
  883. // 转化实体
  884. Staff staff = staffConvert.convertToPo(staffVO);
  885. StaffQuery staffQuery = new StaffQuery();
  886. staffQuery.setStaffCode(staff.getStaffCode());
  887. staffQuery.setCpId(staff.getCpId());
  888. List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
  889. if (staffResponses == null || staffResponses.size() == 0) {
  890. return ResponseResultUtil.error(-200, "绑定员工不存在");
  891. } else {
  892. for (StaffResponse staffResponse : staffResponses) {
  893. // 获取编码和主键UuId
  894. Map<String, Object> codeMap = commonService.getUniqueNoteCode(
  895. Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true);
  896. staff.setStaffId(codeMap.get("outId").toString());
  897. staff.setStaffCode(codeMap.get("outNote").toString());
  898. staff.setStaffName(staff.getStaffName());
  899. staff.setStaffPhone(staff.getStaffPhone());
  900. staff.setOrgId(staffResponse.getOrgId());
  901. staff.setRoleIds(staffResponse.getRoleIds());
  902. staff.setHrStatus(staffResponse.getHrStatus());
  903. staff.setFlgCanLogin(staffResponse.getFlgCanLogin());
  904. staff.setWxUserId(staff.getWxUserId());
  905. staff.setLoginType(staffResponse.getLoginType());
  906. staff.setFlgInit(false);
  907. staff.setFlgGhost(true);
  908. super.insert(staff);
  909. }
  910. return ResponseResultUtil.success();
  911. }
  912. }
  913. /**
  914. * @desc : 删除幽灵标识数据
  915. * @author : 常皓宁
  916. * @date : 2024/6/19 10:53
  917. */
  918. @Transactional(
  919. rollbackFor = {Exception.class}
  920. )
  921. public ResponseResultVO<?> deleteGhostStaff(StaffVO staffVO) {
  922. // 转化实体
  923. Staff staff = staffConvert.convertToPo(staffVO);
  924. StaffQuery staffQuery = new StaffQuery();
  925. staffQuery.setStaffName(staff.getStaffName());
  926. staffQuery.setStaffPhone(staff.getStaffPhone());
  927. staffQuery.setCpId(staff.getCpId());
  928. int a = staffMapper.deleteGhostStaff(staffQuery);
  929. if (a > 0) {
  930. return ResponseResultUtil.success();
  931. } else {
  932. return ResponseResultUtil.error(-200, "绑定员工不存在");
  933. }
  934. }
  935. /**
  936. * @desc : 更新负责人标识
  937. * @author : 刘尧
  938. * @date : 2024/6/21 16:24
  939. */
  940. public ResponseResultVO updateFlgInit(Map<String, Object> params) {
  941. boolean updateBool = staffMapper.updateFlgInit(params);
  942. if (updateBool) {
  943. updateBool = staffMapper.updateFlgInitById(String.valueOf(params.get("owner")));
  944. return ResponseResultUtil.success(updateBool);
  945. }
  946. return ResponseResultUtil.error();
  947. }
  948. }