HtzzController.java 15.5 KB
Newer Older
yuquan.zhu committed
1 2
package cn.timer.api.controller.htzz;

翁国栋 committed
3 4 5
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
yuquan.zhu committed
6

翁国栋 committed
7 8 9 10 11
import cn.timer.api.utils.aliyun.OSSUtil;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.swagger.models.auth.In;
import org.bouncycastle.util.encoders.UrlBase64Encoder;
翁国栋 committed
12
import org.eclipse.jetty.util.StringUtil;
翁国栋 committed
13
import org.eclipse.jetty.util.UrlEncoded;
yuquan.zhu committed
14
import org.springframework.beans.factory.annotation.Autowired;
ilal committed
15
import org.springframework.beans.factory.annotation.Value;
16
import org.springframework.transaction.annotation.Transactional;
翁国栋 committed
17
import org.springframework.util.StringUtils;
yuquan.zhu committed
18 19 20 21 22 23 24 25 26
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

27
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
yuquan.zhu committed
28 29 30 31
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
ilal committed
32
import com.google.common.collect.Lists;
yuquan.zhu committed
33 34 35 36 37 38

import cn.hutool.core.util.StrUtil;
import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.timer.api.bean.htzz.HtzzAdminZzda;
import cn.timer.api.bean.htzz.HtzzAssoHtgx;
ilal committed
39
import cn.timer.api.bean.htzz.HtzzAssoZztx;
40
import cn.timer.api.bean.qyzx.businessService.QyzxRemainingQuantity;
yuquan.zhu committed
41 42 43 44 45
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.htzz.HtzzAdminZzdaMapper;
import cn.timer.api.dto.htzz.HtzzQueryDto;
ilal committed
46
import cn.timer.api.dto.htzz.NotifyPersonDto;
yuquan.zhu committed
47 48 49 50 51
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

翁国栋 committed
52 53 54
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

yuquan.zhu committed
55 56
@Api(tags = "7.0合同证照")
@RestController
57
@Transactional
翁国栋 committed
58
@RequestMapping(value = "/htzz", produces = {"application/json"})
yuquan.zhu committed
59 60
public class HtzzController {

翁国栋 committed
61 62 63 64 65 66 67 68
    @Autowired
    private HtzzAdminZzdaMapper htzzAdminZzdaMapper;
    @Autowired
    private OSSUtil oss;
    @Value("${config-8timer.Aliyun.project_package}")
    private String project_package;
    @Value("${zip.path}")
    private String zipPath;
翁国栋 committed
69 70
    @Value("${config-8timer.Aliyun.endpoint}")
    private String endpoint;
翁国栋 committed
71

翁国栋 committed
72 73 74 75 76 77 78 79 80
    @Value("${sftp.client.root}")
    private String root;

    @Value("${sftp.client.targetPath}")
    private String targetPath;

    @Value("${sftp.client.serverUrl}")
    private String serverUrl;

翁国栋 committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

    /**
     * 新增证件
     *
     * @param userBean
     * @param htzzAdminZzda 证照档案实体
     * @return 新增证件结果
     */
    @PostMapping("/addzj")
    @ApiOperation(value = "新增合同证件", httpMethod = "POST", notes = "接口发布说明")
    public Result<Object> addzj(@CurrentUser UserBean userBean, @RequestBody HtzzAdminZzda zzda) {
        Integer orgCode = userBean.getOrgCode();

        QyzxRemainingQuantity quantity = QyzxRemainingQuantity.builder().build().selectOne(
                new LambdaQueryWrapper<QyzxRemainingQuantity>().eq(QyzxRemainingQuantity::getOrgCode, orgCode)
                        .eq(QyzxRemainingQuantity::getPmid, 1).gt(QyzxRemainingQuantity::getRemainder, 0));
        Date date = null;
        Integer remainder = null;
        if (quantity != null) {
            remainder = quantity.getRemainder();
            date = quantity.getExpireDate();
        }
        if (quantity == null || remainder == null || remainder <= 0) { // 判断充了钱没
            return ResultUtil.error("请充值后使用短信功能!");
        }
        if (date != null && date.getTime() <= new Date().getTime()) {
            Logoutput("企业 " + orgCode + " :短信套餐已过期");
//			return ResultUtil.error("短信套餐已到期!");
        }
        if (zzda.getId() == null) {
            zzda.setTxkgType(1);//默认开启提醒
        }
        zzda.setLrrid(userBean.getEmpNum());
        zzda.setLrsjTime(new Date());
        zzda.setOrgCode(orgCode);

        zzda.setSendingStatus(0);//0:未发;1:已发
        zzda.setTemplateId(zzda.getTemplateId());//消息模板id
ilal committed
119
//		zzda.insert();
翁国栋 committed
120 121 122 123 124 125 126 127
        zzda.insertOrUpdate();

        /**
         * 新增通知关系表,每人一个
         */
        List<NotifyPersonDto> ids = zzda.getIds();//通知人    用户id+手机号码
        List<HtzzAssoHtgx> htgxs = Lists.newArrayList();
        for (NotifyPersonDto pre : ids) {
翁国栋 committed
128 129 130 131 132 133 134
//            HtzzAssoHtgx.builder().build().delete(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getOrgCode, orgCode).eq(HtzzAssoHtgx::getTzrid, pre.getEmpNum())
//                    .eq(HtzzAssoHtgx::getPhone, pre.getPhone()));
            HtzzAssoHtgx htgx = HtzzAssoHtgx.builder().build().selectOne(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getOrgCode, orgCode).eq(HtzzAssoHtgx::getTzrid, pre.getEmpNum())
                    .eq(HtzzAssoHtgx::getPhone, pre.getPhone()).eq(HtzzAssoHtgx::getHtid,zzda.getId()));
            if (htgx == null) {
                htgx = HtzzAssoHtgx.builder().build();
            }
翁国栋 committed
135 136 137 138 139
            htgx.setHtid(zzda.getId());
            htgx.setTzrid(pre.getEmpNum());
            htgx.setName(pre.getEmpName());
            htgx.setPhone(pre.getPhone());
            htgx.setOrgCode(orgCode);
翁国栋 committed
140
            htgx.insertOrUpdate();
翁国栋 committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
            htgxs.add(htgx);
        }
        HtzzAssoZztx zztx = zzda.getZztx();
        zztx.setZzdaId(zzda.getId());
        zztx.setOrgCode(orgCode);
        zztx.setLrrid(userBean.getEmpNum());
        zztx.setLrsjTime(new Date());
        zztx.insertOrUpdate();

        return ResultUtil.datas(zzda, htgxs, "新增证件成功!");
    }

    @GetMapping("/modifytx/{id}")
    @ApiOperation(value = "修改提醒数据", httpMethod = "GET", notes = "接口发布说明")
    public Result<Object> modifytx(@CurrentUser UserBean userBean, @PathVariable Integer id) {


        List<NotifyPersonDto> tzids = new ArrayList<NotifyPersonDto>();
        List<HtzzAssoHtgx> httxs = HtzzAssoHtgx.builder().build().selectList(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getHtid, id));
        for (HtzzAssoHtgx gx : httxs) {
            NotifyPersonDto predto = NotifyPersonDto.builder().build();
            predto.setEmpName(gx.getName());
            predto.setEmpNum(gx.getTzrid());
            predto.setPhone(gx.getPhone());
            tzids.add(predto);
        }

        HtzzAdminZzda zzda = HtzzAdminZzda.builder().id(id).build().selectById();
        HtzzAssoZztx zztx = HtzzAssoZztx.builder().build().selectOne(new QueryWrapper<HtzzAssoZztx>().lambda().eq(HtzzAssoZztx::getZzdaId, id));
        zzda.setZztx(zztx);
        zzda.setIds(tzids);

        return ResultUtil.data(zzda, "新增成功");
    }


    /**
     * 按条件搜索(关键字、到期时间)
     *
     * @param userBean
     * @return
     */
    @GetMapping("/queryht")
    @ApiOperation(value = "按条件搜索(关键字、到期时间)", httpMethod = "GET", notes = "接口发布说明")
    public Result<Object> queryht(@CurrentUser UserBean userBean, HtzzQueryDto htzzQueryDto) {
        String e = htzzQueryDto.getEndTime();
        String q = htzzQueryDto.getQuery();
        Page<HtzzAdminZzda> page = new Page<HtzzAdminZzda>(
                htzzQueryDto.getCurrentPage() == null ? 1 : htzzQueryDto.getCurrentPage(),
                htzzQueryDto.getTotalPage() == null ? 10 : htzzQueryDto.getTotalPage());

        QueryWrapper<HtzzAdminZzda> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_code", userBean.getOrgCode())
                .select("id", "zjmc", "czry", "fzjg", "fzrq", "yxdqr", "txkg_type").eq("is_delete", 0).eq("document_type", htzzQueryDto.getDocumentType())
                .gt(!StrUtil.hasBlank(e), "yxdqr", !StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
                .and(!StrUtil.hasBlank(q), wq -> wq.like("zjmc", q).or().like("czry", q)).orderByDesc("lrsj_time");

        IPage<HtzzAdminZzda> zPage = HtzzAdminZzda.builder().build().selectPage(page, queryWrapper);
        List<HtzzAdminZzda> zccrkgls = zPage.getRecords();
        zPage.getCurrent();
        zPage.getPages();
        zPage.getTotal();
        zPage.getSize();
        return ResultUtil.data(zPage, zccrkgls, "搜索成功");
    }

    /**
     * 根据id查合同
     *
     * @param id
     * @return
     */
    @PostMapping(value = "/queryHt/{id}")
    @ApiOperation(value = "根据id查合同", httpMethod = "POST", notes = "接口发布说明")
    public Result<Object> queryHt(@CurrentUser UserBean userBean, @PathVariable Integer id) {
        List<Object> list = new ArrayList<Object>();
        list.add(HtzzAdminZzda.builder().build().selectOne(new QueryWrapper<HtzzAdminZzda>()
                .eq("org_code", userBean.getOrgCode()).eq("is_delete", 0).eq("id", id)));
        QueryWrapper<HtzzAssoHtgx> q = new QueryWrapper<HtzzAssoHtgx>();
        q.select("id", "name").eq("htid", id);
        List<HtzzAssoHtgx> htgx = HtzzAssoHtgx.builder().build().selectList(q);
        for (HtzzAssoHtgx gx : htgx) {
            String name = gx.getName();
            list.add(name);
        }
        return ResultUtil.data(list);
    }

    /**
     * 根据id删除合同
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delHt")
    @ApiOperation(value = "根据id删除合同", httpMethod = "DELETE", notes = "接口发布说明")
    public Result<Object> delHt(@CurrentUser UserBean userBean, @RequestParam Integer htid) {
        // 删除提醒关系
        HtzzAssoHtgx.builder().build().delete(new QueryWrapper<HtzzAssoHtgx>().eq("org_code", userBean.getOrgCode()).eq("htid", htid));

        //删除证照提醒表配置
        HtzzAssoZztx.builder().build().delete(new QueryWrapper<HtzzAssoZztx>().lambda().eq(HtzzAssoZztx::getZzdaId, htid));

        // 设置证照删除状态
        return ResultUtil.data(HtzzAdminZzda.builder().id(htid).isDelete(1).build().updateById());
    }

    /**
     * 修改提醒状态
     *
     * @param id
     * @return
     */
    @PostMapping(value = "/changeTx")
    @ApiOperation(value = "修改提醒状态", httpMethod = "POST", notes = "接口发布说明")
    public Result<Object> changeTx(@CurrentUser UserBean userBean, @RequestParam Integer htid) {

        QueryWrapper<HtzzAdminZzda> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("txkg_type").eq("id", htid);
        HtzzAdminZzda zzda = HtzzAdminZzda.builder().build().selectOne(queryWrapper);

        UpdateWrapper<HtzzAdminZzda> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", htid);
        HtzzAdminZzda w = HtzzAdminZzda.builder().orgCode(userBean.getOrgCode()).id(htid)
                .txkgType(zzda.getTxkgType() == 0 ? 1 : 0).build();
        htzzAdminZzdaMapper.update(w, updateWrapper);
        return ResultUtil.success("修改成功");

    }

    /**
     * 查詢全部員工id、姓名
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryYg")
    @ApiOperation(value = "查詢全部員工id、姓名", httpMethod = "GET", notes = "接口发布说明")
    public Result<Object> queryYg(@CurrentUser UserBean userBean) {
        return ResultUtil.data(YgglMainEmp.builder().build().selectList(
                new QueryWrapper<YgglMainEmp>().select("emp_num", "name", "phone").eq("org_code", userBean.getOrgCode())));
    }

    @GetMapping(value = "/test")
    @ApiOperation(value = "test", httpMethod = "GET", notes = "接口发布说明")
    public Result<Void> test(String schedulingPattern) {
        CronUtil.schedule("*/2 * * 24 * *", new Task() {
            @Override
            public void execute() {
                Logoutput("start:" + new Date());
            }
        });

        CronUtil.setMatchSecond(true);
        CronUtil.start();
        return ResultUtil.success("操作成功");
    }


    @Value("${config-8timer.environmental-science}")
    public String environmental_science;

    public void Logoutput(String science) {

        if (!("pro").equals(environmental_science)) {

            System.out.println(science);
        } else {
            System.out.println("");
        }
    }

    /**
     * @Author wgd
     * @Description 导出勾选的合同
     * @Date 2021/12/2 17:05
     **/
    @PostMapping(value = "/exportContract")
    public Result<Object> exportContract(@CurrentUser UserBean userBean, @RequestBody List<Integer> ids, HttpServletRequest request, HttpServletResponse resp) {
        if (ids.size() <= 0) {
            return ResultUtil.error("操作失败");
        }
        Map<String, String> url = Maps.newHashMap();
翁国栋 committed
324
        Map<String, String> ftp = Maps.newHashMap();
翁国栋 committed
325 326
        ids.forEach(i -> {
            HtzzAdminZzda htzzAdminZzda = HtzzAdminZzda.builder().id(i).build().selectById();
翁国栋 committed
327
            if (StringUtil.isNotBlank(htzzAdminZzda.getZjfj())) {
翁国栋 committed
328
                /*格式化获取文字*/
翁国栋 committed
329 330 331
                String urla = UrlEncoded.decodeString(htzzAdminZzda.getZjfj());
                /*判断是保存在oss还是服务器*/
                if (urla.contains(endpoint.replace("http://", "."))) {
翁国栋 committed
332 333
                    int index = urla.indexOf(project_package);
                    url.put(htzzAdminZzda.getId() + "_" + htzzAdminZzda.getZjmc(), urla.substring(index));
翁国栋 committed
334
                } else {
翁国栋 committed
335
                    //TODO 区分出云盘文件暂时不下载
翁国栋 committed
336 337
                    StringBuffer newUrl = new StringBuffer(root).append(targetPath).append(urla.substring(serverUrl.length()));
                    ftp.put(htzzAdminZzda.getId() + "_" + htzzAdminZzda.getZjmc(), newUrl.toString());
翁国栋 committed
338 339
                }
            }
翁国栋 committed
340 341 342 343 344
        });
        String zipUrl = null;
        try {
            zipUrl = oss.createZip(url);
            return ResultUtil.data(zipUrl);
345
        } catch (IOException e) {
翁国栋 committed
346
            e.printStackTrace();
347
            return ResultUtil.error("操作失败");
翁国栋 committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
        }
    }

    @GetMapping(value = "/exportContract")
    public void exportContract(@CurrentUser UserBean userBean, @RequestParam("url") String url, HttpServletRequest request, HttpServletResponse resp) {
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        OutputStream os;
        File filePath = null;
        try {
            resp.setContentType("application/octet-stream");
            resp.setHeader("content-disposition", "attachment; filename=" + new String(url.getBytes("UTF8"), "ISO-8859-1"));
            resp.setCharacterEncoding("UTF-8");
            filePath = new File(zipPath + url);
            byte[] buffer = new byte[1024];
            fis = new FileInputStream(filePath);
            bis = new BufferedInputStream(fis);
            os = resp.getOutputStream();
            int i = bis.read(buffer);
            while (i != -1) {
                os.write(buffer, 0, i);
                i = bis.read(buffer);
            }
            os.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            filePath.delete();
        }
    }
yuquan.zhu committed
388
}