吉安感知网项目-后端
linwei
2026-02-04 dccf741494a83781a50654e6a7b67a0e48675ea6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.sxkj.gd.implement.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.sxkj.common.utils.HeaderUtils;
import org.sxkj.gd.common.GenericConverter;
import org.sxkj.gd.common.IdParam;
import org.sxkj.gd.implement.entity.GdImplementListEntity;
import org.sxkj.gd.implement.entity.GdThingListMaterialRelEntity;
import org.sxkj.gd.implement.excel.GdImplementListExcel;
import org.sxkj.gd.implement.mapper.GdImplementListMapper;
import org.sxkj.gd.implement.param.GdImplementListPageParam;
import org.sxkj.gd.implement.param.ThingListMaterialRelationParam;
import org.sxkj.gd.implement.service.IGdImplementListService;
import org.sxkj.gd.implement.service.IGdThingListMaterialRelService;
import org.sxkj.gd.implement.vo.GdImplementListVO;
import org.sxkj.gd.implement.vo.GetThingListMaterialRelationVO;
import org.sxkj.gd.implement.wrapper.GdThingListMaterialRelWrapper;
import org.sxkj.system.cache.SysCache;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 实施清单主表 服务实现类
 *
 * @author Aix
 * @since 2026-01-31
 */
@Service
@AllArgsConstructor
public class GdImplementListServiceImpl extends BaseServiceImpl<GdImplementListMapper, GdImplementListEntity> implements IGdImplementListService {
 
    private final IGdThingListMaterialRelService gdThingListMaterialRelService;
 
    @Override
    public IPage<GdImplementListVO> selectGdImplementListPage(IPage<GdImplementListVO> page, GdImplementListPageParam gdImplementList) {
        List<Long> deptList = new ArrayList<>();
        if (!AuthUtil.isAdministrator()) {
            deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId()));
        }
        gdImplementList.setDeptList(deptList);
        gdImplementList.setAreaCode(HeaderUtils.formatAreaCode(gdImplementList.getAreaCode()));
        return page.setRecords(baseMapper.selectGdImplementListPage(page, gdImplementList));
    }
 
    @Override
    public GetThingListMaterialRelationVO getThingListMaterialRelation(IdParam idParam) {
        GetThingListMaterialRelationVO getThingListMaterialRelationVO = new GetThingListMaterialRelationVO();
 
        // 查询实施清单详情
        GdImplementListEntity gdImplement = getOne(Condition.getQueryWrapper(GenericConverter.convert(idParam, GdImplementListEntity.class)));
        getThingListMaterialRelationVO.setImplementListId(gdImplement.getId());
        getThingListMaterialRelationVO.setProcessDefinitionId(gdImplement.getProcessDefinitionId());
        getThingListMaterialRelationVO.setProcessInstanceId(gdImplement.getProcessInstanceId());
 
        List<GdThingListMaterialRelEntity> gdThingListMaterialRelEntityList = gdThingListMaterialRelService.list(
            Wrappers.<GdThingListMaterialRelEntity>query()
                .lambda().eq(GdThingListMaterialRelEntity::getImplementListId, idParam.getId()));
 
        getThingListMaterialRelationVO.setThingListMaterialRels(GdThingListMaterialRelWrapper.build().listVO(gdThingListMaterialRelEntityList));
        return getThingListMaterialRelationVO;
    }
 
    @Override
    @Transactional
    public boolean thingListMaterialRelation(ThingListMaterialRelationParam param) {
 
        if (null != param.getImplementListId()) {
 
            // 关联关系先删除,在新增
            gdThingListMaterialRelService.remove(
                new QueryWrapper<GdThingListMaterialRelEntity>()
                    .eq("implement_list_id", param.getImplementListId()));
 
            List<GdThingListMaterialRelEntity> gdThingListMaterialRelEntityList = getGdThingListMaterialRelEntities(param);
 
            // 批量新增材料关联关系
            gdThingListMaterialRelService.saveBatch(gdThingListMaterialRelEntityList);
 
            // 保存流程关联关系
            GdImplementListEntity gdImplementList = new GdImplementListEntity();
            gdImplementList.setId(param.getImplementListId());
            gdImplementList.setProcessDefinitionId(param.getProcessDefinitionId());
            gdImplementList.setProcessInstanceId(param.getProcessInstanceId());
            updateById(gdImplementList);
 
            return true;
        }
 
        return false;
    }
 
    @Override
    public List<GdImplementListExcel> exportGdImplementList(Wrapper<GdImplementListEntity> queryWrapper) {
        List<GdImplementListExcel> gdImplementListList = baseMapper.exportGdImplementList(queryWrapper);
        //gdImplementListList.forEach(gdImplementList -> {
        //    gdImplementList.setTypeName(DictCache.getValue(DictEnum.YES_NO, GdImplementList.getType()));
        //});
        return gdImplementListList;
    }
 
    /**
     * 获取材料关联关系(对象转换)
     * @param param 材料关联关系参数
     * @return 材料关联关系
     */
    @NotNull
    private static List<GdThingListMaterialRelEntity> getGdThingListMaterialRelEntities(ThingListMaterialRelationParam param) {
        List<GdThingListMaterialRelEntity> gdThingListMaterialRelEntityList = new ArrayList<>();
        int index = 0;
        for (Long materialId : param.getMaterialIds()) {
            GdThingListMaterialRelEntity gdThingListMaterialRelEntity = new GdThingListMaterialRelEntity();
            gdThingListMaterialRelEntity.setImplementListId(param.getImplementListId());
            gdThingListMaterialRelEntity.setMaterialId(materialId);
            gdThingListMaterialRelEntity.setSort(index);
            index += 1;
 
            gdThingListMaterialRelEntityList.add(gdThingListMaterialRelEntity);
        }
        return gdThingListMaterialRelEntityList;
    }
 
}