package com.mortals.xhx.module.pubdatum.web;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.pubdatum.model.PubdatumEntity;
import com.mortals.xhx.module.pubdatum.service.PubdatumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* 事项材料公共库
*
* @author zxfei
* @date 2022-11-10
*/
@RestController
@RequestMapping("pubdatum")
public class PubdatumController extends BaseCRUDJsonBodyMappingController<PubdatumService,PubdatumEntity,Long> {

    @Autowired
    private ParamService paramService;

    public PubdatumController(){
        super.setModuleDesc( "事项材料公共库");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        super.init(model, context);
    }


    @Override
    protected void doListBefore(PubdatumEntity query, Map<String, Object> model, Context context) throws AppException {
        if(!ObjectUtils.isEmpty(query.getMaterialName())){
            query.setMaterialName("%"+query.getMaterialName()+"%");
        }
        List<OrderCol> orderColList = new ArrayList<>();
        orderColList.add(new OrderCol("createTime", OrderCol.DESCENDING));
        query.setOrderColList(orderColList);
        super.doListBefore(query, model, context);
    }
}