package com.chenyang.nse.bussiness.dao.table.console;

import com.chenyang.nse.bussiness.dao.BaseDao;
import com.chenyang.nse.bussiness.entity.orm.table.console.TConsoleSort;
import java.util.List;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class TConsoleSortDao extends BaseDao<TConsoleSort, String> {
   public void sortSensitiveTypes(List<String> ids) {
      if (ids != null) {
         this.remove(new Criterion[]{Restrictions.eq("flag", "6")});
         this.getSession().flush();
         int index = 1;

         for(String id : ids) {
            TConsoleSort sort = new TConsoleSort();
            sort.setFlag("6");
            sort.setId(id);
            if (index < 10) {
               sort.setSortnum("00" + index);
            } else if (index < 100) {
               sort.setSortnum("0" + index);
            } else {
               sort.setSortnum("" + index);
            }

            this.save(sort);
            ++index;
         }
      }

   }
}
