StaffService.java 41 KB

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