package com.th.demo.service.impl.ware;

import com.th.demo.mapping.ware.StoreDailyMapper;
import com.th.demo.model.system.Type;
import com.th.demo.model.ware.StoreDaily;
import com.th.demo.service.ware.StoreDailyService;
import com.th.demo.tools.JSONTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service("StoreDailyService")
public class StoreDailyServiceImpl implements StoreDailyService {
    @Autowired
    public StoreDailyMapper storeDailyMapper;
    String result = Type.FAIL;
    @Override
    public String query(String queryDate, String userId, String belongId) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        Date today = null;
        today = format.parse(queryDate);
        Calendar calDate = Calendar.getInstance();
        calDate.setTime(today);
        calDate.add(Calendar.DATE,-1);
        String yesterday = format.format(calDate.getTime());
        List<StoreDaily> storeDailyList = storeDailyMapper.query(queryDate,userId,belongId,yesterday);
        result = JSONTools.toString(storeDailyList);
        return result;
    }
}
