package cn.ksource.web.service.impl; import java.util.Random; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import cn.ksource.core.dao.BaseDao; import cn.ksource.core.dao.SqlParameter; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.DateUtil; import cn.ksource.web.service.BillReportCodeService; @Service public class BillReportCodeServiceImpl implements BillReportCodeService { @Autowired private BaseDao baseDao; /** * 获取统一code,XXX-20150127-001 * @param type * @param serial * @return */ private String getUnityCode(String type, int serial) { return type + "-" + DateUtil.getCurrentDate8() + "-" + StringUtils.leftPad(String.valueOf(serial + 1), 3, '0'); } @Override public String getDailyOperationCode(String customerId) { String sql = "select count(1) as NUM from sc_daily_operation_record where CUSTOMER_ID=:customer_id and RECORD_DATE=:report_date"; SqlParameter param = new SqlParameter(); param.addValue("report_date", DateUtil.getCurrentDate8()); param.addValue("customer_id", customerId); int num = baseDao.queryForInteger(sql, param); return getUnityCode("RCYW", num); } @Override public String getDailyPatrolCode(String customerId) { String sql = "select count(1) as NUM from sc_daily_patrol_report where CUSTOMER_ID=:customer_id and REPORT_DATE=:report_date"; SqlParameter param = new SqlParameter(); param.addValue("report_date", DateUtil.getCurrentDate8()); param.addValue("customer_id", customerId); int num = baseDao.queryForInteger(sql, param); return getUnityCode("RCXJ", num); } @Override public String getDailyOperationWeeklyCode(String customerId) { String sql = "select count(1) as NUM from sc_daily_operation_weekly where CUSTOMER_ID=:customer_id "; SqlParameter param = new SqlParameter(); param.addValue("customer_id", customerId); int num = baseDao.queryForInteger(sql, param); return getUnityCode("YWZB", num); } @Override public String getCustomerSatisCode(String partnerId) { String sql = "select count(1) from customer_satis_info where PARTNER_ID=:partner_id "; SqlParameter param = new SqlParameter(); param.addValue("partner_id", partnerId); int num = baseDao.queryForInteger(sql, param); return getUnityCode("MYDDC", num); } }