张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
package com.thhy.secure.modules.biz.material.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.thhy.general.common.BasicResult;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.secure.modules.biz.file.service.FileService;
import com.thhy.secure.modules.biz.material.entity.TMaterial;
import com.thhy.secure.modules.biz.material.entity.TMaterialPath;
import com.thhy.secure.modules.biz.material.mapper.TMaterialMapper;
import com.thhy.secure.modules.biz.material.service.MaterialService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class MaterialServiceImpl implements MaterialService {
 
    @Resource
    private TMaterialMapper materialMapper;
 
    @Resource
    private FileService fileService;
 
 
    @Override
    @Transactional
    public BasicResult materialInsert(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        String userId = sysUserInfo.getUserId();
        values.put("companyId",companyId);
        values.put("materialId","");
        values.put("createUser",userId);
        materialMapper.materialInsert(values);
        //添加后的主键
        String materialId = values.get("materialId").toString();
        List<String> files = (List<String>) values.get("files");
        for (String file:files){
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("materialId",materialId);
            hashMap.put("materialPath",file);
            hashMap.put("materialPathId","");
            materialMapper.materialPathInsert(hashMap);
        }
        return BasicResult.success("添加成功");
    }
 
    @Override
    public BasicResult materialList(Map<String, Object> values) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        Integer pageSize = Integer.valueOf(values.get("pageSize").toString());
        Integer pageNum = Integer.valueOf(values.get("pageNum").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<TMaterial> materials = materialMapper.materialList(values);
        PageInfo<TMaterial> tMaterialPageInfo = new PageInfo<>(materials);
        return BasicResult.success(tMaterialPageInfo);
    }
 
    @Override
    public BasicResult materialInfo(Map<String, Object> values) {
 
        TMaterial material = materialMapper.materialInfo(values);
        List<TMaterialPath> materialPaths = materialMapper.materialPathList(material.getMaterialId());
        materialPaths.forEach(fl ->{
            JSONObject json = new JSONObject();
            json.put("fullpath",fl.getMaterialPath());
            BasicResult basicResult = fileService.fileinfo(json.toJSONString());
            if(basicResult.isSuccess()){
                JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString());
                for(Object obj : jsonArray){
                    JSONObject j = JSON.parseObject(obj.toString());
                    if(j.containsKey("name")&&"name".equals(j.getString("name"))){
                        fl.setMaterialPathName(j.getString("value"));
                    }
                }
            }
        });
        material.setMaterialPaths(materialPaths);
        return BasicResult.success(material);
    }
 
    @Override
    public BasicResult materialUpdate(Map<String, Object> values) {
 
        materialMapper.materialUpdate(values);
        String materialId = values.get("materialId").toString();
        materialMapper.materialPathDel(materialId);
 
        List<String> files = (List<String>) values.get("files");
        for (String file:files){
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("materialId",materialId);
            hashMap.put("materialPath",file);
            hashMap.put("materialPathId","");
            materialMapper.materialPathInsert(hashMap);
        }
        return BasicResult.success("修改成功");
    }
}