|
@@ -0,0 +1,158 @@
|
|
|
|
+package u8c.bs.upifsp.pub;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+
|
|
|
|
+import nc.bs.logging.Logger;
|
|
|
|
+import nc.jdbc.framework.processor.ColumnProcessor;
|
|
|
|
+import nc.vo.fa.base.LockCtl;
|
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
|
+import nc.vo.pub.lang.UFDate;
|
|
|
|
+
|
|
|
|
+public class UpifsTool {
|
|
|
|
+
|
|
|
|
+ // add by wya 生成时间
|
|
|
|
+ public static String GreatDate(Integer year, Integer month, Integer day) {
|
|
|
|
+ String ret_s = null;
|
|
|
|
+
|
|
|
|
+ String year_s = year.toString();
|
|
|
|
+
|
|
|
|
+ String month_s = "";
|
|
|
|
+ if (month < 10) {
|
|
|
|
+ month_s = "0" + month.toString();
|
|
|
|
+ } else {
|
|
|
|
+ month_s = month.toString();
|
|
|
|
+ }
|
|
|
|
+ String day_s = "";
|
|
|
|
+ if (day < 10) {
|
|
|
|
+ day_s = "0" + day.toString();
|
|
|
|
+ } else {
|
|
|
|
+ day_s = day.toString();
|
|
|
|
+ }
|
|
|
|
+ ret_s = year_s + "-" + month_s + "-" + day_s;
|
|
|
|
+
|
|
|
|
+ return ret_s;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 生成编号 billcode_s 单据号前段 billcode_e 单据号流水号
|
|
|
|
+ public static HashMap<String, String> GreatVbillcode(String zdname,
|
|
|
|
+ String billtype, UFDate nowdate, String tablename,String pk_defdoclist)
|
|
|
|
+ throws BusinessException {
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ HashMap<String, String> ret_s = new HashMap<String, String>();
|
|
|
|
+ Integer month = nowdate.getMonth();
|
|
|
|
+ Integer day = nowdate.getDay();
|
|
|
|
+ String month_s = "";
|
|
|
|
+ String day_s = "";
|
|
|
|
+ if (month < 10) {
|
|
|
|
+ month_s = "0" + month.toString();
|
|
|
|
+ } else {
|
|
|
|
+ month_s = month.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (day < 10) {
|
|
|
|
+ day_s = "0" + day.toString();
|
|
|
|
+ } else {
|
|
|
|
+ day_s = day.toString();
|
|
|
|
+ }
|
|
|
|
+ String billcode_s = billtype + nowdate.getYear() + month_s + day_s;
|
|
|
|
+
|
|
|
|
+ String sql_max = "select max(" + zdname + ") from " + tablename
|
|
|
|
+ + " where isnull(dr,0)=0 and pk_defdoclist in (select pk_defdoclist from bd_defdoclist where doclistcode in ('DC(定尺)','YS(颜色)'))";
|
|
|
|
+ Object max_o = UpifspProxy.getIUAPQueryBS().executeQuery(sql_max,
|
|
|
|
+ new ColumnProcessor());
|
|
|
|
+ if (max_o != null) {
|
|
|
|
+
|
|
|
|
+ String billcode_e = max_o.toString().substring(12, 18);
|
|
|
|
+
|
|
|
|
+ ret_s.put("billcode_s", billcode_s);
|
|
|
|
+ ret_s.put("billcode_e", billcode_e);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ ret_s.put("billcode_s", billcode_s);
|
|
|
|
+ ret_s.put("billcode_e", "000000");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ret_s;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ throw new BusinessException(e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //单据流水号转String
|
|
|
|
+ public static String ChangeIntToStr(Integer value) throws BusinessException {
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ String ret_s = "";
|
|
|
|
+ String value_s = value.toString();
|
|
|
|
+ if (value_s.length() < 6) {
|
|
|
|
+ for (int i = value_s.length(); i < 6; i++) {
|
|
|
|
+ value_s = "0" + value_s;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return value_s;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ throw new BusinessException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ * 加锁
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @param pk
|
|
|
|
+ * @param userId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String lockTable(String pk, String userId, String tablename) {
|
|
|
|
+ /** 加锁 **/
|
|
|
|
+ /* isLockedCard=true 表示加锁成功 , false表示该记录已被别人锁定 */
|
|
|
|
+ String res = "";
|
|
|
|
+ int lockedCount = 0;
|
|
|
|
+ while (true) {
|
|
|
|
+ boolean isLockedCard = LockCtl.lockPk(pk, userId, tablename);
|
|
|
|
+ if (isLockedCard) {
|
|
|
|
+ Logger.debug("用户[" + userId + "]锁定表[" + tablename + "]锁成功");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (lockedCount > 3) {// 重试三次
|
|
|
|
+ res = "该凭证正在被他人使用,请稍候再试";
|
|
|
|
+ Logger.debug("该凭证正在被他人使用,请稍候再试");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ Logger.debug("用户[" + userId + "]等待申请业务锁...");
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(2000);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ }
|
|
|
|
+ lockedCount++;
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ * 解锁
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static void freeLock(String pk, String userId, String tablename) {
|
|
|
|
+ /** 解锁 **/
|
|
|
|
+ LockCtl.freePk(pk, userId, tablename);
|
|
|
|
+ Logger.debug("释放业务锁成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|