ContractController.java 32.7 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;
manxiaoqiang committed
9
import org.apache.commons.io.IOUtils;
kangxiaoshan committed
10 11 12
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
13
import org.joda.time.DateTime;
2  
manxiaoqiang committed
14 15
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
manxiaoqiang committed
16
import org.springframework.beans.factory.annotation.Autowired;
manxiaoqiang committed
17 18
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
manxiaoqiang committed
19
import org.springframework.http.MediaType;
manxiaoqiang committed
20
import org.springframework.http.ResponseEntity;
manxiaoqiang committed
21 22
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
kangxiaoshan committed
23
import org.springframework.web.multipart.MultipartFile;
kangxiaoshan committed
24
import security.annotation.AuthKey;
manxiaoqiang committed
25
import security.annotation.CurrentAccount;
kangxiaoshan committed
26
import util.*;
manxiaoqiang committed
27

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

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

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

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

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

    }};

kangxiaoshan committed
69

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

manxiaoqiang committed
74 75 76
    @Autowired
    private ContractService service;

kangxiaoshan committed
77 78 79
    @Autowired
    private ShareIncomeService shareIncomeService;

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

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

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

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


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

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

lzxry committed
138
        List<String> title = Arrays.asList("录入时间,合同编号,客户账号,我方签约主体,签约方,行政区域,隶属集团,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,回款状态,关联合同"
kangxiaoshan committed
139
                .split(","));
lzxry committed
140 141 142
        if(platform.equals("tkio")){
            title.add("总点击次数(万次)");
        }
kangxiaoshan committed
143 144 145 146 147 148 149 150 151 152 153 154 155
        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
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            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());
            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());
            if(platform.equals("tkio")){
                rowBody.createCell(17).setCellValue(contract.getTrackFlow());

            }
kangxiaoshan committed
172 173 174 175 176 177 178

        }

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

manxiaoqiang committed
179

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

kangxiaoshan committed
186
    @RequestMapping(value = "pay/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
manxiaoqiang committed
187
    @ResponseBody
kangxiaoshan committed
188
    @AuthKey(AuthMenuEnmm.COLLECTBILLLIST_EX)
kangxiaoshan committed
189 190 191
    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
192
        List<ContractMoney> moneyList = service.findPayAll(loginAccount, startDate, endDate, platform, moneyType, packageTypeSearch, money_ids);
manxiaoqiang committed
193 194
        Map<String, String> map = new HashMap<>();
        map.put("pay", "收款");
kangxiaoshan committed
195
        map.put("invoice", "开票");
manxiaoqiang committed
196 197 198

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

kangxiaoshan committed
200
        Double parseSum = 0d;
kangxiaoshan committed
201 202
        if (ValidateUtil.isValid(moneyList)) {
            for (ContractMoney c : moneyList) {
kangxiaoshan committed
203
                sb.append(c.getDs()).append(",")
kangxiaoshan committed
204 205 206 207 208 209 210 211 212 213
                        .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
214
                    // 付款
kangxiaoshan committed
215
                    parseSum += c.getMoney();
kangxiaoshan committed
216

kangxiaoshan committed
217
                } else {
kangxiaoshan committed
218 219
                    parseSum -= c.getMoney();
                }
manxiaoqiang committed
220
            }
kangxiaoshan committed
221

manxiaoqiang committed
222
        }
kangxiaoshan committed
223

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

1  
kangxiaoshan committed
229 230 231
        String fileName = "收款开票_" + new DateTime(startDate).toString("yyyyMMdd")
                + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".csv";
        this.exportWrite(fileName, titlebuffer.toString(), "收款开票", response);
manxiaoqiang committed
232

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

manxiaoqiang committed
239 240 241 242 243 244
    @RequestMapping(value = "findone", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findOne(@CurrentAccount User loginAccount, @RequestParam String code) {
        return ResultModel.OK(service.findOne(code));
    }

manxiaoqiang committed
245 246
    @RequestMapping(value = "checkAccount", method = RequestMethod.GET)
    @ResponseBody
manxiaoqiang committed
247 248
    public ResultModel checkAccount(@CurrentAccount User loginAccount, @RequestParam String email, @PathVariable String platform) {
        return ResultModel.OK(service.checkAccount(email, platform));
manxiaoqiang committed
249 250
    }

manxiaoqiang committed
251 252 253 254
    @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
255
        return ResultModel.OK(service.checkTime(email, platform, type, product));
manxiaoqiang committed
256 257
    }

manxiaoqiang committed
258 259
    @RequestMapping(value = "find/body", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
260
    public ResultModel findBody(@CurrentAccount User loginAccount, @PathVariable String platform, String dropall) {
kangxiaoshan committed
261

kangxiaoshan committed
262
        if ("all".equals(dropall)) {
kangxiaoshan committed
263 264 265
            platform = dropall;
        }

kangxiaoshan committed
266
        return ResultModel.OK(service.findBody(platform, loginAccount));
manxiaoqiang committed
267 268 269 270
    }

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

kangxiaoshan committed
273
        return ResultModel.OK(service.getContractCode(code, platform, company));
manxiaoqiang committed
274 275 276 277
    }

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

manxiaoqiang committed
282 283 284 285 286 287
    @RequestMapping(value = "find/increment", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findIncrement(@CurrentAccount User loginAccount) {
        return ResultModel.OK(service.findIncrement());
    }

manxiaoqiang committed
288 289
    @RequestMapping(value = "find/rebat", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
290
    public ResultModel rebat(@CurrentAccount User loginAccount, @RequestParam String product, @RequestParam Integer level, @RequestParam Double money) {
manxiaoqiang committed
291 292 293 294 295 296 297 298 299 300 301 302
        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
303
    public ResultModel create(@CurrentAccount User loginAccount, @RequestBody Contract contract, HttpServletRequest request, @PathVariable String platform) {
kangxiaoshan committed
304

manxiaoqiang committed
305
        Contract contract1 = service.create(loginAccount, contract);
kangxiaoshan committed
306
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "新建合同", "", contract1.toString(), request, platform);
manxiaoqiang committed
307
        userlog.start();
kangxiaoshan committed
308 309
//        ContractSendEmailThread email = new ContractSendEmailThread(contract);
//        email.start();
manxiaoqiang committed
310
        return ResultModel.OK(contract1);
manxiaoqiang committed
311
    }
manxiaoqiang committed
312 313 314

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

        String ip = IPAddrUtil.getIpAddrNew(request);
kangxiaoshan committed
319 320
        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
321
        userlog.start();
kangxiaoshan committed
322

manxiaoqiang committed
323
        return ResultModel.OK(contract1);
manxiaoqiang committed
324 325 326 327
    }

    @RequestMapping(value = "pay", method = RequestMethod.POST)
    @ResponseBody
manxiaoqiang committed
328
    public ResultModel pay(@CurrentAccount User loginAccount, @RequestBody ContractMoney contract, HttpServletRequest request, @PathVariable String platform) {
manxiaoqiang committed
329
        ContractMoney contract1 = service.pay(loginAccount, contract);
kangxiaoshan committed
330
        NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), contract1.getContractCode(), "收款开票", "", contract1.toString(), request, platform);
manxiaoqiang committed
331 332
        userlog.start();
        return ResultModel.OK(contract1);
manxiaoqiang committed
333 334 335 336
    }

    @RequestMapping(value = "change", method = RequestMethod.POST)
    @ResponseBody
kangxiaoshan committed
337 338
    public ResultModel change(@CurrentAccount User loginAccount,
                              @RequestBody ContractChange contract, HttpServletRequest request, @PathVariable String platform) {
kangxiaoshan committed
339 340
        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
341 342
        userlog.start();
        return ResultModel.OK(contract1);
manxiaoqiang committed
343 344
    }

kangxiaoshan committed
345 346 347 348 349 350 351
    /**
     * @param loginAccount
     * @param startDate
     * @param endDate
     * @param code
     * @return
     */
manxiaoqiang committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365
    @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
366 367 368 369 370 371 372 373
    @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
374 375
    @RequestMapping(value = "update/pay", method = RequestMethod.PUT)
    @ResponseBody
kangxiaoshan committed
376 377 378 379
    public ResultModel updatePay(@CurrentAccount User loginAccount, @RequestBody ContractMoney contract, HttpServletRequest request,
                                 @PathVariable String platform) {

        String ip = IPAddrUtil.getIpAddrNew(request);
kangxiaoshan committed
380 381
        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
382 383
        userlog.start();
        return ResultModel.OK(contract1);
manxiaoqiang committed
384
    }
manxiaoqiang committed
385 386 387

    @RequestMapping(value = "find/payall", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
388
    @AuthKey(AuthMenuEnmm.COLLECTBILLLIST_V)
manxiaoqiang committed
389
    public ResultModel findPayAll(@CurrentAccount User loginAccount, @RequestParam String startDate,
kangxiaoshan committed
390 391 392
                                  @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
393

manxiaoqiang committed
394
    }
manxiaoqiang committed
395

manxiaoqiang committed
396 397 398 399
    @RequestMapping(value = "build", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel build(@RequestBody Contract contract, HttpServletRequest request) {

2  
manxiaoqiang committed
400
        logger.error("tkiio---------------" + contract);
manxiaoqiang committed
401 402
        return ResultModel.OK(service.build(contract));
    }
manxiaoqiang committed
403

kangxiaoshan committed
404
    @RequestMapping(value = "trade", method = RequestMethod.GET)
kangxiaoshan committed
405
    @ResponseBody
kangxiaoshan committed
406
    public ResultModel baseCreate(@PathVariable String platform) {
kangxiaoshan committed
407 408 409 410
        return ResultModel.OK(service.getTradeData(platform));
    }


kangxiaoshan committed
411
    @RequestMapping(value = "code/all", method = RequestMethod.GET)
kangxiaoshan committed
412
    @ResponseBody
kangxiaoshan committed
413
    public ResultModel contractCodeAll(@PathVariable String platform, String contractId) {
kangxiaoshan committed
414

kangxiaoshan committed
415
        return ResultModel.OK(service.contractCodeAll(platform, contractId));
kangxiaoshan committed
416 417 418
    }


kangxiaoshan committed
419 420
    @RequestMapping(value = "setstaus", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
421
    @AuthKey(AuthMenuEnmm.CONTRACTMNG_D)
kangxiaoshan committed
422 423
    public ResultModel contractStatusUpdate(@PathVariable String platform, @CurrentAccount User loginUser,
                                            String contractId, String status, HttpServletRequest request) {
kangxiaoshan committed
424

kangxiaoshan committed
425
        String ip = IPAddrUtil.getIpAddrNew(request);
kangxiaoshan committed
426
        return ResultModel.OK(service.contractStatusUpdate(platform, contractId, status, ip, loginUser));
kangxiaoshan committed
427 428 429
    }


kangxiaoshan committed
430 431
    @RequestMapping(value = "codecheck", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
432
    public ResultModel codeCheck(@PathVariable String platform, String contractCode) {
kangxiaoshan committed
433

kangxiaoshan committed
434
        return ResultModel.OK(service.contractCodeCheck(platform, contractCode));
kangxiaoshan committed
435 436 437
    }


kangxiaoshan committed
438 439
    /**
     * 删除记录
kangxiaoshan committed
440
     *
kangxiaoshan committed
441 442 443 444 445 446
     * @param platform
     * @param
     * @return
     */
    @RequestMapping(value = "change/del", method = RequestMethod.GET)
    @ResponseBody
kangxiaoshan committed
447 448 449
    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
450 451 452

    }

453
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
kangxiaoshan committed
454
    @ResponseBody
kangxiaoshan committed
455
    public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform) {
456
        return service.uploadBatchInfo(file, platform);
kangxiaoshan committed
457
    }
kangxiaoshan committed
458

459
    @RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET)
kangxiaoshan committed
460 461 462 463 464
    @ResponseBody
    public ResultModel fileTempUrl() {
        return ResultModel.OK(Constant.importTempUrl);
    }

465 466 467 468 469 470 471 472 473 474 475 476
    /**
     * 分摊收入
     *
     * @param loginAccount
     * @param platform
     * @param startDate
     * @param endDate
     * @param serchName
     * @return
     */
    @RequestMapping(value = "/shareincome/list", method = RequestMethod.GET)
    @ResponseBody
477
    @AuthKey(AuthMenuEnmm.SHARED_INCOME_V)
478 479 480 481
    public ResultModel shareIncome(@CurrentAccount User loginAccount, @PathVariable String platform,
                                   @RequestParam String startDate, @RequestParam String endDate,
                                   String bodyCode, String serchName) {

kangxiaoshan committed
482
        return ResultModel.OK(shareIncomeService.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName));
483 484 485 486 487

    }

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

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

kangxiaoshan committed
496
        //StringBuilder sb = new StringBuilder();
kangxiaoshan committed
497
        /*sb.append("我方签约主体,签约方,合同编号,合同金额,不含税收入,合同开始时间,合同截止时间,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");*/
kangxiaoshan committed
498
        //sb.append("我方签约主体,签约方,合同编号,合同状态,合同金额,不含税收入,合同开始日期,合同截止日期,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");
lzxry committed
499 500 501 502 503
        HSSFWorkbook workbook;
        if(platform.equals("tkio")){
            workbook = createTKIOExcel(contracts);
        }else{
            workbook = createCommonExcel(contracts);
kangxiaoshan committed
504 505 506 507 508 509 510 511 512 513
        }


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



        /*if (ValidateUtil.isValid(contracts)) {
514
            for (Contract c : contracts) {
1  
kangxiaoshan committed
515 516 517
                sb.append(c.getMyBodyName()).append(",")
                        .append(c.getCustomerBody()).append(",")
                        .append(c.getContractCode()).append(",")
kangxiaoshan committed
518
                        .append(CONTRACT_STATUS.get(c.getStatus())).append(",")
1  
kangxiaoshan committed
519 520 521 522 523 524 525
                        .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
526
                        .append("\"").append(df.format(c.getIncomeShareAll() * 1.0 / 100)).append("\"")
527 528 529
                        .append("\r\n");
            }
        }
1  
kangxiaoshan committed
530 531
        String fileName = "分摊收入报表_" + new DateTime(startDate).toString("yyyyMMdd")
                + "_" + new DateTime(endDate).toString("yyyyMMdd") + ".csv";
kangxiaoshan committed
532 533 534 535
        this.exportWrite(fileName, sb.toString(), "分摊收入报表", response);*/

    }

lzxry committed
536 537 538 539 540 541 542 543 544 545 546 547 548 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 579 580 581 582 583 584 585 586 587 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
    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);

        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.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());
            rowBody.createCell(10).setCellValue(contract.getUnitPrice());
            rowBody.createCell(11).setCellValue(contract.getClickFlow());
            rowBody.createCell(12).setCellValue(df.format(contract.getIntervaIncomeShare() / 100.0));
            rowBody.createCell(13).setCellValue(df.format(contract.getAdjustmentFund() / 100.0));
            rowBody.createCell(14).setCellValue(df.format(contract.getIncomeShareAll() / 100.0));
            rowBody.createCell(15).setCellValue(df.format(contract.getIncomeGross() / 100.0));
            rowBody.createCell(16).setCellValue(df2.format(contract.getExtraFlow() / 10000.0));
        }
        return workbook;
    }

kangxiaoshan committed
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
    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
637

kangxiaoshan committed
638
        }
kangxiaoshan committed
639 640 641 642
    }

    private void exportWrite(String fileName, String text, String exportName, HttpServletResponse response) {
        OutputStream os = null;
kangxiaoshan committed
643 644 645 646 647 648
        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
649
            response.setCharacterEncoding("UTF-8");
kangxiaoshan committed
650
            os = response.getOutputStream();
1  
kangxiaoshan committed
651
            os.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
kangxiaoshan committed
652
            os.write(text.getBytes("UTF-8"));
1  
kangxiaoshan committed
653
            os.flush();
kangxiaoshan committed
654
        } catch (Exception e) {
kangxiaoshan committed
655
            logger.error(exportName + "报错", e);
kangxiaoshan committed
656
        } finally {
1  
kangxiaoshan committed
657
            if (os != null) {
kangxiaoshan committed
658
                try {
1  
kangxiaoshan committed
659
                    os.close();
kangxiaoshan committed
660
                } catch (IOException e) {
kangxiaoshan committed
661
                    logger.error(exportName + "导出,关闭流报错", e);
kangxiaoshan committed
662 663
                }
            }
664

kangxiaoshan committed
665
        }
666
    }
kangxiaoshan committed
667

lzxry committed
668 669 670 671 672 673 674 675 676 677 678 679 680
    /**
     * 功能描述:新建合同回显、获取行政区域列表
     * @author liyin
     * @date 2020/9/23
     */
    @GetMapping("/getBarrioCities")
    @ResponseBody
    public ResultModel getBarrioCities(){

        return ResultModel.OK(service.getBarrioCities());
    }


manxiaoqiang committed
681
}