From 0a66b4e946ebbe3ac09a193ad5a60cf7a95fe99d Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期四, 26 六月 2025 14:14:48 +0800 Subject: [PATCH] art: 删除base模块无用代码 --- src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 201 insertions(+), 0 deletions(-) diff --git a/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java b/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java new file mode 100644 index 0000000..049a30c --- /dev/null +++ b/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java @@ -0,0 +1,201 @@ +package org.jeecg.modules.base.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import org.apache.commons.lang3.StringUtils; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.FillRuleConstant; +import org.jeecg.common.util.FillRuleUtil; +import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.base.entity.UserFactory; +import org.jeecg.modules.base.mapper.FactoryMapper; +import org.jeecg.modules.base.mapper.UserFactoryMapper; +import org.jeecg.modules.base.model.FactoryIdModel; +import org.jeecg.modules.base.model.FactoryTreeModel; +import org.jeecg.modules.base.service.IFactoryService; +import org.jeecg.modules.system.mapper.SysUserMapper; +import org.jeecg.modules.system.util.FindsProductionsChildrenUtil; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * @Description: 宸ュ巶/杞﹂棿/浜х嚎 + * @Author: jeecg-boot + * @Date: 2025-06-24 + * @Version: V1.0 + */ +@Service +public class FactoryServiceImpl extends ServiceImpl<FactoryMapper, Factory> implements IFactoryService { + + @Resource + private SysUserMapper sysUserMapper; + + @Resource + private UserFactoryMapper userFactoryMapper; + + /** + * saveFactoryData 瀵瑰簲 add 淇濆瓨鐢ㄦ埛鍦ㄩ〉闈㈡坊鍔犵殑鏂扮殑浜х嚎瀵硅薄鏁版嵁 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void saveFactoryData(Factory factory) { + if (factory != null) { + if (factory.getParentId() == null) { + factory.setParentId(""); + } + factory.setId(IdWorker.getIdStr(factory)); + // 鍏堝垽鏂瀵硅薄鏈夋棤鐖剁骇ID,鏈夊垯鎰忓懗鐫�涓嶆槸鏈�楂樼骇,鍚﹀垯鎰忓懗鐫�鏄渶楂樼骇 + // 鑾峰彇鐖剁骇ID + String parentId = factory.getParentId(); + JSONObject formData = new JSONObject(); + formData.put("parentId",parentId); + String factoryCategory = ""; + if(StringUtils.isBlank(parentId)){ + factoryCategory = "1"; + }else { + // 鏌ヨ鍑虹埗绾т骇绾� + Factory parentFactory = super.getById(parentId); + // 鏍规嵁鐖剁骇浜х嚎绫诲瀷绠楀嚭褰撳墠浜х嚎鐨勭被鍨� + factoryCategory = String.valueOf(Integer.valueOf(parentFactory.getFactoryCategory()) + 1); + } + factory.setFactoryCategory(factoryCategory); + factory.setDelFlag(CommonConstant.DEL_FLAG_0); + this.save(factory); + + //澶勭悊瀛樺湪鐖跺瓙鍏崇郴 mdc鏍囪缁熶竴鐨勯棶棰� + //1.mdc鏍囪 涓� 1 寮�鍚� 鐖剁骇鑺傜偣瑕佺粺涓�寮�鍚� + //2.mdc鏍囪 涓� 0 鍏抽棴 瀛愮骇鑺傜偣瑕佺粺涓�鍏抽棴 鏂板鎿嶄綔 涓嶅瓨鍦ㄦ鎯呭喌 + if(StringUtils.isNotBlank(parentId) && CommonConstant.DEFAULT_1.equals(factory.getMdcFlag())){ + openParentMdcFlag(parentId); + } + } + } + + /** + * queryTreeList 瀵瑰簲 queryTreeList 鏌ヨ鎵�鏈夌殑浜х嚎鏁版嵁,浠ユ爲缁撴瀯褰㈠紡鍝嶅簲缁欏墠绔� + */ + @Override + //@Cacheable(value = "mdc:cache:production:alldata") + public List<FactoryTreeModel> queryTreeList() { + LambdaQueryWrapper<Factory> query = new LambdaQueryWrapper<Factory>(); + query.eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); + query.orderByAsc(Factory::getSorter); + List<Factory> list = this.list(query); + //璋冪敤wrapTreeDataToTreeList鏂规硶鐢熸垚鏍戠姸鏁版嵁 + return FindsProductionsChildrenUtil.wrapTreeDataToTreeList(list); + } + + /** + * queryTreeList 鏍规嵁浜х嚎id鏌ヨ,鍓嶇鍥炴樉璋冪敤 + */ + @Override + public List<FactoryTreeModel> queryTreeList(String ids) { + List<FactoryTreeModel> listResult = new ArrayList<>(); + LambdaQueryWrapper<Factory> query = new LambdaQueryWrapper<Factory>(); + query.eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); + if (oConvertUtils.isNotEmpty(ids)) { + query.in(true, Factory::getId, ids.split(",")); + } + query.orderByAsc(Factory::getSorter); + List<Factory> list = this.list(query); + for (Factory factory : list) { + if (factory.getRemark().isEmpty()){ + factory.setRemark(""); + } + listResult.add(new FactoryTreeModel(factory)); + } + return listResult; + } + + /** + * 鏍规嵁浜х嚎id鍒犻櫎骞跺垹闄ゅ叾鍙兘瀛樺湪鐨勫瓙绾т骇绾� + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean delete(String id) { + List<String> idList = new ArrayList<>(); + idList.add(id); + this.checkChildrenExists(id, idList); + boolean result = this.removeByIds(idList); + //鏍规嵁浜х嚎id鍒犻櫎鐢ㄦ埛涓庝骇绾垮叧绯� + userFactoryMapper.delete(new LambdaQueryWrapper<UserFactory>().in(UserFactory::getFactoryId, idList)); + //鏍规嵁浜х嚎id鍒犻櫎浜х嚎涓庤澶囧叧绯� + //productionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().in(MdcProductionEquipment::getProductionId, idList)); + return result; + } + + /** + * delete 鏂规硶璋冪敤 閫掑綊鏌ユ壘瀛愰泦id + */ + private void checkChildrenExists(String id, List<String> idList) { + LambdaQueryWrapper<Factory> query = new LambdaQueryWrapper<>(); + query.eq(Factory::getParentId, id); + List<Factory> factoryList = this.list(query); + if (factoryList != null && !factoryList.isEmpty()) { + for (Factory factory : factoryList) { + idList.add(factory.getId()); + this.checkChildrenExists(factory.getId(), idList); + } + } + } + + @Override + //@Cacheable(value = "mdc:cache:production:allids") + public List<FactoryIdModel> queryFactoryIdTreeList() { + LambdaQueryWrapper<Factory> query = new LambdaQueryWrapper<>(); + query.eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); + query.orderByAsc(Factory::getSorter); + List<Factory> list = this.list(query); + //璋冪敤wrapTreeDataToTreeList鏂规硶鐢熸垚鏍戠姸鏁版嵁 + return FindsProductionsChildrenUtil.wrapTreeDataToProductionIdTreeList(list); + } + + /** + * 鎵撳紑 鐖惰妭鐐� 鍙� 浠ヤ笂鐨刴dc鏍囪 + * @param parentId + */ + private void openParentMdcFlag(String parentId) { + List<String> listParentTree = findParentIdsForFactory(parentId, new ArrayList<>()); + if (!CollectionUtil.isEmpty(listParentTree)) { + UpdateWrapper<Factory> updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", listParentTree); + updateWrapper.set("mdc_flag", "1"); + super.update(updateWrapper); + } + } + + public List<String> findParentIdsForFactory(String parentId, List<String> idList) { + if (StringUtils.isEmpty(parentId)) { + return null; + } + if (idList == null || idList.isEmpty()) { + idList = new ArrayList<>(); + } + boolean p = true; + if (p) { + Factory en = super.getById(parentId); + if (en != null) { + idList.add(0, en.getId()); + } + if (StringUtils.isNotBlank(en.getParentId())) { + parentId = en.getParentId(); + findParentIdsForFactory(parentId, idList); + } else { + p = false; + return idList; + } + } + return idList; + } +} -- Gitblit v1.9.3