| | |
| | | package com.product.base.service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.product.base.config.BaseErrorCode; |
| | | import com.product.base.config.CmnConst; |
| | | import com.product.core.dao.BaseDao; |
| | | import com.product.core.entity.DataTableEntity; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.module.sys.entity.SystemUser; |
| | |
| | | * @return |
| | | */ |
| | | public DataTableEntity getMaterialTypeTree() { |
| | | return baseDao.listTable(CmnConst.PRODUCT_SYS_DICT, "dict_name=?", new Object[] {CmnConst.MATERIAL_TYPE}); |
| | | return baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL_TYPE); |
| | | } |
| | | |
| | | /** |
| | | * 新增材料类型 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public String saveMaterialType(FieldSetEntity fse) { |
| | | if (BaseUtil.strIsNull(fse.getUUID())) { |
| | | FieldSetEntity fseMaxValue = baseDao.getFieldSetEntityBySQL("SELECT IFNULL((MAX(material_type_value) + 1),0) material_type_value FROM product_project_base_material_type", new Object[] {}, false); |
| | | fse.setValue(CmnConst.MATERIAL_TYPE_VALUE, fseMaxValue.getString(CmnConst.MATERIAL_TYPE_VALUE)); |
| | | } else { |
| | | if ("0".equals(fse.getString(CmnConst.IS_USED))) { |
| | | StringBuilder sb = new StringBuilder(256); |
| | | sb.append("SELECT SUM(num)num FROM ( ") |
| | | .append(" select COUNT(*)num from product_project_budget A where a.material_type=? ") |
| | | .append(" UNION ALL ") |
| | | .append(" select COUNT(*)num from product_project_base_material WHERE FIND_IN_SET (?,material_type)>0 ") |
| | | .append(" )A "); |
| | | FieldSetEntity fseCount = baseDao.getFieldSetEntityBySQL(sb.toString(), new Object[] { fse.getString("material_type_value"),fse.getString("material_type_value") }, false); |
| | | if (fseCount.getInteger("num")<1) { |
| | | baseDao.executeUpdate("DELETE FROM product_project_base_material_type WHERE uuid=?", new Object[] {fse.getUUID()}); |
| | | return fse.getUUID(); |
| | | } |
| | | } |
| | | } |
| | | baseDao.saveFieldSetEntity(fse); |
| | | return fse.getUUID(); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (BaseUtil.strIsNull(fse.getString(CmnConst.MATERIAL_TYPE)) || fse.getInteger(CmnConst.MATERIAL_TYPE)==-1) { |
| | | dt = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, null, null, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); |
| | | }else { |
| | | dt = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, "material_type=?", new Object[] {fse.getInteger(CmnConst.MATERIAL_TYPE)}, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); |
| | | dt = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, "CONCAT(',',material_type,',') like ?", new Object[] {"%,"+fse.getInteger(CmnConst.MATERIAL_TYPE)+",%"}, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); |
| | | } |
| | | |
| | | baseDao.loadPromptData(dt); |
| | | return dt; |
| | | } |
| | | |
| | | /** |
| | | * 获取材料信息 |
| | | * @param uuid |
| | | * @return |
| | | */ |
| | | public FieldSetEntity getMaterialInfo(String uuid) { |
| | | return baseDao.getFieldSet(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, uuid, false); |
| | | } |
| | | |
| | | /** |
| | | * 保存材料信息 |
| | |
| | | * @return |
| | | */ |
| | | public boolean saveMaterialInfo(FieldSetEntity fse) { |
| | | |
| | | //验重条件 |
| | | String filter = "material_code=?"; |
| | | List<String> param = new ArrayList<>(); |
| | | param.add(fse.getString(CmnConst.MATERIAL_CODE)); |
| | | |
| | | SystemUser sysUser = SpringMVCContextHolder.getCurrentUser(); |
| | | if (BaseUtil.strIsNull(fse.getUUID())) { |
| | | BaseUtil.createCreatorAndCreationTime(sysUser, fse); |
| | | }else { |
| | | filter += " AND uuid !=?"; |
| | | param.add(fse.getUUID()); |
| | | BaseUtil.updatedRegeneratorAndUpdateTime(sysUser, fse); |
| | | } |
| | | FieldSetEntity fseExistMaterialCode = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, filter, param.toArray(), false); |
| | | if (fseExistMaterialCode!=null) { |
| | | throw new BaseException(BaseErrorCode.PROJECT_BASE_MATERIAL_CODE_REPEAT.getValue(), BaseErrorCode.PROJECT_BASE_MATERIAL_CODE_REPEAT.getText()); |
| | | } |
| | | return baseDao.saveFieldSetEntity(fse); |
| | | } |
| | | |
| | | /** |
| | | * 删除材料信息 |
| | | * @param uuid |
| | | * @return |
| | | */ |
| | | public boolean deleteMaterialInfo(String uuid) { |
| | | Object [] uuids= uuid.split(","); |
| | | return baseDao.delete(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, "uuid=?", uuids); |
| | | } |
| | | } |