package UIM; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Iterator; import java.util.List; import java.util.Map; import CoreFS.SA01.CoreIComponent; import CoreFS.SA06.CoreReturnObject; /** * 库存区域信息维护类 * * @author siy * @date 2010-8-4 */ public class UIM010010 extends CoreIComponent { /** * 查询区域信息 * * @param areaType * 区域类型 * @return CoreReturnObject * @throws SQLException */ public CoreReturnObject queryYardArea(Integer areaType) throws SQLException { CoreReturnObject cro = new CoreReturnObject(); // System.out.println("----------------------------------------"); // String sql=this.getDao("KgDao").LoadSqlByDB(Sqlid); String sql = "select area_no,area_name,decode(area_type,'1','冷轧原料库'," + "'2','冷轧中间库','3','冷轧成品库') area_type,decode(h_sail,'0','否'," + "'1','是') h_sail,reg_id,reg_time,remark from c_tbk08_coil_yard_area"; if (areaType.intValue() != 0) { sql += " where area_type = " + areaType.intValue(); } sql += " order by area_no"; cro = this.getDao("KgDao").ExcuteQuery(sql); System.out.println(cro); return cro; } /** * 新增区域 * @param areaType 区域类型 * @param areaName 区域名称 * @param hSail 是否可用于外卖 * @param remark 备注 * @param userName 操作人 * @return CoreReturnObject * @throws SQLException */ public CoreReturnObject addArea(Integer areaType, String areaName, String hSail, String remark, String userName) throws SQLException { CoreReturnObject cro = new CoreReturnObject(); long areaNo = queryMaxAreaNo() + 1; String regTime = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar .getInstance().getTime()); String addSql = "insert into c_tbk08_coil_yard_area (AREA_NO,AREA_NAME," + "AREA_TYPE,H_SAIL,REG_ID,REG_TIME,REMARK) values (" + areaNo + ",'" + areaName + "','" + areaType.intValue() + "','" + hSail + "'," + "'" + userName + "','" + regTime + "','" + remark + "')"; cro = this.getDao("KgDao").ExcuteNonQuery(addSql); return cro; } /** * 修改区域 * @param areaNo 区域编号 * @param areaType 区域类型 * @param areaName 区域名称 * @param hSail 是否可用于外卖 * @param remark 备注 * @param userName 操作人 * @return CoreReturnObject * @throws SQLException */ public CoreReturnObject updateArea(Long areaNo, Integer areaType, String areaName, String hSail, String remark, String userName) throws SQLException { CoreReturnObject cro = new CoreReturnObject(); String regTime = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar .getInstance().getTime()); String updSql = "update c_tbk08_coil_yard_area set area_name = ?,area_type = ?," + "h_sail = ?,mod_id = ?,mod_time = ?,remark = ? where area_no = ?"; cro = this.getDao("KgDao").ExcuteNonQuery(updSql,new Object[]{areaName,areaType, hSail,userName,regTime,remark,areaNo}); return cro; } /** * 删除区域信息 * * @param areaNos * 区域编号字符串(多个以‘|’分隔) * @return CoreReturnObject * @throws SQLException */ public CoreReturnObject delArea(String areaNos) throws SQLException { String[] areaNoArray = areaNos.split("\\|"); CoreReturnObject cro = new CoreReturnObject(); String sql = "delete from c_tbk08_coil_yard_area where area_no in ("; for (int i = 0; i < areaNoArray.length; i++) { if (i < areaNoArray.length - 1) { sql += Long.parseLong(areaNoArray[i]) + ","; } else { sql += Long.parseLong(areaNoArray[i]); } } sql += ")"; cro = this.getDao("KgDao").ExcuteNonQuery(sql); return cro; } /** * 判断区域下是否存在垛位 * * @param areaNo * 区域编号 * @return CoreReturnObject * @throws SQLException */ public CoreReturnObject hasYardInArea(Long areaNo) throws SQLException { long areaId = areaNo.longValue(); CoreReturnObject cro = new CoreReturnObject(); String sql = "select count(1) as count from c_tbk08_coil_yard y inner join " + "c_tbk08_coil_yard_area a on y.area_no = a.area_no and a.area_no = " + areaId; List list = this.getDao("KgDao").ExcuteQueryReturnList(sql, new Object[] {});// .ExcuteQuery(sql); int count = 0; Iterator it = list.iterator(); while (it.hasNext()) { Map map = (Map) it.next(); count = Integer.parseInt(map.get("count").toString()); } // System.out.println(count); cro.setResult(count); return cro; } private long queryMaxAreaNo() throws SQLException { String sql = "select max(AREA_NO) as area_no from c_tbk08_coil_yard_area"; List list = this.getDao("KgDao").ExcuteQueryReturnList(sql, new Object[] {});// .ExcuteQuery(sql); long areaNo = 0; Iterator it = list.iterator(); while (it.hasNext()) { Map map = (Map) it.next(); areaNo = Long.parseLong(map.get("area_no").toString()); } return areaNo; } }