java springboot笔记

 

查看nginx日志

ps -ef | grep nginx
查看nginx 目录

最后一行
root 25458 1 0 Mar07 ? 00:00:01 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf

vim /www/server/nginx/conf/nginx.conf

找到include /www/server/panel/vhost/nginx 这个真正虚拟机

cd /www/server/panel/vhost/nginx 
找到你的网站域名目录
cat testsmall.yaotiao.net.conf
找到配置的
access_log /www/wwwlogs/testsmall.yaotiao.net.log;
error_log /www/wwwlogs/testsmall.yaotiao.net.error.log;
这两个日志文件,一个为正常的日志,一个为报错日志

@GetMapping("/ceshidetail") 查询
@PostMapping("/ceshiadd") 添加
@PutMapping(value = "/check/withdraw") 修改

@ApiOperation("tianjia")

更新代码更新maven

wallet-api constant 枚举类

wallet-provider

entity 实体类 存放数据库字段值 usercash
@TableName @TableId 固定格式

mapper 直接操作数据库,注意格式命名 UserCashMapper public interface 类型
@Mapper 固定格式
正常情况方法中为空即可
@Mapper
public interface UserCashMapper extends BaseMapper<UserCash> {
}

@Select("select ifnull(sum(amount),0) from user_cash where del_flag = 0 and status = 0 and DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')")
BigDecimal totalCheckMoney();


service
admin 后台接口
前台接口

UserCashService 注意命名格式,要跟entity下的 UserCash对应
@Service 固定格式 必须写
@Resource 必须写 引入的意思

@Service
public class UserCashService {
private $PROPERTY;

public function __construct($PROPERTY)
{
$this->PROPERTY = $PROPERTY;
}

@Resource 引入mapper直接操作数据库

private UserCashMapper userCashMapper;
私有的 变量名 要引入的mapper类
@Resource
private UserCashConfig userCashConfig;
@Resource
private WalletInOrOutService walletInOrOutService;
@Resource
private UserWalletMapper userWalletMapper;


/**
* 申请提现列表
*/

CeshiApiListResponse 返回的值
CeshiApiListRequest 要插入的值
如果不登录不搜索完全不用这个文件即可
如果定义可以不传递这个参数
只需要在sevice下的model里 进行判断即可
@Service
public class CeshiService {
@Resource
private CeshiMapper ceshiMapper;

/**
* 列表
*/
public TableDataInfo<CeshiApiListResponse> ceshiList(CeshiApiListRequest ceshiApiListRequest) {
//获取当前用户ID
Long userId = ceshiApiListRequest.getUid();
if (userId == null) {
throw new BaseException(CeshiEnum.NO_LOGIN.getCode(), CeshiEnum.NO_LOGIN.getMessage());
}
String title = ceshiApiListRequest.getTitle();
if (title == null){
从dto传递参数的文件中拿到get这个值得方法
如果传递的该值为空,在去做判断
}



TableDataInfo<UserCashApiListResponse 要返回的值
UserCashApiListRequest userCashApiListRequest 要传递的值

wallet-api dto usercash api UserCashApiListRequest
定义好long uid
alt insert xuanze get set Ctrla全选
自动插入get setuid

public TableDataInfo<UserCashApiListResponse> userCashApiList(UserCashApiListRequest userCashApiListRequest) {
//获取当前用户ID
Long userId = userCashApiListRequest.getUid();

定义的要传递的值得方法中的getuid,这里就是ctrl+a生成的 自动插入的哪两个方法

if (userId == null) {
throw new BaseException(UserCashExceptionEnum.NO_LOGIN.getCode(), UserCashExceptionEnum.NO_LOGIN.getMessage());

wallet-api下 exception UserCashExceptionEnum枚举类 中定义的报错提示,
UserCashExceptionEnum.NO_LOGIN.getCode()
UserCashExceptionEnum下的NO_LOGIN常量 以及自定义的getcode方法
}
QueryWrapper<UserCash> queryWrapper = new QueryWrapper<>();
查询构造器不用管,QueryWrapper<UserCash> 中UserCash 就是entity中定义的数据库里的字段

queryWrapper.orderByDesc("id");
queryWrapper.eq("uid", userId); uid 不是指的entity里的字段,而是数据表中的字段
queryWrapper.eq("del_flag", DelFlag.NORMAL);

DelFlag.NORMAL 公共方法不用管,就是成功失败的返回值

IPage<UserCash> page = new Page<>(userCashApiListRequest.getPageNum(), userCashApiListRequest.getPageSize());

分页查询构造器 
page = userCashMapper.selectPage(page, queryWrapper);

List<UserCash> userCashs = page.getRecords();

List<UserCashApiListResponse> result = new ArrayList<>();


for (Comment comments : commentPage) {
CommentApiListResponse commentApiListResponse = new CommentApiListResponse();

sour 回车就是打印的快捷键
System.out.println(comments.getContent());

BeanUtils.copyProperties(a, b); a 赋值给b
for (Comment comments : commentPage) {
CommentListResponse commentListResponse = new CommentListResponse();
BeanUtils.copyProperties(comments, commentListResponse);

断点:
debug 后post慢运行接口
会直接在编辑器中显示
F7 进入方法中
f8 一步一步往下走
f9 跳过该断点往下走


判断为空 特殊字符转义 超长 重复提交



 

http://jenkins.yaotiao.miaijia.com.cn/view/all/newJob
新建任务
jumi-comment 》 构建一个maven项目 》复制--jumi-comment
复制jumi-order 将所有order替换为comment
所有完成后回到主页面,点击jumi-comment后面的小齿轮构建项目,或者点击Build with Parameters
不用修改直接开始构建
provider文件修改后提交分支,然后这里从新构建即可(这个文件是直接从git上拉的)
api下的文件修改后提交分支还需要在maven中点击deploy发布一下

http://101.200.232.125:9009/swagger-ui.html
http://101.200.232.125:(本项目的端口号)/swagger-ui.html 测试

 

 


@PutMapping("/isdelSpecial")
@ApiOperation("是否删除关键词")
public ResponseResult<Boolean> isdelSpecial(SensitiveKeywordDelRequest sensitiveKeywordDelRequest) {
//sensitiveKeywordDelRequest.setUid(getUid());
//sensitiveKeywordDelRequest.setUid(10119L);

sensitiveKeywordRequest.setUpdataUser 指的是数据表的字段getUid() 这个是公共方法获取当前登录用户
sensitiveKeywordRequest.setUpdataUser(getUid());//token中获取 uid
sensitiveKeywordRequest.setUpdataUsername(getUserName());//token中获取 username

ResponseResult<Boolean> result = new ResponseResult<>();
result.setData(adminSpecialService.isdelSpecial(sensitiveKeywordDelRequest));
return result;
}

 

 

 

@ApiOperation("导出")
@PostMapping("/exportExcel")
public void exportExcel(ExportExcelRequest request, HttpServletResponse httpServerResponse) throws IOException {
ExportExcelCommonResponse<SensitiveExportResponse> exportExcelResponseExportExcelCommonResponse = exportExcelService.exportExcel(request);
httpServerResponse.setContentType("application/vnd.ms-excel");
httpServerResponse.setCharacterEncoding("utf-8");
httpServerResponse.setHeader("Content-disposition", "attachment;filename=" + exportExcelResponseExportExcelCommonResponse.getFileName());
EasyExcel.write(httpServerResponse.getOutputStream(), SensitiveExportResponse.class).sheet("sheet1").doWrite(exportExcelResponseExportExcelCommonResponse.getData());
}

/**
* 导入
*/
public boolean excelImport(HttpServletRequest request) throws IOException {
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
EasyExcel.read(request.getInputStream(), SenitiveImplodRequest.class, new SelfWaitSendListener(adminSpecialService)).sheet().doRead();
return true;
}


comment.setGid(commentApiGoodsRequest.getGid());

 

List<InvoiceOrderDetailResponse> listOrderSn = new ArrayList<>();
for (Invoice invoiceSn : userCashes) {
InvoiceOrderDetailResponse invoiceOrderSn = new InvoiceOrderDetailResponse();
BeanUtils.copyProperties(invoiceSn, invoiceOrderSn);
listOrderSn.add(invoiceOrderSn);
}


boolean isStatus = false;
updateAfterSealStatusRequest.checkRequest();

QueryWrapper<Invoice> invoiceQueryWrapper = new QueryWrapper<>();
invoiceQueryWrapper.eq("order_num", invoiceStatusRequest.getOrderNum());
Invoice invoice = invoiceMapper.selectOne(invoiceQueryWrapper);
if (invoice != null) {
invoice.setInvoiceStatus(invoiceStatusRequest.getInvoiceStatus());
int row = invoiceMapper.update(invoice, invoiceQueryWrapper);
if (row > 0) {
isStatus = true;
}
}
return isStatus;


接口参数传参赋值
@RequestParam 将orderId 付给int 用几个参数就写几次
@SpringQueryMap 传递的值是 dto里的多字段的时候用这个

@GetMapping("/feignClient/realSendAmount")
Integer realSendAmount(@RequestParam("orderId") int orderId, @RequestParam("goodsId") int goodsId);

@PostMapping("/order-service/log/add")
Boolean addOrderLog(@SpringQueryMap OrderLogRequest request);


字段为bigint 字段类型为long
字段为int 类型为inter


ExceptionEnum.FAIL_ID_NULL.doThrowIf(id==null); 符合条件就抛异常


主要谈一下对这三个注解的简单理解:
1.@Autowired
org.springframework.beans.factory.annotation.Autowired
SpringBoot项目中常用。简单来说就是引入由Spring容器管理的bean。

2.@Resource
javax.annotation.Resource
作用相当于@Autowired,只不过@Autowired是byType自动注入,而@Resource默认byName自动注入。

3.@Reference
@Reference是dubbo的注解,也是注入,他一般注入的是分布式的远程服务的对象,需要dubbo配置使用。


简单来说他们的区别:
@Reference注入的是分布式中的远程服务对象,@Resource和@Autowired注入的是本地spring容器中的对象


打印sql语句

文件设置-plugins mybatis mybatislog...按装
项目中-bootstrap--root: DEBUG 开启debug
打开 工具-mybatislogplugin 运行项目即可


改duboo服务:
api下service 要都把注解啥的删掉

新建InvoiceServiceImpl 文件将对外报漏接口放到这里,并集成api下service
修改throw信息为返回空,

内部使用方法可以抛异常,但是对外暴露的方法都要返回null,

内部接口与外部暴露接口要区分开
/**
* 根据订单编号查询订单发票状态是否已开票
* @param invoiceOneRequest
* @return
*/
@Override-----------------------------方法前加入此注解
public InvoiceOneResponse invoiceOneStatus(InvoiceOneRequest invoiceOneRequest)

 

 

对解口   新建client  继承接口  
使用:引入
  @Resource
    private GoodsClient goodsClient;

    //根据商品ID--sku查询商品主图【商品服务提供接口】
        List<Long> skuIds = new ArrayList<>();  定一个空数组
        List<GoodsSkuInfoDTO> getGoodsSkuInfoByIds = new ArrayList<>(); 引入goods的entity的字段文件
        for (Comment comments : commentPage) {   循环查出的数据
            skuIds.add(comments.getGid().longValue());  获取数据的gid 并专程long类型,赋值给skuids
        }
        if (skuIds.size() > 0) {
            getGoodsSkuInfoByIds = goodsClient.getGoodsSkuInfoByIds(skuIds); //调用商品接口返回值付给 getGoodsSkuInfoByIds
        }

使用:
//设置商品名称
            if (getGoodsSkuInfoByIds.size() > 0) {
                commentListResponse.setGidTitle(getGoodsSkuInfoByIds.iterator().next().getGoodsName());   iterator().next()指针往下走
            }



//根据订单编号查询订单商品信息【订单提供接口】
        List<Long> skuIds = new ArrayList<>();
        List<InvoiceGoodsResponse> getGoodsInfo = new ArrayList<>();
        for (Invoice invoiceSn : userCashes) {
            skuIds.add(invoiceSn.getGid().longValue());
        }
        if (skuIds.size() > 0) {
            getGoodsSkuInfoByIds = goodsClient.getGoodsSkuInfoByIds(skuIds);
        }




CommentProviderApplication文件添加下面这句,引入一次就行
@EnableDiscoveryClient
@EnableFeignClients

新下的项目无法启动,需要去nacos将他们项目的配置克隆刀我的空间下,(克隆配置 :目标空间-选择本人的  Group 改成DEV_GROUP)
然后本地的bootstrap 的端口跟namespace 要与我nacos空间保持一致,
将项目右击添加add maven project
在pom.xml文件上,右键 Add as Maven Project
     或 在项目上,右键 Add Framework Support

爆红报错--拉不下jar包,F:\res\com\jumi\microservice   找到需要更新的包,删掉,然后maven,重新拉取----clean,validate,compile


引入外来接口或包,使用时不知道定义什么类型返回 例如: userClient.getMemberByUid(1);  选中代码段,再按 Ctrl + Alt + v
结果: R<JmUserReponse> memberByUid = userClient.getMemberByUid(1);
        


clean:翻译:打扫清理,最直接的就是作用于橙色的target目录。在进行真正的构建之前进行一些清理工作,移除所有上一次构建生成的文件。执行该命令会删除项目路径下的target文件,但是不会删除本地的maven仓库已经生成的jar文件。

validate:翻译:验证。验证工程正确性,所需信息完整否。

compile:翻译:编译。大伙都知道java的识别文件是.class,编译生成class文件,编译命令,只编译选定的目标,不管之前是否已经编译过,会在你的项目路径下生成一个target目录,在该目录中包含一个classes文件夹,里面全是生成的class文件及字节码文件。与build区别:只编译选定的目标,不管之前是否已经编译过。

test:翻译:测试。单元测试。

package:翻译:打包。将工程文件打包为指定的格式,例如JAR,WAR等(看你项目的pom文件,里面的packaging标签就是来指定打包类型的)。这个命令会在你的项目路径下一个target目录,并且拥有compile命令的功能进行编译,同时会在target目录下生成项目的jar/war文件。如果a项目依赖于b项目,打包b项目时,只会打包到b项目下target下,编译a项目时就会报错,因为找不到所依赖的b项目,说明a项目在本地仓库是没有找到它所依赖的b项目,这时就用到install命令。

verify:翻译:核实。主要是对package检查是否有效、符合标准。

install:翻译:安装。将包安装至本地仓库,以让其它项目依赖。该命令包含了package命令功能,不但会在项目路径下生成class文件和jar包,同时会在你的本地maven仓库生成jar文件,供其他项目使用(如果没有设置过maven本地仓库,一般在用户/.m2目录下。如果a项目依赖于b项目,那么install b项目时,会在本地仓库同时生成pom文件和jar文件,解决了上面打包package出错的问题)。

build:翻译:建造。功能类似compile,区别是对整个项目进行编译。与compile区别及特点:是对整个工程进行彻底的重新编译,而不管是否已经编译过。Build过程往往会生成发布包,这个具体要看对IDE的配置了,Build在实际中应用很少,因为开发时候基本上不用,发布生产时候一般都用ANT等工具来发布。Build因为要全部编译,还要执行打包等额外工 作,因此时间较长。

site:翻译:站点。生成项目的站点文档。

deploy:翻译:配置部署。复制到远程仓库。


/**
     * 个人所得税计算,阶段计算方式如下:
     * x <= 800             : 0,
     * 800 < x <= 4000      : (x - 800) * 0.2,
     * 4000 < x <= 20000    : x * 0.8 * 0.2,
     * 20000 < x <= 50000   : x * 0.8 * 0.3 - 2000,
     * 50000 < x < ∞        : x * 0.8 * 0.4 -7000
     *
     * @param total 本月提现总金额( = 已提现金额 + 本次要提现金额)
     * @return 总税额
     */
    private BigDecimal calculationTax(BigDecimal total) {
        if (total.compareTo(new BigDecimal(800)) <= 0) {
            return new BigDecimal(0);
        } else if (total.compareTo(new BigDecimal(4000)) <= 0) {
            return total.subtract(new BigDecimal(800)).multiply(new BigDecimal("0.2"));
        } else if (total.compareTo(new BigDecimal(20000)) <= 0) {
            return total.multiply(new BigDecimal("0.8")).multiply(new BigDecimal("0.2"));
        } else if (total.compareTo(new BigDecimal(50000)) <= 0) {
            return total.multiply(new BigDecimal("0.8")).multiply(new BigDecimal("0.3"))
                    .subtract(new BigDecimal(2000));
        } else {
            return total.multiply(new BigDecimal("0.8")).multiply(new BigDecimal("0.4"))
                    .subtract(new BigDecimal(7000));
        }
    }


//计算商品总价减去退款金额跟邮费后的开票金额
//List<GoodsSkuResponse> goodsList = rows.get(0).getGoodsList();
BigDecimal orderAmount = rows.get(0).getOrderAmount();
log.info("\n\n------订单发票添加订单列表申请发票------【orderAmount】:[{}]========【goodsList】:[{}]", JSON.toJSONString(orderAmount),JSON.toJSONString(goodsList));
BigDecimal total=BigDecimal.ZERO;
log.info("订单发票添加订单列表申请发票------【total】:[{}]", JSON.toJSONString(total));
for (GoodsSkuResponse goodsLists:goodsList){
BigDecimal returnPostage = goodsLists.getReturnPostage();
BigDecimal returnPrice = goodsLists.getReturnPrice();
BigDecimal sunReturn = returnPrice.add(returnPostage);
total = total.add(sunReturn);
log.info("订单发票添加订单列表申请发票------【total + add】:[{}]", JSON.toJSONString(total));
}
log.info("订单发票添加订单列表申请发票------【total总共】:[{}]", JSON.toJSONString(total));
BigDecimal subtract = orderAmount.subtract(total);
log.info("订单发票添加订单列表申请发票------【orderAmount。subtract】:[{}]", JSON.toJSONString(subtract));


 


> Show Execution Point (Alt + F10):如果你的光标在其它行或其它页面,点击这个按钮可跳转到当前代码执行的行。


    > Step Over (F8):步过,一行一行地往下走,如果这一行上有方法不会进入方法。


    > Step Into (F7):步入,如果当前行有方法,可以进入方法内部,一般用于进入自定义方法内,不会进入官方类库的方法,如第25行的put方法。


    > Force Step Into (Alt + Shift + F7):强制步入,能进入任何方法,查看底层源码的时候可以用这个进入官方类库的方法。


    > Step Out (Shift + F8):步出,从步入的方法内退出到方法调用处,此时方法已执行完毕,只是还没有完成赋值。


    > Drop Frame (默认无):回退断点,后面章节详细说明。


    > Run to Cursor (Alt + F9):运行到光标处,你可以将光标定位到你需要查看的那一行,然后使用这个功能,代码会运行至光标行,而不需要打断点。


    > Evaluate Expression (Alt + F8):计算表达式,后面章节详细说明

 

 

 

 

posted @ 2020-12-17 10:31  御世制人  阅读(164)  评论(0编辑  收藏  举报