ContractController.java 39 KB
Newer Older
manxiaoqiang committed
1 2
package common.controller;

kangxiaoshan committed
3
import common.model.*;
manxiaoqiang committed
4
import common.service.ContractService;
kangxiaoshan committed
5
import common.service.ShareIncomeService;
kangxiaoshan committed
6
import dic.AuthMenuEnmm;
kangxiaoshan committed
7
import dic.ContractStatusEnum;
manxiaoqiang committed
8
import dic.OperateObjectTypeEnum;
9
import offline.model.TrackFlowVO;
manxiaoqiang committed
10
import org.apache.commons.io.IOUtils;
kangxiaoshan committed
11 12 13
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14
import org.joda.time.DateTime;
2  
manxiaoqiang committed
15 16
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
manxiaoqiang committed
17
import org.springframework.beans.factory.annotation.Autowired;
manxiaoqiang committed
18 19
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
manxiaoqiang committed
20
import org.springframework.http.MediaType;
manxiaoqiang committed
21
import org.springframework.http.ResponseEntity;
manxiaoqiang committed
22 23
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
kangxiaoshan committed
24
import org.springframework.web.multipart.MultipartFile;
kangxiaoshan committed
25
import security.annotation.AuthKey;
manxiaoqiang committed
26
import security.annotation.CurrentAccount;
kangxiaoshan committed
27
import util.*;
manxiaoqiang committed
28

manxiaoqiang committed
29
import javax.servlet.http.HttpServletRequest;
manxiaoqiang committed
30
import javax.servlet.http.HttpServletResponse;
1  
kangxiaoshan committed
31
import java.io.*;
32
import java.math.BigDecimal;
kangxiaoshan committed
33
import java.net.URLEncoder;
34
import java.text.DecimalFormat;
lzxry committed
35
import java.util.*;
manxiaoqiang committed
36 37 38 39 40 41 42 43

/**
 * Created by mxq on 17/12/21.
 * 优先测试账号查询
 */
@Controller
@RequestMapping("{platform}/contract")
public class ContractController {
kangxiaoshan committed
44

2  
manxiaoqiang committed
45
    private static final Logger logger = LoggerFactory.getLogger(ContractController.class);
kangxiaoshan committed
46 47

    private static final Map<String, String> CONTRACT_STATUS = new HashMap<String, String>() {{
kangxiaoshan committed
48

kangxiaoshan committed
49 50 51 52
        putdata(this, ContractStatusEnum.WAIT);
        putdata(this, ContractStatusEnum.EXECUTING);
        putdata(this, ContractStatusEnum.END);
        putdata(this, ContractStatusEnum.CANCEL);
1  
kangxiaoshan committed
53
        putdata(this, ContractStatusEnum.NFORMAL);
kangxiaoshan committed
54 55
        putdata(this, ContractStatusEnum.SUSPEND);
        putdata(this, ContractStatusEnum.LATE);
kangxiaoshan committed
56 57 58
        putdata(this, ContractStatusEnum.BACK_ALL);
        putdata(this, ContractStatusEnum.BACK_NONE);
        putdata(this, ContractStatusEnum.BACK_PART);
kangxiaoshan committed
59 60
        putdata(this, ContractStatusEnum.MONEY_BACK_FIRST);
        putdata(this, ContractStatusEnum.DELETE);
kangxiaoshan committed
61 62 63
        putdata(this, ContractStatusEnum.FIRST_SIGNING);
        putdata(this, ContractStatusEnum.RENEWAL);
        putdata(this, ContractStatusEnum.SUPPLEMENTARY_AGREEMENT);
kangxiaoshan committed
64 65 66

    }};

kangxiaoshan committed
67

kangxiaoshan committed
68 69
    private static void putdata(Map map, ContractStatusEnum a) {
        map.put(a.getKey(), a.getValue());
kangxiaoshan committed
70 71
    }

manxiaoqiang committed
72 73 74
    @Autowired
    private ContractService service;

kangxiaoshan committed
75 76 77
    @Autowired
    private ShareIncomeService shareIncomeService;

manxiaoqiang committed
78 79
    @RequestMapping(value = "find", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
80
    @AuthKey(AuthMenuEnmm.CONTRACTMNG_V)
manxiaoqiang committed
81
    public ResultModel findAll(@CurrentAccount User loginAccount, @PathVariable String platform,
kangxiaoshan committed
82
                               @RequestParam String startDate, @RequestParam String endDate, String contractId) {
kangxiaoshan committed
83

kangxiaoshan committed
84
        return ResultModel.OK(service.findAll(loginAccount, startDate, endDate, platform, contractId));
manxiaoqiang committed
85 86
    }

kangxiaoshan committed
87
    @RequestMapping(value = "contractid/find", method = RequestMethod.GET)
kangxiaoshan committed
88 89
    @ResponseBody
    public ResultModel findOne(@CurrentAccount User loginAccount, @PathVariable String platform,
kangxiaoshan committed
90
                               String startDate, String endDate, String contractId) {
kangxiaoshan committed
91

kangxiaoshan committed
92
        return ResultModel.OK(service.findOne(loginAccount, startDate, endDate, platform, contractId));
kangxiaoshan committed
93 94 95
    }


kangxiaoshan committed
96
    @RequestMapping(value = "export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
manxiaoqiang committed
97
    @ResponseBody
kangxiaoshan committed
98
    @AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
kangxiaoshan committed
99
    public void export(@CurrentAccount User loginAccount, @PathVariable String platform, @RequestParam String startDate
kangxiaoshan committed
100 101
            , @RequestParam String endDate, HttpServletRequest request, HttpServletResponse response) {
        List<Contract> contractList = service.findAll(loginAccount, startDate, endDate, platform, null);
kangxiaoshan committed
102
        /*StringBuilder sb = new StringBuilder();
kangxiaoshan committed
103 104
        //录入时间 合同编号 客户账号 我方签约主体 签约方 行业分类 销售 开始日期 结束日期 套餐类型 合同金额 签约类型 合同状态 回款状态 关联合同
        sb.append("录入时间,合同编号,客户账号,我方签约主体,签约方,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同\r\n");
kangxiaoshan committed
105 106
        if (ValidateUtil.isValid(contractList)) {
            for (Contract c : contractList) {
kangxiaoshan committed
107 108
                sb.append(c.getDs()).append(",").
                        append(c.getContractCode()).append(",")
1  
kangxiaoshan committed
109
                        .append(c.getEmail() == null ? "无" : c.getEmail()).append(",")
kangxiaoshan committed
110 111 112 113 114 115 116 117 118 119
                        .append(c.getMyBodyName()).append(",")
                        .append(c.getCustomerBody()).append(",")
                        .append(c.getTradeName()).append(",")
                        .append(c.getSaleName()).append(",")
                        .append(c.getStartDate()).append(",")
                        .append(c.getEndDate()).append(",")
                        .append(c.getPriceLevelName()).append(",")
                        .append(c.getMoney()).append(",")
                        .append(CONTRACT_STATUS.get(c.getContractType())).append(",")
                        .append(CONTRACT_STATUS.get(c.getStatus())).append(",")
1  
kangxiaoshan committed
120
                        .append(CONTRACT_STATUS.get(c.getBackStatus() + "_back")).append(",")
1  
kangxiaoshan committed
121
                        .append(c.getRelationCode() == null ? "" : c.getRelationCode()).append(",")
kangxiaoshan committed
122
                        .append("\r\n");
manxiaoqiang committed
123 124
            }
        }
1  
kangxiaoshan committed
125
        String fileName = "合同管理_" + new DateTime(startDate).toString("yyyyMMdd") + "_" + new DateTime(endDate).toString("yyyyMMdd")
kangxiaoshan committed
126
                + ".csv";
kangxiaoshan committed
127 128 129 130 131 132 133 134 135
        this.exportWrite(fileName, sb.toString(), "合同管理", response);*/

        //创建工作薄对象
        HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
        //创建工作表对象
        HSSFSheet sheet = workbook.createSheet();
        //创建工作表的行
        HSSFRow row = sheet.createRow(0);

lzxry committed
136
        List<String> title;
lzxry committed
137
        if(platform.equals("tkio")){
lzxry committed
138
            title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同流量(万次),赠送流量(万次),合同金额,签约类型,合同状态,回款状态,关联合同,关联合同编号,补充协议签订日期"
lzxry committed
139 140 141 142
                    .split(","));
        }else{
            title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
                    .split(","));
lzxry committed
143
        }
kangxiaoshan committed
144 145 146 147 148 149 150 151 152 153 154 155 156
        int lineSize = title.size();
        for (int i = 0; i < lineSize; i++) {
            row.createCell(i).setCellValue(title.get(i));
        }

        for (int i = 0; i < contractList.size(); i++) {
            Contract contract = contractList.get(i);
            HSSFRow rowBody = sheet.createRow(i + 1);
            rowBody.createCell(0).setCellValue(new DateTime(contract.getCreateTime()).toString("yyyy-MM-dd"));
            rowBody.createCell(1).setCellValue(contract.getContractCode());
            rowBody.createCell(2).setCellValue(contract.getEmail() == null ? "无" : contract.getEmail());
            rowBody.createCell(3).setCellValue(contract.getMyBodyName());
            rowBody.createCell(4).setCellValue(contract.getCustomerBody());
lzxry committed
157 158 159 160 161 162 163 164
            rowBody.createCell(5).setCellValue(contract.getBarrioName());
            rowBody.createCell(6).setCellValue(contract.getBelongGroup());
            rowBody.createCell(7).setCellValue(contract.getTradeName());
            rowBody.createCell(8).setCellValue(contract.getSaleName());
            rowBody.createCell(9).setCellValue(contract.getStartDate());
            rowBody.createCell(10).setCellValue(contract.getEndDate());
            rowBody.createCell(11).setCellValue(contract.getPriceLevelName());

lzxry committed
165 166 167 168 169 170 171
            if(platform.equals("tkio")){
                rowBody.createCell(12).setCellValue(contract.getTrackFlow());
                rowBody.createCell(13).setCellValue(contract.getExtraFlow());
                rowBody.createCell(14).setCellValue(contract.getMoney());
                rowBody.createCell(15).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
                rowBody.createCell(16).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
                rowBody.createCell(17).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
lzxry committed
172 173 174
                rowBody.createCell(18).setCellValue(contract.getRelationCode() == null ? "无" : "有");
                rowBody.createCell(19).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
                rowBody.createCell(20).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
lzxry committed
175 176 177 178 179 180
            }else{
                rowBody.createCell(12).setCellValue(contract.getMoney());
                rowBody.createCell(13).setCellValue(CONTRACT_STATUS.get(contract.getContractType()));
                rowBody.createCell(14).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
                rowBody.createCell(15).setCellValue(CONTRACT_STATUS.get(contract.getBackStatus() + "_back"));
                rowBody.createCell(16).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
lzxry committed
181
            }
kangxiaoshan committed
182 183 184 185 186 187 188

        }

        String fileName = "合同管理_" + new DateTime(startDate).toString("yyyyMMdd")
                + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
        this.exportWrite(fileName, workbook, "合同管理_", response);

manxiaoqiang committed
189

kangxiaoshan committed
190
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), platform, "导出合同", startDate, endDate, request, platform);
manxiaoqiang committed
191
        userlog.start();
manxiaoqiang committed
192
        //返回文件字符串
kangxiaoshan committed
193
//        return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
manxiaoqiang committed
194 195
    }

kangxiaoshan committed
196
    @RequestMapping(value = "pay/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
manxiaoqiang committed
197
    @ResponseBody
kangxiaoshan committed
198
    @AuthKey(AuthMenuEnmm.COLLECTBILLLIST_EX)
kangxiaoshan committed
199 200 201
    public void exportPay(@CurrentAccount User loginAccount, @RequestParam String startDate, @RequestParam String endDate,
                          HttpServletRequest request, HttpServletResponse response, @PathVariable String platform,
                          String moneyType, String packageTypeSearch, String money_ids) {
kangxiaoshan committed
202
        List<ContractMoney> moneyList = service.findPayAll(loginAccount, startDate, endDate, platform, moneyType, packageTypeSearch, money_ids);
manxiaoqiang committed
203 204
        Map<String, String> map = new HashMap<>();
        map.put("pay", "收款");
kangxiaoshan committed
205
        map.put("invoice", "开票");
manxiaoqiang committed
206 207 208

        byte[] content = new byte[0];
        StringBuilder sb = new StringBuilder();
kangxiaoshan committed
209

kangxiaoshan committed
210
        Double parseSum = 0d;
kangxiaoshan committed
211 212
        if (ValidateUtil.isValid(moneyList)) {
            for (ContractMoney c : moneyList) {
kangxiaoshan committed
213
                sb.append(c.getDs()).append(",")
kangxiaoshan committed
214 215 216 217 218 219 220 221 222 223
                        .append(c.getContractCode() == null ? "" : c.getContractCode()).append(",")
                        .append(c.getEmail() == null ? "" : c.getEmail()).append(",")
                        .append(c.getCompany() == null ? "" : c.getCompany()).append(",")
                        .append(c.getPackageName() == null ? "" : c.getPackageName()).append(",")
                        .append(c.getSalseName() == null ? "" : c.getSalseName()).append(",")
                        .append(map.get(c.getType() == null ? "" : c.getType())).append(",")
                        .append(c.getMoney() == null ? "" : c.getMoney()).append(",")
                        .append(c.getCreateName() == null ? "" : c.getCreateName()).append("\r\n");

                if ("pay".equals(c.getType())) {
kangxiaoshan committed
224
                    // 付款
kangxiaoshan committed
225
                    parseSum += c.getMoney();
kangxiaoshan committed
226

kangxiaoshan committed
227
                } else {
kangxiaoshan committed
228 229
                    parseSum -= c.getMoney();
                }
manxiaoqiang committed
230
            }
kangxiaoshan committed
231

manxiaoqiang committed
232
        }
kangxiaoshan committed
233

kangxiaoshan committed
234 235 236 237
        StringBuffer titlebuffer = new StringBuffer();
        titlebuffer.append("日期, 合同编号 ,客户账号 ,签约方名称 ,套餐类型, 销售, 事项 ,金额 ,操作人 \r\n");
        titlebuffer.append("汇总,  - , -  ,  - ,  - ,  - ,  -  ,").append(parseSum).append(" , - \r\n");
        titlebuffer.append(sb);
kangxiaoshan committed
238

1  
kangxiaoshan committed
239 240 241
        String fileName = "收款开票_" + new DateTime(startDate).toString("yyyyMMdd")
                + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".csv";
        this.exportWrite(fileName, titlebuffer.toString(), "收款开票", response);
manxiaoqiang committed
242

manxiaoqiang committed
243
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), platform, "导出收款开票", startDate, endDate, request, platform);
manxiaoqiang committed
244
        userlog.start();
manxiaoqiang committed
245
        //返回文件字符串
kangxiaoshan committed
246
//        return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
manxiaoqiang committed
247 248
    }

manxiaoqiang committed
249 250 251 252 253 254
    @RequestMapping(value = "findone", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findOne(@CurrentAccount User loginAccount, @RequestParam String code) {
        return ResultModel.OK(service.findOne(code));
    }

manxiaoqiang committed
255 256
    @RequestMapping(value = "checkAccount", method = RequestMethod.GET)
    @ResponseBody
manxiaoqiang committed
257 258
    public ResultModel checkAccount(@CurrentAccount User loginAccount, @RequestParam String email, @PathVariable String platform) {
        return ResultModel.OK(service.checkAccount(email, platform));
manxiaoqiang committed
259 260
    }

manxiaoqiang committed
261 262 263 264
    @RequestMapping(value = "checkTime", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel checkTime(@RequestParam String type, @RequestParam String email,
                                 @RequestParam String platform, @RequestParam(required = false) String product) {
kangxiaoshan committed
265
        return ResultModel.OK(service.checkTime(email, platform, type, product));
manxiaoqiang committed
266 267
    }

manxiaoqiang committed
268 269
    @RequestMapping(value = "find/body", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
270
    public ResultModel findBody(@CurrentAccount User loginAccount, @PathVariable String platform, String dropall) {
kangxiaoshan committed
271

kangxiaoshan committed
272
        if ("all".equals(dropall)) {
kangxiaoshan committed
273 274 275
            platform = dropall;
        }

kangxiaoshan committed
276
        return ResultModel.OK(service.findBody(platform, loginAccount));
manxiaoqiang committed
277 278 279 280
    }

    @RequestMapping(value = "find/code", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
281
    public ResultModel findCode(@CurrentAccount User loginAccount, @RequestParam String code, @PathVariable String platform, String company) {
kangxiaoshan committed
282

kangxiaoshan committed
283
        return ResultModel.OK(service.getContractCode(code, platform, company));
manxiaoqiang committed
284 285 286 287
    }

    @RequestMapping(value = "find/pricelevel", method = RequestMethod.GET)
    @ResponseBody
manxiaoqiang committed
288 289
    public ResultModel findPricelevel(@CurrentAccount User loginAccount, @PathVariable String platform) {
        return ResultModel.OK(service.findSetmeal(platform));
manxiaoqiang committed
290 291
    }

manxiaoqiang committed
292 293 294 295 296 297
    @RequestMapping(value = "find/increment", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findIncrement(@CurrentAccount User loginAccount) {
        return ResultModel.OK(service.findIncrement());
    }

manxiaoqiang committed
298 299
    @RequestMapping(value = "find/rebat", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
300
    public ResultModel rebat(@CurrentAccount User loginAccount, @RequestParam String product, @RequestParam Integer level, @RequestParam Double money) {
manxiaoqiang committed
301 302 303 304 305 306 307 308 309 310 311 312
        return ResultModel.OK(service.getRebat(product, level, money));
    }

    @RequestMapping(value = "find/sale", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel rebat(@CurrentAccount User loginAccount) {
        return ResultModel.OK(service.getSales());
    }


    @RequestMapping(value = "create", method = RequestMethod.POST)
    @ResponseBody
manxiaoqiang committed
313
    public ResultModel create(@CurrentAccount User loginAccount, @RequestBody Contract contract, HttpServletRequest request, @PathVariable String platform) {
kangxiaoshan committed
314

manxiaoqiang committed
315
        Contract contract1 = service.create(loginAccount, contract);
kangxiaoshan committed
316
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "新建合同", "", contract1.toString(), request, platform);
manxiaoqiang committed
317
        userlog.start();
kangxiaoshan committed
318 319
//        ContractSendEmailThread email = new ContractSendEmailThread(contract);
//        email.start();
manxiaoqiang committed
320
        return ResultModel.OK(contract1);
manxiaoqiang committed
321
    }
manxiaoqiang committed
322 323 324

    @RequestMapping(value = "update", method = RequestMethod.PUT)
    @ResponseBody
kangxiaoshan committed
325
    @AuthKey(AuthMenuEnmm.CONTRACTMNG_M)
manxiaoqiang committed
326
    public ResultModel update(@CurrentAccount User loginAccount, @RequestBody Contract contract, HttpServletRequest request, @PathVariable String platform) {
kangxiaoshan committed
327 328

        String ip = IPAddrUtil.getIpAddrNew(request);
kangxiaoshan committed
329 330
        Contract contract1 = service.update(loginAccount, contract, ip);
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "修改合同", "", contract1.toString(), request, platform);
manxiaoqiang committed
331
        userlog.start();
kangxiaoshan committed
332

manxiaoqiang committed
333
        return ResultModel.OK(contract1);
manxiaoqiang committed
334 335 336 337
    }

    @RequestMapping(value = "pay", method = RequestMethod.POST)
    @ResponseBody
manxiaoqiang committed
338
    public ResultModel pay(@CurrentAccount User loginAccount, @RequestBody ContractMoney contract, HttpServletRequest request, @PathVariable String platform) {
manxiaoqiang committed
339
        ContractMoney contract1 = service.pay(loginAccount, contract);
kangxiaoshan committed
340
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "收款开票", "", contract1.toString(), request, platform);
manxiaoqiang committed
341 342
        userlog.start();
        return ResultModel.OK(contract1);
manxiaoqiang committed
343 344 345 346
    }

    @RequestMapping(value = "change", method = RequestMethod.POST)
    @ResponseBody
kangxiaoshan committed
347 348
    public ResultModel change(@CurrentAccount User loginAccount,
                              @RequestBody ContractChange contract, HttpServletRequest request, @PathVariable String platform) {
lzxry committed
349
        contract.setPlatform(platform);
kangxiaoshan committed
350 351
        Contract contract1 = service.change(loginAccount, contract, null);
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "修改套餐", "", contract1.toString(), request, platform);
manxiaoqiang committed
352 353
        userlog.start();
        return ResultModel.OK(contract1);
manxiaoqiang committed
354 355
    }

kangxiaoshan committed
356 357 358 359 360 361 362
    /**
     * @param loginAccount
     * @param startDate
     * @param endDate
     * @param code
     * @return
     */
manxiaoqiang committed
363 364 365 366 367 368 369 370 371 372 373 374 375 376
    @RequestMapping(value = "find/pay", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findPay(@CurrentAccount User loginAccount, @RequestParam String startDate,
                               @RequestParam String endDate, @RequestParam String code) {
        return ResultModel.OK(service.findPay(startDate, endDate, code));
    }

    @RequestMapping(value = "find/change", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findChange(@CurrentAccount User loginAccount, @RequestParam String startDate,
                                  @RequestParam String endDate, @RequestParam String code) {
        return ResultModel.OK(service.findChange(startDate, endDate, code));
    }

kangxiaoshan committed
377 378 379 380 381 382 383 384
    @RequestMapping(value = "find/flowchange", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel flowchange(@CurrentAccount User loginAccount, @RequestParam String startDate,
                                  @RequestParam String endDate, @RequestParam String code) {
        return ResultModel.OK(service.findflowChange(startDate, endDate, code));
    }


manxiaoqiang committed
385 386
    @RequestMapping(value = "update/pay", method = RequestMethod.PUT)
    @ResponseBody
kangxiaoshan committed
387 388 389 390
    public ResultModel updatePay(@CurrentAccount User loginAccount, @RequestBody ContractMoney contract, HttpServletRequest request,
                                 @PathVariable String platform) {

        String ip = IPAddrUtil.getIpAddrNew(request);
kangxiaoshan committed
391 392
        Contract contract1 = service.updatePay(loginAccount, contract, ip);
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "修改收款开票", "", contract1.toString(), request, platform);
manxiaoqiang committed
393 394
        userlog.start();
        return ResultModel.OK(contract1);
manxiaoqiang committed
395
    }
manxiaoqiang committed
396 397 398

    @RequestMapping(value = "find/payall", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
399
    @AuthKey(AuthMenuEnmm.COLLECTBILLLIST_V)
manxiaoqiang committed
400
    public ResultModel findPayAll(@CurrentAccount User loginAccount, @RequestParam String startDate,
kangxiaoshan committed
401 402 403
                                  @RequestParam String endDate, @PathVariable String platform,
                                  String moneyType, String packageTypeSearch, String money_ids) {
        return ResultModel.OK(service.findPayAll(loginAccount, startDate, endDate, platform, moneyType, packageTypeSearch, money_ids));
kangxiaoshan committed
404

manxiaoqiang committed
405
    }
manxiaoqiang committed
406

manxiaoqiang committed
407 408 409 410
    @RequestMapping(value = "build", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel build(@RequestBody Contract contract, HttpServletRequest request) {

2  
manxiaoqiang committed
411
        logger.error("tkiio---------------" + contract);
manxiaoqiang committed
412 413
        return ResultModel.OK(service.build(contract));
    }
manxiaoqiang committed
414

kangxiaoshan committed
415
    @RequestMapping(value = "trade", method = RequestMethod.GET)
kangxiaoshan committed
416
    @ResponseBody
kangxiaoshan committed
417
    public ResultModel baseCreate(@PathVariable String platform) {
kangxiaoshan committed
418 419 420 421
        return ResultModel.OK(service.getTradeData(platform));
    }


kangxiaoshan committed
422
    @RequestMapping(value = "code/all", method = RequestMethod.GET)
kangxiaoshan committed
423
    @ResponseBody
kangxiaoshan committed
424
    public ResultModel contractCodeAll(@PathVariable String platform, String contractId) {
kangxiaoshan committed
425

kangxiaoshan committed
426
        return ResultModel.OK(service.contractCodeAll(platform, contractId));
kangxiaoshan committed
427 428 429
    }


kangxiaoshan committed
430 431
    @RequestMapping(value = "setstaus", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
432
    @AuthKey(AuthMenuEnmm.CONTRACTMNG_D)
kangxiaoshan committed
433 434
    public ResultModel contractStatusUpdate(@PathVariable String platform, @CurrentAccount User loginUser,
                                            String contractId, String status, HttpServletRequest request) {
kangxiaoshan committed
435

kangxiaoshan committed
436
        String ip = IPAddrUtil.getIpAddrNew(request);
kangxiaoshan committed
437
        return ResultModel.OK(service.contractStatusUpdate(platform, contractId, status, ip, loginUser));
kangxiaoshan committed
438 439 440
    }


kangxiaoshan committed
441 442
    @RequestMapping(value = "codecheck", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
443
    public ResultModel codeCheck(@PathVariable String platform, String contractCode) {
kangxiaoshan committed
444

kangxiaoshan committed
445
        return ResultModel.OK(service.contractCodeCheck(platform, contractCode));
kangxiaoshan committed
446 447 448
    }


kangxiaoshan committed
449 450
    /**
     * 删除记录
kangxiaoshan committed
451
     *
kangxiaoshan committed
452 453 454 455 456 457
     * @param platform
     * @param
     * @return
     */
    @RequestMapping(value = "change/del", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
458 459 460
    public ResultModel changesDel(@PathVariable String platform, @CurrentAccount User loginAccount,
                                  String id, String type, HttpServletRequest request) {
        return ResultModel.OK(service.changesDel(platform, id, type, IPAddrUtil.getIpAddrNew(request), loginAccount));
kangxiaoshan committed
461 462 463

    }

464
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
kangxiaoshan committed
465
    @ResponseBody
kangxiaoshan committed
466
    public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform) {
467
        return service.uploadBatchInfo(file, platform);
kangxiaoshan committed
468
    }
kangxiaoshan committed
469

470
    @RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET)
kangxiaoshan committed
471 472 473 474 475
    @ResponseBody
    public ResultModel fileTempUrl() {
        return ResultModel.OK(Constant.importTempUrl);
    }

476 477 478 479 480 481 482 483 484 485 486 487
    /**
     * 分摊收入
     *
     * @param loginAccount
     * @param platform
     * @param startDate
     * @param endDate
     * @param serchName
     * @return
     */
    @RequestMapping(value = "/shareincome/list", method = RequestMethod.GET)
    @ResponseBody
488
    @AuthKey(AuthMenuEnmm.SHARED_INCOME_V)
489 490 491 492
    public ResultModel shareIncome(@CurrentAccount User loginAccount, @PathVariable String platform,
                                   @RequestParam String startDate, @RequestParam String endDate,
                                   String bodyCode, String serchName) {

kangxiaoshan committed
493
        return ResultModel.OK(shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName));
494 495 496 497 498

    }

    @RequestMapping(value = "/shareincome/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @ResponseBody
499
    @AuthKey(AuthMenuEnmm.SHARED_INCOME_E)
kangxiaoshan committed
500 501 502
    public void shareIncomeExport(@CurrentAccount User loginAccount, @PathVariable String platform,
                                  @RequestParam String startDate, @RequestParam String endDate,
                                  String bodyCode, String serchName, HttpServletResponse response, HttpServletRequest request) {
503

kangxiaoshan committed
504
        List<Contract> contracts = shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName);
kangxiaoshan committed
505
        //byte[] content = new byte[0];
lzxry committed
506

kangxiaoshan committed
507
        //StringBuilder sb = new StringBuilder();
kangxiaoshan committed
508
        /*sb.append("我方签约主体,签约方,合同编号,合同金额,不含税收入,合同开始时间,合同截止时间,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");*/
kangxiaoshan committed
509
        //sb.append("我方签约主体,签约方,合同编号,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");
lzxry committed
510 511 512
        HSSFWorkbook workbook;
        if(platform.equals("tkio")){
            workbook = createTKIOExcel(contracts);
lzxry committed
513 514
        }else if(platform.equals("adi")){
            workbook = createADIExcel(contracts);
lzxry committed
515 516
        }else{
            workbook = createCommonExcel(contracts);
kangxiaoshan committed
517 518 519 520 521 522 523 524 525 526
        }


        String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
                + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
        this.exportWrite(fileName, workbook, "分摊收入报表", response);



        /*if (ValidateUtil.isValid(contracts)) {
527
            for (Contract c : contracts) {
1  
kangxiaoshan committed
528 529 530
                sb.append(c.getMyBodyName()).append(",")
                        .append(c.getCustomerBody()).append(",")
                        .append(c.getContractCode()).append(",")
kangxiaoshan committed
531
                        .append(CONTRACT_STATUS.get(c.getStatus())).append(",")
1  
kangxiaoshan committed
532 533 534 535 536 537 538
                        .append("\"").append(df.format(c.getMoney())).append("\",")
                        .append("\"").append(df.format(c.getIncomeExcludingTax() * 1.0 / 100)).append("\",")
                        .append(c.getStartDate()).append(",")
                        .append(c.getEndDate()).append(",")
                        .append(c.getIntervalUseDays()).append(",")
                        .append("\"").append(df.format(c.getIntervaIncomeShare() * 1.0 / 100)).append("\",")
                        .append("\"").append(df.format(c.getAdjustmentFund() * 1.0 / 100)).append("\",")
kangxiaoshan committed
539
                        .append("\"").append(df.format(c.getIncomeShareAll() * 1.0 / 100)).append("\"")
540 541 542
                        .append("\r\n");
            }
        }
1  
kangxiaoshan committed
543 544
        String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
                + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".csv";
kangxiaoshan committed
545 546 547 548
        this.exportWrite(fileName, sb.toString(), "分摊收入报表", response);*/

    }

lzxry committed
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
    private HSSFWorkbook createADIExcel(List<Contract> contracts) {
        DecimalFormat df = new DecimalFormat("##,##0.00");
        //创建工作薄对象
        HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
        //创建工作表对象
        HSSFSheet sheet = workbook.createSheet();
        //创建工作表的行
        HSSFRow row = sheet.createRow(0);

        List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,套餐类型,区间使用天数,区间分摊收入,调整额,分摊总收入"
                .split(","));

        int lineSize = title.size();
        for (int i = 0; i < lineSize; i++) {
            row.createCell(i).setCellValue(title.get(i));
        }

        for (int i = 0; i < contracts.size(); i++) {
            Contract contract = contracts.get(i);
            HSSFRow rowBody = sheet.createRow(i + 1);
            rowBody.createCell(0).setCellValue(contract.getMyBodyName());
            rowBody.createCell(1).setCellValue(contract.getCustomerBody());
            rowBody.createCell(2).setCellValue(contract.getContractCode());
            rowBody.createCell(3).setCellValue(contract.getBarrioName());
            rowBody.createCell(4).setCellValue(contract.getBelongGroup());
            rowBody.createCell(5).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
            rowBody.createCell(6).setCellValue(df.format(contract.getMoney()));
            rowBody.createCell(7).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
            rowBody.createCell(8).setCellValue(contract.getStartDate());
            rowBody.createCell(9).setCellValue(contract.getEndDate());
1  
lzxry committed
579
            rowBody.createCell(10).setCellValue(contract.getPriceLevelName());
lzxry committed
580 581 582 583 584 585 586 587
            rowBody.createCell(11).setCellValue(contract.getIntervalUseDays());
            rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
            rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
            rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
        }
        return workbook;
    }

lzxry committed
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
    private HSSFWorkbook createCommonExcel(List<Contract> contracts){
        DecimalFormat df = new DecimalFormat("##,##0.00");
        //创建工作薄对象
        HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
        //创建工作表对象
        HSSFSheet sheet = workbook.createSheet();
        //创建工作表的行
        HSSFRow row = sheet.createRow(0);

        List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入"
                .split(","));

        int lineSize = title.size();
        for (int i = 0; i < lineSize; i++) {
            row.createCell(i).setCellValue(title.get(i));
        }

        for (int i = 0; i < contracts.size(); i++) {
            Contract contract = contracts.get(i);
            HSSFRow rowBody = sheet.createRow(i + 1);
            rowBody.createCell(0).setCellValue(contract.getMyBodyName());
            rowBody.createCell(1).setCellValue(contract.getCustomerBody());
            rowBody.createCell(2).setCellValue(contract.getContractCode());
            rowBody.createCell(3).setCellValue(contract.getBarrioName());
            rowBody.createCell(4).setCellValue(contract.getBelongGroup());
            rowBody.createCell(5).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
            rowBody.createCell(6).setCellValue(df.format(contract.getMoney()));
            rowBody.createCell(7).setCellValue(df.format(contract.getIncomeExcludingTax() * 1.0 / 100));
            rowBody.createCell(8).setCellValue(contract.getStartDate());
            rowBody.createCell(9).setCellValue(contract.getEndDate());
            rowBody.createCell(10).setCellValue(contract.getIntervalUseDays());
            rowBody.createCell(11).setCellValue(df.format(contract.getIntervaIncomeShare() * 1.0 / 100));
            rowBody.createCell(12).setCellValue(df.format(contract.getAdjustmentFund() * 1.0 / 100));
            rowBody.createCell(13).setCellValue(df.format(contract.getIncomeShareAll() * 1.0 / 100));
        }
        return workbook;
    }
    private HSSFWorkbook createTKIOExcel(List<Contract> contracts){
        DecimalFormat df = new DecimalFormat("##,##0.00");
        DecimalFormat df2 = new DecimalFormat("##,##0.0000");
        //创建工作薄对象
        HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name
        //创建工作表对象
        HSSFSheet sheet = workbook.createSheet();
        //创建工作表的行
        HSSFRow row = sheet.createRow(0);

lzxry committed
635
        List<String> title = Arrays.asList("我方签约主体,签约方,合同编号,行政区域,隶属集团,合同开始日期,合同截止日期,合同状态,合同金额(元),合同流量(万次),单价(元/万次),区间点击数(万次),区间分摊收入(元),区间调整金额(元),区间总收入(元),累计总收入(元),赠送点击量(万次),关联合同编号,补充协议签订日期"
lzxry committed
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
                .split(","));

        int lineSize = title.size();
        for (int i = 0; i < lineSize; i++) {
            row.createCell(i).setCellValue(title.get(i));
        }

        for (int i = 0; i < contracts.size(); i++) {
            Contract contract = contracts.get(i);
            HSSFRow rowBody = sheet.createRow(i + 1);
            rowBody.createCell(0).setCellValue(contract.getMyBodyName());
            rowBody.createCell(1).setCellValue(contract.getCustomerBody());
            rowBody.createCell(2).setCellValue(contract.getContractCode());
            rowBody.createCell(3).setCellValue(contract.getBarrioName());
            rowBody.createCell(4).setCellValue(contract.getBelongGroup());
            rowBody.createCell(5).setCellValue(contract.getStartDate());
            rowBody.createCell(6).setCellValue(contract.getEndDate());
            rowBody.createCell(7).setCellValue(CONTRACT_STATUS.get(contract.getStatus()));
            rowBody.createCell(8).setCellValue(df.format(contract.getMoney()));
            rowBody.createCell(9).setCellValue(contract.getTrackFlow());
lzxry committed
656
            rowBody.createCell(10).setCellValue(contract.getUnitPrice()==null?0:contract.getUnitPrice());
lzxry committed
657
            rowBody.createCell(11).setCellValue(contract.getClickFlow()==null?0.0:contract.getClickFlow());
lzxry committed
658 659 660 661 662
            rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare()==null?0:contract.getIntervaIncomeShare() / 100.0));
            rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund()==null?0:contract.getAdjustmentFund() / 100.0));
            rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll()==null?0:contract.getIncomeShareAll() / 100.0));
            rowBody.createCell(15).setCellValue(df.format(contract.getIncomeGross()==null?0:contract.getIncomeGross() / 100.0));
            rowBody.createCell(16).setCellValue(df2.format(contract.getExtraFlow()==null?0:contract.getExtraFlow() / 10000.0));
lzxry committed
663 664
            rowBody.createCell(17).setCellValue(contract.getRelationCode() == null ? "" : contract.getRelationCode());
            rowBody.createCell(18).setCellValue(contract.getSignedDate() == null ? "" : contract.getSignedDate());
lzxry committed
665 666 667 668
        }
        return workbook;
    }

kangxiaoshan committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
    private void exportWrite(String fileName, HSSFWorkbook workbook, String exportName, HttpServletResponse response) {
        OutputStream os = null;
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
            response.setHeader("filename", fileName);
            response.setHeader("content-disposition", "attachment; filename=" + fileName);
            response.setHeader("Content-Type", "text/xls");
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setCharacterEncoding("UTF-8");
            os = response.getOutputStream();
            workbook.write(os);
            os.flush();
        } catch (Exception e) {
            logger.error(exportName + "报错", e);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    logger.error(exportName + "导出,关闭流报错", e);
                }
            }
kangxiaoshan committed
691

kangxiaoshan committed
692
        }
kangxiaoshan committed
693 694 695 696
    }

    private void exportWrite(String fileName, String text, String exportName, HttpServletResponse response) {
        OutputStream os = null;
kangxiaoshan committed
697 698 699 700 701 702
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
            response.setHeader("filename", fileName);
            response.setHeader("content-disposition", "attachment; filename=" + fileName);
            response.setHeader("Content-Type", "text/csv");
            response.setContentType("APPLICATION/OCTET-STREAM");
1  
kangxiaoshan committed
703
            response.setCharacterEncoding("UTF-8");
kangxiaoshan committed
704
            os = response.getOutputStream();
1  
kangxiaoshan committed
705
            os.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
kangxiaoshan committed
706
            os.write(text.getBytes("UTF-8"));
1  
kangxiaoshan committed
707
            os.flush();
kangxiaoshan committed
708
        } catch (Exception e) {
kangxiaoshan committed
709
            logger.error(exportName + "报错", e);
kangxiaoshan committed
710
        } finally {
1  
kangxiaoshan committed
711
            if (os != null) {
kangxiaoshan committed
712
                try {
1  
kangxiaoshan committed
713
                    os.close();
kangxiaoshan committed
714
                } catch (IOException e) {
kangxiaoshan committed
715
                    logger.error(exportName + "导出,关闭流报错", e);
kangxiaoshan committed
716 717
                }
            }
718

kangxiaoshan committed
719
        }
720
    }
kangxiaoshan committed
721

lzxry committed
722 723 724 725 726 727 728 729 730 731 732
    /**
     * 功能描述:新建合同回显、获取行政区域列表
     * @author liyin
     * @date 2020/9/23
     */
    @GetMapping("/getBarrioCities")
    @ResponseBody
    public ResultModel getBarrioCities(){

        return ResultModel.OK(service.getBarrioCities());
    }
lzxry committed
733 734 735 736 737 738 739 740 741 742 743
    @GetMapping("/getDate")
    @ResponseBody
    public ResultModel getDate(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("new date",new Date().getTime());
        map.put("getBeforeDays(1)",DateUtil.getBeforeDays(1));
        map.put("getBeforeDays(0)",DateUtil.getBeforeDays(0));
        map.put("getCurrentDateStr",DateUtil.getCurrentDateStr());

        return ResultModel.OK(map);
    }
lzxry committed
744 745


746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
    /**
     *  试用流量
     */
    @GetMapping(value = "/trialFlow")
    @ResponseBody
    @AuthKey(AuthMenuEnmm.SHARED_INCOME_V)
    public ResultModel trialFlow(@CurrentAccount User loginAccount, @PathVariable String platform,
                                 @RequestParam String startDate, @RequestParam String endDate,
                                 String email) {

        return ResultModel.OK(shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform,email));

    }


    /**
     * 试用流量导出
     */
    @GetMapping(value = "trialFlowExport", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
    public void trialFlowExport(@CurrentAccount User loginAccount, @PathVariable String platform,
                                @RequestParam String startDate, @RequestParam String endDate,String email, HttpServletRequest request, HttpServletResponse response) {
        List<TrackFlowVO> list = shareIncomeService.trialFlow(loginAccount, startDate, endDate, platform, email);
        List<String> title = Arrays.asList("主账号,流量(万次)".split(","));
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();
        HSSFRow row = sheet.createRow(0);
        int lineSize = title.size();
        for (int i = 0; i < lineSize; i++) {
            row.createCell(i).setCellValue(title.get(i));
        }
        for (int i = 0; i < list.size(); i++) {
            TrackFlowVO flow = list.get(i);
            HSSFRow rowBody = sheet.createRow(i + 1);
            rowBody.createCell(0).setCellValue(flow.getEmail());
            rowBody.createCell(1).setCellValue(flow.getTrackFlow());
        }
        String fileName = "试用流量_" + new DateTime(startDate).toString("yyyyMMdd")+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ".xls";
        this.exportWrite(fileName, workbook, "试用流量_", response);
    }
manxiaoqiang committed
786
}