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);
|
fs.remove("uuid");
|
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) {
|
if (fse.getString("del").equals("2")){
|
baseDao.delete(CmnConst.PRODUCT_PROJECT_BUSINESS_PLAN,"project_uuid=?",new String[]{fse.getUUID()});
|
}
|
return baseDao.saveFieldSetEntity(BaseUtil.createCreatorAndCreationTime(fse));
|
}
|
}
|