|  |  |  | 
|---|
|  |  |  | import com.bstek.dorado.data.provider.Page; | 
|---|
|  |  |  | import com.ld.igds.models.InoutStockChange; | 
|---|
|  |  |  | import com.ld.igds.util.ContextUtil; | 
|---|
|  |  |  | import com.ld.igds.util.DateUtil; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.apache.commons.lang3.time.DateFormatUtils; | 
|---|
|  |  |  | import org.apache.commons.lang3.time.DateUtils; | 
|---|
|  |  |  | import org.hibernate.Session; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String str = (String) param.get("depotId"); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(str)) { | 
|---|
|  |  |  | hql += " and depotId =:depotId"; | 
|---|
|  |  |  | args.put("depotId", str); | 
|---|
|  |  |  | hql += " and depotIdIn =:depotIdIn or depotIdOut =:depotIdOut"; | 
|---|
|  |  |  | args.put("depotIdIn", str); | 
|---|
|  |  |  | args.put("depotIdOut", str); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | data.setUpdateTime(new Date()); | 
|---|
|  |  |  | data.setUpdateUser(ContextUtil.getLoginUserCName()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (null == data.getId()) { | 
|---|
|  |  |  | data.setId(ContextUtil.getUUID()); | 
|---|
|  |  |  | if (null == data.getCzbz()) { | 
|---|
|  |  |  | Map<String, Object> param = new HashMap<>(); | 
|---|
|  |  |  | param.put("dateTime", data.getChangeDate()); | 
|---|
|  |  |  | List<InoutStockChange> list = queryAll(param); | 
|---|
|  |  |  | int max = 0; | 
|---|
|  |  |  | if (list.size() != 0) { | 
|---|
|  |  |  | int num; | 
|---|
|  |  |  | for (InoutStockChange stockChange : list) { | 
|---|
|  |  |  | num = Integer.parseInt(stockChange.getId().substring(stockChange.getId().length() - 4)); | 
|---|
|  |  |  | max = Math.max(max, num); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String date = DateFormatUtils.format(new Date(), "yyyyMMdd"); | 
|---|
|  |  |  | data.setId(date + String.format("%04d", max + 1)); | 
|---|
|  |  |  | data.setCzbz("i"); | 
|---|
|  |  |  | session.save(data); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | data.setCzbz("u"); | 
|---|
|  |  |  | session.update(data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | session.close(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String delData(InoutStockChange data) { | 
|---|
|  |  |  | Session session = this.getSessionFactory().openSession(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<InoutStockChange> queryAll(Map<String, Object> param) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String hql = "from " + InoutStockChange.class.getName() + " where 1 = 1 "; | 
|---|
|  |  |  | Map<String, Object> args = new HashMap<String, Object>(); | 
|---|
|  |  |  | Date date = (Date) param.get("dateTime"); | 
|---|
|  |  |  | if (null != date) { | 
|---|
|  |  |  | hql += " and updateTime >= :startTime and updateTime < :endTime"; | 
|---|
|  |  |  | args.put("startTime", DateUtil.getCurZero(date)); | 
|---|
|  |  |  | args.put("endTime", DateUtil.getNextZero(date)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | hql += " order by  updateTime desc limit 20"; | 
|---|
|  |  |  | return this.query(hql, args); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|