zm
2025-03-04 6e332c32f5121a372cecc8305e45f6571e4baa16
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
package com.product.contract.service;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.product.contract.config.CmnConst;
import com.product.contract.service.ide.IProjectBusinessService;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.transfer.Transactional;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
@Service
public class ProjectBusinessService extends AbstractBaseService implements IProjectBusinessService {
 
    @Autowired
    public BaseDao baseDao;
 
    @Override
    public JSONObject findProject(FieldSetEntity fse) {
        FieldSetEntity fsData = baseDao.getFieldSet(CmnConst.PRODUCT_PROJECT_BUSINESS, fse.getUUID(), false);
        //计算整体项目进度
        String sql ="SELECT CONCAT(sum(REPLACE(a.task_rate, '%', ''))/COUNT(*),'%') task_rate FROM `product_project_schedule_weekly_sub` a\n" +
                "LEFT JOIN  product_project_schedule_weekly b on a.main_uuid=b.uuid\n" +
                "where a.project_uuid=? and b.flow_flag =2 GROUP BY project_uuid";
        FieldSetEntity task_rate_fs = baseDao.getFieldSetEntityBySQL(sql, new String[]{fse.getUUID()}, false);
        if (!FieldSetEntity.isEmpty(task_rate_fs)){
            fsData.setValue("schedule",task_rate_fs.getString("task_rate"));
        }
        //封装项目计划数据接口
        JSONObject json = new JSONObject();
        DataTableEntity planData=baseDao.listTable(CmnConst.PRODUCT_PROJECT_BUSINESS_PLAN,"project_uuid=?",new String[]{fse.getUUID()});
        for (int i = 0; i <planData.getRows() ; i++) {
            FieldSetEntity fs = planData.getFieldSetEntity(i);
            JSONObject jsonObject = BaseUtil.fieldSetEntityToJson(fs);
            JSONArray projectTask = json.getJSONArray(fs.getString("project_task"));
            if (projectTask==null){
                JSONArray objects = new JSONArray();
                objects.add(jsonObject);
                json.put(fs.getString("project_task"),objects);
            }else {
                projectTask.add(jsonObject);
            }
        }
        JSONObject rejson=BaseUtil.fieldSetEntityToJson(fsData);
        rejson.put(CmnConst.PRODUCT_PROJECT_BUSINESS_PLAN,json);
        //封装项目进度数据结构
        DataTableEntity scheduleDt =baseDao.listTable("select  project_task_sub,a.*  from product_project_schedule a\n" +
                "LEFT JOIN product_project_business_plan b  on a.business_sub_uuid =b.uuid\n" +
                "where b.project_uuid=? order by a.business_sub_uuid,a.reporting_time",new String[]{fse.getUUID()});
        baseDao.loadPromptData(scheduleDt);
        rejson.put(CmnConst.PRODUCT_PROJECT_SCHEDULE,BaseUtil.dataTableEntityToJson(scheduleDt));
        //封装资料数据结构
        DataTableEntity dataList = baseDao.listTable(CmnConst.PRODUCT_PROJECT_MANAGER_DATA_LIST, "project_type=?", new String[]{fsData.getString("project_type")});
        rejson.put(CmnConst.PRODUCT_PROJECT_MANAGER_DATA_LIST,BaseUtil.dataTableEntityToJson(dataList));
        return rejson;
    }
    @Override
    public JSONObject findTranslate(FieldSetEntity fse) {
        FieldSetEntity fsData = baseDao.getFieldSetBySQL("SELECT project_type,date FROM product_project_business_translate where project_type=?", new String[]{fse.getString("project_type")}, false);
        JSONObject rejson=BaseUtil.fieldSetEntityToJson(fsData);
        DataTableEntity projectType = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BUSINESS_TRANSLATE, "project_type=? ORDER BY project_task", new String[]{fse.getString("project_type")});
        JSONObject json = new JSONObject();
        for (int i = 0; i < projectType.getRows(); i++) {
            FieldSetEntity fs = projectType.getFieldSetEntity(i);
            if (json.getJSONArray(fs.getString("project_task"))==null){
                JSONArray objects = new JSONArray();
                objects.add(BaseUtil.fieldSetEntityToJson(fs));
                json.put(fs.getString("project_task"),objects);
 
            }else {
                JSONArray projectTask = json.getJSONArray(fs.getString("project_task"));
                projectTask.add(BaseUtil.fieldSetEntityToJson(fs));
            }
        }
        rejson.put(CmnConst.PRODUCT_PROJECT_BUSINESS_TRANSLATE,json);
        
        
        return rejson;
    }
    @Transactional
    @Override
    public boolean saveTranslate(FieldSetEntity fs) {
        DataTableEntity dt = fs.getSubDataTable(CmnConst.PRODUCT_PROJECT_BUSINESS_TRANSLATE);
        boolean a=true;
        for (int i = 0; i < dt.getRows(); i++) {
            FieldSetEntity fse = dt.getFieldSetEntity(i);
            fse.setValue("project_type",fs.getString("project_type"));
            fse.setValue("date",fs.getString("date"));
            BaseUtil.createCreatorAndCreationTime(fse);
            if (fse.getUUID()==null){
                String uuid= baseDao.add(fse);
                if (uuid==null) a= false;
            }else if (fse.getString("~type~")!=null&&fse.getString("~type~").equals("del")){
                boolean delete = baseDao.delete(CmnConst.PRODUCT_PROJECT_BUSINESS_TRANSLATE, "uuid=?", new String[]{fse.getUUID()});
                if (!delete) a= false;
            }else {
                boolean update = baseDao.update(fse);
                if (!update) a= false;
            }
        }
        return a;
    }
    @Transactional
    @Override
    public boolean saveProject(FieldSetEntity fse) {
        return baseDao.saveFieldSetEntity(BaseUtil.createCreatorAndCreationTime(fse));
    }
}