package com.sifang.modules.sunshine.SystemSetting.utils;

import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.sunshine.SystemSetting.entity.CrmProjectSetting;
import com.sifang.modules.sys.common.entity.User;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public class ProjectInfoUtil {


    /**
     * 检索产品名称
     * @return
     */
    public static List<String> findProjectName(){
        return Db.query(" SELECT name from crm_project_setting  WHERE `status` = '0' ");
    }

    /**
     * 检索产品编号
     * @return
     */
    public static List<String> findProjectCode(){
        return Db.query(" SELECT code from crm_project_setting WHERE `status` = '0' ");
    }

    public static List<String> findProjectByCodeName(String name,String code,String pci){
        return Db.query(" SELECT code from crm_project_setting WHERE `status` = '0' and code = ? and name = ? and project_company_id = ? ",name,code,pci);
    }

    /**
     * 根据code获取产品信息
     * @param code
     * @return
     */

    public static List<CrmProjectSetting> findProjectByCode(String code){
        return Db.query(" SELECT * from crm_project_setting WHERE `status` = '0' and code = ? ",code);
    }

    public static int updateEpc(BigDecimal price, User user,String code){
        return Db.update("update crm_project_setting set epc_price = ?,update_by = ?,updator =? ,update_time = ? where code = ?",price,user.getId(),user.getUserName(),new Date(),code);
    }


    /**
     * 获取所属产品线
     */

    public static List<String> findProductLine(){
        return Db.query(" SELECT s.name FROM `crm_product_line_set` s  ");
    }


    /**
     * 获取项目id
     */

    public static List<String> getCompanyIdByCode(String code){
        return Db.query("  select id from crm_project_setting s  where  status = '0' and code = ? ",code);
    }

    //获取项目公司id

    public static String getCompanyByName(String name){
        return Db.queryStr("  SELECT id from crm_project_company_settings WHERE name = ? ",name);
    }

    public static String    getManagementTypeByName(String name){
        return Db.queryStr("   SELECT company_code from crm_project_company_settings WHERE name = ? ",name);
    }

    public static String getCompanyByCode(String code){
        return Db.queryStr("  SELECT id from crm_project_company_settings WHERE name = ? ",code);
    }




    /**
     * 获取项目公司id
     */

    public static String getCompanyFilingTypeByCode(String code){
        return Db.queryStr("  select filing_type from crm_project_setting s  where   code = ? ",code);
    }


    /**
     * 根据名称获取产品线id
     * @param name
     * @return
     */
    public static String getProductLineIdByName(String name){
        return Db.queryStr(" SELECT s.id FROM `crm_product_line_set` s where name = ? ",name);
    }

    /**
     * 所属epc公司
     * @return
     */
    public static List<String> findEpcCompany(){
        return Db.query("select s.name from crm_project_company_settings s where s.status='0' and type= '1' ");
    }
    public static String getEpcCompanyIdByName(String name){
        return Db.queryStr(" select s.id from crm_project_company_settings s where s.status='0' and type= '1' and name = ?",name);
    }


    public static String getInsuranceIdByName(String name){
        return Db.queryStr("SELECT id FROM crm_insurance_list  WHERE `status` = '0' and name = ?",name);
    }


    /**
     * 所属项目公司名称
     * @return
     */
    public static List<String> findCompanyList(){
        return Db.query(" select name from crm_project_company_settings s where s.status='0' and type = '0' ");
    }

    /**
     * 组件规格
     * @return
     */
    public static List<String> findAssemblySpecsList(){
        return Db.query("  SELECT DISTINCT(s.model) FROM `crm_electric_set` s WHERE s.status='0' AND s.type= '3' ORDER BY  CAST(model AS SIGNED) asc");
    }

    /**
     * 资方名称
     * @return
     */
    public static List<String> findPartnerList(){
        return Db.query("  SELECT name from  crm_partner where status = '0' ");
    }


    /**
     * 保险名称
     */
    public static List<String> findInsuranceNameList(String name){
        return Db.query("  SELECT a.name from crm_insurance_list a left join crm_project_company_settings b on a.policyholder=b.id  WHERE a.status = '0' and b.name = ?",name);
    }




}
