📄 measureunitgroupdaoimpl.java
字号:
package com.cownew.PIS.basedata.bizLayer;
import java.sql.SQLException;
import java.util.List;
import com.cownew.PIS.basedata.common.IMeasureUnitDAO;
import com.cownew.PIS.basedata.common.IMeasureUnitGroupDAO;
import com.cownew.PIS.basedata.common.MeasureUnitException;
import com.cownew.PIS.basedata.common.MeasureUnitGroupInfo;
import com.cownew.PIS.basedata.common.MeasureUnitInfo;
import com.cownew.PIS.framework.bizLayer.BaseDAOImpl;
import com.cownew.PIS.framework.common.utils.KeyValueList;
import com.cownew.PIS.framework.server.helper.LocalServiceLocator;
import com.cownew.PIS.framework.server.helper.ServerSQLExecutorUtils;
import com.cownew.ctk.common.ExceptionUtils;
import com.cownew.ctk.constant.BigDecimalConst;
public class MeasureUnitGroupDAOImpl extends BaseDAOImpl implements
IMeasureUnitGroupDAO
{
public MeasureUnitGroupDAOImpl()
{
super();
}
protected Class getPersistObjectClass()
{
return MeasureUnitGroupInfo.class;
}
public void rename(String groupId, String newName)
throws MeasureUnitException
{
StringBuffer sql = new StringBuffer();
sql.append("update T_BD_MeasureUnitGroup ");
sql.append("set FName=? where FId=?");
try
{
ServerSQLExecutorUtils.execute(sql.toString(), new Object[] {
groupId, newName });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
public List getAllUnits(String groupId) throws MeasureUnitException
{
IMeasureUnitDAO muDAO = (IMeasureUnitDAO) LocalServiceLocator
.getInstance().getService(IMeasureUnitDAO.class);
KeyValueList kvList = new KeyValueList();
kvList.add("groupId", groupId);
List muList = muDAO.load("from " + MeasureUnitInfo.class.getName()
+ " where head.id=:groupId", kvList);
return muList;
}
public void setBaseUnit(String groupId, String unitId)
throws MeasureUnitException
{
if (!isInGroup(groupId, unitId))
{
throw new MeasureUnitException(MeasureUnitException.NOTINGROUP,
new Object[] { unitId, groupId });
}
// 修改以前的基本计量单位为非基本
StringBuffer sqlOther = new StringBuffer();
sqlOther.append("update T_BD_MeasureUnit ");
sqlOther.append("set FIsBaseUnit=? where FIsBaseUnit=? and FHeadId=?");
try
{
ServerSQLExecutorUtils.execute(sqlOther.toString(), new Object[] {
Boolean.FALSE, Boolean.TRUE, groupId });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
// 设置要设置的计量单位为基本,并且设置转换率为1
StringBuffer sql = new StringBuffer();
sql.append("update T_BD_MeasureUnit ");
sql.append("set FIsBaseUnit=?, FConvertRate=? where FId=?");
try
{
ServerSQLExecutorUtils.execute(sql.toString(), new Object[] {
Boolean.TRUE, BigDecimalConst.ONE, unitId });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
public MeasureUnitInfo getBaseUnit(String groupId)
throws MeasureUnitException
{
IMeasureUnitDAO muDAO = (IMeasureUnitDAO) LocalServiceLocator
.getInstance().getService(IMeasureUnitDAO.class);
KeyValueList kvList = new KeyValueList();
kvList.add("groupId", groupId);
List muList = muDAO.load("from " + MeasureUnitInfo.class.getName()
+ " where head.id=:groupId and isBaseUnit=true", kvList);
if (muList.size() == 1)
{
return (MeasureUnitInfo) muList.get(0);
} else if (muList.size() <= 0)
{
return null;
} else
{
throw new MeasureUnitException(
MeasureUnitException.BASEUNITUNUNIQUE);
}
}
public boolean hasBaseUnit(String groupId) throws MeasureUnitException
{
IMeasureUnitDAO muDAO = (IMeasureUnitDAO) LocalServiceLocator
.getInstance().getService(IMeasureUnitDAO.class);
KeyValueList kvList = new KeyValueList();
kvList.add("groupId", groupId);
return muDAO.exists("from " + MeasureUnitInfo.class.getName()
+ " where head.id=:groupId and isBaseUnit=true", kvList);
}
public boolean isInGroup(String groupId, String unitId)
throws MeasureUnitException
{
IMeasureUnitDAO muDAO = (IMeasureUnitDAO) LocalServiceLocator
.getInstance().getService(IMeasureUnitDAO.class);
KeyValueList kvList = new KeyValueList();
kvList.add("groupId", groupId);
kvList.add("unitId", unitId);
return muDAO.exists("from " + MeasureUnitInfo.class.getName()
+ " where head.id=:groupId and id=:unitId", kvList);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -