package com.ag.rate.tariff.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.ag.base.*;
import com.ag.entity.fee.*;
import com.ag.entity.fee.vo.ContractVO;
import com.ag.rate.tariff.dao.ContractDao;
import com.ag.rate.tariff.dao.TariffDao;
import com.ag.secp.platform.spring.SpringApplicationContext;
import com.ag.util.StrUtil;
import com.ag.util.TimeUtil;
import com.ag.util.UUIDUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/3 0003.
 */
@Service
public class ContractService extends BaseService {
    @Autowired
    private ContractDao contractDao;
    @Autowired
    private TariffDao tariffDao;

    @Autowired
    //return "C_" + toLower(tableName);表名带C_  类名不带C
    private BaseRepositoryImpl feeDao;
    @Autowired
    //return toLower(tableName);表名类名一致
    private DefaultBussniessImpl bizDao;

    /**
     * 查询合同
     */
    public String findAllContract(HttpServletRequest request){
        Contract contract = new Contract();
        contract.setTenancyId(super.getTenancyId(request));
        return contractDao.findAll(contract);
    }
    /**
     * 保存合同（附件上传在webBuilder中实现）
     * ScriptObjectMirror对象包含了所有的request和session中的属性值，通过serverScript中传入app.get()参数获得
     * so.get("id")等同于request.getParameter("id")
     * 不建议使用该参数，将来如果脱离webBuilder，后台java部分request可复用。
     * 但使用Wb.upload方法时request对象取不到数据，此时需要用到ScriptObjectMirror对象
     */
    public String saveContract(HttpServletRequest request, ScriptObjectMirror so){
        //Contract contract = new ParamUtil<Contract>().packPOJO(super.getRequestMap(request), Contract.class);
        Contract contract = new ParamUtil<Contract>().packPOJO(super.getScriptMap(so), Contract.class);
        contract.setId(UUIDUtil.getUUID());
        contract.setConfirmStatus(0);
        contract.setIsDefault(0);
        contract.setCalcFlag(1);
        contract.setDelFlag(0);
        if (contract.getExpiredDate() != null){
            contract.setExpiredDate(TimeUtil.getTimestamp(TimeUtil.getDate(contract.getExpiredDate()) + " 23:59:59"));
        }
        super.setSaveUser(request, contract);
        int num = contractDao.save(contract);
        if(num > 0 ){
            IRedisService service = (IRedisService) SpringApplicationContext.getBean("redisServiceImpl");
            service.refreshByDictName("C_CONTRACT");
        }
        ContractVO vo = new ContractVO();
        BeanUtils.copyProperties(contract, vo);
        vo.setDateFormat(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
        return JSON.toJSONString(vo);
    }

    /**
     * 修改合同
     */
    public String updateContract(HttpServletRequest request, ScriptObjectMirror so){
        Contract contract = new ParamUtil<Contract>().packPOJO(super.getScriptMap(so), Contract.class);
        if (contract.getExpiredDate() != null){
            contract.setExpiredDate(TimeUtil.getTimestamp(TimeUtil.getDate(contract.getExpiredDate()) + " 23:59:59"));
        }
        super.setUpdateUser(request, contract);
        int num = contractDao.update(contract, super.getRequestParam(request));
        if(num > 0 ){
            IRedisService service = (IRedisService) SpringApplicationContext.getBean("redisServiceImpl");
            service.refreshByDictName("C_CONTRACT");
        }
        ContractVO vo = new ContractVO();
        BeanUtils.copyProperties(contract, vo);
        vo.setDateFormat(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
        return JSON.toJSONString(vo);
    }

    /**
     * 删除合同
     */
    public int deleteContract(HttpServletRequest request, String id){
        Contract contract = new Contract();
        contract.setId(id);
        contract.setDelFlag(1);
        String[] updateCol = {"DEL_FLAG"};
        int num = contractDao.update(contract,updateCol);//删除合同，更新标识
        contractDao.deleteContractItem(id);//删除合同费目，更新标识
        tariffDao.deleteTariff(id);//删除费率，更新标识
        tariffDao.deleteRitemsByContract(id);//删除费率子表，更新标识
        tariffDao.deleteStepByContract(id);//删除费率阶梯，更新标识

        ContractItem contractItem = new ContractItem();
        contractItem.setContractId(id);
        contractItem.setDelFlag(0);
        List<ContractItem> ciLst = contractDao.findByContract(contractItem);//查询合同费目列表
        //复制合同费率
        Tariff tariff = new Tariff();
        tariff.setContractId(id);
        List<Tariff> tariffLst = tariffDao.findByContract(tariff);
        String ids = "";
        for(int j = 0;j<tariffLst.size();j++){
            ids = ids + tariffLst.get(j).getId() +',';//费率id集合 逗号分隔
        }
        for(int i=0;i<ciLst.size();i++){//循环费目
            handleLog(3, ciLst.get(i).getItemId(),id, ids,tariffLst,getSysUserName(request));
        }
        if(num > 0 ){
            IRedisService service = (IRedisService) SpringApplicationContext.getBean("redisServiceImpl");
            service.refreshByDictName("C_CONTRACT");
        }
        return num;
    }


    /**
     * 合同号查询费类
     */
    public String queryCateByContract(HttpServletRequest request){
        ContractCategory contractCategory = new ParamUtil<ContractCategory>().packPOJO(super.getRequestMap(request), ContractCategory.class);
        contractCategory.setTenancyId(super.getTenancyId(request));
        return contractDao.queryCateByContract(contractCategory);
    }

    /**
     * 保存合同费类
     */
    @Transactional
    public void saveContractCategory(HttpServletRequest request){
        String id = request.getParameter("ID");//合同号
        String ids = request.getParameter("ids");//费类号
        StringBuilder newIds = new StringBuilder();//新增id
        StringBuilder oldIds = new StringBuilder();//原始id
        //组织新增ids
        JSONArray ja = JSONArray.parseArray(ids);
        for(Object obj : ja.toArray()){
            newIds.append(obj.toString()).append(",");
        }
        //组织原始ids
        ContractCategory vo = new ContractCategory();
        vo.setTenancyId(super.getTenancyId(request));
        vo.setContractId(id);
        List<ContractCategory> oldLst = contractDao.findByContract(vo);
        for(ContractCategory old : oldLst){
            oldIds.append(old.getCategoryId()).append(",");
        }
        StrUtil.removeDu(oldIds, newIds);//old删除，new新增

        String saveIds = StrUtil.subRightString(newIds.toString(), ",");
        BaseCategory cate = new BaseCategory();
        cate.setTenancyId(super.getTenancyId(request));
        List<BaseCategory> cateLst = tariffDao.findByInIds(saveIds.replace(",", "','"), cate);
        List<ContractCategory> saveLst = new ArrayList<ContractCategory>();
        for(BaseCategory cateEny : cateLst){
            ContractCategory saveCC = new ContractCategory();
            saveCC.setId(UUIDUtil.getUUID());
            super.setSaveUser(request, saveCC);
            saveCC.setContractId(id);
            saveCC.setCategoryId(cateEny.getId());
            saveCC.setIsAll(cateEny.getIsAll());
            saveCC.setBizScope(cateEny.getBizScope());
            saveCC.setByagent(cateEny.getByagent());
            saveCC.setEffectived(cateEny.getEffectived());
            saveLst.add(saveCC);
        }

        contractDao.saveContCate(saveLst);
        if("".equals(oldIds.toString())){
            return;
        }
        List<ContractCategory> delLst = new ArrayList<>();
        String[] delIds = oldIds.toString().split(",");
        for(String delId : delIds){
            ContractCategory delCC = new ContractCategory();
            delCC.setTenancyId(super.getTenancyId(request));
            delCC.setCategoryId(delId);
            delCC.setContractId(id);
            delLst.add(delCC);
        }
        contractDao.delContCate(delLst, "TENANCY_ID","CATEGORY_ID","CONTRACT_ID");

    }

    /**
     * 合同号+费类 = 合同费目
     */
    public String queryItemByCate(HttpServletRequest request){
        ContractItem item = new ParamUtil<ContractItem>().packPOJO(super.getRequestMap(request), ContractItem.class);
        item.setTenancyId(super.getTenancyId(request));
        return contractDao.queryItemByCate(item);
    }

    /**
     * 保存合同费目(失效)
     */
    @Deprecated
    @Transactional
    public void saveContractItem(HttpServletRequest request){
        String contractId = request.getParameter("CONTRACT_ID");//合同号
        String categoryId = request.getParameter("CATEGORY_ID");//费类号
        String ids = request.getParameter("ids");//费目号
        StringBuilder newIds = new StringBuilder();//新增id
        StringBuilder oldIds = new StringBuilder();//原始id
        //组织新增ids
        JSONArray ja = JSONArray.parseArray(ids);
        for(Object obj : ja.toArray()){
            newIds.append(obj.toString()).append(",");
        }
        //组织原始ids
        ContractItem vo = new ContractItem();
        vo.setTenancyId(super.getTenancyId(request));
        vo.setContractId(contractId);
        vo.setCategoryId(categoryId);
        List<ContractItem> oldLst = contractDao.findByContract(vo);
        for(ContractItem old : oldLst){
            oldIds.append(old.getItemId()).append(",");
        }
        StrUtil.removeDu(oldIds, newIds);//old删除，new新增

        String saveIds = StrUtil.subRightString(newIds.toString(), ",").replace(",", "','");
        BaseChargingItem item = new BaseChargingItem();
        item.setTenancyId(super.getTenancyId(request));
        //增加合同费目
        List<BaseChargingItem> cateLst = tariffDao.findByInIds(saveIds, item);
        List<ContractItem> saveLst = new ArrayList<>();
        for(BaseChargingItem cateEny : cateLst){
            ContractItem saveCI = new ContractItem();
            BeanUtils.copyProperties(cateEny, saveCI);
            saveCI.setId(UUIDUtil.getUUID());
            super.setSaveUser(request, saveCI);
            saveCI.setContractId(contractId);
            saveCI.setCategoryId(categoryId);
            saveCI.setItemId(cateEny.getId());
            saveLst.add(saveCI);
        }
        contractDao.saveContItem(saveLst);


        //删除合同费目
        if("".equals(oldIds.toString())){
            return;
        }
        List<ContractItem> delLst = new ArrayList<ContractItem>();
        String[] delIds = oldIds.toString().split(",");
        for(String delId : delIds){
            ContractItem delCI = new ContractItem();
            delCI.setTenancyId(super.getTenancyId(request));
            delCI.setCategoryId(categoryId);
            delCI.setContractId(contractId);
            delCI.setItemId(delId);
            delLst.add(delCI);
        }
        contractDao.delContItem(delLst, "TENANCY_ID","CATEGORY_ID","CONTRACT_ID","ITEM_ID");

    }

    /**
     * 添加合同费目
     */
    @Transactional
    public void addContractItem(org.json.JSONObject json, HttpServletResponse response, HttpServletRequest request){
        String ids = json.getString("ids");
        String contractId = json.getString("CONTRACT_ID");//合同号
        List<BaseChargingItem> charges = feeDao.findInIds(BaseChargingItem.class, ids, "ID");
        List<ContractItem> items = new ArrayList<>();
        for (BaseChargingItem charge : charges){
            ContractItem item = new ContractItem();
            BeanUtils.copyProperties(charge, item);
            item.setId(UUIDUtil.getUUID());
            item.setContractId(contractId);
            item.setItemId(charge.getId());
            item.setLifeStatus(1);
            super.setSaveUser(request, item);
            items.add(item);
        }
        feeDao.saveAll(items);
    }

    /**
     * 删除合同费目
     */
    @Transactional
    public void delContractItem(org.json.JSONObject json, HttpServletResponse response, HttpServletRequest request){
        String[] ids = StrUtil.split(json.getString("ids"), ",");
        List<ContractItem> items = new ArrayList<>();
        for (String id : ids){
            ContractItem item = new ContractItem();
            item.setId(id);
            items.add(item);
        }
        feeDao.deleteAll(items, "ID");

        /*
        List<ContractItem> items = feeDao.findInIds(ContractItem.class, json.getString("ids"), "ID");
        SqlUtil sqlUtil = new SqlUtil();
        String itemIds = sqlUtil.getAddInIds(items, "id");
        List<ContractItemRule> itemRules = new ArrayList<>();
        for (ContractItem item : items){
            ContractItemRule rule = new ContractItemRule();
            BeanUtils.copyProperties(item, rule);
            itemRules.add(rule);
        }
        List<ContractItemRuleCondition> conditions = new ArrayList<>();
        for (ContractItem item : items){
            ContractItemRuleCondition condition = new ContractItemRuleCondition();
            BeanUtils.copyProperties(item, condition);
            conditions.add(condition);
        }
        */
    }


    /**
     * 合同号+费目 = 合同费率
     */
    public String findTariffByCategory(HttpServletRequest request){
        Tariff tariff = new ParamUtil<Tariff>().packPOJO(super.getRequestMap(request), Tariff.class);
        tariff.setTenancyId(super.getTenancyId(request));
        return tariffDao.findTariffByCategory(tariff);
    }

    /**
     * 合同复制
     */
    @Transactional
    public String copyContract(HttpServletRequest request, ScriptObjectMirror so){
//        String copyId = request.getParameter("COPY_ID");
        String copyId = String.valueOf(so.get("COPY_ID"));
        //新建合同
        Contract contract = new ParamUtil<Contract>().packPOJO(super.getScriptMap(so), Contract.class);
        contract.setId(UUIDUtil.getUUID());
        contract.setDelFlag(0);
        super.setSaveUser(request, contract);

        //复制合同费类
//        ContractCategory contractCategory = new ContractCategory();
//        contractCategory.setContractId(copyId);
//        contractCategory.setTenancyId(super.getTenancyId(request));
//        List<ContractCategory> ccLst = contractDao.findByContract(contractCategory);
//        for(ContractCategory contCate : ccLst){
//            contCate.setId(UUIDUtil.getUUID());
//            contCate.setContractId(contract.getId());
//            super.setSaveUser(request, contCate);
//        }

        //复制合同费目
        ContractItem contractItem = new ContractItem();
        contractItem.setContractId(copyId);
        contractItem.setDelFlag(0);
        //contractItem.setTenancyId(super.getTenancyId(request));
        List<ContractItem> ciLst = contractDao.findByContract(contractItem);
        for(ContractItem contItem : ciLst){
            contItem.setId(UUIDUtil.getUUID());
            contItem.setContractId(contract.getId());
            super.setSaveUser(request, contItem);
        }

        //复制合同费率
        Tariff tariff = new Tariff();
        tariff.setContractId(copyId);
        //tariff.setTenancyId(super.getTenancyId(request));
        List<Tariff> tariffLst = tariffDao.findByContract(tariff);
        //复制费率条件
        List<TariffRitem> ritems = tariffDao.findRitemsByContract(tariff);
        //复制阶梯费率
        List<TariffMultistep> steps = tariffDao.findStepByContract(tariff);

        for(Tariff tariffCpy : tariffLst){
            String tariffId = UUIDUtil.getUUID();
            for (TariffRitem ritem : ritems){
                if (tariffCpy.getId().equals(ritem.getRuleId())){
                    ritem.setRuleId(tariffId);
                    ritem.setId(UUIDUtil.getUUID());
                }
            }
            for (TariffMultistep step : steps){
                if (tariffCpy.getId().equals(step.getTariffId())){
                    step.setTariffId(tariffId);
                    step.setId(UUIDUtil.getUUID());
                }
            }
            tariffCpy.setId(tariffId);
            tariffCpy.setContractId(contract.getId());
            super.setSaveUser(request, tariffCpy);
        }

        //复制合同计费免费规则
//        ContractItemRule itemRule = new ContractItemRule();
//        itemRule.setContractId(copyId);
//        itemRule.setTenancyId(super.getTenancyId(request));
//        List<ContractItemRule> ruleLst = contractDao.findByContract(itemRule);
//        List<ContractItemRuleCondition> conditionLst = contractDao.findConditionByContract(itemRule);
//        changeId(ruleLst, conditionLst, contract.getId());

        int num = contractDao.save(contract);
        //contractDao.saveContCate(ccLst);
        contractDao.saveContItem(ciLst);
        tariffDao.saveTariff(tariffLst);
        tariffDao.saveRitem(ritems);
        tariffDao.saveStep(steps);
       // contractDao.saveContItemRule(ruleLst);
        //contractDao.saveContRuleCondition(conditionLst);
        for(ContractItem contItem : ciLst){
            Tariff tariffnew = new Tariff();
            tariffnew.setContractId(contract.getId());
            tariffnew.setChargingId(contItem.getItemId());
            tariffnew.setDelFlag(0);
            List<Tariff> tariffLstNew = tariffDao.findByItemIdAndContractId(tariffnew);//根据费目id及合同id查询费率
            String ids = "";
            for(int j = 0;j<tariffLstNew.size();j++){
                ids = ids + tariffLstNew.get(j).getId() +',';//费率id集合 逗号分隔
            }
            handleLog(1, contItem.getItemId(),contract.getId(), ids,tariffLstNew,getSysUserName(request));//添加删除费率日志
        }

        //刷新合同缓存
        if(num > 0 ){
            IRedisService service = (IRedisService) SpringApplicationContext.getBean("redisServiceImpl");
            service.refreshByDictName("C_CONTRACT");
        }
        return JSON.toJSONString(contract);
    }


    /**
     * 查询合同费类
     */
    public String queryContractByCategory(HttpServletRequest request, String categoryId){
        ContractCategory contractCategory = new ContractCategory();
        contractCategory.setTenancyId(super.getTenancyId(request));
        contractCategory.setCategoryId(categoryId);
        return contractDao.queryContractByCategory(contractCategory);
    }

    /**
     * 合同审核
     */
    public int verifyContract(HttpServletRequest request){
        Contract contract = new Contract();
        contract.setId(request.getParameter("ID"));
        super.setUpdateUser(request, contract);
        contract.setConfirmStatus(2);
        contract.setConfirmUser(contract.getUpdatedBy());
        contract.setConfirmDate(new Date());
        return contractDao.update(contract, null);
    }

    public int updateContCate(HttpServletRequest request) {
        ContractCategory entity = new ParamUtil<ContractCategory>().packPOJO(super.getRequestMap(request), ContractCategory.class);
        super.setUpdateUser(request, entity);
        return contractDao.update(entity, super.getRequestParam(request));
    }

    public int updateContItem(HttpServletRequest request) {
        ContractItem entity = new ParamUtil<ContractItem>().packPOJO(super.getRequestMap(request), ContractItem.class);
        super.setUpdateUser(request, entity);
        return contractDao.update(entity, super.getRequestParam(request));
    }


    /**
     * 保存合同选择的费目
     */
    @Transactional
    public void saveContractSelectItem(org.json.JSONObject json, HttpServletResponse response, HttpServletRequest request){
        String[] delIds = StrUtil.split(json.getString("delIds"), ",");
        String[] delItemIds = StrUtil.split(json.getString("delItemIds"), ",");
        String addIds = json.getString("addIds");
        String contractId = json.getString("contractId");//合同号
       //处理新增start
        List<BaseChargingItem> charges = feeDao.findInIds(BaseChargingItem.class, addIds, "ID");//查询基础费目其他信息
        List<ContractItem> items = new ArrayList<>();
        for (BaseChargingItem charge : charges){//组织合同费目数据
            ContractItem item = new ContractItem();
            BeanUtils.copyProperties(charge, item);
            item.setId(UUIDUtil.getUUID());
            item.setContractId(contractId);
            item.setItemId(charge.getId());
            item.setLifeStatus(1);
            item.setDelFlag(0);
            super.setSaveUser(request, item);
            items.add(item);
        }
        feeDao.saveAll(items);
        //处理新增end
        //处理删除start
        List<ContractItem> itemsDel = new ArrayList<>();
        for (String id : delIds){
            ContractItem item = new ContractItem();
            item.setId(id);
            item.setDelFlag(1);//删除标识
            itemsDel.add(item);
        }
        feeDao.updateAll(itemsDel, "ID");
        for (String itemId : delItemIds){
            Tariff tariff = new Tariff();
            tariff.setContractId(contractId);
            tariff.setChargingId(itemId);
            List<Tariff> tariffLst = tariffDao.findByItemIdAndContractId(tariff);//根据费目id及合同id查询费率
            String ids = "";
            for(int j = 0;j<tariffLst.size();j++){
                ids = ids + tariffLst.get(j).getId() +',';//费率id集合 逗号分隔
            }
            handleLog(3, itemId,contractId, ids,tariffLst,getSysUserName(request));//添加删除费率日志
            ContractItem contractItem = new ContractItem();
            contractItem.setContractId(contractId);
            contractItem.setItemId(itemId);
            tariffDao.deleteTariffByContractItem(contractItem);//删除费率，更新标识
            tariffDao.deleteRitemsByContractItem(contractItem);//删除费率子表，更新标识
            tariffDao.deleteStepByContractItem(contractItem);//删除费率阶梯，更新标识
        }
        //处理删除end
    }
    /**
     * 保存合同选择的客户
     */
    @Transactional
    public void saveContractSelectCustom(org.json.JSONObject json, HttpServletResponse response, HttpServletRequest request){
        String[] newIds = StrUtil.split(json.getString("newIds"), ",");
        String contractId = json.getString("contractId");//合同号
        List<ContractRelation> items = new ArrayList<>();
        for (String customerId : newIds){//组织合同客户数据
            ContractRelation item = new ContractRelation();
            item.setId(UUIDUtil.getUUID());
            item.setContractId(contractId);
            item.setCustomerId(customerId);
            item.setDelFlag(0);
            item.setCreatedOn(getNow());
            item.setCreatedBy(getSysUserName(request));
            items.add(item);
        }
        bizDao.saveAll(items);
    }
    /**
     * 保存合同选择的客户
     */
    @Transactional
    public void delContractSelectCustom(org.json.JSONObject json, HttpServletResponse response, HttpServletRequest request){
        String[] delIds = StrUtil.split(json.getString("delIds"), ",");//合同客户表主键id
        //处理删除start
        List<ContractRelation> itemsDel = new ArrayList<>();
        for (String id : delIds){
            ContractRelation item = new ContractRelation();
            item.setId(id);
            item.setDelFlag(1);//删除标识
            itemsDel.add(item);
        }
        bizDao.updateAll(itemsDel, "ID");
        //处理删除end
    }

    /**
     * 费率增删改日志
     */
    private void handleLog(Integer status, String itemId, String contractId, String ids, List<Tariff> tariffs, String userName){
        try {
            Contract contract = new Contract();
            contract.setId(contractId);
            BaseChargingItem item = new BaseChargingItem();
            item.setId(itemId);
            ItemProperties entity = new ItemProperties();
            entity.setItemId(itemId);
            contract = (Contract) feeDao.findById(contract, Contract.class, "ID");
            item = (BaseChargingItem) feeDao.findById(item, BaseChargingItem.class, "ID");
            List<TariffRitem> ritems = feeDao.findInIds(TariffRitem.class, ids, "RULE_ID");
            List<ItemProperties> properties = feeDao.findByEqCriteria(entity, ItemProperties.class, "ITEM_ID");

            List<TariffOperLog> logs = new ArrayList<>();
            for (Tariff tariff : tariffs){
                String note = "", rate = "";
                for (TariffRitem ritem : ritems){
                    if (ritem.getDelFlag() == null || ritem.getDelFlag() == 1){
                        continue;
                    }
                    if(ObjectUtil.equal(tariff.getId(), ritem.getRuleId())){
                        if (ObjectUtil.equal(ritem.getKeyName(), "RATE")){
                            rate = Convert.toStr(ritem.getCompareVal());
                        }
                    }

                    if (ObjectUtil.equal(tariff.getId(), ritem.getRuleId())){
                        for (ItemProperties propertie : properties){
                            if (ObjectUtil.equal(propertie.getPropertyCode(), ritem.getKeyName())){
                                note += propertie.getPropertyName() + ritem.getOperChar() + ritem.getCompareName() + ";";
                                break;
                            }
                        }
                    }
                }
                note = "[费率："+rate+"]" + note;
                if (status == 1){
                    note = "新增-->" + note;
                }else if(status == 2){
                    note = "修改<--" + note;
                }else if(status == 3){
                    note = "删除<--" + note;
                }
                TariffOperLog log = new TariffOperLog();
                log.setId(UUIDUtil.getUUID());
                log.setContractName(contract.getDescription());
                log.setItemName(item.getDescription());
                log.setCreatedBy(userName);
                log.setCreatedOn(new Date());
                log.setDescription(note);
                logs.add(log);
            }
            bizDao.saveAll(logs);
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
