| | |
| | | package com.highdatas.mdm.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.highdatas.mdm.entity.Flows; |
| | | import com.highdatas.mdm.entity.Maintain; |
| | | import com.highdatas.mdm.entity.MaintainField; |
| | | import com.highdatas.mdm.entity.SysField; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.mapper.MaintainFieldMapper; |
| | | import com.highdatas.mdm.pojo.ActivitiStatus; |
| | | import com.highdatas.mdm.pojo.Operate; |
| | | import com.highdatas.mdm.service.IFlowsService; |
| | | import com.highdatas.mdm.service.IMaintainFieldService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.highdatas.mdm.service.IMaintainService; |
| | | import com.highdatas.mdm.service.ISysFieldService; |
| | | import com.highdatas.mdm.service.*; |
| | | import com.highdatas.mdm.util.Constant; |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.mybatis.spring.SqlSessionTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.sql.Connection; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.SQLException; |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | IFlowsService flowsService; |
| | | @Autowired |
| | | ISysFieldService fieldService; |
| | | |
| | | @Autowired |
| | | MaintainFieldMapper maintainFieldMapper; |
| | | |
| | | @Autowired |
| | | IMasterAuthorService masterAuthorService; |
| | | @Autowired |
| | | IMasterAuthorDetailService masterAuthorDetailService; |
| | | @Override |
| | | public MaintainField getNextMaintain(String tableName, String userId) { |
| | | MaintainField maintain = this.getMaxVersion(tableName); |
| | |
| | | nowMaintain.setId(DbUtils.getUUID()); |
| | | } |
| | | return nowMaintain; |
| | | } |
| | | |
| | | @Override |
| | | public List<Maintain> getMaintainByMaintainField(String maintainFieldId, String tableName) { |
| | | HashMap<String, List<Maintain>> resultMap = getMaintainFieldMapByTable(tableName); |
| | | if (resultMap == null) { |
| | | return null; |
| | | } |
| | | return resultMap.get(maintainFieldId); |
| | | } |
| | | |
| | | @Override |
| | |
| | | maintainField.deleteById(); |
| | | } |
| | | else if (status.equals(ActivitiStatus.open)) { |
| | | |
| | | Integer orderNo = maintainField.getOrderNo(); |
| | | int preNo = orderNo - 1; |
| | | if (preNo< 0) { |
| | | return; |
| | | } |
| | | MaintainField preMaintainField = selectOne(new EntityWrapper<MaintainField>() |
| | | .eq("table_name", maintainField.getTableName()) |
| | | .eq("order_no", preNo)); |
| | | if (preMaintainField == null){ |
| | | return; |
| | | } |
| | | List<MasterAuthor> masterAuthors = masterAuthorService.selectList( |
| | | new EntityWrapper<MasterAuthor>() |
| | | .eq("maintain_auto", true) |
| | | .eq("table_name", maintainField.getTableName()) |
| | | .eq("maintain_field_id", preMaintainField.getId())); |
| | | if (masterAuthors.isEmpty()) { |
| | | return; |
| | | } |
| | | List<SysField> fieldList = fieldService.selectList(new EntityWrapper<SysField>().eq("maintain_field_id", maintainField.getId())); |
| | | |
| | | List<SysField> collect = fieldList.stream().filter(sysField -> Operate.delete.equals(sysField.getOperate())).collect(Collectors.toList()); |
| | | //delete |
| | | for (SysField field : collect) { |
| | | List<SysField> deleteList = fieldList.stream().filter(sysField -> Operate.delete.equals(sysField.getOperate())).collect(Collectors.toList()); |
| | | List<SysField> updateList = fieldList.stream().filter(sysField -> (Operate.update.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | List<SysField> createList = fieldList.stream().filter(sysField -> (Operate.create.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | |
| | | List<String> createFieldList = createList.stream().map(sysField -> sysField.getField()).collect(Collectors.toList()); |
| | | |
| | | |
| | | for (MasterAuthor masterAuthor : masterAuthors) { |
| | | Boolean fieldAuto = masterAuthor.getFieldAuto(); |
| | | masterAuthor.setMaintainFieldId(maintainField.getId()) |
| | | .setCreateTime(new Date()) |
| | | .setUpdateTime(null) |
| | | .setId(DbUtils.getUUID()) |
| | | .insert(); |
| | | List<MasterAuthorDetail> masterAuthorDetails = masterAuthorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, preMaintainField.getId())); |
| | | |
| | | for (MasterAuthorDetail masterAuthorDetail : masterAuthorDetails) { |
| | | masterAuthorDetail.setParentId(maintainField.getId()).setId(DbUtils.getUUID()).insert(); |
| | | } |
| | | |
| | | if (fieldAuto) { |
| | | for (String s : createFieldList) { |
| | | new MasterAuthorDetail().setField(s).setVal(Constant.z_AllVal).setAll(true).setParentId(maintainField.getId()).setId(DbUtils.getUUID()).insert(); |
| | | } |
| | | } |
| | | } |
| | | // |
| | | |
| | | |
| | | //delete |
| | | for (SysField field : deleteList) { |
| | | field.deleteById(); |
| | | } |
| | | //update |
| | | List<SysField> updateList = fieldList.stream().filter(sysField -> (Operate.update.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | for (SysField field : updateList) { |
| | | field.setOperate(null).updateById(); |
| | | } |
| | | List<SysField> createList = fieldList.stream().filter(sysField -> (Operate.create.equals(sysField.getOperate()))).collect(Collectors.toList()); |
| | | for (SysField field : createList) { |
| | | for (SysField field : createList) { |
| | | String fieldType = field.getFieldType(); |
| | | if (StringUtils.isEmpty(fieldType)) { |
| | | fieldType = Constant.varchar; |
| | |
| | | |
| | | field.setOperate(null).updateById(); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public int getUnFlowCount(String tableName, String userId) { |
| | |
| | | } |
| | | return cnt; |
| | | } |
| | | |
| | | @Override |
| | | public JSONArray getMaintainListByTable(String tableName) { |
| | | HashMap<String, List<Maintain>> resultMap = getMaintainFieldMapByTable(tableName); |
| | | |
| | | Set<String> keySet = resultMap.keySet(); |
| | | ArrayList<String> keys = new ArrayList<>(keySet); |
| | | Collections.sort(keys, new Comparator<String>() { |
| | | @Override |
| | | public int compare(String maintianFieldId1, String maintianFieldId2) { |
| | | MaintainField maintainField1 = selectById(maintianFieldId1); |
| | | MaintainField maintainField2 = selectById(maintianFieldId2); |
| | | if (maintainField1 == null) { |
| | | return 1; |
| | | } |
| | | if (maintainField2 == null){ |
| | | return -1; |
| | | } |
| | | |
| | | return maintainField1.getOrderNo().compareTo(maintainField2.getOrderNo()); |
| | | } |
| | | }); |
| | | |
| | | JSONArray array = new JSONArray(); |
| | | for (String s : keys) { |
| | | List<Maintain> list = resultMap.get(s); |
| | | Maintain max = list.stream().max(new Comparator<Maintain>() { |
| | | @Override |
| | | public int compare(Maintain o1, Maintain o2) { |
| | | return o1.getOrderNo() - o2.getOrderNo(); |
| | | } |
| | | }).get(); |
| | | Maintain min = list.stream().min(new Comparator<Maintain>() { |
| | | @Override |
| | | public int compare(Maintain o1, Maintain o2) { |
| | | return o1.getOrderNo() - o2.getOrderNo(); |
| | | } |
| | | }).get(); |
| | | JSONObject object = new JSONObject(); |
| | | object.fluentPut("maintainFieldId", s); |
| | | object.fluentPut("version", MessageFormat.format(Constant.extent, min.getVersion(), max.getVersion())); |
| | | object.fluentPut("list", list); |
| | | |
| | | array.add(object); |
| | | } |
| | | return array; |
| | | } |
| | | |
| | | @Override |
| | | public List<Maintain> getMaintainListByMaintainField(String id, String tableName) { |
| | | MaintainField maintainField = selectById(id); |
| | | if (maintainField == null) { |
| | | if (!id.equalsIgnoreCase(Constant.Default)){ |
| | | return null; |
| | | }else { |
| | | maintainField = new MaintainField().setId(Constant.Default).setTableName(tableName); |
| | | } |
| | | |
| | | } |
| | | |
| | | return getMaintainByMaintainField(maintainField.getId(), maintainField.getTableName()); |
| | | } |
| | | |
| | | private HashMap<String, List<Maintain>> getMaintainFieldMapByTable(String tableName) { |
| | | List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("order_no desc")); |
| | | HashMap<String, List<Maintain>> resultMap = new HashMap<>(); |
| | | for (Maintain maintain : maintainList) { |
| | | ActivitiStatus status = flowsService.getStatusByBusinessId(maintain.getId()); |
| | | if (!status.equals(ActivitiStatus.open)) { |
| | | continue; |
| | | } |
| | | MaintainField maintainFieldByMaintain = fieldService.getMaintainFieldByMaintain(maintain.getId()); |
| | | List<Maintain> list = resultMap.get(maintainFieldByMaintain.getId()); |
| | | if (list == null) { |
| | | list = new ArrayList<>(); |
| | | } |
| | | list.add(maintain); |
| | | resultMap.put(maintainFieldByMaintain.getId(), list); |
| | | } |
| | | return resultMap; |
| | | } |
| | | } |